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