OTPClient 3.4.0 brings the following changes:
+OTPClient 3.3.0 brings the following changes:
diff --git a/src/app.c b/src/app.c index 2b34897d..18970834 100644 --- a/src/app.c +++ b/src/app.c @@ -24,6 +24,7 @@ #include "edit-row-cb.h" #include "show-qr-cb.h" #include "dbinfo-cb.h" +#include "change-file-cb.h" #ifndef USE_FLATPAK_APP_FOLDER static gchar *get_db_path (AppData *app_data); @@ -208,11 +209,14 @@ activate (GtkApplication *app, retry: app_data->db_data->key = prompt_for_password (app_data, NULL, NULL, FALSE); if (app_data->db_data->key == NULL) { - if (change_file (app_data) == FALSE) { + retry_change_file: + if (change_file (app_data) == QUIT_APP) { g_free (app_data->db_data); g_free (app_data); g_application_quit (G_APPLICATION(app)); return; + } else { + goto retry_change_file; } } } diff --git a/src/change-db-cb.c b/src/change-db-cb.c index cdbc5773..a1afa16f 100644 --- a/src/change-db-cb.c +++ b/src/change-db-cb.c @@ -7,15 +7,11 @@ #include "password-cb.h" #include "db-actions.h" #include "secret-schema.h" +#include "change-file-cb.h" - -void -change_db_cb (GSimpleAction *simple __attribute__((unused)), - GVariant *parameter __attribute__((unused)), - gpointer user_data) +int +change_db (AppData *app_data) { - AppData *app_data = (AppData *)user_data; - GtkWidget *changedb_diag = GTK_WIDGET(gtk_builder_get_object (app_data->builder, "changedb_diag_id")); GtkWidget *old_changedb_entry = GTK_WIDGET(gtk_builder_get_object (app_data->builder, "changedb_olddb_entry_id")); GtkWidget *new_changedb_entry = GTK_WIDGET(gtk_builder_get_object (app_data->builder, "changedb_entry_id")); @@ -29,29 +25,60 @@ change_db_cb (GSimpleAction *simple __attribute__((unused)), gint result = gtk_dialog_run (GTK_DIALOG (changedb_diag)); switch (result) { case GTK_RESPONSE_OK: + if (gtk_entry_get_text_length (GTK_ENTRY(new_changedb_entry)) == 0) { + show_message_dialog (app_data->main_window, "Input path cannot be empty.", GTK_MESSAGE_ERROR); + gtk_widget_hide (changedb_diag); + return RETRY_CHANGE; + } new_db_path = gtk_entry_get_text (GTK_ENTRY(new_changedb_entry)); if (!g_file_test (new_db_path, G_FILE_TEST_IS_REGULAR) || g_file_test (new_db_path,G_FILE_TEST_IS_SYMLINK)){ show_message_dialog (app_data->main_window, "Selected file is either a symlink or a non regular file.\nPlease choose another file.", GTK_MESSAGE_ERROR); - } else { - g_free (app_data->db_data->db_path); - app_data->db_data->db_path = g_strdup (new_db_path); - update_cfg_file (app_data); - gcry_free (app_data->db_data->key); - app_data->db_data->key = prompt_for_password (app_data, NULL, NULL, FALSE); - secret_password_store (OTPCLIENT_SCHEMA, SECRET_COLLECTION_DEFAULT, "main_pwd", app_data->db_data->key, NULL, on_password_stored, NULL, "string", "main_pwd", NULL); - GError *err = NULL; - load_new_db (app_data, &err); - if (err != NULL) { - show_message_dialog (app_data->main_window, err->message, GTK_MESSAGE_ERROR); - g_clear_error (&err); - } + gtk_widget_hide (changedb_diag); + return RETRY_CHANGE; + } + gchar *old_db_path = g_strdup (app_data->db_data->db_path); + g_free (app_data->db_data->db_path); + app_data->db_data->db_path = g_strdup (new_db_path); + update_cfg_file (app_data); + gcry_free (app_data->db_data->key); + app_data->db_data->key = prompt_for_password (app_data, NULL, NULL, FALSE); + if (app_data->db_data->key == NULL) { + gtk_widget_hide (changedb_diag); + revert_db_path (app_data, old_db_path); + return RETRY_CHANGE; } + secret_password_store (OTPCLIENT_SCHEMA, SECRET_COLLECTION_DEFAULT, "main_pwd", app_data->db_data->key, NULL, on_password_stored, NULL, "string", "main_pwd", NULL); + GError *err = NULL; + load_new_db (app_data, &err); + if (err != NULL) { + show_message_dialog (app_data->main_window, err->message, GTK_MESSAGE_ERROR); + g_clear_error (&err); + gtk_widget_hide (changedb_diag); + revert_db_path (app_data, old_db_path); + return RETRY_CHANGE; + } + g_free (old_db_path); break; case GTK_RESPONSE_CANCEL: + gtk_widget_destroy (changedb_diag); + return QUIT_APP; default: break; } gtk_widget_destroy (changedb_diag); + + return CHANGE_OK; +} + + +void +change_db_cb (GSimpleAction *action_name __attribute__((unused)), + GVariant *parameter __attribute__((unused)), + gpointer user_data) +{ + AppData *app_data = (AppData *)user_data; + + change_db (app_data); } @@ -60,4 +87,4 @@ change_db_cb_shortcut (GtkWidget *w __attribute__((unused)), gpointer user_data) { change_db_cb (NULL, NULL, user_data); -} +} \ No newline at end of file diff --git a/src/change-db-cb.h b/src/change-db-cb.h index 1cfb9aec..4b995b02 100644 --- a/src/change-db-cb.h +++ b/src/change-db-cb.h @@ -4,6 +4,8 @@ G_BEGIN_DECLS +int change_db (AppData *app_data); + void change_db_cb (GSimpleAction *simple, GVariant *parameter, gpointer user_data); diff --git a/src/change-file-cb.c b/src/change-file-cb.c index 6396cbe7..dd5e4cee 100644 --- a/src/change-file-cb.c +++ b/src/change-file-cb.c @@ -1,10 +1,10 @@ #include