]>
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>
24 #include <KSharedConfig>
25 #include <KLocalizedString>
26 #include "kitemviews/kfileitemmodel.h"
29 #include <QVBoxLayout>
32 #include <Baloo/IndexerConfig>
35 AdditionalInfoDialog::AdditionalInfoDialog(QWidget
* parent
,
36 const QList
<QByteArray
>& visibleRoles
) :
38 m_visibleRoles(visibleRoles
),
41 setCaption(i18nc("@title:window", "Additional Information"));
42 setButtons(Ok
| Cancel
);
45 QWidget
* mainWidget
= new QWidget(this);
46 mainWidget
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::Minimum
);
49 QLabel
* header
= new QLabel(mainWidget
);
50 header
->setText(i18nc("@label", "Select which additional information should be shown:"));
51 header
->setWordWrap(true);
54 bool indexingEnabled
= false;
56 Baloo::IndexerConfig config
;
57 indexingEnabled
= config
.fileIndexingEnabled();
60 m_listWidget
= new QListWidget(mainWidget
);
61 m_listWidget
->setSelectionMode(QAbstractItemView::NoSelection
);
62 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
63 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
64 QListWidgetItem
* item
= new QListWidgetItem(info
.translation
, m_listWidget
);
65 item
->setCheckState(visibleRoles
.contains(info
.role
) ? Qt::Checked
: Qt::Unchecked
);
67 const bool enable
= (!info
.requiresBaloo
&& !info
.requiresIndexer
) ||
68 (info
.requiresBaloo
) ||
69 (info
.requiresIndexer
&& indexingEnabled
);
72 item
->setFlags(item
->flags() & ~Qt::ItemIsEnabled
);
76 QVBoxLayout
* layout
= new QVBoxLayout(mainWidget
);
77 layout
->addWidget(header
);
78 layout
->addWidget(m_listWidget
);
80 setMainWidget(mainWidget
);
82 const KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"), "AdditionalInfoDialog");
83 restoreDialogSize(dialogConfig
);
85 connect(this, &AdditionalInfoDialog::okClicked
, this, &AdditionalInfoDialog::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
);