Skip to content

Commit

Permalink
Import GAuth account exports (#142)
Browse files Browse the repository at this point in the history
* Import GAuth account exports
* PO files update
  • Loading branch information
gr211 authored Mar 29, 2024
1 parent dbe9996 commit 8d3bd14
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 98 deletions.
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ gettext-rs = {version = "0", features = ["gettext-system"]}
gio = "0.19"
gtk-macros = "0.3"
glib-macros = "0.19"
google_authenticator_converter = "0.2.0"
image = "0"
log = "0"
log4rs = "1"
Expand Down
25 changes: 16 additions & 9 deletions data/resources/gtk/ui/error_popup.ui
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,23 @@
<property name="icon-name">object-select-symbolic</property>
<property name="use-fallback">True</property>
</object>
<object class="GtkFileFilter" id="yaml_filter">
<mime-types>
<mime-type>text/yaml</mime-type>
</mime-types>
<patterns>
<pattern>*.yaml</pattern>
<pattern>*.yml</pattern>
</patterns>
<object class="GtkFileFilter" id="import_filter">
<mime-types>
<mime-type>text/yaml</mime-type>
</mime-types>
<patterns>
<pattern>*.yaml</pattern>
<pattern>*.yml</pattern>
</patterns>
</object>
<object class="GtkFileFilter" id="import_filter_ga">
<mime-types>
<mime-type>image/png</mime-type>
</mime-types>
<patterns>
<pattern>*.png</pattern>
</patterns>
</object>
<object class="GtkFileChooserDialog" id="dialog">
<property name="name">dialog</property>
<property name="width-request">1200</property>
Expand All @@ -110,7 +118,6 @@
<property name="window-position">center-on-parent</property>
<property name="type-hint">dialog</property>
<property name="action">save</property>
<property name="filter">yaml_filter</property>
<property name="preview-widget-active">False</property>
<property name="use-preview-label">False</property>
<child internal-child="vbox">
Expand Down
49 changes: 37 additions & 12 deletions data/resources/gtk/ui/system_menu.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkPopoverMenu" id="popover">
Expand All @@ -15,9 +15,8 @@
<property name="hexpand">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkButton" id="import_button">
<property name="name">import_button</property>
<property name="visible">True</property>
<object class="GtkButton" id="import_button_yaml">
<property name="name">import_button_yaml</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="margin-start">3</property>
Expand All @@ -28,10 +27,10 @@
<property name="always-show-image">True</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">import_button_yaml_tootlip</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Import accounts</property>
<property name="label" translatable="yes">Import YAML</property>
</object>
</child>
</object>
Expand All @@ -41,6 +40,32 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="import_button_ga">
<property name="name">import_button_ga</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="margin-start">3</property>
<property name="margin-end">3</property>
<property name="margin-top">3</property>
<property name="margin-bottom">3</property>
<property name="hexpand">True</property>
<property name="always-show-image">True</property>
<child>
<object class="GtkLabel">
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">import_button_gauth_tootlip</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Import GAuth</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="export_button">
<property name="name">export_button</property>
Expand All @@ -57,15 +82,16 @@
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="tooltip-text" translatable="yes">export_button_yaml_tootlip</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Export accounts</property>
<property name="label" translatable="yes">Export YAML</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
<child>
Expand Down Expand Up @@ -105,7 +131,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">3</property>
</packing>
</child>
<child>
Expand All @@ -118,7 +144,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
<property name="position">4</property>
</packing>
</child>
<child>
Expand All @@ -145,7 +171,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
<property name="position">5</property>
</packing>
</child>
</object>
Expand All @@ -160,7 +186,6 @@
<widget name="grid1"/>
<widget name="about_button"/>
<widget name="export_button"/>
<widget name="import_button"/>
</widgets>
</object>
<object class="GtkMenuButton" id="system_menu">
Expand Down
25 changes: 23 additions & 2 deletions po/en_GB.po
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,23 @@ msgstr "Icon"
msgid "Icon URL"
msgstr "Icon URL"

msgid "Import accounts"
msgstr "Import accounts"
msgid "Import YAML"
msgstr "Import YAML"

msgid "import_button_yaml_tootlip"
msgstr "Import accounts from a YAML file"

msgid "Import GAuth"
msgstr "Import GAuth"

msgid "import_button_gauth_tootlip"
msgstr "Import accounts from a Google Authenticator export file"

msgid "Export YAML"
msgstr "Export YAML"

msgid "export_button_yaml_tootlip"
msgstr "Export accounts to a YAML file"

msgid "keyring_locked"
msgstr "Gnome keyring is locked."
Expand Down Expand Up @@ -154,3 +169,9 @@ msgstr "Collapse"

msgid "Expand"
msgstr "Expand"

msgid "New group"
msgstr "New group"

msgid "Edit group"
msgstr "Edit group"
25 changes: 23 additions & 2 deletions po/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,23 @@ msgstr "Icône"
msgid "Icon URL"
msgstr "URL de l'icône"

msgid "Import accounts"
msgstr "Importer"
msgid "Import YAML"
msgstr "Importer YAML"

msgid "import_button_yaml_tootlip"
msgstr "Importer des comptes depuis un fichier YAML"

msgid "Import GAuth"
msgstr "Importer GAuth"

msgid "import_button_gauth_tootlip"
msgstr "Importer des comptes depuis l'application Google Authenticator"

msgid "Export YAML"
msgstr "Exporter YAML"

msgid "export_button_yaml_tootlip"
msgstr "Exportez vos comptes vers un fichier YAML"

msgid "keyring_locked"
msgstr "Gnome keyring est verrouillé."
Expand Down Expand Up @@ -154,3 +169,9 @@ msgstr "Réduire"

msgid "Expand"
msgstr "Étendre"

msgid "New group"
msgstr "Nouveau groupe"

msgid "Edit group"
msgstr "Modifier le groupe"
28 changes: 22 additions & 6 deletions src/exporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ use crate::NAMESPACE_PREFIX;
pub type AccountsImportExportResult = Result<(), RepositoryError>;
type PopupButtonClosure = Box<dyn Fn(&[gtk::glib::Value]) -> Option<gtk::glib::Value>>;

#[derive(Debug, Clone)]
pub enum ImportType {
Internal,
GoogleAuthenticator,
}

pub trait Exporting {
fn export_accounts(&self, popover: PopoverMenu, connection: Arc<Mutex<Connection>>) -> Box<dyn Fn(&Button)>;

fn import_accounts(&self, popover: PopoverMenu, connection: Arc<Mutex<Connection>>) -> Box<dyn Fn(&Button)>;
fn import_accounts(&self, import_type: ImportType, popover: PopoverMenu, connection: Arc<Mutex<Connection>>) -> Box<dyn Fn(&Button)>;

fn popup_close(popup: gtk::Window) -> PopupButtonClosure;
}
Expand All @@ -33,10 +39,14 @@ impl Exporting for MainWindow {
get_widget!(builder, gtk::FileChooserDialog, dialog);
get_widget!(builder, gtk::Window, error_popup);
get_widget!(builder, gtk::Label, error_popup_body);
get_widget!(builder, gtk::FileFilter, yaml_filter);

dialog.set_filter(&yaml_filter);

dialog.set_do_overwrite_confirmation(true);
error_popup_body.set_label(&gettext("Could not export accounts!"));


builder.connect_signals(clone!(@strong error_popup => move |_, handler_name| match handler_name {
"export_account_error_close" => Self::popup_close(error_popup.clone()),
_ => Box::new(|_| None),
Expand Down Expand Up @@ -69,7 +79,7 @@ impl Exporting for MainWindow {
}))
}

fn import_accounts(&self, popover: PopoverMenu, connection: Arc<Mutex<Connection>>) -> Box<dyn Fn(&Button)> {
fn import_accounts(&self, import_type: ImportType, popover: PopoverMenu, connection: Arc<Mutex<Connection>>) -> Box<dyn Fn(&Button)> {
Box::new(clone!(@strong self as gui => move |_b: &Button| {
popover.set_visible(false);

Expand All @@ -78,6 +88,13 @@ impl Exporting for MainWindow {
get_widget!(builder, gtk::FileChooserDialog, dialog);
get_widget!(builder, gtk::Window, error_popup);
get_widget!(builder, gtk::Label, error_popup_body);
get_widget!(builder, gtk::FileFilter, import_filter);
get_widget!(builder, gtk::FileFilter, import_filter_ga);

match import_type {
ImportType::Internal => dialog.set_filter(&import_filter),
ImportType::GoogleAuthenticator => dialog.set_filter(&import_filter_ga),
}

error_popup.set_title(&gettext("Error"));
error_popup_body.set_label(&gettext("Could not import accounts!"));
Expand All @@ -98,8 +115,7 @@ impl Exporting for MainWindow {
let (tx, rx) = async_channel::bounded::<AccountsImportExportResult>(1);

glib::spawn_future_local(clone!(@strong gui, @strong connection => async move {
let result = rx.recv().await.unwrap();
match result {
match rx.recv().await.unwrap() {
Ok(_) => {
gui.accounts_window.refresh_accounts(&gui, connection.clone());
gui.accounts_window.accounts_container.set_sensitive(true);
Expand All @@ -111,8 +127,8 @@ impl Exporting for MainWindow {
}
}));

glib::spawn_future_local(clone!(@strong connection, @strong path, @strong tx => async move {
Backup::restore_account_and_signal_back(path, connection, tx).await
glib::spawn_future_local(clone!(@strong connection, @strong path, @strong import_type, @strong tx => async move {
Backup::restore_account_and_signal_back(import_type, path, connection, tx).await
}));
}
_ => dialog.close(),
Expand Down
Loading

0 comments on commit 8d3bd14

Please sign in to comment.