diff --git a/.gitignore b/.gitignore index ac14c4c..91fe117 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,11 @@ release/ debian/timeshift/ rpm/ + +debian/debhelper-build-stamp + +debian/files + +debian/timeshift.debhelper.log + +debian/timeshift.substvars diff --git a/AUTHORS b/AUTHORS index 89374f5..3220e6c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,3 @@ -Copyright (C) 2013 Tony George (teejee2008@gmail.com) +Copyright (C) 2020 Tony George (teejeetech@gmail.com) diff --git a/src/Utility/ArchiveFile.vala b/src/Utility/ArchiveFile.vala deleted file mode 100644 index 937eaed..0000000 --- a/src/Utility/ArchiveFile.vala +++ /dev/null @@ -1,83 +0,0 @@ -/* - * ArchiveFile.vala - * - * Copyright 2012-2018 Tony George - * - * 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 GLib; -using Gtk; -using Gee; -using Json; - -using TeeJee.Logging; -using TeeJee.FileSystem; -using TeeJee.JsonHelper; -using TeeJee.ProcessHelper; -using TeeJee.GtkHelper; -using TeeJee.System; -using TeeJee.Misc; - -public class ArchiveFile : FileItem { - - // additional properties - public int64 archive_size = 0; - public int64 archive_unpacked_size = 0; - public double compression_ratio = 0.0; - public string archive_type = ""; - public string archive_method = ""; - public bool archive_is_encrypted = false; - public bool archive_is_solid = false; - public int archive_blocks = 0; - public int64 archive_header_size = 0; - public DateTime archive_modified; - - public string password = ""; - public string keyfile = ""; - - // extraction - public Gee.ArrayList extract_list; - - // temp - public string temp_dir = ""; - public string script_file = ""; - public string log_file = ""; - - public ArchiveFile(string archive_file_path = "") { - base.from_path_and_type(archive_file_path, FileType.REGULAR); - is_archive = true; - - //this.tag = this; - - extract_list = new Gee.ArrayList(); - temp_dir = TEMP_DIR + "/" + timestamp_for_path(); - log_file = temp_dir + "/log.txt"; - script_file = temp_dir + "/convert.sh"; - dir_create (temp_dir); - } - - public void add_items(Gee.ArrayList item_list){ - if (item_list.size > 0){ - foreach(string item in item_list){ - add_child_from_disk(item); - } - } - } -} - diff --git a/src/Utility/AsyncTask.vala b/src/Utility/AsyncTask.vala index 0bbc85f..b26cbbe 100644 --- a/src/Utility/AsyncTask.vala +++ b/src/Utility/AsyncTask.vala @@ -74,6 +74,7 @@ public abstract class AsyncTask : GLib.Object{ public signal void task_complete(); protected AsyncTask(){ + working_dir = TEMP_DIR + "/" + timestamp_for_path(); script_file = path_combine(working_dir, "script.sh"); log_file = path_combine(working_dir, "task.log"); @@ -258,6 +259,7 @@ public abstract class AsyncTask : GLib.Object{ protected abstract void parse_stderr_line(string err_line); private void finish(){ + // finish() gets called by 2 threads but should be executed only once if (finish_called) { return; } finish_called = true; @@ -317,6 +319,7 @@ public abstract class AsyncTask : GLib.Object{ protected abstract void finish_task(); protected int read_exit_code(){ + exit_code = -1; var path = file_parent(script_file) + "/status"; if (file_exists(path)){ @@ -328,12 +331,14 @@ public abstract class AsyncTask : GLib.Object{ } public bool is_running(){ + return (status == AppStatus.RUNNING); } // public actions -------------- public void pause() { + Pid sub_child_pid; foreach (long pid in get_process_children(child_pid)) { sub_child_pid = (Pid) pid; @@ -344,6 +349,7 @@ public abstract class AsyncTask : GLib.Object{ } public void resume() { + Pid sub_child_pid; foreach (long pid in get_process_children(child_pid)) { sub_child_pid = (Pid) pid; @@ -354,6 +360,7 @@ public abstract class AsyncTask : GLib.Object{ } public void stop(AppStatus status_to_update = AppStatus.CANCELLED) { + // we need to un-freeze the processes before we kill them if (status == AppStatus.PAUSED) { resume(); @@ -367,6 +374,7 @@ public abstract class AsyncTask : GLib.Object{ } public void set_priority() { + if (background_mode){ set_priority_value(5); } @@ -376,6 +384,7 @@ public abstract class AsyncTask : GLib.Object{ } public void set_priority_value(int prio) { + Pid app_pid = Posix.getpid(); process_set_priority (app_pid, prio); @@ -414,6 +423,7 @@ public abstract class AsyncTask : GLib.Object{ } public void print_app_status(){ + switch(status){ case AppStatus.NOT_STARTED: log_debug("status=%s".printf("NOT_STARTED")); diff --git a/src/Utility/Bash.vala b/src/Utility/Bash.vala deleted file mode 100644 index 2edda6e..0000000 --- a/src/Utility/Bash.vala +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Bash.vala - * - * Copyright 2012-2018 Tony George - * - * 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 GLib; -using Gtk; -using Gee; -using Json; - -using TeeJee.Logging; -using TeeJee.FileSystem; -using TeeJee.JsonHelper; -using TeeJee.ProcessHelper; -using TeeJee.GtkHelper; -using TeeJee.System; -using TeeJee.Misc; - -public class Bash : AsyncTask { - - public Pid bash_pid = -1; - public int status_code = -1; - private static Gee.HashMap regex_list; - - public Bash() { - init_regular_expressions(); - } - - private static void init_regular_expressions(){ - if (regex_list != null){ - return; // already initialized - } - - regex_list = new Gee.HashMap(); - - try { - //Example: status=-1 - regex_list["status"] = new Regex("""status=([0-9\-]+)"""); - } - catch (Error e) { - log_error (e.message); - } - } - - // execution ---------------------------- - - public void start_shell() { - dir_create(working_dir); - - var sh = "bash -c 'pkexec bash'"; - save_bash_script_temp(sh, script_file); - begin(); - log_debug("Started bash shell"); - - if (status == AppStatus.RUNNING){ - bash_pid = -1; - while ((status == AppStatus.RUNNING) && (bash_pid == -1)) { - sleep(200); - var children = get_process_children(child_pid); - if (children.length > 0){ - bash_pid = children[0]; - } - } - - log_debug("script pid: %d".printf(child_pid)); - log_debug("bash shell pid: %d".printf(bash_pid)); - } - } - - public override void parse_stdout_line(string out_line){ - if ((out_line == null) || (out_line.length == 0)) { - return; - } - MatchInfo match; - if (regex_list["status"].match(out_line, 0, out match)) { - status_code = int.parse(match.fetch(1)); - } - stdout.printf(out_line + "\n"); - stdout.flush(); - } - - public override void parse_stderr_line(string err_line){ - stdout.printf(err_line + "\n"); - stdout.flush(); - } - - public int execute(string line){ - status_code = -1; - write_stdin(line); - write_stdin("echo status=$?"); - - while (status_code == -1){ - sleep(200); - gtk_do_events(); - } - - return status_code; - } - - protected override void finish_task(){ - log_debug("Bash: finish_task()"); - } - - public int read_status(){ - var status_file = working_dir + "/status"; - var f = File.new_for_path(status_file); - if (f.query_exists()){ - var txt = file_read(status_file); - return int.parse(txt); - } - return -1; - } - -} - diff --git a/src/Utility/CryptTabEntry.vala b/src/Utility/CryptTabEntry.vala index 02590c6..81b0abc 100644 --- a/src/Utility/CryptTabEntry.vala +++ b/src/Utility/CryptTabEntry.vala @@ -31,6 +31,7 @@ using TeeJee.System; using TeeJee.Misc; public class CryptTabEntry : GLib.Object{ + public bool is_comment = false; public bool is_empty_line = false; @@ -56,6 +57,7 @@ public class CryptTabEntry : GLib.Object{ } public static Gee.ArrayList read_file(string file_path){ + var list = new Gee.ArrayList(); if (!file_exists(file_path)){ return list; } @@ -103,9 +105,7 @@ public class CryptTabEntry : GLib.Object{ return list; } - public static string write_file( - Gee.ArrayList entries, string file_path, - bool keep_comments_and_empty_lines = true){ + public static string write_file(Gee.ArrayList entries, string file_path, bool keep_comments_and_empty_lines = true){ string text = ""; foreach(var entry in entries){ diff --git a/src/Utility/FileItem.vala b/src/Utility/FileItem.vala index ba8d4aa..647c5ad 100644 --- a/src/Utility/FileItem.vala +++ b/src/Utility/FileItem.vala @@ -51,65 +51,19 @@ public class FileItem : GLib.Object,Gee.Comparable { public bool is_selected = false; public bool is_symlink = false; public string symlink_target = ""; - public bool is_archive = false; - public bool is_stale = false; - public FileItem parent; - public Gee.HashMap children = new Gee.HashMap(); - public FileItem? source_archive; - - public GLib.Object? tag; - //public Gtk.TreeIter? treeiter; - public long file_count = 0; public long dir_count = 0; private int64 _size = 0; - private int64 _size_compressed = 0; - public long file_count_total = 0; - public long dir_count_total = 0; - - //public string icon_name = "gtk-file"; public GLib.Icon icon; - public bool is_dummy = false; - - public static string[] archive_extensions = { - ".tar", - ".tar.gz", ".tgz", - ".tar.bzip2", ".tar.bz2", ".tbz", ".tbz2", ".tb2", - ".tar.lzma", ".tar.lz", ".tlz", - ".tar.xz", ".txz", - ".tar.7z", - ".tar.zip", - ".7z", ".lzma", - ".bz2", ".bzip2", - ".gz", ".gzip", - ".zip", ".rar", ".cab", ".arj", ".z", ".taz", ".cpio", - ".rpm", ".deb", - ".lzh", ".lha", - ".chm", ".chw", ".hxs", - ".iso", ".dmg", ".xar", ".hfs", ".ntfs", ".fat", ".vhd", ".mbr", - ".wim", ".swm", ".squashfs", ".cramfs", ".scap" - }; - - // contructors ------------------------------- - public FileItem(string name = "New Archive") { + public FileItem(string name) { file_name = name; } - public FileItem.dummy(FileType _file_type) { - is_dummy = true; - file_type = _file_type; - } - - public FileItem.dummy_root() { - file_name = "dummy"; - file_location = ""; - } - public FileItem.from_disk_path_with_basic_info(string _file_path) { file_path = _file_path; file_name = file_basename(_file_path); @@ -124,7 +78,7 @@ public class FileItem : GLib.Object,Gee.Comparable { file_type = _file_type; } - // properties -------------------------------------- + // properties ------------------------------------------------- public int64 size { get{ @@ -132,13 +86,7 @@ public class FileItem : GLib.Object,Gee.Comparable { } } - public int64 size_compressed { - get{ - return _size_compressed; - } - } - - // helpers --------------- + // helpers ---------------------------------------------------- public int compare_to(FileItem b){ if (this.file_type != b.file_type) { @@ -159,211 +107,8 @@ public class FileItem : GLib.Object,Gee.Comparable { } } - // instance methods ------------------------------------------ - - public FileItem add_child_from_disk(string item_file_path, int depth = -1) { - FileItem item = null; - - //log_debug("add_child_from_disk: %02d: %s".printf(depth, item_file_path)); - - try { - FileEnumerator enumerator; - FileInfo info; - File file = File.parse_name (item_file_path); - - if (file.query_exists()) { - - // query file type - var item_file_type = file.query_file_type(FileQueryInfoFlags.NONE); - - //add item - item = this.add_child(item_file_path, item_file_type, 0, 0, true); - - if ((item.file_type == FileType.DIRECTORY) && !item.is_symlink) { - if (depth != 0){ - //recurse children - enumerator = file.enumerate_children ("%s".printf(FileAttribute.STANDARD_NAME), 0); - while ((info = enumerator.next_file()) != null) { - string child_path = "%s/%s".printf(item_file_path, info.get_name()); - item.add_child_from_disk(child_path, depth - 1); - } - } - } - } - } - catch (Error e) { - log_error (e.message); - } - - return item; - } - - public FileItem add_descendant( - string _file_path, - FileType ? _file_type, - int64 item_size, - int64 item_size_compressed) { - - //log_debug("add_descendant=%s".printf(_file_path)); - - string item_path = _file_path.strip(); - FileType item_type = (_file_type == null) ? FileType.REGULAR : _file_type; - - if (item_path.has_suffix("/")) { - item_path = item_path[0:item_path.length - 1]; - item_type = FileType.DIRECTORY; - } - - if (item_path.has_prefix("/")) { - item_path = item_path[1:item_path.length]; - } - - string dir_name = ""; - string dir_path = ""; - - //create dirs and find parent dir - FileItem current_dir = this; - string[] arr = item_path.split("/"); - for (int i = 0; i < arr.length - 1; i++) { - //get dir name - dir_name = arr[i]; - - //add dir - if (!current_dir.children.keys.contains(dir_name)) { - if ((current_dir == this) && current_dir.is_archive){ - dir_path = ""; - } - else { - dir_path = current_dir.file_path + "/"; - } - dir_path = "%s%s".printf(dir_path, dir_name); - current_dir.add_child(dir_path, FileType.DIRECTORY, 0, 0, false); - } - - current_dir = current_dir.children[dir_name]; - } - - //get item name - string item_name = arr[arr.length - 1]; - - //add item - if (!current_dir.children.keys.contains(item_name)) { - - //log_debug("add_descendant: add_child()"); - - current_dir.add_child( - item_path, item_type, item_size, item_size_compressed, false); - } - - //log_debug("add_descendant: finished: %s".printf(item_path)); - - return current_dir.children[item_name]; - } - - public FileItem add_child( - string item_file_path, - FileType item_file_type, - int64 item_size, - int64 item_size_compressed, - bool item_query_file_info){ - - // create new item ------------------------------ - - //log_debug("add_child: %s".printf(item_file_path)); - - FileItem item = new FileItem.from_path_and_type(item_file_path, item_file_type); - //item.tag = this.tag; - - foreach(var ext in archive_extensions){ - if (item_file_path.has_suffix(ext)) { - item = new ArchiveFile(item_file_path); - item.is_archive = true; - break; - } - } - - // check existing ---------------------------- - - bool existing_file = false; - if (!children.has_key(item.file_name)){ - children[item.file_name] = item; - - //set parent - item.parent = this; - } - else{ - existing_file = true; - item = this.children[item.file_name]; - - // mark as fresh - item.is_stale = false; - } - - // copy prefix from parent - item.file_path_prefix = this.file_path_prefix; - - // query file properties - if (item_query_file_info){ - //log_debug("add_child: query_file_info()"); - item.query_file_info(); - } - - if (item_file_type == FileType.REGULAR) { - - //log_debug("add_child: regular file"); - - // set file sizes - if (item_size > 0) { - item._size = item_size; - } - if (item_size_compressed > 0) { - item._size_compressed = item_size_compressed; - } - - // update file counts - if (!existing_file){ - this.file_count++; - this.file_count_total++; - this._size += item_size; - this._size_compressed += item_size_compressed; - - // update file count and size of parent dirs - var temp = this; - while (temp.parent != null) { - temp.parent.file_count_total++; - temp.parent._size += item_size; - temp.parent._size_compressed += item_size_compressed; - temp = temp.parent; - } - } - } - else if (item_file_type == FileType.DIRECTORY) { - - //log_debug("add_child: directory"); - - if (!existing_file){ + // instance methods ------------------------------------------- - // update dir counts - this.dir_count++; - this.dir_count_total++; - //this.size += _size; - //size will be updated when children are added - - // update dir count of parent dirs - var temp = this; - while (temp.parent != null) { - temp.parent.dir_count_total++; - temp = temp.parent; - } - } - } - - //log_debug("add_child: finished: fc=%lld dc=%lld path=%s".printf( - // file_count, dir_count, item_file_path)); - - return item; - } - public void query_file_info() { try { @@ -378,7 +123,7 @@ public class FileItem : GLib.Object,Gee.Comparable { FileAttribute.STANDARD_TYPE, FileAttribute.STANDARD_ICON, FileAttribute.STANDARD_SYMLINK_TARGET), - FileQueryInfoFlags.NOFOLLOW_SYMLINKS); + FileQueryInfoFlags.NOFOLLOW_SYMLINKS); var item_file_type = info.get_file_type(); @@ -477,186 +222,7 @@ public class FileItem : GLib.Object,Gee.Comparable { } } - public void query_children(int depth = -1) { - FileEnumerator enumerator; - FileInfo info; - File file = File.parse_name (file_path); - - if (!file.query_exists()) { - return; - } - - if (file_type == FileType.DIRECTORY) { - if (depth == 0){ - return; - } - - try{ - // mark existing children as stale - foreach(var child in children.values){ - child.is_stale = true; - } - - // recurse children - enumerator = file.enumerate_children ("%s".printf(FileAttribute.STANDARD_NAME), 0); - while ((info = enumerator.next_file()) != null) { - string child_name = info.get_name(); - string child_path = GLib.Path.build_filename(file_path, child_name); - this.add_child_from_disk(child_path, depth - 1); - } - - // remove stale children - var list = new Gee.ArrayList(); - foreach(var key in children.keys){ - if (children[key].is_stale){ - list.add(key); - } - } - foreach(var key in list){ - //log_debug("Unset:%s".printf(key)); - children.unset(key); - } - } - catch (Error e) { - log_error (e.message); - } - } - } - - public void clear_children() { - this.children.clear(); - } - - public FileItem remove_child(string child_name) { - FileItem child = null; - - if (this.children.has_key(child_name)) { - child = this.children[child_name]; - this.children.unset(child_name); - - if (child.file_type == FileType.REGULAR) { - //update file counts - this.file_count--; - this.file_count_total--; - - //subtract child size - this._size -= child.size; - this._size_compressed -= child.size_compressed; - - //update file count and size of parent dirs - var temp = this; - while (temp.parent != null) { - temp.parent.file_count_total--; - - temp.parent._size -= child.size; - temp.parent._size_compressed -= child.size_compressed; - - temp = temp.parent; - } - } - else { - //update dir counts - this.dir_count--; - this.dir_count_total--; - - //subtract child counts - this.file_count_total -= child.file_count_total; - this.dir_count_total -= child.dir_count_total; - this._size -= child.size; - this._size_compressed -= child.size_compressed; - - //update dir count of parent dirs - var temp = this; - while (temp.parent != null) { - temp.parent.dir_count_total--; - - temp.parent.file_count_total -= child.file_count_total; - temp.parent.dir_count_total -= child.dir_count_total; - temp.parent._size -= child.size; - temp.parent._size_compressed -= child.size_compressed; - - temp = temp.parent; - } - } - } - - //log_debug("%3ld %3ld %s".printf(file_count, dir_count, file_path)); - - return child; - } - - public FileItem? find_descendant(string path){ - var child = this; - - foreach(var part in path.split("/")){ - - // query children if needed - if (child.children.size == 0){ - child.query_children(1); - if (child.children.size == 0){ - break; - } - } - - if (child.children.has_key(part)){ - child = child.children[part]; - } - } - - if (child.file_path == path){ - return child; - } - else{ - return null; - } - } - - public void set_file_path_prefix(string prefix){ - file_path_prefix = prefix; - foreach(var child in this.children.values){ - child.set_file_path_prefix(prefix); - } - } - - public void print(int level) { - - if (level == 0) { - stdout.printf("\n"); - stdout.flush(); - } - - stdout.printf("%s%s\n".printf(string.nfill(level * 2, ' '), file_name)); - stdout.flush(); - - foreach (var key in this.children.keys) { - this.children[key].print(level + 1); - } - } - - public Gee.ArrayList get_children_sorted(){ - var list = new Gee.ArrayList(); - - foreach(string key in children.keys) { - var item = children[key]; - list.add(item); - } - - list.sort((a, b) => { - if ((a.file_type == FileType.DIRECTORY) && (b.file_type != FileType.DIRECTORY)){ - return -1; - } - else if ((a.file_type != FileType.DIRECTORY) && (b.file_type == FileType.DIRECTORY)){ - return 1; - } - else{ - return strcmp(a.file_name.down(), b.file_name.down()); - } - }); - - return list; - } - - // icons + // icons ------------------------------------------------------ public Gdk.Pixbuf? get_icon(int icon_size, bool add_transparency, bool add_emblems){ @@ -678,6 +244,3 @@ public class FileItem : GLib.Object,Gee.Comparable { return pixbuf; } } - - - diff --git a/src/Utility/FsTabEntry.vala b/src/Utility/FsTabEntry.vala index aa4714f..f0045ce 100755 --- a/src/Utility/FsTabEntry.vala +++ b/src/Utility/FsTabEntry.vala @@ -191,8 +191,7 @@ public class FsTabEntry : GLib.Object{ } } - public static FsTabEntry? find_entry_by_mount_point( - Gee.ArrayList entries, string mount_path){ + public static FsTabEntry? find_entry_by_mount_point(Gee.ArrayList entries, string mount_path){ foreach(var entry in entries){ if (entry.mount_point == mount_path){ @@ -203,6 +202,7 @@ public class FsTabEntry : GLib.Object{ } public Device? resolve_device(Gee.ArrayList crypttab, Gtk.Window? parent_window){ + Device dev_fstab = null; if (device_uuid.length > 0){ dev_fstab = Device.get_device_by_uuid(device_uuid); diff --git a/src/Utility/GtkHelper.vala b/src/Utility/GtkHelper.vala index 4fb7dab..5478ccd 100644 --- a/src/Utility/GtkHelper.vala +++ b/src/Utility/GtkHelper.vala @@ -53,8 +53,7 @@ namespace TeeJee.GtkHelper{ gtk_do_events (); } - public void gtk_messagebox( - string title, string message, Gtk.Window? parent_win, bool is_error = false){ + public void gtk_messagebox(string title, string message, Gtk.Window? parent_win, bool is_error = false){ /* Shows a simple message box */ @@ -81,8 +80,7 @@ namespace TeeJee.GtkHelper{ dlg.destroy(); } - public string? gtk_inputbox( - string title, string message, Gtk.Window? parent_win, bool mask_password = false){ + public string? gtk_inputbox(string title, string message, Gtk.Window? parent_win, bool mask_password = false){ /* Shows a simple input prompt */ @@ -194,10 +192,7 @@ namespace TeeJee.GtkHelper{ return val; } - public GLib.Object gtk_combobox_get_selected_object ( - ComboBox combo, - int index, - GLib.Object default_value){ + public GLib.Object gtk_combobox_get_selected_object (ComboBox combo, int index, GLib.Object default_value){ /* Conveniance function to get combobox value */ @@ -230,6 +225,7 @@ namespace TeeJee.GtkHelper{ // styles ---------------- public static int CSS_AUTO_CLASS_INDEX = 0; + public static void gtk_apply_css(Gtk.Widget[] widgets, string css_style){ var css_provider = new Gtk.CssProvider(); var css = ".style_%d { %s }".printf(++CSS_AUTO_CLASS_INDEX, css_style); @@ -262,98 +258,12 @@ namespace TeeJee.GtkHelper{ return count; } - public void gtk_stripe_row( - Gtk.CellRenderer cell, - bool odd_row, - string odd_color = "#F4F6F7", - string even_color = "#FFFFFF"){ - - if (cell is Gtk.CellRendererText){ - (cell as Gtk.CellRendererText).background = odd_row ? odd_color : even_color; - } - else if (cell is Gtk.CellRendererPixbuf){ - (cell as Gtk.CellRendererPixbuf).cell_background = odd_row ? odd_color : even_color; - } - } - public void gtk_treeview_redraw(Gtk.TreeView treeview){ var model = treeview.model; treeview.model = null; treeview.model = model; } - // menu - - public void gtk_menu_add_separator(Gtk.Menu menu){ - Gdk.RGBA gray = Gdk.RGBA(); - gray.parse ("rgba(200,200,200,1)"); - - // separator - var menu_item = new Gtk.SeparatorMenuItem(); - menu_item.override_color (StateFlags.NORMAL, gray); - menu.append(menu_item); - } - - public Gtk.MenuItem gtk_menu_add_item( - Gtk.Menu menu, - string label, - string tooltip, - Gtk.Image? icon_image, - Gtk.SizeGroup? sg_icon = null, - Gtk.SizeGroup? sg_label = null){ - - var menu_item = new Gtk.MenuItem(); - menu.append(menu_item); - - var box = new Gtk.Box(Orientation.HORIZONTAL, 3); - menu_item.add(box); - - // add icon - - if (icon_image == null){ - var dummy = new Gtk.Label(""); - box.add(dummy); - - if (sg_icon != null){ - sg_icon.add_widget(dummy); - } - } - else{ - box.add(icon_image); - - if (sg_icon != null){ - sg_icon.add_widget(icon_image); - } - } - - // add label - - var lbl = new Gtk.Label(label); - lbl.xalign = (float) 0.0; - lbl.margin_right = 6; - box.add(lbl); - - if (sg_label != null){ - sg_label.add_widget(lbl); - } - - box.set_tooltip_text(tooltip); - - return menu_item; - } - - // build ui - - public Gtk.Label gtk_box_add_header(Gtk.Box box, string text){ - var label = new Gtk.Label("" + text + ""); - label.set_use_markup(true); - label.xalign = (float) 0.0; - label.margin_bottom = 6; - box.add(label); - - return label; - } - // misc public bool gtk_container_has_child(Gtk.Container container, Gtk.Widget widget){ @@ -365,31 +275,6 @@ namespace TeeJee.GtkHelper{ return false; } - - private void text_view_append(Gtk.TextView view, string text){ - TextIter iter; - view.buffer.get_end_iter(out iter); - view.buffer.insert(ref iter, text, text.length); - } - - private void text_view_prepend(Gtk.TextView view, string text){ - TextIter iter; - view.buffer.get_start_iter(out iter); - view.buffer.insert(ref iter, text, text.length); - } - - private void text_view_scroll_to_end(Gtk.TextView view){ - TextIter iter; - view.buffer.get_end_iter(out iter); - view.scroll_to_iter(iter, 0.0, false, 0.0, 0.0); - } - - private void text_view_scroll_to_start(Gtk.TextView view){ - TextIter iter; - view.buffer.get_start_iter(out iter); - view.scroll_to_iter(iter, 0.0, false, 0.0, 0.0); - } - // file chooser ---------------- public Gtk.FileFilter create_file_filter(string group_name, string[] patterns) { @@ -404,8 +289,7 @@ namespace TeeJee.GtkHelper{ // utility ------------------ // add_notebook - private Gtk.Notebook add_notebook( - Gtk.Box box, bool show_tabs = true, bool show_border = true){ + private Gtk.Notebook add_notebook(Gtk.Box box, bool show_tabs = true, bool show_border = true){ // notebook var book = new Gtk.Notebook(); @@ -418,24 +302,8 @@ namespace TeeJee.GtkHelper{ return book; } - // add_tab - private Gtk.Box add_tab( - Gtk.Notebook book, string title, int margin = 12, int spacing = 6){ - - // label - var label = new Gtk.Label(title); - - // vbox - var vbox = new Gtk.Box(Gtk.Orientation.VERTICAL, spacing); - vbox.margin = margin; - book.append_page (vbox, label); - - return vbox; - } - // add_treeview - private Gtk.TreeView add_treeview(Gtk.Box box, - Gtk.SelectionMode selection_mode = Gtk.SelectionMode.SINGLE){ + private Gtk.TreeView add_treeview(Gtk.Box box, Gtk.SelectionMode selection_mode = Gtk.SelectionMode.SINGLE){ // TreeView var treeview = new TreeView(); @@ -455,8 +323,7 @@ namespace TeeJee.GtkHelper{ } // add_column_text - private Gtk.TreeViewColumn add_column_text( - Gtk.TreeView treeview, string title, out Gtk.CellRendererText cell){ + private Gtk.TreeViewColumn add_column_text(Gtk.TreeView treeview, string title, out Gtk.CellRendererText cell){ // TreeViewColumn var col = new Gtk.TreeViewColumn(); @@ -470,10 +337,8 @@ namespace TeeJee.GtkHelper{ return col; } - // add_column_icon - private Gtk.TreeViewColumn add_column_icon( - Gtk.TreeView treeview, string title, out Gtk.CellRendererPixbuf cell){ + private Gtk.TreeViewColumn add_column_icon(Gtk.TreeView treeview, string title, out Gtk.CellRendererPixbuf cell){ // TreeViewColumn var col = new Gtk.TreeViewColumn(); @@ -488,8 +353,7 @@ namespace TeeJee.GtkHelper{ } // add_column_icon_and_text - private Gtk.TreeViewColumn add_column_icon_and_text( - Gtk.TreeView treeview, string title, + private Gtk.TreeViewColumn add_column_icon_and_text(Gtk.TreeView treeview, string title, out Gtk.CellRendererPixbuf cell_pix, out Gtk.CellRendererText cell_text){ // TreeViewColumn @@ -509,8 +373,7 @@ namespace TeeJee.GtkHelper{ } // add_column_radio_and_text - private Gtk.TreeViewColumn add_column_radio_and_text( - Gtk.TreeView treeview, string title, + private Gtk.TreeViewColumn add_column_radio_and_text(Gtk.TreeView treeview, string title, out Gtk.CellRendererToggle cell_radio, out Gtk.CellRendererText cell_text){ // TreeViewColumn @@ -532,11 +395,8 @@ namespace TeeJee.GtkHelper{ } // add_column_icon_radio_text - private 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){ + private 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(); @@ -561,9 +421,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){ + private 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); @@ -599,33 +457,8 @@ namespace TeeJee.GtkHelper{ return label; } - // add_text_view - private Gtk.TextView add_text_view( - Gtk.Box box, string text){ - - // ScrolledWindow - var scrolled = new Gtk.ScrolledWindow(null, null); - scrolled.hscrollbar_policy = PolicyType.NEVER; - scrolled.vscrollbar_policy = PolicyType.ALWAYS; - scrolled.expand = true; - box.add(scrolled); - - var view = new Gtk.TextView(); - view.wrap_mode = Gtk.WrapMode.WORD_CHAR; - view.accepts_tab = false; - view.editable = false; - view.cursor_visible = false; - view.buffer.text = text; - view.sensitive = false; - scrolled.add (view); - - return view; - } - // add_label - private Gtk.Label add_label( - Gtk.Box box, string text, bool bold = false, - bool italic = false, bool large = false){ + private Gtk.Label add_label(Gtk.Box box, string text, bool bold = false, bool italic = false, bool large = false){ string msg = "%s".printf( (bold ? " weight=\"bold\"" : ""), @@ -642,9 +475,7 @@ namespace TeeJee.GtkHelper{ return label; } - private string format_text( - string text, - bool bold = false, bool italic = false, bool large = false){ + private string format_text(string text, bool bold = false, bool italic = false, bool large = false){ string msg = "%s".printf( (bold ? " weight=\"bold\"" : ""), @@ -656,8 +487,7 @@ namespace TeeJee.GtkHelper{ } // add_label_header - private Gtk.Label add_label_header( - Gtk.Box box, string text, bool large_heading = false){ + private 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; @@ -665,8 +495,7 @@ namespace TeeJee.GtkHelper{ } // add_label_subnote - private Gtk.Label add_label_subnote( - Gtk.Box box, string text){ + private Gtk.Label add_label_subnote(Gtk.Box box, string text){ var label = add_label(box, text, false, true); label.margin_left = 6; @@ -674,8 +503,7 @@ namespace TeeJee.GtkHelper{ } // add_radio - private Gtk.RadioButton add_radio( - Gtk.Box box, string text, Gtk.RadioButton? another_radio_in_group){ + private Gtk.RadioButton add_radio(Gtk.Box box, string text, Gtk.RadioButton? another_radio_in_group){ Gtk.RadioButton radio = null; @@ -702,8 +530,7 @@ namespace TeeJee.GtkHelper{ } // add_checkbox - private Gtk.CheckButton add_checkbox( - Gtk.Box box, string text){ + private Gtk.CheckButton add_checkbox(Gtk.Box box, string text){ var chk = new Gtk.CheckButton.with_label(text); chk.label = text; @@ -727,9 +554,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){ + private 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); @@ -746,10 +571,7 @@ 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){ + private 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); @@ -770,10 +592,7 @@ namespace TeeJee.GtkHelper{ } // add_toggle_button - private Gtk.ToggleButton add_toggle_button( - Gtk.Box box, string text, string tooltip, - Gtk.SizeGroup? size_group, - Gtk.Image? icon = null){ + private Gtk.ToggleButton add_toggle_button(Gtk.Box box, string text, string tooltip, Gtk.SizeGroup? size_group, Gtk.Image? icon = null){ var button = new Gtk.ToggleButton(); box.add(button); @@ -794,8 +613,7 @@ namespace TeeJee.GtkHelper{ } // add_directory_chooser - private Gtk.Entry add_directory_chooser( - Gtk.Box box, string selected_directory, Gtk.Window parent_window){ + private Gtk.Entry add_directory_chooser(Gtk.Box box, string selected_directory, Gtk.Window parent_window){ // Entry var entry = new Gtk.Entry(); @@ -837,6 +655,5 @@ namespace TeeJee.GtkHelper{ return entry; } - } diff --git a/src/Utility/IconManager.vala b/src/Utility/IconManager.vala index 5a7841f..5376456 100644 --- a/src/Utility/IconManager.vala +++ b/src/Utility/IconManager.vala @@ -201,8 +201,7 @@ public class IconManager : GLib.Object { return null; } - public static Gdk.Pixbuf? add_emblem (Gdk.Pixbuf pixbuf, string icon_name, int emblem_size, - bool emblem_symbolic, Gtk.CornerType corner_type) { + public static Gdk.Pixbuf? add_emblem (Gdk.Pixbuf pixbuf, string icon_name, int emblem_size, bool emblem_symbolic, Gtk.CornerType corner_type) { if (icon_name.length == 0){ return pixbuf; } diff --git a/src/Utility/LinuxDistro.vala b/src/Utility/LinuxDistro.vala index d29d07c..ea38e47 100644 --- a/src/Utility/LinuxDistro.vala +++ b/src/Utility/LinuxDistro.vala @@ -36,6 +36,7 @@ public class LinuxDistro : GLib.Object{ public string codename = ""; public LinuxDistro(){ + dist_id = ""; description = ""; release = ""; @@ -43,6 +44,7 @@ public class LinuxDistro : GLib.Object{ } public string full_name(){ + if (dist_id == ""){ return ""; } diff --git a/src/Utility/MountEntry.vala b/src/Utility/MountEntry.vala index bf233cc..09aa10e 100644 --- a/src/Utility/MountEntry.vala +++ b/src/Utility/MountEntry.vala @@ -14,6 +14,7 @@ public class MountEntry : GLib.Object{ public string mount_options = ""; public MountEntry(Device? device, string mount_point, string mount_options){ + this.device = device; this.mount_point = mount_point; this.mount_options = mount_options; @@ -37,6 +38,7 @@ public class MountEntry : GLib.Object{ } public string lvm_name(){ + if ((device != null) && (device.type == "lvm") && (device.mapped_name.length > 0)){ return device.mapped_name.strip(); } @@ -45,14 +47,14 @@ public class MountEntry : GLib.Object{ } } - public static MountEntry? find_entry_by_mount_point( - Gee.ArrayList entries, string mount_path){ + public static MountEntry? find_entry_by_mount_point(Gee.ArrayList entries, string mount_path){ foreach(var entry in entries){ if (entry.mount_point == mount_path){ return entry; } } + return null; } } diff --git a/src/Utility/OSDNotify.vala b/src/Utility/OSDNotify.vala index d98e482..8d9a777 100644 --- a/src/Utility/OSDNotify.vala +++ b/src/Utility/OSDNotify.vala @@ -28,6 +28,7 @@ using TeeJee.ProcessHelper; // dep: notify-send public class OSDNotify : GLib.Object { + private static DateTime dt_last_notification = null; public const int NOTIFICATION_INTERVAL = 3; @@ -53,7 +54,9 @@ 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); @@ -79,12 +82,9 @@ public class OSDNotify : GLib.Object { } public static bool is_supported(){ - string path = get_cmd_path ("notify-send"); - if ((path != null) && (path.length > 0)){ - return true; - } - else{ - return false; - } + + string path = get_cmd_path("notify-send"); + + return (path != null) && (path.length > 0); } } diff --git a/timeshift.pot b/timeshift.pot index a6c8237..82c8ce3 100644 --- a/timeshift.pot +++ b/timeshift.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: timeshift 18.2\n" "Report-Msgid-Bugs-To: teejeetech@gmail.com\n" -"POT-Creation-Date: 2020-11-15 13:00+0530\n" +"POT-Creation-Date: 2020-11-15 13:22+0530\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -688,10 +688,6 @@ msgstr "" msgid "Devices with Windows file systems are not supported (NTFS, FAT, etc)." msgstr "" -#: Utility/TeeJee.FileSystem.vala:502 -msgid "Dir not found" -msgstr "" - #: Core/SnapshotRepo.vala:974 msgid "Directory not found" msgstr "" @@ -992,12 +988,8 @@ msgstr "" msgid "File and directory counts:" msgstr "" -#: Utility/TeeJee.FileSystem.vala:655 Utility/TeeJee.FileSystem.vala:704 -msgid "File is missing" -msgstr "" - #: Utility/CronTab.vala:225 Utility/TeeJee.FileSystem.vala:183 -#: Utility/TeeJee.FileSystem.vala:531 Utility/RsyncTask.vala:298 +#: Utility/RsyncTask.vala:298 msgid "File not found" msgstr "" @@ -2257,7 +2249,7 @@ msgstr "" msgid "Stop cron emails for scheduled tasks" msgstr "" -#: Utility/TeeJee.Process.vala:514 +#: Utility/TeeJee.Process.vala:486 msgid "Stopped" msgstr ""