diff --git a/src/db-misc.c b/src/db-misc.c
index cbe4d04..c40bce1 100644
--- a/src/db-misc.c
+++ b/src/db-misc.c
@@ -14,25 +14,41 @@ typedef struct header_data_t {
guint8 salt[KDF_SALT_SIZE];
} HeaderData;
-static void reload_db (DatabaseData *db_data, GError **err);
+static void reload_db (DatabaseData *db_data,
+ GError **err);
-static void update_db (DatabaseData *db_data, GError **err);
+static void update_db (DatabaseData *db_data,
+ GError **err);
-static gpointer encrypt_db (const gchar *db_path, const gchar *in_memory_json, const gchar *password, GError **err);
+static gpointer encrypt_db (const gchar *db_path,
+ const gchar *in_memory_json,
+ const gchar *password,
+ GError **err);
-static inline void add_to_json (gpointer list_elem, gpointer json_array);
+static inline void add_to_json (gpointer list_elem,
+ gpointer json_array);
-static gchar *decrypt_db (const gchar *db_path, const gchar *password);
+static gchar *decrypt_db (const gchar *db_path,
+ const gchar *password);
-static guchar *get_derived_key (const gchar *pwd, HeaderData *header_data);
+static guchar *get_derived_key (const gchar *pwd,
+ HeaderData *header_data);
-static void backup_db (const gchar *path);
+static void backup_db (const gchar *path);
-static void restore_db (const gchar *path);
+static void restore_db (const gchar *path);
-static inline void json_free (gpointer data);
+static inline void json_free (gpointer data);
-static void cleanup (GFile *, gpointer, HeaderData *, GError *);
+static void cleanup_gfile (GFile *file,
+ gpointer stream,
+ GError *err);
+
+static void free_resources (gcry_cipher_hd_t hd,
+ guchar *derived_key,
+ guchar *enc_buf,
+ gchar *dec_buf,
+ HeaderData *header_data);
void
@@ -213,20 +229,23 @@ encrypt_db (const gchar *db_path,
if (local_err != NULL) {
g_printerr ("%s\n", local_err->message);
g_set_error (err, generic_error_gquark (), GENERIC_ERRCODE, "Failed to replace existing file");
- cleanup (out_file, NULL, header_data, local_err);
+ cleanup_gfile (out_file, NULL, local_err);
+ g_free (header_data);
return GENERIC_ERROR;
}
if (g_output_stream_write (G_OUTPUT_STREAM (out_stream), header_data, sizeof (HeaderData), NULL, &local_err) == -1) {
g_printerr ("%s\n", local_err->message);
g_set_error (err, generic_error_gquark (), GENERIC_ERRCODE, "Failed while writing header data to file");
- cleanup (out_file, out_stream, header_data, local_err);
+ cleanup_gfile (out_file, out_stream, local_err);
+ g_free (header_data);
return GENERIC_ERROR;
}
guchar *derived_key = get_derived_key (password, header_data);
if (derived_key == SECURE_MEMORY_ALLOC_ERR || derived_key == KEY_DERIV_ERR) {
- cleanup (out_file, out_stream, header_data, local_err);
g_set_error (err, generic_error_gquark (), GENERIC_ERRCODE, "Failed to derive key.\nPlease check Secure Memory wiki page");
+ cleanup_gfile (out_file, out_stream, local_err);
+ g_free (header_data);
return (gpointer)derived_key;
}
@@ -235,28 +254,23 @@ encrypt_db (const gchar *db_path,
gcry_cipher_hd_t hd = open_cipher_and_set_data (derived_key, header_data->iv, IV_SIZE);
if (hd == NULL) {
- gcry_free (derived_key);
- g_free (header_data);
- g_free (enc_buffer);
+ cleanup_gfile (out_file, out_stream, local_err);
+ free_resources (NULL, derived_key, enc_buffer, NULL, header_data);
return NULL;
}
gpg_error_t gpg_err = gcry_cipher_authenticate (hd, header_data, sizeof (HeaderData));
if (gpg_err) {
g_printerr ("%s\n", _("Error while processing the authenticated data."));
- gcry_free (derived_key);
- g_free (header_data);
- g_free (enc_buffer);
- gcry_cipher_close (hd);
+ cleanup_gfile (out_file, out_stream, local_err);
+ free_resources (hd, derived_key, enc_buffer, NULL, header_data);
return GENERIC_ERROR;
}
gpg_err = gcry_cipher_encrypt (hd, enc_buffer, input_data_len, in_memory_json, input_data_len);
if (gpg_err) {
g_printerr ("%s\n", _("Error while encrypting the data."));
- gcry_free (derived_key);
- g_free (enc_buffer);
- g_free (header_data);
- gcry_cipher_close (hd);
+ cleanup_gfile (out_file, out_stream, local_err);
+ free_resources (hd, derived_key, enc_buffer, NULL, header_data);
return GENERIC_ERROR;
}
@@ -264,34 +278,26 @@ encrypt_db (const gchar *db_path,
gpg_err = gcry_cipher_gettag (hd, tag, TAG_SIZE); //append tag to outfile
if (gpg_err) {
g_printerr ("%s\n", _("Error while getting the tag."));
- gcry_free (derived_key);
- g_free (enc_buffer);
- g_free (header_data);
- gcry_cipher_close (hd);
+ cleanup_gfile (out_file, out_stream, local_err);
+ free_resources (hd, derived_key, enc_buffer, NULL, header_data);
return GENERIC_ERROR;
}
if (g_output_stream_write (G_OUTPUT_STREAM(out_stream), enc_buffer, input_data_len, NULL, &local_err) == -1) {
g_set_error (err, generic_error_gquark (), GENERIC_ERRCODE, "Failed while writing encrypted buffer to file");
- cleanup (out_file, out_stream, header_data, local_err);
- g_free (enc_buffer);
- gcry_free (derived_key);
- gcry_cipher_close (hd);
+ cleanup_gfile (out_file, out_stream, local_err);
+ free_resources (hd, derived_key, enc_buffer, NULL, header_data);
return GENERIC_ERROR;
}
if (g_output_stream_write (G_OUTPUT_STREAM(out_stream), tag, TAG_SIZE, NULL, &local_err) == -1) {
g_set_error (err, generic_error_gquark (), GENERIC_ERRCODE, "Failed while writing tag data to file");
- cleanup (out_file, out_stream, header_data, local_err);
- g_free (enc_buffer);
- gcry_free (derived_key);
- gcry_cipher_close (hd);
+ cleanup_gfile (out_file, out_stream, local_err);
+ free_resources (hd, derived_key, enc_buffer, NULL, header_data);
return GENERIC_ERROR;
}
- g_free (enc_buffer);
- gcry_free (derived_key);
- gcry_cipher_close (hd);
- cleanup (out_file, out_stream, header_data, NULL);
+ free_resources (hd, derived_key, enc_buffer, NULL, header_data);
+ cleanup_gfile (out_file, out_stream, NULL);
return NULL;
}
@@ -310,24 +316,28 @@ decrypt_db (const gchar *db_path,
GFileInputStream *in_stream = g_file_read (in_file, NULL, &err);
if (err != NULL) {
g_printerr ("%s\n", err->message);
- cleanup (in_file, NULL, header_data, err);
+ cleanup_gfile (in_file, NULL, err);
+ g_free (header_data);
return GENERIC_ERROR;
}
if (g_input_stream_read (G_INPUT_STREAM (in_stream), header_data, sizeof (HeaderData), NULL, &err) == -1) {
g_printerr ("%s\n", err->message);
- cleanup (in_file, in_stream, header_data, err);
+ cleanup_gfile (in_file, in_stream, err);
+ g_free (header_data);
return GENERIC_ERROR;
}
guchar tag[TAG_SIZE];
if (!g_seekable_seek (G_SEEKABLE (in_stream), input_file_size - TAG_SIZE, G_SEEK_SET, NULL, &err)) {
g_printerr ("%s\n", err->message);
- cleanup (in_file, in_stream, header_data, err);
+ cleanup_gfile (in_file, in_stream, err);
+ g_free (header_data);
return GENERIC_ERROR;
}
if (g_input_stream_read (G_INPUT_STREAM (in_stream), tag, TAG_SIZE, NULL, &err) == -1) {
g_printerr ("%s\n", err->message);
- cleanup (in_file, in_stream, header_data, err);
+ cleanup_gfile (in_file, in_stream, err);
+ g_free (header_data);
return GENERIC_ERROR;
}
@@ -336,14 +346,14 @@ decrypt_db (const gchar *db_path,
if (!g_seekable_seek (G_SEEKABLE (in_stream), sizeof (HeaderData), G_SEEK_SET, NULL, &err)) {
g_printerr ("%s\n", err->message);
- cleanup (in_file, in_stream, header_data, err);
- g_free (enc_buf);
+ cleanup_gfile (in_file, in_stream, err);
+
return GENERIC_ERROR;
}
if (g_input_stream_read (G_INPUT_STREAM (in_stream), enc_buf, enc_buf_size, NULL, &err) == -1) {
g_printerr ("%s\n", err->message);
- cleanup (in_file, in_stream, header_data, err);
- g_free (enc_buf);
+ cleanup_gfile (in_file, in_stream, err);
+ free_resources (NULL, NULL, enc_buf, NULL, header_data);
return GENERIC_ERROR;
}
g_object_unref (in_stream);
@@ -351,61 +361,41 @@ decrypt_db (const gchar *db_path,
guchar *derived_key = get_derived_key (password, header_data);
if (derived_key == SECURE_MEMORY_ALLOC_ERR || derived_key == KEY_DERIV_ERR) {
- g_free (header_data);
- g_free (enc_buf);
+ free_resources (NULL, NULL, enc_buf, NULL, header_data);
return (gpointer)derived_key;
}
gcry_cipher_hd_t hd = open_cipher_and_set_data (derived_key, header_data->iv, IV_SIZE);
if (hd == NULL) {
- gcry_free (derived_key);
- g_free (enc_buf);
- g_free (header_data);
+ free_resources (NULL, derived_key, enc_buf, NULL, header_data);
return GENERIC_ERROR;
}
gpg_error_t gpg_err = gcry_cipher_authenticate (hd, header_data, sizeof (HeaderData));
if (gpg_err) {
g_printerr ("%s\n", _("Error while processing the authenticated data."));
- gcry_free (derived_key);
- g_free (header_data);
- g_free (enc_buf);
- gcry_cipher_close (hd);
+ free_resources (hd, derived_key, enc_buf, NULL, header_data);
return GENERIC_ERROR;
}
gchar *dec_buf = gcry_calloc_secure (enc_buf_size, 1);
if (dec_buf == NULL) {
g_printerr ("%s\n", _("Error while allocating secure memory."));
- gcry_free (derived_key);
- g_free (header_data);
- g_free (enc_buf);
- gcry_cipher_close (hd);
+ free_resources (hd, derived_key, enc_buf, NULL, header_data);
return GENERIC_ERROR;
}
gpg_err = gcry_cipher_decrypt (hd, dec_buf, enc_buf_size, enc_buf, enc_buf_size);
if (gpg_err) {
g_printerr ("%s\n", _("Error while decrypting the data."));
- gcry_free (derived_key);
- gcry_free (dec_buf);
- g_free (header_data);
- g_free (enc_buf);
- gcry_cipher_close (hd);
+ free_resources (hd, derived_key, enc_buf, dec_buf, header_data);
return GENERIC_ERROR;
}
if (gcry_err_code (gcry_cipher_checktag (hd, tag, TAG_SIZE)) == GPG_ERR_CHECKSUM) {
- gcry_cipher_close (hd);
- gcry_free (derived_key);
- gcry_free (dec_buf);
- g_free (header_data);
- g_free (enc_buf);
+ free_resources (hd, derived_key, enc_buf, dec_buf, header_data);
return TAG_MISMATCH;
}
- gcry_cipher_close (hd);
- gcry_free (derived_key);
- g_free (header_data);
- g_free (enc_buf);
+ free_resources (hd, derived_key, enc_buf, NULL, header_data);
return dec_buf;
}
@@ -435,38 +425,42 @@ get_derived_key (const gchar *pwd,
static void
-backup_db (const gchar *path)
+perform_backup_restore (const gchar *path,
+ gboolean is_backup)
{
GError *err = NULL;
- GFile *src = g_file_new_for_path (path);
- gchar *dst_path = g_strconcat (path, ".bak", NULL);
+ gchar *src_path = is_backup ? g_strdup (path) : g_strconcat (path, ".bak", NULL);
+ gchar *dst_path = is_backup ? g_strconcat (path, ".bak", NULL) : g_strdup (path);
+
+ GFile *src = g_file_new_for_path (src_path);
GFile *dst = g_file_new_for_path (dst_path);
+
+ g_free (src_path);
g_free (dst_path);
+
if (!g_file_copy (src, dst, G_FILE_COPY_OVERWRITE | G_FILE_COPY_NOFOLLOW_SYMLINKS, NULL, NULL, NULL, &err)) {
- g_printerr ("Couldn't create the backup file: %s\n", err->message);
+ g_printerr ("Couldn't %s: %s\n", is_backup ? "create the backup" : "restore the backup", err->message);
g_clear_error (&err);
+ } else {
+ g_print("%s\n", is_backup ? _("Backup copy successfully created.") : _("Backup copy successfully restored."));
}
+
g_object_unref (src);
g_object_unref (dst);
}
+static void
+backup_db (const gchar *path)
+{
+ perform_backup_restore (path, TRUE);
+}
+
+
static void
restore_db (const gchar *path)
{
- GError *err = NULL;
- gchar *src_path = g_strconcat (path, ".bak", NULL);
- GFile *src = g_file_new_for_path (src_path);
- GFile *dst = g_file_new_for_path (path);
- g_free (src_path);
- if (!g_file_copy (src, dst, G_FILE_COPY_OVERWRITE | G_FILE_COPY_NOFOLLOW_SYMLINKS, NULL, NULL, NULL, &err)) {
- g_printerr ("Couldn't restore the backup file: %s\n", err->message);
- g_clear_error (&err);
- } else {
- g_print ("%s\n", _("Backup copy successfully restored."));
- }
- g_object_unref (src);
- g_object_unref (dst);
+ perform_backup_restore (path, FALSE);
}
@@ -478,16 +472,32 @@ json_free (gpointer data)
static void
-cleanup (GFile *in_file,
- gpointer in_stream,
- HeaderData *header_data,
- GError *err)
+cleanup_gfile (GFile *file,
+ gpointer stream,
+ GError *err)
{
- g_object_unref (in_file);
- if (in_stream != NULL)
- g_object_unref (in_stream);
- if (header_data != NULL)
- g_free (header_data);
- if (err != NULL)
- g_clear_error (&err);
+ g_object_unref (file);
+ g_clear_error (&err);
+
+ if (stream != NULL)
+ g_object_unref (stream);
}
+
+
+static void
+free_resources (gcry_cipher_hd_t hd,
+ guchar *derived_key,
+ guchar *enc_buf,
+ gchar *dec_buf,
+ HeaderData *header_data)
+{
+ g_free (enc_buf);
+ g_free (header_data);
+
+ if (hd != NULL)
+ gcry_cipher_close (hd);
+ if (derived_key != NULL)
+ gcry_free (derived_key);
+ if (dec_buf != NULL)
+ gcry_free (dec_buf);
+}
\ No newline at end of file
diff --git a/src/dbinfo-cb.c b/src/dbinfo-cb.c
index cee6923..22c152e 100644
--- a/src/dbinfo-cb.c
+++ b/src/dbinfo-cb.c
@@ -3,8 +3,8 @@
void
dbinfo_cb (GSimpleAction *simple __attribute__((unused)),
- GVariant *parameter __attribute__((unused)),
- gpointer user_data)
+ GVariant *parameter __attribute__((unused)),
+ gpointer user_data)
{
AppData *app_data = (AppData *)user_data;
diff --git a/src/dbinfo-cb.h b/src/dbinfo-cb.h
index e180f2f..91ae09f 100644
--- a/src/dbinfo-cb.h
+++ b/src/dbinfo-cb.h
@@ -4,8 +4,8 @@
G_BEGIN_DECLS
-void dbinfo_cb (GSimpleAction *simple,
- GVariant *parameter,
- gpointer user_data);
+void dbinfo_cb (GSimpleAction *simple,
+ GVariant *parameter,
+ gpointer user_data);
G_END_DECLS
\ No newline at end of file
diff --git a/src/edit-row-cb.h b/src/edit-row-cb.h
index f0baec7..b9aa5ee 100644
--- a/src/edit-row-cb.h
+++ b/src/edit-row-cb.h
@@ -4,11 +4,11 @@
G_BEGIN_DECLS
-void edit_row_cb (GSimpleAction *simple,
- GVariant *parameter,
- gpointer user_data);
+void edit_row_cb (GSimpleAction *simple,
+ GVariant *parameter,
+ gpointer user_data);
-void edit_row_cb_shortcut (GtkWidget *w,
- gpointer user_data);
+void edit_row_cb_shortcut (GtkWidget *w,
+ gpointer user_data);
G_END_DECLS
\ No newline at end of file
diff --git a/src/password-cb.c b/src/password-cb.c
index 6ea90db..55d8235 100644
--- a/src/password-cb.c
+++ b/src/password-cb.c
@@ -3,7 +3,6 @@
#include "gui-common.h"
#include "message-dialogs.h"
#include "get-builder.h"
-#include "otpclient.h"
#include "common/common.h"
typedef struct entrywidgets_t {
diff --git a/src/qrcode-parser.c b/src/qrcode-parser.c
index 0a84f99..4c4a987 100644
--- a/src/qrcode-parser.c
+++ b/src/qrcode-parser.c
@@ -19,7 +19,6 @@ gchar *
parse_qrcode (const gchar *png_path,
gchar **otpauth_uri)
{
-
zbar_image_scanner_t *scanner = zbar_image_scanner_create ();
zbar_image_scanner_set_config (scanner, ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
diff --git a/src/setup-signals-shortcuts.c b/src/setup-signals-shortcuts.c
index e2f2e6e..a0d1d7c 100644
--- a/src/setup-signals-shortcuts.c
+++ b/src/setup-signals-shortcuts.c
@@ -9,6 +9,12 @@
#include "show-qr-cb.h"
#include "change-db-cb.h"
+static const char *signal_names[] = {
+ "toggle-reorder-button", "toggle-delete-button", "lock-app",
+ "change-db", "change-pwd", "show-settings", "show-kb-shortcuts",
+ "scan-webcam", "manual-add", "edit-row", "show-qr"
+};
+
static void setup_signals (void);
static void connect_signals (AppData *app_data);
@@ -24,51 +30,52 @@ setup_kb_shortcuts (AppData *app_data)
GtkBindingSet *mw_binding_set = gtk_binding_set_by_class (GTK_APPLICATION_WINDOW_GET_CLASS(app_data->main_window));
- gtk_binding_entry_add_signal(mw_binding_set, GDK_KEY_r, GDK_CONTROL_MASK, "toggle-reorder-button", 0);
- gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_d, GDK_CONTROL_MASK, "toggle-delete-button", 0);
+ gtk_binding_entry_add_signal(mw_binding_set, GDK_KEY_r, GDK_CONTROL_MASK, signal_names[0], 0);
+ gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_d, GDK_CONTROL_MASK, signal_names[1], 0);
if (app_data->auto_lock == TRUE || app_data->inactivity_timeout > 0) {
// auto-lock is enabled, so secret service is disabled, therefore we allow the shortcut
- gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_l, GDK_CONTROL_MASK, "lock-app", 0);
+ gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_l, GDK_CONTROL_MASK, signal_names[2], 0);
}
- gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_b, GDK_CONTROL_MASK, "change-db", 0);
- gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_o, GDK_CONTROL_MASK, "change-pwd", 0);
- gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_s, GDK_CONTROL_MASK, "show-settings", 0);
- gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_k, GDK_CONTROL_MASK, "show-kb-shortcuts", 0);
+ gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_b, GDK_CONTROL_MASK, signal_names[3], 0);
+ gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_o, GDK_CONTROL_MASK, signal_names[4], 0);
+ gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_s, GDK_CONTROL_MASK, signal_names[5], 0);
+ gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_k, GDK_CONTROL_MASK, signal_names[6], 0);
// GDM_MOD1_MASK: the fourth modifier key (it depends on the modifier mapping of the X server which key is interpreted as this modifier, but normally it is the Alt key).
- gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_w, GDK_MOD1_MASK, "scan-webcam", 0);
- gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_m, GDK_MOD1_MASK, "manual-add", 0);
- gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_e, GDK_MOD1_MASK, "edit-row", 0);
- gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_q, GDK_MOD1_MASK, "show-qr", 0);
+ gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_w, GDK_MOD1_MASK, signal_names[7], 0);
+ gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_m, GDK_MOD1_MASK, signal_names[8], 0);
+ gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_e, GDK_MOD1_MASK, signal_names[9], 0);
+ gtk_binding_entry_add_signal (mw_binding_set, GDK_KEY_q, GDK_MOD1_MASK, signal_names[10], 0);
}
static void
setup_signals (void)
{
- g_signal_new ("toggle-reorder-button", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
- g_signal_new ("toggle-delete-button", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
- g_signal_new ("lock-app", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
- g_signal_new ("change-db", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
- g_signal_new ("change-pwd", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
- g_signal_new ("show-settings", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
- g_signal_new ("show-kb-shortcuts", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
- g_signal_new ("scan-webcam", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
- g_signal_new ("manual-add", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
- g_signal_new ("edit-row", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
- g_signal_new ("show-qr", G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
+ for (int i = 0; i < G_N_ELEMENTS(signal_names); ++i) {
+ g_signal_new (signal_names[i], G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
+ }
}
static void
connect_signals (AppData *app_data)
{
- g_signal_connect (app_data->main_window, "change-db", G_CALLBACK(change_db_cb_shortcut), app_data);
- g_signal_connect (app_data->main_window, "change-pwd", G_CALLBACK(change_pwd_cb_shortcut), app_data);
- g_signal_connect (app_data->main_window, "show-settings", G_CALLBACK(show_settings_cb_shortcut), app_data);
- g_signal_connect (app_data->main_window, "show-kb-shortcuts", G_CALLBACK(show_kbs_cb_shortcut), app_data);
- g_signal_connect (app_data->main_window, "scan-webcam", G_CALLBACK(webcam_add_cb_shortcut), app_data);
- g_signal_connect (app_data->main_window, "manual-add", G_CALLBACK(manual_add_cb_shortcut), app_data);
- g_signal_connect (app_data->main_window, "edit-row", G_CALLBACK(edit_row_cb_shortcut), app_data);
- g_signal_connect (app_data->main_window, "show-qr", G_CALLBACK(show_qr_cb_shortcut), app_data);
+ struct {
+ const char *signal_name;
+ GCallback callback;
+ } signal_connections[] = {
+ {"change-db", G_CALLBACK(change_db_cb_shortcut)},
+ {"change-pwd", G_CALLBACK(change_pwd_cb_shortcut)},
+ {"show-settings", G_CALLBACK(show_settings_cb_shortcut)},
+ {"show-kb-shortcuts", G_CALLBACK(show_kbs_cb_shortcut)},
+ {"scan-webcam", G_CALLBACK(webcam_add_cb_shortcut)},
+ {"manual-add", G_CALLBACK(manual_add_cb_shortcut)},
+ {"edit-row", G_CALLBACK(edit_row_cb_shortcut)},
+ {"show-qr", G_CALLBACK(show_qr_cb_shortcut)}
+ };
+
+ for (int i = 0; i < G_N_ELEMENTS(signal_connections); ++i) {
+ g_signal_connect (app_data->main_window, signal_connections[i].signal_name, signal_connections[i].callback, app_data);
+ }
}
\ No newline at end of file
diff --git a/src/treeview.c b/src/treeview.c
index 67f4b34..967d8da 100644
--- a/src/treeview.c
+++ b/src/treeview.c
@@ -277,9 +277,9 @@ set_json_data (json_t *array,
ParsedData *pjd)
{
gsize array_len = json_array_size (array);
- pjd->types = (gchar **) g_malloc0 ((array_len + 1) * sizeof (gchar *));
- pjd->labels = (gchar **) g_malloc0 ((array_len + 1) * sizeof (gchar *));
- pjd->issuers = (gchar **) g_malloc0 ((array_len + 1) * sizeof (gchar *));
+ pjd->types = (gchar **)g_malloc0 ((array_len + 1) * sizeof(gchar *));
+ pjd->labels = (gchar **)g_malloc0 ((array_len + 1) * sizeof(gchar *));
+ pjd->issuers = (gchar **)g_malloc0 ((array_len + 1) * sizeof(gchar *));
pjd->periods = g_array_new (FALSE, FALSE, sizeof(gint));
for (guint i = 0; i < array_len; i++) {
json_t *obj = json_array_get (array, i);
@@ -323,51 +323,33 @@ add_data_to_model (DatabaseData *db_data,
static void
-add_columns (GtkTreeView *tree_view)
+add_column_with_attributes (GtkTreeView *tree_view,
+ const gchar *title,
+ gint column_id,
+ gboolean visible)
{
GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
- GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes ("Type", renderer, "text", COLUMN_TYPE, NULL);
- gtk_tree_view_append_column (tree_view, column);
-
- renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes ("Account", renderer, "text", COLUMN_ACC_LABEL, NULL);
- gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN(column), GTK_TREE_VIEW_COLUMN_AUTOSIZE);
- gtk_tree_view_append_column (tree_view, column);
-
- renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes ("Issuer", renderer, "text", COLUMN_ACC_ISSUER, NULL);
- gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN(column), GTK_TREE_VIEW_COLUMN_AUTOSIZE);
- gtk_tree_view_append_column (tree_view, column);
-
- renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes ("OTP Value", renderer, "text", COLUMN_OTP, NULL);
- gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN(column), GTK_TREE_VIEW_COLUMN_AUTOSIZE);
- gtk_tree_view_append_column (tree_view, column);
-
- renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes ("Validity", renderer, "text", COLUMN_VALIDITY, NULL);
- gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN(column), GTK_TREE_VIEW_COLUMN_AUTOSIZE);
- gtk_tree_view_append_column (tree_view, column);
-
- renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes ("Period", renderer, "text", COLUMN_PERIOD, NULL);
- gtk_tree_view_column_set_visible (column, FALSE);
- gtk_tree_view_append_column (tree_view, column);
-
- renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes ("Updated", renderer, "text", COLUMN_UPDATED, NULL);
- gtk_tree_view_column_set_visible (column, FALSE);
+ GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes (title, renderer, "text", column_id, NULL);
+ gtk_tree_view_column_set_visible (column, visible);
gtk_tree_view_append_column (tree_view, column);
+}
- renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes ("Less Than a Minute", renderer, "text", COLUMN_LESS_THAN_A_MINUTE, NULL);
- gtk_tree_view_column_set_visible (column, FALSE);
- gtk_tree_view_append_column (tree_view, column);
- renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes ("Position in Database", renderer, "text", COLUMN_POSITION_IN_DB, NULL);
- gtk_tree_view_column_set_visible (column, FALSE);
- gtk_tree_view_append_column (tree_view, column);
+static void
+add_columns (GtkTreeView *tree_view)
+{
+ // Main columns
+ add_column_with_attributes (tree_view, "Type", COLUMN_TYPE, TRUE);
+ add_column_with_attributes (tree_view, "Account", COLUMN_ACC_LABEL, TRUE);
+ add_column_with_attributes (tree_view, "Issuer", COLUMN_ACC_ISSUER, TRUE);
+ add_column_with_attributes (tree_view, "OTP Value", COLUMN_OTP, TRUE);
+ add_column_with_attributes (tree_view, "Validity", COLUMN_VALIDITY, TRUE);
+
+ // Additional columns (hidden by default)
+ add_column_with_attributes (tree_view, "Period", COLUMN_PERIOD, FALSE);
+ add_column_with_attributes (tree_view, "Updated", COLUMN_UPDATED, FALSE);
+ add_column_with_attributes (tree_view, "Less Than a Minute", COLUMN_LESS_THAN_A_MINUTE, FALSE);
+ add_column_with_attributes (tree_view, "Position in Database", COLUMN_POSITION_IN_DB, FALSE);
}
diff --git a/src/webcam-add-cb.c b/src/webcam-add-cb.c
index f3b6d87..9e099b3 100644
--- a/src/webcam-add-cb.c
+++ b/src/webcam-add-cb.c
@@ -2,7 +2,6 @@
#include
#include
#include "imports.h"
-#include "parse-uri.h"
#include "message-dialogs.h"
#include "get-builder.h"
#include "common/common.h"