mirror of
https://github.com/linuxmint/timeshift.git
synced 2024-09-11 08:55:25 +03:00
#443 Add support for custom date format; Add new page for Misc settings;
This commit is contained in:
parent
8fe0c5db3b
commit
4f7fa9ea37
@ -132,6 +132,9 @@ public class Main : GLib.Object{
|
||||
public string log_file = "";
|
||||
public AppLock app_lock;
|
||||
|
||||
public string date_format = "%Y-%m-%d %H:%M:%S";
|
||||
public const string date_format_default = "%Y-%m-%d %H:%M:%S";
|
||||
|
||||
public Gee.ArrayList<Snapshot> delete_list;
|
||||
|
||||
public Snapshot snapshot_to_delete;
|
||||
@ -3062,6 +3065,8 @@ public class Main : GLib.Object{
|
||||
config.set_string_member("snapshot_size", first_snapshot_size.to_string());
|
||||
config.set_string_member("snapshot_count", first_snapshot_count.to_string());
|
||||
|
||||
config.set_string_member("date_format", date_format);
|
||||
|
||||
Json.Array arr = new Json.Array();
|
||||
foreach(string path in exclude_list_user){
|
||||
arr.add_string_element(path);
|
||||
@ -3156,6 +3161,8 @@ public class Main : GLib.Object{
|
||||
this.count_hourly = json_get_int(config,"count_hourly",count_hourly);
|
||||
this.count_boot = json_get_int(config,"count_boot",count_boot);
|
||||
|
||||
this.date_format = json_get_string(config, "date_format", date_format_default);
|
||||
|
||||
Main.first_snapshot_size = json_get_uint64(config,"snapshot_size", Main.first_snapshot_size);
|
||||
|
||||
Main.first_snapshot_count = (int64) json_get_uint64(config,"snapshot_count", Main.first_snapshot_count);
|
||||
|
@ -94,7 +94,7 @@ public class Snapshot : GLib.Object{
|
||||
|
||||
public string date_formatted{
|
||||
owned get{
|
||||
return date.format("%Y-%m-%d %H:%M:%S");
|
||||
return date.format(App.date_format);//.format("%Y-%m-%d %H:%M:%S");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1031,9 +1031,9 @@ class MainWindow : Gtk.Window{
|
||||
set_shield_label(_("Timeshift is active"));
|
||||
set_shield_subnote("%s: %s\n%s: %s".printf(
|
||||
_("Latest snapshot"),
|
||||
(last_snapshot_date == null) ? _("None") : last_snapshot_date.format ("%B %d, %Y %H:%M"),
|
||||
(last_snapshot_date == null) ? _("None") : last_snapshot_date.format(App.date_format),
|
||||
_("Oldest snapshot"),
|
||||
(oldest_snapshot_date == null) ? _("None") : oldest_snapshot_date.format ("%B %d, %Y %H:%M")
|
||||
(oldest_snapshot_date == null) ? _("None") : oldest_snapshot_date.format(App.date_format)
|
||||
));
|
||||
}
|
||||
else{
|
||||
|
186
src/Gtk/MiscBox.vala
Normal file
186
src/Gtk/MiscBox.vala
Normal file
@ -0,0 +1,186 @@
|
||||
/*
|
||||
* MiscBox.vala
|
||||
*
|
||||
* Copyright 2012-2018 Tony George <teejeetech@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 TeeJee.Logging;
|
||||
using TeeJee.FileSystem;
|
||||
using TeeJee.JsonHelper;
|
||||
using TeeJee.ProcessHelper;
|
||||
using TeeJee.GtkHelper;
|
||||
using TeeJee.System;
|
||||
using TeeJee.Misc;
|
||||
|
||||
class MiscBox : Gtk.Box{
|
||||
|
||||
private Gtk.Window parent_window;
|
||||
private bool restore_mode = false;
|
||||
|
||||
//private Gtk.CheckButton chk_include_btrfs_home;
|
||||
//private Gtk.CheckButton chk_enable_qgroups;
|
||||
|
||||
|
||||
public MiscBox (Gtk.Window _parent_window, bool _restore_mode) {
|
||||
|
||||
log_debug("MiscBox: MiscBox()");
|
||||
|
||||
//base(Gtk.Orientation.VERTICAL, 6); // issue with vala
|
||||
Object(orientation: Gtk.Orientation.VERTICAL, spacing: 6); // work-around
|
||||
parent_window = _parent_window;
|
||||
margin = 12;
|
||||
|
||||
restore_mode = _restore_mode;
|
||||
|
||||
var vbox = new Gtk.Box(Gtk.Orientation.VERTICAL, 6);
|
||||
this.add(vbox);
|
||||
|
||||
// ------------------------
|
||||
|
||||
init_date_format_option(vbox);
|
||||
|
||||
refresh();
|
||||
|
||||
log_debug("MiscBox: MiscBox(): exit");
|
||||
}
|
||||
|
||||
private void init_date_format_option(Gtk.Box box){
|
||||
|
||||
log_debug("MiscBox: init_date_format_option()");
|
||||
|
||||
add_label_header(box, _("Date Format"), false);
|
||||
|
||||
var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 6);
|
||||
box.add(hbox);
|
||||
|
||||
var combo = new Gtk.ComboBox();
|
||||
combo.hexpand = true;
|
||||
hbox.add(combo);
|
||||
|
||||
var entry = new Gtk.Entry();
|
||||
entry.hexpand = true;
|
||||
hbox.add(entry);
|
||||
|
||||
var cell_pix = new Gtk.CellRendererPixbuf();
|
||||
combo.pack_start (cell_pix, false);
|
||||
|
||||
var cell_text = new Gtk.CellRendererText();
|
||||
cell_text.xalign = (float) 0.0;
|
||||
combo.pack_start (cell_text, false);
|
||||
|
||||
var now = new DateTime.local(2019, 8, 11, 20, 25, 43);
|
||||
|
||||
combo.set_cell_data_func(cell_text, (cell_layout, cell, model, iter)=>{
|
||||
|
||||
string txt;
|
||||
model.get (iter, 0, out txt, -1);
|
||||
|
||||
(cell as Gtk.CellRendererText).text = (txt.length == 0) ? _("Custom") : now.format(txt);
|
||||
});
|
||||
|
||||
// populate combo
|
||||
var model = new Gtk.ListStore(1, typeof(string));
|
||||
combo.model = model;
|
||||
|
||||
int active = -1;
|
||||
int index = -1;
|
||||
TreeIter iter;
|
||||
foreach(var fmt in new string[]{
|
||||
"", // custom
|
||||
"%Y-%m-%d %H:%M:%S", // 2019-08-11 20:00:00
|
||||
"%Y-%m-%d %I:%M %p", // 2019-08-11 08:00 PM
|
||||
"%d %b %Y %I:%M %p", // 11 Aug 2019 08:00 PM
|
||||
"%Y %b %d, %I:%M %p", // 2019 Aug 11, 08:00 PM
|
||||
"%c" // Sunday, 11 August 2019 08:00:00 PM IST
|
||||
}){
|
||||
|
||||
index++;
|
||||
model.append(out iter);
|
||||
model.set(iter, 0, fmt);
|
||||
|
||||
if (App.date_format == fmt){
|
||||
active = index;
|
||||
}
|
||||
}
|
||||
|
||||
if (active < 0){
|
||||
active = 0;
|
||||
}
|
||||
|
||||
combo.active = active;
|
||||
|
||||
combo.changed.connect((path) => {
|
||||
|
||||
TreeIter iter_active;
|
||||
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);
|
||||
|
||||
string fmt = Main.date_format_default;
|
||||
if (txt.length > 0){
|
||||
fmt = txt;
|
||||
}
|
||||
|
||||
entry.text = fmt;
|
||||
|
||||
entry.sensitive = (txt.length == 0);
|
||||
|
||||
App.date_format = fmt;
|
||||
});
|
||||
|
||||
entry.text = App.date_format;
|
||||
|
||||
entry.sensitive = (combo.active == 0);
|
||||
|
||||
entry.focus_out_event.connect((entry1, event1) => {
|
||||
App.date_format = entry.text;
|
||||
log_debug("saved date_format: %s".printf(App.date_format));
|
||||
return false;
|
||||
});
|
||||
|
||||
show_all();
|
||||
|
||||
log_debug("MiscBox: init_date_format_option(): exit");
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
public void refresh(){
|
||||
|
||||
if (App.btrfs_mode){
|
||||
|
||||
//chk_include_btrfs_home.active = App.include_btrfs_home_for_restore;
|
||||
}
|
||||
else{
|
||||
|
||||
//chk_include_btrfs_home
|
||||
}
|
||||
|
||||
show_all();
|
||||
}
|
||||
}
|
@ -43,7 +43,8 @@ class SettingsWindow : Gtk.Window{
|
||||
private ScheduleBox schedule_box;
|
||||
private ExcludeBox exclude_box;
|
||||
private UsersBox users_box;
|
||||
|
||||
private MiscBox misc_box;
|
||||
|
||||
private uint tmr_init;
|
||||
private int def_width = 500;
|
||||
private int def_height = 500;
|
||||
@ -94,11 +95,15 @@ class SettingsWindow : Gtk.Window{
|
||||
exclude_box = new ExcludeBox(this);
|
||||
users_box = new UsersBox(this, exclude_box, false);
|
||||
exclude_box.set_users_box(users_box);
|
||||
|
||||
misc_box = new MiscBox(this, false);
|
||||
|
||||
stack.add_titled (users_box, "users", _("Users"));
|
||||
|
||||
stack.add_titled (exclude_box, "filters", _("Filters"));
|
||||
|
||||
stack.add_titled (misc_box, "misc", _("Misc"));
|
||||
|
||||
backend_box.type_changed.connect(()=>{
|
||||
exclude_box.visible = !App.btrfs_mode;
|
||||
backup_dev_box.refresh();
|
||||
|
Loading…
Reference in New Issue
Block a user