~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to powerdevil/daemon/actions/bundled/runscriptconfig.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2010 by Dario Freddi <drf@kde.org>                      *
 
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
 
 
21
#include "runscriptconfig.h"
 
22
 
 
23
#include <QHBoxLayout>
 
24
 
 
25
#include <KLocalizedString>
 
26
#include <KUrlRequester>
 
27
#include <KComboBox>
 
28
#include <KIntSpinBox>
 
29
#include <KPluginFactory>
 
30
 
 
31
K_PLUGIN_FACTORY(PowerDevilRunScriptConfigFactory, registerPlugin<PowerDevil::BundledActions::RunScriptConfig>(); )
 
32
K_EXPORT_PLUGIN(PowerDevilRunScriptConfigFactory("powerdevilrunscriptaction_config"))
 
33
 
 
34
namespace PowerDevil {
 
35
namespace BundledActions {
 
36
 
 
37
RunScriptConfig::RunScriptConfig(QObject* parent, const QVariantList&)
 
38
    : ActionConfig(parent)
 
39
{
 
40
 
 
41
}
 
42
 
 
43
RunScriptConfig::~RunScriptConfig()
 
44
{
 
45
 
 
46
}
 
47
 
 
48
void RunScriptConfig::save()
 
49
{
 
50
    configGroup().writeEntry("scriptCommand", m_urlRequester->text());
 
51
    configGroup().writeEntry("scriptPhase", m_comboBox->currentIndex());
 
52
    configGroup().writeEntry("idleTime", m_idleTime->value() * 60 * 1000);
 
53
 
 
54
    configGroup().sync();
 
55
}
 
56
 
 
57
void RunScriptConfig::load()
 
58
{
 
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);
 
62
}
 
63
 
 
64
QList< QPair< QString, QWidget* > > RunScriptConfig::buildUi()
 
65
{
 
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));
 
71
 
 
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)));
 
86
 
 
87
    hlay->addWidget(m_comboBox);
 
88
    hlay->addWidget(m_idleTime);
 
89
    hlay->addStretch();
 
90
 
 
91
    tempWidget->setLayout(hlay);
 
92
 
 
93
    retlist.append(qMakePair< QString, QWidget* >(i18n("Run script"), tempWidget));
 
94
 
 
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()));
 
98
 
 
99
    return retlist;
 
100
}
 
101
 
 
102
void RunScriptConfig::onIndexChanged(const QString &text)
 
103
{
 
104
    m_idleTime->setEnabled(text == i18n("After"));
 
105
}
 
106
 
 
107
}
 
108
}
 
109
 
 
110
#include "runscriptconfig.moc"