Add exclude entries for root user's home dircetory

This commit is contained in:
Tony George 2013-10-14 00:02:18 +05:30
parent 74868e7921
commit ab3de6a1c2
5 changed files with 224 additions and 86 deletions

View File

@ -0,0 +1,191 @@
/*
* ExcludeMessageWindow.vala
*
* Copyright 2013 Tony George <teejee2008@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 Gtk;
using Gee;
using Utility;
public class ExcludeMessageWindow : Gtk.Dialog{
private Box vbox_main;
private Box hbox_action;
//exclude
private TreeView tv_exclude;
private ScrolledWindow sw_exclude;
private TreeViewColumn col_exclude;
private Label lbl_header_exclude;
private Label lbl_exclude;
private Label lbl_header_home;
private Label lbl_home;
//actions
private Button btn_ok;
public ExcludeMessageWindow () {
this.title = _("Excluded Directories");
this.window_position = WindowPosition.CENTER_ON_PARENT;
this.set_destroy_with_parent (true);
this.set_modal (true);
this.set_default_size (400, 400);
//set app icon
try{
this.icon = new Gdk.Pixbuf.from_file (App.share_folder + "/pixmaps/timeshift.png");
}
catch(Error e){
log_error (e.message);
}
string msg;
//vbox_main
vbox_main = get_content_area ();
vbox_main.margin = 3;
vbox_main.spacing = 3;
//lbl_header_exclude
lbl_header_exclude = new Gtk.Label("<b>" + _("Exclude List") + ":</b>");
lbl_header_exclude.xalign = (float) 0.0;
lbl_header_exclude.set_use_markup(true);
vbox_main.add(lbl_header_exclude);
//lbl_exclude
lbl_exclude = new Gtk.Label(_("Files matching the following patterns will be <i>excluded</i>") + ":");
lbl_exclude.xalign = (float) 0.0;
lbl_exclude.set_use_markup(true);
vbox_main.add(lbl_exclude);
//tv_exclude-----------------------------------------------
//tv_exclude
tv_exclude = new TreeView();
tv_exclude.get_selection().mode = SelectionMode.MULTIPLE;
tv_exclude.headers_visible = false;
tv_exclude.set_rules_hint (true);
tv_exclude.sensitive = false;
//tv_exclude.row_activated.connect(tv_exclude_row_activated);
//sw_exclude
sw_exclude = new ScrolledWindow(null, null);
sw_exclude.set_shadow_type (ShadowType.ETCHED_IN);
sw_exclude.add (tv_exclude);
sw_exclude.expand = true;
vbox_main.add(sw_exclude);
//col_exclude
col_exclude = new TreeViewColumn();
col_exclude.title = _("File Pattern");
col_exclude.expand = true;
CellRendererText cell_exclude_margin = new CellRendererText ();
cell_exclude_margin.text = "";
col_exclude.pack_start (cell_exclude_margin, false);
CellRendererPixbuf cell_exclude_icon = new CellRendererPixbuf ();
col_exclude.pack_start (cell_exclude_icon, false);
col_exclude.set_attributes(cell_exclude_icon, "pixbuf", 1);
CellRendererText cell_exclude_text = new CellRendererText ();
col_exclude.pack_start (cell_exclude_text, false);
col_exclude.set_cell_data_func (cell_exclude_text, cell_exclude_text_render);
cell_exclude_text.foreground = "#222222";
tv_exclude.append_column(col_exclude);
//lbl_header_home
lbl_header_home = new Gtk.Label("<b>" + _("Home Directory") + ":</b>");
lbl_header_home.xalign = (float) 0.0;
lbl_header_home.set_use_markup(true);
lbl_header_home.margin_top = 6;
vbox_main.add(lbl_header_home);
//lbl_home
lbl_home = new Gtk.Label("");
lbl_home.xalign = (float) 0.0;
lbl_home.set_use_markup(true);
vbox_main.add(lbl_home);
msg = _("Hidden files and folders are included by default since \nthey contain user-specific configuration files.") + "\n";
msg += _("All other files and folders are excluded.") + "\n";
lbl_home.label =msg;
//Actions ----------------------------------------------
//hbox_action
hbox_action = (Box) get_action_area ();
//btn_ok
btn_ok = new Button.from_stock(Gtk.Stock.OK);
hbox_action.add(btn_ok);
btn_ok.clicked.connect (btn_ok_clicked);
//initialize -----------------------------------------
ListStore model = new ListStore(2, typeof(string), typeof(Gdk.Pixbuf));
tv_exclude.model = model;
foreach(string path in App.exclude_list_default){
tv_exclude_add_item(path);
}
}
private void cell_exclude_text_render (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter){
string pattern;
model.get (iter, 0, out pattern, -1);
(cell as Gtk.CellRendererText).text = pattern.has_prefix("+ ") ? pattern[2:pattern.length] : pattern;
}
private void tv_exclude_add_item(string path){
Gdk.Pixbuf pix_exclude = null;
Gdk.Pixbuf pix_include = null;
Gdk.Pixbuf pix_selected = null;
try{
pix_exclude = new Gdk.Pixbuf.from_file (App.share_folder + "/timeshift/images/item-gray.png");
pix_include = new Gdk.Pixbuf.from_file (App.share_folder + "/timeshift/images/item-blue.png");
}
catch(Error e){
log_error (e.message);
}
TreeIter iter;
ListStore model = (ListStore) tv_exclude.model;
model.append(out iter);
if (path.has_prefix("+ ")){
pix_selected = pix_include;
}
else{
pix_selected = pix_exclude;
}
model.set (iter, 0, path, 1, pix_selected);
Adjustment adj = tv_exclude.get_hadjustment();
adj.value = adj.upper;
}
private void btn_ok_clicked(){
this.response(Gtk.ResponseType.OK);
return;
}
}

View File

@ -259,6 +259,15 @@ public class Main : GLib.Object{
exclude_list_default.add("/var/lock/*");
exclude_list_default.add("/lost+found");
exclude_list_default.add("/timeshift/*");
exclude_list_default.add("/root/.thumbnails");
exclude_list_default.add("/root/.cache");
exclude_list_default.add("/root/.gvfs");
exclude_list_default.add("/root/.mozilla/firefox/*.default/Cache");
exclude_list_default.add("/root/.mozilla/firefox/*.default/OfflineCache");
exclude_list_default.add("/root/.opera/cache");
exclude_list_default.add("/root/.local/share/Trash");
exclude_list_default.add("/home/*/.thumbnails");
exclude_list_default.add("/home/*/.cache");
exclude_list_default.add("/home/*/.gvfs");
@ -266,6 +275,9 @@ public class Main : GLib.Object{
exclude_list_default.add("/home/*/.mozilla/firefox/*.default/OfflineCache");
exclude_list_default.add("/home/*/.opera/cache");
exclude_list_default.add("/home/*/.local/share/Trash");
exclude_list_home.add("+ /root/.**");
exclude_list_home.add("/root/**");
exclude_list_home.add("+ /home/*/.**");
exclude_list_home.add("/home/*/**");

View File

@ -43,7 +43,6 @@ public class RestoreWindow : Gtk.Dialog{
//bootloader
private Label lbl_header_bootloader;
//private CheckButton chk_restore_grub2;
private ComboBox cmb_boot_device;
//exclude
@ -80,7 +79,7 @@ public class RestoreWindow : Gtk.Dialog{
this.window_position = WindowPosition.CENTER_ON_PARENT;
this.set_destroy_with_parent (true);
this.set_modal (true);
this.set_default_size (550, 450);
this.set_default_size (550, 500);
//set app icon
try{
@ -199,18 +198,6 @@ public class RestoreWindow : Gtk.Dialog{
hbox_grub.margin_right = 6;
hbox_grub.margin_bottom = 6;
vbox_target.add (hbox_grub);
/*string grub_msg = _("Re-install GRUB2 bootloader on the target device (recommended)");
//chk_restore_grub2
chk_restore_grub2 = new CheckButton.with_label(_("Re-install GRUB2") + ":");
chk_restore_grub2.active = true;
chk_restore_grub2.set_tooltip_markup(grub_msg);
hbox_grub.add(chk_restore_grub2);
chk_restore_grub2.toggled.connect(()=>{
cmb_boot_device.sensitive = chk_restore_grub2.active;
});*/
//cmb_boot_device
cmb_boot_device = new ComboBox ();
@ -430,10 +417,6 @@ public class RestoreWindow : Gtk.Dialog{
refresh_cmb_boot_device();
btn_reset_exclude_list_clicked();
//chk_restore_grub2.active = true; //keep enabled always
//chk_restore_grub2.sensitive = false; //don't allow user to disable
//cmb_boot_device.sensitive = chk_restore_grub2.active;
}
@ -485,10 +468,9 @@ public class RestoreWindow : Gtk.Dialog{
}
private void cell_exclude_text_render (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter){
string pattern, color;
model.get (iter, 0, out pattern, 2, out color, -1);
string pattern;
model.get (iter, 0, out pattern, -1);
(cell as Gtk.CellRendererText).text = pattern.has_prefix("+ ") ? pattern[2:pattern.length] : pattern;
(cell as Gtk.CellRendererText).foreground = color;
}
private void cell_exclude_text_edited (string path, string new_text) {
@ -577,7 +559,7 @@ public class RestoreWindow : Gtk.Dialog{
}
private void refresh_tv_exclude(){
ListStore model = new ListStore(3, typeof(string), typeof(Gdk.Pixbuf), typeof(string));
ListStore model = new ListStore(2, typeof(string), typeof(Gdk.Pixbuf));
tv_exclude.model = model;
foreach(string path in temp_exclude_list){
@ -589,8 +571,7 @@ public class RestoreWindow : Gtk.Dialog{
Gdk.Pixbuf pix_exclude = null;
Gdk.Pixbuf pix_include = null;
Gdk.Pixbuf pix_selected = null;
string text_color;
try{
pix_exclude = new Gdk.Pixbuf.from_file (App.share_folder + "/timeshift/images/item-gray.png");
pix_include = new Gdk.Pixbuf.from_file (App.share_folder + "/timeshift/images/item-blue.png");
@ -609,42 +590,20 @@ public class RestoreWindow : Gtk.Dialog{
else{
pix_selected = pix_exclude;
}
if (App.exclude_list_default.contains(path)){
text_color = "#0B610B";
}
else{
text_color = "#000000";
}
model.set (iter, 0, path, 1, pix_selected, 2, text_color, -1);
model.set (iter, 0, path, 1, pix_selected, -1);
Adjustment adj = tv_exclude.get_hadjustment();
adj.value = adj.upper;
}
private bool lnk_default_list_activate(){
string msg = "";
msg += "<b>" + _("Exclude List") + ":</b>\n\n";
msg += _("Files matching the following patterns will be <i>excluded</i>") + ":\n\n";
foreach(string path in App.exclude_list_default){
msg += path + "\n";
}
msg += "\n";
msg += "<b>" + _("Home Directory") + ":</b>\n\n";
msg += _("Hidden files and folders are included by default since \nthey contain user-specific configuration files.") + "\n";
msg += _("All other files and folders are excluded.") + "\n";
var dialog = new Gtk.MessageDialog.with_markup(null, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, msg);
dialog.set_title(_("Default Entries"));
dialog.set_default_size (200, -1);
dialog.set_transient_for(this);
dialog.set_modal(true);
//show message window -----------------
var dialog = new ExcludeMessageWindow();
dialog.set_transient_for (this);
dialog.show_all();
dialog.run();
dialog.destroy();
return true;
}

View File

@ -503,10 +503,9 @@ public class SettingsWindow : Gtk.Dialog{
}
private void cell_exclude_text_render (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter){
string pattern, color;
model.get (iter, 0, out pattern, 2, out color, -1);
string pattern;
model.get (iter, 0, out pattern, -1);
(cell as Gtk.CellRendererText).text = pattern.has_prefix("+ ") ? pattern[2:pattern.length] : pattern;
(cell as Gtk.CellRendererText).foreground = color;
}
private void cell_exclude_text_edited (string path, string new_text) {
@ -618,7 +617,7 @@ public class SettingsWindow : Gtk.Dialog{
}
private void refresh_tv_exclude(){
ListStore model = new ListStore(3, typeof(string), typeof(Gdk.Pixbuf), typeof(string));
ListStore model = new ListStore(2, typeof(string), typeof(Gdk.Pixbuf));
tv_exclude.model = model;
foreach(string path in temp_exclude_list){
@ -630,8 +629,7 @@ public class SettingsWindow : Gtk.Dialog{
Gdk.Pixbuf pix_exclude = null;
Gdk.Pixbuf pix_include = null;
Gdk.Pixbuf pix_selected = null;
string text_color;
try{
pix_exclude = new Gdk.Pixbuf.from_file (App.share_folder + "/timeshift/images/item-gray.png");
pix_include = new Gdk.Pixbuf.from_file (App.share_folder + "/timeshift/images/item-blue.png");
@ -650,15 +648,8 @@ public class SettingsWindow : Gtk.Dialog{
else{
pix_selected = pix_exclude;
}
if (App.exclude_list_default.contains(path)){
text_color = "#0B610B";
}
else{
text_color = "#000000";
}
model.set (iter, 0, path, 1, pix_selected, 2, text_color, -1);
model.set (iter, 0, path, 1, pix_selected, -1);
Adjustment adj = tv_exclude.get_hadjustment();
adj.value = adj.upper;
@ -703,27 +694,12 @@ public class SettingsWindow : Gtk.Dialog{
}
private bool lnk_default_list_activate(){
string msg = "";
msg += "<b>" + _("Exclude List") + ":</b>\n\n";
msg += _("Files matching the following patterns will be <i>excluded</i>") + ":\n\n";
foreach(string path in App.exclude_list_default){
msg += path + "\n";
}
msg += "\n";
msg += "<b>" + _("Home Directory") + ":</b>\n\n";
msg += _("Hidden files and folders are included by default since \nthey contain user-specific configuration files.") + "\n";
msg += _("All other files and folders are excluded.") + "\n";
var dialog = new Gtk.MessageDialog.with_markup(null, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, msg);
dialog.set_title(_("Default Entries"));
dialog.set_default_size (200, -1);
dialog.set_transient_for(this);
dialog.set_modal(true);
//show message window -----------------
var dialog = new ExcludeMessageWindow();
dialog.set_transient_for (this);
dialog.show_all();
dialog.run();
dialog.destroy();
return true;
}

View File

@ -8,7 +8,7 @@ man1dir = $(mandir)/man1
CFLAGS = --std=c99
all:
valac -X -D'GETTEXT_PACKAGE="timeshift"' --Xcc="-lm" --thread "Main.vala" "Utility.vala" "MainWindow.vala" "SettingsWindow.vala" "RestoreWindow.vala" -o timeshift --pkg glib-2.0 --pkg gio-unix-2.0 --pkg posix --pkg gtk+-3.0 --pkg gee-1.0 --pkg libsoup-2.4 --pkg json-glib-1.0
valac -X -D'GETTEXT_PACKAGE="timeshift"' --Xcc="-lm" --thread "Main.vala" "Utility.vala" "MainWindow.vala" "SettingsWindow.vala" "RestoreWindow.vala" "ExcludeMessageWindow.vala" -o timeshift --pkg glib-2.0 --pkg gio-unix-2.0 --pkg posix --pkg gtk+-3.0 --pkg gee-1.0 --pkg libsoup-2.4 --pkg json-glib-1.0
clean:
rm -rf *.o timeshift