~ubuntu-branches/ubuntu/utopic/almanah/utopic

« back to all changes in this revision

Viewing changes to src/export-operation.c

  • Committer: Package Import Robot
  • Author(s): Angel Abad
  • Date: 2012-10-29 10:14:18 UTC
  • mfrom: (1.4.1) (10.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20121029101418-k2c27xb0aku22zeg
Tags: 0.10.0-1~exp1
* Imported Upstream version 0.10.0
* debian/control:
  - Bump evolution Build-Depends ( >=3.6.0)
  - debian/control: Depends on evolution-common (>= 3.6.0)
* Bump Standards-Version to 3.9.4 (no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "export-operation.h"
26
26
#include "entry.h"
27
27
#include "storage-manager.h"
28
 
#include "main.h"
29
28
 
30
29
typedef gboolean (*ExportFunc) (AlmanahExportOperation *self, GFile *destination, AlmanahExportProgressCallback progress_callback,
31
30
                                gpointer progress_user_data, GCancellable *cancellable, GError **error);
54
53
          export_database }
55
54
};
56
55
 
 
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);
58
59
 
59
60
struct _AlmanahExportOperationPrivate {
60
61
        gint current_mode; /* index into export_modes */
 
62
        AlmanahStorageManager *storage_manager;
61
63
        GFile *destination;
62
64
};
63
65
 
 
66
enum {
 
67
        PROP_STORAGE_MANAGER = 1,
 
68
};
 
69
 
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))
66
72
 
71
77
 
72
78
        g_type_class_add_private (klass, sizeof (AlmanahExportOperationPrivate));
73
79
 
 
80
        gobject_class->get_property = get_property;
 
81
        gobject_class->set_property = set_property;
74
82
        gobject_class->dispose = almanah_export_operation_dispose;
 
83
 
 
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));
75
89
}
76
90
 
77
91
static void
86
100
{
87
101
        AlmanahExportOperationPrivate *priv = ALMANAH_EXPORT_OPERATION (object)->priv;
88
102
 
 
103
        if (priv->storage_manager != NULL)
 
104
                g_object_unref (priv->storage_manager);
 
105
        priv->storage_manager = NULL;
 
106
 
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);
95
113
}
96
114
 
 
115
static void
 
116
get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
 
117
{
 
118
        AlmanahExportOperationPrivate *priv = ALMANAH_EXPORT_OPERATION (object)->priv;
 
119
 
 
120
        switch (property_id) {
 
121
                case PROP_STORAGE_MANAGER:
 
122
                        g_value_set_object (value, priv->storage_manager);
 
123
                        break;
 
124
                default:
 
125
                        /* We don't have any other property... */
 
126
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
127
                        break;
 
128
        }
 
129
}
 
130
 
 
131
static void
 
132
set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 
133
{
 
134
        AlmanahExportOperation *self = ALMANAH_EXPORT_OPERATION (object);
 
135
 
 
136
        switch (property_id) {
 
137
                case PROP_STORAGE_MANAGER:
 
138
                        self->priv->storage_manager = g_value_dup_object (value);
 
139
                        break;
 
140
                default:
 
141
                        /* We don't have any other property... */
 
142
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
143
                        break;
 
144
        }
 
145
}
 
146
 
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)
99
149
{
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);
103
153
 
161
211
 
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) {
165
215
                GDate date;
166
216
                gchar *filename, *content;
167
217
                GFile *file;
201
251
                g_object_unref (file);
202
252
                g_free (content);
203
253
 
 
254
                /* Clear the buffer. */
 
255
                gtk_text_buffer_delete (buffer, &start_iter, &end_iter);
 
256
 
204
257
                /* Check for cancellation */
205
258
                if (cancellable != NULL && g_cancellable_set_error_if_cancelled (cancellable, &child_error) == TRUE)
206
259
                        break;
230
283
        /* We ignore the progress callbacks, since this is a fairly fast operation, and it exports all the entries at once. */
231
284
 
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));
234
287
 
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);