[gnome-builder] context: add IdeContext::log signal



commit d456163cf258beb5eff532bff14193786e0c03d9
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jan 5 20:16:32 2018 -0800

    context: add IdeContext::log signal
    
    This can be used to implement a messages API. We may want to
    ensure that we proxy log messages via main loop.

 src/libide/ide-context.c |   47 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 40 insertions(+), 7 deletions(-)
---
diff --git a/src/libide/ide-context.c b/src/libide/ide-context.c
index f8e5f01..d664f39 100644
--- a/src/libide/ide-context.c
+++ b/src/libide/ide-context.c
@@ -27,6 +27,7 @@
 #include "ide-pausable.h"
 #include "ide-service.h"
 
+#include "application/ide-application.h"
 #include "buffers/ide-buffer-manager.h"
 #include "buffers/ide-buffer.h"
 #include "buffers/ide-unsaved-file.h"
@@ -161,6 +162,7 @@ enum {
 
 enum {
   LOADED,
+  LOG,
   LAST_SIGNAL
 };
 
@@ -495,6 +497,14 @@ ide_context_loaded (IdeContext *self)
 }
 
 static void
+ide_context_real_log (IdeContext     *self,
+                      GLogLevelFlags  log_level,
+                      const gchar    *str)
+{
+  g_log ("Ide", log_level, "%s", str);
+}
+
+static void
 ide_context_dispose (GObject *object)
 {
   IdeContext *self = (IdeContext *)object;
@@ -743,6 +753,28 @@ ide_context_class_init (IdeContextClass *klass)
                                 G_CALLBACK (ide_context_loaded),
                                 NULL, NULL, NULL,
                                 G_TYPE_NONE, 0);
+
+  /**
+   * IdeContext::log:
+   * @self: an #IdeContext
+   * @log_level: the #GLogLevelFlags
+   * @message: the log message
+   *
+   * The "log" signal is emitted when ide_context_warning()
+   * or other log messages are sent.
+   *
+   * Since: 3.28
+   */
+  signals [LOG] =
+    g_signal_new_class_handler ("log",
+                                G_TYPE_FROM_CLASS (klass),
+                                G_SIGNAL_RUN_LAST,
+                                G_CALLBACK (ide_context_real_log),
+                                NULL, NULL, NULL,
+                                G_TYPE_NONE,
+                                2,
+                                G_TYPE_UINT,
+                                G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
 }
 
 static void
@@ -1290,8 +1322,9 @@ ide_context_init_add_recent (gpointer             source_object,
   if (error != NULL &&
       !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
     {
-      g_warning ("Unable to open recent projects \"%s\" file: %s",
-                 self->recent_projects_path, error->message);
+      ide_context_warning (self,
+                           "Unable to open recent projects \"%s\" file: %s",
+                           self->recent_projects_path, error->message);
       g_task_return_boolean (task, TRUE);
       IDE_EXIT;
     }
@@ -2277,18 +2310,18 @@ ide_context_warning (IdeContext  *self,
                      const gchar *format,
                      ...)
 {
+  g_autofree gchar *str = NULL;
   va_list args;
 
+  g_return_if_fail (IDE_IS_MAIN_THREAD ());
   g_return_if_fail (IDE_IS_CONTEXT (self));
   g_return_if_fail (format != NULL);
 
   va_start (args, format);
-  /*
-   * TODO: Track logging information so that we can display warnings
-   *       to the user in the workbench.
-   */
-  g_logv ("Ide", G_LOG_LEVEL_WARNING, format, args);
+  str = g_strdup_vprintf (format, args);
   va_end (args);
+
+  g_signal_emit (self, signals [LOG], 0, G_LOG_LEVEL_WARNING, str);
 }
 
 /**


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