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

« back to all changes in this revision

Viewing changes to powerdevil/daemon/actions/bundled/suspendsessionconfig.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 "suspendsessionconfig.h"
 
22
 
 
23
#include <QHBoxLayout>
 
24
 
 
25
#include <Solid/PowerManagement>
 
26
 
 
27
#include <KComboBox>
 
28
#include <KIntSpinBox>
 
29
#include <KLocalizedString>
 
30
#include <KPluginFactory>
 
31
#include <KIcon>
 
32
#include "suspendsession.h"
 
33
 
 
34
K_PLUGIN_FACTORY(PowerDevilSuspendSessionConfigFactory, registerPlugin<PowerDevil::BundledActions::SuspendSessionConfig>(); )
 
35
K_EXPORT_PLUGIN(PowerDevilSuspendSessionConfigFactory("powerdevilsuspendsessionaction_config"))
 
36
 
 
37
namespace PowerDevil {
 
38
namespace BundledActions {
 
39
 
 
40
SuspendSessionConfig::SuspendSessionConfig(QObject* parent, const QVariantList&)
 
41
        : ActionConfig(parent)
 
42
{
 
43
 
 
44
}
 
45
 
 
46
SuspendSessionConfig::~SuspendSessionConfig()
 
47
{
 
48
 
 
49
}
 
50
 
 
51
void SuspendSessionConfig::save()
 
52
{
 
53
    configGroup().writeEntry< uint >("suspendType", m_comboBox->itemData(m_comboBox->currentIndex()).toUInt());
 
54
    configGroup().writeEntry("idleTime", m_idleTime->value() * 60 * 1000);
 
55
 
 
56
    configGroup().sync();
 
57
}
 
58
 
 
59
void SuspendSessionConfig::load()
 
60
{
 
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);
 
64
}
 
65
 
 
66
QList< QPair< QString, QWidget* > > SuspendSessionConfig::buildUi()
 
67
{
 
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"));
 
76
 
 
77
    QSet< Solid::PowerManagement::SleepState > methods = Solid::PowerManagement::supportedSleepStates();
 
78
 
 
79
    if (methods.contains(Solid::PowerManagement::SuspendState)) {
 
80
        m_comboBox->addItem(KIcon("system-suspend"), i18n("Sleep"), (uint)SuspendSession::ToRamMode);
 
81
    }
 
82
    if (methods.contains(Solid::PowerManagement::HibernateState)) {
 
83
        m_comboBox->addItem(KIcon("system-suspend-hibernate"), i18n("Hibernate"), (uint)SuspendSession::ToDiskMode);
 
84
    }
 
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);
 
87
 
 
88
    hlay->addWidget(m_idleTime);
 
89
    hlay->addWidget(m_comboBox);
 
90
    hlay->addStretch();
 
91
 
 
92
    tempWidget->setLayout(hlay);
 
93
 
 
94
    QList< QPair< QString, QWidget* > > retlist;
 
95
    retlist.append(qMakePair< QString, QWidget* >(i18n("After"), tempWidget));
 
96
 
 
97
    connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setChanged()));
 
98
    connect(m_idleTime, SIGNAL(valueChanged(int)), this, SLOT(setChanged()));
 
99
 
 
100
    return retlist;
 
101
}
 
102
 
 
103
}
 
104
}