[frogr] Basic stubs to implement the 'Load Project' feature
- From: Mario Sanchez Prada <msanchez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [frogr] Basic stubs to implement the 'Load Project' feature
- Date: Sun, 11 Nov 2012 00:08:58 +0000 (UTC)
commit 229dc9a98f7fadd1917f048dcf31edb28ca90b70
Author: Mario Sanchez Prada <msanchez gnome org>
Date: Thu Nov 8 17:28:09 2012 +0100
Basic stubs to implement the 'Load Project' feature
We should implement the logic in frogr_main_view_model_deserialize
and a new function in FrogrFileLoader to allow just loading the
pixbufs for a list of pictures (opposite to loading everything
just given the list of URIS)
src/frogr-controller.c | 45 ++++++++++++++++++++++++
src/frogr-controller.h | 2 +
src/frogr-main-view.c | 89 ++++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 130 insertions(+), 6 deletions(-)
---
diff --git a/src/frogr-controller.c b/src/frogr-controller.c
index 59ba5bb..7467020 100644
--- a/src/frogr-controller.c
+++ b/src/frogr-controller.c
@@ -2739,6 +2739,51 @@ frogr_controller_cancel_ongoing_requests (FrogrController *self)
}
void
+frogr_controller_load_project_from_file (FrogrController *self, const gchar *path)
+{
+ JsonParser *json_parser = NULL;
+ GError *error = NULL;
+
+ g_return_if_fail(FROGR_IS_CONTROLLER (self));
+
+ /* Load from disk */
+ json_parser = json_parser_new ();
+ json_parser_load_from_file (json_parser, path, &error);
+ if (error)
+ {
+ DEBUG ("Error loading project file from %s: %s",
+ path, error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ FrogrControllerPrivate *priv = NULL;
+ FrogrMainViewModel *mainview_model = NULL;
+ JsonNode *json_root = NULL;
+
+ priv = FROGR_CONTROLLER_GET_PRIVATE (self);
+
+ /* Make sure we are not fetching any data from the network at
+ this moment, or cancel otherwise, so the model is ready */
+ if (priv->fetching_photosets || priv->fetching_groups || priv->fetching_tags)
+ frogr_controller_cancel_ongoing_requests (self);
+
+ /* Deserialize from the JSON data and update the model */
+ mainview_model = frogr_main_view_get_model (priv->mainview);
+ json_root = json_parser_get_root (json_parser);
+ frogr_main_view_model_deserialize (mainview_model, json_root);
+
+ /* TODO: We now should have the relevant data in the model, and
+ so we would just need to load the pixbufs for all the pictures */
+
+ json_node_free (json_root);
+ }
+
+ g_object_unref (json_parser);
+
+}
+
+void
frogr_controller_save_project_to_file (FrogrController *self, const gchar *path)
{
FrogrControllerPrivate *priv = NULL;
diff --git a/src/frogr-controller.h b/src/frogr-controller.h
index 032fd15..08a1b35 100644
--- a/src/frogr-controller.h
+++ b/src/frogr-controller.h
@@ -126,6 +126,8 @@ void frogr_controller_reorder_pictures (FrogrController *self);
void frogr_controller_cancel_ongoing_requests (FrogrController *self);
+void frogr_controller_load_project_from_file (FrogrController *self, const gchar *path);
+
void frogr_controller_save_project_to_file (FrogrController *self, const gchar *path);
#ifdef GTK_API_VERSION_3
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index d0c6839..1e5a2a1 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -97,6 +97,7 @@ typedef struct _FrogrMainViewPrivate {
GtkBuilder *builder;
+ GtkAction *load_project_action;
GtkAction *save_project_action;
GtkAction *save_project_as_action;
GtkAction *load_pictures_action;
@@ -179,6 +180,14 @@ static GSList *_get_selected_pictures (FrogrMainView *self);
static gint _n_pictures (FrogrMainView *self);
static void _open_pictures_in_external_viewer (FrogrMainView *self);
+static void _load_project_from_file (FrogrMainView *self, const gchar *filepath);
+
+static void _load_project_dialog_response_cb (GtkDialog *dialog,
+ gint response,
+ gpointer data);
+
+static void _load_project_dialog (FrogrMainView *self);
+
static void _save_current_project (FrogrMainView *self);
static void _save_project_to_file (FrogrMainView *self, const gchar *filepath);
@@ -580,7 +589,9 @@ _on_action_activated (GtkAction *action, gpointer data)
FrogrMainViewPrivate *priv = NULL;
priv = FROGR_MAIN_VIEW_GET_PRIVATE (data);
- if (action == priv->save_project_action)
+ if (action == priv->load_project_action)
+ _load_project_dialog (mainview);
+ else if (action == priv->save_project_action)
_save_current_project (mainview);
else if (action == priv->save_project_as_action)
_save_project_as_dialog (mainview);
@@ -952,6 +963,72 @@ _n_pictures (FrogrMainView *self)
}
static void
+_load_project_from_file (FrogrMainView *self, const gchar *filepath)
+{
+ FrogrMainViewPrivate *priv = FROGR_MAIN_VIEW_GET_PRIVATE (self);
+
+ /* Load from disk and update project's path */
+ frogr_controller_load_project_from_file (priv->controller, filepath);
+ _update_project_path (self, filepath);
+
+ /* Update title marking it as non-dirty (just loaded) */
+ /* FIXME: This should not happen until we know the load is finished */
+ _update_window_title (self, FALSE);
+}
+
+static void
+_load_project_dialog_response_cb (GtkDialog *dialog,
+ gint response,
+ gpointer data)
+{
+ FrogrMainView *self = FROGR_MAIN_VIEW (data);
+
+ if (response == GTK_RESPONSE_ACCEPT)
+ {
+ gchar *filename = NULL;
+
+ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ if (filename != NULL)
+ _load_project_from_file (self, filename);
+
+ g_free (filename);
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
+}
+
+static void
+_load_project_dialog (FrogrMainView *self)
+{
+ FrogrMainViewPrivate *priv = FROGR_MAIN_VIEW_GET_PRIVATE (self);
+ GtkWidget *dialog;
+ GtkFileFilter *filter;
+
+ dialog = gtk_file_chooser_dialog_new (_("Select File"),
+ GTK_WINDOW (priv->window),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
+ gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
+
+ /* Let's allow text files only */
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_add_mime_type (filter, "text/*");
+ gtk_file_filter_set_name (filter, _("Text Files"));
+ gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+ g_signal_connect (G_OBJECT (dialog), "response",
+ G_CALLBACK (_load_project_dialog_response_cb), self);
+
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+ gtk_widget_show_all (dialog);
+}
+
+static void
_save_current_project (FrogrMainView *self)
{
FrogrMainViewPrivate *priv = FROGR_MAIN_VIEW_GET_PRIVATE (self);
@@ -966,17 +1043,13 @@ static void
_save_project_to_file (FrogrMainView *self, const gchar *filepath)
{
FrogrMainViewPrivate *priv = FROGR_MAIN_VIEW_GET_PRIVATE (self);
- GFile *file = NULL;
/* Save to disk and update project's path */
- file = g_file_new_for_path (filepath);
frogr_controller_save_project_to_file (priv->controller, filepath);
_update_project_path (self, filepath);
- /* Update title marking it as non-dirty again */
+ /* Update title marking it as non-dirty (just saved) */
_update_window_title (self, FALSE);
-
- g_object_unref (file);
}
static void
@@ -1605,6 +1678,7 @@ _update_sensitiveness (FrogrMainView *self)
{
case FROGR_STATE_LOADING_PICTURES:
case FROGR_STATE_UPLOADING_PICTURES:
+ gtk_action_set_sensitive (priv->load_project_action, FALSE);
gtk_action_set_sensitive (priv->save_project_action, FALSE);
gtk_action_set_sensitive (priv->save_project_as_action, FALSE);
gtk_action_set_sensitive (priv->load_pictures_action, FALSE);
@@ -1626,6 +1700,7 @@ _update_sensitiveness (FrogrMainView *self)
has_accounts = (priv->accounts_menu != NULL);
n_selected_pics = priv->n_selected_pictures;
+ gtk_action_set_sensitive (priv->load_project_action, TRUE);
gtk_action_set_sensitive (priv->save_project_action, TRUE);
gtk_action_set_sensitive (priv->save_project_as_action, TRUE);
gtk_action_set_sensitive (priv->load_pictures_action, TRUE);
@@ -1816,6 +1891,8 @@ frogr_main_view_init (FrogrMainView *self)
priv->status_bar = status_bar;
/* Get actions from GtkBuilder */
+ priv->load_project_action =
+ GTK_ACTION (gtk_builder_get_object (builder, "load_project_action"));
priv->save_project_action =
GTK_ACTION (gtk_builder_get_object (builder, "save_project_action"));
priv->save_project_as_action =
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]