-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathAppGtk.vala
More file actions
168 lines (133 loc) · 3.94 KB
/
AppGtk.vala
File metadata and controls
168 lines (133 loc) · 3.94 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* AptikGtk.vala
*
* Copyright 2012-2018 Tony George <teejeetech@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
using GLib;
using Gtk;
using Gee;
using Json;
using TeeJee.Logging;
using TeeJee.FileSystem;
using TeeJee.JsonHelper;
using TeeJee.ProcessHelper;
using TeeJee.GtkHelper;
using TeeJee.System;
using TeeJee.Misc;
public Main App;
public const string AppName = "Timeshift-gtk";
public const string AppShortName = "timeshift";
public const string AppVersion = Constants.VERSION;
public const string AppAuthor = "Tony George";
public const string AppAuthorEmail = "teejeetech@gmail.com";
const string GETTEXT_PACKAGE = "";
const string LOCALE_DIR = "/usr/share/locale";
extern void exit(int exit_code);
public class AppGtk : GLib.Object {
public static int main (string[] args) {
set_locale();
if (args.length > 1) {
switch (args[1].down()) {
case "--help":
case "--h":
case "-h":
stdout.printf (help_message ());
return 0;
case "--version":
stdout.printf (version_message ());
return 0;
}
}
Gtk.init(ref args);
GTK_INITIALIZED = true;
init_tmp();
check_if_admin();
App = new Main(args, true);
parse_arguments(args);
App.initialize();
start_application();
App.exit_app();
return 0;
}
private static void set_locale() {
log_debug("setting locale...");
Intl.setlocale(GLib.LocaleCategory.MESSAGES, "timeshift");
Intl.textdomain(GETTEXT_PACKAGE);
Intl.bind_textdomain_codeset(GETTEXT_PACKAGE, "utf-8");
Intl.bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
}
public static bool parse_arguments(string[] args) {
//parse options
for (int k = 1; k < args.length; k++) // Oth arg is app path
{
switch (args[k].down()) {
case "--debug":
LOG_DEBUG = true;
break;
case "--config":
App.cmd_config = args[++k];
break;
default:
//unknown option - show help and exit
log_error(_("Unknown option") + ": %s".printf(args[k]));
log_msg(help_message());
App.exit_app(1);
return false;
}
}
return true;
}
private static string version_message (){
string msg = "%s %s\n".printf( AppName, AppVersion);
return msg;
}
public static string help_message() {
string msg = "\n%s v%s by Tony George (%s)\n".printf(AppName, AppVersion, AppAuthorEmail);
msg += "\n";
msg += _("Syntax") + ": timeshift-gtk [options]\n";
msg += "\n";
msg += _("Options") + ":\n";
msg += "\n";
msg += " --debug " + _("Print debug information") + "\n";
msg += " --h[elp] " + _("Show all options") + "\n";
msg += " --version " + _("Print version number") + "\n";
msg += "\n\n";
msg += "\n%s\n".printf(_("Run 'timeshift' for the command-line version of this tool"));
return msg;
}
public static void check_if_admin(){
if (!user_is_admin()){
var msg = _("Admin access is required to backup and restore system files.") + "\n";
msg += _("Please re-run the application as admin (using 'sudo' or 'su')");
log_error(msg);
string title = _("Admin Access Required");
gtk_messagebox(title, msg, null, true);
exit(1);
}
}
public static void start_application(){
// show main window
var window = new MainWindow ();
window.destroy.connect(Gtk.main_quit);
window.show_all();
// start event loop
Gtk.main();
}
}