[gnome-builder/wip/mwleeds/ide-config-provider: 5/15] config-provider: Add IdeConfigurationProvider



commit 22bb50021bea2d82476a5ac41ce15bd2eef020bd
Author: Matthew Leeds <mleeds redhat com>
Date:   Wed Dec 21 13:31:05 2016 -0600

    config-provider: Add IdeConfigurationProvider
    
    This interface will allow build configurations to come from any plugin,
    such as the flatpak one.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777959

 libide/Makefile.am                              |    2 +
 libide/buildsystem/OVERVIEW.md                  |    5 +
 libide/buildsystem/ide-configuration-provider.c |  113 +++++++++++++++++++++++
 libide/buildsystem/ide-configuration-provider.h |   63 +++++++++++++
 libide/ide.h                                    |    1 +
 5 files changed, 184 insertions(+), 0 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index 1839c33..89a8ad2 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -40,6 +40,7 @@ libide_1_0_la_public_headers =                            \
        buildsystem/ide-builder.h                         \
        buildsystem/ide-configuration-manager.h           \
        buildsystem/ide-configuration.h                   \
+       buildsystem/ide-configuration-provider.h          \
        buildsystem/ide-environment-variable.h            \
        buildsystem/ide-environment.h                     \
        buildsystem/ide-simple-builder.h                  \
@@ -208,6 +209,7 @@ libide_1_0_la_public_sources =                            \
        buildsystem/ide-builder.c                         \
        buildsystem/ide-configuration-manager.c           \
        buildsystem/ide-configuration.c                   \
+       buildsystem/ide-configuration-provider.c          \
        buildsystem/ide-environment-variable.c            \
        buildsystem/ide-environment.c                     \
        buildsystem/ide-simple-builder.c                  \
diff --git a/libide/buildsystem/OVERVIEW.md b/libide/buildsystem/OVERVIEW.md
index 643a506..0d9c8f2 100644
--- a/libide/buildsystem/OVERVIEW.md
+++ b/libide/buildsystem/OVERVIEW.md
@@ -32,6 +32,11 @@ file.
 
 An individual configuration that was loaded/persisted to the .buildconfig file.
 
+## ide-configuration-provider.*
+
+This is the interface used for loading and unloading configurations into the
+IdeConfigurationManager. The flatpak plugin is one place it's implemented.
+
 ## ide-environment.c
 
 Manages a collection of key/value pairs (IdeEnvironmentVariable). This is a
diff --git a/libide/buildsystem/ide-configuration-provider.c b/libide/buildsystem/ide-configuration-provider.c
new file mode 100644
index 0000000..836fe04
--- /dev/null
+++ b/libide/buildsystem/ide-configuration-provider.c
@@ -0,0 +1,113 @@
+/* ide-configuration-provider.c
+ *
+ * Copyright (C) 2016 Matthew Leeds <mleeds redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ide-configuration-manager.h"
+#include "ide-configuration-provider.h"
+
+G_DEFINE_INTERFACE (IdeConfigurationProvider, ide_configuration_provider, G_TYPE_OBJECT)
+
+static void
+ide_configuration_provider_real_load (IdeConfigurationProvider *self,
+                                      IdeConfigurationManager  *manager)
+{
+}
+
+static void
+ide_configuration_provider_real_unload (IdeConfigurationProvider *self,
+                                        IdeConfigurationManager  *manager)
+{
+}
+
+void
+ide_configuration_provider_real_save_async (IdeConfigurationProvider *self,
+                                            GCancellable             *cancellable,
+                                            GAsyncReadyCallback       callback,
+                                            gpointer                  user_data)
+{
+  g_autoptr(GTask) task = user_data;
+
+  g_return_if_fail (IDE_IS_CONFIGURATION_PROVIDER (self));
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+  g_return_if_fail (G_IS_TASK (task));
+
+  g_warning ("The current IdeConfigurationProvider doesn't implement save_async");
+  g_task_return_boolean (task, TRUE);
+}
+
+gboolean
+ide_configuration_provider_real_save_finish (IdeConfigurationProvider  *self,
+                                             GAsyncResult              *result,
+                                             GError                   **error)
+{
+  g_return_val_if_fail (IDE_IS_CONFIGURATION_PROVIDER (self), FALSE);
+  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+
+  return TRUE;
+}
+
+static void
+ide_configuration_provider_default_init (IdeConfigurationProviderInterface *iface)
+{
+  iface->load = ide_configuration_provider_real_load;
+  iface->unload = ide_configuration_provider_real_unload;
+  iface->save_async = ide_configuration_provider_real_save_async;
+  iface->save_finish = ide_configuration_provider_real_save_finish;
+}
+
+void
+ide_configuration_provider_load (IdeConfigurationProvider *self,
+                                 IdeConfigurationManager  *manager)
+{
+  g_return_if_fail (IDE_IS_CONFIGURATION_PROVIDER (self));
+  g_return_if_fail (IDE_IS_CONFIGURATION_MANAGER (manager));
+
+  IDE_CONFIGURATION_PROVIDER_GET_IFACE (self)->load (self, manager);
+}
+
+void
+ide_configuration_provider_unload (IdeConfigurationProvider *self,
+                                   IdeConfigurationManager  *manager)
+{
+  g_return_if_fail (IDE_IS_CONFIGURATION_PROVIDER (self));
+  g_return_if_fail (IDE_IS_CONFIGURATION_MANAGER (manager));
+
+  IDE_CONFIGURATION_PROVIDER_GET_IFACE (self)->unload (self, manager);
+}
+
+void
+ide_configuration_provider_save_async (IdeConfigurationProvider *self,
+                                       GCancellable             *cancellable,
+                                       GAsyncReadyCallback       callback,
+                                       gpointer                  user_data)
+{
+  g_return_if_fail (IDE_IS_CONFIGURATION_PROVIDER (self));
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  IDE_CONFIGURATION_PROVIDER_GET_IFACE (self)->save_async (self, cancellable, callback, user_data);
+}
+
+gboolean
+ide_configuration_provider_save_finish (IdeConfigurationProvider  *self,
+                                        GAsyncResult              *result,
+                                        GError                   **error)
+{
+  g_return_val_if_fail (IDE_IS_CONFIGURATION_PROVIDER (self), FALSE);
+  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+
+  return IDE_CONFIGURATION_PROVIDER_GET_IFACE (self)->save_finish (self, result, error);
+}
diff --git a/libide/buildsystem/ide-configuration-provider.h b/libide/buildsystem/ide-configuration-provider.h
new file mode 100644
index 0000000..717f242
--- /dev/null
+++ b/libide/buildsystem/ide-configuration-provider.h
@@ -0,0 +1,63 @@
+/* ide-configuration-provider.h
+ *
+ * Copyright (C) 2016 Matthew Leeds <mleeds redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_CONFIGURATION_PROVIDER_H
+#define IDE_CONFIGURATION_PROVIDER_H
+
+#include <gio/gio.h>
+
+#include "ide-types.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_CONFIGURATION_PROVIDER (ide_configuration_provider_get_type ())
+
+G_DECLARE_INTERFACE (IdeConfigurationProvider, ide_configuration_provider, IDE, CONFIGURATION_PROVIDER, 
GObject)
+
+struct _IdeConfigurationProviderInterface
+{
+  GTypeInterface parent;
+
+  void   (*load)          (IdeConfigurationProvider  *self,
+                           IdeConfigurationManager   *manager);
+  void   (*unload)        (IdeConfigurationProvider  *self,
+                           IdeConfigurationManager   *manager);
+  void   (*save_async)    (IdeConfigurationProvider  *self,
+                           GCancellable              *cancellable,
+                           GAsyncReadyCallback        callback,
+                           gpointer                   user_data);
+  gboolean (*save_finish) (IdeConfigurationProvider  *self,
+                           GAsyncResult              *result,
+                           GError                   **error);
+};
+
+void ide_configuration_provider_load            (IdeConfigurationProvider *self,
+                                                 IdeConfigurationManager  *manager);
+void ide_configuration_provider_unload          (IdeConfigurationProvider *self,
+                                                 IdeConfigurationManager  *manager);
+void ide_configuration_provider_save_async      (IdeConfigurationProvider *self,
+                                                 GCancellable             *cancellable,
+                                                 GAsyncReadyCallback       callback,
+                                                 gpointer                  user_data);
+gboolean ide_configuration_provider_save_finish (IdeConfigurationProvider  *self,
+                                                 GAsyncResult              *result,
+                                                 GError                   **error);
+
+G_END_DECLS
+
+#endif /* IDE_CONFIGURATION_PROVIDER_H */
diff --git a/libide/ide.h b/libide/ide.h
index b8cc8f2..7bc3634 100644
--- a/libide/ide.h
+++ b/libide/ide.h
@@ -45,6 +45,7 @@ G_BEGIN_DECLS
 #include "buildsystem/ide-builder.h"
 #include "buildsystem/ide-configuration-manager.h"
 #include "buildsystem/ide-configuration.h"
+#include "buildsystem/ide-configuration-provider.h"
 #include "buildsystem/ide-environment-variable.h"
 #include "buildsystem/ide-environment.h"
 #include "buildsystem/ide-simple-builder.h"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]