This repository has been archived by the owner on Dec 17, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
/
main.cpp
116 lines (99 loc) · 3.5 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
*
* Razor - a lightweight, Qt based, desktop toolset
* http://razor-qt.org
*
* Copyright: 2010-2011 Razor team
* Authors:
* Alexander Sokoloff <sokoloff.a@gmail.com>
*
* This program or library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* END_COMMON_COPYRIGHT_HEADER */
#include <razorqt/razorapplication.h>
#include "dialog.h"
#include "razortranslate.h"
#include <QtCore/QTextStream>
#include <razorqt/razorpower/razorpower.h>
#include <QtCore/QDebug>
void help()
{
QTextStream out(stdout);
out << "Usage: razor-power" << endl;
out << " or: razor-power --check ACTION" << endl;
out << " or: razor-power ACTION" << endl;
out << "The first variant starts the GUI interface." << endl;
out << "The second variant checks is the action can be performed." << endl;
out << "The third variant executes the ACTION without the GUI." << endl;
out << endl;
out << "Actions:" << endl;
out << " logout Close the current user session." << endl;
out << " hibernate Hibernate the computer" << endl;
out << " reboot Reboot the computer" << endl;
out << " shutdown, halt Shutdown the computer" << endl;
out << " suspend Suspend the computer" << endl;
}
int main(int argc, char *argv[])
{
RazorApplication app(argc, argv);
bool check=false;
bool actionSet=false;
RazorPower::Action action;
QStringList args = app.arguments();
for (int i=1; i < args.count(); ++i)
{
QString arg = args.at(i);
if (arg == "--help" || arg == "-h" )
{
help();
return 0;
}
if (arg == "--check" )
{
check = true;
continue;
}
arg = arg.toLower();
if (arg == "logout" ) { action = RazorPower::PowerLogout; actionSet = true; continue; }
if (arg == "hibernate" ) { action = RazorPower::PowerHibernate; actionSet = true; continue; }
if (arg == "reboot" ) { action = RazorPower::PowerReboot; actionSet = true; continue; }
if (arg == "shutdown" ) { action = RazorPower::PowerShutdown; actionSet = true; continue; }
if (arg == "halt" ) { action = RazorPower::PowerShutdown; actionSet = true; continue; }
if (arg == "suspend" ) { action = RazorPower::PowerSuspend; actionSet = true; continue; }
qWarning() << "Unknown option: " << args.at(i);
help();
return 2;
}
if (actionSet)
{
RazorPower power;
bool res;
if (check)
res = power.canAction(action);
else
res = power.doAction(action);
if (res)
return 0;
else
return 1;
}
{
TRANSLATE_APP;
Dialog w;
w.show();
return app.exec();
}
}