[gnome-builder/wip/tintou/sysroot] sysroot: align with project code-style
- From: Corentin Noël <corentinnoel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/tintou/sysroot] sysroot: align with project code-style
- Date: Thu, 22 Feb 2018 11:46:11 +0000 (UTC)
commit 06dfa91805b68369e16b74748f55b19c4e2d1a8b
Author: Corentin Noël <corentin noel collabora co uk>
Date: Thu Feb 22 11:44:17 2018 +0000
sysroot: align with project code-style
src/plugins/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 ++---
src/plugins/sysroot/ide-sysroot-preferences-row.c | 78 ++++++++-----
src/plugins/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 <http://www.gnu.org/licenses/>.
*/
+#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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]