Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 3.6.0 #354

Merged
merged 6 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
clean up code
  • Loading branch information
paolostivanin committed Mar 11, 2024
commit 91b8f339c50e00ec6f4984828e8c5164540ae98d
7 changes: 7 additions & 0 deletions src/common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,11 @@ build_json_obj (const gchar *type,
}

return obj;
}


void
json_free (gpointer data)
{
json_decref (data);
}
2 changes: 2 additions & 0 deletions src/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,6 @@ json_t *build_json_obj (const gchar *type,
guint period,
guint64 ctr);

void json_free (gpointer data);

G_END_DECLS
2 changes: 1 addition & 1 deletion src/gui/change-db-cb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <libsecret/secret.h>
#include "data.h"
#include "message-dialogs.h"
#include "db-misc.h"
#include "gui-misc.h"
#include "password-cb.h"
#include "db-actions.h"
#include "../common/secret-schema.h"
Expand Down
1 change: 0 additions & 1 deletion src/gui/change-pwd-cb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <libsecret/secret.h>
#include "data.h"
#include "message-dialogs.h"
#include "db-misc.h"
#include "password-cb.h"
#include "../common/secret-schema.h"
#include "otpclient.h"
Expand Down
46 changes: 0 additions & 46 deletions src/gui/db-misc.c

This file was deleted.

17 changes: 0 additions & 17 deletions src/gui/db-misc.h

This file was deleted.

3 changes: 1 addition & 2 deletions src/gui/edit-row-cb.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include <gtk/gtk.h>
#include <gcrypt.h>
#include "treeview.h"
#include "db-misc.h"
#include "gui-misc.h"
#include "get-builder.h"
#include "message-dialogs.h"
#include "gui-misc.h"
#include "../common/gquarks.h"

typedef struct edit_data_t {
Expand Down
38 changes: 8 additions & 30 deletions src/gui/export-from-gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
#include "message-dialogs.h"
#include "../common/import-export.h"

static void show_ret_msg_dialog (GtkWidget *mainwin,
const gchar *fpath,
const gchar *ret_msg);


void
export_data_cb (GSimpleAction *simple,
Expand Down Expand Up @@ -69,7 +65,7 @@ export_data_cb (GSimpleAction *simple,

gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(fl_diag), filename);

gchar *export_file_abs_path = NULL;
g_autofree gchar *export_file_abs_path = NULL;
gint native_diag_res = gtk_native_dialog_run (GTK_NATIVE_DIALOG(fl_diag));
if (native_diag_res == GTK_RESPONSE_ACCEPT) {
export_file_abs_path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(fl_diag));
Expand All @@ -84,7 +80,7 @@ export_data_cb (GSimpleAction *simple,
return;
}

gchar *ret_msg = NULL;
g_autofree gchar *ret_msg = NULL;
if (g_strcmp0 (action_name, ANDOTP_PLAIN_ACTION_NAME) == 0 || g_strcmp0 (action_name, ANDOTP_ENC_ACTION_NAME) == 0) {
ret_msg = export_andotp (export_file_abs_path, password, app_data->db_data->json_data);
} else if (g_strcmp0 (action_name, FREEOTPPLUS_PLAIN_ACTION_NAME) == 0) {
Expand All @@ -99,30 +95,12 @@ export_data_cb (GSimpleAction *simple,
show_message_dialog (app_data->main_window, "Invalid export action.", GTK_MESSAGE_ERROR);
return;
}
show_ret_msg_dialog (app_data->main_window, export_file_abs_path, ret_msg);
g_free (ret_msg);
g_free (export_file_abs_path);

g_autofree gchar *message = (ret_msg != NULL) ? g_strconcat ("Error while exporting data: ", ret_msg, NULL)
: g_strconcat ("Data successfully exported to ", export_file_abs_path, NULL);
GtkMessageType msg_type = (ret_msg != NULL) ? GTK_MESSAGE_ERROR : GTK_MESSAGE_INFO;
show_message_dialog (app_data->main_window, message, msg_type);
if (encrypted == TRUE) {
gcry_free (password);
}
}


static void
show_ret_msg_dialog (GtkWidget *mainwin,
const gchar *fpath,
const gchar *ret_msg)
{
GtkMessageType msg_type;
gchar *message = NULL;

if (ret_msg != NULL) {
message = g_strconcat ("Error while exporting data: ", ret_msg, NULL);
msg_type = GTK_MESSAGE_ERROR;
} else {
message = g_strconcat ("Data successfully exported to ", fpath, NULL);
msg_type = GTK_MESSAGE_INFO;
}
show_message_dialog (mainwin, message, msg_type);
g_free (message);
}
}
35 changes: 35 additions & 0 deletions src/gui/gui-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "gui-misc.h"
#include "../common/common.h"
#include "google-migration.pb-c.h"
#include "../common/gquarks.h"
#include "treeview.h"


void
Expand Down Expand Up @@ -268,6 +270,39 @@ decode_migration_data (const gchar *encoded_uri)
}


gchar *
update_db_from_otps (GSList *otps, AppData *app_data)
{
add_otps_to_db (otps, app_data->db_data);

GError *err = NULL;
update_db (app_data->db_data, &err);
if (err != NULL && !g_error_matches (err, missing_file_gquark (), MISSING_FILE_CODE)) {
return g_strdup (err->message);
}
reload_db (app_data->db_data, &err);
if (err != NULL && !g_error_matches (err, missing_file_gquark (), MISSING_FILE_CODE)) {
return g_strdup (err->message);
}
regenerate_model (app_data);

return NULL;
}


void
load_new_db (AppData *app_data,
GError **err)
{
reload_db (app_data->db_data, err);
if (*err != NULL) {
return;
}

update_model (app_data);
g_slist_free_full (app_data->db_data->data_to_add, json_free);
app_data->db_data->data_to_add = NULL;
}


GKeyFile *
Expand Down
3 changes: 3 additions & 0 deletions src/gui/gui-misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ void export_data_cb (GSimpleAction *simple,
gchar *update_db_from_otps (GSList *otps,
AppData *app_data);

void load_new_db (AppData *app_data,
GError **err);

G_END_DECLS
21 changes: 0 additions & 21 deletions src/gui/import-from-gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "../common/import-export.h"
#include "../common/gquarks.h"
#include "gui-misc.h"
#include "db-misc.h"


static gboolean parse_data_and_update_db (AppData *app_data,
Expand Down Expand Up @@ -41,26 +40,6 @@ import_data_cb (GSimpleAction *simple,
}


gchar *
update_db_from_otps (GSList *otps, AppData *app_data)
{
add_otps_to_db (otps, app_data->db_data);

GError *err = NULL;
update_db (app_data->db_data, &err);
if (err != NULL && !g_error_matches (err, missing_file_gquark (), MISSING_FILE_CODE)) {
return g_strdup (err->message);
}
reload_db (app_data->db_data, &err);
if (err != NULL && !g_error_matches (err, missing_file_gquark (), MISSING_FILE_CODE)) {
return g_strdup (err->message);
}
regenerate_model (app_data);

return NULL;
}


static gboolean
parse_data_and_update_db (AppData *app_data,
const gchar *filename,
Expand Down
1 change: 0 additions & 1 deletion src/gui/liststore-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "treeview.h"
#include "liststore-misc.h"
#include "../common/gquarks.h"
#include "../common/common.h"


typedef struct otp_data_t {
Expand Down
2 changes: 0 additions & 2 deletions src/gui/liststore-misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

G_BEGIN_DECLS

#include "db-misc.h"

gboolean traverse_liststore (gpointer user_data);

void set_otp (GtkListStore *list_store,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/manual-add-cb.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <gtk/gtk.h>
#include "db-misc.h"
#include "gui-misc.h"
#include "manual-add-cb.h"
#include "../common/gquarks.h"
#include "message-dialogs.h"
#include "get-builder.h"
#include "treeview.h"

static void changed_otp_cb (GtkWidget *cb,
gpointer user_data);
Expand Down
2 changes: 2 additions & 0 deletions src/gui/manual-add-cb.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "../common/db-common.h"

G_BEGIN_DECLS

typedef struct widgets_t {
Expand Down
4 changes: 2 additions & 2 deletions src/gui/new-db-cb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <gcrypt.h>
#include <libsecret/secret.h>
#include "data.h"
#include "db-misc.h"
#include "gui-misc.h"
#include "message-dialogs.h"
#include "password-cb.h"
#include "db-actions.h"
Expand Down Expand Up @@ -48,7 +48,7 @@ new_db (AppData *app_data)
}
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;
write_db_to_disk (app_data->db_data, &err);
update_db (app_data->db_data, &err);
if (err != NULL) {
show_message_dialog (app_data->main_window, err->message, GTK_MESSAGE_ERROR);
g_clear_error (&err);
Expand Down
1 change: 0 additions & 1 deletion src/gui/parse-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <jansson.h>
#include <gcrypt.h>
#include <cotp.h>
#include "db-misc.h"
#include "manual-add-cb.h"
#include "../common/gquarks.h"
#include "message-dialogs.h"
Expand Down
9 changes: 9 additions & 0 deletions src/gui/treeview.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,15 @@ reorder_db (AppData *app_data)
}


void
regenerate_model (AppData *app_data)
{
update_model (app_data);
g_slist_free_full (app_data->db_data->data_to_add, json_free);
app_data->db_data->data_to_add = NULL;
}


static void
hide_all_otps_cb (GtkTreeView *tree_view,
gpointer user_data)
Expand Down
2 changes: 2 additions & 0 deletions src/gui/treeview.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ void row_selected_cb (GtkTreeView *tree_view,

void reorder_db (AppData *app_data);

void regenerate_model (AppData *app_data);

G_END_DECLS