[gnome-builder] plugins/sdkui: new plugin to do SDK installation from preferences
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] plugins/sdkui: new plugin to do SDK installation from preferences
- Date: Tue, 23 Aug 2022 01:06:03 +0000 (UTC)
commit 0ddd37ba6da8d37d1140ddc6d8969b7e1faaa125
Author: Christian Hergert <chergert redhat com>
Date: Mon Aug 22 18:01:26 2022 -0700
plugins/sdkui: new plugin to do SDK installation from preferences
This uses the tweaks engine to list available SDKs in the preferences. I'm
certain that eventually we'll want to do something nicer than what i
displayed here, but this at leasts gives users a way to update SDKs that
were installed (possibly to private installations).
src/plugins/meson.build | 1 +
src/plugins/sdkui/gbp-sdkui-tweaks-addin.c | 153 +++++++++++++++++++++++++++++
src/plugins/sdkui/gbp-sdkui-tweaks-addin.h | 31 ++++++
src/plugins/sdkui/meson.build | 12 +++
src/plugins/sdkui/sdkui-plugin.c | 38 +++++++
src/plugins/sdkui/sdkui.gresource.xml | 7 ++
src/plugins/sdkui/sdkui.plugin | 8 ++
src/plugins/sdkui/tweaks.ui | 37 +++++++
8 files changed, 287 insertions(+)
---
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index f22545489..1993c2aaf 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -112,6 +112,7 @@ subdir('retab')
subdir('rstcheck')
subdir('rubocop')
subdir('rust-analyzer')
+subdir('sdkui')
subdir('shellcmd')
subdir('snippets')
subdir('spellcheck')
diff --git a/src/plugins/sdkui/gbp-sdkui-tweaks-addin.c b/src/plugins/sdkui/gbp-sdkui-tweaks-addin.c
new file mode 100644
index 000000000..b1ca976ea
--- /dev/null
+++ b/src/plugins/sdkui/gbp-sdkui-tweaks-addin.c
@@ -0,0 +1,153 @@
+/* gbp-sdkui-tweaks-addin.c
+ *
+ * Copyright 2022 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-sdkui-tweaks-addin"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include <libide-foundry.h>
+#include <libide-gtk.h>
+
+#include "gbp-sdkui-tweaks-addin.h"
+
+struct _GbpSdkuiTweaksAddin
+{
+ IdeTweaksAddin parent_instance;
+};
+
+G_DEFINE_FINAL_TYPE (GbpSdkuiTweaksAddin, gbp_sdkui_tweaks_addin, IDE_TYPE_TWEAKS_ADDIN)
+
+static void
+gbp_sdkui_tweaks_addin_update_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ g_autoptr(IdeInstallButton) button = user_data;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_INSTALL_BUTTON (button));
+
+ ide_install_button_cancel (button);
+
+ IDE_EXIT;
+}
+
+static void
+gbp_sdkui_tweaks_addin_install_cb (IdeSdk *sdk,
+ IdeNotification *notif,
+ GCancellable *cancellable,
+ IdeInstallButton *button)
+{
+ IdeSdkProvider *provider;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (IDE_IS_SDK (sdk));
+ g_assert (IDE_IS_INSTALL_BUTTON (button));
+ g_assert (G_IS_CANCELLABLE (cancellable));
+ g_assert (IDE_IS_NOTIFICATION (notif));
+
+ if (!(provider = ide_sdk_get_provider (sdk)))
+ IDE_EXIT;
+
+ ide_sdk_provider_update_async (provider,
+ sdk,
+ notif,
+ cancellable,
+ gbp_sdkui_tweaks_addin_update_cb,
+ g_object_ref (button));
+
+ IDE_EXIT;
+}
+
+static GtkWidget *
+create_sdk_row_cb (gpointer item,
+ gpointer user_data)
+{
+ IdeInstallButton *button;
+ AdwActionRow *row;
+ IdeSdk *sdk = item;
+
+ g_assert (IDE_IS_SDK (sdk));
+
+ row = g_object_new (ADW_TYPE_ACTION_ROW,
+ "title", ide_sdk_get_title (sdk),
+ "subtitle", ide_sdk_get_subtitle (sdk),
+ NULL);
+
+ button = g_object_new (IDE_TYPE_INSTALL_BUTTON,
+ "label", _("Update"),
+ "valign", GTK_ALIGN_CENTER,
+ NULL);
+ g_object_bind_property (sdk, "can-update",
+ button, "sensitive",
+ G_BINDING_SYNC_CREATE);
+ g_signal_connect_object (button,
+ "install",
+ G_CALLBACK (gbp_sdkui_tweaks_addin_install_cb),
+ sdk,
+ G_CONNECT_SWAPPED);
+ adw_action_row_add_suffix (row, GTK_WIDGET (button));
+
+ return GTK_WIDGET (row);
+}
+
+static GtkWidget *
+create_sdk_list_cb (GbpSdkuiTweaksAddin *self,
+ IdeTweaksWidget *widget,
+ IdeTweaksWidget *instance)
+{
+ IdeSdkManager *sdk_manager;
+ GtkListBox *list;
+
+ g_assert (GBP_IS_SDKUI_TWEAKS_ADDIN (self));
+ g_assert (IDE_IS_TWEAKS_WIDGET (widget));
+ g_assert (IDE_IS_TWEAKS_WIDGET (instance));
+
+ sdk_manager = ide_sdk_manager_get_default ();
+
+ list = g_object_new (GTK_TYPE_LIST_BOX,
+ "css-classes", IDE_STRV_INIT ("boxed-list"),
+ "selection-mode", GTK_SELECTION_NONE,
+ NULL);
+ gtk_list_box_bind_model (list,
+ G_LIST_MODEL (sdk_manager),
+ create_sdk_row_cb,
+ NULL, NULL);
+
+ return GTK_WIDGET (list);
+}
+
+static void
+gbp_sdkui_tweaks_addin_class_init (GbpSdkuiTweaksAddinClass *klass)
+{
+}
+
+static void
+gbp_sdkui_tweaks_addin_init (GbpSdkuiTweaksAddin *self)
+{
+ ide_tweaks_addin_set_resource_paths (IDE_TWEAKS_ADDIN (self),
+ IDE_STRV_INIT ("/plugins/sdkui/tweaks.ui"));
+ ide_tweaks_addin_bind_callback (IDE_TWEAKS_ADDIN (self), create_sdk_list_cb);
+}
diff --git a/src/plugins/sdkui/gbp-sdkui-tweaks-addin.h b/src/plugins/sdkui/gbp-sdkui-tweaks-addin.h
new file mode 100644
index 000000000..6d367350e
--- /dev/null
+++ b/src/plugins/sdkui/gbp-sdkui-tweaks-addin.h
@@ -0,0 +1,31 @@
+/* gbp-sdkui-tweaks-addin.h
+ *
+ * Copyright 2022 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 <libide-tweaks.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_SDKUI_TWEAKS_ADDIN (gbp_sdkui_tweaks_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpSdkuiTweaksAddin, gbp_sdkui_tweaks_addin, GBP, SDKUI_TWEAKS_ADDIN, IdeTweaksAddin)
+
+G_END_DECLS
diff --git a/src/plugins/sdkui/meson.build b/src/plugins/sdkui/meson.build
new file mode 100644
index 000000000..df9374ff9
--- /dev/null
+++ b/src/plugins/sdkui/meson.build
@@ -0,0 +1,12 @@
+plugins_sources += files([
+ 'sdkui-plugin.c',
+ 'gbp-sdkui-tweaks-addin.c',
+])
+
+plugin_sdkui_resources = gnome.compile_resources(
+ 'sdkui-resources',
+ 'sdkui.gresource.xml',
+ c_name: 'gbp_sdkui',
+)
+
+plugins_sources += plugin_sdkui_resources
diff --git a/src/plugins/sdkui/sdkui-plugin.c b/src/plugins/sdkui/sdkui-plugin.c
new file mode 100644
index 000000000..7a8b9c359
--- /dev/null
+++ b/src/plugins/sdkui/sdkui-plugin.c
@@ -0,0 +1,38 @@
+/* sdkui-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 "sdkui-plugin"
+
+#include "config.h"
+
+#include <libpeas/peas.h>
+
+#include <libide-gui.h>
+#include <libide-tweaks.h>
+
+#include "gbp-sdkui-tweaks-addin.h"
+
+_IDE_EXTERN void
+_gbp_sdkui_register_types (PeasObjectModule *module)
+{
+ peas_object_module_register_extension_type (module,
+ IDE_TYPE_TWEAKS_ADDIN,
+ GBP_TYPE_SDKUI_TWEAKS_ADDIN);
+}
diff --git a/src/plugins/sdkui/sdkui.gresource.xml b/src/plugins/sdkui/sdkui.gresource.xml
new file mode 100644
index 000000000..f2691ff40
--- /dev/null
+++ b/src/plugins/sdkui/sdkui.gresource.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/plugins/sdkui">
+ <file>sdkui.plugin</file>
+ <file preprocess="xml-stripblanks">tweaks.ui</file>
+ </gresource>
+</gresources>
diff --git a/src/plugins/sdkui/sdkui.plugin b/src/plugins/sdkui/sdkui.plugin
new file mode 100644
index 000000000..fa227dd69
--- /dev/null
+++ b/src/plugins/sdkui/sdkui.plugin
@@ -0,0 +1,8 @@
+[Plugin]
+Authors=Christian Hergert <christian hergert me>
+Builtin=true
+Copyright=Copyright © 2022 Christian Hergert
+Embedded=_gbp_sdkui_register_types
+Hidden=true
+Module=sdkui
+Name=SDK UI Integration
diff --git a/src/plugins/sdkui/tweaks.ui b/src/plugins/sdkui/tweaks.ui
new file mode 100644
index 000000000..93ec3d3d2
--- /dev/null
+++ b/src/plugins/sdkui/tweaks.ui
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="IdeTweaks">
+ <child internal-child="external_section">
+ <object class="IdeTweaksSection">
+ <child>
+ <object class="IdeTweaksPage" id="sdk_page">
+ <property name="icon-name">builder-sdk-symbolic</property>
+ <property name="title" translatable="yes">SDKs</property>
+ <child>
+ <object class="IdeTweaksGroup">
+ <property name="title" translatable="yes">Downloads</property>
+ <child>
+ <object class="IdeTweaksSwitch">
+ <property name="title" translatable="yes">Download on Metered Connections</property>
+ <property name="subtitle" translatable="yes">Allow the download of SDKs and dependencies
when on metered internet connections</property>
+ <property
name="action-name">settings.org.gnome.builder.build.allow-network-when-metered</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="IdeTweaksGroup">
+ <property name="title" translatable="yes">Available SDKs</property>
+ <child>
+ <object class="IdeTweaksWidget" id="sdk_list">
+ <signal name="create-for-item" handler="create_sdk_list_cb" swapped="true"
object="GbpSdkuiTweaksAddin"/>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]