Browse Source

Move the Yorkie context to a separate module.

Use a dedicated module to store the yki_ctx_t structure and
associated helper functions. Also rename the structure from
the original yorkie_ctx_t to yki_ctx_t for consistency.
master
Damien Goutte-Gattat 2 years ago
parent
commit
1f6371c3c3
  1. 2
      src/Makefile.am
  2. 40
      src/yki.c
  3. 47
      src/ykiutil.c
  4. 51
      src/ykiutil.h

2
src/Makefile.am

@ -1,7 +1,7 @@
bin_PROGRAMS = yki
yki_SOURCES = yki.c gpgutil.c gpgutil.h error.c error.h errors.h \
yki-encrypt.ui resources.xml
ykiutil.c ykiutil.h yki-encrypt.ui resources.xml
nodist_yki_SOURCES = resources.c

40
src/yki.c

@ -29,17 +29,7 @@
#include "error.h"
#include "gpgutil.h"
typedef struct {
gpgme_ctx_t gpgme;
GtkListStore *public_keys;
unsigned selected_keys;
gboolean symmetric;
gboolean sign;
gboolean detached;
} yorkie_ctx_t;
#include "ykiutil.h"
static int
@ -75,7 +65,7 @@ populate_public_key_list(gpgme_ctx_t ctx, GtkListStore *key_list, GError **error
}
static gpgme_key_t *
get_selected_keys(yorkie_ctx_t *yki)
get_selected_keys(yki_ctx_t *yki)
{
gpgme_key_t *keys;
GtkTreeIter iter;
@ -115,7 +105,7 @@ free_key_in_list(GtkTreeModel *store, GtkTreePath *path, GtkTreeIter *iter, gpoi
}
static gpgme_error_t
encrypt_or_sign_buffer(yorkie_ctx_t *yki, gpgme_data_t in, gpgme_data_t out)
encrypt_or_sign_buffer(yki_ctx_t *yki, gpgme_data_t in, gpgme_data_t out)
{
gpgme_error_t gerr;
@ -147,7 +137,7 @@ public_key_toggled(GtkCellRendererToggle *renderer,
gchar *path,
gpointer data)
{
yorkie_ctx_t *yki = (yorkie_ctx_t *)data;
yki_ctx_t *yki = (yki_ctx_t *)data;
GtkTreeIter iter;
gboolean selected;
@ -163,24 +153,24 @@ public_key_toggled(GtkCellRendererToggle *renderer,
static void
symmetric_encrypt_toggled(GtkWidget *widget, gpointer data)
{
((yorkie_ctx_t *)data)->symmetric = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
((yki_ctx_t *)data)->symmetric = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
}
void
sign_toggled(GtkWidget *widget, gpointer data)
{
((yorkie_ctx_t *)data)->sign = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
((yki_ctx_t *)data)->sign = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
}
void
detach_sign_toggled(GtkWidget *widget, gpointer data)
{
((yorkie_ctx_t *)data)->detached = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
((yki_ctx_t *)data)->detached = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
}
static GtkDialog *
create_encrypt_dialog(yorkie_ctx_t *yki)
create_encrypt_dialog(yki_ctx_t *yki)
{
GtkBuilder *builder;
GObject *widget;
@ -214,7 +204,7 @@ create_encrypt_dialog(yorkie_ctx_t *yki)
}
static int
encrypt_or_sign_file(yorkie_ctx_t *yki, const char *filename, GError **error)
encrypt_or_sign_file(yki_ctx_t *yki, const char *filename, GError **error)
{
gpgutil_file_t in, out;
gchar *outname;
@ -241,13 +231,10 @@ encrypt_or_sign_file(yorkie_ctx_t *yki, const char *filename, GError **error)
}
static int
do_encrypt(yorkie_ctx_t *yki, const char *file, GError **error)
do_encrypt(yki_ctx_t *yki, const char *file, GError **error)
{
GtkDialog *dlg;
yki->selected_keys = 0;
yki->symmetric = yki->sign = yki->detached = FALSE;
dlg = create_encrypt_dialog(yki);
populate_public_key_list(yki->gpgme, yki->public_keys, error);
if ( ! *error && gtk_dialog_run(dlg) == GTK_RESPONSE_OK && can_proceed(*yki) )
@ -281,7 +268,7 @@ check_non_option_args(GOptionContext *parser, GOptionGroup *group, gpointer data
int
main(int argc, char **argv)
{
yorkie_ctx_t yki;
yki_ctx_t yki;
GError *error = NULL;
gboolean encrypt;
gchar **files;
@ -308,7 +295,7 @@ main(int argc, char **argv)
g_option_context_parse(parser, &argc, &argv, &error);
if ( ! error )
yki.gpgme = gpgutil_initialize(&error);
yki_init(&yki, &error);
if ( ! error ) {
if ( encrypt )
@ -322,8 +309,7 @@ main(int argc, char **argv)
g_option_context_free(parser);
g_strfreev(files);
if ( yki.gpgme )
gpgme_release(yki.gpgme);
yki_release(&yki);
return error ? EXIT_FAILURE : EXIT_SUCCESS;
}

47
src/ykiutil.c

@ -0,0 +1,47 @@
/*
* Yorkie - A task-oriented GnuPG frontend
* Copyright (C) 2020 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "ykiutil.h"
#include "gpgutil.h"
int
yki_init(yki_ctx_t *yki, GError **error)
{
g_assert(yki);
yki->gpgme = gpgutil_initialize(error);
yki->public_keys = NULL;
yki->selected_keys = 0;
yki->symmetric = yki->sign = yki->detached = FALSE;
return yki->gpgme != NULL;
}
void
yki_release(yki_ctx_t *yki)
{
g_assert(yki);
if ( yki->gpgme )
gpgme_release(yki->gpgme);
}

51
src/ykiutil.h

@ -0,0 +1,51 @@
/*
* Yorkie - A task-oriented GnuPG frontend
* Copyright (C) 2020 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ICP20200503_YKIUTIL_H
#define ICP20200503_YKIUTIL_H
#include <glib.h>
#include <gtk/gtk.h>
#include <gpgme.h>
typedef struct {
gpgme_ctx_t gpgme;
GtkListStore *public_keys;
unsigned selected_keys;
gboolean symmetric;
gboolean sign;
gboolean detached;
} yki_ctx_t;
#ifdef __cpluscplus
extern "C" {
#endif
int
yki_init(yki_ctx_t *, GError **);
void
yki_release(yki_ctx_t *);
#ifdef __cplusplus
}
#endif
#endif /* !ICP20200503_YKIUTIL_H */
Loading…
Cancel
Save