]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/additionalinfodialog.cpp
1 /***************************************************************************
2 * Copyright (C) 2007-2012 by Peter Penz <peter.penz19@gmail.com> *
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. *
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. *
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 ***************************************************************************/
20 #include "additionalinfodialog.h"
22 #include <config-baloo.h>
25 #include "kitemviews/kfileitemmodel.h"
28 #include <QVBoxLayout>
31 #include <baloo/indexerconfig.h>
34 AdditionalInfoDialog::AdditionalInfoDialog(QWidget
* parent
,
35 const QList
<QByteArray
>& visibleRoles
) :
37 m_visibleRoles(visibleRoles
),
40 setCaption(i18nc("@title:window", "Additional Information"));
41 setButtons(Ok
| Cancel
);
44 QWidget
* mainWidget
= new QWidget(this);
45 mainWidget
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Minimum
);
48 QLabel
* header
= new QLabel(mainWidget
);
49 header
->setText(i18nc("@label", "Select which additional information should be shown:"));
50 header
->setWordWrap(true);
53 bool indexingEnabled
= false;
55 Baloo::IndexerConfig config
;
56 indexingEnabled
= config
.fileIndexingEnabled();
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
);
66 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
67 (info
.requiresBaloo
) ||
68 (info
.requiresIndexer
&& indexingEnabled
);
71 item
->setFlags(item
->flags() & ~Qt::ItemIsEnabled
);
75 QVBoxLayout
* layout
= new QVBoxLayout(mainWidget
);
76 layout
->addWidget(header
);
77 layout
->addWidget(m_listWidget
);
78 layout
->addStretch(1);
80 setMainWidget(mainWidget
);
82 const KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"), "AdditionalInfoDialog");
83 restoreDialogSize(dialogConfig
);
85 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
88 AdditionalInfoDialog::~AdditionalInfoDialog()
90 KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"), "AdditionalInfoDialog");
91 saveDialogSize(dialogConfig
, KConfigBase::Persistent
);
94 QList
<QByteArray
> AdditionalInfoDialog::visibleRoles() const
96 return m_visibleRoles
;
99 void AdditionalInfoDialog::slotOk()
101 m_visibleRoles
.clear();
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
);
114 #include "additionalinfodialog.moc"