1
/***************************************************************************
2
* Copyright (C) 2010 by Dario Freddi <drf@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 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
***************************************************************************/
21
#include "runscriptconfig.h"
23
#include <QHBoxLayout>
25
#include <KLocalizedString>
26
#include <KUrlRequester>
28
#include <KIntSpinBox>
29
#include <KPluginFactory>
31
K_PLUGIN_FACTORY(PowerDevilRunScriptConfigFactory, registerPlugin<PowerDevil::BundledActions::RunScriptConfig>(); )
32
K_EXPORT_PLUGIN(PowerDevilRunScriptConfigFactory("powerdevilrunscriptaction_config"))
34
namespace PowerDevil {
35
namespace BundledActions {
37
RunScriptConfig::RunScriptConfig(QObject* parent, const QVariantList&)
38
: ActionConfig(parent)
43
RunScriptConfig::~RunScriptConfig()
48
void RunScriptConfig::save()
50
configGroup().writeEntry("scriptCommand", m_urlRequester->text());
51
configGroup().writeEntry("scriptPhase", m_comboBox->currentIndex());
52
configGroup().writeEntry("idleTime", m_idleTime->value() * 60 * 1000);
57
void RunScriptConfig::load()
59
m_urlRequester->setText(configGroup().readEntry<QString>("scriptCommand", QString()));
60
m_comboBox->setCurrentIndex(configGroup().readEntry<int>("scriptPhase", 0));
61
m_idleTime->setValue((configGroup().readEntry<int>("idleTime", 600000) / 60) / 1000);
64
QList< QPair< QString, QWidget* > > RunScriptConfig::buildUi()
66
QList< QPair< QString, QWidget* > > retlist;
67
m_urlRequester = new KUrlRequester();
68
m_urlRequester->setMode(KFile::File | KFile::LocalOnly | KFile::ExistingOnly);
69
m_urlRequester->setMaximumWidth(300);
70
retlist.append(qMakePair< QString, QWidget* >(i18n("Script"), m_urlRequester));
72
QWidget *tempWidget = new QWidget;
73
QHBoxLayout *hlay = new QHBoxLayout;
74
m_comboBox = new KComboBox;
75
m_idleTime = new KIntSpinBox(0, 180, 1, 0, 0);
76
m_idleTime->setMaximumWidth(150);
77
m_idleTime->setMinimum(1);
78
m_idleTime->setMaximum(360);
79
m_idleTime->setDisabled(true);
80
m_idleTime->setSuffix(i18n(" min"));
81
m_comboBox->addItem(i18n("On Profile Load"));
82
m_comboBox->addItem(i18n("On Profile Unload"));
83
m_comboBox->addItem(i18n("After"));
84
connect(m_comboBox, SIGNAL(currentIndexChanged(QString)),
85
this, SLOT(onIndexChanged(QString)));
87
hlay->addWidget(m_comboBox);
88
hlay->addWidget(m_idleTime);
91
tempWidget->setLayout(hlay);
93
retlist.append(qMakePair< QString, QWidget* >(i18n("Run script"), tempWidget));
95
connect(m_urlRequester, SIGNAL(textChanged(QString)), this, SLOT(setChanged()));
96
connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setChanged()));
97
connect(m_idleTime, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
102
void RunScriptConfig::onIndexChanged(const QString &text)
104
m_idleTime->setEnabled(text == i18n("After"));
110
#include "runscriptconfig.moc"