[gnome-builder/wip/plugins] device-manager: stub out device manager plugin



commit c1867543a0a2bf99f09130cc9c32eb362c6d9f60
Author: Christian Hergert <christian hergert me>
Date:   Sat Jun 13 02:20:57 2015 -0700

    device-manager: stub out device manager plugin
    
    This will contain the available devices that can be targets for a build
    request. We probably need to be able to set a default build device
    (current), as well as some basic management info.

 configure.ac                                       |    1 +
 plugins/Makefile.am                                |    1 +
 plugins/device-manager/Makefile.am                 |   45 ++++++
 plugins/device-manager/gb-device-manager-panel.c   |  151 ++++++++++++++++++++
 plugins/device-manager/gb-device-manager-panel.h   |   36 +++++
 plugins/device-manager/gb-device-manager-panel.ui  |   26 ++++
 plugins/device-manager/gb-device-manager-plugin.c  |   25 ++++
 .../gb-device-manager-tree-builder.c               |   79 ++++++++++
 .../gb-device-manager-tree-builder.h               |   33 +++++
 .../device-manager/gb-device-manager.gresource.xml |    7 +
 plugins/device-manager/gb-device-manager.plugin    |    6 +
 src/Makefile.am                                    |    1 +
 src/workbench/gb-workbench.c                       |   65 +++++----
 13 files changed, 444 insertions(+), 32 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f32b0c0..d32441d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -385,6 +385,7 @@ AC_CONFIG_FILES([
        plugins/Makefile
        plugins/command-bar/Makefile
        plugins/devhelp/Makefile
+       plugins/device-manager/Makefile
        plugins/file-search/Makefile
        plugins/symbol-tree/Makefile
        plugins/sysmon/Makefile
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 9355d8a..370d79d 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -1,6 +1,7 @@
 SUBDIRS = \
        command-bar \
        devhelp \
+       device-manager \
        file-search \
        symbol-tree \
        sysmon \
diff --git a/plugins/device-manager/Makefile.am b/plugins/device-manager/Makefile.am
new file mode 100644
index 0000000..19262e8
--- /dev/null
+++ b/plugins/device-manager/Makefile.am
@@ -0,0 +1,45 @@
+DISTCLEANFILES =
+BUILT_SOURCES =
+CLEANFILES =
+EXTRA_DIST =
+
+noinst_LTLIBRARIES = libdevice-manager.la
+
+libdevice_manager_la_SOURCES = \
+       gb-device-manager-panel.c \
+       gb-device-manager-panel.h \
+       gb-device-manager-plugin.c \
+       gb-device-manager-tree-builder.c \
+       gb-device-manager-tree-builder.h \
+       $(NULL)
+
+libdevice_manager_la_CFLAGS = \
+       $(BUILDER_CFLAGS) \
+       -I$(top_srcdir)/src \
+       -I$(top_srcdir)/src/tree \
+       -I$(top_srcdir)/src/workbench \
+       -I$(top_srcdir)/src/workspace \
+       -I$(top_srcdir)/libide \
+       $(NULL)
+
+libdevice_manager_la_LIBADD = \
+       $(BUILDER_LIBS) \
+       $(top_builddir)/libide/libide-1.0.la \
+       $(NULL)
+
+libdevice_manager_la_LDFLAGS = \
+       -avoid-version \
+       -module \
+       $(NULL)
+
+nodist_libdevice_manager_la_SOURCES = \
+       gb-device-manager-resources.c \
+       gb-device-manager-resources.h
+
+glib_resources_c = gb-device-manager-resources.c
+glib_resources_h = gb-device-manager-resources.h
+glib_resources_xml = gb-device-manager.gresource.xml
+glib_resources_namespace = gb_device_manager
+include $(top_srcdir)/build/autotools/Makefile.am.gresources
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/device-manager/gb-device-manager-panel.c 
b/plugins/device-manager/gb-device-manager-panel.c
new file mode 100644
index 0000000..85fe5ca
--- /dev/null
+++ b/plugins/device-manager/gb-device-manager-panel.c
@@ -0,0 +1,151 @@
+/* gb-device-manager-panel.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * 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 "gb-device-manager-panel.h"
+#include "gb-device-manager-tree-builder.h"
+#include "gb-tree.h"
+#include "gb-workspace.h"
+
+struct _GbDeviceManagerPanel
+{
+  GtkBox       parent_instance;
+
+  GbWorkbench *workbench;
+  GbTree      *tree;
+};
+
+static void workbench_addin_iface_init (GbWorkbenchAddinInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GbDeviceManagerPanel, gb_device_manager_panel, GTK_TYPE_BOX,
+                         G_IMPLEMENT_INTERFACE (GB_TYPE_WORKBENCH_ADDIN,
+                                                workbench_addin_iface_init))
+
+enum {
+  PROP_0,
+  PROP_WORKBENCH,
+  LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+static void
+gb_device_manager_panel_load (GbWorkbenchAddin *addin)
+{
+  GbDeviceManagerPanel *self = (GbDeviceManagerPanel *)addin;
+  IdeContext *context;
+  IdeDeviceManager *device_manager;
+  GbTreeNode *root;
+  GtkWidget *workspace;
+  GtkWidget *pane;
+
+  g_return_if_fail (GB_IS_DEVICE_MANAGER_PANEL (self));
+
+  context = gb_workbench_get_context (self->workbench);
+  device_manager = ide_context_get_device_manager (context);
+
+  root = gb_tree_node_new ();
+  gb_tree_node_set_item (root, G_OBJECT (device_manager));
+  gb_tree_set_root (self->tree, root);
+
+  workspace = gb_workbench_get_workspace (self->workbench);
+  pane = gb_workspace_get_left_pane (GB_WORKSPACE (workspace));
+  gb_workspace_pane_add_page (GB_WORKSPACE_PANE (pane),
+                              GTK_WIDGET (self),
+                              _("Device"),
+                              "computer-symbolic");
+}
+
+static void
+gb_device_manager_panel_unload (GbWorkbenchAddin *addin)
+{
+  GbDeviceManagerPanel *self = (GbDeviceManagerPanel *)addin;
+  GtkWidget *parent;
+
+  g_return_if_fail (GB_IS_DEVICE_MANAGER_PANEL (self));
+
+  parent = gtk_widget_get_parent (GTK_WIDGET (self));
+  gtk_container_remove (GTK_CONTAINER (parent), GTK_WIDGET (self));
+}
+
+static void
+gb_device_manager_panel_finalize (GObject *object)
+{
+  GbDeviceManagerPanel *self = (GbDeviceManagerPanel *)object;
+
+  ide_clear_weak_pointer (&self->workbench);
+
+  G_OBJECT_CLASS (gb_device_manager_panel_parent_class)->finalize (object);
+}
+
+static void
+gb_device_manager_panel_set_property (GObject      *object,
+                                      guint         prop_id,
+                                      const GValue *value,
+                                      GParamSpec   *pspec)
+{
+  GbDeviceManagerPanel *self = GB_DEVICE_MANAGER_PANEL (object);
+
+  switch (prop_id)
+    {
+    case PROP_WORKBENCH:
+      ide_set_weak_pointer (&self->workbench, g_value_get_object (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    }
+}
+
+static void
+gb_device_manager_panel_class_init (GbDeviceManagerPanelClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  object_class->finalize = gb_device_manager_panel_finalize;
+  object_class->set_property = gb_device_manager_panel_set_property;
+
+  gParamSpecs [PROP_WORKBENCH] =
+    g_param_spec_object ("workbench",
+                         "Workbench",
+                         "Workbench",
+                         GB_TYPE_WORKBENCH,
+                         (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+
+  g_object_class_install_properties (object_class, LAST_PROP, gParamSpecs);
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/builder/plugins/device-manager/gb-device-manager-panel.ui");
+  gtk_widget_class_bind_template_child (widget_class, GbDeviceManagerPanel, tree);
+
+  g_type_ensure (GB_TYPE_DEVICE_MANAGER_TREE_BUILDER);
+}
+
+static void
+gb_device_manager_panel_init (GbDeviceManagerPanel *self)
+{
+  gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+static void
+workbench_addin_iface_init (GbWorkbenchAddinInterface *iface)
+{
+  iface->load = gb_device_manager_panel_load;
+  iface->unload = gb_device_manager_panel_unload;
+}
diff --git a/plugins/device-manager/gb-device-manager-panel.h 
b/plugins/device-manager/gb-device-manager-panel.h
new file mode 100644
index 0000000..90e163d
--- /dev/null
+++ b/plugins/device-manager/gb-device-manager-panel.h
@@ -0,0 +1,36 @@
+/* gb-device-manager-panel.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * 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/>.
+ */
+
+#ifndef GB_DEVICE_MANAGER_PANEL_H
+#define GB_DEVICE_MANAGER_PANEL_H
+
+#include <gtk/gtk.h>
+
+#include "gb-workbench-addin.h"
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_DEVICE_MANAGER_PANEL (gb_device_manager_panel_get_type())
+
+G_DECLARE_FINAL_TYPE (GbDeviceManagerPanel, gb_device_manager_panel,
+                      GB, DEVICE_MANAGER_PANEL,
+                      GtkBox)
+
+G_END_DECLS
+
+#endif /* GB_DEVICE_MANAGER_PANEL_H */
diff --git a/plugins/device-manager/gb-device-manager-panel.ui 
b/plugins/device-manager/gb-device-manager-panel.ui
new file mode 100644
index 0000000..f5aefb4
--- /dev/null
+++ b/plugins/device-manager/gb-device-manager-panel.ui
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.16 -->
+  <template class="GbDeviceManagerPanel" parent="GtkBox">
+    <property name="orientation">vertical</property>
+    <property name="vexpand">true</property>
+    <property name="visible">true</property>
+    <child>
+      <object class="GtkScrolledWindow">
+        <property name="visible">true</property>
+        <property name="vexpand">true</property>
+        <child>
+          <object class="GbTree" id="tree">
+            <property name="headers-visible">false</property>
+            <property name="show-icons">true</property>
+            <property name="visible">true</property>
+            <child type="builder">
+              <object class="GbDeviceManagerTreeBuilder">
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/plugins/device-manager/gb-device-manager-plugin.c 
b/plugins/device-manager/gb-device-manager-plugin.c
new file mode 100644
index 0000000..8a8aa85
--- /dev/null
+++ b/plugins/device-manager/gb-device-manager-plugin.c
@@ -0,0 +1,25 @@
+/* gb-device-manager-plugin.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * 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 "gb-plugins.h"
+#include "gb-device-manager-panel.h"
+
+GB_DEFINE_EMBEDDED_PLUGIN (gb_device_manager,
+                           gb_device_manager_get_resource (),
+                           "resource:///org/gnome/builder/plugins/device-manager/gb-device-manager.plugin",
+                           GB_DEFINE_PLUGIN_TYPE (GB_TYPE_WORKBENCH_ADDIN, GB_TYPE_DEVICE_MANAGER_PANEL))
diff --git a/plugins/device-manager/gb-device-manager-tree-builder.c 
b/plugins/device-manager/gb-device-manager-tree-builder.c
new file mode 100644
index 0000000..3256666
--- /dev/null
+++ b/plugins/device-manager/gb-device-manager-tree-builder.c
@@ -0,0 +1,79 @@
+/* gb-device-manager-tree-builder.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * 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 <ide.h>
+
+#include "gb-device-manager-tree-builder.h"
+
+struct _GbDeviceManagerTreeBuilder
+{
+  GbTreeBuilder parent_instance;
+};
+
+G_DEFINE_TYPE (GbDeviceManagerTreeBuilder, gb_device_manager_tree_builder, GB_TYPE_TREE_BUILDER)
+
+static void
+gb_device_manager_tree_builder_build_node (GbTreeBuilder *builder,
+                                           GbTreeNode    *node)
+{
+  GObject *item;
+
+  g_assert (GB_IS_TREE_BUILDER (builder));
+  g_assert (GB_IS_TREE_NODE (node));
+
+  item = gb_tree_node_get_item (node);
+
+  if (IDE_IS_DEVICE_MANAGER (item))
+    {
+      g_autoptr(GPtrArray) devices = NULL;
+      gsize i;
+
+      devices = ide_device_manager_get_devices (IDE_DEVICE_MANAGER (item));
+
+      for (i = 0; i < devices->len; i++)
+        {
+          IdeDevice *device;
+          GbTreeNode *child;
+
+          device = g_ptr_array_index (devices, i);
+
+          child = g_object_new (GB_TYPE_TREE_NODE,
+                                "item", device,
+                                "icon-name", "computer-symbolic",
+                                NULL);
+          g_object_bind_property (device, "display-name", child, "text", G_BINDING_SYNC_CREATE);
+          gb_tree_node_append (node, child);
+        }
+    }
+  else if (IDE_IS_DEVICE (item))
+    {
+    }
+}
+
+static void
+gb_device_manager_tree_builder_class_init (GbDeviceManagerTreeBuilderClass *klass)
+{
+  GbTreeBuilderClass *builder_class = GB_TREE_BUILDER_CLASS (klass);
+
+  builder_class->build_node = gb_device_manager_tree_builder_build_node;
+}
+
+static void
+gb_device_manager_tree_builder_init (GbDeviceManagerTreeBuilder *self)
+{
+}
diff --git a/plugins/device-manager/gb-device-manager-tree-builder.h 
b/plugins/device-manager/gb-device-manager-tree-builder.h
new file mode 100644
index 0000000..8235f71
--- /dev/null
+++ b/plugins/device-manager/gb-device-manager-tree-builder.h
@@ -0,0 +1,33 @@
+/* gb-device-manager-tree-builder.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * 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/>.
+ */
+
+#ifndef GB_DEVICE_MANAGER_TREE_BUILDER_H
+#define GB_DEVICE_MANAGER_TREE_BUILDER_H
+
+#include "gb-tree-builder.h"
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_DEVICE_MANAGER_TREE_BUILDER (gb_device_manager_tree_builder_get_type())
+
+G_DECLARE_FINAL_TYPE (GbDeviceManagerTreeBuilder, gb_device_manager_tree_builder,
+                      GB, DEVICE_MANAGER_TREE_BUILDER, GbTreeBuilder)
+
+G_END_DECLS
+
+#endif /* GB_DEVICE_MANAGER_TREE_BUILDER_H */
diff --git a/plugins/device-manager/gb-device-manager.gresource.xml 
b/plugins/device-manager/gb-device-manager.gresource.xml
new file mode 100644
index 0000000..0151dfa
--- /dev/null
+++ b/plugins/device-manager/gb-device-manager.gresource.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/builder/plugins/device-manager">
+    <file>gb-device-manager.plugin</file>
+    <file>gb-device-manager-panel.ui</file>
+  </gresource>
+</gresources>
diff --git a/plugins/device-manager/gb-device-manager.plugin b/plugins/device-manager/gb-device-manager.plugin
new file mode 100644
index 0000000..bf371af
--- /dev/null
+++ b/plugins/device-manager/gb-device-manager.plugin
@@ -0,0 +1,6 @@
+[Plugin]
+Module=gb-device-manager
+Name=Device Manager
+Description=Manage connected devices
+Authors=Christian Hergert <christian hergert me>
+Copyright=Copyright © 2015 Christian Hergert
diff --git a/src/Makefile.am b/src/Makefile.am
index 8253d8b..e7b9fad 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -212,6 +212,7 @@ define_plugin = -Wl,--whole-archive,$(top_builddir)/plugins/$1/.libs/lib$1.a,--n
 gnome_builder_PLUGINS = \
        devhelp \
        command-bar \
+       device-manager \
        file-search \
        symbol-tree \
        sysmon \
diff --git a/src/workbench/gb-workbench.c b/src/workbench/gb-workbench.c
index 060f2d7..a24c5c5 100644
--- a/src/workbench/gb-workbench.c
+++ b/src/workbench/gb-workbench.c
@@ -456,6 +456,23 @@ gb_workbench_realize (GtkWidget *widget)
 }
 
 static void
+gb_workbench__extension_added (PeasExtensionSet *set,
+                               PeasPluginInfo   *plugin_info,
+                               GbWorkbenchAddin *addin)
+{
+  gb_workbench_addin_load (addin);
+}
+
+static void
+gb_workbench__extension_removed (PeasExtensionSet *set,
+                                 PeasPluginInfo   *plugin_info,
+                                 GbWorkbenchAddin *addin)
+{
+  gb_workbench_addin_unload (addin);
+}
+
+
+static void
 gb_workbench_constructed (GObject *object)
 {
   GbWorkbench *self = (GbWorkbench *)object;
@@ -472,6 +489,22 @@ gb_workbench_constructed (GObject *object)
   menu = gtk_application_get_menu_by_id (app, "gear-menu");
   gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (self->gear_menu_button), G_MENU_MODEL (menu));
 
+  self->extensions = peas_extension_set_new (peas_engine_get_default (),
+                                             GB_TYPE_WORKBENCH_ADDIN,
+                                             "workbench", self,
+                                             NULL);
+  peas_extension_set_foreach (self->extensions,
+                              (PeasExtensionSetForeachFunc)gb_workbench__extension_added,
+                              NULL);
+  g_signal_connect (self->extensions,
+                    "extension-added",
+                    G_CALLBACK (gb_workbench__extension_added),
+                    self);
+  g_signal_connect (self->extensions,
+                    "extension-removed",
+                    G_CALLBACK (gb_workbench__extension_removed),
+                    self);
+
   gtk_widget_grab_focus (GTK_WIDGET (self->workspace));
 
   IDE_EXIT;
@@ -621,22 +654,6 @@ gb_workbench_class_init (GbWorkbenchClass *klass)
 }
 
 static void
-gb_workbench__extension_added (PeasExtensionSet *set,
-                               PeasPluginInfo   *plugin_info,
-                               GbWorkbenchAddin *addin)
-{
-  gb_workbench_addin_load (addin);
-}
-
-static void
-gb_workbench__extension_removed (PeasExtensionSet *set,
-                                 PeasPluginInfo   *plugin_info,
-                                 GbWorkbenchAddin *addin)
-{
-  gb_workbench_addin_unload (addin);
-}
-
-static void
 gb_workbench_init (GbWorkbench *self)
 {
   IDE_ENTRY;
@@ -650,22 +667,6 @@ gb_workbench_init (GbWorkbench *self)
 
   gb_settings_init_window (GTK_WINDOW (self));
 
-  self->extensions = peas_extension_set_new (peas_engine_get_default (),
-                                             GB_TYPE_WORKBENCH_ADDIN,
-                                             "workbench", self,
-                                             NULL);
-  peas_extension_set_foreach (self->extensions,
-                              (PeasExtensionSetForeachFunc)gb_workbench__extension_added,
-                              NULL);
-  g_signal_connect (self->extensions,
-                    "extension-added",
-                    G_CALLBACK (gb_workbench__extension_added),
-                    self);
-  g_signal_connect (self->extensions,
-                    "extension-removed",
-                    G_CALLBACK (gb_workbench__extension_removed),
-                    self);
-
   IDE_EXIT;
 }
 


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