RazorAutostartEntry => LxQt::AutostartEntry
[lxde/liblxqt.git] / screensaver.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 <qtxdg/xdgicon.h>
32 #include "screensaver.h"
33 #include "libtranslate.h"
34
35 ScreenSaver::ScreenSaver(QObject * parent)
36 : QObject(parent)
37 {
38 LxQt::libTranslate("librazorqt");
39 m_xdgProcess = new QProcess(this);
40 connect(m_xdgProcess, SIGNAL(finished(int,QProcess::ExitStatus)),
41 this, SLOT(xdgProcess_finished(int,QProcess::ExitStatus)));
42 }
43
44 QList<QAction*> ScreenSaver::availableActions()
45 {
46 QList<QAction*> ret;
47 QAction * act;
48
49 act = new QAction(XdgIcon::fromTheme("system-lock-screen", "lock"), tr("Lock Screen"), this);
50 connect(act, SIGNAL(triggered()), this, SLOT(lockScreen()));
51 ret.append(act);
52
53 return ret;
54 }
55
56 void ScreenSaver::lockScreen()
57 {
58 m_xdgProcess->start("xdg-screensaver", QStringList() << "lock");
59 }
60
61 void ScreenSaver::xdgProcess_finished(int err, QProcess::ExitStatus status)
62 {
63 QWidget *p = qobject_cast<QWidget*>(parent());
64
65 if (status == QProcess::CrashExit)
66 {
67 QMessageBox::warning(p,
68 tr("Screen Saver Activation Error"),
69 tr("An error occurred starting screensaver. "
70 "xdg-screensaver cannot be started due its crash.")
71 );
72 }
73 else if (err == -2)
74 {
75 QMessageBox::warning(p,
76 tr("Screen Saver Activation Error"),
77 tr("An error occurred starting screensaver. "
78 "xdg-screensaver is not installed correctly.")
79 );
80 }
81 else if (err == -1)
82 {
83 QMessageBox::warning(p,
84 tr("Screen Saver Activation Error"),
85 tr("An error occurred starting screensaver. "
86 "xdg-screensaver cannot be started.")
87 );
88 }
89 else if (err == 0)
90 {
91 emit activated();
92 }
93 else if (err == 1)
94 {
95 QMessageBox::warning(p,
96 tr("Screen Saver Activation Error"),
97 tr("An error occurred starting screensaver. "
98 "Syntax error in xdg-screensaver arguments.")
99 );
100 }
101 else if (err == 3)
102 {
103 QMessageBox::warning(p,
104 tr("Screen Saver Activation Error"),
105 tr("An error occurred starting screensaver. "
106 "Ensure you have xscreensaver installed and running.")
107 );
108 }
109 else if (err == 4)
110 {
111 QMessageBox::warning(p,
112 tr("Screen Saver Activation Error"),
113 tr("An error occurred starting screensaver. "
114 "Action 'activate' failed. "
115 "Ensure you have xscreensaver installed and running.")
116 );
117 }
118 else
119 {
120 QMessageBox::warning(p,
121 tr("Screen Saver Activation Error"),
122 tr("An error occurred starting screensaver. "
123 "Unknown error - undocumented return value from xdg-screensaver=%1.").arg(err)
124 );
125 }
126 }
127