]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/additionalinfodialog.cpp
Port Dolphin to Baloo
[dolphin.git] / src / settings / additionalinfodialog.cpp
1 /***************************************************************************
2 * Copyright (C) 2007-2012 by Peter Penz <peter.penz19@gmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "additionalinfodialog.h"
21
22 #include <config-baloo.h>
23
24 #include <KLocale>
25 #include "kitemviews/kfileitemmodel.h"
26 #include <QCheckBox>
27 #include <QLabel>
28 #include <QVBoxLayout>
29
30 #ifdef HAVE_BALOO
31 #include <baloo/indexerconfig.h>
32 #endif
33
34 AdditionalInfoDialog::AdditionalInfoDialog(QWidget* parent,
35 const QList<QByteArray>& visibleRoles) :
36 KDialog(parent),
37 m_visibleRoles(visibleRoles),
38 m_listWidget(0)
39 {
40 setCaption(i18nc("@title:window", "Additional Information"));
41 setButtons(Ok | Cancel);
42 setDefaultButton(Ok);
43
44 QWidget* mainWidget = new QWidget(this);
45 mainWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
46
47 // Add header
48 QLabel* header = new QLabel(mainWidget);
49 header->setText(i18nc("@label", "Select which additional information should be shown:"));
50 header->setWordWrap(true);
51
52 // Add checkboxes
53 bool indexingEnabled = false;
54 #ifdef HAVE_BALOO
55 Baloo::IndexerConfig config;
56 indexingEnabled = config.fileIndexingEnabled();
57 #endif
58
59 m_listWidget = new QListWidget(mainWidget);
60 m_listWidget->setSelectionMode(QAbstractItemView::NoSelection);
61 const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
62 foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
63 QListWidgetItem* item = new QListWidgetItem(info.translation, m_listWidget);
64 item->setCheckState(visibleRoles.contains(info.role) ? Qt::Checked : Qt::Unchecked);
65
66 const bool enable = (!info.requiresBaloo && !info.requiresIndexer) ||
67 (info.requiresBaloo) ||
68 (info.requiresIndexer && indexingEnabled);
69
70 if (!enable) {
71 item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
72 }
73 }
74
75 QVBoxLayout* layout = new QVBoxLayout(mainWidget);
76 layout->addWidget(header);
77 layout->addWidget(m_listWidget);
78 layout->addStretch(1);
79
80 setMainWidget(mainWidget);
81
82 const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "AdditionalInfoDialog");
83 restoreDialogSize(dialogConfig);
84
85 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
86 }
87
88 AdditionalInfoDialog::~AdditionalInfoDialog()
89 {
90 KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "AdditionalInfoDialog");
91 saveDialogSize(dialogConfig, KConfigBase::Persistent);
92 }
93
94 QList<QByteArray> AdditionalInfoDialog::visibleRoles() const
95 {
96 return m_visibleRoles;
97 }
98
99 void AdditionalInfoDialog::slotOk()
100 {
101 m_visibleRoles.clear();
102
103 int index = 0;
104 const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
105 foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
106 const QListWidgetItem* item = m_listWidget->item(index);
107 if (item->checkState() == Qt::Checked) {
108 m_visibleRoles.append(info.role);
109 }
110 ++index;
111 }
112 }
113
114 #include "additionalinfodialog.moc"