~teejee2008/timeshift/trunk

« back to all changes in this revision

Viewing changes to src/Gtk/ExcludeMessageWindow.vala

  • Committer: Tony George
  • Date: 2016-08-13 04:16:47 UTC
  • Revision ID: tony.george.kol@gmail.com-20160813041647-ivf2g6rszt00xco5
Updated project structure

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ExcludeMessageWindow.vala
 
3
 *
 
4
 * Copyright 2013 Tony George <teejee2008@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
using Gee;
 
26
 
 
27
using TeeJee.Logging;
 
28
using TeeJee.FileSystem;
 
29
using TeeJee.Devices;
 
30
using TeeJee.JsonHelper;
 
31
using TeeJee.ProcessHelper;
 
32
using TeeJee.GtkHelper;
 
33
using TeeJee.System;
 
34
using TeeJee.Misc;
 
35
 
 
36
public class ExcludeMessageWindow : Gtk.Dialog{
 
37
        private Box vbox_main;
 
38
        private Box hbox_action;
 
39
 
 
40
        //exclude
 
41
        private TreeView tv_exclude;
 
42
        private ScrolledWindow sw_exclude;
 
43
        private TreeViewColumn col_exclude;
 
44
        private Label lbl_header_exclude;
 
45
        private Label lbl_exclude;
 
46
        private Label lbl_header_home;
 
47
        private Label lbl_home;
 
48
 
 
49
        //actions
 
50
        private Button btn_ok;
 
51
 
 
52
        public ExcludeMessageWindow () {
 
53
                this.title = _("Excluded Directories");
 
54
        this.window_position = WindowPosition.CENTER_ON_PARENT;
 
55
        this.set_destroy_with_parent (true);
 
56
                this.set_modal (true);
 
57
        this.set_default_size (400, 400);
 
58
 
 
59
        //set app icon
 
60
                try{
 
61
                        this.icon = new Gdk.Pixbuf.from_file (App.share_folder + "/pixmaps/timeshift.png");
 
62
                }
 
63
        catch(Error e){
 
64
                log_error (e.message);
 
65
            }
 
66
 
 
67
            string msg;
 
68
 
 
69
            //vbox_main
 
70
        vbox_main = get_content_area ();
 
71
                vbox_main.margin = 3;
 
72
                vbox_main.spacing = 3;
 
73
 
 
74
                //lbl_header_exclude
 
75
                lbl_header_exclude = new Gtk.Label("<b>" + _("Exclude List") + ":</b>");
 
76
                lbl_header_exclude.xalign = (float) 0.0;
 
77
                lbl_header_exclude.set_use_markup(true);
 
78
                vbox_main.add(lbl_header_exclude);
 
79
 
 
80
                //lbl_exclude
 
81
                lbl_exclude = new Gtk.Label(_("Files matching the following patterns will be excluded") + ":");
 
82
                lbl_exclude.xalign = (float) 0.0;
 
83
                lbl_exclude.set_use_markup(true);
 
84
                vbox_main.add(lbl_exclude);
 
85
 
 
86
                //tv_exclude-----------------------------------------------
 
87
 
 
88
                //tv_exclude
 
89
                tv_exclude = new TreeView();
 
90
                tv_exclude.get_selection().mode = SelectionMode.MULTIPLE;
 
91
                tv_exclude.headers_visible = false;
 
92
                tv_exclude.set_rules_hint (true);
 
93
 
 
94
                //sw_exclude
 
95
                sw_exclude = new ScrolledWindow(null, null);
 
96
                sw_exclude.set_shadow_type (ShadowType.ETCHED_IN);
 
97
                sw_exclude.add (tv_exclude);
 
98
                sw_exclude.expand = true;
 
99
                vbox_main.add(sw_exclude);
 
100
 
 
101
        //col_exclude
 
102
                col_exclude = new TreeViewColumn();
 
103
                col_exclude.title = _("File Pattern");
 
104
                col_exclude.expand = true;
 
105
 
 
106
                CellRendererText cell_exclude_margin = new CellRendererText ();
 
107
                cell_exclude_margin.text = "";
 
108
                col_exclude.pack_start (cell_exclude_margin, false);
 
109
 
 
110
                CellRendererPixbuf cell_exclude_icon = new CellRendererPixbuf ();
 
111
                col_exclude.pack_start (cell_exclude_icon, false);
 
112
                col_exclude.set_attributes(cell_exclude_icon, "pixbuf", 1);
 
113
 
 
114
                CellRendererText cell_exclude_text = new CellRendererText ();
 
115
                col_exclude.pack_start (cell_exclude_text, false);
 
116
                col_exclude.set_cell_data_func (cell_exclude_text, cell_exclude_text_render);
 
117
                cell_exclude_text.foreground = "#222222";
 
118
                tv_exclude.append_column(col_exclude);
 
119
 
 
120
                //lbl_header_home
 
121
                lbl_header_home = new Gtk.Label("<b>" + _("Home Directory") + ":</b>");
 
122
                lbl_header_home.xalign = (float) 0.0;
 
123
                lbl_header_home.set_use_markup(true);
 
124
                lbl_header_home.margin_top = 6;
 
125
                vbox_main.add(lbl_header_home);
 
126
 
 
127
                //lbl_home
 
128
                lbl_home = new Gtk.Label("");
 
129
                lbl_home.xalign = (float) 0.0;
 
130
                lbl_home.set_use_markup(true);
 
131
                lbl_home.wrap = true;
 
132
                vbox_main.add(lbl_home);
 
133
 
 
134
                msg = _("Hidden files and folders are included by default since they contain user-specific configuration files.") + "\n";
 
135
                msg += _("All other files and folders are excluded.") + "\n";
 
136
                lbl_home.label =msg;
 
137
 
 
138
                //Actions ----------------------------------------------
 
139
 
 
140
                //hbox_action
 
141
        hbox_action = (Box) get_action_area ();
 
142
 
 
143
        //btn_ok
 
144
        btn_ok = new Button.from_stock("gtk-ok");
 
145
        hbox_action.add(btn_ok);
 
146
        btn_ok.clicked.connect (btn_ok_clicked);
 
147
 
 
148
                //initialize -----------------------------------------
 
149
 
 
150
                var model = new Gtk.ListStore(2, typeof(string), typeof(Gdk.Pixbuf));
 
151
                tv_exclude.model = model;
 
152
 
 
153
                foreach(string path in App.exclude_list_default){
 
154
                        tv_exclude_add_item(path);
 
155
                }
 
156
        }
 
157
 
 
158
        private void cell_exclude_text_render (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter){
 
159
                string pattern;
 
160
                model.get (iter, 0, out pattern, -1);
 
161
                (cell as Gtk.CellRendererText).text = pattern.has_prefix("+ ") ? pattern[2:pattern.length] : pattern;
 
162
        }
 
163
 
 
164
        private void tv_exclude_add_item(string path){
 
165
                Gdk.Pixbuf pix_exclude = null;
 
166
                Gdk.Pixbuf pix_include = null;
 
167
                Gdk.Pixbuf pix_selected = null;
 
168
 
 
169
                try{
 
170
                        pix_exclude = new Gdk.Pixbuf.from_file (App.share_folder + "/timeshift/images/item-gray.png");
 
171
                        pix_include = new Gdk.Pixbuf.from_file (App.share_folder + "/timeshift/images/item-blue.png");
 
172
                }
 
173
        catch(Error e){
 
174
                log_error (e.message);
 
175
            }
 
176
 
 
177
                TreeIter iter;
 
178
                var model = (Gtk.ListStore) tv_exclude.model;
 
179
                model.append(out iter);
 
180
 
 
181
                if (path.has_prefix("+ ")){
 
182
                        pix_selected = pix_include;
 
183
                }
 
184
                else{
 
185
                        pix_selected = pix_exclude;
 
186
                }
 
187
 
 
188
                model.set (iter, 0, path, 1, pix_selected);
 
189
 
 
190
                Adjustment adj = tv_exclude.get_hadjustment();
 
191
                adj.value = adj.upper;
 
192
        }
 
193
 
 
194
        private void btn_ok_clicked(){
 
195
                this.response(Gtk.ResponseType.OK);
 
196
                return;
 
197
        }
 
198
}