Browse Source

Show dialog with gtk_dialog_run.

Use the gtk_dialog_run function to display the encrypt dialog.
This make things slightly easier as we no longer need to connect
callbacks to the `clicked` signal from the buttons or the
`destroy` signal from the dialog.
master
Damien Goutte-Gattat 2 years ago
parent
commit
cba231b670
  1. 7
      src/yki-encrypt.ui
  2. 40
      src/yki.c

7
src/yki-encrypt.ui

@ -2,12 +2,11 @@
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkAction" id="action1"/>
<object class="GtkListStore" id="lstPublicKeys">
<columns>
<!-- column-name Selected -->
<column type="gboolean"/>
<!-- column-name User ID -->
<!-- column-name User -->
<column type="gchararray"/>
<!-- column-name Key -->
<column type="gpointer"/>
@ -223,8 +222,8 @@
</object>
</child>
<action-widgets>
<action-widget response="0">btnCancel</action-widget>
<action-widget response="0">btnOK</action-widget>
<action-widget response="cancel">btnCancel</action-widget>
<action-widget response="ok">btnOK</action-widget>
</action-widgets>
</object>
</interface>

40
src/yki.c

@ -34,7 +34,6 @@ typedef struct {
GtkListStore *public_keys;
unsigned selected_keys;
gboolean proceed;
gboolean symmetric;
gboolean sign;
gboolean detached;
@ -132,20 +131,6 @@ public_key_toggled(GtkCellRendererToggle *renderer,
gtk_list_store_set(GTK_LIST_STORE(yki->public_keys), &iter, 0, selected, -1);
}
static void
encrypt_dialog_confirm_clicked(GtkWidget *widget, gpointer data)
{
((yorkie_ctx_t *)data)->proceed = TRUE;
gtk_main_quit();
}
static void
encrypt_dialog_cancel_clicked(GtkWidget *widget, gpointer data)
{
((yorkie_ctx_t *)data)->proceed = FALSE;
gtk_main_quit();
}
static void
symmetric_encrypt_toggled(GtkWidget *widget, gpointer data)
{
@ -165,26 +150,16 @@ detach_sign_toggled(GtkWidget *widget, gpointer data)
}
static GtkWidget *
static GtkDialog *
create_encrypt_dialog(yorkie_ctx_t *yki)
{
GtkBuilder *builder;
GObject *window, *widget;
GObject *widget;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
builder = gtk_builder_new_from_resource("/org/incenp/Yorkie/yki-encrypt.ui");
window = gtk_builder_get_object(builder, "dlgEncrypt");
g_signal_connect(window, "close", G_CALLBACK(encrypt_dialog_cancel_clicked), yki);
g_signal_connect(window, "destroy", G_CALLBACK(encrypt_dialog_cancel_clicked), yki);
g_signal_connect(gtk_builder_get_object(builder, "btnOK"),
"clicked", G_CALLBACK(encrypt_dialog_confirm_clicked), yki);
g_signal_connect(gtk_builder_get_object(builder, "btnCancel"),
"clicked", G_CALLBACK(encrypt_dialog_cancel_clicked), yki);
g_signal_connect(gtk_builder_get_object(builder, "chkSymEncrypt"),
"clicked", G_CALLBACK(symmetric_encrypt_toggled), yki);
@ -206,7 +181,7 @@ create_encrypt_dialog(yorkie_ctx_t *yki)
column = gtk_tree_view_column_new_with_attributes("User ID", renderer, "text", 1, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(widget), column);
return GTK_WIDGET(window);
return GTK_DIALOG(gtk_builder_get_object(builder, "dlgEncrypt"));
}
@ -214,11 +189,11 @@ int
main(int argc, char **argv)
{
yorkie_ctx_t yki;
GtkWidget *dlg;
GtkDialog *dlg;
gpgme_error_t gerr;
yki.selected_keys = 0;
yki.symmetric = yki.sign = yki.detached = yki.proceed = FALSE;
yki.symmetric = yki.sign = yki.detached = FALSE;
gtk_init(&argc, &argv);
if ( argc != 2 )
@ -228,10 +203,7 @@ main(int argc, char **argv)
dlg = create_encrypt_dialog(&yki);
populate_public_key_list(&yki);
gtk_widget_show_all(dlg);
gtk_main();
if ( can_proceed(yki) ) {
if ( gtk_dialog_run(dlg) == GTK_RESPONSE_OK && can_proceed(yki) ) {
FILE *in, *out;
gpgme_data_t gin, gout;
gchar *outname;

Loading…
Cancel
Save