25
25
#include "export-operation.h"
27
27
#include "storage-manager.h"
30
29
typedef gboolean (*ExportFunc) (AlmanahExportOperation *self, GFile *destination, AlmanahExportProgressCallback progress_callback,
31
30
gpointer progress_user_data, GCancellable *cancellable, GError **error);
56
static void get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
57
static void set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
57
58
static void almanah_export_operation_dispose (GObject *object);
59
60
struct _AlmanahExportOperationPrivate {
60
61
gint current_mode; /* index into export_modes */
62
AlmanahStorageManager *storage_manager;
61
63
GFile *destination;
67
PROP_STORAGE_MANAGER = 1,
64
70
G_DEFINE_TYPE (AlmanahExportOperation, almanah_export_operation, G_TYPE_OBJECT)
65
71
#define ALMANAH_EXPORT_OPERATION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ALMANAH_TYPE_EXPORT_OPERATION, AlmanahExportOperationPrivate))
72
78
g_type_class_add_private (klass, sizeof (AlmanahExportOperationPrivate));
80
gobject_class->get_property = get_property;
81
gobject_class->set_property = set_property;
74
82
gobject_class->dispose = almanah_export_operation_dispose;
84
g_object_class_install_property (gobject_class, PROP_STORAGE_MANAGER,
85
g_param_spec_object ("storage-manager",
86
"Storage manager", "The source storage manager for the export operation.",
87
ALMANAH_TYPE_STORAGE_MANAGER,
88
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
87
101
AlmanahExportOperationPrivate *priv = ALMANAH_EXPORT_OPERATION (object)->priv;
103
if (priv->storage_manager != NULL)
104
g_object_unref (priv->storage_manager);
105
priv->storage_manager = NULL;
89
107
if (priv->destination != NULL)
90
108
g_object_unref (priv->destination);
91
109
priv->destination = NULL;
94
112
G_OBJECT_CLASS (almanah_export_operation_parent_class)->dispose (object);
116
get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
118
AlmanahExportOperationPrivate *priv = ALMANAH_EXPORT_OPERATION (object)->priv;
120
switch (property_id) {
121
case PROP_STORAGE_MANAGER:
122
g_value_set_object (value, priv->storage_manager);
125
/* We don't have any other property... */
126
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
132
set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
134
AlmanahExportOperation *self = ALMANAH_EXPORT_OPERATION (object);
136
switch (property_id) {
137
case PROP_STORAGE_MANAGER:
138
self->priv->storage_manager = g_value_dup_object (value);
141
/* We don't have any other property... */
142
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
97
147
AlmanahExportOperation *
98
almanah_export_operation_new (AlmanahExportOperationType type_id, GFile *destination)
148
almanah_export_operation_new (AlmanahExportOperationType type_id, AlmanahStorageManager *source_storage_manager, GFile *destination)
100
AlmanahExportOperation *export_operation = g_object_new (ALMANAH_TYPE_EXPORT_OPERATION, NULL);
150
AlmanahExportOperation *export_operation = g_object_new (ALMANAH_TYPE_EXPORT_OPERATION, "storage-manager", source_storage_manager, NULL);
101
151
export_operation->priv->current_mode = type_id;
102
152
export_operation->priv->destination = g_object_ref (destination);
162
212
/* Iterate through the entries */
163
213
almanah_storage_manager_iter_init (&iter);
164
while ((entry = almanah_storage_manager_get_entries (almanah->storage_manager, &iter)) != NULL) {
214
while ((entry = almanah_storage_manager_get_entries (self->priv->storage_manager, &iter)) != NULL) {
166
216
gchar *filename, *content;
201
251
g_object_unref (file);
202
252
g_free (content);
254
/* Clear the buffer. */
255
gtk_text_buffer_delete (buffer, &start_iter, &end_iter);
204
257
/* Check for cancellation */
205
258
if (cancellable != NULL && g_cancellable_set_error_if_cancelled (cancellable, &child_error) == TRUE)
230
283
/* We ignore the progress callbacks, since this is a fairly fast operation, and it exports all the entries at once. */
232
285
/* Get the input file (current unencrypted database) */
233
source = g_file_new_for_path (almanah_storage_manager_get_filename (almanah->storage_manager, TRUE));
286
source = g_file_new_for_path (almanah_storage_manager_get_filename (self->priv->storage_manager, TRUE));
235
288
/* Copy the current database to that location */
236
289
success = g_file_copy (source, destination, G_FILE_COPY_OVERWRITE, cancellable, NULL, NULL, error);