not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / krunner / configdialog.cpp
blob0efff857b22ab94b2e649e706acebada4809fb0a
1 /*
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 <QGroupBox>
24 #include <QDialogButtonBox>
25 #include <QPushButton>
26 #include <QRadioButton>
27 #include <QTabWidget>
28 #include <QVBoxLayout>
30 #include <KConfigGroup>
31 #include <KDebug>
32 #include <KGlobal>
33 #include <KPluginInfo>
34 #include <KPluginSelector>
35 #include <KServiceTypeTrader>
37 #include <Plasma/RunnerManager>
39 #include "interfaces/default/interface.h"
40 #include "krunnersettings.h"
41 #include "interfaces/quicksand/qs_dialog.h"
43 KRunnerConfigDialog::KRunnerConfigDialog(Plasma::RunnerManager *manager, QWidget *parent)
44 : KDialog(parent),
45 m_preview(0),
46 m_manager(manager)
48 setButtons(Ok | Cancel);
49 QTabWidget *m_tab = new QTabWidget(this);
50 setMainWidget(m_tab);
52 m_sel = new KPluginSelector(m_tab);
53 m_tab->addTab(m_sel, i18n("Plugins"));
55 QWidget *m_generalSettings = new QWidget(this);
56 QVBoxLayout *genLayout = new QVBoxLayout(m_generalSettings);
59 m_interfaceType = KRunnerSettings::interface();
60 QRadioButton *commandButton = new QRadioButton(i18n("Command oriented"), m_generalSettings);
61 QRadioButton *taskButton = new QRadioButton(i18n("Task oriented"), m_generalSettings);
63 QButtonGroup *displayButtons = new QButtonGroup(m_generalSettings);
64 displayButtons->addButton(commandButton, KRunnerSettings::EnumInterface::CommandOriented);
65 displayButtons->addButton(taskButton, KRunnerSettings::EnumInterface::TaskOriented);
66 connect(displayButtons, SIGNAL(buttonClicked(int)), this, SLOT(setInterface(int)));
68 if (m_interfaceType == KRunnerSettings::EnumInterface::CommandOriented) {
69 commandButton->setChecked(true);
70 } else {
71 taskButton->setChecked(true);
75 QPushButton *previewButton = new QPushButton(i18n("Preview"), m_generalSettings);
76 connect(previewButton, SIGNAL(clicked()), this, SLOT(previewInterface()));
78 genLayout->addWidget(commandButton);
79 genLayout->addWidget(taskButton);
80 genLayout->addWidget(previewButton);
81 genLayout->addStretch();
83 m_tab->addTab(m_generalSettings, i18n("User Interface"));
85 setInitialSize(QSize(400, 500));
86 setWindowTitle(i18n("KRunner Settings"));
88 connect(m_sel, SIGNAL(configCommitted(const QByteArray&)), this, SLOT(updateRunner(const QByteArray&)));
89 connect(this, SIGNAL(okClicked()), this, SLOT(accept()));
91 KService::List offers = KServiceTypeTrader::self()->query("Plasma/Runner");
92 QList<KPluginInfo> effectinfos = KPluginInfo::fromServices(offers);
93 m_sel->addPlugins(effectinfos, KPluginSelector::ReadConfigFile, i18n("Available Features"), QString(), KSharedConfig::openConfig("krunnerrc"));
95 KConfigGroup config(KGlobal::config(), "ConfigurationDialog");
96 restoreDialogSize(config);
99 void KRunnerConfigDialog::previewInterface()
101 delete m_preview;
102 switch (m_interfaceType) {
103 case KRunnerSettings::EnumInterface::CommandOriented:
104 m_preview = new Interface(m_manager, this);
105 break;
106 default:
107 m_preview = new QsDialog(m_manager, this);
108 break;
110 m_preview->show();
113 void KRunnerConfigDialog::setInterface(int type)
115 m_interfaceType = type;
118 void KRunnerConfigDialog::updateRunner(const QByteArray &name)
120 Plasma::AbstractRunner *runner = m_manager->runner(name);
121 //Update runner if runner is loaded
122 if (runner) {
123 runner->reloadConfiguration();
127 KRunnerConfigDialog::~KRunnerConfigDialog()
129 KConfigGroup config(KGlobal::config(), "ConfigurationDialog");
130 saveDialogSize(config);
131 KGlobal::config()->sync();
134 void KRunnerConfigDialog::accept()
136 m_sel->save();
137 m_manager->reloadConfiguration();
138 KRunnerSettings::setInterface(m_interfaceType);
139 KRunnerSettings::self()->writeConfig();
140 close();
143 #include "configdialog.moc"