static gpgme_error_t passphrase_get (gconstpointer dummy, const gchar *passphrase_hint, const char* passphrase_info, int flags, int fd) { GtkDialog *dialog; gpgme_error_t err; gchar **split_uid = NULL; gchar *label = NULL; gchar *errmsg = NULL; const gchar *pass; gboolean confirm = FALSE; if (passphrase_info && strlen(passphrase_info) < 16) { flags |= SEAHORSE_PASS_NEW; confirm = TRUE; } if (passphrase_hint) split_uid = g_strsplit (passphrase_hint, " ", 2); if (flags & SEAHORSE_PASS_BAD) errmsg = g_strdup_printf (_("Wrong passphrase.")); if (split_uid && split_uid[0] && split_uid[1]) { if (flags & SEAHORSE_PASS_NEW) label = g_strdup_printf (_("Enter new passphrase for '%s'"), split_uid[1]); else label = g_strdup_printf (_("Enter passphrase for '%s'"), split_uid[1]); } else { if (flags & SEAHORSE_PASS_NEW) label = g_strdup (_("Enter new passphrase")); else label = g_strdup (_("Enter passphrase")); } g_strfreev (split_uid); dialog = seahorse_passphrase_prompt_show (_("Passphrase"), errmsg ? errmsg : label, NULL, NULL, confirm); g_free (label); g_free (errmsg); switch (gtk_dialog_run (dialog)) { case GTK_RESPONSE_ACCEPT: pass = seahorse_passphrase_prompt_get (dialog); seahorse_util_printf_fd (fd, "%s\n", pass); err = GPG_OK; break; default: err = GPG_E (GPG_ERR_CANCELED); break; }; gtk_widget_destroy (GTK_WIDGET (dialog)); return err; }
gboolean seahorse_tool_progress_update (gdouble fract, const gchar *message) { if (progress_fd != -1) { if (!seahorse_util_printf_fd (progress_fd, "%s %0.2f %s\n", CMD_PROGRESS, fract, message ? message : "")) { cancelled = TRUE; return FALSE; } } return seahorse_tool_progress_check (); }
void seahorse_tool_progress_block (gboolean block) { if (progress_fd != -1) seahorse_util_printf_fd (progress_fd, "%s \n", block ? CMD_BLOCK : CMD_UNBLOCK); }
gpgme_error_t seahorse_passphrase_get (gconstpointer dummy, const gchar *passphrase_hint, const char* passphrase_info, int flags, int fd) { gchar **split_uid = NULL; gchar *label = NULL; gchar *errmsg = NULL; const gchar *pass; GcrPrompt *prompt; SyncClosure sync; GError *error = NULL; gchar *msg; sync.result = NULL; sync.loop = g_main_loop_new (NULL, FALSE); gcr_system_prompt_open_async (-1, NULL, on_sync_complete, &sync); g_main_loop_run (sync.loop); g_assert (sync.result != NULL); prompt = gcr_system_prompt_open_finish (sync.result, &error); g_main_loop_unref (sync.loop); g_object_unref (sync.result); if (error != NULL) { g_message ("Couldn't open system prompt: %s", error->message); g_error_free (error); return gpgme_error (GPG_ERR_CANCELED); } if (passphrase_info && strlen(passphrase_info) < 16) flags |= SEAHORSE_PASS_NEW; if (passphrase_hint) split_uid = g_strsplit (passphrase_hint, " ", 2); if (flags & SEAHORSE_PASS_BAD) errmsg = g_strdup_printf (_("Wrong passphrase.")); if (split_uid && split_uid[0] && split_uid[1]) { if (flags & SEAHORSE_PASS_NEW) label = g_strdup_printf (_("Enter new passphrase for “%s”"), split_uid[1]); else label = g_strdup_printf (_("Enter passphrase for “%s”"), split_uid[1]); } else { if (flags & SEAHORSE_PASS_NEW) label = g_strdup (_("Enter new passphrase")); else label = g_strdup (_("Enter passphrase")); } g_strfreev (split_uid); gcr_prompt_set_message (prompt, _("Passphrase")); msg = utf8_validate (errmsg ? errmsg : label); gcr_prompt_set_description (prompt, msg); g_free (msg); gcr_prompt_set_password_new (prompt, flags & SEAHORSE_PASS_NEW); gcr_prompt_set_continue_label (prompt, _("OK")); gcr_prompt_set_cancel_label (prompt, _("Cancel")); g_free (label); g_free (errmsg); pass = gcr_prompt_password_run (prompt, NULL, &error); if (pass != NULL) seahorse_util_printf_fd (fd, "%s\n", pass); gcr_system_prompt_close_async (GCR_SYSTEM_PROMPT (prompt), NULL, NULL, NULL); g_object_unref (prompt); if (error != NULL) { g_message ("Couldn't prompt for password: %s", error->message); g_error_free (error); return gpgme_error (GPG_ERR_CANCELED); } return 0; }