~teejee2008/timeshift/trunk

« back to all changes in this revision

Viewing changes to src/Utility/CustomMessageDialog.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
 * CustomMessageDialog.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
 
 
25
using Gtk;
 
26
using Gee;
 
27
 
 
28
using TeeJee.Logging;
 
29
using TeeJee.FileSystem;
 
30
using TeeJee.JsonHelper;
 
31
using TeeJee.ProcessHelper;
 
32
using TeeJee.GtkHelper;
 
33
using TeeJee.System;
 
34
using TeeJee.Misc;
 
35
 
 
36
public class CustomMessageDialog : Gtk.Dialog {
 
37
        private Gtk.Box vbox_main;
 
38
        private Gtk.Label lbl_msg;
 
39
        private Gtk.ScrolledWindow sw_msg;
 
40
        private Gtk.Button btn_ok;
 
41
        private Gtk.Button btn_cancel;
 
42
        private Gtk.Button btn_yes;
 
43
        private Gtk.Button btn_no;
 
44
 
 
45
        private string msg_title;
 
46
        private string msg_body;
 
47
        private Gtk.MessageType msg_type;
 
48
        private Gtk.ButtonsType buttons_type;
 
49
        
 
50
        public CustomMessageDialog(
 
51
                string _msg_title, string _msg_body,
 
52
                Gtk.MessageType _msg_type, Window? parent, Gtk.ButtonsType _buttons_type) {
 
53
                        
 
54
                set_transient_for(parent);
 
55
                set_modal(true);
 
56
 
 
57
                msg_title = _msg_title;
 
58
                msg_body = _msg_body;
 
59
                msg_type = _msg_type;
 
60
                buttons_type = _buttons_type;
 
61
                
 
62
                init_window();
 
63
 
 
64
                show_all();
 
65
 
 
66
                if (lbl_msg.get_allocated_height() > 400){
 
67
                        sw_msg.vscrollbar_policy = PolicyType.AUTOMATIC;
 
68
                        sw_msg.set_size_request(-1,400);
 
69
                        lbl_msg.margin_right = 25;
 
70
                }
 
71
                else{
 
72
                        sw_msg.vscrollbar_policy = PolicyType.NEVER;
 
73
                }
 
74
        }
 
75
 
 
76
        public void init_window () {
 
77
                title = "";
 
78
                
 
79
                window_position = WindowPosition.CENTER_ON_PARENT;
 
80
                icon = get_app_icon(16);
 
81
                resizable = false;
 
82
                deletable = false;
 
83
                skip_taskbar_hint = true;
 
84
                skip_pager_hint = true;
 
85
                
 
86
                //vbox_main
 
87
                vbox_main = get_content_area () as Gtk.Box;
 
88
                vbox_main.margin = 6;
 
89
 
 
90
                //hbox_contents
 
91
                var hbox_contents = new Box (Orientation.HORIZONTAL, 6);
 
92
                hbox_contents.margin = 6;
 
93
                vbox_main.add (hbox_contents);
 
94
 
 
95
                string icon_name = "gtk-dialog-info";
 
96
                
 
97
                switch(msg_type){
 
98
                case Gtk.MessageType.INFO:
 
99
                        icon_name = "gtk-dialog-info";
 
100
                        break;
 
101
                case Gtk.MessageType.WARNING:
 
102
                        icon_name = "gtk-dialog-warning";
 
103
                        break;
 
104
                case Gtk.MessageType.QUESTION:
 
105
                        icon_name = "gtk-dialog-question";
 
106
                        break;
 
107
                case Gtk.MessageType.ERROR:
 
108
                        icon_name = "gtk-dialog-error";
 
109
                        break;
 
110
                }
 
111
 
 
112
                // image ----------------
 
113
                
 
114
                var img = new Image.from_icon_name(icon_name, Gtk.IconSize.DIALOG);
 
115
                img.margin_right = 12;
 
116
                hbox_contents.add(img);
 
117
                
 
118
                // label -------------------
 
119
 
 
120
                var text = "<span weight=\"bold\" size=\"x-large\">%s</span>\n\n%s".printf(
 
121
                        escape_html(msg_title),
 
122
                        escape_html(msg_body));
 
123
                lbl_msg = new Gtk.Label(text);
 
124
                lbl_msg.xalign = (float) 0.0;
 
125
                lbl_msg.max_width_chars = 70;
 
126
                lbl_msg.wrap = true;
 
127
                lbl_msg.wrap_mode = Pango.WrapMode.WORD_CHAR;
 
128
                lbl_msg.use_markup = true;
 
129
 
 
130
                //sw_msg
 
131
                sw_msg = new ScrolledWindow(null, null);
 
132
                //sw_msg.set_shadow_type (ShadowType.ETCHED_IN);
 
133
                sw_msg.add (lbl_msg);
 
134
                sw_msg.expand = true;
 
135
                sw_msg.hscrollbar_policy = PolicyType.NEVER;
 
136
                sw_msg.vscrollbar_policy = PolicyType.AUTOMATIC;
 
137
                //sw_msg.set_size_request();
 
138
                hbox_contents.add(sw_msg);
 
139
 
 
140
                // actions -------------------------
 
141
                
 
142
                var action_area = get_action_area () as Gtk.Box;
 
143
                action_area.margin_top = 12;
 
144
 
 
145
                switch(buttons_type){
 
146
                case Gtk.ButtonsType.OK:
 
147
                        btn_ok = (Gtk.Button) add_button ("_Ok", Gtk.ResponseType.OK);
 
148
                        break;
 
149
                case Gtk.ButtonsType.OK_CANCEL:
 
150
                        btn_ok = (Gtk.Button) add_button ("_Ok", Gtk.ResponseType.OK);
 
151
                        btn_cancel = (Gtk.Button) add_button ("_Cancel", Gtk.ResponseType.CANCEL);
 
152
                        break;
 
153
                case Gtk.ButtonsType.YES_NO:
 
154
                        btn_yes = (Gtk.Button) add_button ("_Yes", Gtk.ResponseType.YES);
 
155
                        btn_no = (Gtk.Button) add_button ("_No", Gtk.ResponseType.NO);
 
156
                        break;
 
157
                        
 
158
                }
 
159
        }
 
160
}
 
161
 
 
162