static gboolean step_process_multiple (FilesCtx *ctx, const gchar **orig_uris, GError **err) { SeahorseWidget *swidget; gboolean done = FALSE; FileInfo *pkg_info = NULL; gchar *package = NULL; gchar *ext; GFile *file, *parent; gboolean ok = FALSE; GtkWidget *dlg; guint nfolders, nfiles; gchar *uris[2]; gchar *uri; GList *l; g_assert (err && !*err); for (l = ctx->finfos, nfolders = nfiles = 0; l; l = g_list_next (l)) { FileInfo *finfo = (FileInfo*)l->data; if (g_file_info_get_file_type (finfo->info) == G_FILE_TYPE_DIRECTORY) ++nfolders; else ++nfiles; } /* In the case of one or less files, no dialog */ if(nfolders == 0 && nfiles <= 1) return TRUE; /* The package extension */ if ((ext = g_settings_get_string (seahorse_tool_settings, "package-extension")) == NULL) ext = g_strdup (".zip"); /* Yes this happens when the schema isn't installed */ /* Figure out a good URI for our package */ for (l = ctx->finfos; l; l = g_list_next (l)) { if (l->data) { pkg_info = (FileInfo*)(l->data); break; } } /* This sets up but doesn't run the dialog */ swidget = prepare_dialog (ctx, nfolders, nfiles, pkg_info->info, ext); g_free (ext); dlg = seahorse_widget_get_toplevel (swidget); /* Inhibit popping up of progress dialog */ seahorse_tool_progress_block (TRUE); while (!done) { switch (gtk_dialog_run (GTK_DIALOG (dlg))) { case GTK_RESPONSE_HELP: /* TODO: Implement help */ break; case GTK_RESPONSE_OK: package = get_results (swidget); ok = TRUE; /* Fall through */ default: done = TRUE; break; } } /* Let progress dialog pop up */ seahorse_tool_progress_block (FALSE); seahorse_widget_destroy (swidget); /* Cancelled */ if (!ok) return FALSE; /* No package was selected? */ if (!package) return TRUE; /* A package was selected */ /* Make a new path based on the first uri */ parent = g_file_get_parent (pkg_info->file); if (!parent) parent = pkg_info->file; file = g_file_get_child_for_display_name (parent, package, err); if (!file) return FALSE; uri = g_file_get_uri (file); g_return_val_if_fail (uri, FALSE); g_object_unref (file); if (!seahorse_util_uris_package (uri, orig_uris)) { g_free (uri); return FALSE; } /* Free all file info */ g_list_foreach (ctx->finfos, (GFunc)free_file_info, NULL); g_list_free (ctx->finfos); ctx->finfos = NULL; /* Reload up the new file, as what to encrypt */ uris[0] = uri; uris[1] = NULL; ok = step_check_uris (ctx, (const gchar**)uris, err); g_free (uri); return ok; }
static gboolean step_operation (FilesCtx *ctx, SeahorseToolMode *mode, GError **err) { SeahorsePGPOperation *pop = NULL; gpgme_data_t data = NULL; gboolean ret = FALSE; SeahorseOperation *op; FileInfo *finfo; GList *l; gchar *filename; /* Reset our done counter */ ctx->done = 0; for (l = ctx->finfos; l; l = g_list_next (l)) { finfo = (FileInfo*)l->data; if (!finfo || !finfo->file) continue; ctx->cur = finfo; /* A new operation for each context */ pop = seahorse_pgp_operation_new (NULL); op = SEAHORSE_OPERATION (pop); data = seahorse_vfs_data_create_full (finfo->file, SEAHORSE_VFS_READ, (SeahorseVfsProgressCb)progress_cb, ctx, err); if (!data) goto finally; /* Inhibit popping up of progress dialog */ seahorse_tool_progress_block (TRUE); /* Embed filename during encryption */ if (mode_encrypt) { filename = g_file_get_basename (finfo->file); gpgme_data_set_file_name (data, filename); g_free (filename); } /* The start callback */ if (mode->startcb) { if (!(mode->startcb) (mode, finfo->uri, data, pop, err)) goto finally; } /* Let progress dialog pop up */ seahorse_tool_progress_block (FALSE); /* Run until the operation completes */ seahorse_util_wait_until ((!seahorse_operation_is_running (op) || !seahorse_tool_progress_check ())); /* If cancel then reflect that */ if (seahorse_operation_is_running (op)) { seahorse_operation_cancel (op); goto finally; } if (!seahorse_operation_is_successful (op)) { seahorse_operation_copy_error (op, err); goto finally; } /* The done callback */ if (mode->donecb) { if (!(mode->donecb) (mode, finfo->uri, data, pop, err)) goto finally; } ctx->done += g_file_info_get_size (finfo->info); ctx->cur = NULL; g_object_unref (pop); pop = NULL; gpgme_data_release (data); data = NULL; } seahorse_tool_progress_update (1.0, ""); ret = TRUE; finally: if (pop) g_object_unref (pop); if (data) gpgme_data_release (data); return ret; }
static gboolean verify_start (SeahorseToolMode *mode, const gchar *uri, gpgme_data_t uridata, SeahorsePGPOperation *pop, GError **err) { gpgme_data_t plain; gpgme_error_t gerr; gchar *original, *unesc_uri; /* File to decrypt to */ original = seahorse_util_remove_suffix (uri, NULL); /* The original file doesn't exist, prompt for it */ if (!seahorse_util_uri_exists (original)) { GtkWidget *dialog; gchar *t; unesc_uri = g_uri_unescape_string (seahorse_util_uri_get_last (uri), NULL); t = g_strdup_printf (_("Choose Original File for '%s'"), unesc_uri); dialog = gtk_file_chooser_dialog_new (t, NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); g_free (unesc_uri); g_free (t); gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog), original); gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE); g_free (original); original = NULL; seahorse_tool_progress_block (TRUE); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) original = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog)); seahorse_tool_progress_block (FALSE); gtk_widget_destroy (dialog); } if (!original) return FALSE; g_object_set_data_full (G_OBJECT (pop), "original-file", original, g_free); /* Open necessary files, release with operation */ plain = seahorse_vfs_data_create (original, SEAHORSE_VFS_READ, err); if (!plain) return FALSE; g_object_set_data_full (G_OBJECT (pop), "plain-data", plain, (GDestroyNotify)gpgme_data_release); /* Start actual verify */ gerr = gpgme_op_verify_start (pop->gctx, uridata, plain, NULL); if (gerr != 0) { seahorse_util_gpgme_to_error (gerr, err); return FALSE; } return TRUE; }