]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/servicessettingspage.cpp
Provide a basic UI for the "Services" settings dialog. It's open yet whether installi...
[dolphin.git] / src / settings / servicessettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 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 "servicessettingspage.h"
21
22 #include <kdesktopfileactions.h>
23 #include <kicon.h>
24 #include <klocale.h>
25 #include <kservice.h>
26 #include <kservicetypetrader.h>
27 #include <kstandarddirs.h>
28
29 #include <QEvent>
30 #include <QLabel>
31 #include <QListWidget>
32 #include <QVBoxLayout>
33
34 ServicesSettingsPage::ServicesSettingsPage(QWidget* parent) :
35 SettingsPageBase(parent),
36 m_initialized(false),
37 m_servicesList(0)
38 {
39 QVBoxLayout* topLayout = new QVBoxLayout(this);
40
41 QLabel* label = new QLabel(i18nc("@label:textbox",
42 "Configure which services should "
43 "be shown in the context menu."), this);
44
45 m_servicesList = new QListWidget(this);
46 m_servicesList->setSortingEnabled(true);
47 m_servicesList->setSelectionMode(QAbstractItemView::NoSelection);
48
49 topLayout->addWidget(label);
50 topLayout->addWidget(m_servicesList);
51 }
52
53 ServicesSettingsPage::~ServicesSettingsPage()
54 {
55 }
56
57 void ServicesSettingsPage::applySettings()
58 {
59 }
60
61 void ServicesSettingsPage::restoreDefaults()
62 {
63 const int count = m_servicesList->count();
64 for (int i = 0; i < count; ++i) {
65 QListWidgetItem* item = m_servicesList->item(i);
66 item->setCheckState(Qt::Checked);
67 }
68 }
69
70 bool ServicesSettingsPage::event(QEvent* event)
71 {
72 if ((event->type() == QEvent::Polish) && !m_initialized) {
73 QMetaObject::invokeMethod(this, "loadServices", Qt::QueuedConnection);
74 m_initialized = true;
75 }
76 return SettingsPageBase::event(event);
77 }
78
79 void ServicesSettingsPage::loadServices()
80 {
81 const KService::List entries = KServiceTypeTrader::self()->query("KonqPopupMenu/Plugin");
82 foreach (const KSharedPtr<KService>& service, entries) {
83 const QString file = KStandardDirs::locate("services", service->entryPath());
84 const QList<KServiceAction> serviceActions =
85 KDesktopFileActions::userDefinedServices(file, true);
86
87 foreach (const KServiceAction& action, serviceActions) {
88 if (!action.noDisplay() && !action.isSeparator()) {
89 QListWidgetItem* item = new QListWidgetItem(KIcon(action.icon()),
90 action.text(),
91 m_servicesList);
92 item->setCheckState(Qt::Checked);
93 }
94 }
95 }
96 }
97
98 #include "servicessettingspage.moc"