2
* Copyright (C) 2007 Ivan Cukic <ivan.cukic(at)kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2,
6
* or (at your option) any later version, as published by the Free
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
15
* License 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.
20
#include "LancelotAppletConfig.h"
21
#include "lancelot_interface.h"
23
#include <KIconDialog>
25
void LancelotAppletConfig::setupUi(QWidget * widget)
27
Ui::LancelotAppletConfigBase::setupUi(widget);
29
qbgIcons = new QButtonGroup(widget);
30
qbgIcons->addButton(radioShowCategories);
31
qbgIcons->addButton(radioShowMenuIconOnly);
33
qbgMenuActivation = new QButtonGroup(widget);
34
qbgMenuActivation->addButton(radioActivationHover);
35
qbgMenuActivation->addButton(radioActivationClick);
37
connect(radioShowCategories, SIGNAL(clicked()),
38
this, SLOT(updateCard()));
39
connect(radioShowMenuIconOnly, SIGNAL(clicked()),
40
this, SLOT(updateCard()));
41
connect(listIcons, SIGNAL(itemClicked(QListWidgetItem *)),
42
this, SLOT(iconItemClicked()));
44
org::kde::lancelot::App lancelot(
45
"org.kde.lancelot", "/Lancelot",
46
QDBusConnection::sessionBus()
49
QDBusReply<QStringList> replyIDs = lancelot.sectionIDs();
50
QDBusReply<QStringList> replyNames = lancelot.sectionNames();
51
QDBusReply<QStringList> replyIcons = lancelot.sectionIcons();
54
QListWidgetItem * item;
55
item = new QListWidgetItem(
56
KIcon("lancelot"), i18n("Lancelot"), listIcons);
57
icons["lancelot"] = item;
58
item = new QListWidgetItem(
59
KIcon("kde"), i18n("KDE Logo"), listIcons);
61
item = new QListWidgetItem(
62
KIcon("start-here"), i18n("Start here"), listIcons);
63
icons["start-here"] = item;
64
item = new QListWidgetItem(
65
KIcon("unknown"), i18n("Custom"), listIcons);
66
icons["custom"] = item;
69
if (!replyIDs.isValid() || !replyNames.isValid() || !replyIcons.isValid()) {
70
// Error connecting to Lancelot via d-bus
71
// setFailedToLaunch(true);
75
for (int i = 0; i < replyIDs.value().size(); i++) {
76
QListWidgetItem * item = new QListWidgetItem(
77
KIcon(replyIcons.value().at(i)), replyNames.value().at(i));
78
item->setData(Qt::UserRole, replyIDs.value().at(i));
79
categories[replyIDs.value().at(i)] = item;
80
listSections->addItem(item);
81
item->setSelected(true);
85
void LancelotAppletConfig::iconItemClicked()
87
if (!icons.contains("custom")) {
91
if (icons["custom"]->isSelected()) {
92
QString newCustomIcon = KIconDialog::getIcon();
93
if (!newCustomIcon.isEmpty()) {
94
customIcon = newCustomIcon;
95
icons["custom"]->setIcon(KIcon(customIcon));
100
bool LancelotAppletConfig::showCategory(const QString & id) const
102
return categories.value(id)->isSelected();
105
bool LancelotAppletConfig::showCategories() const
107
return radioShowCategories->isChecked();
110
bool LancelotAppletConfig::clickActivation() const
112
return radioActivationClick->isChecked();
115
QStringList LancelotAppletConfig::showingCategories(bool value) const
118
foreach (QListWidgetItem * item, categories) {
119
if (item->isSelected() == value) {
120
result << item->data(Qt::UserRole).toString();
126
QString LancelotAppletConfig::icon() const
128
foreach (const QString & id, icons.keys()) //krazy:exclude=foreach
130
QListWidgetItem * item = icons[id];
131
if (item->isSelected()) {
132
if (id == "custom") {
141
void LancelotAppletConfig::setShowAllCategories(bool value)
143
foreach (QListWidgetItem * item, categories) //krazy:exclude=foreach
145
item->setSelected(value);
149
void LancelotAppletConfig::setShowingCategories(QStringList ids, bool value)
151
foreach (const QString & id, categories.keys()) //krazy:exclude=foreach
153
QListWidgetItem * item = categories[id];
154
item->setSelected((ids.contains(id)) ? value : (!value));
158
void LancelotAppletConfig::setShowCategory(const QString & id, bool value)
160
categories.value(id)->setSelected(value);
163
void LancelotAppletConfig::setShowCategories(bool value)
166
radioShowCategories->click();
168
radioShowMenuIconOnly->click();
172
void LancelotAppletConfig::setClickActivation(bool value)
175
radioActivationClick->click();
177
radioActivationHover->click();
181
void LancelotAppletConfig::setIcon(const QString & icon)
184
foreach (const QString &id, icons.keys()) //krazy:exclude=foreach
186
QListWidgetItem * item = icons[id];
187
item->setSelected(id == icon);
193
if (found || !icons.contains("custom")) {
198
icons["custom"]->setSelected(true);
199
icons["custom"]->setIcon(KIcon(customIcon));
202
void LancelotAppletConfig::updateCard()
204
if (radioShowCategories->isChecked()) {
205
stackedAppletButtons->setCurrentWidget(pageCategoriesChoose);
207
stackedAppletButtons->setCurrentWidget(pageAppletIconsChoose);