From dcdc0df27114e9d704f99a5fbc69882b355c9766 Mon Sep 17 00:00:00 2001 From: ygerlach <100762533+ygerlach@users.noreply.github.com> Date: Sat, 7 Dec 2024 12:52:24 +0100 Subject: [PATCH 1/8] remove dependency to which --- src/Core/Main.vala | 12 +++----- src/Utility/OSDNotify.vala | 12 +++----- src/Utility/TeeJee.Process.vala | 28 ++----------------- src/Utility/TeeJee.System.vala | 49 ++++++++++++++++----------------- 4 files changed, 34 insertions(+), 67 deletions(-) diff --git a/src/Core/Main.vala b/src/Core/Main.vala index 519a4862..d02bc4ea 100644 --- a/src/Core/Main.vala +++ b/src/Core/Main.vala @@ -311,7 +311,7 @@ public class Main : GLib.Object{ } else{ //timeshift is running from system directory - update app_path - this.app_path = get_cmd_path("timeshift"); + this.app_path = Environment.find_program_in_path("timeshift"); } // initialize lists ----------------- @@ -347,17 +347,13 @@ public class Main : GLib.Object{ } public bool check_dependencies(out string msg){ - - msg = ""; - log_debug("Main: check_dependencies()"); - string[] dependencies = { "rsync","/sbin/blkid","df","mount","umount","fuser","crontab","cp","rm","touch","ln","sync","which", "run-parts"}; //"shutdown","chroot", + string[] dependencies = { "rsync","/sbin/blkid","df","mount","umount","fuser","crontab","cp","rm","touch","ln","sync", "run-parts"}; //"shutdown","chroot", - string path; + msg = ""; foreach(string cmd_tool in dependencies){ - path = get_cmd_path (cmd_tool); - if ((path == null) || (path.length == 0)){ + if(!cmd_exists(cmd_tool)) { msg += " * " + cmd_tool + "\n"; } } diff --git a/src/Utility/OSDNotify.vala b/src/Utility/OSDNotify.vala index 8d9a7773..e557309e 100644 --- a/src/Utility/OSDNotify.vala +++ b/src/Utility/OSDNotify.vala @@ -56,16 +56,15 @@ public class OSDNotify : GLib.Object { long seconds = 9999; if (dt_last_notification != null){ - DateTime dt_end = new DateTime.now_local(); TimeSpan elapsed = dt_end.difference(dt_last_notification); seconds = (long)(elapsed * 1.0 / TimeSpan.SECOND); } if (seconds > NOTIFICATION_INTERVAL){ - - if (cmd_exists("notify-send")){ - + + if (is_supported()){ + string desktop_entry = "timeshift-gtk"; string hint = "string:desktop-entry:%s".printf(desktop_entry); @@ -82,9 +81,6 @@ public class OSDNotify : GLib.Object { } public static bool is_supported(){ - - string path = get_cmd_path("notify-send"); - - return (path != null) && (path.length > 0); + return cmd_exists("notify-send"); } } diff --git a/src/Utility/TeeJee.Process.vala b/src/Utility/TeeJee.Process.vala index 72375ee7..1bdc1f13 100644 --- a/src/Utility/TeeJee.Process.vala +++ b/src/Utility/TeeJee.Process.vala @@ -259,32 +259,10 @@ namespace TeeJee.ProcessHelper{ } // find process ------------------------------- - - // dep: which - public string get_cmd_path (string cmd_tool){ - - /* Returns the full path to a command */ - try { - int exitCode; - string stdout, stderr; - Process.spawn_command_line_sync("which " + cmd_tool, out stdout, out stderr, out exitCode); - return stdout; - } - catch (Error e){ - log_error (e.message); - return ""; - } - } - - public bool cmd_exists(string cmd_tool){ - string path = get_cmd_path (cmd_tool); - if ((path == null) || (path.length == 0)){ - return false; - } - else{ - return true; - } + public static bool cmd_exists(string cmd_tool){ + string? path = Environment.find_program_in_path(cmd_tool); + return (path != null) && (path.length > 0); } // return the name of the executable of a given pid or self if pid is <= 0 diff --git a/src/Utility/TeeJee.System.vala b/src/Utility/TeeJee.System.vala index 38e19d1b..adab1d73 100644 --- a/src/Utility/TeeJee.System.vala +++ b/src/Utility/TeeJee.System.vala @@ -164,9 +164,8 @@ namespace TeeJee.System{ // open ----------------------------- - public bool xdg_open (string file, string user = ""){ - string path = get_cmd_path ("xdg-open"); - if ((path != null) && (path != "")){ + public static bool xdg_open (string file, string user = ""){ + if (cmd_exists("xdg-open")){ string cmd = "xdg-open '%s'".printf(escape_single_quote(file)); if (user.length > 0){ cmd = "pkexec --user %s env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY ".printf(user) + cmd; @@ -189,38 +188,36 @@ namespace TeeJee.System{ We will first try using xdg-open and then check for specific file managers if it fails. */ - string path; - int status; - - if (xdg_open_try_first){ + bool xdgAvailable = cmd_exists("xdg-open"); + string escaped_dir_path = escape_single_quote(dir_path); + int status = -1; + + if (xdg_open_try_first && xdgAvailable){ //try using xdg-open - path = get_cmd_path ("xdg-open"); - if ((path != null)&&(path != "")){ - string cmd = "xdg-open '%s'".printf(escape_single_quote(dir_path)); - status = exec_script_async (cmd); - return (status == 0); - } + string cmd = "xdg-open '%s'".printf(escaped_dir_path); + status = exec_script_async (cmd); + return (status == 0); } foreach(string app_name in new string[]{ "nemo", "nautilus", "thunar", "io.elementary.files", "pantheon-files", "marlin", "dolphin" }){ - - path = get_cmd_path (app_name); - if ((path != null)&&(path != "")){ - string cmd = "%s '%s'".printf(app_name, escape_single_quote(dir_path)); - status = exec_script_async (cmd); - return (status == 0); + if(!cmd_exists(app_name)) { + continue; + } + + string cmd = "%s '%s'".printf(app_name, escaped_dir_path); + status = exec_script_async (cmd); + + if(status == 0) { + return true; } } - if (xdg_open_try_first == false){ + if (!xdg_open_try_first && xdgAvailable){ //try using xdg-open - path = get_cmd_path ("xdg-open"); - if ((path != null)&&(path != "")){ - string cmd = "xdg-open '%s'".printf(escape_single_quote(dir_path)); - status = exec_script_async (cmd); - return (status == 0); - } + string cmd = "xdg-open '%s'".printf(escaped_dir_path); + status = exec_script_async (cmd); + return (status == 0); } return false; From 2672bdb83f3a12c456dd1193fe363cafe75c7398 Mon Sep 17 00:00:00 2001 From: ygerlach <100762533+ygerlach@users.noreply.github.com> Date: Sat, 7 Dec 2024 13:07:34 +0100 Subject: [PATCH 2/8] remove unused code --- src/Gtk/BootOptionsWindow.vala | 3 -- src/Gtk/ExcludeBox.vala | 59 +--------------------------------- src/Gtk/MainWindow.vala | 23 ------------- src/Gtk/MiscBox.vala | 3 -- src/Gtk/RestoreExcludeBox.vala | 5 --- src/Gtk/RsyncLogBox.vala | 44 ------------------------- src/Gtk/UsersBox.vala | 29 ----------------- src/Utility/TeeJee.Misc.vala | 15 --------- 8 files changed, 1 insertion(+), 180 deletions(-) diff --git a/src/Gtk/BootOptionsWindow.vala b/src/Gtk/BootOptionsWindow.vala index 94d213c0..7ecff892 100644 --- a/src/Gtk/BootOptionsWindow.vala +++ b/src/Gtk/BootOptionsWindow.vala @@ -35,12 +35,9 @@ using TeeJee.Misc; class BootOptionsWindow : Gtk.Window{ private Gtk.Box vbox_main; - private Gtk.ButtonBox bbox_action; private BootOptionsBox boot_options_box; private uint tmr_init; - private int def_width = 450; - private int def_height = 500; public BootOptionsWindow() { diff --git a/src/Gtk/ExcludeBox.vala b/src/Gtk/ExcludeBox.vala index c93c5fee..cc5aebc6 100644 --- a/src/Gtk/ExcludeBox.vala +++ b/src/Gtk/ExcludeBox.vala @@ -370,44 +370,6 @@ class ExcludeBox : Gtk.Box{ save_changes(); } - private void add_folder_contents_clicked(){ - - var list = browse_folder(); - - if (list.length() > 0){ - foreach(string item in list){ - - string pattern = item; - - if (!pattern.has_suffix("/**")){ - pattern = "%s/**".printf(pattern); - } - - /* - NOTE: - - + /** will include the directory along with the contents - + / will include only the directory without the contents - - /** will exclude the directory contents but include the empty directory - / will exclude the directory along with the contents - */ - - if (!App.exclude_list_user.contains(pattern)){ - App.exclude_list_user.add(pattern); - treeview_add_item(treeview, pattern); - log_debug("contents: %s".printf(pattern)); - Main.first_snapshot_size = 0; //re-calculate - } - else{ - log_debug("exclude_list_user contains: %s".printf(pattern)); - } - } - } - - save_changes(); - } - private SList browse_files(){ var list = new SList(); @@ -506,25 +468,6 @@ class ExcludeBox : Gtk.Box{ model.set (iter, 3, !include); } - private void cell_exclude_text_edited(string path, string new_text) { - - string old_pattern; - string new_pattern; - - TreeIter iter; - var model = (Gtk.ListStore) treeview.model; - model.get_iter_from_string (out iter, path); - model.get (iter, 0, out old_pattern, -1); - - if (old_pattern.has_prefix("+ ")){ - new_pattern = "+ " + new_text; - } - else{ - new_pattern = new_text; - } - model.set (iter, 0, new_pattern); - } - public void save_changes(){ App.exclude_list_user.clear(); @@ -540,7 +483,7 @@ class ExcludeBox : Gtk.Box{ if (!App.exclude_list_user.contains(pattern) && !App.exclude_list_default.contains(pattern) && !App.exclude_list_home.contains(pattern)){ - + App.exclude_list_user.add(pattern); } diff --git a/src/Gtk/MainWindow.vala b/src/Gtk/MainWindow.vala index 4dcf74c3..f4ab1ff7 100644 --- a/src/Gtk/MainWindow.vala +++ b/src/Gtk/MainWindow.vala @@ -405,19 +405,6 @@ class MainWindow : Gtk.Window{ return menu_item; } - - private Gtk.MenuItem create_menu_item_separator(){ - - var menu_item = new Gtk.MenuItem(); - menu_item.sensitive = false; - - var box = new Gtk.Box(Orientation.HORIZONTAL, 3); - menu_item.add(box); - - box.add(new Gtk.Separator(Gtk.Orientation.HORIZONTAL)); - - return menu_item; - } private bool refresh_all(){ @@ -748,16 +735,6 @@ class MainWindow : Gtk.Window{ restore(); } - private void btn_clone_clicked(){ - - if (check_if_deletion_running()){ - return; - } - - App.mirror_system = true; - restore(); - } - private bool check_if_deletion_running(){ if (App.thread_delete_running){ diff --git a/src/Gtk/MiscBox.vala b/src/Gtk/MiscBox.vala index 9f4798a1..b652324b 100644 --- a/src/Gtk/MiscBox.vala +++ b/src/Gtk/MiscBox.vala @@ -131,9 +131,6 @@ class MiscBox : Gtk.Box{ bool selected = combo.get_active_iter(out iter_active); if (!selected){ return; } - TreeIter iter_combo; - var store = (Gtk.ListStore) combo.model; - string txt; model.get (iter_active, 0, out txt, -1); diff --git a/src/Gtk/RestoreExcludeBox.vala b/src/Gtk/RestoreExcludeBox.vala index 630dd920..467b2025 100644 --- a/src/Gtk/RestoreExcludeBox.vala +++ b/src/Gtk/RestoreExcludeBox.vala @@ -131,9 +131,4 @@ class RestoreExcludeBox : Gtk.Box{ chk_web.toggled(); chk_torrent.toggled(); } - - public bool show_all_apps(){ - - return chk_other.active; - } } diff --git a/src/Gtk/RsyncLogBox.vala b/src/Gtk/RsyncLogBox.vala index 79979d5f..08d6f1fe 100644 --- a/src/Gtk/RsyncLogBox.vala +++ b/src/Gtk/RsyncLogBox.vala @@ -667,48 +667,4 @@ public class RsyncLogBox : Gtk.Box { return (item.file_status == status_filter); } } - - private void exclude_selected_items(){ - var list = new Gee.ArrayList(); - foreach(var pattern in App.exclude_list_user){ - list.add(pattern); - } - App.exclude_list_user.clear(); - - // TODO: medium: exclude selected items: not working - - // add include list - TreeIter iter; - var store = (Gtk.ListStore) treeview.model; - bool iterExists = store.get_iter_first (out iter); - while (iterExists) { - FileItem item; - store.get (iter, 0, out item); - - string pattern = item.file_path; - - if (item.file_type == FileType.DIRECTORY){ - pattern = "%s/***".printf(pattern); - } - else{ - //pattern = "%s/***".printf(pattern); - } - - if (!App.exclude_list_user.contains(pattern) - && !App.exclude_list_default.contains(pattern) - && !App.exclude_list_home.contains(pattern)){ - - list.add(pattern); - } - - iterExists = store.iter_next (ref iter); - } - - App.exclude_list_user = list; - - log_debug("exclude_selected_items()"); - foreach(var item in App.exclude_list_user){ - log_debug(item); - } - } } diff --git a/src/Gtk/UsersBox.vala b/src/Gtk/UsersBox.vala index 902a29ac..be549c07 100644 --- a/src/Gtk/UsersBox.vala +++ b/src/Gtk/UsersBox.vala @@ -427,33 +427,4 @@ class UsersBox : Gtk.Box{ exclude_box.refresh_treeview(); } - - public void save_changes(){ - - //App.exclude_list_user.clear(); - - // add include patterns from treeview - /*TreeIter iter; - var store = (Gtk.ListStore) treeview.model; - bool iterExists = store.get_iter_first (out iter); - while (iterExists) { - string pattern; - store.get(iter, 0, out pattern); - - if (!App.exclude_list_user.contains(pattern) - && !App.exclude_list_default.contains(pattern) - && !App.exclude_list_home.contains(pattern)){ - - App.exclude_list_user.add(pattern); - } - - iterExists = store.iter_next(ref iter); - }*/ - - log_debug("save_changes(): exclude_list_user:"); - foreach(var item in App.exclude_list_user){ - log_debug(item); - } - log_debug(""); - } } diff --git a/src/Utility/TeeJee.Misc.vala b/src/Utility/TeeJee.Misc.vala index 3b9573e2..29fe66f7 100644 --- a/src/Utility/TeeJee.Misc.vala +++ b/src/Utility/TeeJee.Misc.vala @@ -107,19 +107,4 @@ namespace TeeJee.Misc { return random; } - - internal string regex_replace(string expression, string text, string replacement){ - - try - { - Regex? regex = null; - regex = new Regex(expression, 0); - return regex.replace(text, text.length, 0, replacement); - } - catch (Error e) - { - log_error (e.message); - return text; - } - } } From 904233c42a0791caa55968fb3e538c45350d614c Mon Sep 17 00:00:00 2001 From: ygerlach <100762533+ygerlach@users.noreply.github.com> Date: Sat, 7 Dec 2024 13:32:24 +0100 Subject: [PATCH 3/8] remove unused functions and mark the others correctly --- src/Utility/GtkHelper.vala | 82 ++++++++++---------------------------- 1 file changed, 20 insertions(+), 62 deletions(-) diff --git a/src/Utility/GtkHelper.vala b/src/Utility/GtkHelper.vala index ba21dabb..627c244c 100644 --- a/src/Utility/GtkHelper.vala +++ b/src/Utility/GtkHelper.vala @@ -182,8 +182,8 @@ namespace TeeJee.GtkHelper{ // utility ------------------ // add_notebook - private Gtk.Notebook add_notebook(Gtk.Box box, bool show_tabs = true, bool show_border = true){ - + public static Gtk.Notebook add_notebook(Gtk.Box box, bool show_tabs = true, bool show_border = true){ + // notebook var book = new Gtk.Notebook(); book.margin = 0; @@ -191,13 +191,13 @@ namespace TeeJee.GtkHelper{ book.show_border = show_border; box.pack_start(book, true, true, 0); - + return book; } // add_treeview - private Gtk.TreeView add_treeview(Gtk.Box box, Gtk.SelectionMode selection_mode = Gtk.SelectionMode.SINGLE){ - + public static Gtk.TreeView add_treeview(Gtk.Box box, Gtk.SelectionMode selection_mode = Gtk.SelectionMode.SINGLE){ + // TreeView var treeview = new TreeView(); treeview.get_selection().mode = selection_mode; @@ -215,39 +215,24 @@ namespace TeeJee.GtkHelper{ } // add_column_text - private Gtk.TreeViewColumn add_column_text(Gtk.TreeView treeview, string title, out Gtk.CellRendererText cell){ + public static Gtk.TreeViewColumn add_column_text(Gtk.TreeView treeview, string title, out Gtk.CellRendererText cell){ // TreeViewColumn var col = new Gtk.TreeViewColumn(); col.title = title; - + cell = new Gtk.CellRendererText(); cell.xalign = (float) 0.0; col.pack_start (cell, false); treeview.append_column(col); - - return col; - } - - // add_column_icon - private Gtk.TreeViewColumn add_column_icon(Gtk.TreeView treeview, string title, out Gtk.CellRendererPixbuf cell){ - - // TreeViewColumn - var col = new Gtk.TreeViewColumn(); - col.title = title; - - cell = new Gtk.CellRendererPixbuf(); - cell.xpad = 2; - col.pack_start (cell, false); - treeview.append_column(col); return col; } // add_column_icon_radio_text - private Gtk.TreeViewColumn add_column_icon_radio_text(Gtk.TreeView treeview, string title, + public static Gtk.TreeViewColumn add_column_icon_radio_text(Gtk.TreeView treeview, string title, out Gtk.CellRendererPixbuf cell_pix, out Gtk.CellRendererToggle cell_radio, out Gtk.CellRendererText cell_text){ - + // TreeViewColumn var col = new Gtk.TreeViewColumn(); col.title = title; @@ -271,7 +256,7 @@ namespace TeeJee.GtkHelper{ } // add_label_scrolled - private Gtk.Label add_label_scrolled(Gtk.Box box, string text, bool show_border = false, bool wrap = false, int ellipsize_chars = 40){ + public static Gtk.Label add_label_scrolled(Gtk.Box box, string text, bool show_border = false, bool wrap = false, int ellipsize_chars = 40){ // ScrolledWindow var scroll = new Gtk.ScrolledWindow(null, null); @@ -322,54 +307,27 @@ namespace TeeJee.GtkHelper{ return label; } - private string format_text(string text, bool bold = false, bool italic = false, bool large = false){ - + public static string format_text(string text, bool bold = false, bool italic = false, bool large = false){ + string msg = "%s".printf( (bold ? " weight=\"bold\"" : ""), (italic ? " style=\"italic\"" : ""), (large ? " size=\"x-large\"" : ""), escape_html(text)); - + return msg; } // add_label_header - private Gtk.Label add_label_header(Gtk.Box box, string text, bool large_heading = false){ - + public static Gtk.Label add_label_header(Gtk.Box box, string text, bool large_heading = false){ + var label = add_label(box, escape_html(text), true, false, large_heading); label.margin_bottom = 12; return label; } - // add_radio - private Gtk.RadioButton add_radio(Gtk.Box box, string text, Gtk.RadioButton? another_radio_in_group){ - - Gtk.RadioButton radio = null; - - if (another_radio_in_group == null){ - radio = new Gtk.RadioButton(null); - } - else{ - radio = new Gtk.RadioButton.from_widget(another_radio_in_group); - } - - radio.label = text; - - box.add(radio); - - foreach(var child in radio.get_children()){ - if (child is Gtk.Label){ - var label = (Gtk.Label) child; - label.use_markup = true; - break; - } - } - - return radio; - } - // add_checkbox - private Gtk.CheckButton add_checkbox(Gtk.Box box, string text){ + public static Gtk.CheckButton add_checkbox(Gtk.Box box, string text){ var chk = new Gtk.CheckButton.with_label(text); chk.label = text; @@ -393,7 +351,7 @@ namespace TeeJee.GtkHelper{ } // add_spin - private Gtk.SpinButton add_spin(Gtk.Box box, double min, double max, double val, int digits = 0, double step = 1, double step_page = 1){ + public static Gtk.SpinButton add_spin(Gtk.Box box, double min, double max, double val, int digits = 0, double step = 1, double step_page = 1){ var adj = new Gtk.Adjustment(val, min, max, step, step_page, 0); var spin = new Gtk.SpinButton(adj, step, digits); @@ -410,8 +368,8 @@ namespace TeeJee.GtkHelper{ } // add_button - private Gtk.Button add_button(Gtk.Box box, string text, string tooltip, Gtk.SizeGroup? size_group, Gtk.Image? icon = null){ - + public static Gtk.Button add_button(Gtk.Box box, string text, string tooltip, Gtk.SizeGroup? size_group, Gtk.Image? icon = null){ + var button = new Gtk.Button(); box.add(button); @@ -430,7 +388,7 @@ namespace TeeJee.GtkHelper{ return button; } - public Gtk.ButtonBox add_button_box(Gtk.Container box, Gtk.Orientation orientation = Gtk.Orientation.HORIZONTAL, + public static Gtk.ButtonBox add_button_box(Gtk.Container box, Gtk.Orientation orientation = Gtk.Orientation.HORIZONTAL, Gtk.ButtonBoxStyle layout = Gtk.ButtonBoxStyle.CENTER, int spacing = 6){ var bbox = new Gtk.ButtonBox(orientation); From f05e497605d2eb56890bfca1d205caf8e4ac495a Mon Sep 17 00:00:00 2001 From: ygerlach <100762533+ygerlach@users.noreply.github.com> Date: Sat, 7 Dec 2024 13:40:16 +0100 Subject: [PATCH 4/8] add cases for other ButtonTypes --- src/Utility/Gtk/CustomMessageDialog.vala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Utility/Gtk/CustomMessageDialog.vala b/src/Utility/Gtk/CustomMessageDialog.vala index 2407de6d..3ae18d87 100644 --- a/src/Utility/Gtk/CustomMessageDialog.vala +++ b/src/Utility/Gtk/CustomMessageDialog.vala @@ -143,10 +143,19 @@ public class CustomMessageDialog : Gtk.Dialog { // actions ------------------------- switch(buttons_type){ + case Gtk.ButtonsType.NONE: break; case Gtk.ButtonsType.OK: btn_ok = (Gtk.Button) add_button (_("OK"), Gtk.ResponseType.OK); btn_ok.grab_focus(); break; + case Gtk.ButtonsType.CLOSE: + btn_cancel = (Gtk.Button) add_button (_("Close"), Gtk.ResponseType.CLOSE); + btn_cancel.grab_focus(); + break; + case Gtk.ButtonsType.CANCEL: + btn_cancel = (Gtk.Button) add_button (_("Cancel"), Gtk.ResponseType.CANCEL); + btn_cancel.grab_focus(); + break; case Gtk.ButtonsType.OK_CANCEL: btn_ok = (Gtk.Button) add_button (_("OK"), Gtk.ResponseType.OK); btn_cancel = (Gtk.Button) add_button (_("Cancel"), Gtk.ResponseType.CANCEL); @@ -157,7 +166,6 @@ public class CustomMessageDialog : Gtk.Dialog { btn_no = (Gtk.Button) add_button (_("No"), Gtk.ResponseType.NO); btn_yes.grab_focus(); break; - } } } From 233060b933bc9c4d63e2d788be77432f9c280a9e Mon Sep 17 00:00:00 2001 From: ygerlach <100762533+ygerlach@users.noreply.github.com> Date: Sat, 7 Dec 2024 13:40:41 +0100 Subject: [PATCH 5/8] simplyfy calling of CustomMessageDialog --- src/Gtk/MainWindow.vala | 4 +--- src/Gtk/RestoreWindow.vala | 7 ++----- src/Utility/GtkHelper.vala | 20 ++------------------ 3 files changed, 5 insertions(+), 26 deletions(-) diff --git a/src/Gtk/MainWindow.vala b/src/Gtk/MainWindow.vala index f4ab1ff7..5ef5519b 100644 --- a/src/Gtk/MainWindow.vala +++ b/src/Gtk/MainWindow.vala @@ -450,9 +450,7 @@ class MainWindow : Gtk.Window{ var msg = _("Select another device?"); var type = Gtk.MessageType.ERROR; - var buttons_type = Gtk.ButtonsType.YES_NO; - - var dlg = new CustomMessageDialog(title, msg, type, this, buttons_type); + var dlg = new CustomMessageDialog(title, msg, type, this, Gtk.ButtonsType.YES_NO); var response = dlg.run(); dlg.destroy(); diff --git a/src/Gtk/RestoreWindow.vala b/src/Gtk/RestoreWindow.vala index ab418de7..b88f4bd2 100644 --- a/src/Gtk/RestoreWindow.vala +++ b/src/Gtk/RestoreWindow.vala @@ -230,11 +230,8 @@ class RestoreWindow : Gtk.Window{ var title = _("Cancel restore?"); var msg = _("Cancelling the restore process will leave the target system in an inconsistent state. The system may fail to boot or you may run into various issues. After cancelling, you need to restore another snapshot, to bring the system to a consistent state. Click Yes to confirm."); - - var type = Gtk.MessageType.ERROR; - var buttons_type = Gtk.ButtonsType.YES_NO; - - var dlg = new CustomMessageDialog(title, msg, type, this, buttons_type); + + var dlg = new CustomMessageDialog(title, msg, Gtk.MessageType.ERROR, this, Gtk.ButtonsType.YES_NO); var response = dlg.run(); dlg.destroy(); diff --git a/src/Utility/GtkHelper.vala b/src/Utility/GtkHelper.vala index 627c244c..fe0f2a3b 100644 --- a/src/Utility/GtkHelper.vala +++ b/src/Utility/GtkHelper.vala @@ -43,27 +43,11 @@ namespace TeeJee.GtkHelper{ gtk_do_events (); } - public void gtk_messagebox(string title, string message, Gtk.Window? parent_win, bool is_error = false){ + public static void gtk_messagebox(string title, string message, Gtk.Window? parent_win, bool is_error = false){ /* Shows a simple message box */ - var type = Gtk.MessageType.INFO; - if (is_error){ - type = Gtk.MessageType.ERROR; - } - else{ - type = Gtk.MessageType.INFO; - } - - /*var dlg = new Gtk.MessageDialog.with_markup(null, Gtk.DialogFlags.MODAL, type, Gtk.ButtonsType.OK, message); - dlg.title = title; - dlg.set_default_size (200, -1); - if (parent_win != null){ - dlg.set_transient_for(parent_win); - dlg.set_modal(true); - } - dlg.run(); - dlg.destroy();*/ + Gtk.MessageType type = is_error ? Gtk.MessageType.ERROR : Gtk.MessageType.INFO; var dlg = new CustomMessageDialog(title,message,type,parent_win, Gtk.ButtonsType.OK); dlg.run(); From a7582021105d9788af7dd69a868d368d6b70c818 Mon Sep 17 00:00:00 2001 From: ygerlach <100762533+ygerlach@users.noreply.github.com> Date: Sat, 7 Dec 2024 14:54:20 +0100 Subject: [PATCH 6/8] remove dependency of chmod --- src/Utility/CronTab.vala | 2 +- src/Utility/TeeJee.FileSystem.vala | 7 ------- src/Utility/TeeJee.Process.vala | 6 +++--- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/Utility/CronTab.vala b/src/Utility/CronTab.vala index 282a92ca..f05eda76 100644 --- a/src/Utility/CronTab.vala +++ b/src/Utility/CronTab.vala @@ -307,7 +307,7 @@ public class CronTab : GLib.Object { file_write(file_path, sh); chown(file_path, "root", "root"); - chmod(file_path, "644"); + Posix.chmod(file_path, 0644); log_msg(_("Added cron task") + ": %s".printf(file_path)); diff --git a/src/Utility/TeeJee.FileSystem.vala b/src/Utility/TeeJee.FileSystem.vala index 125c0c7b..f84df607 100644 --- a/src/Utility/TeeJee.FileSystem.vala +++ b/src/Utility/TeeJee.FileSystem.vala @@ -475,11 +475,4 @@ namespace TeeJee.FileSystem{ return file_path.replace("'","'\\''"); } - - // dep: chmod - public int chmod(string file, string permission){ - - string cmd = "chmod %s '%s'".printf(permission, escape_single_quote(file)); - return exec_sync (cmd, null, null); - } } diff --git a/src/Utility/TeeJee.Process.vala b/src/Utility/TeeJee.Process.vala index 1bdc1f13..1af2c8f5 100644 --- a/src/Utility/TeeJee.Process.vala +++ b/src/Utility/TeeJee.Process.vala @@ -49,7 +49,7 @@ namespace TeeJee.ProcessHelper{ TEMP_DIR = tempPlace + "/timeshift-" + random_string(); dir_create(TEMP_DIR); - chmod(TEMP_DIR, "0750"); + Posix.chmod(TEMP_DIR, 0750); exec_script_sync("echo 'ok'",out std_out,out std_err, true); if ((std_out == null) || (std_out.strip() != "ok")){ @@ -223,7 +223,7 @@ namespace TeeJee.ProcessHelper{ script.append ("echo ${exitCode} > status\n"); if ((sh_path == null) || (sh_path.length == 0)){ - sh_path = get_temp_file_path() + ".sh"; + sh_path = get_temp_file_path(); } try{ @@ -238,7 +238,7 @@ namespace TeeJee.ProcessHelper{ data_stream.close(); // set execute permission - chmod (sh_path, "u+x"); + Posix.chmod (sh_path, 0744); return sh_path; } From f7093eb6034e1abbae9eae7efbdfbc18f0b87c76 Mon Sep 17 00:00:00 2001 From: ygerlach <100762533+ygerlach@users.noreply.github.com> Date: Sat, 7 Dec 2024 14:56:55 +0100 Subject: [PATCH 7/8] remove dependency of chown --- src/Utility/CronTab.vala | 2 +- src/Utility/TeeJee.FileSystem.vala | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Utility/CronTab.vala b/src/Utility/CronTab.vala index f05eda76..e1691a58 100644 --- a/src/Utility/CronTab.vala +++ b/src/Utility/CronTab.vala @@ -306,7 +306,7 @@ public class CronTab : GLib.Object { } file_write(file_path, sh); - chown(file_path, "root", "root"); + Posix.chown(file_path, 0, 0); // chown to root:root Posix.chmod(file_path, 0644); log_msg(_("Added cron task") + ": %s".printf(file_path)); diff --git a/src/Utility/TeeJee.FileSystem.vala b/src/Utility/TeeJee.FileSystem.vala index f84df607..f0e6753e 100644 --- a/src/Utility/TeeJee.FileSystem.vala +++ b/src/Utility/TeeJee.FileSystem.vala @@ -414,12 +414,6 @@ namespace TeeJee.FileSystem{ return list; } - public bool chown(string dir_path, string user, string group = user){ - string cmd = "chown %s:%s -R '%s'".printf(user, group, escape_single_quote(dir_path)); - int status = exec_sync(cmd, null, null); - return (status == 0); - } - // misc -------------------- public string format_file_size ( From c891410a5d3a4a9513e6d7f1bae4a190ad7e4bb9 Mon Sep 17 00:00:00 2001 From: ygerlach <100762533+ygerlach@users.noreply.github.com> Date: Sat, 26 Jul 2025 11:45:05 +0200 Subject: [PATCH 8/8] only update control file if comment was edited --- src/Gtk/SnapshotListBox.vala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Gtk/SnapshotListBox.vala b/src/Gtk/SnapshotListBox.vala index 8b680813..1e851690 100644 --- a/src/Gtk/SnapshotListBox.vala +++ b/src/Gtk/SnapshotListBox.vala @@ -237,8 +237,10 @@ class SnapshotListBox : Gtk.Box{ var model = (Gtk.ListStore) treeview.model; model.get_iter_from_string (out iter, path); model.get (iter, 0, out bak, -1); - bak.description = new_text; - bak.update_control_file(); + if (bak.description != new_text) { + bak.description = new_text; + bak.update_control_file(); + } }); var col_buffer = new TreeViewColumn();