From 9f7daf5f4f2494d8ea889baa99bb6f2b4a397ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Thu, 15 Feb 2018 11:39:08 +0000 Subject: [PATCH 1/7] sysroot: add a new plugin allowing to specify the sysroot A developer might want to specify the sysroot (the path to another system root where all the libraries will be used). This is notably used when compiling for a foreign architecture or system. This is ensured to work with the default GNOME project generated by GNOME Builder. It is currently possible to specify the sysroot path and give extra arguments to Pkg-Config as the differents multiarch implementations are difficult to handle. --- meson_options.txt | 1 + src/plugins/meson.build | 2 + .../sysroot/ide-host-subprocess-launcher.c | 96 ++++++++ .../sysroot/ide-host-subprocess-launcher.h | 32 +++ src/plugins/sysroot/ide-sysroot-manager.c | 232 ++++++++++++++++++ src/plugins/sysroot/ide-sysroot-manager.h | 56 +++++ .../sysroot/ide-sysroot-preferences-addin.c | 201 +++++++++++++++ .../sysroot/ide-sysroot-preferences-addin.h | 30 +++ .../sysroot/ide-sysroot-preferences-row.c | 230 +++++++++++++++++ .../sysroot/ide-sysroot-preferences-row.h | 32 +++ .../sysroot/ide-sysroot-preferences-row.ui | 123 ++++++++++ .../sysroot/ide-sysroot-runtime-provider.c | 171 +++++++++++++ .../sysroot/ide-sysroot-runtime-provider.h | 30 +++ src/plugins/sysroot/ide-sysroot-runtime.c | 187 ++++++++++++++ src/plugins/sysroot/ide-sysroot-runtime.h | 33 +++ src/plugins/sysroot/meson.build | 28 +++ src/plugins/sysroot/sysroot-plugin.c | 30 +++ src/plugins/sysroot/sysroot.gresource.xml | 9 + src/plugins/sysroot/sysroot.plugin | 8 + 19 files changed, 1531 insertions(+) create mode 100644 src/plugins/sysroot/ide-host-subprocess-launcher.c create mode 100644 src/plugins/sysroot/ide-host-subprocess-launcher.h create mode 100644 src/plugins/sysroot/ide-sysroot-manager.c create mode 100644 src/plugins/sysroot/ide-sysroot-manager.h create mode 100644 src/plugins/sysroot/ide-sysroot-preferences-addin.c create mode 100644 src/plugins/sysroot/ide-sysroot-preferences-addin.h create mode 100644 src/plugins/sysroot/ide-sysroot-preferences-row.c create mode 100644 src/plugins/sysroot/ide-sysroot-preferences-row.h create mode 100644 src/plugins/sysroot/ide-sysroot-preferences-row.ui create mode 100644 src/plugins/sysroot/ide-sysroot-runtime-provider.c create mode 100644 src/plugins/sysroot/ide-sysroot-runtime-provider.h create mode 100644 src/plugins/sysroot/ide-sysroot-runtime.c create mode 100644 src/plugins/sysroot/ide-sysroot-runtime.h create mode 100644 src/plugins/sysroot/meson.build create mode 100644 src/plugins/sysroot/sysroot-plugin.c create mode 100644 src/plugins/sysroot/sysroot.gresource.xml create mode 100644 src/plugins/sysroot/sysroot.plugin diff --git a/meson_options.txt b/meson_options.txt index aa0e00f5c..03e386b06 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -71,6 +71,7 @@ option('with_support', type: 'boolean') option('with_symbol_tree', type: 'boolean') option('with_sysmon', type: 'boolean') option('with_sysprof', type: 'boolean') +option('with_sysroot', type: 'boolean') option('with_todo', type: 'boolean') option('with_vala_pack', type: 'boolean') option('with_valgrind', type: 'boolean') diff --git a/src/plugins/meson.build b/src/plugins/meson.build index d97d7e373..b37ea3fac 100644 --- a/src/plugins/meson.build +++ b/src/plugins/meson.build @@ -65,6 +65,7 @@ subdir('support') subdir('symbol-tree') subdir('sysmon') subdir('sysprof') +subdir('sysroot') subdir('terminal') subdir('todo') subdir('vala-pack') @@ -141,6 +142,7 @@ status += [ 'Symbol Tree ........... : @0@'.format(get_option('with_symbol_tree')), 'System Monitor ........ : @0@'.format(get_option('with_sysmon')), 'Sysprof Profiler ...... : @0@'.format(get_option('with_sysprof')), + 'Sysroot ...... : @0@'.format(get_option('with_sysroot')), 'Todo .................. : @0@'.format(get_option('with_todo')), 'Vala Language Pack .... : @0@'.format(get_option('with_vala_pack')), 'Valgrind .............. : @0@'.format(get_option('with_valgrind')), diff --git a/src/plugins/sysroot/ide-host-subprocess-launcher.c b/src/plugins/sysroot/ide-host-subprocess-launcher.c new file mode 100644 index 000000000..d9d9f371b --- /dev/null +++ b/src/plugins/sysroot/ide-host-subprocess-launcher.c @@ -0,0 +1,96 @@ +/* ide-host-subprocess-launcher.c + * + * Copyright (C) 2018 Corentin Noël + * Copyright (C) 2018 Collabora Ltd. + * + * 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 . + */ + +#define G_LOG_DOMAIN "ide-host-subprocess-launcher" + +#include + +#include "ide-host-subprocess-launcher.h" + +struct _IdeHostSubprocessLauncher +{ + IdeSubprocessLauncher parent_instance; +}; + +G_DEFINE_TYPE (IdeHostSubprocessLauncher, + ide_host_subprocess_launcher, + IDE_TYPE_SUBPROCESS_LAUNCHER) + +IdeHostSubprocessLauncher * +ide_host_subprocess_launcher_new (GSubprocessFlags flags) +{ + return g_object_new (IDE_TYPE_HOST_SUBPROCESS_LAUNCHER, + "flags", flags, + NULL); +} + +static IdeSubprocess * +ide_hostsubprocess_launcher_spawn (IdeSubprocessLauncher *self, + GCancellable *cancellable, + GError **error) +{ + gchar *argv = NULL; + const gchar * const *args = NULL; + const gchar * const *environ = NULL; + GString *cmd = NULL; + + g_assert (IDE_IS_SUBPROCESS_LAUNCHER (self)); + g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); + + // don't prepend `sh -c` twice + args = ide_subprocess_launcher_get_argv (self); + if (g_strv_length ((gchar **)args) >= 2) + { + if (g_strcmp0 (args[0], "sh") == 0 && g_strcmp0 (args[1], "-c") == 0) + { + return IDE_SUBPROCESS_LAUNCHER_CLASS (ide_host_subprocess_launcher_parent_class)->spawn (self, cancellable, error); + } + } + + argv = ide_subprocess_launcher_pop_argv (self); + cmd = g_string_new (argv); + g_free (argv); + + while ((argv = ide_subprocess_launcher_pop_argv (self)) != NULL) + { + g_string_prepend (cmd, " "); + g_string_prepend (cmd, argv); + g_free (argv); + } + + ide_subprocess_launcher_push_argv (self, "sh"); + ide_subprocess_launcher_push_argv (self, "-c"); + ide_subprocess_launcher_push_argv (self, g_string_free (cmd, FALSE)); + + return IDE_SUBPROCESS_LAUNCHER_CLASS (ide_host_subprocess_launcher_parent_class)->spawn (self, cancellable, error); +} + +static void +ide_host_subprocess_launcher_class_init (IdeHostSubprocessLauncherClass *klass) +{ + IdeSubprocessLauncherClass *subprocess_launcher_class = IDE_SUBPROCESS_LAUNCHER_CLASS (klass); + + subprocess_launcher_class->spawn = ide_hostsubprocess_launcher_spawn; +} + +static void +ide_host_subprocess_launcher_init (IdeHostSubprocessLauncher *self) +{ + +} diff --git a/src/plugins/sysroot/ide-host-subprocess-launcher.h b/src/plugins/sysroot/ide-host-subprocess-launcher.h new file mode 100644 index 000000000..e5f0f8f7f --- /dev/null +++ b/src/plugins/sysroot/ide-host-subprocess-launcher.h @@ -0,0 +1,32 @@ +/* ide-host-subprocess-launcher.h + * + * Copyright (C) 2018 Corentin Noël + * Copyright (C) 2018 Collabora Ltd. + * + * 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 . + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define IDE_TYPE_HOST_SUBPROCESS_LAUNCHER (ide_host_subprocess_launcher_get_type()) + +G_DECLARE_FINAL_TYPE (IdeHostSubprocessLauncher, ide_host_subprocess_launcher, IDE, HOST_SUBPROCESS_LAUNCHER, IdeSubprocessLauncher) + +IdeHostSubprocessLauncher *ide_host_subprocess_launcher_new (GSubprocessFlags flags); + +G_END_DECLS diff --git a/src/plugins/sysroot/ide-sysroot-manager.c b/src/plugins/sysroot/ide-sysroot-manager.c new file mode 100644 index 000000000..a0fbc6b72 --- /dev/null +++ b/src/plugins/sysroot/ide-sysroot-manager.c @@ -0,0 +1,232 @@ +/* ide-sysroot-manager.c + * + * Copyright (C) 2018 Corentin Noël + * Copyright (C) 2018 Collabora Ltd. + * + * 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 . + */ + +#include "ide-sysroot-manager.h" + +struct _IdeSysrootManager +{ + GObject parent_instance; + GKeyFile *key_file; +}; + +G_DEFINE_TYPE (IdeSysrootManager, ide_sysroot_manager, G_TYPE_OBJECT) + +enum { + TARGET_MODIFIED, + TARGET_NAME_CHANGED, + LAST_SIGNAL +}; + +static guint signals [LAST_SIGNAL]; + +static IdeSysrootManager *instance; + +gchar * +sysroot_manager_get_path (void) +{ + gchar *directory_path = NULL; + gchar *conf_file = NULL; + + directory_path = g_build_filename (g_get_user_config_dir (), + ide_get_program_name (), + "sysroot", + NULL); + + g_mkdir_with_parents (directory_path, 0750); + conf_file = g_build_filename (directory_path, "general.conf", NULL); + g_free (directory_path); + return conf_file; +} + +static void +sysroot_manager_save (IdeSysrootManager *self) +{ + gchar *conf_file = NULL; + GError *error = NULL; + conf_file = sysroot_manager_get_path (); + + if (!g_key_file_save_to_file (self->key_file, conf_file, &error)) + { + g_critical ("Error loading the sysroot configuration: %s", error->message); + g_error_free (error); + } + + g_free (conf_file); +} + +IdeSysrootManager * +ide_sysroot_manager_get_default (void) +{ + if (instance == NULL) + { + instance = g_object_new (IDE_TYPE_SYSROOT_MANAGER, NULL); + } + + return instance; +} + +gchar * +ide_sysroot_manager_create_target (IdeSysrootManager *self) +{ + for (guint i = 0; i < UINT_MAX; i++) + { + gchar * result; + GString *sysroot_name = g_string_new (NULL); + g_string_printf (sysroot_name, "Sysroot %u", i); + result = g_string_free (sysroot_name, FALSE); + if (!g_key_file_has_group (self->key_file, result)) + { + g_key_file_set_string (self->key_file, result, "Name", result); + g_key_file_set_string (self->key_file, result, "Path", "/"); + sysroot_manager_save (self); + g_signal_emit (self, signals[TARGET_MODIFIED], 0, result, IDE_SYSROOT_MANAGER_TARGET_CREATED); + return result; + } + } + + return NULL; +} + +void +ide_sysroot_manager_remove_target (IdeSysrootManager *self, const char *target) +{ + GError *error = NULL; + g_key_file_remove_group (self->key_file, target, &error); + if (error) + { + g_critical ("Error removing target \"%s\": %s", target, error->message); + g_error_free (error); + } + + g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, IDE_SYSROOT_MANAGER_TARGET_REMOVED); + sysroot_manager_save (self); +} + +void +ide_sysroot_manager_set_target_name (IdeSysrootManager *self, const char *target, const char *name) +{ + g_key_file_set_string (self->key_file, target, "Name", name); + g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, IDE_SYSROOT_MANAGER_TARGET_CHANGED); + g_signal_emit (self, signals[TARGET_NAME_CHANGED], 0, target, name); + sysroot_manager_save (self); +} + +gchar * +ide_sysroot_manager_get_target_name (IdeSysrootManager *self, const char *target) +{ + return g_key_file_get_string (self->key_file, target, "Name", NULL); +} + +void +ide_sysroot_manager_set_target_path (IdeSysrootManager *self, const char *target, const char *path) +{ + g_key_file_set_string (self->key_file, target, "Path", path); + g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, IDE_SYSROOT_MANAGER_TARGET_CHANGED); + sysroot_manager_save (self); +} + +gchar * +ide_sysroot_manager_get_target_path (IdeSysrootManager *self, const char *target) +{ + return g_key_file_get_string (self->key_file, target, "Path", NULL); +} + +void +ide_sysroot_manager_set_target_pkg_config_path (IdeSysrootManager *self, const char *target, const char *path) +{ + g_key_file_set_string (self->key_file, target, "PkgConfigPath", path); + g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, IDE_SYSROOT_MANAGER_TARGET_CHANGED); + sysroot_manager_save (self); +} + +gchar * +ide_sysroot_manager_get_target_pkg_config_path (IdeSysrootManager *self, const char *target) +{ + return g_key_file_get_string (self->key_file, target, "PkgConfigPath", NULL); +} + +GArray * +ide_sysroot_manager_list (IdeSysrootManager *self) +{ + GArray *list = NULL; + gchar **groups = NULL; + gsize groups_length = 0; + + list = g_array_new (FALSE, FALSE, sizeof (char*)); + groups = g_key_file_get_groups (self->key_file, &groups_length); + g_array_append_vals (list, groups, groups_length); + + return list; +} + +void +ide_sysroot_manager_finalize (GObject *object) +{ + IdeSysrootManager *self = IDE_SYSROOT_MANAGER(object); + + g_clear_pointer (&self->key_file, g_key_file_free); + + G_OBJECT_CLASS (ide_sysroot_manager_parent_class)->finalize (object); +} + +void +ide_sysroot_manager_class_init (IdeSysrootManagerClass *klass) +{ + G_OBJECT_CLASS (klass)->finalize = ide_sysroot_manager_finalize; + + signals [TARGET_MODIFIED] = + g_signal_new_class_handler ("target-changed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST, + NULL, NULL, NULL, NULL, + G_TYPE_NONE, + 2, + G_TYPE_STRING, + G_TYPE_INT); + + signals [TARGET_NAME_CHANGED] = + g_signal_new_class_handler ("target-name-changed", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_FIRST, + NULL, NULL, NULL, NULL, + G_TYPE_NONE, + 2, + G_TYPE_STRING, + G_TYPE_STRING); +} + +static void +ide_sysroot_manager_init (IdeSysrootManager *self) +{ + gchar *conf_file = NULL; + GError *error = NULL; + + conf_file = sysroot_manager_get_path (); + self->key_file = g_key_file_new (); + g_key_file_load_from_file (self->key_file, conf_file, G_KEY_FILE_KEEP_COMMENTS, &error); + if (error) + { + if (error->code != G_FILE_ERROR_NOENT) + { + g_critical ("Error loading the sysroot configuration: %s", error->message); + } + + g_error_free (error); + } +} diff --git a/src/plugins/sysroot/ide-sysroot-manager.h b/src/plugins/sysroot/ide-sysroot-manager.h new file mode 100644 index 000000000..c1db3b011 --- /dev/null +++ b/src/plugins/sysroot/ide-sysroot-manager.h @@ -0,0 +1,56 @@ +/* ide-sysroot-manager.h + * + * Copyright (C) 2018 Corentin Noël + * Copyright (C) 2018 Collabora Ltd. + * + * 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 . + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define IDE_TYPE_SYSROOT_MANAGER (ide_sysroot_manager_get_type()) + +G_DECLARE_FINAL_TYPE (IdeSysrootManager, ide_sysroot_manager, IDE, SYSROOT_MANAGER, GObject) + +typedef enum { + IDE_SYSROOT_MANAGER_TARGET_CHANGED, + IDE_SYSROOT_MANAGER_TARGET_CREATED, + IDE_SYSROOT_MANAGER_TARGET_REMOVED +} IdeSysrootManagerTargetModificationType; + +IdeSysrootManager *ide_sysroot_manager_get_default (void); + +gchar *ide_sysroot_manager_create_target (IdeSysrootManager *self); + +void ide_sysroot_manager_remove_target (IdeSysrootManager *self, const char *target); + +void ide_sysroot_manager_set_target_name (IdeSysrootManager *self, const char *target, const char *path); + +gchar *ide_sysroot_manager_get_target_name (IdeSysrootManager *self, const char *target); + +void ide_sysroot_manager_set_target_path (IdeSysrootManager *self, const char *target, const char *path); + +gchar *ide_sysroot_manager_get_target_path (IdeSysrootManager *self, const char *target); + +void ide_sysroot_manager_set_target_pkg_config_path (IdeSysrootManager *self, const char *target, const char *path); + +gchar *ide_sysroot_manager_get_target_pkg_config_path (IdeSysrootManager *self, const char *target); + +GArray *ide_sysroot_manager_list (IdeSysrootManager *self); + +G_END_DECLS diff --git a/src/plugins/sysroot/ide-sysroot-preferences-addin.c b/src/plugins/sysroot/ide-sysroot-preferences-addin.c new file mode 100644 index 000000000..44e03efc5 --- /dev/null +++ b/src/plugins/sysroot/ide-sysroot-preferences-addin.c @@ -0,0 +1,201 @@ +/* ide-sysroot-preferences.c + * + * Copyright (C) 2018 Corentin Noël + * Copyright (C) 2018 Collabora Ltd. + * + * 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, eitIher 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 . + */ + +#define G_LOG_DOMAIN "ide-sysroot-preferences-addin" + +#include + +#include "ide-sysroot-preferences-addin.h" +#include "ide-sysroot-preferences-row.h" +#include "ide-sysroot-manager.h" + +struct _IdeSysrootPreferencesAddin +{ + GObject parent_instance; + + GArray *ids; + DzlPreferences *preferences; +}; + +static void sysroot_preferences_add_new (IdeSysrootPreferencesAddin *self, + GtkWidget *emitter) +{ + GtkWidget *pref_row = NULL; + guint id = 0; + gchar *new_target; + IdeSysrootManager *sysroot_manager = NULL; + + g_assert (IDE_IS_SYSROOT_PREFERENCES_ADDIN (self)); + g_assert (DZL_IS_PREFERENCES_BIN (emitter)); + + sysroot_manager = ide_sysroot_manager_get_default (); + new_target = ide_sysroot_manager_create_target (sysroot_manager); + pref_row = g_object_new (IDE_TYPE_SYSROOT_PREFERENCES_ROW, + "visible", TRUE, + "sysroot-id", new_target, + NULL); + + id = dzl_preferences_add_custom (self->preferences, "sdk", "sysroot", pref_row, "", 1); + g_array_append_val (self->ids, id); + + ide_sysroot_preferences_row_show_popup (IDE_SYSROOT_PREFERENCES_ROW (pref_row)); +} + +GtkWidget * +sysroot_preferences_get_add_widget (IdeSysrootPreferencesAddin *self) +{ + GtkWidget *bin = NULL; + GtkWidget *grid = NULL; + GtkWidget *label = NULL; + GtkWidget *subtitle = NULL; + GtkWidget *image = NULL; + + bin = g_object_new (DZL_TYPE_PREFERENCES_BIN, + "visible", TRUE, + NULL); + + grid = g_object_new (GTK_TYPE_GRID, + "visible", TRUE, + NULL); + + label = g_object_new (GTK_TYPE_LABEL, + "visible", TRUE, + "label", _("Add sysroot"), + "xalign", 0.0f, + "hexpand", TRUE, + NULL); + + subtitle = g_object_new (GTK_TYPE_LABEL, + "visible", TRUE, + "label", g_markup_printf_escaped ("%s", _("Define a new sysroot target to build against a different target")), + "use-markup", TRUE, + "xalign", 0.0f, + "hexpand", TRUE, + NULL); + + gtk_style_context_add_class (gtk_widget_get_style_context (subtitle), GTK_STYLE_CLASS_DIM_LABEL); + + image = g_object_new (GTK_TYPE_IMAGE, + "visible", TRUE, + "icon-name", "list-add-symbolic", + "valign", GTK_ALIGN_CENTER, + NULL); + + gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1); + gtk_grid_attach (GTK_GRID (grid), subtitle, 0, 1, 1, 1); + gtk_grid_attach (GTK_GRID (grid), image, 1, 0, 1, 2); + + gtk_container_add (GTK_CONTAINER (bin), grid); + + g_signal_connect_swapped (bin, "preference-activated", G_CALLBACK(sysroot_preferences_add_new), self); + + return bin; +} + +static void +ide_sysroot_preferences_addin_load (IdePreferencesAddin *addin, + DzlPreferences *preferences) +{ + IdeSysrootPreferencesAddin *self = IDE_SYSROOT_PREFERENCES_ADDIN (addin); + GtkWidget *widget = NULL; + IdeSysrootManager *sysroot_manager = NULL; + GArray *sysroots = NULL; + guint id = 0; + + IDE_ENTRY; + + g_assert (IDE_IS_SYSROOT_PREFERENCES_ADDIN (self)); + g_assert (DZL_IS_PREFERENCES (preferences)); + + self->ids = g_array_new (FALSE, FALSE, sizeof (guint)); + self->preferences = preferences; + + dzl_preferences_add_list_group (preferences, "sdk", "sysroot", _("Sysroots"), GTK_SELECTION_NONE, 0); + + widget = sysroot_preferences_get_add_widget (self); + id = dzl_preferences_add_custom (preferences, "sdk", "sysroot", widget, "", 0); + + g_array_append_val (self->ids, id); + + sysroot_manager = ide_sysroot_manager_get_default (); + sysroots = ide_sysroot_manager_list (sysroot_manager); + for (guint i = 0; i < sysroots->len; i++) + { + gchar *sysroot_id = g_array_index (sysroots, gchar*, i); + GtkWidget *pref_row = g_object_new (IDE_TYPE_SYSROOT_PREFERENCES_ROW, + "visible", TRUE, + "sysroot-id", sysroot_id, + NULL); + + id = dzl_preferences_add_custom (self->preferences, "sdk", "sysroot", pref_row, NULL, 1); + g_array_append_val (self->ids, id); + } + + g_array_free (sysroots, TRUE); + + IDE_EXIT; +} + +static void +ide_sysroot_preferences_addin_unload (IdePreferencesAddin *addin, + DzlPreferences *preferences) +{ + IdeSysrootPreferencesAddin *self = IDE_SYSROOT_PREFERENCES_ADDIN (addin); + + IDE_ENTRY; + + g_assert (IDE_IS_SYSROOT_PREFERENCES_ADDIN (self)); + g_assert (DZL_IS_PREFERENCES (preferences)); + + /* Clear preferences so reload code doesn't try to + * make forward progress updating items. + */ + self->preferences = NULL; + + for (guint i = 0; i < self->ids->len; i++) + { + guint id = g_array_index (self->ids, guint, i); + + dzl_preferences_remove_id (preferences, id); + } + + g_clear_pointer (&self->ids, g_array_unref); + + IDE_EXIT; +} + +static void +preferences_addin_iface_init (IdePreferencesAddinInterface *iface) +{ + iface->load = ide_sysroot_preferences_addin_load; + iface->unload = ide_sysroot_preferences_addin_unload; +} + +G_DEFINE_TYPE_EXTENDED (IdeSysrootPreferencesAddin, ide_sysroot_preferences_addin, G_TYPE_OBJECT, 0, + G_IMPLEMENT_INTERFACE (IDE_TYPE_PREFERENCES_ADDIN, preferences_addin_iface_init)) + +static void +ide_sysroot_preferences_addin_class_init (IdeSysrootPreferencesAddinClass *klass) +{ +} + +static void +ide_sysroot_preferences_addin_init (IdeSysrootPreferencesAddin *self) +{ +} diff --git a/src/plugins/sysroot/ide-sysroot-preferences-addin.h b/src/plugins/sysroot/ide-sysroot-preferences-addin.h new file mode 100644 index 000000000..a1f8e7b46 --- /dev/null +++ b/src/plugins/sysroot/ide-sysroot-preferences-addin.h @@ -0,0 +1,30 @@ +/* ide-sysroot-preferences.h + * + * Copyright (C) 2018 Corentin Noël + * Copyright (C) 2018 Collabora Ltd. + * + * 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, eitIher 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 . + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define IDE_TYPE_SYSROOT_PREFERENCES_ADDIN (ide_sysroot_preferences_addin_get_type()) + +G_DECLARE_FINAL_TYPE (IdeSysrootPreferencesAddin, ide_sysroot_preferences_addin, IDE, SYSROOT_PREFERENCES_ADDIN, GObject) + +G_END_DECLS diff --git a/src/plugins/sysroot/ide-sysroot-preferences-row.c b/src/plugins/sysroot/ide-sysroot-preferences-row.c new file mode 100644 index 000000000..b5880478c --- /dev/null +++ b/src/plugins/sysroot/ide-sysroot-preferences-row.c @@ -0,0 +1,230 @@ +/* ide-sysroot-preferences-row.c + * + * Copyright (C) 2018 Corentin Noël + * Copyright (C) 2018 Collabora Ltd. + * + * 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 . + */ + +#include "ide-sysroot-preferences-row.h" +#include "ide-sysroot-manager.h" + +struct _IdeSysrootPreferencesRow +{ + DzlPreferencesBin parent_instance; + gchar *sysroot_id; + GtkLabel *display_name; + GtkEntry *name_entry; + GtkEntry *sysroot_entry; + GtkEntry *pkg_config_entry; + GtkButton *delete_button; + GtkWidget *popover; +}; + +G_DEFINE_TYPE (IdeSysrootPreferencesRow, ide_sysroot_preferences_row, DZL_TYPE_PREFERENCES_BIN) + +enum { + PROP_0, + PROP_SYSROOT_ID, + LAST_PROP +}; + +static GParamSpec *properties [LAST_PROP]; + +static void +sysroot_preferences_row_name_changed (IdeSysrootPreferencesRow *self, gpointer user_data) +{ + IdeSysrootManager *sysroot_manager = NULL; + + g_assert (IDE_IS_SYSROOT_PREFERENCES_ROW (self)); + g_assert (GTK_IS_ENTRY (user_data)); + + sysroot_manager = ide_sysroot_manager_get_default (); + ide_sysroot_manager_set_target_name (sysroot_manager, self->sysroot_id, gtk_entry_get_text (GTK_ENTRY (user_data))); +} + +static void +sysroot_preferences_row_sysroot_changed (IdeSysrootPreferencesRow *self, gpointer user_data) +{ + IdeSysrootManager *sysroot_manager = NULL; + + g_assert (IDE_IS_SYSROOT_PREFERENCES_ROW (self)); + g_assert (GTK_IS_ENTRY (user_data)); + + sysroot_manager = ide_sysroot_manager_get_default (); + ide_sysroot_manager_set_target_path (sysroot_manager, self->sysroot_id, gtk_entry_get_text (GTK_ENTRY (user_data))); +} + +static void +sysroot_preferences_row_pkg_config_changed (IdeSysrootPreferencesRow *self, gpointer user_data) +{ + IdeSysrootManager *sysroot_manager = NULL; + + g_assert (IDE_IS_SYSROOT_PREFERENCES_ROW (self)); + g_assert (GTK_IS_ENTRY (user_data)); + + sysroot_manager = ide_sysroot_manager_get_default (); + ide_sysroot_manager_set_target_pkg_config_path (sysroot_manager, self->sysroot_id, gtk_entry_get_text (GTK_ENTRY (user_data))); +} + +static void +sysroot_preferences_row_clicked (IdeSysrootPreferencesRow *self, gpointer user_data) +{ + ide_sysroot_preferences_row_show_popup (self); +} + +static void +sysroot_preferences_delete (IdeSysrootPreferencesRow *self, gpointer user_data) +{ + IdeSysrootManager *sysroot_manager = NULL; + + g_assert (IDE_IS_SYSROOT_PREFERENCES_ROW (self)); + + sysroot_manager = ide_sysroot_manager_get_default (); + ide_sysroot_manager_remove_target (sysroot_manager, self->sysroot_id); + + // The row is wrapped into a GtkListBoxRow that won't be removed when child is destroyed + gtk_widget_destroy (gtk_widget_get_parent (GTK_WIDGET (self))); +} + +static void +ide_sysroot_preferences_row_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + IdeSysrootPreferencesRow *self = IDE_SYSROOT_PREFERENCES_ROW (object); + + switch (prop_id) + { + case PROP_SYSROOT_ID: + g_value_set_string (value, self->sysroot_id); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +ide_sysroot_preferences_row_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + IdeSysrootPreferencesRow *self = IDE_SYSROOT_PREFERENCES_ROW (object); + + switch (prop_id) + { + case PROP_SYSROOT_ID: + self->sysroot_id = g_value_dup_string (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + } +} + +static void +ide_sysroot_preferences_row_finalize (GObject *object) +{ + IdeSysrootPreferencesRow *self = IDE_SYSROOT_PREFERENCES_ROW (object); + + g_clear_pointer (&self->sysroot_id, g_free); + + G_OBJECT_CLASS (ide_sysroot_preferences_row_parent_class)->finalize (object); +} + +void +ide_sysroot_preferences_row_show_popup (IdeSysrootPreferencesRow *self) +{ + gtk_popover_popup (GTK_POPOVER (self->popover)); + gtk_popover_set_modal (GTK_POPOVER (self->popover), TRUE); +} + +static GObject * +ide_sysroot_preferences_row_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam * construct_properties) +{ + IdeSysrootManager *sysroot_manager = NULL; + gchar *value; + GObject * obj = G_OBJECT_CLASS (ide_sysroot_preferences_row_parent_class)->constructor (type, n_construct_properties, construct_properties); + IdeSysrootPreferencesRow *self = IDE_SYSROOT_PREFERENCES_ROW (obj); + + sysroot_manager = ide_sysroot_manager_get_default (); + gtk_entry_set_text (self->name_entry, ide_sysroot_manager_get_target_name (sysroot_manager, self->sysroot_id)); + gtk_entry_set_text (self->sysroot_entry, ide_sysroot_manager_get_target_path (sysroot_manager, self->sysroot_id)); + value = ide_sysroot_manager_get_target_pkg_config_path (sysroot_manager, self->sysroot_id); + if (value != NULL) + gtk_entry_set_text (self->pkg_config_entry, value); + + g_signal_connect_object (self->name_entry, + "changed", + G_CALLBACK (sysroot_preferences_row_name_changed), + self, + G_CONNECT_SWAPPED); + + g_signal_connect_object (self->sysroot_entry, + "changed", + G_CALLBACK (sysroot_preferences_row_sysroot_changed), + self, + G_CONNECT_SWAPPED); + + g_signal_connect_object (self->pkg_config_entry, + "changed", + G_CALLBACK (sysroot_preferences_row_pkg_config_changed), + self, + G_CONNECT_SWAPPED); + return obj; +} + +static void +ide_sysroot_preferences_row_class_init (IdeSysrootPreferencesRowClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + object_class->finalize = ide_sysroot_preferences_row_finalize; + object_class->get_property = ide_sysroot_preferences_row_get_property; + object_class->set_property = ide_sysroot_preferences_row_set_property; + object_class->constructor = ide_sysroot_preferences_row_constructor; + + properties [PROP_SYSROOT_ID] = + g_param_spec_string ("sysroot-id", + "Sysroot ID", + "Internal id of the sysroot", + NULL, + (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_properties (object_class, LAST_PROP, properties); + + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/builder/plugins/sysroot-plugin/ide-sysroot-preferences-row.ui"); + gtk_widget_class_bind_template_child (widget_class, IdeSysrootPreferencesRow, display_name); + gtk_widget_class_bind_template_child (widget_class, IdeSysrootPreferencesRow, popover); + gtk_widget_class_bind_template_child (widget_class, IdeSysrootPreferencesRow, name_entry); + gtk_widget_class_bind_template_child (widget_class, IdeSysrootPreferencesRow, sysroot_entry); + gtk_widget_class_bind_template_child (widget_class, IdeSysrootPreferencesRow, pkg_config_entry); + gtk_widget_class_bind_template_child (widget_class, IdeSysrootPreferencesRow, delete_button); +} + +static void +ide_sysroot_preferences_row_init (IdeSysrootPreferencesRow *self) +{ + gtk_widget_init_template (GTK_WIDGET (self)); + + g_signal_connect (self, "preference-activated", G_CALLBACK(sysroot_preferences_row_clicked), NULL); + g_signal_connect_swapped (self->delete_button, "clicked", G_CALLBACK(sysroot_preferences_delete), self); + g_object_bind_property (self->name_entry, "text", self->display_name, "label", 0); +} diff --git a/src/plugins/sysroot/ide-sysroot-preferences-row.h b/src/plugins/sysroot/ide-sysroot-preferences-row.h new file mode 100644 index 000000000..4fd314c95 --- /dev/null +++ b/src/plugins/sysroot/ide-sysroot-preferences-row.h @@ -0,0 +1,32 @@ +/* ide-sysroot-preferences-row.h + * + * Copyright (C) 2018 Corentin Noël + * Copyright (C) 2018 Collabora Ltd. + * + * 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 . + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define IDE_TYPE_SYSROOT_PREFERENCES_ROW (ide_sysroot_preferences_row_get_type()) + +G_DECLARE_FINAL_TYPE (IdeSysrootPreferencesRow, ide_sysroot_preferences_row, IDE, SYSROOT_PREFERENCES_ROW, DzlPreferencesBin) + +void ide_sysroot_preferences_row_show_popup (IdeSysrootPreferencesRow *self); + +G_END_DECLS diff --git a/src/plugins/sysroot/ide-sysroot-preferences-row.ui b/src/plugins/sysroot/ide-sysroot-preferences-row.ui new file mode 100644 index 000000000..bddd70179 --- /dev/null +++ b/src/plugins/sysroot/ide-sysroot-preferences-row.ui @@ -0,0 +1,123 @@ + + + + + + image + bottom + true + + + horizontal + 12 + 6 + 6 + true + + + true + 1.0 + Name + + + 0 + 0 + + + + + true + true + true + + + 1 + 0 + + + + + true + 1.0 + Sysroot path + + + 0 + 1 + + + + + true + true + true + + + 1 + 1 + + + + + true + 1.0 + Additional Pkg-config path + + + 0 + 2 + + + + + true + true + true + + + 1 + 2 + + + + + + Delete + true + true + true + end + + + 0 + 3 + 2 + + + + + + diff --git a/src/plugins/sysroot/ide-sysroot-runtime-provider.c b/src/plugins/sysroot/ide-sysroot-runtime-provider.c new file mode 100644 index 000000000..70345f52f --- /dev/null +++ b/src/plugins/sysroot/ide-sysroot-runtime-provider.c @@ -0,0 +1,171 @@ +/* ide-sysroot-runtime-provider.c + * + * Copyright (C) 2018 Corentin Noël + * Copyright (C) 2018 Collabora Ltd. + * + * 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 . + */ + +#define G_LOG_DOMAIN "ide-sysroot-runtime-provider" + +#include + +#include "ide-sysroot-runtime.h" +#include "ide-sysroot-runtime-provider.h" +#include "ide-sysroot-manager.h" + +struct _IdeSysrootRuntimeProvider +{ + IdeObject parent_instance; + + GPtrArray *runtimes; + IdeRuntimeManager *runtime_manager; +}; + +static void runtime_provider_iface_init (IdeRuntimeProviderInterface *iface); + +G_DEFINE_TYPE_EXTENDED (IdeSysrootRuntimeProvider, + ide_sysroot_runtime_provider, + IDE_TYPE_OBJECT, + 0, + G_IMPLEMENT_INTERFACE (IDE_TYPE_RUNTIME_PROVIDER, + runtime_provider_iface_init)) + +static void +sysroot_runtime_provider_remove_target (IdeSysrootRuntimeProvider *self, gchar *target) +{ + if (self->runtimes != NULL) + { + for (guint i= 0; i < self->runtimes->len; i++) + { + IdeRuntime *runtime = g_ptr_array_index (self->runtimes, i); + const gchar *sysroot_id = ide_sysroot_runtime_get_sysroot_id (IDE_SYSROOT_RUNTIME (runtime)); + if (g_strcmp0 (target, sysroot_id) == 0) + { + ide_runtime_manager_remove (self->runtime_manager, runtime); + return; + } + } + } +} + +static void +sysroot_runtime_provider_add_target (IdeSysrootRuntimeProvider *self, gchar *target) +{ + GObject *runtime = NULL; + IdeContext *context = NULL; + + context = ide_object_get_context (IDE_OBJECT (self->runtime_manager)); + runtime = ide_sysroot_runtime_new (context, target); + + ide_runtime_manager_add (self->runtime_manager, IDE_RUNTIME (runtime)); + g_ptr_array_add (self->runtimes, g_steal_pointer (&runtime)); +} + +static void +sysroot_runtime_provider_target_changed (IdeSysrootRuntimeProvider *self, + gchar *target, + IdeSysrootManagerTargetModificationType mod_type, + gpointer user_data) +{ + if (mod_type == IDE_SYSROOT_MANAGER_TARGET_CREATED) + { + sysroot_runtime_provider_add_target (self, target); + } + else if (mod_type == IDE_SYSROOT_MANAGER_TARGET_REMOVED) + { + sysroot_runtime_provider_remove_target (self, target); + } +} + +static void +ide_sysroot_runtime_provider_class_init (IdeSysrootRuntimeProviderClass *klass) +{ + +} + +static void +ide_sysroot_runtime_provider_init (IdeSysrootRuntimeProvider *self) +{ + +} + +static void +ide_sysroot_runtime_provider_load (IdeRuntimeProvider *provider, + IdeRuntimeManager *manager) +{ + IdeSysrootRuntimeProvider *self = IDE_SYSROOT_RUNTIME_PROVIDER (provider); + IdeSysrootManager *sysroot_manager = NULL; + GArray *sysroots = NULL; + + IDE_ENTRY; + + g_assert (IDE_IS_SYSROOT_RUNTIME_PROVIDER (self)); + g_assert (IDE_IS_RUNTIME_MANAGER (manager)); + + self->runtime_manager = manager; + self->runtimes = g_ptr_array_new_with_free_func (g_object_unref); + + sysroot_manager = ide_sysroot_manager_get_default (); + sysroots = ide_sysroot_manager_list (sysroot_manager); + for (guint i = 0; i < sysroots->len; i++) + { + gchar *sysroot_id = g_array_index (sysroots, gchar*, i); + sysroot_runtime_provider_add_target (self, sysroot_id); + } + + g_signal_connect_swapped (sysroot_manager, "target-changed", G_CALLBACK (sysroot_runtime_provider_target_changed), self); + + g_array_free (sysroots, TRUE); + + + IDE_EXIT; +} + +static void +ide_sysroot_runtime_provider_unload (IdeRuntimeProvider *provider, + IdeRuntimeManager *manager) +{ + IdeSysrootRuntimeProvider *self = IDE_SYSROOT_RUNTIME_PROVIDER (provider); + IdeSysrootManager *sysroot_manager = NULL; + + IDE_ENTRY; + + g_assert (IDE_IS_SYSROOT_RUNTIME_PROVIDER (self)); + g_assert (IDE_IS_RUNTIME_MANAGER (manager)); + + sysroot_manager = ide_sysroot_manager_get_default (); + g_object_unref (sysroot_manager); + + if (self->runtimes != NULL) + { + for (guint i= 0; i < self->runtimes->len; i++) + { + IdeRuntime *runtime = g_ptr_array_index (self->runtimes, i); + + ide_runtime_manager_remove (manager, runtime); + } + } + + g_clear_pointer (&self->runtimes, g_ptr_array_unref); + + IDE_EXIT; +} + +static void +runtime_provider_iface_init (IdeRuntimeProviderInterface *iface) +{ + iface->load = ide_sysroot_runtime_provider_load; + iface->unload = ide_sysroot_runtime_provider_unload; +} diff --git a/src/plugins/sysroot/ide-sysroot-runtime-provider.h b/src/plugins/sysroot/ide-sysroot-runtime-provider.h new file mode 100644 index 000000000..04a1ccc04 --- /dev/null +++ b/src/plugins/sysroot/ide-sysroot-runtime-provider.h @@ -0,0 +1,30 @@ +/* ide-sysroot-runtime-provider.h + * + * Copyright (C) 2018 Corentin Noël + * Copyright (C) 2018 Collabora Ltd. + * + * 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 . + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define IDE_TYPE_SYSROOT_RUNTIME_PROVIDER (ide_sysroot_runtime_provider_get_type()) + +G_DECLARE_FINAL_TYPE (IdeSysrootRuntimeProvider,ide_sysroot_runtime_provider, IDE, SYSROOT_RUNTIME_PROVIDER, IdeObject) + +G_END_DECLS diff --git a/src/plugins/sysroot/ide-sysroot-runtime.c b/src/plugins/sysroot/ide-sysroot-runtime.c new file mode 100644 index 000000000..5f0ee7b46 --- /dev/null +++ b/src/plugins/sysroot/ide-sysroot-runtime.c @@ -0,0 +1,187 @@ +/* ide-sysroot-runtime.c + * + * Copyright (C) 2018 Corentin Noël + * Copyright (C) 2018 Collabora Ltd. + * + * 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, eitIher 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 . + */ + +#define G_LOG_DOMAIN "ide-sysroot-runtime" + +#include "config.h" + +#include "ide-sysroot-runtime.h" +#include "ide-sysroot-manager.h" +#include "ide-host-subprocess-launcher.h" + +// This is a list of common libdirs to use +#define BASIC_LIBDIRS "/usr/lib/pkgconfig:/usr/share/pkgconfig" +#define RUNTIME_PREFIX "sysroot:" + +struct _IdeSysrootRuntime +{ + IdeRuntime parent_instance; +}; + +G_DEFINE_TYPE (IdeSysrootRuntime, ide_sysroot_runtime, IDE_TYPE_RUNTIME) + +GObject * +ide_sysroot_runtime_new (IdeContext *context, gchar* sysroot_id) +{ + GObject *runtime = NULL; + + g_return_val_if_fail (IDE_IS_CONTEXT (context), NULL); + + runtime = g_object_new (IDE_TYPE_SYSROOT_RUNTIME, + "id", g_strconcat (RUNTIME_PREFIX, sysroot_id, NULL), + "context", context, + "display-name", "", + NULL); + return runtime; +} + +const gchar * +ide_sysroot_runtime_get_sysroot_id (IdeSysrootRuntime *self) +{ + const gchar *runtime_id = ide_runtime_get_id (IDE_RUNTIME (self)); + if (!g_str_has_prefix (runtime_id, RUNTIME_PREFIX)) + return runtime_id; + + return g_utf8_offset_to_pointer (runtime_id, g_utf8_strlen (RUNTIME_PREFIX, -1)); +} + +static IdeSubprocessLauncher * +ide_sysroot_runtime_create_launcher (IdeRuntime *runtime, + GError **error) +{ + IdeSubprocessLauncher *ret; + IdeSysrootRuntime *self = IDE_SYSROOT_RUNTIME(runtime); + + IDE_ENTRY; + + g_return_val_if_fail (IDE_IS_SYSROOT_RUNTIME (self), NULL); + + ret = (IdeSubprocessLauncher *)ide_host_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE); + + if (ret != NULL) + { + IdeSysrootManager *sysroot_manager = NULL; + const gchar *env_var = NULL; + const gchar *sysroot_id = NULL; + gchar *sysroot_cflags = NULL; + gchar *sysroot_libdirs = NULL; + gchar **path_parts = NULL; + gchar *sysroot_path = NULL; + gchar *pkgconfig_dirs = NULL; + + sysroot_id = ide_sysroot_runtime_get_sysroot_id (self); + + sysroot_manager = ide_sysroot_manager_get_default (); + + ide_subprocess_launcher_set_run_on_host (ret, TRUE); + ide_subprocess_launcher_set_clear_env (ret, FALSE); + + sysroot_path = ide_sysroot_manager_get_target_path (sysroot_manager, sysroot_id); + + env_var = ide_subprocess_launcher_getenv (ret, "CFLAGS"); + sysroot_cflags = g_strconcat ("--sysroot=", sysroot_path, NULL); + ide_subprocess_launcher_setenv (ret, "CFLAGS", g_strjoin (" ", sysroot_cflags, env_var, NULL), TRUE); + g_free (sysroot_cflags); + + ide_subprocess_launcher_setenv (ret, "PKG_CONFIG_DIR", "", TRUE); + + ide_subprocess_launcher_setenv (ret, "PKG_CONFIG_SYSROOT_DIR", g_strdup (sysroot_path), TRUE); + + // Prepend the sysroot path to the BASIC_LIBDIRS values + path_parts = g_strsplit (BASIC_LIBDIRS, ":", 0); + for (gint i = g_strv_length (path_parts) - 1; i >= 0; i--) + { + gchar *path_i = g_build_path (G_DIR_SEPARATOR_S, sysroot_path, path_parts[i], NULL); + gchar *libdir_tmp = g_strjoin (":", path_i, sysroot_libdirs, NULL); + g_free (sysroot_libdirs); + sysroot_libdirs = libdir_tmp; + g_free (path_i); + } + + pkgconfig_dirs = ide_sysroot_manager_get_target_pkg_config_path (sysroot_manager, sysroot_id); + if (pkgconfig_dirs != NULL && g_strcmp0 (pkgconfig_dirs, "") != 0) + { + gchar *libdir_tmp = g_strjoin (":", pkgconfig_dirs, sysroot_libdirs, NULL); + g_free (sysroot_libdirs); + sysroot_libdirs = libdir_tmp; + } + + g_strfreev (path_parts); + ide_subprocess_launcher_setenv (ret, "PKG_CONFIG_LIBDIR", sysroot_libdirs, TRUE); + g_free (sysroot_libdirs); + } + else + { + g_set_error (error, + G_IO_ERROR, + G_IO_ERROR_FAILED, + "An unknown error ocurred"); + } + + IDE_RETURN (ret); +} + + +static void +sysroot_runtime_target_name_changed (IdeSysrootRuntime *self, + gchar *target, + gchar *new_name, + gpointer user_data) +{ + const gchar* sysroot_id = ide_sysroot_runtime_get_sysroot_id (self); + if (g_strcmp0 (target, sysroot_id) == 0) + ide_runtime_set_display_name (IDE_RUNTIME (self), new_name); +} + +static GObject * +ide_sysroot_runtime_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_properties) +{ + GObject *object = G_OBJECT_CLASS (ide_sysroot_runtime_parent_class)->constructor (type, n_construct_properties, construct_properties); + IdeSysrootManager *sysroot_manager = NULL; + gchar *display_name = NULL; + const gchar* sysroot_id = NULL; + + sysroot_id = ide_sysroot_runtime_get_sysroot_id (IDE_SYSROOT_RUNTIME (object)); + sysroot_manager = ide_sysroot_manager_get_default (); + display_name = ide_sysroot_manager_get_target_name (sysroot_manager, sysroot_id); + ide_runtime_set_display_name (IDE_RUNTIME (object), display_name); + + g_signal_connect_swapped (sysroot_manager, "target-name-changed", G_CALLBACK (sysroot_runtime_target_name_changed), object); + return object; +} + +static void +ide_sysroot_runtime_class_init (IdeSysrootRuntimeClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + IdeRuntimeClass *runtime_class = IDE_RUNTIME_CLASS (klass); + + object_class->constructor = ide_sysroot_runtime_constructor; + + runtime_class->create_launcher = ide_sysroot_runtime_create_launcher; +} + +static void +ide_sysroot_runtime_init (IdeSysrootRuntime *self) +{ + +} + diff --git a/src/plugins/sysroot/ide-sysroot-runtime.h b/src/plugins/sysroot/ide-sysroot-runtime.h new file mode 100644 index 000000000..0220aba01 --- /dev/null +++ b/src/plugins/sysroot/ide-sysroot-runtime.h @@ -0,0 +1,33 @@ +/* ide-sysroot-runtime.h + * + * Copyright (C) 2018 Corentin Noël + * Copyright (C) 2018 Collabora Ltd. + * + * 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 . + */ + +#pragma once + +#include + +G_BEGIN_DECLS + +#define IDE_TYPE_SYSROOT_RUNTIME (ide_sysroot_runtime_get_type()) + +G_DECLARE_FINAL_TYPE (IdeSysrootRuntime, ide_sysroot_runtime, IDE, SYSROOT_RUNTIME, IdeRuntime) + +GObject *ide_sysroot_runtime_new (IdeContext *context, gchar* sysroot_id); +const gchar *ide_sysroot_runtime_get_sysroot_id (IdeSysrootRuntime *self); + +G_END_DECLS diff --git a/src/plugins/sysroot/meson.build b/src/plugins/sysroot/meson.build new file mode 100644 index 000000000..1a15b79e2 --- /dev/null +++ b/src/plugins/sysroot/meson.build @@ -0,0 +1,28 @@ +if get_option('with_sysroot') + +sysroot_resources = gnome.compile_resources( + 'sysroot-resources', + 'sysroot.gresource.xml', + c_name: 'ide_sysroot', +) + +sysroot_sources = [ + 'sysroot-plugin.c', + 'ide-sysroot-runtime.c', + 'ide-sysroot-runtime.h', + 'ide-sysroot-runtime-provider.c', + 'ide-sysroot-runtime-provider.h', + 'ide-host-subprocess-launcher.c', + 'ide-host-subprocess-launcher.h', + 'ide-sysroot-preferences-addin.c', + 'ide-sysroot-preferences-addin.h', + 'ide-sysroot-preferences-row.c', + 'ide-sysroot-preferences-row.h', + 'ide-sysroot-manager.c', + 'ide-sysroot-manager.h' +] + +gnome_builder_plugins_sources += files(sysroot_sources) +gnome_builder_plugins_sources += sysroot_resources[0] + +endif diff --git a/src/plugins/sysroot/sysroot-plugin.c b/src/plugins/sysroot/sysroot-plugin.c new file mode 100644 index 000000000..424e2dda2 --- /dev/null +++ b/src/plugins/sysroot/sysroot-plugin.c @@ -0,0 +1,30 @@ +/* sysroot-plugin.c + * + * Copyright (C) 2018 Corentin Noël + * Copyright (C) 2018 Collabora Ltd. + * + * 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 . + */ + +#include + +#include "ide-sysroot-runtime-provider.h" +#include "ide-sysroot-preferences-addin.h" + +void +ide_sysroot_register_types (PeasObjectModule *module) +{ + peas_object_module_register_extension_type (module, IDE_TYPE_RUNTIME_PROVIDER, IDE_TYPE_SYSROOT_RUNTIME_PROVIDER); + peas_object_module_register_extension_type (module, IDE_TYPE_PREFERENCES_ADDIN, IDE_TYPE_SYSROOT_PREFERENCES_ADDIN); +} diff --git a/src/plugins/sysroot/sysroot.gresource.xml b/src/plugins/sysroot/sysroot.gresource.xml new file mode 100644 index 000000000..b03f6e6a0 --- /dev/null +++ b/src/plugins/sysroot/sysroot.gresource.xml @@ -0,0 +1,9 @@ + + + + sysroot.plugin + + + ide-sysroot-preferences-row.ui + + diff --git a/src/plugins/sysroot/sysroot.plugin b/src/plugins/sysroot/sysroot.plugin new file mode 100644 index 000000000..3277b70cc --- /dev/null +++ b/src/plugins/sysroot/sysroot.plugin @@ -0,0 +1,8 @@ +[Plugin] +Module=sysroot-plugin +Name=Sysroot Support +Description=Provides sysroot support +Authors=Corentin Noël +Copyright=Copyright © 2018 Collabora Ltd. +Builtin=true +Embedded=ide_sysroot_register_types -- GitLab From 4ff6cb1bf333a9ea207c14c07e6fd7b5433c6cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Thu, 22 Feb 2018 11:44:17 +0000 Subject: [PATCH 2/7] sysroot: align with project code-style --- .../sysroot/ide-host-subprocess-launcher.c | 33 ++--- src/plugins/sysroot/ide-sysroot-manager.c | 125 +++++++++++------- src/plugins/sysroot/ide-sysroot-manager.h | 39 +++--- .../sysroot/ide-sysroot-preferences-addin.c | 30 +++-- .../sysroot/ide-sysroot-preferences-row.c | 78 ++++++----- .../sysroot/ide-sysroot-runtime-provider.c | 50 +++---- src/plugins/sysroot/ide-sysroot-runtime.c | 67 +++++----- src/plugins/sysroot/ide-sysroot-runtime.h | 5 +- 8 files changed, 234 insertions(+), 193 deletions(-) diff --git a/src/plugins/sysroot/ide-host-subprocess-launcher.c b/src/plugins/sysroot/ide-host-subprocess-launcher.c index d9d9f371b..815ca6bd7 100644 --- a/src/plugins/sysroot/ide-host-subprocess-launcher.c +++ b/src/plugins/sysroot/ide-host-subprocess-launcher.c @@ -41,42 +41,35 @@ ide_host_subprocess_launcher_new (GSubprocessFlags flags) } static IdeSubprocess * -ide_hostsubprocess_launcher_spawn (IdeSubprocessLauncher *self, - GCancellable *cancellable, - GError **error) +ide_host_subprocess_launcher_spawn (IdeSubprocessLauncher *self, + GCancellable *cancellable, + GError **error) { - gchar *argv = NULL; + g_autofree gchar *argv = NULL; const gchar * const *args = NULL; - const gchar * const *environ = NULL; - GString *cmd = NULL; + g_autoptr(GString) cmd = NULL; - g_assert (IDE_IS_SUBPROCESS_LAUNCHER (self)); + g_assert (IDE_IS_HOST_SUBPROCESS_LAUNCHER (self)); g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - // don't prepend `sh -c` twice + /* don't prepend `sh -c` twice */ args = ide_subprocess_launcher_get_argv (self); - if (g_strv_length ((gchar **)args) >= 2) - { - if (g_strcmp0 (args[0], "sh") == 0 && g_strcmp0 (args[1], "-c") == 0) - { - return IDE_SUBPROCESS_LAUNCHER_CLASS (ide_host_subprocess_launcher_parent_class)->spawn (self, cancellable, error); - } - } + if (args[0] != NULL && g_strcmp0 (args[0], "sh") == 0 && g_strcmp0 (args[1], "-c") == 0) + return IDE_SUBPROCESS_LAUNCHER_CLASS (ide_host_subprocess_launcher_parent_class)->spawn (self, cancellable, error); argv = ide_subprocess_launcher_pop_argv (self); cmd = g_string_new (argv); - g_free (argv); while ((argv = ide_subprocess_launcher_pop_argv (self)) != NULL) { + g_autofree gchar *arg = g_shell_quote(argv); g_string_prepend (cmd, " "); - g_string_prepend (cmd, argv); - g_free (argv); + g_string_prepend (cmd, arg); } ide_subprocess_launcher_push_argv (self, "sh"); ide_subprocess_launcher_push_argv (self, "-c"); - ide_subprocess_launcher_push_argv (self, g_string_free (cmd, FALSE)); + ide_subprocess_launcher_push_argv (self, cmd->str); return IDE_SUBPROCESS_LAUNCHER_CLASS (ide_host_subprocess_launcher_parent_class)->spawn (self, cancellable, error); } @@ -86,7 +79,7 @@ ide_host_subprocess_launcher_class_init (IdeHostSubprocessLauncherClass *klass) { IdeSubprocessLauncherClass *subprocess_launcher_class = IDE_SUBPROCESS_LAUNCHER_CLASS (klass); - subprocess_launcher_class->spawn = ide_hostsubprocess_launcher_spawn; + subprocess_launcher_class->spawn = ide_host_subprocess_launcher_spawn; } static void diff --git a/src/plugins/sysroot/ide-sysroot-manager.c b/src/plugins/sysroot/ide-sysroot-manager.c index a0fbc6b72..92647340f 100644 --- a/src/plugins/sysroot/ide-sysroot-manager.c +++ b/src/plugins/sysroot/ide-sysroot-manager.c @@ -30,17 +30,15 @@ G_DEFINE_TYPE (IdeSysrootManager, ide_sysroot_manager, G_TYPE_OBJECT) enum { TARGET_MODIFIED, TARGET_NAME_CHANGED, - LAST_SIGNAL + N_SIGNALS }; -static guint signals [LAST_SIGNAL]; +static guint signals [N_SIGNALS]; -static IdeSysrootManager *instance; - -gchar * +static gchar * sysroot_manager_get_path (void) { - gchar *directory_path = NULL; + g_autofree gchar *directory_path = NULL; gchar *conf_file = NULL; directory_path = g_build_filename (g_get_user_config_dir (), @@ -50,29 +48,28 @@ sysroot_manager_get_path (void) g_mkdir_with_parents (directory_path, 0750); conf_file = g_build_filename (directory_path, "general.conf", NULL); - g_free (directory_path); - return conf_file; + return g_steal_pointer (&conf_file); } static void sysroot_manager_save (IdeSysrootManager *self) { - gchar *conf_file = NULL; - GError *error = NULL; + g_autofree gchar *conf_file = NULL; + g_autoptr(GError) error = NULL; + + g_assert (IDE_IS_SYSROOT_MANAGER (self)); + g_assert (self->key_file != NULL); + conf_file = sysroot_manager_get_path (); if (!g_key_file_save_to_file (self->key_file, conf_file, &error)) - { - g_critical ("Error loading the sysroot configuration: %s", error->message); - g_error_free (error); - } - - g_free (conf_file); + g_critical ("Error loading the sysroot configuration: %s", error->message); } IdeSysrootManager * ide_sysroot_manager_get_default (void) { + static IdeSysrootManager *instance; if (instance == NULL) { instance = g_object_new (IDE_TYPE_SYSROOT_MANAGER, NULL); @@ -84,19 +81,23 @@ ide_sysroot_manager_get_default (void) gchar * ide_sysroot_manager_create_target (IdeSysrootManager *self) { + g_return_val_if_fail (IDE_IS_SYSROOT_MANAGER (self), NULL); + g_return_val_if_fail (self->key_file != NULL, NULL); + for (guint i = 0; i < UINT_MAX; i++) { gchar * result; - GString *sysroot_name = g_string_new (NULL); + g_autoptr(GString) sysroot_name = g_string_new (NULL); + g_string_printf (sysroot_name, "Sysroot %u", i); - result = g_string_free (sysroot_name, FALSE); + result = sysroot_name->str; if (!g_key_file_has_group (self->key_file, result)) { g_key_file_set_string (self->key_file, result, "Name", result); g_key_file_set_string (self->key_file, result, "Path", "/"); sysroot_manager_save (self); g_signal_emit (self, signals[TARGET_MODIFIED], 0, result, IDE_SYSROOT_MANAGER_TARGET_CREATED); - return result; + return g_string_free (g_steal_pointer (&sysroot_name), FALSE); } } @@ -104,23 +105,32 @@ ide_sysroot_manager_create_target (IdeSysrootManager *self) } void -ide_sysroot_manager_remove_target (IdeSysrootManager *self, const char *target) +ide_sysroot_manager_remove_target (IdeSysrootManager *self, + const gchar *target) { - GError *error = NULL; + g_autoptr(GError) error = NULL; + + g_return_if_fail (IDE_IS_SYSROOT_MANAGER (self)); + g_return_if_fail (self->key_file != NULL); + g_return_if_fail (target != NULL); + g_key_file_remove_group (self->key_file, target, &error); if (error) - { - g_critical ("Error removing target \"%s\": %s", target, error->message); - g_error_free (error); - } + g_critical ("Error removing target \"%s\": %s", target, error->message); g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, IDE_SYSROOT_MANAGER_TARGET_REMOVED); sysroot_manager_save (self); } void -ide_sysroot_manager_set_target_name (IdeSysrootManager *self, const char *target, const char *name) +ide_sysroot_manager_set_target_name (IdeSysrootManager *self, + const gchar *target, + const gchar *name) { + g_return_if_fail (IDE_IS_SYSROOT_MANAGER (self)); + g_return_if_fail (self->key_file != NULL); + g_return_if_fail (target != NULL); + g_key_file_set_string (self->key_file, target, "Name", name); g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, IDE_SYSROOT_MANAGER_TARGET_CHANGED); g_signal_emit (self, signals[TARGET_NAME_CHANGED], 0, target, name); @@ -128,51 +138,73 @@ ide_sysroot_manager_set_target_name (IdeSysrootManager *self, const char *target } gchar * -ide_sysroot_manager_get_target_name (IdeSysrootManager *self, const char *target) +ide_sysroot_manager_get_target_name (IdeSysrootManager *self, + const gchar *target) { + g_return_val_if_fail (IDE_IS_SYSROOT_MANAGER (self), NULL); + g_return_val_if_fail (self->key_file != NULL, NULL); + g_return_val_if_fail (target != NULL, NULL); + return g_key_file_get_string (self->key_file, target, "Name", NULL); } void -ide_sysroot_manager_set_target_path (IdeSysrootManager *self, const char *target, const char *path) +ide_sysroot_manager_set_target_path (IdeSysrootManager *self, + const gchar *target, + const gchar *path) { + g_return_if_fail (IDE_IS_SYSROOT_MANAGER (self)); + g_return_if_fail (self->key_file != NULL); + g_return_if_fail (target != NULL); + g_key_file_set_string (self->key_file, target, "Path", path); g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, IDE_SYSROOT_MANAGER_TARGET_CHANGED); sysroot_manager_save (self); } gchar * -ide_sysroot_manager_get_target_path (IdeSysrootManager *self, const char *target) +ide_sysroot_manager_get_target_path (IdeSysrootManager *self, + const gchar *target) { + g_return_val_if_fail (IDE_IS_SYSROOT_MANAGER (self), NULL); + g_return_val_if_fail (self->key_file != NULL, NULL); + g_return_val_if_fail (target != NULL, NULL); + return g_key_file_get_string (self->key_file, target, "Path", NULL); } void -ide_sysroot_manager_set_target_pkg_config_path (IdeSysrootManager *self, const char *target, const char *path) +ide_sysroot_manager_set_target_pkg_config_path (IdeSysrootManager *self, + const gchar *target, + const gchar *path) { + g_return_if_fail (IDE_IS_SYSROOT_MANAGER (self)); + g_return_if_fail (self->key_file != NULL); + g_return_if_fail (target != NULL); + g_key_file_set_string (self->key_file, target, "PkgConfigPath", path); g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, IDE_SYSROOT_MANAGER_TARGET_CHANGED); sysroot_manager_save (self); } gchar * -ide_sysroot_manager_get_target_pkg_config_path (IdeSysrootManager *self, const char *target) +ide_sysroot_manager_get_target_pkg_config_path (IdeSysrootManager *self, + const gchar *target) { + g_return_val_if_fail (IDE_IS_SYSROOT_MANAGER (self), NULL); + g_return_val_if_fail (self->key_file != NULL, NULL); + g_return_val_if_fail (target != NULL, NULL); + return g_key_file_get_string (self->key_file, target, "PkgConfigPath", NULL); } -GArray * +gchar ** ide_sysroot_manager_list (IdeSysrootManager *self) { - GArray *list = NULL; - gchar **groups = NULL; - gsize groups_length = 0; - - list = g_array_new (FALSE, FALSE, sizeof (char*)); - groups = g_key_file_get_groups (self->key_file, &groups_length); - g_array_append_vals (list, groups, groups_length); + g_return_val_if_fail (IDE_IS_SYSROOT_MANAGER (self), NULL); + g_return_val_if_fail (self->key_file != NULL, NULL); - return list; + return g_key_file_get_groups (self->key_file, NULL); } void @@ -215,18 +247,11 @@ static void ide_sysroot_manager_init (IdeSysrootManager *self) { gchar *conf_file = NULL; - GError *error = NULL; + g_autoptr(GError) error = NULL; conf_file = sysroot_manager_get_path (); self->key_file = g_key_file_new (); g_key_file_load_from_file (self->key_file, conf_file, G_KEY_FILE_KEEP_COMMENTS, &error); - if (error) - { - if (error->code != G_FILE_ERROR_NOENT) - { - g_critical ("Error loading the sysroot configuration: %s", error->message); - } - - g_error_free (error); - } + if (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) + g_critical ("Error loading the sysroot configuration: %s", error->message); } diff --git a/src/plugins/sysroot/ide-sysroot-manager.h b/src/plugins/sysroot/ide-sysroot-manager.h index c1db3b011..935b13068 100644 --- a/src/plugins/sysroot/ide-sysroot-manager.h +++ b/src/plugins/sysroot/ide-sysroot-manager.h @@ -33,24 +33,25 @@ typedef enum { IDE_SYSROOT_MANAGER_TARGET_REMOVED } IdeSysrootManagerTargetModificationType; -IdeSysrootManager *ide_sysroot_manager_get_default (void); - -gchar *ide_sysroot_manager_create_target (IdeSysrootManager *self); - -void ide_sysroot_manager_remove_target (IdeSysrootManager *self, const char *target); - -void ide_sysroot_manager_set_target_name (IdeSysrootManager *self, const char *target, const char *path); - -gchar *ide_sysroot_manager_get_target_name (IdeSysrootManager *self, const char *target); - -void ide_sysroot_manager_set_target_path (IdeSysrootManager *self, const char *target, const char *path); - -gchar *ide_sysroot_manager_get_target_path (IdeSysrootManager *self, const char *target); - -void ide_sysroot_manager_set_target_pkg_config_path (IdeSysrootManager *self, const char *target, const char *path); - -gchar *ide_sysroot_manager_get_target_pkg_config_path (IdeSysrootManager *self, const char *target); - -GArray *ide_sysroot_manager_list (IdeSysrootManager *self); +IdeSysrootManager *ide_sysroot_manager_get_default (void); +gchar *ide_sysroot_manager_create_target (IdeSysrootManager *self); +void ide_sysroot_manager_remove_target (IdeSysrootManager *self, + const gchar *target); +void ide_sysroot_manager_set_target_name (IdeSysrootManager *self, + const gchar *target, + const gchar *path); +gchar *ide_sysroot_manager_get_target_name (IdeSysrootManager *self, + const gchar *target); +void ide_sysroot_manager_set_target_path (IdeSysrootManager *self, + const gchar *target, + const gchar *path); +gchar *ide_sysroot_manager_get_target_path (IdeSysrootManager *self, + const gchar *target); +void ide_sysroot_manager_set_target_pkg_config_path (IdeSysrootManager *self, + const gchar *target, + const gchar *path); +gchar *ide_sysroot_manager_get_target_pkg_config_path (IdeSysrootManager *self, + const gchar *target); +gchar **ide_sysroot_manager_list (IdeSysrootManager *self); G_END_DECLS diff --git a/src/plugins/sysroot/ide-sysroot-preferences-addin.c b/src/plugins/sysroot/ide-sysroot-preferences-addin.c index 44e03efc5..d6fe339f1 100644 --- a/src/plugins/sysroot/ide-sysroot-preferences-addin.c +++ b/src/plugins/sysroot/ide-sysroot-preferences-addin.c @@ -33,12 +33,13 @@ struct _IdeSysrootPreferencesAddin DzlPreferences *preferences; }; -static void sysroot_preferences_add_new (IdeSysrootPreferencesAddin *self, - GtkWidget *emitter) +static void +sysroot_preferences_add_new (IdeSysrootPreferencesAddin *self, + GtkWidget *emitter) { GtkWidget *pref_row = NULL; guint id = 0; - gchar *new_target; + g_autofree gchar *new_target; IdeSysrootManager *sysroot_manager = NULL; g_assert (IDE_IS_SYSROOT_PREFERENCES_ADDIN (self)); @@ -57,7 +58,7 @@ static void sysroot_preferences_add_new (IdeSysrootPreferencesAddin *self, ide_sysroot_preferences_row_show_popup (IDE_SYSROOT_PREFERENCES_ROW (pref_row)); } -GtkWidget * +static GtkWidget * sysroot_preferences_get_add_widget (IdeSysrootPreferencesAddin *self) { GtkWidget *bin = NULL; @@ -103,7 +104,11 @@ sysroot_preferences_get_add_widget (IdeSysrootPreferencesAddin *self) gtk_container_add (GTK_CONTAINER (bin), grid); - g_signal_connect_swapped (bin, "preference-activated", G_CALLBACK(sysroot_preferences_add_new), self); + g_signal_connect_object (bin, + "preference-activated", + G_CALLBACK (sysroot_preferences_add_new), + self, + G_CONNECT_SWAPPED); return bin; } @@ -112,10 +117,11 @@ static void ide_sysroot_preferences_addin_load (IdePreferencesAddin *addin, DzlPreferences *preferences) { - IdeSysrootPreferencesAddin *self = IDE_SYSROOT_PREFERENCES_ADDIN (addin); + IdeSysrootPreferencesAddin *self = (IdeSysrootPreferencesAddin *)addin; GtkWidget *widget = NULL; IdeSysrootManager *sysroot_manager = NULL; - GArray *sysroots = NULL; + g_auto(GStrv) sysroots = NULL; + guint sysroots_length = 0; guint id = 0; IDE_ENTRY; @@ -135,20 +141,18 @@ ide_sysroot_preferences_addin_load (IdePreferencesAddin *addin, sysroot_manager = ide_sysroot_manager_get_default (); sysroots = ide_sysroot_manager_list (sysroot_manager); - for (guint i = 0; i < sysroots->len; i++) + sysroots_length = g_strv_length (sysroots); + for (guint i = 0; i < sysroots_length; i++) { - gchar *sysroot_id = g_array_index (sysroots, gchar*, i); GtkWidget *pref_row = g_object_new (IDE_TYPE_SYSROOT_PREFERENCES_ROW, "visible", TRUE, - "sysroot-id", sysroot_id, + "sysroot-id", sysroots[i], NULL); - id = dzl_preferences_add_custom (self->preferences, "sdk", "sysroot", pref_row, NULL, 1); + id = dzl_preferences_add_custom (self->preferences, "sdk", "sysroot", pref_row, NULL, i); g_array_append_val (self->ids, id); } - g_array_free (sysroots, TRUE); - IDE_EXIT; } diff --git a/src/plugins/sysroot/ide-sysroot-preferences-row.c b/src/plugins/sysroot/ide-sysroot-preferences-row.c index b5880478c..01ea6e0ed 100644 --- a/src/plugins/sysroot/ide-sysroot-preferences-row.c +++ b/src/plugins/sysroot/ide-sysroot-preferences-row.c @@ -17,6 +17,8 @@ * along with this program. If not, see . */ +#define G_LOG_DOMAIN "ide-sysroot-preferences-row" + #include "ide-sysroot-preferences-row.h" #include "ide-sysroot-manager.h" @@ -37,13 +39,14 @@ G_DEFINE_TYPE (IdeSysrootPreferencesRow, ide_sysroot_preferences_row, DZL_TYPE_P enum { PROP_0, PROP_SYSROOT_ID, - LAST_PROP + N_PROPS }; -static GParamSpec *properties [LAST_PROP]; +static GParamSpec *properties [N_PROPS]; static void -sysroot_preferences_row_name_changed (IdeSysrootPreferencesRow *self, gpointer user_data) +sysroot_preferences_row_name_changed (IdeSysrootPreferencesRow *self, + gpointer user_data) { IdeSysrootManager *sysroot_manager = NULL; @@ -51,11 +54,14 @@ sysroot_preferences_row_name_changed (IdeSysrootPreferencesRow *self, gpointer u g_assert (GTK_IS_ENTRY (user_data)); sysroot_manager = ide_sysroot_manager_get_default (); - ide_sysroot_manager_set_target_name (sysroot_manager, self->sysroot_id, gtk_entry_get_text (GTK_ENTRY (user_data))); + ide_sysroot_manager_set_target_name (sysroot_manager, + self->sysroot_id, + gtk_entry_get_text (GTK_ENTRY (user_data))); } static void -sysroot_preferences_row_sysroot_changed (IdeSysrootPreferencesRow *self, gpointer user_data) +sysroot_preferences_row_sysroot_changed (IdeSysrootPreferencesRow *self, + gpointer user_data) { IdeSysrootManager *sysroot_manager = NULL; @@ -63,11 +69,14 @@ sysroot_preferences_row_sysroot_changed (IdeSysrootPreferencesRow *self, gpointe g_assert (GTK_IS_ENTRY (user_data)); sysroot_manager = ide_sysroot_manager_get_default (); - ide_sysroot_manager_set_target_path (sysroot_manager, self->sysroot_id, gtk_entry_get_text (GTK_ENTRY (user_data))); + ide_sysroot_manager_set_target_path (sysroot_manager, + self->sysroot_id, + gtk_entry_get_text (GTK_ENTRY (user_data))); } static void -sysroot_preferences_row_pkg_config_changed (IdeSysrootPreferencesRow *self, gpointer user_data) +sysroot_preferences_row_pkg_config_changed (IdeSysrootPreferencesRow *self, + gpointer user_data) { IdeSysrootManager *sysroot_manager = NULL; @@ -75,17 +84,23 @@ sysroot_preferences_row_pkg_config_changed (IdeSysrootPreferencesRow *self, gpoi g_assert (GTK_IS_ENTRY (user_data)); sysroot_manager = ide_sysroot_manager_get_default (); - ide_sysroot_manager_set_target_pkg_config_path (sysroot_manager, self->sysroot_id, gtk_entry_get_text (GTK_ENTRY (user_data))); + ide_sysroot_manager_set_target_pkg_config_path (sysroot_manager, + self->sysroot_id, + gtk_entry_get_text (GTK_ENTRY (user_data))); } static void -sysroot_preferences_row_clicked (IdeSysrootPreferencesRow *self, gpointer user_data) +sysroot_preferences_row_clicked (IdeSysrootPreferencesRow *self, + gpointer user_data) { + g_assert (IDE_IS_SYSROOT_PREFERENCES_ROW (self)); + ide_sysroot_preferences_row_show_popup (self); } static void -sysroot_preferences_delete (IdeSysrootPreferencesRow *self, gpointer user_data) +sysroot_preferences_delete (IdeSysrootPreferencesRow *self, + gpointer user_data) { IdeSysrootManager *sysroot_manager = NULL; @@ -94,15 +109,15 @@ sysroot_preferences_delete (IdeSysrootPreferencesRow *self, gpointer user_data) sysroot_manager = ide_sysroot_manager_get_default (); ide_sysroot_manager_remove_target (sysroot_manager, self->sysroot_id); - // The row is wrapped into a GtkListBoxRow that won't be removed when child is destroyed + /* The row is wrapped into a GtkListBoxRow that won't be removed when child is destroyed */ gtk_widget_destroy (gtk_widget_get_parent (GTK_WIDGET (self))); } static void ide_sysroot_preferences_row_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { IdeSysrootPreferencesRow *self = IDE_SYSROOT_PREFERENCES_ROW (object); @@ -119,9 +134,9 @@ ide_sysroot_preferences_row_get_property (GObject *object, static void ide_sysroot_preferences_row_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { IdeSysrootPreferencesRow *self = IDE_SYSROOT_PREFERENCES_ROW (object); @@ -139,7 +154,7 @@ ide_sysroot_preferences_row_set_property (GObject *object, static void ide_sysroot_preferences_row_finalize (GObject *object) { - IdeSysrootPreferencesRow *self = IDE_SYSROOT_PREFERENCES_ROW (object); + IdeSysrootPreferencesRow *self = (IdeSysrootPreferencesRow *) object; g_clear_pointer (&self->sysroot_id, g_free); @@ -149,23 +164,25 @@ ide_sysroot_preferences_row_finalize (GObject *object) void ide_sysroot_preferences_row_show_popup (IdeSysrootPreferencesRow *self) { + g_return_if_fail (IDE_IS_SYSROOT_PREFERENCES_ROW (self)); + g_return_if_fail (GTK_IS_POPOVER (self->popover)); + gtk_popover_popup (GTK_POPOVER (self->popover)); gtk_popover_set_modal (GTK_POPOVER (self->popover), TRUE); } -static GObject * -ide_sysroot_preferences_row_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam * construct_properties) +static void +ide_sysroot_preferences_row_constructed (GObject *object) { IdeSysrootManager *sysroot_manager = NULL; gchar *value; - GObject * obj = G_OBJECT_CLASS (ide_sysroot_preferences_row_parent_class)->constructor (type, n_construct_properties, construct_properties); - IdeSysrootPreferencesRow *self = IDE_SYSROOT_PREFERENCES_ROW (obj); + IdeSysrootPreferencesRow *self = (IdeSysrootPreferencesRow *) object; sysroot_manager = ide_sysroot_manager_get_default (); - gtk_entry_set_text (self->name_entry, ide_sysroot_manager_get_target_name (sysroot_manager, self->sysroot_id)); - gtk_entry_set_text (self->sysroot_entry, ide_sysroot_manager_get_target_path (sysroot_manager, self->sysroot_id)); + gtk_entry_set_text (self->name_entry, + ide_sysroot_manager_get_target_name (sysroot_manager, self->sysroot_id)); + gtk_entry_set_text (self->sysroot_entry, + ide_sysroot_manager_get_target_path (sysroot_manager, self->sysroot_id)); value = ide_sysroot_manager_get_target_pkg_config_path (sysroot_manager, self->sysroot_id); if (value != NULL) gtk_entry_set_text (self->pkg_config_entry, value); @@ -187,7 +204,6 @@ ide_sysroot_preferences_row_constructor (GType type, G_CALLBACK (sysroot_preferences_row_pkg_config_changed), self, G_CONNECT_SWAPPED); - return obj; } static void @@ -199,7 +215,7 @@ ide_sysroot_preferences_row_class_init (IdeSysrootPreferencesRowClass *klass) object_class->finalize = ide_sysroot_preferences_row_finalize; object_class->get_property = ide_sysroot_preferences_row_get_property; object_class->set_property = ide_sysroot_preferences_row_set_property; - object_class->constructor = ide_sysroot_preferences_row_constructor; + object_class->constructed = ide_sysroot_preferences_row_constructed; properties [PROP_SYSROOT_ID] = g_param_spec_string ("sysroot-id", @@ -208,7 +224,7 @@ ide_sysroot_preferences_row_class_init (IdeSysrootPreferencesRowClass *klass) NULL, (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - g_object_class_install_properties (object_class, LAST_PROP, properties); + g_object_class_install_properties (object_class, N_PROPS, properties); gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/builder/plugins/sysroot-plugin/ide-sysroot-preferences-row.ui"); gtk_widget_class_bind_template_child (widget_class, IdeSysrootPreferencesRow, display_name); @@ -224,7 +240,7 @@ ide_sysroot_preferences_row_init (IdeSysrootPreferencesRow *self) { gtk_widget_init_template (GTK_WIDGET (self)); - g_signal_connect (self, "preference-activated", G_CALLBACK(sysroot_preferences_row_clicked), NULL); - g_signal_connect_swapped (self->delete_button, "clicked", G_CALLBACK(sysroot_preferences_delete), self); + g_signal_connect (self, "preference-activated", G_CALLBACK (sysroot_preferences_row_clicked), NULL); + g_signal_connect_swapped (self->delete_button, "clicked", G_CALLBACK (sysroot_preferences_delete), self); g_object_bind_property (self->name_entry, "text", self->display_name, "label", 0); } diff --git a/src/plugins/sysroot/ide-sysroot-runtime-provider.c b/src/plugins/sysroot/ide-sysroot-runtime-provider.c index 70345f52f..2966b77ad 100644 --- a/src/plugins/sysroot/ide-sysroot-runtime-provider.c +++ b/src/plugins/sysroot/ide-sysroot-runtime-provider.c @@ -43,17 +43,19 @@ G_DEFINE_TYPE_EXTENDED (IdeSysrootRuntimeProvider, runtime_provider_iface_init)) static void -sysroot_runtime_provider_remove_target (IdeSysrootRuntimeProvider *self, gchar *target) +sysroot_runtime_provider_remove_target (IdeSysrootRuntimeProvider *self, + const gchar *target) { if (self->runtimes != NULL) { for (guint i= 0; i < self->runtimes->len; i++) { - IdeRuntime *runtime = g_ptr_array_index (self->runtimes, i); - const gchar *sysroot_id = ide_sysroot_runtime_get_sysroot_id (IDE_SYSROOT_RUNTIME (runtime)); + IdeSysrootRuntime *runtime = g_ptr_array_index (self->runtimes, i); + const gchar *sysroot_id = ide_sysroot_runtime_get_sysroot_id (runtime); + if (g_strcmp0 (target, sysroot_id) == 0) { - ide_runtime_manager_remove (self->runtime_manager, runtime); + ide_runtime_manager_remove (self->runtime_manager, IDE_RUNTIME (runtime)); return; } } @@ -61,9 +63,10 @@ sysroot_runtime_provider_remove_target (IdeSysrootRuntimeProvider *self, gchar * } static void -sysroot_runtime_provider_add_target (IdeSysrootRuntimeProvider *self, gchar *target) +sysroot_runtime_provider_add_target (IdeSysrootRuntimeProvider *self, + const gchar *target) { - GObject *runtime = NULL; + g_autoptr(IdeSysrootRuntime) runtime = NULL; IdeContext *context = NULL; context = ide_object_get_context (IDE_OBJECT (self->runtime_manager)); @@ -74,19 +77,15 @@ sysroot_runtime_provider_add_target (IdeSysrootRuntimeProvider *self, gchar *tar } static void -sysroot_runtime_provider_target_changed (IdeSysrootRuntimeProvider *self, - gchar *target, - IdeSysrootManagerTargetModificationType mod_type, - gpointer user_data) +sysroot_runtime_provider_target_changed (IdeSysrootRuntimeProvider *self, + const gchar *target, + IdeSysrootManagerTargetModificationType mod_type, + gpointer user_data) { if (mod_type == IDE_SYSROOT_MANAGER_TARGET_CREATED) - { - sysroot_runtime_provider_add_target (self, target); - } + sysroot_runtime_provider_add_target (self, target); else if (mod_type == IDE_SYSROOT_MANAGER_TARGET_REMOVED) - { - sysroot_runtime_provider_remove_target (self, target); - } + sysroot_runtime_provider_remove_target (self, target); } static void @@ -107,7 +106,8 @@ ide_sysroot_runtime_provider_load (IdeRuntimeProvider *provider, { IdeSysrootRuntimeProvider *self = IDE_SYSROOT_RUNTIME_PROVIDER (provider); IdeSysrootManager *sysroot_manager = NULL; - GArray *sysroots = NULL; + g_auto(GStrv) sysroots = NULL; + guint sysroots_length = 0; IDE_ENTRY; @@ -119,23 +119,23 @@ ide_sysroot_runtime_provider_load (IdeRuntimeProvider *provider, sysroot_manager = ide_sysroot_manager_get_default (); sysroots = ide_sysroot_manager_list (sysroot_manager); - for (guint i = 0; i < sysroots->len; i++) + sysroots_length = g_strv_length (sysroots); + for (guint i = 0; i < sysroots_length; i++) { - gchar *sysroot_id = g_array_index (sysroots, gchar*, i); - sysroot_runtime_provider_add_target (self, sysroot_id); + sysroot_runtime_provider_add_target (self, sysroots[i]); } - g_signal_connect_swapped (sysroot_manager, "target-changed", G_CALLBACK (sysroot_runtime_provider_target_changed), self); - - g_array_free (sysroots, TRUE); - + g_signal_connect_swapped (sysroot_manager, + "target-changed", + G_CALLBACK (sysroot_runtime_provider_target_changed), + self); IDE_EXIT; } static void ide_sysroot_runtime_provider_unload (IdeRuntimeProvider *provider, - IdeRuntimeManager *manager) + IdeRuntimeManager *manager) { IdeSysrootRuntimeProvider *self = IDE_SYSROOT_RUNTIME_PROVIDER (provider); IdeSysrootManager *sysroot_manager = NULL; diff --git a/src/plugins/sysroot/ide-sysroot-runtime.c b/src/plugins/sysroot/ide-sysroot-runtime.c index 5f0ee7b46..58dfd0fcf 100644 --- a/src/plugins/sysroot/ide-sysroot-runtime.c +++ b/src/plugins/sysroot/ide-sysroot-runtime.c @@ -36,29 +36,34 @@ struct _IdeSysrootRuntime G_DEFINE_TYPE (IdeSysrootRuntime, ide_sysroot_runtime, IDE_TYPE_RUNTIME) -GObject * -ide_sysroot_runtime_new (IdeContext *context, gchar* sysroot_id) +IdeSysrootRuntime * +ide_sysroot_runtime_new (IdeContext *context, + const gchar *sysroot_id) { - GObject *runtime = NULL; + g_autoptr(IdeRuntime) runtime = NULL; + g_autofree gchar *built_id = NULL; g_return_val_if_fail (IDE_IS_CONTEXT (context), NULL); + g_return_val_if_fail (sysroot_id != NULL, NULL); + built_id = g_strconcat (RUNTIME_PREFIX, sysroot_id, NULL); runtime = g_object_new (IDE_TYPE_SYSROOT_RUNTIME, - "id", g_strconcat (RUNTIME_PREFIX, sysroot_id, NULL), + "id", g_steal_pointer (&built_id), "context", context, "display-name", "", NULL); - return runtime; + return g_steal_pointer (&runtime); } const gchar * ide_sysroot_runtime_get_sysroot_id (IdeSysrootRuntime *self) { const gchar *runtime_id = ide_runtime_get_id (IDE_RUNTIME (self)); + if (!g_str_has_prefix (runtime_id, RUNTIME_PREFIX)) return runtime_id; - return g_utf8_offset_to_pointer (runtime_id, g_utf8_strlen (RUNTIME_PREFIX, -1)); + return runtime_id + strlen(RUNTIME_PREFIX); } static IdeSubprocessLauncher * @@ -79,11 +84,11 @@ ide_sysroot_runtime_create_launcher (IdeRuntime *runtime, IdeSysrootManager *sysroot_manager = NULL; const gchar *env_var = NULL; const gchar *sysroot_id = NULL; - gchar *sysroot_cflags = NULL; - gchar *sysroot_libdirs = NULL; - gchar **path_parts = NULL; - gchar *sysroot_path = NULL; - gchar *pkgconfig_dirs = NULL; + g_autofree gchar *sysroot_cflags = NULL; + g_autofree gchar *sysroot_libdirs = NULL; + g_auto(GStrv) path_parts = NULL; + g_autofree gchar *sysroot_path = NULL; + g_autofree gchar *pkgconfig_dirs = NULL; sysroot_id = ide_sysroot_runtime_get_sysroot_id (self); @@ -97,7 +102,6 @@ ide_sysroot_runtime_create_launcher (IdeRuntime *runtime, env_var = ide_subprocess_launcher_getenv (ret, "CFLAGS"); sysroot_cflags = g_strconcat ("--sysroot=", sysroot_path, NULL); ide_subprocess_launcher_setenv (ret, "CFLAGS", g_strjoin (" ", sysroot_cflags, env_var, NULL), TRUE); - g_free (sysroot_cflags); ide_subprocess_launcher_setenv (ret, "PKG_CONFIG_DIR", "", TRUE); @@ -107,24 +111,24 @@ ide_sysroot_runtime_create_launcher (IdeRuntime *runtime, path_parts = g_strsplit (BASIC_LIBDIRS, ":", 0); for (gint i = g_strv_length (path_parts) - 1; i >= 0; i--) { - gchar *path_i = g_build_path (G_DIR_SEPARATOR_S, sysroot_path, path_parts[i], NULL); - gchar *libdir_tmp = g_strjoin (":", path_i, sysroot_libdirs, NULL); - g_free (sysroot_libdirs); - sysroot_libdirs = libdir_tmp; - g_free (path_i); + g_autofree gchar *path_i = NULL; + g_autofree gchar *libdir_tmp = NULL; + + path_i = g_build_path (G_DIR_SEPARATOR_S, sysroot_path, path_parts[i], NULL); + libdir_tmp = g_strjoin (":", path_i, sysroot_libdirs, NULL); + sysroot_libdirs = g_steal_pointer (&libdir_tmp); } pkgconfig_dirs = ide_sysroot_manager_get_target_pkg_config_path (sysroot_manager, sysroot_id); if (pkgconfig_dirs != NULL && g_strcmp0 (pkgconfig_dirs, "") != 0) { - gchar *libdir_tmp = g_strjoin (":", pkgconfig_dirs, sysroot_libdirs, NULL); - g_free (sysroot_libdirs); - sysroot_libdirs = libdir_tmp; + g_autofree gchar *libdir_tmp = NULL; + + libdir_tmp = g_strjoin (":", pkgconfig_dirs, sysroot_libdirs, NULL); + sysroot_libdirs = g_steal_pointer (&libdir_tmp); } - g_strfreev (path_parts); ide_subprocess_launcher_setenv (ret, "PKG_CONFIG_LIBDIR", sysroot_libdirs, TRUE); - g_free (sysroot_libdirs); } else { @@ -140,23 +144,21 @@ ide_sysroot_runtime_create_launcher (IdeRuntime *runtime, static void sysroot_runtime_target_name_changed (IdeSysrootRuntime *self, - gchar *target, - gchar *new_name, - gpointer user_data) + gchar *target, + gchar *new_name, + gpointer user_data) { const gchar* sysroot_id = ide_sysroot_runtime_get_sysroot_id (self); + if (g_strcmp0 (target, sysroot_id) == 0) ide_runtime_set_display_name (IDE_RUNTIME (self), new_name); } -static GObject * -ide_sysroot_runtime_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_properties) +static void +ide_sysroot_runtime_constructed (GObject *object) { - GObject *object = G_OBJECT_CLASS (ide_sysroot_runtime_parent_class)->constructor (type, n_construct_properties, construct_properties); IdeSysrootManager *sysroot_manager = NULL; - gchar *display_name = NULL; + g_autofree gchar *display_name = NULL; const gchar* sysroot_id = NULL; sysroot_id = ide_sysroot_runtime_get_sysroot_id (IDE_SYSROOT_RUNTIME (object)); @@ -165,7 +167,6 @@ ide_sysroot_runtime_constructor (GType type, ide_runtime_set_display_name (IDE_RUNTIME (object), display_name); g_signal_connect_swapped (sysroot_manager, "target-name-changed", G_CALLBACK (sysroot_runtime_target_name_changed), object); - return object; } static void @@ -174,7 +175,7 @@ ide_sysroot_runtime_class_init (IdeSysrootRuntimeClass *klass) GObjectClass *object_class = G_OBJECT_CLASS (klass); IdeRuntimeClass *runtime_class = IDE_RUNTIME_CLASS (klass); - object_class->constructor = ide_sysroot_runtime_constructor; + object_class->constructed = ide_sysroot_runtime_constructed; runtime_class->create_launcher = ide_sysroot_runtime_create_launcher; } diff --git a/src/plugins/sysroot/ide-sysroot-runtime.h b/src/plugins/sysroot/ide-sysroot-runtime.h index 0220aba01..b269ad0cd 100644 --- a/src/plugins/sysroot/ide-sysroot-runtime.h +++ b/src/plugins/sysroot/ide-sysroot-runtime.h @@ -27,7 +27,8 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (IdeSysrootRuntime, ide_sysroot_runtime, IDE, SYSROOT_RUNTIME, IdeRuntime) -GObject *ide_sysroot_runtime_new (IdeContext *context, gchar* sysroot_id); -const gchar *ide_sysroot_runtime_get_sysroot_id (IdeSysrootRuntime *self); +IdeSysrootRuntime *ide_sysroot_runtime_new (IdeContext *context, + const gchar* sysroot_id); +const gchar *ide_sysroot_runtime_get_sysroot_id (IdeSysrootRuntime *self); G_END_DECLS -- GitLab From df53ff1e4c8a2c1793ce9c518ec6ddc9e357961b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Thu, 22 Feb 2018 14:08:48 +0000 Subject: [PATCH 3/7] sysroot: rename IdeSysroot* to GbpSysroot The GNOME Builder Plugins namespace is here for plugins --- ...ysroot-manager.c => gbp-sysroot-manager.c} | 78 ++++++------ ...ysroot-manager.h => gbp-sysroot-manager.h} | 36 +++--- ...ddin.c => gbp-sysroot-preferences-addin.c} | 58 ++++----- ...ddin.h => gbp-sysroot-preferences-addin.h} | 6 +- ...es-row.c => gbp-sysroot-preferences-row.c} | 116 +++++++++--------- ...es-row.h => gbp-sysroot-preferences-row.h} | 8 +- ...-row.ui => gbp-sysroot-preferences-row.ui} | 2 +- ...vider.c => gbp-sysroot-runtime-provider.c} | 66 +++++----- ...vider.h => gbp-sysroot-runtime-provider.h} | 6 +- ...ysroot-runtime.c => gbp-sysroot-runtime.c} | 62 +++++----- ...ysroot-runtime.h => gbp-sysroot-runtime.h} | 12 +- ...er.c => gbp-sysroot-subprocess-launcher.c} | 36 +++--- ...er.h => gbp-sysroot-subprocess-launcher.h} | 8 +- src/plugins/sysroot/meson.build | 26 ++-- src/plugins/sysroot/sysroot-plugin.c | 10 +- src/plugins/sysroot/sysroot.gresource.xml | 2 +- src/plugins/sysroot/sysroot.plugin | 2 +- 17 files changed, 267 insertions(+), 267 deletions(-) rename src/plugins/sysroot/{ide-sysroot-manager.c => gbp-sysroot-manager.c} (74%) rename src/plugins/sysroot/{ide-sysroot-manager.h => gbp-sysroot-manager.h} (59%) rename src/plugins/sysroot/{ide-sysroot-preferences-addin.c => gbp-sysroot-preferences-addin.c} (76%) rename src/plugins/sysroot/{ide-sysroot-preferences-addin.h => gbp-sysroot-preferences-addin.h} (79%) rename src/plugins/sysroot/{ide-sysroot-preferences-row.c => gbp-sysroot-preferences-row.c} (62%) rename src/plugins/sysroot/{ide-sysroot-preferences-row.h => gbp-sysroot-preferences-row.h} (74%) rename src/plugins/sysroot/{ide-sysroot-preferences-row.ui => gbp-sysroot-preferences-row.ui} (98%) rename src/plugins/sysroot/{ide-sysroot-runtime-provider.c => gbp-sysroot-runtime-provider.c} (66%) rename src/plugins/sysroot/{ide-sysroot-runtime-provider.h => gbp-sysroot-runtime-provider.h} (79%) rename src/plugins/sysroot/{ide-sysroot-runtime.c => gbp-sysroot-runtime.c} (73%) rename src/plugins/sysroot/{ide-sysroot-runtime.h => gbp-sysroot-runtime.h} (71%) rename src/plugins/sysroot/{ide-host-subprocess-launcher.c => gbp-sysroot-subprocess-launcher.c} (61%) rename src/plugins/sysroot/{ide-host-subprocess-launcher.h => gbp-sysroot-subprocess-launcher.h} (69%) diff --git a/src/plugins/sysroot/ide-sysroot-manager.c b/src/plugins/sysroot/gbp-sysroot-manager.c similarity index 74% rename from src/plugins/sysroot/ide-sysroot-manager.c rename to src/plugins/sysroot/gbp-sysroot-manager.c index 92647340f..f7cf02ef0 100644 --- a/src/plugins/sysroot/ide-sysroot-manager.c +++ b/src/plugins/sysroot/gbp-sysroot-manager.c @@ -1,4 +1,4 @@ -/* ide-sysroot-manager.c +/* gbp-sysroot-manager.c * * Copyright (C) 2018 Corentin Noël * Copyright (C) 2018 Collabora Ltd. @@ -17,15 +17,15 @@ * along with this program. If not, see . */ -#include "ide-sysroot-manager.h" +#include "gbp-sysroot-manager.h" -struct _IdeSysrootManager +struct _GbpSysrootManager { GObject parent_instance; GKeyFile *key_file; }; -G_DEFINE_TYPE (IdeSysrootManager, ide_sysroot_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (GbpSysrootManager, gbp_sysroot_manager, G_TYPE_OBJECT) enum { TARGET_MODIFIED, @@ -52,12 +52,12 @@ sysroot_manager_get_path (void) } static void -sysroot_manager_save (IdeSysrootManager *self) +sysroot_manager_save (GbpSysrootManager *self) { g_autofree gchar *conf_file = NULL; g_autoptr(GError) error = NULL; - g_assert (IDE_IS_SYSROOT_MANAGER (self)); + g_assert (GBP_IS_SYSROOT_MANAGER (self)); g_assert (self->key_file != NULL); conf_file = sysroot_manager_get_path (); @@ -66,22 +66,22 @@ sysroot_manager_save (IdeSysrootManager *self) g_critical ("Error loading the sysroot configuration: %s", error->message); } -IdeSysrootManager * -ide_sysroot_manager_get_default (void) +GbpSysrootManager * +gbp_sysroot_manager_get_default (void) { - static IdeSysrootManager *instance; + static GbpSysrootManager *instance; if (instance == NULL) { - instance = g_object_new (IDE_TYPE_SYSROOT_MANAGER, NULL); + instance = g_object_new (GBP_TYPE_SYSROOT_MANAGER, NULL); } return instance; } gchar * -ide_sysroot_manager_create_target (IdeSysrootManager *self) +gbp_sysroot_manager_create_target (GbpSysrootManager *self) { - g_return_val_if_fail (IDE_IS_SYSROOT_MANAGER (self), NULL); + g_return_val_if_fail (GBP_IS_SYSROOT_MANAGER (self), NULL); g_return_val_if_fail (self->key_file != NULL, NULL); for (guint i = 0; i < UINT_MAX; i++) @@ -96,7 +96,7 @@ ide_sysroot_manager_create_target (IdeSysrootManager *self) g_key_file_set_string (self->key_file, result, "Name", result); g_key_file_set_string (self->key_file, result, "Path", "/"); sysroot_manager_save (self); - g_signal_emit (self, signals[TARGET_MODIFIED], 0, result, IDE_SYSROOT_MANAGER_TARGET_CREATED); + g_signal_emit (self, signals[TARGET_MODIFIED], 0, result, GBP_SYSROOT_MANAGER_TARGET_CREATED); return g_string_free (g_steal_pointer (&sysroot_name), FALSE); } } @@ -105,12 +105,12 @@ ide_sysroot_manager_create_target (IdeSysrootManager *self) } void -ide_sysroot_manager_remove_target (IdeSysrootManager *self, +gbp_sysroot_manager_remove_target (GbpSysrootManager *self, const gchar *target) { g_autoptr(GError) error = NULL; - g_return_if_fail (IDE_IS_SYSROOT_MANAGER (self)); + g_return_if_fail (GBP_IS_SYSROOT_MANAGER (self)); g_return_if_fail (self->key_file != NULL); g_return_if_fail (target != NULL); @@ -118,30 +118,30 @@ ide_sysroot_manager_remove_target (IdeSysrootManager *self, if (error) g_critical ("Error removing target \"%s\": %s", target, error->message); - g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, IDE_SYSROOT_MANAGER_TARGET_REMOVED); + g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, GBP_SYSROOT_MANAGER_TARGET_REMOVED); sysroot_manager_save (self); } void -ide_sysroot_manager_set_target_name (IdeSysrootManager *self, +gbp_sysroot_manager_set_target_name (GbpSysrootManager *self, const gchar *target, const gchar *name) { - g_return_if_fail (IDE_IS_SYSROOT_MANAGER (self)); + g_return_if_fail (GBP_IS_SYSROOT_MANAGER (self)); g_return_if_fail (self->key_file != NULL); g_return_if_fail (target != NULL); g_key_file_set_string (self->key_file, target, "Name", name); - g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, IDE_SYSROOT_MANAGER_TARGET_CHANGED); + g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, GBP_SYSROOT_MANAGER_TARGET_CHANGED); g_signal_emit (self, signals[TARGET_NAME_CHANGED], 0, target, name); sysroot_manager_save (self); } gchar * -ide_sysroot_manager_get_target_name (IdeSysrootManager *self, +gbp_sysroot_manager_get_target_name (GbpSysrootManager *self, const gchar *target) { - g_return_val_if_fail (IDE_IS_SYSROOT_MANAGER (self), NULL); + g_return_val_if_fail (GBP_IS_SYSROOT_MANAGER (self), NULL); g_return_val_if_fail (self->key_file != NULL, NULL); g_return_val_if_fail (target != NULL, NULL); @@ -149,24 +149,24 @@ ide_sysroot_manager_get_target_name (IdeSysrootManager *self, } void -ide_sysroot_manager_set_target_path (IdeSysrootManager *self, +gbp_sysroot_manager_set_target_path (GbpSysrootManager *self, const gchar *target, const gchar *path) { - g_return_if_fail (IDE_IS_SYSROOT_MANAGER (self)); + g_return_if_fail (GBP_IS_SYSROOT_MANAGER (self)); g_return_if_fail (self->key_file != NULL); g_return_if_fail (target != NULL); g_key_file_set_string (self->key_file, target, "Path", path); - g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, IDE_SYSROOT_MANAGER_TARGET_CHANGED); + g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, GBP_SYSROOT_MANAGER_TARGET_CHANGED); sysroot_manager_save (self); } gchar * -ide_sysroot_manager_get_target_path (IdeSysrootManager *self, +gbp_sysroot_manager_get_target_path (GbpSysrootManager *self, const gchar *target) { - g_return_val_if_fail (IDE_IS_SYSROOT_MANAGER (self), NULL); + g_return_val_if_fail (GBP_IS_SYSROOT_MANAGER (self), NULL); g_return_val_if_fail (self->key_file != NULL, NULL); g_return_val_if_fail (target != NULL, NULL); @@ -174,24 +174,24 @@ ide_sysroot_manager_get_target_path (IdeSysrootManager *self, } void -ide_sysroot_manager_set_target_pkg_config_path (IdeSysrootManager *self, +gbp_sysroot_manager_set_target_pkg_config_path (GbpSysrootManager *self, const gchar *target, const gchar *path) { - g_return_if_fail (IDE_IS_SYSROOT_MANAGER (self)); + g_return_if_fail (GBP_IS_SYSROOT_MANAGER (self)); g_return_if_fail (self->key_file != NULL); g_return_if_fail (target != NULL); g_key_file_set_string (self->key_file, target, "PkgConfigPath", path); - g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, IDE_SYSROOT_MANAGER_TARGET_CHANGED); + g_signal_emit (self, signals[TARGET_MODIFIED], 0, target, GBP_SYSROOT_MANAGER_TARGET_CHANGED); sysroot_manager_save (self); } gchar * -ide_sysroot_manager_get_target_pkg_config_path (IdeSysrootManager *self, +gbp_sysroot_manager_get_target_pkg_config_path (GbpSysrootManager *self, const gchar *target) { - g_return_val_if_fail (IDE_IS_SYSROOT_MANAGER (self), NULL); + g_return_val_if_fail (GBP_IS_SYSROOT_MANAGER (self), NULL); g_return_val_if_fail (self->key_file != NULL, NULL); g_return_val_if_fail (target != NULL, NULL); @@ -199,28 +199,28 @@ ide_sysroot_manager_get_target_pkg_config_path (IdeSysrootManager *self, } gchar ** -ide_sysroot_manager_list (IdeSysrootManager *self) +gbp_sysroot_manager_list (GbpSysrootManager *self) { - g_return_val_if_fail (IDE_IS_SYSROOT_MANAGER (self), NULL); + g_return_val_if_fail (GBP_IS_SYSROOT_MANAGER (self), NULL); g_return_val_if_fail (self->key_file != NULL, NULL); return g_key_file_get_groups (self->key_file, NULL); } void -ide_sysroot_manager_finalize (GObject *object) +gbp_sysroot_manager_finalize (GObject *object) { - IdeSysrootManager *self = IDE_SYSROOT_MANAGER(object); + GbpSysrootManager *self = GBP_SYSROOT_MANAGER(object); g_clear_pointer (&self->key_file, g_key_file_free); - G_OBJECT_CLASS (ide_sysroot_manager_parent_class)->finalize (object); + G_OBJECT_CLASS (gbp_sysroot_manager_parent_class)->finalize (object); } void -ide_sysroot_manager_class_init (IdeSysrootManagerClass *klass) +gbp_sysroot_manager_class_init (GbpSysrootManagerClass *klass) { - G_OBJECT_CLASS (klass)->finalize = ide_sysroot_manager_finalize; + G_OBJECT_CLASS (klass)->finalize = gbp_sysroot_manager_finalize; signals [TARGET_MODIFIED] = g_signal_new_class_handler ("target-changed", @@ -244,7 +244,7 @@ ide_sysroot_manager_class_init (IdeSysrootManagerClass *klass) } static void -ide_sysroot_manager_init (IdeSysrootManager *self) +gbp_sysroot_manager_init (GbpSysrootManager *self) { gchar *conf_file = NULL; g_autoptr(GError) error = NULL; diff --git a/src/plugins/sysroot/ide-sysroot-manager.h b/src/plugins/sysroot/gbp-sysroot-manager.h similarity index 59% rename from src/plugins/sysroot/ide-sysroot-manager.h rename to src/plugins/sysroot/gbp-sysroot-manager.h index 935b13068..eceac01fa 100644 --- a/src/plugins/sysroot/ide-sysroot-manager.h +++ b/src/plugins/sysroot/gbp-sysroot-manager.h @@ -1,4 +1,4 @@ -/* ide-sysroot-manager.h +/* gbp-sysroot-manager.h * * Copyright (C) 2018 Corentin Noël * Copyright (C) 2018 Collabora Ltd. @@ -23,35 +23,35 @@ G_BEGIN_DECLS -#define IDE_TYPE_SYSROOT_MANAGER (ide_sysroot_manager_get_type()) +#define GBP_TYPE_SYSROOT_MANAGER (gbp_sysroot_manager_get_type()) -G_DECLARE_FINAL_TYPE (IdeSysrootManager, ide_sysroot_manager, IDE, SYSROOT_MANAGER, GObject) +G_DECLARE_FINAL_TYPE (GbpSysrootManager, gbp_sysroot_manager, GBP, SYSROOT_MANAGER, GObject) typedef enum { - IDE_SYSROOT_MANAGER_TARGET_CHANGED, - IDE_SYSROOT_MANAGER_TARGET_CREATED, - IDE_SYSROOT_MANAGER_TARGET_REMOVED -} IdeSysrootManagerTargetModificationType; - -IdeSysrootManager *ide_sysroot_manager_get_default (void); -gchar *ide_sysroot_manager_create_target (IdeSysrootManager *self); -void ide_sysroot_manager_remove_target (IdeSysrootManager *self, + GBP_SYSROOT_MANAGER_TARGET_CHANGED, + GBP_SYSROOT_MANAGER_TARGET_CREATED, + GBP_SYSROOT_MANAGER_TARGET_REMOVED +} GbpSysrootManagerTargetModificationType; + +GbpSysrootManager *gbp_sysroot_manager_get_default (void); +gchar *gbp_sysroot_manager_create_target (GbpSysrootManager *self); +void gbp_sysroot_manager_remove_target (GbpSysrootManager *self, const gchar *target); -void ide_sysroot_manager_set_target_name (IdeSysrootManager *self, +void gbp_sysroot_manager_set_target_name (GbpSysrootManager *self, const gchar *target, const gchar *path); -gchar *ide_sysroot_manager_get_target_name (IdeSysrootManager *self, +gchar *gbp_sysroot_manager_get_target_name (GbpSysrootManager *self, const gchar *target); -void ide_sysroot_manager_set_target_path (IdeSysrootManager *self, +void gbp_sysroot_manager_set_target_path (GbpSysrootManager *self, const gchar *target, const gchar *path); -gchar *ide_sysroot_manager_get_target_path (IdeSysrootManager *self, +gchar *gbp_sysroot_manager_get_target_path (GbpSysrootManager *self, const gchar *target); -void ide_sysroot_manager_set_target_pkg_config_path (IdeSysrootManager *self, +void gbp_sysroot_manager_set_target_pkg_config_path (GbpSysrootManager *self, const gchar *target, const gchar *path); -gchar *ide_sysroot_manager_get_target_pkg_config_path (IdeSysrootManager *self, +gchar *gbp_sysroot_manager_get_target_pkg_config_path (GbpSysrootManager *self, const gchar *target); -gchar **ide_sysroot_manager_list (IdeSysrootManager *self); +gchar **gbp_sysroot_manager_list (GbpSysrootManager *self); G_END_DECLS diff --git a/src/plugins/sysroot/ide-sysroot-preferences-addin.c b/src/plugins/sysroot/gbp-sysroot-preferences-addin.c similarity index 76% rename from src/plugins/sysroot/ide-sysroot-preferences-addin.c rename to src/plugins/sysroot/gbp-sysroot-preferences-addin.c index d6fe339f1..607340ab4 100644 --- a/src/plugins/sysroot/ide-sysroot-preferences-addin.c +++ b/src/plugins/sysroot/gbp-sysroot-preferences-addin.c @@ -1,4 +1,4 @@ -/* ide-sysroot-preferences.c +/* gbp-sysroot-preferences.c * * Copyright (C) 2018 Corentin Noël * Copyright (C) 2018 Collabora Ltd. @@ -17,15 +17,15 @@ * along with this program. If not, see . */ -#define G_LOG_DOMAIN "ide-sysroot-preferences-addin" +#define G_LOG_DOMAIN "gbp-sysroot-preferences-addin" #include -#include "ide-sysroot-preferences-addin.h" -#include "ide-sysroot-preferences-row.h" -#include "ide-sysroot-manager.h" +#include "gbp-sysroot-preferences-addin.h" +#include "gbp-sysroot-preferences-row.h" +#include "gbp-sysroot-manager.h" -struct _IdeSysrootPreferencesAddin +struct _GbpSysrootPreferencesAddin { GObject parent_instance; @@ -34,20 +34,20 @@ struct _IdeSysrootPreferencesAddin }; static void -sysroot_preferences_add_new (IdeSysrootPreferencesAddin *self, +sysroot_preferences_add_new (GbpSysrootPreferencesAddin *self, GtkWidget *emitter) { GtkWidget *pref_row = NULL; guint id = 0; g_autofree gchar *new_target; - IdeSysrootManager *sysroot_manager = NULL; + GbpSysrootManager *sysroot_manager = NULL; - g_assert (IDE_IS_SYSROOT_PREFERENCES_ADDIN (self)); + g_assert (GBP_IS_SYSROOT_PREFERENCES_ADDIN (self)); g_assert (DZL_IS_PREFERENCES_BIN (emitter)); - sysroot_manager = ide_sysroot_manager_get_default (); - new_target = ide_sysroot_manager_create_target (sysroot_manager); - pref_row = g_object_new (IDE_TYPE_SYSROOT_PREFERENCES_ROW, + sysroot_manager = gbp_sysroot_manager_get_default (); + new_target = gbp_sysroot_manager_create_target (sysroot_manager); + pref_row = g_object_new (GBP_TYPE_SYSROOT_PREFERENCES_ROW, "visible", TRUE, "sysroot-id", new_target, NULL); @@ -55,11 +55,11 @@ sysroot_preferences_add_new (IdeSysrootPreferencesAddin *self, id = dzl_preferences_add_custom (self->preferences, "sdk", "sysroot", pref_row, "", 1); g_array_append_val (self->ids, id); - ide_sysroot_preferences_row_show_popup (IDE_SYSROOT_PREFERENCES_ROW (pref_row)); + gbp_sysroot_preferences_row_show_popup (GBP_SYSROOT_PREFERENCES_ROW (pref_row)); } static GtkWidget * -sysroot_preferences_get_add_widget (IdeSysrootPreferencesAddin *self) +sysroot_preferences_get_add_widget (GbpSysrootPreferencesAddin *self) { GtkWidget *bin = NULL; GtkWidget *grid = NULL; @@ -114,19 +114,19 @@ sysroot_preferences_get_add_widget (IdeSysrootPreferencesAddin *self) } static void -ide_sysroot_preferences_addin_load (IdePreferencesAddin *addin, +gbp_sysroot_preferences_addin_load (IdePreferencesAddin *addin, DzlPreferences *preferences) { - IdeSysrootPreferencesAddin *self = (IdeSysrootPreferencesAddin *)addin; + GbpSysrootPreferencesAddin *self = (GbpSysrootPreferencesAddin *)addin; GtkWidget *widget = NULL; - IdeSysrootManager *sysroot_manager = NULL; + GbpSysrootManager *sysroot_manager = NULL; g_auto(GStrv) sysroots = NULL; guint sysroots_length = 0; guint id = 0; IDE_ENTRY; - g_assert (IDE_IS_SYSROOT_PREFERENCES_ADDIN (self)); + g_assert (GBP_IS_SYSROOT_PREFERENCES_ADDIN (self)); g_assert (DZL_IS_PREFERENCES (preferences)); self->ids = g_array_new (FALSE, FALSE, sizeof (guint)); @@ -139,12 +139,12 @@ ide_sysroot_preferences_addin_load (IdePreferencesAddin *addin, g_array_append_val (self->ids, id); - sysroot_manager = ide_sysroot_manager_get_default (); - sysroots = ide_sysroot_manager_list (sysroot_manager); + sysroot_manager = gbp_sysroot_manager_get_default (); + sysroots = gbp_sysroot_manager_list (sysroot_manager); sysroots_length = g_strv_length (sysroots); for (guint i = 0; i < sysroots_length; i++) { - GtkWidget *pref_row = g_object_new (IDE_TYPE_SYSROOT_PREFERENCES_ROW, + GtkWidget *pref_row = g_object_new (GBP_TYPE_SYSROOT_PREFERENCES_ROW, "visible", TRUE, "sysroot-id", sysroots[i], NULL); @@ -157,14 +157,14 @@ ide_sysroot_preferences_addin_load (IdePreferencesAddin *addin, } static void -ide_sysroot_preferences_addin_unload (IdePreferencesAddin *addin, +gbp_sysroot_preferences_addin_unload (IdePreferencesAddin *addin, DzlPreferences *preferences) { - IdeSysrootPreferencesAddin *self = IDE_SYSROOT_PREFERENCES_ADDIN (addin); + GbpSysrootPreferencesAddin *self = (GbpSysrootPreferencesAddin *)addin; IDE_ENTRY; - g_assert (IDE_IS_SYSROOT_PREFERENCES_ADDIN (self)); + g_assert (GBP_IS_SYSROOT_PREFERENCES_ADDIN (self)); g_assert (DZL_IS_PREFERENCES (preferences)); /* Clear preferences so reload code doesn't try to @@ -187,19 +187,19 @@ ide_sysroot_preferences_addin_unload (IdePreferencesAddin *addin, static void preferences_addin_iface_init (IdePreferencesAddinInterface *iface) { - iface->load = ide_sysroot_preferences_addin_load; - iface->unload = ide_sysroot_preferences_addin_unload; + iface->load = gbp_sysroot_preferences_addin_load; + iface->unload = gbp_sysroot_preferences_addin_unload; } -G_DEFINE_TYPE_EXTENDED (IdeSysrootPreferencesAddin, ide_sysroot_preferences_addin, G_TYPE_OBJECT, 0, +G_DEFINE_TYPE_EXTENDED (GbpSysrootPreferencesAddin, gbp_sysroot_preferences_addin, G_TYPE_OBJECT, 0, G_IMPLEMENT_INTERFACE (IDE_TYPE_PREFERENCES_ADDIN, preferences_addin_iface_init)) static void -ide_sysroot_preferences_addin_class_init (IdeSysrootPreferencesAddinClass *klass) +gbp_sysroot_preferences_addin_class_init (GbpSysrootPreferencesAddinClass *klass) { } static void -ide_sysroot_preferences_addin_init (IdeSysrootPreferencesAddin *self) +gbp_sysroot_preferences_addin_init (GbpSysrootPreferencesAddin *self) { } diff --git a/src/plugins/sysroot/ide-sysroot-preferences-addin.h b/src/plugins/sysroot/gbp-sysroot-preferences-addin.h similarity index 79% rename from src/plugins/sysroot/ide-sysroot-preferences-addin.h rename to src/plugins/sysroot/gbp-sysroot-preferences-addin.h index a1f8e7b46..e8a4072cc 100644 --- a/src/plugins/sysroot/ide-sysroot-preferences-addin.h +++ b/src/plugins/sysroot/gbp-sysroot-preferences-addin.h @@ -1,4 +1,4 @@ -/* ide-sysroot-preferences.h +/* gbp-sysroot-preferences.h * * Copyright (C) 2018 Corentin Noël * Copyright (C) 2018 Collabora Ltd. @@ -23,8 +23,8 @@ G_BEGIN_DECLS -#define IDE_TYPE_SYSROOT_PREFERENCES_ADDIN (ide_sysroot_preferences_addin_get_type()) +#define GBP_TYPE_SYSROOT_PREFERENCES_ADDIN (gbp_sysroot_preferences_addin_get_type()) -G_DECLARE_FINAL_TYPE (IdeSysrootPreferencesAddin, ide_sysroot_preferences_addin, IDE, SYSROOT_PREFERENCES_ADDIN, GObject) +G_DECLARE_FINAL_TYPE (GbpSysrootPreferencesAddin, gbp_sysroot_preferences_addin, GBP, SYSROOT_PREFERENCES_ADDIN, GObject) G_END_DECLS diff --git a/src/plugins/sysroot/ide-sysroot-preferences-row.c b/src/plugins/sysroot/gbp-sysroot-preferences-row.c similarity index 62% rename from src/plugins/sysroot/ide-sysroot-preferences-row.c rename to src/plugins/sysroot/gbp-sysroot-preferences-row.c index 01ea6e0ed..5b23614b1 100644 --- a/src/plugins/sysroot/ide-sysroot-preferences-row.c +++ b/src/plugins/sysroot/gbp-sysroot-preferences-row.c @@ -1,4 +1,4 @@ -/* ide-sysroot-preferences-row.c +/* gbp-sysroot-preferences-row.c * * Copyright (C) 2018 Corentin Noël * Copyright (C) 2018 Collabora Ltd. @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -#define G_LOG_DOMAIN "ide-sysroot-preferences-row" +#define G_LOG_DOMAIN "gbp-sysroot-preferences-row" -#include "ide-sysroot-preferences-row.h" -#include "ide-sysroot-manager.h" +#include "gbp-sysroot-preferences-row.h" +#include "gbp-sysroot-manager.h" -struct _IdeSysrootPreferencesRow +struct _GbpSysrootPreferencesRow { DzlPreferencesBin parent_instance; gchar *sysroot_id; @@ -34,7 +34,7 @@ struct _IdeSysrootPreferencesRow GtkWidget *popover; }; -G_DEFINE_TYPE (IdeSysrootPreferencesRow, ide_sysroot_preferences_row, DZL_TYPE_PREFERENCES_BIN) +G_DEFINE_TYPE (GbpSysrootPreferencesRow, gbp_sysroot_preferences_row, DZL_TYPE_PREFERENCES_BIN) enum { PROP_0, @@ -45,81 +45,81 @@ enum { static GParamSpec *properties [N_PROPS]; static void -sysroot_preferences_row_name_changed (IdeSysrootPreferencesRow *self, +sysroot_preferences_row_name_changed (GbpSysrootPreferencesRow *self, gpointer user_data) { - IdeSysrootManager *sysroot_manager = NULL; + GbpSysrootManager *sysroot_manager = NULL; - g_assert (IDE_IS_SYSROOT_PREFERENCES_ROW (self)); + g_assert (GBP_IS_SYSROOT_PREFERENCES_ROW (self)); g_assert (GTK_IS_ENTRY (user_data)); - sysroot_manager = ide_sysroot_manager_get_default (); - ide_sysroot_manager_set_target_name (sysroot_manager, + sysroot_manager = gbp_sysroot_manager_get_default (); + gbp_sysroot_manager_set_target_name (sysroot_manager, self->sysroot_id, gtk_entry_get_text (GTK_ENTRY (user_data))); } static void -sysroot_preferences_row_sysroot_changed (IdeSysrootPreferencesRow *self, +sysroot_preferences_row_sysroot_changed (GbpSysrootPreferencesRow *self, gpointer user_data) { - IdeSysrootManager *sysroot_manager = NULL; + GbpSysrootManager *sysroot_manager = NULL; - g_assert (IDE_IS_SYSROOT_PREFERENCES_ROW (self)); + g_assert (GBP_IS_SYSROOT_PREFERENCES_ROW (self)); g_assert (GTK_IS_ENTRY (user_data)); - sysroot_manager = ide_sysroot_manager_get_default (); - ide_sysroot_manager_set_target_path (sysroot_manager, + sysroot_manager = gbp_sysroot_manager_get_default (); + gbp_sysroot_manager_set_target_path (sysroot_manager, self->sysroot_id, gtk_entry_get_text (GTK_ENTRY (user_data))); } static void -sysroot_preferences_row_pkg_config_changed (IdeSysrootPreferencesRow *self, +sysroot_preferences_row_pkg_config_changed (GbpSysrootPreferencesRow *self, gpointer user_data) { - IdeSysrootManager *sysroot_manager = NULL; + GbpSysrootManager *sysroot_manager = NULL; - g_assert (IDE_IS_SYSROOT_PREFERENCES_ROW (self)); + g_assert (GBP_IS_SYSROOT_PREFERENCES_ROW (self)); g_assert (GTK_IS_ENTRY (user_data)); - sysroot_manager = ide_sysroot_manager_get_default (); - ide_sysroot_manager_set_target_pkg_config_path (sysroot_manager, + sysroot_manager = gbp_sysroot_manager_get_default (); + gbp_sysroot_manager_set_target_pkg_config_path (sysroot_manager, self->sysroot_id, gtk_entry_get_text (GTK_ENTRY (user_data))); } static void -sysroot_preferences_row_clicked (IdeSysrootPreferencesRow *self, +sysroot_preferences_row_clicked (GbpSysrootPreferencesRow *self, gpointer user_data) { - g_assert (IDE_IS_SYSROOT_PREFERENCES_ROW (self)); + g_assert (GBP_IS_SYSROOT_PREFERENCES_ROW (self)); - ide_sysroot_preferences_row_show_popup (self); + gbp_sysroot_preferences_row_show_popup (self); } static void -sysroot_preferences_delete (IdeSysrootPreferencesRow *self, +sysroot_preferences_delete (GbpSysrootPreferencesRow *self, gpointer user_data) { - IdeSysrootManager *sysroot_manager = NULL; + GbpSysrootManager *sysroot_manager = NULL; - g_assert (IDE_IS_SYSROOT_PREFERENCES_ROW (self)); + g_assert (GBP_IS_SYSROOT_PREFERENCES_ROW (self)); - sysroot_manager = ide_sysroot_manager_get_default (); - ide_sysroot_manager_remove_target (sysroot_manager, self->sysroot_id); + sysroot_manager = gbp_sysroot_manager_get_default (); + gbp_sysroot_manager_remove_target (sysroot_manager, self->sysroot_id); /* The row is wrapped into a GtkListBoxRow that won't be removed when child is destroyed */ gtk_widget_destroy (gtk_widget_get_parent (GTK_WIDGET (self))); } static void -ide_sysroot_preferences_row_get_property (GObject *object, +gbp_sysroot_preferences_row_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - IdeSysrootPreferencesRow *self = IDE_SYSROOT_PREFERENCES_ROW (object); + GbpSysrootPreferencesRow *self = GBP_SYSROOT_PREFERENCES_ROW (object); switch (prop_id) { @@ -133,12 +133,12 @@ ide_sysroot_preferences_row_get_property (GObject *object, } static void -ide_sysroot_preferences_row_set_property (GObject *object, +gbp_sysroot_preferences_row_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - IdeSysrootPreferencesRow *self = IDE_SYSROOT_PREFERENCES_ROW (object); + GbpSysrootPreferencesRow *self = GBP_SYSROOT_PREFERENCES_ROW (object); switch (prop_id) { @@ -152,19 +152,19 @@ ide_sysroot_preferences_row_set_property (GObject *object, } static void -ide_sysroot_preferences_row_finalize (GObject *object) +gbp_sysroot_preferences_row_finalize (GObject *object) { - IdeSysrootPreferencesRow *self = (IdeSysrootPreferencesRow *) object; + GbpSysrootPreferencesRow *self = (GbpSysrootPreferencesRow *) object; g_clear_pointer (&self->sysroot_id, g_free); - G_OBJECT_CLASS (ide_sysroot_preferences_row_parent_class)->finalize (object); + G_OBJECT_CLASS (gbp_sysroot_preferences_row_parent_class)->finalize (object); } void -ide_sysroot_preferences_row_show_popup (IdeSysrootPreferencesRow *self) +gbp_sysroot_preferences_row_show_popup (GbpSysrootPreferencesRow *self) { - g_return_if_fail (IDE_IS_SYSROOT_PREFERENCES_ROW (self)); + g_return_if_fail (GBP_IS_SYSROOT_PREFERENCES_ROW (self)); g_return_if_fail (GTK_IS_POPOVER (self->popover)); gtk_popover_popup (GTK_POPOVER (self->popover)); @@ -172,18 +172,18 @@ ide_sysroot_preferences_row_show_popup (IdeSysrootPreferencesRow *self) } static void -ide_sysroot_preferences_row_constructed (GObject *object) +gbp_sysroot_preferences_row_constructed (GObject *object) { - IdeSysrootManager *sysroot_manager = NULL; + GbpSysrootManager *sysroot_manager = NULL; gchar *value; - IdeSysrootPreferencesRow *self = (IdeSysrootPreferencesRow *) object; + GbpSysrootPreferencesRow *self = (GbpSysrootPreferencesRow *) object; - sysroot_manager = ide_sysroot_manager_get_default (); + sysroot_manager = gbp_sysroot_manager_get_default (); gtk_entry_set_text (self->name_entry, - ide_sysroot_manager_get_target_name (sysroot_manager, self->sysroot_id)); + gbp_sysroot_manager_get_target_name (sysroot_manager, self->sysroot_id)); gtk_entry_set_text (self->sysroot_entry, - ide_sysroot_manager_get_target_path (sysroot_manager, self->sysroot_id)); - value = ide_sysroot_manager_get_target_pkg_config_path (sysroot_manager, self->sysroot_id); + gbp_sysroot_manager_get_target_path (sysroot_manager, self->sysroot_id)); + value = gbp_sysroot_manager_get_target_pkg_config_path (sysroot_manager, self->sysroot_id); if (value != NULL) gtk_entry_set_text (self->pkg_config_entry, value); @@ -207,15 +207,15 @@ ide_sysroot_preferences_row_constructed (GObject *object) } static void -ide_sysroot_preferences_row_class_init (IdeSysrootPreferencesRowClass *klass) +gbp_sysroot_preferences_row_class_init (GbpSysrootPreferencesRowClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - object_class->finalize = ide_sysroot_preferences_row_finalize; - object_class->get_property = ide_sysroot_preferences_row_get_property; - object_class->set_property = ide_sysroot_preferences_row_set_property; - object_class->constructed = ide_sysroot_preferences_row_constructed; + object_class->finalize = gbp_sysroot_preferences_row_finalize; + object_class->get_property = gbp_sysroot_preferences_row_get_property; + object_class->set_property = gbp_sysroot_preferences_row_set_property; + object_class->constructed = gbp_sysroot_preferences_row_constructed; properties [PROP_SYSROOT_ID] = g_param_spec_string ("sysroot-id", @@ -226,17 +226,17 @@ ide_sysroot_preferences_row_class_init (IdeSysrootPreferencesRowClass *klass) g_object_class_install_properties (object_class, N_PROPS, properties); - gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/builder/plugins/sysroot-plugin/ide-sysroot-preferences-row.ui"); - gtk_widget_class_bind_template_child (widget_class, IdeSysrootPreferencesRow, display_name); - gtk_widget_class_bind_template_child (widget_class, IdeSysrootPreferencesRow, popover); - gtk_widget_class_bind_template_child (widget_class, IdeSysrootPreferencesRow, name_entry); - gtk_widget_class_bind_template_child (widget_class, IdeSysrootPreferencesRow, sysroot_entry); - gtk_widget_class_bind_template_child (widget_class, IdeSysrootPreferencesRow, pkg_config_entry); - gtk_widget_class_bind_template_child (widget_class, IdeSysrootPreferencesRow, delete_button); + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/builder/plugins/sysroot-plugin/gbp-sysroot-preferences-row.ui"); + gtk_widget_class_bind_template_child (widget_class, GbpSysrootPreferencesRow, display_name); + gtk_widget_class_bind_template_child (widget_class, GbpSysrootPreferencesRow, popover); + gtk_widget_class_bind_template_child (widget_class, GbpSysrootPreferencesRow, name_entry); + gtk_widget_class_bind_template_child (widget_class, GbpSysrootPreferencesRow, sysroot_entry); + gtk_widget_class_bind_template_child (widget_class, GbpSysrootPreferencesRow, pkg_config_entry); + gtk_widget_class_bind_template_child (widget_class, GbpSysrootPreferencesRow, delete_button); } static void -ide_sysroot_preferences_row_init (IdeSysrootPreferencesRow *self) +gbp_sysroot_preferences_row_init (GbpSysrootPreferencesRow *self) { gtk_widget_init_template (GTK_WIDGET (self)); diff --git a/src/plugins/sysroot/ide-sysroot-preferences-row.h b/src/plugins/sysroot/gbp-sysroot-preferences-row.h similarity index 74% rename from src/plugins/sysroot/ide-sysroot-preferences-row.h rename to src/plugins/sysroot/gbp-sysroot-preferences-row.h index 4fd314c95..ac3e08206 100644 --- a/src/plugins/sysroot/ide-sysroot-preferences-row.h +++ b/src/plugins/sysroot/gbp-sysroot-preferences-row.h @@ -1,4 +1,4 @@ -/* ide-sysroot-preferences-row.h +/* gbp-sysroot-preferences-row.h * * Copyright (C) 2018 Corentin Noël * Copyright (C) 2018 Collabora Ltd. @@ -23,10 +23,10 @@ G_BEGIN_DECLS -#define IDE_TYPE_SYSROOT_PREFERENCES_ROW (ide_sysroot_preferences_row_get_type()) +#define GBP_TYPE_SYSROOT_PREFERENCES_ROW (gbp_sysroot_preferences_row_get_type()) -G_DECLARE_FINAL_TYPE (IdeSysrootPreferencesRow, ide_sysroot_preferences_row, IDE, SYSROOT_PREFERENCES_ROW, DzlPreferencesBin) +G_DECLARE_FINAL_TYPE (GbpSysrootPreferencesRow, gbp_sysroot_preferences_row, GBP, SYSROOT_PREFERENCES_ROW, DzlPreferencesBin) -void ide_sysroot_preferences_row_show_popup (IdeSysrootPreferencesRow *self); +void gbp_sysroot_preferences_row_show_popup (GbpSysrootPreferencesRow *self); G_END_DECLS diff --git a/src/plugins/sysroot/ide-sysroot-preferences-row.ui b/src/plugins/sysroot/gbp-sysroot-preferences-row.ui similarity index 98% rename from src/plugins/sysroot/ide-sysroot-preferences-row.ui rename to src/plugins/sysroot/gbp-sysroot-preferences-row.ui index bddd70179..853ed6a8e 100644 --- a/src/plugins/sysroot/ide-sysroot-preferences-row.ui +++ b/src/plugins/sysroot/gbp-sysroot-preferences-row.ui @@ -1,7 +1,7 @@ -