Skip to content

Commit

Permalink
Improve Backup Page
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 committed May 13, 2024
1 parent 6e64698 commit cbec92f
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 27 deletions.
3 changes: 3 additions & 0 deletions data/io.github.alainm23.planify.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<file alias="mail-attachment-symbolic.svg">resources/icons/mail-attachment-symbolic.svg</file>
<file alias="arrow-turn-down-right-symbolic.svg">resources/icons/arrow-turn-down-right-symbolic.svg</file>
<file alias="shoe-box-symbolic.svg">resources/icons/shoe-box-symbolic.svg</file>
<file alias="eye-open-negative-filled-symbolic.svg">resources/icons/eye-open-negative-filled-symbolic.svg</file>
</gresource>

<gresource prefix="/io/github/alainm23/planify/Devel/icons/scalable/actions">
Expand Down Expand Up @@ -150,6 +151,7 @@
<file alias="mail-attachment-symbolic.svg">resources/icons/mail-attachment-symbolic.svg</file>
<file alias="arrow-turn-down-right-symbolic.svg">resources/icons/arrow-turn-down-right-symbolic.svg</file>
<file alias="shoe-box-symbolic.svg">resources/icons/shoe-box-symbolic.svg</file>
<file alias="eye-open-negative-filled-symbolic.svg">resources/icons/eye-open-negative-filled-symbolic.svg</file>
</gresource>

<gresource prefix="/io/github/alainm23/planify/quick-add/icons/scalable/actions">
Expand Down Expand Up @@ -212,5 +214,6 @@
<file alias="mail-attachment-symbolic.svg">resources/icons/mail-attachment-symbolic.svg</file>
<file alias="arrow-turn-down-right-symbolic.svg">resources/icons/arrow-turn-down-right-symbolic.svg</file>
<file alias="shoe-box-symbolic.svg">resources/icons/shoe-box-symbolic.svg</file>
<file alias="eye-open-negative-filled-symbolic.svg">resources/icons/eye-open-negative-filled-symbolic.svg</file>
</gresource>
</gresources>
7 changes: 7 additions & 0 deletions data/resources/icons/eye-open-negative-filled-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
124 changes: 98 additions & 26 deletions src/Dialogs/Preferences/Pages/Backup.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public class Dialogs.Preferences.Pages.Backup : Adw.Bin {
child = toolbar_view;

settings_header.back_activated.connect (() => {
pop_subpage ();
if (stack.visible_child_name == "import-page") {
stack.set_visible_child_name ("backup-page");
} else {
pop_subpage ();
}
});
}

Expand Down Expand Up @@ -113,23 +117,8 @@ public class Dialogs.Preferences.Pages.Backup : Adw.Bin {
import_button.clicked.connect (() => {
Services.Backups.get_default ().import_backup.begin ((obj, res) => {
GLib.File file = Services.Backups.get_default ().import_backup.end (res);

var backup = new Objects.Backup.from_file (file);

if (backup.valid ()) {
Gtk.Widget? import_page;
import_page = (Gtk.Widget) stack.get_child_by_name ("import-page");

if (import_page != null) {
stack.remove (import_page);
}

stack.add_named (get_import_page (backup), "import-page");
stack.set_visible_child_name ("import-page");
} else {
debug ("%s", backup.error);
popup_toast (_("Selected file is invalid"));
}
Objects.Backup backup = new Objects.Backup.from_file (file);
view_backup (backup);
});
});

Expand Down Expand Up @@ -171,7 +160,7 @@ public class Dialogs.Preferences.Pages.Backup : Adw.Bin {

var todoist_row = new Adw.ActionRow ();
todoist_row.title = _("Todoist");
todoist_row.add_suffix (generate_icon (backup.todoist_backend ? "object-select-symbolic" : "window-close-symbolic", 16));
todoist_row.add_suffix (generate_icon (backup.todoist_backend ? "check-round-outline-symbolic" : "window-close-symbolic", 16));

var general_group = new Adw.PreferencesGroup () {
margin_top = 24
Expand All @@ -187,7 +176,7 @@ public class Dialogs.Preferences.Pages.Backup : Adw.Bin {
sections_row.add_suffix (new Gtk.Label (backup.sections.size.to_string ()));

var items_row = new Adw.ActionRow ();
items_row.title = _("Items");
items_row.title = _("To-Dos");
items_row.add_suffix (new Gtk.Label (backup.items.size.to_string ()));

var labels_row = new Adw.ActionRow ();
Expand Down Expand Up @@ -283,6 +272,11 @@ public class Dialogs.Preferences.Pages.Backup : Adw.Bin {

private void add_backup_row (Objects.Backup backup, Layouts.HeaderItem group) {
var row = new Widgets.BackupRow (backup);

row.view.connect (() => {
view_backup (backup);
});

group.insert_child (row, 0);
}

Expand All @@ -291,11 +285,31 @@ public class Dialogs.Preferences.Pages.Backup : Adw.Bin {
pixel_size = size
};
}

private void view_backup (Objects.Backup backup) {
if (backup.valid ()) {
Gtk.Widget? import_page;
import_page = (Gtk.Widget) stack.get_child_by_name ("import-page");

if (import_page != null) {
stack.remove (import_page);
}

stack.add_named (get_import_page (backup), "import-page");
stack.set_visible_child_name ("import-page");
} else {
debug ("%s", backup.error);
popup_toast (_("Selected file is invalid"));
}
}
}

public class Widgets.BackupRow : Gtk.ListBoxRow {
public Objects.Backup backup { get; construct; }

private Gtk.Revealer main_revealer;
public signal void view ();

public BackupRow (Objects.Backup backup) {
Object (
backup: backup
Expand All @@ -310,14 +324,28 @@ public class Widgets.BackupRow : Gtk.ListBoxRow {
name_label.valign = Gtk.Align.CENTER;
name_label.ellipsize = Pango.EllipsizeMode.END;

var download_button = new Gtk.Button.from_icon_name ("folder-download-symbolic") {
var view_button = new Gtk.Button.from_icon_name ("eye-open-negative-filled-symbolic") {
valign = CENTER,
css_classes = { "flat" },
tooltip_text = _("View Backup")
};

var menu_button = new Gtk.MenuButton () {
hexpand = true,
halign = END,
popover = build_context_menu (),
icon_name = "view-more-symbolic",
css_classes = { "flat" }
};

var end_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
halign = END,
hexpand = true,
css_classes = { "flat" },
tooltip_text = _("Download")
};

end_box.append (view_button);
end_box.append (menu_button);

var content_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) {
margin_top = 6,
margin_start = 12,
Expand All @@ -327,9 +355,9 @@ public class Widgets.BackupRow : Gtk.ListBoxRow {

content_box.append (new Gtk.Image.from_icon_name ("paper-symbolic"));
content_box.append (name_label);
content_box.append (download_button);
content_box.append (end_box);

var main_revealer = new Gtk.Revealer () {
main_revealer = new Gtk.Revealer () {
transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN,
child = content_box
};
Expand All @@ -341,8 +369,52 @@ public class Widgets.BackupRow : Gtk.ListBoxRow {
return GLib.Source.REMOVE;
});

download_button.clicked.connect (() => {
view_button.clicked.connect (() => {
view ();
});

backup.deleted.connect (() => {
hide_destroy ();
});
}

private Gtk.Popover build_context_menu () {
var download_item = new Widgets.ContextMenu.MenuItem (_("Download"), "folder-download-symbolic");
var delete_item = new Widgets.ContextMenu.MenuItem (_("Delete"), "user-trash-symbolic");
delete_item.add_css_class ("menu-item-danger");

var menu_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
menu_box.margin_top = menu_box.margin_bottom = 3;

menu_box.append (download_item);
menu_box.append (new Widgets.ContextMenu.MenuSeparator ());
menu_box.append (delete_item);

var menu_popover = new Gtk.Popover () {
has_arrow = false,
child = menu_box,
position = Gtk.PositionType.BOTTOM,
width_request = 250
};

delete_item.clicked.connect (() => {
menu_popover.popdown ();
Services.Backups.get_default ().save_file_as (backup);
});

delete_item.clicked.connect (() => {
menu_popover.popdown ();
backup.delete_backup ((Gtk.Window) Planify.instance.main_window);
});

return menu_popover;
}

public void hide_destroy () {
main_revealer.reveal_child = false;
Timeout.add (main_revealer.transition_duration, () => {
((Gtk.ListBox) parent).remove (this);
return GLib.Source.REMOVE;
});
}
}
31 changes: 30 additions & 1 deletion src/Objects/Backup.vala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class Objects.Backup : Object {
return _todoist_backend;
}
}
public bool google_backend { get; set; default = false; }

public signal void deleted ();

public Backup.from_file (File file) {
var parser = new Json.Parser ();
Expand Down Expand Up @@ -119,4 +120,32 @@ public class Objects.Backup : Object {

return true;
}

public void delete_backup (Gtk.Window window) {
var dialog = new Adw.MessageDialog (
window,
_("Delete Backup"),
_("This can not be undone")
);

dialog.add_response ("cancel", _("Cancel"));
dialog.add_response ("delete", _("Delete"));
dialog.set_response_appearance ("delete", Adw.ResponseAppearance.DESTRUCTIVE);
dialog.show ();

dialog.response.connect ((response) => {
if (response == "delete") {
File db_file = File.new_for_path (path);
if (db_file.query_exists ()) {
try {
if (db_file.delete ()) {
deleted ();
}
} catch (Error err) {
warning (err.message);
}
}
}
});
}
}
7 changes: 7 additions & 0 deletions src/Services/Backups.vala
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class Services.Backups : Object {
builder.set_member_name ("local-inbox-project-id");
builder.add_string_value (Services.Settings.get_default ().settings.get_string ("local-inbox-project-id"));

// Todoist
builder.set_member_name ("todoist-access-token");
builder.add_string_value (Services.Settings.get_default ().settings.get_string ("todoist-access-token"));

Expand Down Expand Up @@ -236,6 +237,9 @@ public class Services.Backups : Object {
builder.set_member_name ("due_date");
builder.add_string_value (project.due_date);

builder.set_member_name ("sync_id");
builder.add_string_value (project.sync_id);

builder.end_object ();
}
builder.end_array ();
Expand Down Expand Up @@ -340,6 +344,9 @@ public class Services.Backups : Object {
builder.add_string_value (label.name);
}
builder.end_array ();

builder.set_member_name ("extra_data");
builder.add_string_value (item.extra_data);
builder.end_object ();

builder.end_object ();
Expand Down

0 comments on commit cbec92f

Please sign in to comment.