[gnome-builder/document-manager] GbEditorDocument: add "progress" property for load and save progress



commit b611a423d6233622bbb635e67c5ef59f46905958
Author: Christian Hergert <christian hergert me>
Date:   Mon Dec 8 01:32:25 2014 -0800

    GbEditorDocument: add "progress" property for load and save progress
    
    This will allow all views to monitor the progress to provide visualization
    rather than providing progress callback during load call.

 src/editor/gb-editor-document.c |   72 ++++++++++++++++++++++++++++++++------
 src/editor/gb-editor-document.h |    6 ---
 src/editor/gb-editor-tab.c      |   42 ----------------------
 3 files changed, 60 insertions(+), 60 deletions(-)
---
diff --git a/src/editor/gb-editor-document.c b/src/editor/gb-editor-document.c
index 6d513a8..cc14474 100644
--- a/src/editor/gb-editor-document.c
+++ b/src/editor/gb-editor-document.c
@@ -36,6 +36,7 @@ struct _GbEditorDocumentPrivate
   GbSourceCodeAssistant *code_assistant;
   gchar                 *title;
 
+  gdouble                progress;
   guint                  doc_seq_id;
   guint                  trim_trailing_whitespace : 1;
 };
@@ -45,6 +46,7 @@ enum {
   PROP_CHANGE_MONITOR,
   PROP_FILE,
   PROP_MODIFIED,
+  PROP_PROGRESS,
   PROP_STYLE_SCHEME_NAME,
   PROP_TITLE,
   PROP_TRIM_TRAILING_WHITESPACE,
@@ -76,6 +78,26 @@ gb_editor_document_new (void)
   return g_object_new (GB_TYPE_EDITOR_DOCUMENT, NULL);
 }
 
+gdouble
+gb_editor_document_get_progress (GbEditorDocument *document)
+{
+  g_return_val_if_fail (GB_IS_EDITOR_DOCUMENT (document), 0.0);
+
+  return document->priv->progress;
+}
+
+static void
+gb_editor_document_set_progress (GbEditorDocument *document,
+                                 gdouble           progress)
+{
+  g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
+  g_return_if_fail (progress >= 0.0);
+  g_return_if_fail (progress <= 1.0);
+
+  document->priv->progress = progress;
+  g_object_notify_by_pspec (G_OBJECT (document), gParamSpecs [PROP_PROGRESS]);
+}
+
 gboolean
 gb_editor_document_get_trim_trailing_whitespace (GbEditorDocument *document)
 {
@@ -511,6 +533,23 @@ gb_editor_document_notify_file_location (GbEditorDocument *document,
 }
 
 static void
+gb_editor_document_progress_cb (goffset  current_num_bytes,
+                                goffset  total_num_bytes,
+                                gpointer user_data)
+{
+  GbEditorDocument *document = user_data;
+  gdouble fraction;
+
+  g_return_if_fail (GB_IS_EDITOR_DOCUMENT (document));
+
+  fraction = total_num_bytes
+           ? ((gdouble)current_num_bytes / (gdouble)total_num_bytes)
+           : 1.0;
+
+  gb_editor_document_set_progress (document, fraction);
+}
+
+static void
 gb_editor_document_save_cb (GObject      *object,
                             GAsyncResult *result,
                             gpointer      user_data)
@@ -557,9 +596,6 @@ cleanup:
 void
 gb_editor_document_save_async (GbEditorDocument      *document,
                                GCancellable          *cancellable,
-                               GFileProgressCallback  progress_callback,
-                               gpointer               progress_data,
-                               GDestroyNotify         progress_data_notify,
                                GAsyncReadyCallback    callback,
                                gpointer               user_data)
 {
@@ -607,9 +643,9 @@ gb_editor_document_save_async (GbEditorDocument      *document,
   gtk_source_file_saver_save_async (saver,
                                     G_PRIORITY_DEFAULT,
                                     cancellable,
-                                    progress_callback,
-                                    progress_data,
-                                    progress_data_notify,
+                                    gb_editor_document_progress_cb,
+                                    g_object_ref (document),
+                                    g_object_unref,
                                     gb_editor_document_save_cb,
                                     task);
 
@@ -668,9 +704,6 @@ void
 gb_editor_document_load_async (GbEditorDocument      *document,
                                GFile                 *file,
                                GCancellable          *cancellable,
-                               GFileProgressCallback  progress_callback,
-                               gpointer               progress_data,
-                               GDestroyNotify         progress_data_notify,
                                GAsyncReadyCallback    callback,
                                gpointer               user_data)
 {
@@ -693,9 +726,9 @@ gb_editor_document_load_async (GbEditorDocument      *document,
   gtk_source_file_loader_load_async (loader,
                                      G_PRIORITY_DEFAULT,
                                      cancellable,
-                                     progress_callback,
-                                     progress_data,
-                                     progress_data_notify,
+                                     gb_editor_document_progress_cb,
+                                     g_object_ref (document),
+                                     g_object_unref,
                                      gb_editor_document_load_cb,
                                      task);
 
@@ -800,6 +833,10 @@ gb_editor_document_get_property (GObject    *object,
       g_value_set_object (value, gb_editor_document_get_file (self));
       break;
 
+    case PROP_PROGRESS:
+      g_value_set_double (value, gb_editor_document_get_progress (self));
+      break;
+
     case PROP_TITLE:
       g_value_set_string (value,
                           gb_editor_document_get_title (GB_DOCUMENT (self)));
@@ -876,6 +913,17 @@ gb_editor_document_class_init (GbEditorDocumentClass *klass)
   g_object_class_install_property (object_class, PROP_FILE,
                                    gParamSpecs [PROP_FILE]);
 
+  gParamSpecs [PROP_PROGRESS] =
+    g_param_spec_double ("progress",
+                         _("Progress"),
+                         _("Loading or saving progress."),
+                         0.0,
+                         1.0,
+                         0.0,
+                         (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+  g_object_class_install_property (object_class, PROP_PROGRESS,
+                                   gParamSpecs [PROP_PROGRESS]);
+
   gParamSpecs [PROP_STYLE_SCHEME_NAME] =
     g_param_spec_string ("style-scheme-name",
                          _("Style Scheme Name"),
diff --git a/src/editor/gb-editor-document.h b/src/editor/gb-editor-document.h
index 8bf3ee6..c5991d1 100644
--- a/src/editor/gb-editor-document.h
+++ b/src/editor/gb-editor-document.h
@@ -66,9 +66,6 @@ void                   gb_editor_document_set_trim_trailing_whitespace (GbEditor
 void                   gb_editor_document_load_async                   (GbEditorDocument       *document,
                                                                         GFile                  *file,
                                                                         GCancellable           *cancellable,
-                                                                        GFileProgressCallback   
progress_callback,
-                                                                        gpointer                
progress_data,
-                                                                        GDestroyNotify          
progress_data_notify,
                                                                         GAsyncReadyCallback     callback,
                                                                         gpointer                user_data);
 gboolean               gb_editor_document_load_finish                  (GbEditorDocument       *document,
@@ -76,9 +73,6 @@ gboolean               gb_editor_document_load_finish                  (GbEditor
                                                                         GError                **error);
 void                   gb_editor_document_save_async                   (GbEditorDocument       *document,
                                                                         GCancellable           *cancellable,
-                                                                        GFileProgressCallback   
progress_callback,
-                                                                        gpointer                
progress_data,
-                                                                        GDestroyNotify          
progress_data_notify,
                                                                         GAsyncReadyCallback     callback,
                                                                         gpointer                user_data);
 gboolean               gb_editor_document_save_finish                  (GbEditorDocument       *document,
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index b631b9c..ff06506 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -39,42 +39,6 @@ gb_editor_tab_new (void)
 }
 
 static void
-gb_editor_tab_progress_cb (goffset  current_num_bytes,
-                           goffset  total_num_bytes,
-                           gpointer user_data)
-{
-  GbEditorTabPrivate *priv;
-  GbEditorTab *tab = user_data;
-  gdouble fraction;
-
-  g_return_if_fail (GB_IS_EDITOR_TAB (tab));
-
-  priv = tab->priv;
-
-  if (priv->progress_animation)
-    {
-      g_object_remove_weak_pointer (G_OBJECT (priv->progress_animation),
-                                    (gpointer *)&priv->progress_animation);
-      gb_animation_stop (priv->progress_animation);
-      priv->progress_animation = NULL;
-    }
-
-  fraction = total_num_bytes
-           ? ((gdouble)current_num_bytes / (gdouble)total_num_bytes)
-           : 1.0;
-
-  priv->progress_animation =
-    gb_object_animate (priv->progress_bar,
-                       GB_ANIMATION_LINEAR,
-                       250,
-                       NULL,
-                       "fraction", fraction,
-                       NULL);
-  g_object_add_weak_pointer (G_OBJECT (priv->progress_animation),
-                             (gpointer *)&priv->progress_animation);
-}
-
-static void
 gb_editor_tab_save_cb (GObject      *source_object,
                        GAsyncResult *result,
                        gpointer      user_data)
@@ -115,9 +79,6 @@ gb_editor_tab_do_save (GbEditorTab *tab)
 
   gb_editor_document_save_async (tab->priv->document,
                                  NULL, /* cancellable */
-                                 gb_editor_tab_progress_cb,
-                                 tab,
-                                 NULL,
                                  gb_editor_tab_save_cb,
                                  g_object_ref (tab));
 
@@ -249,9 +210,6 @@ gb_editor_tab_open_file (GbEditorTab *tab,
   gb_editor_document_load_async (tab->priv->document,
                                  file,
                                  NULL, /* cancellable */
-                                 gb_editor_tab_progress_cb,
-                                 tab,
-                                 NULL,
                                  gb_editor_tab_open_file_cb,
                                  g_object_ref (tab));
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]