G_MODULE_EXPORT void on_gpgme_add_subkey_ok_clicked (GtkButton *button, gpointer user_data) { SeahorseWidget *swidget = SEAHORSE_WIDGET (user_data); SeahorseObjectWidget *skwidget; SeahorseKeyEncType real_type; gint type; guint length; time_t expires; gpgme_error_t err; GtkWidget *widget; GtkComboBox *combo; GtkTreeModel *model; GtkTreeIter iter; skwidget = SEAHORSE_OBJECT_WIDGET (swidget); combo = GTK_COMBO_BOX (seahorse_widget_get_widget (swidget, "type")); gtk_combo_box_get_active_iter (combo, &iter); model = gtk_combo_box_get_model (combo); gtk_tree_model_get (model, &iter, COMBO_INT, &type, -1); length = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON ( seahorse_widget_get_widget (swidget, LENGTH))); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ( seahorse_widget_get_widget (swidget, "never_expires")))) expires = 0; else { widget = GTK_WIDGET (g_object_get_data (G_OBJECT (swidget), "expires-datetime")); g_return_if_fail (widget); egg_datetime_get_as_time_t (EGG_DATETIME (widget), &expires); } switch (type) { case 0: real_type = DSA; break; case 1: real_type = ELGAMAL; break; case 2: real_type = RSA_SIGN; break; default: real_type = RSA_ENCRYPT; break; } widget = GTK_WIDGET (seahorse_widget_get_widget (swidget, swidget->name)); gtk_widget_set_sensitive (widget, FALSE); err = seahorse_gpgme_key_op_add_subkey (SEAHORSE_GPGME_KEY (skwidget->object), real_type, length, expires); gtk_widget_set_sensitive (widget, TRUE); if (!GPG_IS_OK (err)) seahorse_gpgme_handle_error (err, _("Couldn't add subkey")); seahorse_widget_destroy (swidget); }
/** * on_gpgme_generate_response: * @dialog: * @response: the user's response * @swidget: the bastile main widget * * If everything is allright, a passphrase is requested and the key will be * generated * */ G_MODULE_EXPORT void on_gpgme_generate_response (GtkDialog *dialog, guint response, BastileWidget *swidget) { BastileGpgmeSource *sksrc; GtkWidget *widget; gchar *name; const gchar *email; const gchar *comment; gint sel; guint type; time_t expires; guint bits; if (response == GTK_RESPONSE_HELP) { bastile_widget_show_help (swidget); return; } if (response != GTK_RESPONSE_OK) { bastile_widget_destroy (swidget); return; } /* The name */ widget = bastile_widget_get_widget (swidget, "name-entry"); g_return_if_fail (widget != NULL); name = g_strdup(gtk_entry_get_text (GTK_ENTRY (widget))); g_return_if_fail (name); /* Make sure it's the right length. Should have been checked earlier */ name = g_strstrip (name); g_return_if_fail (strlen(name) >= 5); /* The email address */ widget = bastile_widget_get_widget (swidget, "email-entry"); g_return_if_fail (widget != NULL); email = gtk_entry_get_text (GTK_ENTRY (widget)); /* The comment */ widget = bastile_widget_get_widget (swidget, "comment-entry"); g_return_if_fail (widget != NULL); comment = gtk_entry_get_text (GTK_ENTRY (widget)); /* The algorithm */ widget = bastile_widget_get_widget (swidget, "algorithm-choice"); g_return_if_fail (widget != NULL); sel = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)); g_assert (sel <= G_N_ELEMENTS(available_algorithms)); type = available_algorithms[sel].type; /* The number of bits */ widget = bastile_widget_get_widget (swidget, "bits-entry"); g_return_if_fail (widget != NULL); bits = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget)); if (bits < available_algorithms[sel].min || bits > available_algorithms[sel].max) { bits = available_algorithms[sel].def; g_message ("invalid key size: %s defaulting to %u", available_algorithms[sel].desc, bits); } /* The expiry */ widget = bastile_widget_get_widget (swidget, "expires-check"); g_return_if_fail (widget != NULL); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) expires = 0; else { widget = get_expiry_date (swidget); g_return_if_fail (widget); egg_datetime_get_as_time_t (EGG_DATETIME (widget), &expires); } sksrc = BASTILE_GPGME_SOURCE (g_object_get_data (G_OBJECT (swidget), "source")); g_assert (BASTILE_IS_GPGME_SOURCE (sksrc)); /* Less confusing with less on the screen */ gtk_widget_hide (bastile_widget_get_toplevel (swidget)); bastile_gpgme_generate_key (sksrc, name, email, comment, type, bits, expires); bastile_widget_destroy (swidget); g_free (name); }