]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/additionalinfodialog.cpp
0efa8a5fe4bee62e2caf681d2a9036741655360e
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-nepomuk.h>
25 #include "kitemviews/kfileitemmodel.h"
28 #include <QVBoxLayout>
31 #include <Nepomuk2/ResourceManager>
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 nepomukRunning
= false;
54 bool indexingEnabled
= false;
56 nepomukRunning
= (Nepomuk2::ResourceManager::instance()->initialized());
58 KConfig
config("nepomukserverrc");
59 indexingEnabled
= config
.group("Service-nepomukfileindexer").readEntry("autostart", true);
63 m_listWidget
= new QListWidget(mainWidget
);
64 m_listWidget
->setSelectionMode(QAbstractItemView::NoSelection
);
65 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
66 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
67 QListWidgetItem
* item
= new QListWidgetItem(info
.translation
, m_listWidget
);
68 item
->setCheckState(visibleRoles
.contains(info
.role
) ? Qt::Checked
: Qt::Unchecked
);
70 const bool enable
= (!info
.requiresNepomuk
&& !info
.requiresIndexer
) ||
71 (info
.requiresNepomuk
&& nepomukRunning
) ||
72 (info
.requiresIndexer
&& indexingEnabled
);
75 item
->setFlags(item
->flags() & ~Qt::ItemIsEnabled
);
79 QVBoxLayout
* layout
= new QVBoxLayout(mainWidget
);
80 layout
->addWidget(header
);
81 layout
->addWidget(m_listWidget
);
82 layout
->addStretch(1);
84 setMainWidget(mainWidget
);
86 const KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"), "AdditionalInfoDialog");
87 restoreDialogSize(dialogConfig
);
89 connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
92 AdditionalInfoDialog::~AdditionalInfoDialog()
94 KConfigGroup
dialogConfig(KSharedConfig::openConfig("dolphinrc"), "AdditionalInfoDialog");
95 saveDialogSize(dialogConfig
, KConfigBase::Persistent
);
98 QList
<QByteArray
> AdditionalInfoDialog::visibleRoles() const
100 return m_visibleRoles
;
103 void AdditionalInfoDialog::slotOk()
105 m_visibleRoles
.clear();
108 const QList
<KFileItemModel::RoleInfo
> rolesInfo
= KFileItemModel::rolesInformation();
109 foreach (const KFileItemModel::RoleInfo
& info
, rolesInfo
) {
110 const QListWidgetItem
* item
= m_listWidget
->item(index
);
111 if (item
->checkState() == Qt::Checked
) {
112 m_visibleRoles
.append(info
.role
);
118 #include "additionalinfodialog.moc"