2
* Copyright 2008 Ryan P. Bitanga <ryan.bitanga@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Library General Public License as
6
* published by the Free Software Foundation; either version 2, 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 Library 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 "configdialog.h"
22
#include <QButtonGroup>
23
#include <QDialogButtonBox>
25
#include <QDialogButtonBox>
26
#include <QPushButton>
27
#include <QRadioButton>
29
#include <QVBoxLayout>
31
#include <KConfigGroup>
34
#include <KPluginInfo>
35
#include <KPluginSelector>
36
#include <KServiceTypeTrader>
38
#include <Plasma/RunnerManager>
39
#include <Plasma/Theme>
41
#include "interfaces/default/interface.h"
42
#include "krunnersettings.h"
43
#include "interfaces/quicksand/qs_dialog.h"
45
KRunnerConfigWidget::KRunnerConfigWidget(Plasma::RunnerManager *manager, QWidget *parent)
50
m_tabWidget = new KTabWidget(this);
51
m_sel = new KPluginSelector(m_tabWidget);
52
m_tabWidget->addTab(m_sel, i18n("Plugins"));
54
QWidget *m_generalSettings = new QWidget(m_tabWidget);
55
//QVBoxLayout *genLayout = new QVBoxLayout(m_generalSettings);
57
m_interfaceType = KRunnerSettings::interface();
58
m_uiOptions.setupUi(m_generalSettings);
61
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(syncPalette()));
63
QButtonGroup *positionButtons = new QButtonGroup(m_generalSettings);
64
positionButtons->addButton(m_uiOptions.topEdgeButton);
65
positionButtons->addButton(m_uiOptions.freeFloatingButton);
66
m_uiOptions.freeFloatingButton->setChecked(KRunnerSettings::freeFloating());
68
QButtonGroup *displayButtons = new QButtonGroup(m_generalSettings);
69
connect(displayButtons, SIGNAL(buttonClicked(int)), this, SLOT(setInterface(int)));
70
displayButtons->addButton(m_uiOptions.commandButton, KRunnerSettings::EnumInterface::CommandOriented);
71
displayButtons->addButton(m_uiOptions.taskButton, KRunnerSettings::EnumInterface::TaskOriented);
73
if (m_interfaceType == KRunnerSettings::EnumInterface::CommandOriented) {
74
m_uiOptions.commandButton->setChecked(true);
76
m_uiOptions.taskButton->setChecked(true);
79
connect(m_uiOptions.previewButton, SIGNAL(clicked()), this, SLOT(previewInterface()));
81
m_tabWidget->addTab(m_generalSettings, i18n("User Interface"));
83
connect(m_sel, SIGNAL(configCommitted(const QByteArray&)), this, SLOT(updateRunner(const QByteArray&)));
85
m_sel->addPlugins(Plasma::RunnerManager::listRunnerInfo(),
86
KPluginSelector::ReadConfigFile,
87
i18n("Available Features"), QString(),
88
KSharedConfig::openConfig(QLatin1String( "krunnerrc" )));
90
m_buttons = new QDialogButtonBox(this);
91
m_buttons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel);
92
connect(m_buttons, SIGNAL(clicked(QAbstractButton*)), this, SLOT(save(QAbstractButton*)));
93
connect(m_buttons, SIGNAL(rejected()), this, SIGNAL(finished()));
95
QVBoxLayout *topLayout = new QVBoxLayout(this);
96
topLayout->addWidget(m_tabWidget);
97
topLayout->addWidget(m_buttons);
100
KRunnerConfigWidget::~KRunnerConfigWidget()
104
void KRunnerConfigWidget::syncPalette()
106
QColor color = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
107
QPalette p = palette();
108
p.setColor(QPalette::Normal, QPalette::WindowText, color);
109
p.setColor(QPalette::Inactive, QPalette::WindowText, color);
110
color.setAlphaF(0.6);
111
p.setColor(QPalette::Disabled, QPalette::WindowText, color);
113
p.setColor(QPalette::Normal, QPalette::Link, Plasma::Theme::defaultTheme()->color(Plasma::Theme::LinkColor));
114
p.setColor(QPalette::Normal, QPalette::LinkVisited, Plasma::Theme::defaultTheme()->color(Plasma::Theme::VisitedLinkColor));
118
void KRunnerConfigWidget::previewInterface()
121
switch (m_interfaceType) {
122
case KRunnerSettings::EnumInterface::CommandOriented:
123
m_preview = new Interface(m_manager, this);
126
m_preview = new QsDialog(m_manager, this);
130
m_preview->setFreeFloating(m_uiOptions.freeFloatingButton->isChecked());
134
void KRunnerConfigWidget::setInterface(int type)
136
m_interfaceType = type;
139
void KRunnerConfigWidget::updateRunner(const QByteArray &name)
141
Plasma::AbstractRunner *runner = m_manager->runner(QString::fromLatin1( name ));
142
//Update runner if runner is loaded
144
runner->reloadConfiguration();
148
void KRunnerConfigWidget::save(QAbstractButton *pushed)
150
if (m_buttons->buttonRole(pushed) == QDialogButtonBox::ApplyRole ||
151
m_buttons->buttonRole(pushed) == QDialogButtonBox::AcceptRole) {
153
m_manager->reloadConfiguration();
154
KRunnerSettings::setInterface(m_interfaceType);
155
KRunnerSettings::setFreeFloating(m_uiOptions.freeFloatingButton->isChecked());
156
KRunnerSettings::self()->writeConfig();
158
if (m_buttons->buttonRole(pushed) == QDialogButtonBox::AcceptRole) {
164
#include "configdialog.moc"