]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/additionalinfodialog.cpp
4589b5d4477a947622236fa10316a97bd39002ed
1 /***************************************************************************
2 * Copyright (C) 2007-2012 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "additionalinfodialog.h"
22 #include <config-baloo.h>
24 #include <KSharedConfig>
25 #include <KLocalizedString>
26 #include "kitemviews/kfileitemmodel.h"
27 #include <KConfigGroup>
28 #include <KWindowConfig>
32 #include <QVBoxLayout>
33 #include <QDialogButtonBox>
34 #include <QPushButton>
37 #include <Baloo/IndexerConfig>
40 AdditionalInfoDialog::AdditionalInfoDialog(QWidget
* parent
,
41 const QList
<QByteArray
>& visibleRoles
) :
43 m_visibleRoles(visibleRoles
),
46 setWindowTitle(i18nc("@title:window", "Additional Information"));
47 setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Minimum
);
49 auto layout
= new QVBoxLayout(this);
53 auto header
= new QLabel(this);
54 header
->setText(i18nc("@label", "Select which additional information should be shown:"));
55 header
->setWordWrap(true);
56 layout
->addWidget(header
);
59 bool indexingEnabled
= false;
61 Baloo::IndexerConfig config
;
62 indexingEnabled
= config
.fileIndexingEnabled();
65 m_listWidget
= new QListWidget(this);
66 m_listWidget
->setSelectionMode(QAbstractItemView::NoSelection
);
67 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
68 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
69 QListWidgetItem
* item
= new QListWidgetItem(info
.translation
, m_listWidget
);
70 item
->setCheckState(visibleRoles
.contains(info
.role
) ? Qt::Checked
: Qt::Unchecked
);
72 const bool enable
= ((!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
73 (info
.requiresBaloo
) ||
74 (info
.requiresIndexer
&& indexingEnabled
)) && info
.role
!= "text";
77 item
->setFlags(item
->flags() & ~Qt::ItemIsEnabled
);
80 layout
->addWidget(m_listWidget
);
82 auto buttonBox
= new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel
, this);
83 connect(buttonBox
, &QDialogButtonBox::accepted
, this, &AdditionalInfoDialog::accept
);
84 connect(buttonBox
, &QDialogButtonBox::rejected
, this, &AdditionalInfoDialog::reject
);
85 layout
->addWidget(buttonBox
);
87 auto okButton
= buttonBox
->button(QDialogButtonBox::Ok
);
88 okButton
->setShortcut(Qt::CTRL
| Qt::Key_Return
);
89 okButton
->setDefault(true);
91 const KConfigGroup
dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "AdditionalInfoDialog");
92 KWindowConfig::restoreWindowSize(windowHandle(), dialogConfig
);
95 AdditionalInfoDialog::~AdditionalInfoDialog()
97 KConfigGroup
dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "AdditionalInfoDialog");
98 KWindowConfig::saveWindowSize(windowHandle(), dialogConfig
);
101 QList
<QByteArray
> AdditionalInfoDialog::visibleRoles() const
103 return m_visibleRoles
;
106 void AdditionalInfoDialog::accept()
108 m_visibleRoles
.clear();
111 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
112 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
113 const QListWidgetItem
* item
= m_listWidget
->item(index
);
114 if (item
->checkState() == Qt::Checked
) {
115 m_visibleRoles
.append(info
.role
);