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 "suspendsessionconfig.h"
23
#include <QHBoxLayout>
25
#include <Solid/PowerManagement>
28
#include <KIntSpinBox>
29
#include <KLocalizedString>
30
#include <KPluginFactory>
32
#include "suspendsession.h"
34
K_PLUGIN_FACTORY(PowerDevilSuspendSessionConfigFactory, registerPlugin<PowerDevil::BundledActions::SuspendSessionConfig>(); )
35
K_EXPORT_PLUGIN(PowerDevilSuspendSessionConfigFactory("powerdevilsuspendsessionaction_config"))
37
namespace PowerDevil {
38
namespace BundledActions {
40
SuspendSessionConfig::SuspendSessionConfig(QObject* parent, const QVariantList&)
41
: ActionConfig(parent)
46
SuspendSessionConfig::~SuspendSessionConfig()
51
void SuspendSessionConfig::save()
53
configGroup().writeEntry< uint >("suspendType", m_comboBox->itemData(m_comboBox->currentIndex()).toUInt());
54
configGroup().writeEntry("idleTime", m_idleTime->value() * 60 * 1000);
59
void SuspendSessionConfig::load()
61
uint suspendType = configGroup().readEntry< uint >("suspendType", 0);
62
m_comboBox->setCurrentIndex(m_comboBox->findData(suspendType));
63
m_idleTime->setValue((configGroup().readEntry<int>("idleTime", 600000) / 60) / 1000);
66
QList< QPair< QString, QWidget* > > SuspendSessionConfig::buildUi()
68
QWidget *tempWidget = new QWidget;
69
QHBoxLayout *hlay = new QHBoxLayout;
70
m_comboBox = new KComboBox;
71
m_idleTime = new KIntSpinBox(0, 180, 1, 0, 0);
72
m_idleTime->setMaximumWidth(150);
73
m_idleTime->setMinimum(1);
74
m_idleTime->setMaximum(360);
75
m_idleTime->setSuffix(i18n(" min"));
77
QSet< Solid::PowerManagement::SleepState > methods = Solid::PowerManagement::supportedSleepStates();
79
if (methods.contains(Solid::PowerManagement::SuspendState)) {
80
m_comboBox->addItem(KIcon("system-suspend"), i18n("Sleep"), (uint)SuspendSession::ToRamMode);
82
if (methods.contains(Solid::PowerManagement::HibernateState)) {
83
m_comboBox->addItem(KIcon("system-suspend-hibernate"), i18n("Hibernate"), (uint)SuspendSession::ToDiskMode);
85
m_comboBox->addItem(KIcon("system-shutdown"), i18n("Shutdown"), (uint)SuspendSession::ShutdownMode);
86
m_comboBox->addItem(KIcon("system-lock-screen"), i18n("Lock screen"), (uint)SuspendSession::LockScreenMode);
88
hlay->addWidget(m_idleTime);
89
hlay->addWidget(m_comboBox);
92
tempWidget->setLayout(hlay);
94
QList< QPair< QString, QWidget* > > retlist;
95
retlist.append(qMakePair< QString, QWidget* >(i18n("After"), tempWidget));
97
connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setChanged()));
98
connect(m_idleTime, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));