[gnome-builder] support: move support log generation to plugin



commit 20fa464747aea873f5f2b2358cb625cf8f409c50
Author: Christian Hergert <chergert redhat com>
Date:   Thu Dec 3 23:53:09 2015 -0800

    support: move support log generation to plugin
    
    This doesn't need to be hard coded in, we can compartmentalize it now.

 configure.ac                                       |    2 +
 data/gtk/menus.ui                                  |    9 +-
 libide/Makefile.am                                 |    3 -
 libide/ide-application-actions.c                   |   53 --------
 plugins/Makefile.am                                |    1 +
 plugins/support/Makefile.am                        |   48 +++++++
 plugins/support/configure.ac                       |   12 ++
 plugins/support/gtk/menus.ui                       |   12 ++
 plugins/support/ide-support-application-addin.c    |  131 ++++++++++++++++++++
 .../support/ide-support-application-addin.h        |   16 ++-
 .../support/ide-support-plugin.c                   |   24 ++--
 .../support/ide-support-resources.gresource.xml    |    6 +
 {libide => plugins}/support/ide-support.c          |    0
 {libide => plugins}/support/ide-support.h          |    0
 plugins/support/support.plugin                     |    8 ++
 15 files changed, 244 insertions(+), 81 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4d58bfa..c8d937b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -244,6 +244,7 @@ m4_include([plugins/mingw/configure.ac])
 m4_include([plugins/project-tree/configure.ac])
 m4_include([plugins/python-gi-imports-completion/configure.ac])
 m4_include([plugins/python-pack/configure.ac])
+m4_include([plugins/support/configure.ac])
 m4_include([plugins/symbol-tree/configure.ac])
 m4_include([plugins/sysmon/configure.ac])
 m4_include([plugins/terminal/configure.ac])
@@ -496,6 +497,7 @@ echo "  Project Tree ......................... : ${enable_project_tree_plugin}"
 echo "  Python GObject Introspection ......... : ${enable_python_gi_imports_completion_plugin}"
 echo "  Python Jedi Autocompletion ........... : ${enable_jedi_plugin}"
 echo "  Python Language Pack ................. : ${enable_python_pack_plugin}"
+echo "  Support .............................. : ${enable_support_plugin}"
 echo "  System Monitor ....................... : ${enable_sysmon_plugin}"
 echo "  Symbol Tree .......................... : ${enable_symbol_tree_plugin}"
 echo "  Terminal ............................. : ${enable_terminal_plugin}"
diff --git a/data/gtk/menus.ui b/data/gtk/menus.ui
index b7b56ca..c7b4537 100644
--- a/data/gtk/menus.ui
+++ b/data/gtk/menus.ui
@@ -12,18 +12,14 @@
         <attribute name="action">app.open-project</attribute>
       </item>
     </section>
+    <section id="app-menu-placeholder-1"/>
     <section id="app-menu-preferences-section">
       <item>
         <attribute name="label" translatable="yes">_Preferences</attribute>
         <attribute name="action">app.preferences</attribute>
       </item>
     </section>
-    <section id="app-menu-support-section">
-      <item>
-        <attribute name="label" translatable="yes">Generate Support Log</attribute>
-        <attribute name="action">app.support</attribute>
-      </item>
-    </section>
+    <section id="app-menu-placeholder-2"/>
     <section id="app-menu-help-section">
       <attribute name="id">help-section</attribute>
       <item>
@@ -35,6 +31,7 @@
         <attribute name="action">app.about</attribute>
       </item>
     </section>
+    <section id="app-menu-placeholder-3"/>
     <section id="app-menu-quit-section">
       <item>
         <attribute name="label" translatable="yes">_Quit</attribute>
diff --git a/libide/Makefile.am b/libide/Makefile.am
index fcd657b..599bfef 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -359,8 +359,6 @@ libide_1_0_la_SOURCES = \
        search/ide-omni-search-group.h \
        search/ide-omni-search-row.c \
        search/ide-omni-search-row.h \
-       support/ide-support.c \
-       support/ide-support.h \
        theatrics/ide-box-theatric.c \
        theatrics/ide-box-theatric.h \
        util/ide-cairo.c \
@@ -411,7 +409,6 @@ libide_1_0_la_includes = \
        -I$(srcdir)/modelines \
        -I$(srcdir)/preferences \
        -I$(srcdir)/resources \
-       -I$(srcdir)/support \
        -I$(srcdir)/theatrics \
        -I$(srcdir)/util \
        $(NULL)
diff --git a/libide/ide-application-actions.c b/libide/ide-application-actions.c
index c54b7f1..28b56bd 100644
--- a/libide/ide-application-actions.c
+++ b/libide/ide-application-actions.c
@@ -28,7 +28,6 @@
 #include "ide-application-private.h"
 #include "ide-debug.h"
 #include "ide-shortcuts-window.h"
-#include "ide-support.h"
 #include "ide-workbench.h"
 
 static void
@@ -70,57 +69,6 @@ ide_application_actions_preferences (GSimpleAction *action,
 }
 
 static void
-ide_application_actions_support (GSimpleAction *action,
-                                 GVariant      *parameter,
-                                 gpointer       user_data)
-{
-  IdeApplication *self = user_data;
-  GtkWidget *dialog;
-  gchar *text = NULL;
-  GList *windows;
-  GError *error = NULL;
-  gchar *str = NULL;
-  gchar *log_path = NULL;
-  gchar *name = NULL;
-
-  name = g_strdup_printf ("gnome-builder-%u.log", (int)getpid ());
-  log_path = g_build_filename (g_get_home_dir (), name, NULL);
-  g_free (name);
-
-  windows = gtk_application_get_windows (GTK_APPLICATION (self));
-
-  str = ide_get_support_log ();
-
-  if (!g_file_set_contents (log_path, str, -1, &error))
-    {
-      g_printerr ("%s\n", error->message);
-      goto cleanup;
-    }
-
-  text = g_strdup_printf (_("The support log file has been written to '%s'. "
-                            "Please provide this file as an attachment on "
-                            "your bug report or support request."),
-                            log_path);
-
-  g_message ("%s", text);
-
-  dialog = gtk_message_dialog_new (windows ? windows->data : NULL,
-                                   GTK_DIALOG_DESTROY_WITH_PARENT,
-                                   GTK_MESSAGE_INFO,
-                                   GTK_BUTTONS_CLOSE,
-                                   "%s", text);
-  gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
-  g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
-  gtk_window_present (GTK_WINDOW (dialog));
-
-cleanup:
-  g_free (text);
-  g_clear_error (&error);
-  g_free (str);
-  g_free (log_path);
-}
-
-static void
 ide_application_actions_quit (GSimpleAction *action,
                               GVariant      *param,
                               gpointer       user_data)
@@ -280,7 +228,6 @@ static const GActionEntry IdeApplicationActions[] = {
   { "preferences",  ide_application_actions_preferences },
   { "quit",         ide_application_actions_quit },
   { "shortcuts",    ide_application_actions_shortcuts },
-  { "support",      ide_application_actions_support },
 };
 
 void
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 2223a01..24bae6c 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -15,6 +15,7 @@ SUBDIRS = \
        python-gi-imports-completion \
        mingw \
        python-pack \
+       support \
        symbol-tree \
        sysmon \
        terminal \
diff --git a/plugins/support/Makefile.am b/plugins/support/Makefile.am
new file mode 100644
index 0000000..c227ed9
--- /dev/null
+++ b/plugins/support/Makefile.am
@@ -0,0 +1,48 @@
+if ENABLE_DEVHELP_PLUGIN
+
+DISTCLEANFILES =
+BUILT_SOURCES =
+CLEANFILES =
+EXTRA_DIST = $(plugin_DATA)
+
+plugindir = $(libdir)/gnome-builder/plugins
+plugin_LTLIBRARIES = libsupport-plugin.la
+dist_plugin_DATA = support.plugin
+
+libsupport_plugin_la_SOURCES = \
+       ide-support-application-addin.c \
+       ide-support-application-addin.h \
+       ide-support.c \
+       ide-support.h \
+       ide-support-plugin.c \
+       $(NULL)
+
+nodist_libsupport_plugin_la_SOURCES = \
+       ide-support-resources.c \
+       ide-support-resources.h
+
+libsupport_plugin_la_CFLAGS = \
+       $(LIBIDE_CFLAGS) \
+       $(OPTIMIZE_CFLAGS) \
+       -I$(top_srcdir)/libide \
+       -I$(top_srcdir)/contrib/egg \
+       $(NULL)
+
+libsupport_plugin_la_LDFLAGS = \
+       $(OPTIMIZE_LDFLAGS) \
+       -avoid-version \
+       -module \
+       -export-regex peas_register_types \
+       $(NULL)
+
+glib_resources_c = ide-support-resources.c
+glib_resources_h = ide-support-resources.h
+glib_resources_xml = ide-support-resources.gresource.xml
+glib_resources_namespace = ide_support
+include $(top_srcdir)/build/autotools/Makefile.am.gresources
+
+include $(top_srcdir)/plugins/Makefile.plugin
+
+endif
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/support/configure.ac b/plugins/support/configure.ac
new file mode 100644
index 0000000..182a99f
--- /dev/null
+++ b/plugins/support/configure.ac
@@ -0,0 +1,12 @@
+# --enable-support-plugin=yes/no
+AC_ARG_ENABLE([support-plugin],
+              [AS_HELP_STRING([--enable-support-plugin=@<:@yes/no@:>@],
+                              [Build with support for generating bug/support logs.])],
+              [enable_support_plugin=$enableval],
+              [enable_support_plugin=yes])
+
+# for if ENABLE_SUPPORT_PLUGIN in Makefile.am
+AM_CONDITIONAL(ENABLE_SUPPORT_PLUGIN, test x$enable_support_plugin != xno)
+
+# Ensure our makefile is generated by autoconf
+AC_CONFIG_FILES([plugins/support/Makefile])
diff --git a/plugins/support/gtk/menus.ui b/plugins/support/gtk/menus.ui
new file mode 100644
index 0000000..c222d41
--- /dev/null
+++ b/plugins/support/gtk/menus.ui
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <menu id="app-menu">
+    <section id="app-menu-placeholder-2">
+      <item>
+        <attribute name="label" translatable="yes">Generate Support Log</attribute>
+        <attribute name="action">app.generate-support</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/plugins/support/ide-support-application-addin.c b/plugins/support/ide-support-application-addin.c
new file mode 100644
index 0000000..ddd814a
--- /dev/null
+++ b/plugins/support/ide-support-application-addin.c
@@ -0,0 +1,131 @@
+/* ide-support-application-addin.c
+ *
+ * Copyright (C) 2015 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+#include <ide.h>
+
+#include "ide-support-application-addin.h"
+#include "ide-support.h"
+
+struct _IdeSupportApplicationAddin
+{
+  GObject parent_instance;
+};
+
+static void application_addin_iface_init (IdeApplicationAddinInterface *iface);
+
+G_DEFINE_TYPE_EXTENDED (IdeSupportApplicationAddin,
+                        ide_support_application_addin,
+                        G_TYPE_OBJECT,
+                        0,
+                        G_IMPLEMENT_INTERFACE (IDE_TYPE_APPLICATION_ADDIN,
+                                               application_addin_iface_init))
+
+static void
+ide_support_application_addin_class_init (IdeSupportApplicationAddinClass *klass)
+{
+}
+
+static void
+ide_support_application_addin_init (IdeSupportApplicationAddin *addin)
+{
+}
+
+static void
+generate_support_activate (GSimpleAction              *action,
+                           GVariant                   *variant,
+                           IdeSupportApplicationAddin *self)
+{
+  GtkWidget *dialog;
+  gchar *text = NULL;
+  GList *windows;
+  GError *error = NULL;
+  gchar *str = NULL;
+  gchar *log_path = NULL;
+  gchar *name = NULL;
+
+  g_assert (G_IS_SIMPLE_ACTION (action));
+  g_assert (IDE_IS_SUPPORT_APPLICATION_ADDIN (self));
+
+  name = g_strdup_printf ("gnome-builder-%u.log", (int)getpid ());
+  log_path = g_build_filename (g_get_home_dir (), name, NULL);
+  g_free (name);
+
+  windows = gtk_application_get_windows (GTK_APPLICATION (IDE_APPLICATION_DEFAULT));
+
+  str = ide_get_support_log ();
+
+  if (!g_file_set_contents (log_path, str, -1, &error))
+    {
+      g_printerr ("%s\n", error->message);
+      goto cleanup;
+    }
+
+  text = g_strdup_printf (_("The support log file has been written to '%s'. "
+                            "Please provide this file as an attachment on "
+                            "your bug report or support request."),
+                            log_path);
+
+  g_message ("%s", text);
+
+  dialog = gtk_message_dialog_new (windows ? windows->data : NULL,
+                                   GTK_DIALOG_DESTROY_WITH_PARENT,
+                                   GTK_MESSAGE_INFO,
+                                   GTK_BUTTONS_CLOSE,
+                                   "%s", text);
+  gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+  g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
+  gtk_window_present (GTK_WINDOW (dialog));
+
+cleanup:
+  g_free (text);
+  g_clear_error (&error);
+  g_free (str);
+  g_free (log_path);
+}
+
+static void
+ide_support_application_addin_load (IdeApplicationAddin *addin,
+                                    IdeApplication      *application)
+{
+  GSimpleAction *action;
+
+  g_assert (IDE_IS_APPLICATION_ADDIN (addin));
+  g_assert (IDE_IS_APPLICATION (application));
+
+  action = g_simple_action_new ("generate-support", NULL);
+  g_signal_connect (action, "activate", G_CALLBACK (generate_support_activate), addin);
+  g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (action));
+}
+
+static void
+ide_support_application_addin_unload (IdeApplicationAddin *addin,
+                                      IdeApplication      *application)
+{
+  g_assert (IDE_IS_APPLICATION_ADDIN (addin));
+  g_assert (IDE_IS_APPLICATION (application));
+
+  g_action_map_remove_action (G_ACTION_MAP (application), "generate-support");
+}
+
+static void
+application_addin_iface_init (IdeApplicationAddinInterface *iface)
+{
+  iface->load = ide_support_application_addin_load;
+  iface->unload = ide_support_application_addin_unload;
+}
diff --git a/libide/support/ide-support.h b/plugins/support/ide-support-application-addin.h
similarity index 60%
copy from libide/support/ide-support.h
copy to plugins/support/ide-support-application-addin.h
index 1a5da85..b125583 100644
--- a/libide/support/ide-support.h
+++ b/plugins/support/ide-support-application-addin.h
@@ -1,6 +1,6 @@
-/* ide-support.h
+/* ide-support-application-addin.h
  *
- * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ * Copyright (C) 2015 Christian Hergert <chergert redhat com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,15 +16,17 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef IDE_SUPPORT_H
-#define IDE_SUPPORT_H
+#ifndef IDE_SUPPORT_APPLICATION_ADDIN_H
+#define IDE_SUPPORT_APPLICATION_ADDIN_H
 
-#include <glib.h>
+#include <glib-object.h>
 
 G_BEGIN_DECLS
 
-gchar *ide_get_support_log (void);
+#define IDE_TYPE_SUPPORT_APPLICATION_ADDIN (ide_support_application_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeSupportApplicationAddin, ide_support_application_addin, IDE, 
SUPPORT_APPLICATION_ADDIN, GObject)
 
 G_END_DECLS
 
-#endif /* IDE_SUPPORT_H */
+#endif /* IDE_SUPPORT_APPLICATION_ADDIN_H */
diff --git a/libide/support/ide-support.h b/plugins/support/ide-support-plugin.c
similarity index 60%
copy from libide/support/ide-support.h
copy to plugins/support/ide-support-plugin.c
index 1a5da85..78c0a3b 100644
--- a/libide/support/ide-support.h
+++ b/plugins/support/ide-support-plugin.c
@@ -1,6 +1,6 @@
-/* ide-support.h
+/* ide-support-plugin.c
  *
- * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ * Copyright (C) 2015 Christian Hergert <chergert redhat com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,15 +16,15 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef IDE_SUPPORT_H
-#define IDE_SUPPORT_H
+#include <libpeas/peas.h>
+#include <ide.h>
 
-#include <glib.h>
+#include "ide-support-application-addin.h"
 
-G_BEGIN_DECLS
-
-gchar *ide_get_support_log (void);
-
-G_END_DECLS
-
-#endif /* IDE_SUPPORT_H */
+void
+peas_register_types (PeasObjectModule *module)
+{
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_APPLICATION_ADDIN,
+                                              IDE_TYPE_SUPPORT_APPLICATION_ADDIN);
+}
diff --git a/plugins/support/ide-support-resources.gresource.xml 
b/plugins/support/ide-support-resources.gresource.xml
new file mode 100644
index 0000000..9efa318
--- /dev/null
+++ b/plugins/support/ide-support-resources.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/builder/plugins/support-plugin">
+    <file>gtk/menus.ui</file>
+  </gresource>
+</gresources>
diff --git a/libide/support/ide-support.c b/plugins/support/ide-support.c
similarity index 100%
rename from libide/support/ide-support.c
rename to plugins/support/ide-support.c
diff --git a/libide/support/ide-support.h b/plugins/support/ide-support.h
similarity index 100%
rename from libide/support/ide-support.h
rename to plugins/support/ide-support.h
diff --git a/plugins/support/support.plugin b/plugins/support/support.plugin
new file mode 100644
index 0000000..bc0c1d3
--- /dev/null
+++ b/plugins/support/support.plugin
@@ -0,0 +1,8 @@
+[Plugin]
+Module=support-plugin
+Name=Support
+Description=Generate support logs for assistance
+Authors=Christian Hergert <christian hergert me>
+Copyright=Copyright © 2015 Christian Hergert
+Builtin=true
+Hidden=true


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