[gnome-builder/wip/project-selector: 3/10] libide: add IdeProjectMiner and IdeProjectInfo types
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/project-selector: 3/10] libide: add IdeProjectMiner and IdeProjectInfo types
- Date: Mon, 30 Mar 2015 21:09:54 +0000 (UTC)
commit fcc87ff04cda4cc53946e9ce8a833832ebaa4c45
Author: Christian Hergert <christian hergert me>
Date: Sun Mar 29 19:20:46 2015 -0700
libide: add IdeProjectMiner and IdeProjectInfo types
libide/Makefile.am | 4 +
libide/ide-project-info.c | 236 ++++++++++++++++++++++++++++++++++++++++++++
libide/ide-project-info.h | 42 ++++++++
libide/ide-project-miner.c | 111 +++++++++++++++++++++
libide/ide-project-miner.h | 59 +++++++++++
5 files changed, 452 insertions(+), 0 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index d0b2922..a239fdb 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -119,8 +119,12 @@ libide_1_0_la_public_sources = \
libide/ide-project-file.h \
libide/ide-project-files.c \
libide/ide-project-files.h \
+ libide/ide-project-info.c \
+ libide/ide-project-info.h \
libide/ide-project-item.c \
libide/ide-project-item.h \
+ libide/ide-project-miner.c \
+ libide/ide-project-miner.h \
libide/ide-project.c \
libide/ide-project.h \
libide/ide-refactory.c \
diff --git a/libide/ide-project-info.c b/libide/ide-project-info.c
new file mode 100644
index 0000000..8036616
--- /dev/null
+++ b/libide/ide-project-info.c
@@ -0,0 +1,236 @@
+/* ide-project-info.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "ide-project-info"
+
+#include <glib/gi18n.h>
+
+#include "ide-project-info.h"
+
+/**
+ * SECTION:ide-project-info:
+ * @title: IdeProjectInfo
+ * @short_description: Information about a project not yet loaded
+ *
+ * This class contains information about a project that can be loaded.
+ * This information should be used to display a list of available projects.
+ */
+
+struct _IdeProjectInfo
+{
+ GObject parent_instance;
+
+ GFile *directory;
+ GFile *file;
+ gchar *name;
+};
+
+G_DEFINE_TYPE (IdeProjectInfo, ide_project_info, G_TYPE_OBJECT)
+
+enum {
+ PROP_0,
+ PROP_DIRECTORY,
+ PROP_FILE,
+ PROP_NAME,
+ LAST_PROP
+};
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+/**
+ * ide_project_info_get_directory:
+ * @self: (in): A #IdeProjectInfo.
+ *
+ * Gets the #IdeProjectInfo:directory property.
+ * This is the directory containing the project (if known).
+ *
+ * Returns: (nullable) (transfer none): A #GFile.
+ */
+GFile *
+ide_project_info_get_directory (IdeProjectInfo *self)
+{
+ g_return_val_if_fail (IDE_IS_PROJECT_INFO (self), NULL);
+
+ return self->directory;
+}
+
+/**
+ * ide_project_info_get_file:
+ * @self: (in): A #IdeProjectInfo.
+ *
+ * Gets the #IdeProjectInfo:file property.
+ * This is the project file (such as configure.ac) of the project.
+ *
+ * Returns: (nullable) (transfer none): A #GFile.
+ */
+GFile *
+ide_project_info_get_file (IdeProjectInfo *self)
+{
+ g_return_val_if_fail (IDE_IS_PROJECT_INFO (self), NULL);
+
+ return self->file;
+}
+
+const gchar *
+ide_project_info_get_name (IdeProjectInfo *self)
+{
+ g_return_val_if_fail (IDE_IS_PROJECT_INFO (self), NULL);
+
+ return self->name;
+}
+
+void
+ide_project_info_set_directory (IdeProjectInfo *self,
+ GFile *directory)
+{
+ g_return_if_fail (IDE_IS_PROJECT_INFO (self));
+ g_return_if_fail (!directory || G_IS_FILE (directory));
+
+ if (g_set_object (&self->directory, directory))
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_DIRECTORY]);
+}
+
+void
+ide_project_info_set_file (IdeProjectInfo *self,
+ GFile *file)
+{
+ g_return_if_fail (IDE_IS_PROJECT_INFO (self));
+ g_return_if_fail (!file || G_IS_FILE (file));
+
+ if (g_set_object (&self->file, file))
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_FILE]);
+}
+
+void
+ide_project_info_set_name (IdeProjectInfo *self,
+ const gchar *name)
+{
+ g_return_if_fail (IDE_IS_PROJECT_INFO (self));
+
+ if (name != self->name)
+ {
+ g_free (self->name);
+ self->name = g_strdup (name);
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_NAME]);
+ }
+}
+
+static void
+ide_project_info_finalize (GObject *object)
+{
+ IdeProjectInfo *self = (IdeProjectInfo *)object;
+
+ g_clear_pointer (&self->name, g_free);
+ g_clear_object (&self->directory);
+ g_clear_object (&self->file);
+
+ G_OBJECT_CLASS (ide_project_info_parent_class)->finalize (object);
+}
+
+static void
+ide_project_info_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ IdeProjectInfo *self = IDE_PROJECT_INFO (object);
+
+ switch (prop_id)
+ {
+ case PROP_DIRECTORY:
+ g_value_set_object (value, ide_project_info_get_directory (self));
+ break;
+
+ case PROP_FILE:
+ g_value_set_object (value, ide_project_info_get_file (self));
+ break;
+
+ case PROP_NAME:
+ g_value_set_string (value, ide_project_info_get_name (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_project_info_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ IdeProjectInfo *self = IDE_PROJECT_INFO (object);
+
+ switch (prop_id)
+ {
+ case PROP_DIRECTORY:
+ ide_project_info_set_directory (self, g_value_get_object (value));
+ break;
+
+ case PROP_FILE:
+ ide_project_info_set_file (self, g_value_get_object (value));
+ break;
+
+ case PROP_NAME:
+ ide_project_info_set_name (self, g_value_get_string (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ide_project_info_class_init (IdeProjectInfoClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = ide_project_info_finalize;
+ object_class->get_property = ide_project_info_get_property;
+ object_class->set_property = ide_project_info_set_property;
+
+ gParamSpecs [PROP_NAME] =
+ g_param_spec_string ("name",
+ _("Name"),
+ _("The project name"),
+ NULL,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_NAME, gParamSpecs [PROP_NAME]);
+
+ gParamSpecs [PROP_DIRECTORY] =
+ g_param_spec_object ("directory",
+ _("Directory"),
+ _("The project directory."),
+ G_TYPE_FILE,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_DIRECTORY, gParamSpecs [PROP_DIRECTORY]);
+
+ gParamSpecs [PROP_FILE] =
+ g_param_spec_object ("file",
+ _("File"),
+ _("The toplevel project file"),
+ G_TYPE_FILE,
+ (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_FILE, gParamSpecs [PROP_FILE]);
+}
+
+static void
+ide_project_info_init (IdeProjectInfo *self)
+{
+}
diff --git a/libide/ide-project-info.h b/libide/ide-project-info.h
new file mode 100644
index 0000000..81e56d0
--- /dev/null
+++ b/libide/ide-project-info.h
@@ -0,0 +1,42 @@
+/* ide-project-info.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_PROJECT_INFO_H
+#define IDE_PROJECT_INFO_H
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_PROJECT_INFO (ide_project_info_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeProjectInfo, ide_project_info, IDE, PROJECT_INFO, GObject)
+
+GFile *ide_project_info_get_file (IdeProjectInfo *self);
+GFile *ide_project_info_get_directory (IdeProjectInfo *self);
+const gchar *ide_project_info_get_name (IdeProjectInfo *self);
+void ide_project_info_set_file (IdeProjectInfo *self,
+ GFile *file);
+void ide_project_info_set_directory (IdeProjectInfo *self,
+ GFile *directory);
+void ide_project_info_set_name (IdeProjectInfo *self,
+ const gchar *name);
+
+G_END_DECLS
+
+#endif /* IDE_PROJECT_INFO_H */
diff --git a/libide/ide-project-miner.c b/libide/ide-project-miner.c
new file mode 100644
index 0000000..415883c
--- /dev/null
+++ b/libide/ide-project-miner.c
@@ -0,0 +1,111 @@
+/* ide-project-miner.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "ide-project-miner"
+
+#include "ide-project-miner.h"
+
+G_DEFINE_ABSTRACT_TYPE (IdeProjectMiner, ide_project_miner, G_TYPE_OBJECT)
+
+enum {
+ DISCOVERED,
+ LAST_SIGNAL
+};
+
+static guint gSignals [LAST_SIGNAL];
+
+static void
+ide_project_miner_class_init (IdeProjectMinerClass *klass)
+{
+ /**
+ * IdeProjectMiner::discovered:
+ * @self: An #IdeProjectMiner
+ * @project_info: An #IdeProjectInfo
+ *
+ * This signal is emitted when a new project has been discovered by the miner.
+ * The signal will always be emitted from the primary thread (Gtk+) as long as
+ * ide_project_miner_emit_discovered() was used to emit the signal.
+ */
+ gSignals [DISCOVERED] = g_signal_new ("discovered",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (IdeProjectMinerClass, discovered),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ IDE_TYPE_PROJECT_INFO);
+}
+
+static void
+ide_project_miner_init (IdeProjectMiner *self)
+{
+}
+
+static gboolean
+emit_discovered_cb (gpointer user_data)
+{
+ gpointer *data = user_data;
+ g_autoptr(IdeProjectMiner) miner = data[0];
+ g_autoptr(IdeProjectInfo) project_info = data[1];
+
+ g_signal_emit (miner, gSignals [DISCOVERED], 0, project_info);
+
+ g_free (data);
+
+ return G_SOURCE_REMOVE;
+}
+
+void
+ide_project_miner_emit_discovered (IdeProjectMiner *self,
+ IdeProjectInfo *project_info)
+{
+ gpointer *data;
+
+ g_return_if_fail (IDE_IS_PROJECT_MINER (self));
+ g_return_if_fail (IDE_IS_PROJECT_INFO (project_info));
+
+ data = g_new0 (gpointer, 2);
+ data[0] = g_object_ref (self);
+ data[1] = g_object_ref (project_info);
+
+ g_timeout_add (0, emit_discovered_cb, data);
+}
+
+void
+ide_project_miner_mine_async (IdeProjectMiner *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (IDE_IS_PROJECT_MINER (self));
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ IDE_PROJECT_MINER_GET_CLASS (self)->mine_async (self, cancellable, callback, user_data);
+}
+
+gboolean
+ide_project_miner_mine_finish (IdeProjectMiner *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (IDE_IS_PROJECT_MINER (self), FALSE);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+
+ return IDE_PROJECT_MINER_GET_CLASS (self)->mine_finish (self, result, error);
+}
diff --git a/libide/ide-project-miner.h b/libide/ide-project-miner.h
new file mode 100644
index 0000000..8b48a70
--- /dev/null
+++ b/libide/ide-project-miner.h
@@ -0,0 +1,59 @@
+/* ide-project-miner.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_PROJECT_MINER_H
+#define IDE_PROJECT_MINER_H
+
+#include <gio/gio.h>
+
+#include "ide-project-info.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_PROJECT_MINER (ide_project_miner_get_type())
+
+G_DECLARE_DERIVABLE_TYPE (IdeProjectMiner, ide_project_miner, IDE, PROJECT_MINER, GObject)
+
+struct _IdeProjectMinerClass
+{
+ GObjectClass parent;
+
+ void (*discovered) (IdeProjectMiner *self,
+ IdeProjectInfo *project_info);
+ void (*mine_async) (IdeProjectMiner *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ gboolean (*mine_finish) (IdeProjectMiner *self,
+ GAsyncResult *result,
+ GError **error);
+};
+
+void ide_project_miner_emit_discovered (IdeProjectMiner *self,
+ IdeProjectInfo *project_info);
+void ide_project_miner_mine_async (IdeProjectMiner *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean ide_project_miner_mine_finish (IdeProjectMiner *self,
+ GAsyncResult *result,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* IDE_PROJECT_MINER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]