Qt5 support (step 1)
[lxde/liblxqt.git] / lxqtscreensaver.cpp
1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2 * (c)LGPL2+
3 *
4 * Razor - 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 <QtCore/QProcess>
29 #include <QtGui/QMessageBox>
30
31 #include <xdgqt/XdgIcon>
32 #include "lxqtscreensaver.h"
33 #include "lxqttranslator.h"
34
35 using namespace LxQt;
36
37 ScreenSaver::ScreenSaver(QObject * parent)
38 : QObject(parent)
39 {
40 Translator::translateLibrary("liblxqt");
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 QWidget *p = qobject_cast<QWidget*>(parent());
66
67 if (status == QProcess::CrashExit)
68 {
69 QMessageBox::warning(p,
70 tr("Screen Saver Activation Error"),
71 tr("An error occurred starting screensaver. "
72 "xdg-screensaver cannot be started due its crash.")
73 );
74 }
75 else if (err == -2)
76 {
77 QMessageBox::warning(p,
78 tr("Screen Saver Activation Error"),
79 tr("An error occurred starting screensaver. "
80 "xdg-screensaver is not installed correctly.")
81 );
82 }
83 else if (err == -1)
84 {
85 QMessageBox::warning(p,
86 tr("Screen Saver Activation Error"),
87 tr("An error occurred starting screensaver. "
88 "xdg-screensaver cannot be started.")
89 );
90 }
91 else if (err == 0)
92 {
93 emit activated();
94 }
95 else if (err == 1)
96 {
97 QMessageBox::warning(p,
98 tr("Screen Saver Activation Error"),
99 tr("An error occurred starting screensaver. "
100 "Syntax error in xdg-screensaver arguments.")
101 );
102 }
103 else if (err == 3)
104 {
105 QMessageBox::warning(p,
106 tr("Screen Saver Activation Error"),
107 tr("An error occurred starting screensaver. "
108 "Ensure you have xscreensaver installed and running.")
109 );
110 }
111 else if (err == 4)
112 {
113 QMessageBox::warning(p,
114 tr("Screen Saver Activation Error"),
115 tr("An error occurred starting screensaver. "
116 "Action 'activate' failed. "
117 "Ensure you have xscreensaver installed and running.")
118 );
119 }
120 else
121 {
122 QMessageBox::warning(p,
123 tr("Screen Saver Activation Error"),
124 tr("An error occurred starting screensaver. "
125 "Unknown error - undocumented return value from xdg-screensaver=%1.").arg(err)
126 );
127 }
128 }
129