]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/additionalinfodialog.cpp
Use the AdditionalInfoAccessor to be flexible for future changes/extensions in KFileI...
[dolphin.git] / src / settings / additionalinfodialog.cpp
1 /***************************************************************************
2 * Copyright (C) 2007 by Peter Penz (peter.penz@gmx.at) *
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 "additionalinfoaccessor.h"
23 #include <klocale.h>
24
25 #include <QCheckBox>
26 #include <QLabel>
27 #include <QVBoxLayout>
28
29 AdditionalInfoDialog::AdditionalInfoDialog(QWidget* parent,
30 KFileItemDelegate::InformationList infoList) :
31 KDialog(parent),
32 m_infoList(infoList),
33 m_checkBoxes()
34 {
35 setCaption(i18nc("@title:window", "Additional Information"));
36 setButtons(Ok | Cancel);
37 setDefaultButton(Ok);
38
39 QWidget* mainWidget = new QWidget(this);
40 mainWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
41 QVBoxLayout* layout = new QVBoxLayout(mainWidget);
42
43 // Add header
44 QLabel* header = new QLabel(mainWidget);
45 header->setText(i18nc("@label", "Configure which additional information should be shown."));
46 header->setWordWrap(true);
47 layout->addWidget(header);
48
49 // Add checkboxes
50 const AdditionalInfoAccessor& infoAccessor = AdditionalInfoAccessor::instance();
51 const KFileItemDelegate::InformationList keys = infoAccessor.keys();
52 foreach (const KFileItemDelegate::Information info, keys) {
53 QCheckBox* checkBox = new QCheckBox(infoAccessor.translation(info), mainWidget);
54 checkBox->setChecked(infoList.contains(info));
55 layout->addWidget(checkBox);
56 m_checkBoxes.append(checkBox);
57 }
58
59 layout->addStretch(1);
60
61 setMainWidget(mainWidget);
62
63 const KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"),
64 "AdditionalInfoDialog");
65 restoreDialogSize(dialogConfig);
66
67 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
68 }
69
70 AdditionalInfoDialog::~AdditionalInfoDialog()
71 {
72 KConfigGroup dialogConfig(KSharedConfig::openConfig("dolphinrc"),
73 "AdditionalInfoDialog");
74 saveDialogSize(dialogConfig, KConfigBase::Persistent);
75 }
76
77 KFileItemDelegate::InformationList AdditionalInfoDialog::informationList() const
78 {
79 return m_infoList;
80 }
81
82 void AdditionalInfoDialog::slotOk()
83 {
84 m_infoList.clear();
85
86 const KFileItemDelegate::InformationList keys = AdditionalInfoAccessor::instance().keys();
87 int index = 0;
88 foreach (const KFileItemDelegate::Information info, keys) {
89 if (m_checkBoxes[index]->isChecked()) {
90 m_infoList.append(info);
91 }
92 ++index;
93 }
94 }
95
96 #include "additionalinfodialog.moc"