]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/additionalinfodialog.cpp
4589b5d4477a947622236fa10316a97bd39002ed
[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 <KSharedConfig>
25 #include <KLocalizedString>
26 #include "kitemviews/kfileitemmodel.h"
27 #include <KConfigGroup>
28 #include <KWindowConfig>
29
30 #include <QCheckBox>
31 #include <QLabel>
32 #include <QVBoxLayout>
33 #include <QDialogButtonBox>
34 #include <QPushButton>
35
36 #ifdef HAVE_BALOO
37 #include <Baloo/IndexerConfig>
38 #endif
39
40 AdditionalInfoDialog::AdditionalInfoDialog(QWidget* parent,
41 const QList<QByteArray>& visibleRoles) :
42 QDialog(parent),
43 m_visibleRoles(visibleRoles),
44 m_listWidget(0)
45 {
46 setWindowTitle(i18nc("@title:window", "Additional Information"));
47 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
48
49 auto layout = new QVBoxLayout(this);
50 setLayout(layout);
51
52 // Add header
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);
57
58 // Add checkboxes
59 bool indexingEnabled = false;
60 #ifdef HAVE_BALOO
61 Baloo::IndexerConfig config;
62 indexingEnabled = config.fileIndexingEnabled();
63 #endif
64
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);
71
72 const bool enable = ((!info.requiresBaloo && !info.requiresIndexer) ||
73 (info.requiresBaloo) ||
74 (info.requiresIndexer && indexingEnabled)) && info.role != "text";
75
76 if (!enable) {
77 item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
78 }
79 }
80 layout->addWidget(m_listWidget);
81
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);
86
87 auto okButton = buttonBox->button(QDialogButtonBox::Ok);
88 okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
89 okButton->setDefault(true);
90
91 const KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "AdditionalInfoDialog");
92 KWindowConfig::restoreWindowSize(windowHandle(), dialogConfig);
93 }
94
95 AdditionalInfoDialog::~AdditionalInfoDialog()
96 {
97 KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "AdditionalInfoDialog");
98 KWindowConfig::saveWindowSize(windowHandle(), dialogConfig);
99 }
100
101 QList<QByteArray> AdditionalInfoDialog::visibleRoles() const
102 {
103 return m_visibleRoles;
104 }
105
106 void AdditionalInfoDialog::accept()
107 {
108 m_visibleRoles.clear();
109
110 int index = 0;
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);
116 }
117 ++index;
118 }
119
120 QDialog::accept();
121 }