~teejee2008/timeshift/trunk

« back to all changes in this revision

Viewing changes to src/Gtk/AboutWindow.vala

  • Committer: Tony George
  • Date: 2016-10-16 13:42:12 UTC
  • Revision ID: tony.george.kol@gmail.com-20161016134212-ibjsptmgbha7a2mw
Fixed scheduled backups; Initialize display for the scheduled cron task;

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * AboutWindow.vala
3
 
 *
4
 
 * Copyright 2016 Tony George <teejeetech@gmail.com>
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
9
 
 * (at your option) any later version.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 
 * MA 02110-1301, USA.
20
 
 *
21
 
 *
22
 
 */
23
 
 
24
 
using Gtk;
25
 
 
26
 
using TeeJee.Logging;
27
 
using TeeJee.FileSystem;
28
 
using TeeJee.JsonHelper;
29
 
using TeeJee.ProcessHelper;
30
 
using TeeJee.GtkHelper;
31
 
using TeeJee.System;
32
 
using TeeJee.Misc;
33
 
 
34
 
public class AboutWindow : Dialog {
35
 
        private Box vbox_main;
36
 
        private Box vbox_logo;
37
 
        private Box vbox_credits;
38
 
        private Box vbox_lines;
39
 
        private Box hbox_action;
40
 
        private Button btn_credits;
41
 
        private Button btn_close;
42
 
 
43
 
        private Gtk.Image img_logo;
44
 
        private Label lbl_program_name;
45
 
        private Label lbl_version;
46
 
        private Label lbl_comments;
47
 
        private LinkButton lbtn_website;
48
 
        private Label lbl_copyright;
49
 
 
50
 
        private string[] _artists;
51
 
        public string[] artists{
52
 
                get{
53
 
                        return _artists;
54
 
                }
55
 
                set{
56
 
                        _artists = value;
57
 
                }
58
 
        }
59
 
 
60
 
        private string[] _authors;
61
 
        public string[] authors{
62
 
                get{
63
 
                        return _authors;
64
 
                }
65
 
                set{
66
 
                        _authors = value;
67
 
                }
68
 
        }
69
 
 
70
 
        private string[] _contributors;
71
 
        public string[] contributors{
72
 
                get{
73
 
                        return _contributors;
74
 
                }
75
 
                set{
76
 
                        _contributors = value;
77
 
                }
78
 
        }
79
 
        
80
 
        private string _comments = "";
81
 
        public string comments{
82
 
                get{
83
 
                        return _comments;
84
 
                }
85
 
                set{
86
 
                        _comments = value;
87
 
                }
88
 
        }
89
 
 
90
 
        private string _copyright = "";
91
 
        public string copyright{
92
 
                get{
93
 
                        return _copyright;
94
 
                }
95
 
                set{
96
 
                        _copyright = value;
97
 
                }
98
 
        }
99
 
 
100
 
        private string[] _documenters;
101
 
        public string[] documenters{
102
 
                get{
103
 
                        return _documenters;
104
 
                }
105
 
                set{
106
 
                        _documenters = value;
107
 
                }
108
 
        }
109
 
 
110
 
        private string[] _donations;
111
 
        public string[] donations{
112
 
                get{
113
 
                        return _donations;
114
 
                }
115
 
                set{
116
 
                        _donations = value;
117
 
                }
118
 
        }
119
 
 
120
 
        private string _license = "";
121
 
        public string license{
122
 
                get{
123
 
                        return _license;
124
 
                }
125
 
                set{
126
 
                        _license = value;
127
 
                }
128
 
        }
129
 
 
130
 
        private Gdk.Pixbuf _logo;
131
 
        public Gdk.Pixbuf logo{
132
 
                get{
133
 
                        return _logo;
134
 
                }
135
 
                set{
136
 
                        _logo = value;
137
 
                }
138
 
        }
139
 
 
140
 
        private string _program_name = "";
141
 
        public string program_name{
142
 
                get{
143
 
                        return _program_name;
144
 
                }
145
 
                set{
146
 
                        _program_name = value;
147
 
                }
148
 
        }
149
 
 
150
 
        private string[] _translators;
151
 
        public string[] translators{
152
 
                get{
153
 
                        return _translators;
154
 
                }
155
 
                set{
156
 
                        _translators = value;
157
 
                }
158
 
        }
159
 
 
160
 
        private string[] _third_party;
161
 
        public string[] third_party{
162
 
                get{
163
 
                        return _third_party;
164
 
                }
165
 
                set{
166
 
                        _third_party = value;
167
 
                }
168
 
        }
169
 
 
170
 
        private string _version = "";
171
 
        public string version{
172
 
                get{
173
 
                        return _version;
174
 
                }
175
 
                set{
176
 
                        _version = value;
177
 
                }
178
 
        }
179
 
 
180
 
        private string _website = "";
181
 
        public string website{
182
 
                get{
183
 
                        return _website;
184
 
                }
185
 
                set{
186
 
                        _website = value;
187
 
                }
188
 
        }
189
 
 
190
 
        private string _website_label = "";
191
 
        public string website_label{
192
 
                get{
193
 
                        return _website_label;
194
 
                }
195
 
                set{
196
 
                        _website_label = value;
197
 
                }
198
 
        }
199
 
 
200
 
        public AboutWindow() {
201
 
        window_position = WindowPosition.CENTER_ON_PARENT;
202
 
                set_destroy_with_parent (true);
203
 
                set_modal (true);
204
 
        skip_taskbar_hint = false;
205
 
        set_default_size (450, 400);
206
 
 
207
 
            vbox_main = get_content_area();
208
 
                vbox_main.margin = 6;
209
 
                vbox_main.spacing = 6;
210
 
 
211
 
                vbox_logo = new Box(Orientation.VERTICAL,0);
212
 
                vbox_main.add(vbox_logo);
213
 
 
214
 
                vbox_credits = new Box(Orientation.VERTICAL,0);
215
 
                vbox_credits.no_show_all = true;
216
 
                vbox_main.add(vbox_credits);
217
 
 
218
 
                vbox_lines = new Box(Orientation.VERTICAL,0);
219
 
                vbox_lines.margin_top = 10;
220
 
 
221
 
                //logo
222
 
                img_logo = new Gtk.Image();
223
 
                img_logo.margin_top = 6;
224
 
                img_logo.margin_bottom = 6;
225
 
        vbox_logo.add(img_logo);
226
 
 
227
 
                //program_name
228
 
                lbl_program_name = new Label("");
229
 
                lbl_program_name.set_use_markup(true);
230
 
                vbox_logo.add(lbl_program_name);
231
 
 
232
 
                //version
233
 
                lbl_version = new Label("");
234
 
                lbl_version.set_use_markup(true);
235
 
                lbl_version.margin_top = 5;
236
 
                vbox_logo.add(lbl_version);
237
 
 
238
 
                //comments
239
 
                lbl_comments = new Label("");
240
 
                lbl_comments.set_use_markup(true);
241
 
                lbl_comments.margin_top = 10;
242
 
                vbox_logo.add(lbl_comments);
243
 
 
244
 
                //website
245
 
                lbtn_website = new LinkButton("");
246
 
                lbtn_website.margin_top = 5;
247
 
                vbox_logo.add(lbtn_website);
248
 
 
249
 
                lbtn_website.activate_link.connect(()=>{
250
 
                        try{
251
 
                                return Gtk.show_uri(null, lbtn_website.uri, Gdk.CURRENT_TIME);
252
 
                        }
253
 
                        catch(Error e){
254
 
                                return false;
255
 
                        }
256
 
                });
257
 
 
258
 
                //copyright
259
 
                lbl_copyright = new Label("");
260
 
                lbl_copyright.set_use_markup(true);
261
 
                lbl_copyright.margin_top = 5;
262
 
                vbox_logo.add(lbl_copyright);
263
 
 
264
 
                //spacer_bottom
265
 
                var spacer_bottom = new Label("");
266
 
                spacer_bottom.margin_top = 20;
267
 
                vbox_logo.add(spacer_bottom);
268
 
 
269
 
                //scroller
270
 
                var sw_credits = new ScrolledWindow(null, null);
271
 
                sw_credits.set_shadow_type(ShadowType.ETCHED_IN);
272
 
                sw_credits.expand = true;
273
 
 
274
 
                vbox_credits.add(sw_credits);
275
 
                sw_credits.add(vbox_lines);
276
 
 
277
 
                //hbox_commands --------------------------------------------------
278
 
 
279
 
                hbox_action = (Box) get_action_area();
280
 
 
281
 
                //btn_credits
282
 
                btn_credits = new Button.with_label("  " + _("Credits"));
283
 
                btn_credits.set_image (new Image.from_stock ("gtk-about", IconSize.MENU));
284
 
                hbox_action.add(btn_credits);
285
 
 
286
 
        btn_credits.clicked.connect(()=>{
287
 
                        vbox_logo.visible = !(vbox_logo.visible);
288
 
                        vbox_credits.visible = !(vbox_credits.visible);
289
 
 
290
 
                        if ((vbox_credits.visible)&&(!sw_credits.visible)){
291
 
                                sw_credits.show_all();
292
 
                        }
293
 
 
294
 
                        if (vbox_credits.visible){
295
 
                                btn_credits.label = "  " + _("Back");
296
 
                                btn_credits.set_image (new Image.from_stock ("gtk-go-back", IconSize.MENU));
297
 
                        }
298
 
                        else{
299
 
                                btn_credits.label = "  " + _("Credits");
300
 
                                btn_credits.set_image (new Image.from_stock ("gtk-about", IconSize.MENU));
301
 
                        }
302
 
                });
303
 
 
304
 
                //btn_close
305
 
                btn_close = new Button.with_label("  " + _("Close"));
306
 
                btn_close.set_image (new Image.from_stock ("gtk-close", IconSize.MENU));
307
 
                hbox_action.add(btn_close);
308
 
 
309
 
                btn_close.clicked.connect(()=>{ this.destroy(); });
310
 
        }
311
 
 
312
 
        public void initialize() {
313
 
                title = program_name;
314
 
                img_logo.pixbuf = logo.scale_simple(128,128,Gdk.InterpType.HYPER);
315
 
                lbl_program_name.label = "<span size='larger'>%s</span>".printf(program_name);
316
 
                lbl_version.label = "v%s".printf(version);
317
 
                lbl_comments.label = "%s".printf(comments);
318
 
                lbtn_website.uri = website;
319
 
                lbtn_website.label = website_label;
320
 
                //lbl_copyright.label = "<span size='smaller'>%s</span>".printf(copyright);
321
 
                lbl_copyright.label = "<span>%s</span>".printf(copyright);
322
 
 
323
 
                if (authors.length > 0){
324
 
                        add_header("<b>%s</b>\n".printf(_("Authors")));
325
 
                        foreach(string name in authors){
326
 
                                add_line("%s\n".printf(name));
327
 
                        }
328
 
                        add_line("\n");
329
 
                }
330
 
 
331
 
                if (contributors.length > 0){
332
 
                        add_header("<b>%s</b>\n".printf(_("Contributions")));
333
 
                        foreach(string name in contributors){
334
 
                                add_line("%s\n".printf(name));
335
 
                        }
336
 
                        add_line("\n");
337
 
                }
338
 
                
339
 
                if (third_party.length > 0){
340
 
                        add_header("<b>%s</b>\n".printf(_("Third Party Tools")));
341
 
                        foreach(string name in third_party){
342
 
                                add_line("%s\n".printf(name));
343
 
                        }
344
 
                        add_line("\n");
345
 
                }
346
 
 
347
 
                if (artists.length > 0){
348
 
                        add_header("<b>%s</b>\n".printf(_("Artists")));
349
 
                        foreach(string name in artists){
350
 
                                add_line("%s\n".printf(name));
351
 
                        }
352
 
                        add_line("\n");
353
 
                }
354
 
 
355
 
                if (translators.length > 0){
356
 
                        add_header("<b>%s</b>\n".printf(_("Translators")));
357
 
                        foreach(string name in translators){
358
 
                                add_line("%s\n".printf(name));
359
 
                        }
360
 
                        add_line("\n");
361
 
                }
362
 
 
363
 
                if (documenters.length > 0){
364
 
                        add_header("<b>%s</b>\n".printf(_("Documenters")));
365
 
                        foreach(string name in documenters){
366
 
                                add_line("%s\n".printf(name));
367
 
                        }
368
 
                        add_line("\n");
369
 
                }
370
 
 
371
 
                if (donations.length > 0){
372
 
                        add_header("<b>%s</b>\n".printf(_("Donations")));
373
 
                        foreach(string name in donations){
374
 
                                add_line("%s\n".printf(name));
375
 
                        }
376
 
                        add_line("\n");
377
 
                }
378
 
 
379
 
                if (vbox_lines.get_children().length() == 0){
380
 
                        btn_credits.visible = false;
381
 
                }
382
 
        }
383
 
 
384
 
        public void add_line(string text, bool escape_html_chars = true){
385
 
                
386
 
                if (text.split(":").length >= 2){
387
 
                        var link = new LinkButton(escape_html(text.split(":")[0]));
388
 
                        vbox_lines.add(link);
389
 
 
390
 
                        string val = text[text.index_of(":") + 1:text.length];
391
 
                        if (val.contains("@")){
392
 
                                link.uri = "mailto:" + val;
393
 
                        }
394
 
                        else if(val.has_prefix("http://")){
395
 
                                link.uri = val;
396
 
                        }
397
 
                        else{
398
 
                                link.uri = "http://" + val;
399
 
                        }
400
 
 
401
 
                        link.activate_link.connect(()=>{
402
 
                                try{
403
 
                                        return Gtk.show_uri(null, link.uri, Gdk.CURRENT_TIME);
404
 
                                }
405
 
                                catch(Error e){
406
 
                                        return false;
407
 
                                }
408
 
                        });
409
 
                }
410
 
                else{
411
 
                        var txt = text;
412
 
                        if (escape_html_chars){
413
 
                                txt = escape_html(text);
414
 
                        }
415
 
 
416
 
                        var lbl = new Label(txt);
417
 
                        lbl.set_use_markup(true);
418
 
                        lbl.valign = Align.START;
419
 
                        lbl.wrap = true;
420
 
                        lbl.wrap_mode = Pango.WrapMode.WORD;
421
 
                        vbox_lines.add(lbl);
422
 
                }
423
 
        }
424
 
 
425
 
        public void add_header(string text){
426
 
                add_line(text, false);
427
 
        }
428
 
}