[gnome-panel] add GpModuleManager
- From: Alberts MuktupÄvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] add GpModuleManager
- Date: Fri, 5 Jan 2018 23:12:22 +0000 (UTC)
commit ba068a7d02ef81430653c6b46f059aab6b3d24be
Author: Alberts MuktupÄvels <alberts muktupavels gmail com>
Date: Fri Jan 5 21:58:57 2018 +0200
add GpModuleManager
gnome-panel/Makefile.am | 3 +
gnome-panel/gp-module-manager.c | 122 +++++++++++++++++++++++++++++++++++++++
gnome-panel/gp-module-manager.h | 35 +++++++++++
3 files changed, 160 insertions(+), 0 deletions(-)
---
diff --git a/gnome-panel/Makefile.am b/gnome-panel/Makefile.am
index 5747305..0f8cac3 100644
--- a/gnome-panel/Makefile.am
+++ b/gnome-panel/Makefile.am
@@ -13,6 +13,8 @@ bin_PROGRAMS = \
panel_sources = \
gp-arrow-button.c \
gp-arrow-button.h \
+ gp-module-manager.c \
+ gp-module-manager.h \
gp-properties-dialog.c \
gp-properties-dialog.h \
gp-theme.c \
@@ -105,6 +107,7 @@ gnome_panel_SOURCES = \
gnome_panel_CFLAGS = \
-DGMENU_I_KNOW_THIS_IS_UNSTABLE \
-DGNOME_DESKTOP_USE_UNSTABLE_API \
+ -DMODULESDIR=\""$(libdir)/gnome-panel/modules"\" \
-DPANELDATADIR=\""$(datadir)/gnome-panel"\" \
-DGNOMELOCALEDIR=\""$(localedir)"\" \
-I$(srcdir) \
diff --git a/gnome-panel/gp-module-manager.c b/gnome-panel/gp-module-manager.c
new file mode 100644
index 0000000..e5a81d5
--- /dev/null
+++ b/gnome-panel/gp-module-manager.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2018 Alberts MuktupÄvels
+ *
+ * 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 2 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 "config.h"
+
+#include <libgnome-panel/gp-module-private.h>
+
+#include "gp-module-manager.h"
+
+struct _GpModuleManager
+{
+ GObject parent;
+
+ GHashTable *modules;
+};
+
+G_DEFINE_TYPE (GpModuleManager, gp_module_manager, G_TYPE_OBJECT)
+
+static gint
+sort_modules (gconstpointer a,
+ gconstpointer b)
+{
+ GpModule *a_module;
+ GpModule *b_module;
+
+ a_module = (GpModule *) a;
+ b_module = (GpModule *) b;
+
+ return g_strcmp0 (gp_module_get_id (a_module), gp_module_get_id (b_module));
+}
+
+static void
+load_modules (GpModuleManager *manager)
+{
+ GDir *dir;
+ const gchar *name;
+
+ dir = g_dir_open (MODULESDIR, 0, NULL);
+ if (!dir)
+ return;
+
+ while ((name = g_dir_read_name (dir)) != NULL)
+ {
+ gchar *path;
+ GpModule *module;
+ const gchar *id;
+
+ path = g_build_filename (MODULESDIR, name, NULL);
+ module = gp_module_new_from_path (path);
+ g_free (path);
+
+ if (module == NULL)
+ continue;
+
+ id = gp_module_get_id (module);
+ g_hash_table_insert (manager->modules, g_strdup (id), module);
+ }
+
+ g_dir_close (dir);
+}
+
+static void
+gp_module_manager_finalize (GObject *object)
+{
+ GpModuleManager *manager;
+
+ manager = GP_MODULE_MANAGER (object);
+
+ g_clear_pointer (&manager->modules, g_hash_table_destroy);
+
+ G_OBJECT_CLASS (gp_module_manager_parent_class)->finalize (object);
+}
+
+static void
+gp_module_manager_class_init (GpModuleManagerClass *manager_class)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (manager_class);
+
+ object_class->finalize = gp_module_manager_finalize;
+}
+
+static void
+gp_module_manager_init (GpModuleManager *manager)
+{
+ manager->modules = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, g_object_unref);
+
+ load_modules (manager);
+}
+
+GpModuleManager *
+gp_module_manager_new (void)
+{
+ return g_object_new (GP_TYPE_MODULE_MANAGER, NULL);
+}
+
+GList *
+gp_module_manager_get_modules (GpModuleManager *manager)
+{
+ GList *modules;
+
+ modules = g_hash_table_get_values (manager->modules);
+ modules = g_list_sort (modules, sort_modules);
+
+ return modules;
+}
diff --git a/gnome-panel/gp-module-manager.h b/gnome-panel/gp-module-manager.h
new file mode 100644
index 0000000..f1ffc94
--- /dev/null
+++ b/gnome-panel/gp-module-manager.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2018 Alberts MuktupÄvels
+ *
+ * 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 2 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 GP_MODULE_MANAGER_H
+#define GP_MODULE_MANAGER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GP_TYPE_MODULE_MANAGER (gp_module_manager_get_type ())
+G_DECLARE_FINAL_TYPE (GpModuleManager, gp_module_manager,
+ GP, MODULE_MANAGER, GObject)
+
+GpModuleManager *gp_module_manager_new (void);
+
+GList *gp_module_manager_get_modules (GpModuleManager *manager);
+
+G_END_DECLS
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]