]>
cloud.milkyroute.net Git - dolphin.git/blob - src/settings/servicessettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
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 "servicessettingspage.h"
23 #include <kconfiggroup.h>
24 #include <kdesktopfileactions.h>
27 #include <knewstuff2/engine.h>
29 #include <kservicetypetrader.h>
30 #include <kstandarddirs.h>
34 #include <QListWidget>
35 #include <QPushButton>
36 #include <QVBoxLayout>
38 ServicesSettingsPage::ServicesSettingsPage(QWidget
* parent
) :
39 SettingsPageBase(parent
),
43 QVBoxLayout
* topLayout
= new QVBoxLayout(this);
45 QLabel
* label
= new QLabel(i18nc("@label:textbox",
46 "Configure which services should "
47 "be shown in the context menu."), this);
48 label
->setWordWrap(true);
50 m_servicesList
= new QListWidget(this);
51 m_servicesList
->setSortingEnabled(true);
52 m_servicesList
->setSelectionMode(QAbstractItemView::NoSelection
);
53 connect(m_servicesList
, SIGNAL(itemClicked(QListWidgetItem
*)),
54 this, SIGNAL(changed()));
56 QPushButton
* downloadButton
= new QPushButton(i18nc("@action:button", "Download New Services..."));
57 downloadButton
->setIcon(KIcon("get-hot-new-stuff"));
58 connect(downloadButton
, SIGNAL(clicked()), this, SLOT(downloadNewServices()));
60 topLayout
->addWidget(label
);
61 topLayout
->addWidget(m_servicesList
);
62 topLayout
->addWidget(downloadButton
);
65 ServicesSettingsPage::~ServicesSettingsPage()
69 void ServicesSettingsPage::applySettings()
71 KConfig
config("kservicemenurc", KConfig::NoGlobals
);
72 KConfigGroup showGroup
= config
.group("Show");
74 const int count
= m_servicesList
->count();
75 for (int i
= 0; i
< count
; ++i
) {
76 QListWidgetItem
* item
= m_servicesList
->item(i
);
77 const bool show
= (item
->checkState() == Qt::Checked
);
78 const QString service
= item
->data(Qt::UserRole
).toString();
79 showGroup
.writeEntry(service
, show
);
85 void ServicesSettingsPage::restoreDefaults()
87 const int count
= m_servicesList
->count();
88 for (int i
= 0; i
< count
; ++i
) {
89 QListWidgetItem
* item
= m_servicesList
->item(i
);
90 item
->setCheckState(Qt::Checked
);
94 bool ServicesSettingsPage::event(QEvent
* event
)
96 if ((event
->type() == QEvent::Polish
) && !m_initialized
) {
97 QMetaObject::invokeMethod(this, "loadServices", Qt::QueuedConnection
);
100 return SettingsPageBase::event(event
);
103 void ServicesSettingsPage::loadServices()
105 const KConfig
config("kservicemenurc", KConfig::NoGlobals
);
106 const KConfigGroup showGroup
= config
.group("Show");
108 const KService::List entries
= KServiceTypeTrader::self()->query("KonqPopupMenu/Plugin");
109 foreach (const KSharedPtr
<KService
>& service
, entries
) {
110 const QString file
= KStandardDirs::locate("services", service
->entryPath());
111 const QList
<KServiceAction
> serviceActions
=
112 KDesktopFileActions::userDefinedServices(file
, true);
114 foreach (const KServiceAction
& action
, serviceActions
) {
115 const QString service
= action
.name();
116 const bool addService
= !action
.noDisplay()
117 && !action
.isSeparator()
118 && !isInServicesList(service
);
121 QListWidgetItem
* item
= new QListWidgetItem(KIcon(action
.icon()),
124 item
->setData(Qt::UserRole
, service
);
125 const bool show
= showGroup
.readEntry(service
, true);
126 item
->setCheckState(show
? Qt::Checked
: Qt::Unchecked
);
132 void ServicesSettingsPage::downloadNewServices()
134 KNS::Engine
khns(this);
135 khns
.init("servicemenu.knsrc");
136 khns
.downloadDialogModal(this);
140 bool ServicesSettingsPage::isInServicesList(const QString
& service
) const
142 const int count
= m_servicesList
->count();
143 for (int i
= 0; i
< count
; ++i
) {
144 QListWidgetItem
* item
= m_servicesList
->item(i
);
145 if (item
->data(Qt::UserRole
).toString() == service
) {
152 #include "servicessettingspage.moc"