]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/additionalinfodialog.cpp
Remove RolesInfoAccessor
[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 <KLocale>
23 #include "kitemviews/kfileitemmodel.h"
24 #include <QCheckBox>
25 #include <QLabel>
26 #include <QVBoxLayout>
27
28 AdditionalInfoDialog::AdditionalInfoDialog(QWidget* parent,
29 const QList<QByteArray>& visibleRoles) :
30 KDialog(parent),
31 m_visibleRoles(visibleRoles),
32 m_listWidget(0)
33 {
34 setCaption(i18nc("@title:window", "Additional Information"));
35 setButtons(Ok | Cancel);
36 setDefaultButton(Ok);
37
38 QWidget* mainWidget = new QWidget(this);
39 mainWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
40
41 // Add header
42 QLabel* header = new QLabel(mainWidget);
43 header->setText(i18nc("@label", "Select which additional information should be shown:"));
44 header->setWordWrap(true);
45
46 // Add checkboxes
47 m_listWidget = new QListWidget(mainWidget);
48 m_listWidget->setSelectionMode(QAbstractItemView::NoSelection);
49 const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
50 foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
51 QListWidgetItem* item = new QListWidgetItem(info.translation, m_listWidget);
52 item->setCheckState(visibleRoles.contains(info.role) ? Qt::Checked : Qt::Unchecked);
53 }
54
55 QVBoxLayout* layout = new QVBoxLayout(mainWidget);
56 layout->addWidget(header);
57 layout->addWidget(m_listWidget);
58 layout->addStretch(1);
59
60 setMainWidget(mainWidget);
61
62 const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "AdditionalInfoDialog");
63 restoreDialogSize(dialogConfig);
64
65 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
66 }
67
68 AdditionalInfoDialog::~AdditionalInfoDialog()
69 {
70 KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"), "AdditionalInfoDialog");
71 saveDialogSize(dialogConfig, KConfigBase::Persistent);
72 }
73
74 QList<QByteArray> AdditionalInfoDialog::visibleRoles() const
75 {
76 return m_visibleRoles;
77 }
78
79 void AdditionalInfoDialog::slotOk()
80 {
81 m_visibleRoles.clear();
82
83 int index = 0;
84 const QList<KFileItemModel::RoleInfo> rolesInfo = KFileItemModel::rolesInformation();
85 foreach (const KFileItemModel::RoleInfo& info, rolesInfo) {
86 const QListWidgetItem* item = m_listWidget->item(index);
87 if (item->checkState() == Qt::Checked) {
88 m_visibleRoles.append(info.role);
89 }
90 ++index;
91 }
92 }
93
94 #include "additionalinfodialog.moc"