|
@@ -0,0 +1,126 @@
|
|
|
|
+using Gtk;
|
|
|
|
+using Adw;
|
|
|
|
+
|
|
|
|
+namespace Publicate {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public class ManageIdentitiesWindow : Adw.Window {
|
|
|
|
+
|
|
|
|
+ private Adw.HeaderBar header_bar;
|
|
|
|
+ private ViewerWindow window;
|
|
|
|
+ private IdentityList identity_list;
|
|
|
|
+ private Button delete_button;
|
|
|
|
+ private Button import_button;
|
|
|
|
+ private Button export_button;
|
|
|
|
+
|
|
|
|
+ public ManageIdentitiesWindow(ViewerWindow window) {
|
|
|
|
+ this.window = window;
|
|
|
|
+ modal = true;
|
|
|
|
+ transient_for = window;
|
|
|
|
+
|
|
|
|
+ var box = new Box(Orientation.VERTICAL, 8);
|
|
|
|
+ header_bar = new Adw.HeaderBar();
|
|
|
|
+ title = "Manage identities";
|
|
|
|
+
|
|
|
|
+ box.append (header_bar);
|
|
|
|
+
|
|
|
|
+ identity_list = new IdentityList(window);
|
|
|
|
+ identity_list.margin_start = 18;
|
|
|
|
+ identity_list.margin_end = 18;
|
|
|
|
+ identity_list.margin_top = 18;
|
|
|
|
+ identity_list.add_css_class ("boxed-list");
|
|
|
|
+ box.append(identity_list);
|
|
|
|
+
|
|
|
|
+ default_height = 400;
|
|
|
|
+ default_width = 450;
|
|
|
|
+
|
|
|
|
+ var action_buttons = new Box(Orientation.HORIZONTAL, 8);
|
|
|
|
+ action_buttons.margin_bottom = 18;
|
|
|
|
+ action_buttons.margin_start = 18;
|
|
|
|
+ action_buttons.margin_end = 18;
|
|
|
|
+ action_buttons.halign = Align.FILL;
|
|
|
|
+
|
|
|
|
+ delete_button = new Button.with_label("Delete");
|
|
|
|
+ delete_button.add_css_class("destructive-action");
|
|
|
|
+ delete_button.halign = Align.START;
|
|
|
|
+ delete_button.clicked.connect(() => delete_entry());
|
|
|
|
+ action_buttons.append(delete_button);
|
|
|
|
+
|
|
|
|
+ export_button = new Button.with_label("Export");
|
|
|
|
+ export_button.halign = Align.START;
|
|
|
|
+ export_button.clicked.connect(() => export_credentials.begin());
|
|
|
|
+ action_buttons.append(export_button);
|
|
|
|
+
|
|
|
|
+ import_button = new Button.with_label("Import Identity");
|
|
|
|
+ import_button.hexpand = true;
|
|
|
|
+ import_button.halign = Align.END;
|
|
|
|
+ import_button.clicked.connect(() => import_credentials.begin());
|
|
|
|
+ action_buttons.append(import_button);
|
|
|
|
+
|
|
|
|
+ box.append(action_buttons);
|
|
|
|
+ content = box;
|
|
|
|
+
|
|
|
|
+ refresh_list();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void refresh_list() {
|
|
|
|
+ identity_list.populate_credentials();
|
|
|
|
+ delete_button.sensitive = identity_list.has_entries;
|
|
|
|
+ export_button.sensitive = identity_list.has_entries;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void delete_entry() {
|
|
|
|
+ var prompt = new Adw.MessageDialog(this, "Delete identity?", @"Are you sure you want to delete the identity $(identity_list.selected_name)? This cannot be undone.");
|
|
|
|
+ prompt.add_response("cancel", "Cancel");
|
|
|
|
+ prompt.add_response("delete", "Delete");
|
|
|
|
+ prompt.set_response_appearance("delete", ResponseAppearance.DESTRUCTIVE);
|
|
|
|
+ prompt.response.connect(r => {
|
|
|
|
+ if(r == "delete") {
|
|
|
|
+ File.new_for_path(get_publicate_path() + "/credentials/" + identity_list.selected_name).delete();
|
|
|
|
+ refresh_list();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ prompt.present();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public async void export_credentials() throws Error {
|
|
|
|
+ var dialog = new FileDialog();
|
|
|
|
+ dialog.accept_label = "Export";
|
|
|
|
+ var file = yield dialog.save(window, null);
|
|
|
|
+
|
|
|
|
+ if(file == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ yield File.new_for_path(get_publicate_path() + "/credentials/" + identity_list.selected_name).copy_async(file, FileCopyFlags.OVERWRITE, 1, null, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public async void import_credentials() throws Error {
|
|
|
|
+ var dialog = new FileDialog();
|
|
|
|
+ dialog.accept_label = "Import";
|
|
|
|
+ var file = yield dialog.open(window, null);
|
|
|
|
+
|
|
|
|
+ if(file == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ // First verify it's a valid credentials file
|
|
|
|
+ string cred_str;
|
|
|
|
+ FileUtils.get_contents(file.get_path(), out cred_str, null);
|
|
|
|
+ new Ppub.CollectionMemberCredentials.from_string(cred_str);
|
|
|
|
+
|
|
|
|
+ yield file.copy_async(File.new_for_path(get_publicate_path() + "/credentials/" + file.get_basename()), FileCopyFlags.OVERWRITE, 1, null, null);
|
|
|
|
+ refresh_list();
|
|
|
|
+ }
|
|
|
|
+ catch(Error e) {
|
|
|
|
+ var prompt = new Adw.MessageDialog(this, "Import error", @"Could not import identity: $(e.message)");
|
|
|
|
+ prompt.add_response("ok", "Close");
|
|
|
|
+ prompt.present();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|