2
* ExcludeMessageWindow.vala
4
* Copyright 2013 Tony George <teejee2008@gmail.com>
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.
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.
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,
28
using TeeJee.FileSystem;
30
using TeeJee.JsonHelper;
31
using TeeJee.ProcessHelper;
32
using TeeJee.GtkHelper;
36
public class ExcludeMessageWindow : Gtk.Dialog{
37
private Box vbox_main;
38
private Box hbox_action;
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;
50
private Button btn_ok;
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);
61
this.icon = new Gdk.Pixbuf.from_file (App.share_folder + "/pixmaps/timeshift.png");
64
log_error (e.message);
70
vbox_main = get_content_area ();
72
vbox_main.spacing = 3;
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);
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);
86
//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);
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);
102
col_exclude = new TreeViewColumn();
103
col_exclude.title = _("File Pattern");
104
col_exclude.expand = true;
106
CellRendererText cell_exclude_margin = new CellRendererText ();
107
cell_exclude_margin.text = "";
108
col_exclude.pack_start (cell_exclude_margin, false);
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);
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);
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);
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);
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";
138
//Actions ----------------------------------------------
141
hbox_action = (Box) get_action_area ();
144
btn_ok = new Button.from_stock("gtk-ok");
145
hbox_action.add(btn_ok);
146
btn_ok.clicked.connect (btn_ok_clicked);
148
//initialize -----------------------------------------
150
var model = new Gtk.ListStore(2, typeof(string), typeof(Gdk.Pixbuf));
151
tv_exclude.model = model;
153
foreach(string path in App.exclude_list_default){
154
tv_exclude_add_item(path);
158
private void cell_exclude_text_render (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter){
160
model.get (iter, 0, out pattern, -1);
161
(cell as Gtk.CellRendererText).text = pattern.has_prefix("+ ") ? pattern[2:pattern.length] : pattern;
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;
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");
174
log_error (e.message);
178
var model = (Gtk.ListStore) tv_exclude.model;
179
model.append(out iter);
181
if (path.has_prefix("+ ")){
182
pix_selected = pix_include;
185
pix_selected = pix_exclude;
188
model.set (iter, 0, path, 1, pix_selected);
190
Adjustment adj = tv_exclude.get_hadjustment();
191
adj.value = adj.upper;
194
private void btn_ok_clicked(){
195
this.response(Gtk.ResponseType.OK);