[gnome-builder: 75/139] deviceui: add deviceui plugin
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder: 75/139] deviceui: add deviceui plugin
- Date: Thu, 10 Jan 2019 04:23:37 +0000 (UTC)
commit 36ebe876ada50afe4ca6467ae91078b95d59049e
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 9 17:15:56 2019 -0800
deviceui: add deviceui plugin
This adds a new plugin to manage the UI components around device selection.
Most of the device tracking is still in libide-foundry, but this deals
with the UI bits such as the button in the header bar.
src/plugins/deviceui/deviceui-plugin.c | 36 ++++++
src/plugins/deviceui/deviceui.gresource.xml | 6 +
src/plugins/deviceui/deviceui.plugin | 11 ++
.../deviceui/gbp-deviceui-workspace-addin.c | 128 +++++++++++++++++++++
.../deviceui/gbp-deviceui-workspace-addin.h | 31 +++++
src/plugins/deviceui/meson.build | 12 ++
6 files changed, 224 insertions(+)
---
diff --git a/src/plugins/deviceui/deviceui-plugin.c b/src/plugins/deviceui/deviceui-plugin.c
new file mode 100644
index 000000000..97f1d7cc4
--- /dev/null
+++ b/src/plugins/deviceui/deviceui-plugin.c
@@ -0,0 +1,36 @@
+/* deviceui-plugin.c
+ *
+ * Copyright 2018-2019 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "deviceui-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+#include <libide-gui.h>
+
+#include "gbp-deviceui-workspace-addin.h"
+
+_IDE_EXTERN void
+_gbp_deviceui_register_types (PeasObjectModule *module)
+{
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_WORKSPACE_ADDIN,
+ GBP_TYPE_DEVICEUI_WORKSPACE_ADDIN);
+}
diff --git a/src/plugins/deviceui/deviceui.gresource.xml b/src/plugins/deviceui/deviceui.gresource.xml
new file mode 100644
index 000000000..088c243af
--- /dev/null
+++ b/src/plugins/deviceui/deviceui.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/plugins/deviceui">
+ <file>deviceui.plugin</file>
+ </gresource>
+</gresources>
diff --git a/src/plugins/deviceui/deviceui.plugin b/src/plugins/deviceui/deviceui.plugin
new file mode 100644
index 000000000..3c0ebea8d
--- /dev/null
+++ b/src/plugins/deviceui/deviceui.plugin
@@ -0,0 +1,11 @@
+[Plugin]
+Authors=Christian Hergert <christian hergert me>
+Builtin=true
+Copyright=Copyright © 2018 Christian Hergert
+Depends=editor;
+Description=Provides user interface components to display devices
+Embedded=_gbp_deviceui_register_types
+Hidden=true
+Module=deviceui
+Name=Device UI
+X-Workspace-Kind=primary;
diff --git a/src/plugins/deviceui/gbp-deviceui-workspace-addin.c
b/src/plugins/deviceui/gbp-deviceui-workspace-addin.c
new file mode 100644
index 000000000..f7cd7fb2c
--- /dev/null
+++ b/src/plugins/deviceui/gbp-deviceui-workspace-addin.c
@@ -0,0 +1,128 @@
+/* gbp-deviceui-workspace-addin.c
+ *
+ * Copyright 2018-2019 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-deviceui-workspace-addin"
+
+#include "config.h"
+
+#include <libide-foundry.h>
+#include <libide-gui.h>
+
+#include "ide-device-private.h"
+
+#include "gbp-deviceui-workspace-addin.h"
+
+struct _GbpDeviceuiWorkspaceAddin
+{
+ GObject parent_instance;
+ GtkWidget *button;
+};
+
+static gboolean
+device_to_icon_name (GBinding *binding,
+ const GValue *from_value,
+ GValue *to_value,
+ gpointer user_data)
+{
+ IdeDevice *device;
+ const gchar *icon_name;
+
+ if (G_VALUE_HOLDS (from_value, IDE_TYPE_DEVICE) &&
+ (device = g_value_get_object (from_value)) &&
+ (icon_name = ide_device_get_icon_name (device)))
+ g_value_set_string (to_value, icon_name);
+ else
+ g_value_set_static_string (to_value, "computer-symbolic");
+
+ return TRUE;
+}
+
+static void
+gbp_deviceui_workspace_addin_load (IdeWorkspaceAddin *addin,
+ IdeWorkspace *workspace)
+{
+ GbpDeviceuiWorkspaceAddin *self = (GbpDeviceuiWorkspaceAddin *)addin;
+ IdeDeviceManager *device_manager;
+ IdeHeaderBar *header;
+ IdeContext *context;
+ GMenu *menu;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (IDE_IS_WORKSPACE_ADDIN (self));
+ g_assert (IDE_IS_PRIMARY_WORKSPACE (workspace));
+
+ header = ide_workspace_get_header_bar (workspace);
+ context = ide_widget_get_context (GTK_WIDGET (workspace));
+ device_manager = ide_device_manager_from_context (context);
+ menu = _ide_device_manager_get_menu (device_manager);
+
+ self->button = g_object_new (DZL_TYPE_MENU_BUTTON,
+ "focus-on-click", FALSE,
+ "model", menu,
+ "show-arrow", TRUE,
+ "show-icons", TRUE,
+ "visible", TRUE,
+ NULL);
+ g_signal_connect (self->button,
+ "destroy",
+ G_CALLBACK (gtk_widget_destroyed),
+ &self->button);
+ ide_header_bar_add_center_left (header, self->button);
+
+ g_object_bind_property_full (device_manager, "device",
+ self->button, "icon-name",
+ G_BINDING_SYNC_CREATE,
+ device_to_icon_name,
+ NULL, NULL, NULL);
+}
+
+static void
+gbp_deviceui_workspace_addin_unload (IdeWorkspaceAddin *addin,
+ IdeWorkspace *workspace)
+{
+ GbpDeviceuiWorkspaceAddin *self = (GbpDeviceuiWorkspaceAddin *)addin;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (IDE_IS_WORKSPACE_ADDIN (self));
+ g_assert (IDE_IS_PRIMARY_WORKSPACE (workspace));
+
+ if (self->button)
+ gtk_widget_destroy (self->button);
+}
+
+static void
+workspace_addin_iface_init (IdeWorkspaceAddinInterface *iface)
+{
+ iface->load = gbp_deviceui_workspace_addin_load;
+ iface->unload = gbp_deviceui_workspace_addin_unload;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpDeviceuiWorkspaceAddin, gbp_deviceui_workspace_addin, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKSPACE_ADDIN, workspace_addin_iface_init))
+
+static void
+gbp_deviceui_workspace_addin_class_init (GbpDeviceuiWorkspaceAddinClass *klass)
+{
+}
+
+static void
+gbp_deviceui_workspace_addin_init (GbpDeviceuiWorkspaceAddin *self)
+{
+}
diff --git a/src/plugins/deviceui/gbp-deviceui-workspace-addin.h
b/src/plugins/deviceui/gbp-deviceui-workspace-addin.h
new file mode 100644
index 000000000..872c0a7d5
--- /dev/null
+++ b/src/plugins/deviceui/gbp-deviceui-workspace-addin.h
@@ -0,0 +1,31 @@
+/* gbp-deviceui-workspace-addin.h
+ *
+ * Copyright 2018-2019 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_DEVICEUI_WORKSPACE_ADDIN (gbp_deviceui_workspace_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpDeviceuiWorkspaceAddin, gbp_deviceui_workspace_addin, GBP,
DEVICEUI_WORKSPACE_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/deviceui/meson.build b/src/plugins/deviceui/meson.build
new file mode 100644
index 000000000..d1d00235c
--- /dev/null
+++ b/src/plugins/deviceui/meson.build
@@ -0,0 +1,12 @@
+plugins_sources += files([
+ 'deviceui-plugin.c',
+ 'gbp-deviceui-workspace-addin.c',
+])
+
+plugin_deviceui_resources = gnome.compile_resources(
+ 'deviceui-resources',
+ 'deviceui.gresource.xml',
+ c_name: 'gbp_deviceui',
+)
+
+plugins_sources += plugin_deviceui_resources[0]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]