bump year
[lxde/liblxqt.git] / lxqtscreensaver.cpp
1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2 * (c)LGPL2+
3 *
4 * LXQt - a lightweight, Qt based, desktop toolset
5 * http://razor-qt.org
6 *
7 * Copyright: 2010-2011 Razor team
8 * Authors:
9 * Petr Vanek <petr@scribus.info>
10 *
11 * This program or library is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20
21 * You should have received a copy of the GNU Lesser General
22 * Public License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301 USA
25 *
26 * END_COMMON_COPYRIGHT_HEADER */
27
28 #include <QProcess>
29 #include "lxqtscreensaver.h"
30 #include "lxqttranslator.h"
31
32 #include <XdgIcon>
33 #include <QMessageBox>
34 #include <QAction>
35
36 using namespace LXQt;
37
38 ScreenSaver::ScreenSaver(QObject * parent)
39 : QObject(parent)
40 {
41 m_xdgProcess = new QProcess(this);
42 connect(m_xdgProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
43 this, SLOT(xdgProcess_finished(int,QProcess::ExitStatus)));
44 }
45
46 QList<QAction*> ScreenSaver::availableActions()
47 {
48 QList<QAction*> ret;
49 QAction * act;
50
51 act = new QAction(XdgIcon::fromTheme("system-lock-screen", "lock"), tr("Lock Screen"), this);
52 connect(act, SIGNAL(triggered()), this, SLOT(lockScreen()));
53 ret.append(act);
54
55 return ret;
56 }
57
58 void ScreenSaver::lockScreen()
59 {
60 m_xdgProcess->start("xdg-screensaver", QStringList() << "lock");
61 }
62
63 void ScreenSaver::xdgProcess_finished(int err, QProcess::ExitStatus status)
64 {
65 // http://portland.freedesktop.org/xdg-utils-1.1.0-rc1/scripts/xdg-screensaver
66
67 if (err == 0)
68 emit activated();
69 else
70 {
71 QMessageBox *box = new QMessageBox;
72 box->setAttribute(Qt::WA_DeleteOnClose);
73 box->setIcon(QMessageBox::Warning);
74
75 if (err == 1)
76 {
77 box->setWindowTitle(tr("Screen Saver Error"));
78 box->setText(tr("An error occurred starting screensaver. "
79 "Syntax error in xdg-screensaver arguments."));
80 }
81 else if (err == 3)
82 {
83 box->setWindowTitle(tr("Screen Saver Activation Error"));
84 box->setText(tr("An error occurred starting screensaver. "
85 "Ensure you have xscreensaver installed and running."));
86 }
87 else if (err == 4)
88 {
89 box->setWindowTitle(tr("Screen Saver Activation Error"));
90 box->setText(tr("An error occurred starting screensaver. "
91 "Action 'activate' failed. "
92 "Ensure you have xscreensaver installed and running."));
93 }
94 else
95 {
96 box->setWindowTitle(tr("Screen Saver Activation Error"));
97 box->setText(tr("An error occurred starting screensaver. "
98 "Unknown error - undocumented return value from xdg-screensaver: %1.")
99 .arg(err));
100 }
101
102 box->exec();
103 }
104
105 emit done();
106 }
107