[gnome-panel] libgnome-panel: add gp_module_set_compatibility



commit c9268c5eab4a4cb54e41b52356cbd541114ea00b
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Fri Jan 5 20:52:32 2018 +0200

    libgnome-panel: add gp_module_set_compatibility

 .../libpanel-applet-private/gp-applet-manager.c    |    2 +-
 libgnome-panel/gp-module-private.h                 |   32 ++++++------
 libgnome-panel/gp-module.c                         |   54 +++++++++++++------
 libgnome-panel/gp-module.h                         |   37 +++++++++-----
 modules/clock/clock-module.c                       |    7 ++-
 modules/fish/fish-module.c                         |    7 ++-
 modules/notification-area/na-module.c              |    7 ++-
 modules/separator/separator-module.c               |    7 ++-
 modules/status-notifier/sn-module.c                |    7 ++-
 modules/wncklet/wncklet-module.c                   |    7 ++-
 10 files changed, 102 insertions(+), 65 deletions(-)
---
diff --git a/gnome-panel/libpanel-applet-private/gp-applet-manager.c 
b/gnome-panel/libpanel-applet-private/gp-applet-manager.c
index 2dba09e..38b9743 100644
--- a/gnome-panel/libpanel-applet-private/gp-applet-manager.c
+++ b/gnome-panel/libpanel-applet-private/gp-applet-manager.c
@@ -296,7 +296,7 @@ gp_applet_manager_get_new_iid (PanelAppletsManager *manager,
       const gchar *applet;
 
       module = GP_MODULE (l->data);
-      applet = gp_module_get_applet_from_iid (module, old_iid);
+      applet = gp_module_get_applet_id_from_iid (module, old_iid);
 
       if (applet != NULL)
         {
diff --git a/libgnome-panel/gp-module-private.h b/libgnome-panel/gp-module-private.h
index 425a792..894a7d4 100644
--- a/libgnome-panel/gp-module-private.h
+++ b/libgnome-panel/gp-module-private.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2017 Alberts Muktupāvels
+ * Copyright (C) 2016-2018 Alberts Muktupāvels
  *
  * This library is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published by
@@ -33,26 +33,26 @@ typedef enum
 #define GP_MODULE_ERROR gp_module_error_quark ()
 GQuark gp_module_error_quark (void);
 
-GpModule            *gp_module_new_from_path       (const gchar           *path);
+GpModule            *gp_module_new_from_path         (const gchar           *path);
 
-const gchar         *gp_module_get_id              (GpModule              *module);
+const gchar         *gp_module_get_id                (GpModule              *module);
 
-const gchar * const *gp_module_get_applets         (GpModule              *module);
+const gchar * const *gp_module_get_applets           (GpModule              *module);
 
-GpAppletInfo        *gp_module_get_applet_info     (GpModule              *module,
-                                                    const gchar           *applet,
-                                                    GError               **error);
+GpAppletInfo        *gp_module_get_applet_info       (GpModule              *module,
+                                                      const gchar           *applet,
+                                                      GError               **error);
 
-const gchar         *gp_module_get_applet_from_iid (GpModule              *module,
-                                                    const gchar           *old_iid);
+const gchar         *gp_module_get_applet_id_from_iid (GpModule              *module,
+                                                       const gchar           *old_iid);
 
-GpApplet            *gp_module_applet_new          (GpModule              *module,
-                                                    const gchar           *applet,
-                                                    const gchar           *settings_path,
-                                                    gboolean               locked_down,
-                                                    GtkOrientation         orientation,
-                                                    GtkPositionType        position,
-                                                    GError               **error);
+GpApplet            *gp_module_applet_new             (GpModule              *module,
+                                                       const gchar           *applet,
+                                                       const gchar           *settings_path,
+                                                       gboolean               locked_down,
+                                                       GtkOrientation         orientation,
+                                                       GtkPositionType        position,
+                                                       GError               **error);
 
 G_END_DECLS
 
diff --git a/libgnome-panel/gp-module.c b/libgnome-panel/gp-module.c
index 21f10cd..ba0d615 100644
--- a/libgnome-panel/gp-module.c
+++ b/libgnome-panel/gp-module.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2017 Alberts Muktupāvels
+ * Copyright (C) 2016-2018 Alberts Muktupāvels
  *
  * This library is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published by
@@ -67,7 +67,7 @@
  * }
  *
  * static const gchar *
- * example_get_applet_from_iid (const gchar *iid)
+ * example_get_applet_id_from_iid (const gchar *iid)
  * {
  *   if (g_strcmp0 (iid, "ExampleAppletFactory::Example1Applet") == 0)
  *     {
@@ -110,6 +110,8 @@
  *   gp_module_set_version (module, PACKAGE_VERSION);
  *
  *   gp_module_set_applet_ids (module, "example1", "example2", NULL);
+ *
+ *   gp_module_set_compatibility (module, example_get_applet_id_from_iid);
  * }
  *
  * void
@@ -118,7 +120,6 @@
  *   *vtable = (GpAppletVTable) {
  *     example_get_applet_info,
  *     example_get_applet_type,
- *     example_get_applet_from_iid, // or NULL if not needed
  *     example_setup_about // or NULL if not needed
  *   };
  * }
@@ -146,22 +147,24 @@ typedef void (* GetAppletVTableFunc) (GpAppletVTable *vtable);
 
 struct _GpModule
 {
-  GObject          parent;
+  GObject                  parent;
+
+  gchar                   *path;
+  GModule                 *library;
 
-  gchar           *path;
-  GModule         *library;
+  guint32                  abi_version;
 
-  guint32          abi_version;
+  gchar                   *id;
+  gchar                   *version;
 
-  gchar           *id;
-  gchar           *version;
+  gchar                   *gettext_domain;
 
-  gchar           *gettext_domain;
+  gchar                  **applet_ids;
 
-  gchar          **applet_ids;
+  GetAppletIdFromIidFunc   compatibility_func;
 
-  GpAppletVTable   applet_vtable;
-  GHashTable      *applets;
+  GpAppletVTable           applet_vtable;
+  GHashTable              *applets;
 };
 
 G_DEFINE_TYPE (GpModule, gp_module, G_TYPE_OBJECT)
@@ -553,14 +556,31 @@ gp_module_get_applet_info (GpModule     *module,
   return get_applet_info (module, applet, error);
 }
 
+/**
+ * gp_module_set_compatibility:
+ * @module: a #GpModule
+ * @func: the function to call to convert applet iid to id
+ *
+ * Specifies a function to be used to convert old applet iid to id.
+ *
+ * The function must check if iid is known to module and only then return
+ * new applet id.
+ */
+void
+gp_module_set_compatibility (GpModule               *module,
+                             GetAppletIdFromIidFunc  func)
+{
+  module->compatibility_func = func;
+}
+
 const gchar *
-gp_module_get_applet_from_iid (GpModule    *module,
-                               const gchar *old_iid)
+gp_module_get_applet_id_from_iid (GpModule    *module,
+                                  const gchar *old_iid)
 {
-  if (module->applet_vtable.get_applet_from_iid == NULL)
+  if (module->compatibility_func == NULL)
     return NULL;
 
-  return module->applet_vtable.get_applet_from_iid (old_iid);
+  return module->compatibility_func (old_iid);
 }
 
 /**
diff --git a/libgnome-panel/gp-module.h b/libgnome-panel/gp-module.h
index 07b1608..15df3e7 100644
--- a/libgnome-panel/gp-module.h
+++ b/libgnome-panel/gp-module.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2017 Alberts Muktupāvels
+ * Copyright (C) 2016-2018 Alberts Muktupāvels
  *
  * This library is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published by
@@ -31,10 +31,20 @@ G_BEGIN_DECLS
 #define GP_MODULE_ABI_VERSION 0x0001
 
 /**
+ * GetAppletIdFromIidFunc:
+ * @iid: the applet iid
+ *
+ * Specifies the type of the module function called to convert old applet
+ * iid to new id. See gp_module_set_compatibility().
+ *
+ * Returns: (transfer none): the applet id, or %NULL.
+ */
+typedef const gchar * (* GetAppletIdFromIidFunc) (const gchar *iid);
+
+/**
  * GpAppletVTable:
  * @get_applet_info: (transfer full): returns a #GpAppletInfo.
  * @get_applet_type: returns a #GType.
- * @get_applet_from_iid: Compatibility function.
  * @setup_about: Function for setting up about dialog.
  *
  * The #GpAppletVTable provides the functions required by the #GpModule.
@@ -46,8 +56,6 @@ struct _GpAppletVTable
 
   GType          (* get_applet_type)     (const gchar    *applet);
 
-  const gchar  * (* get_applet_from_iid) (const gchar    *iid);
-
   gboolean       (* setup_about)         (GtkAboutDialog *dialog,
                                           const gchar    *applet);
 };
@@ -55,21 +63,24 @@ struct _GpAppletVTable
 #define GP_TYPE_MODULE (gp_module_get_type ())
 G_DECLARE_FINAL_TYPE (GpModule, gp_module, GP, MODULE, GObject)
 
-void          gp_module_set_abi_version    (GpModule    *module,
-                                            guint32      abi_version);
+void          gp_module_set_abi_version    (GpModule               *module,
+                                            guint32                 abi_version);
 
-void          gp_module_set_gettext_domain (GpModule    *module,
-                                            const gchar *gettext_domain);
+void          gp_module_set_gettext_domain (GpModule               *module,
+                                            const gchar            *gettext_domain);
 
-void          gp_module_set_id             (GpModule    *module,
-                                            const gchar *id);
+void          gp_module_set_id             (GpModule               *module,
+                                            const gchar            *id);
 
-void          gp_module_set_version        (GpModule    *module,
-                                            const gchar *version);
+void          gp_module_set_version        (GpModule               *module,
+                                            const gchar            *version);
 
-void          gp_module_set_applet_ids     (GpModule    *module,
+void          gp_module_set_applet_ids     (GpModule               *module,
                                             ...);
 
+void          gp_module_set_compatibility  (GpModule               *module,
+                                            GetAppletIdFromIidFunc  func);
+
 /**
  * gp_module_load:
  * @module: a #GpModule
diff --git a/modules/clock/clock-module.c b/modules/clock/clock-module.c
index 2d61dde..c0b19e2 100644
--- a/modules/clock/clock-module.c
+++ b/modules/clock/clock-module.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2017 Alberts Muktupāvels
+ * Copyright (C) 2016-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
@@ -43,7 +43,7 @@ clock_get_applet_type (const gchar *applet)
 }
 
 static const gchar *
-clock_get_applet_from_iid (const gchar *iid)
+clock_get_applet_id_from_iid (const gchar *iid)
 {
   if (g_strcmp0 (iid, "ClockAppletFactory::ClockApplet") == 0 ||
       g_strcmp0 (iid, "clock::clock") == 0)
@@ -65,6 +65,8 @@ gp_module_load (GpModule *module)
   gp_module_set_version (module, PACKAGE_VERSION);
 
   gp_module_set_applet_ids (module, "clock", NULL);
+
+  gp_module_set_compatibility (module, clock_get_applet_id_from_iid);
 }
 
 void
@@ -73,7 +75,6 @@ gp_module_get_applet_vtable (GpAppletVTable *vtable)
   *vtable = (GpAppletVTable) {
     clock_get_applet_info,
     clock_get_applet_type,
-    clock_get_applet_from_iid,
     NULL
   };
 }
diff --git a/modules/fish/fish-module.c b/modules/fish/fish-module.c
index 18a0112..5626a6b 100644
--- a/modules/fish/fish-module.c
+++ b/modules/fish/fish-module.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2017 Alberts Muktupāvels
+ * Copyright (C) 2016-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
@@ -43,7 +43,7 @@ fish_get_applet_type (const gchar *applet)
 }
 
 static const gchar *
-fish_get_applet_from_iid (const gchar *iid)
+fish_get_applet_id_from_iid (const gchar *iid)
 {
   if (g_strcmp0 (iid, "FishAppletFactory::FishApplet") == 0 ||
       g_strcmp0 (iid, "fish::fish") == 0)
@@ -65,6 +65,8 @@ gp_module_load (GpModule *module)
   gp_module_set_version (module, PACKAGE_VERSION);
 
   gp_module_set_applet_ids (module, "fish", NULL);
+
+  gp_module_set_compatibility (module, fish_get_applet_id_from_iid);
 }
 
 void
@@ -73,7 +75,6 @@ gp_module_get_applet_vtable (GpAppletVTable *vtable)
   *vtable = (GpAppletVTable) {
     fish_get_applet_info,
     fish_get_applet_type,
-    fish_get_applet_from_iid,
     NULL
   };
 }
diff --git a/modules/notification-area/na-module.c b/modules/notification-area/na-module.c
index 73d4d0c..5a732b7 100644
--- a/modules/notification-area/na-module.c
+++ b/modules/notification-area/na-module.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2017 Alberts Muktupāvels
+ * Copyright (C) 2016-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
@@ -43,7 +43,7 @@ na_get_applet_type (const gchar *applet)
 }
 
 static const gchar *
-na_get_applet_from_iid (const gchar *iid)
+na_get_applet_id_from_iid (const gchar *iid)
 {
   if (g_strcmp0 (iid, "NotificationAreaAppletFactory::NotificationArea") == 0 ||
       g_strcmp0 (iid, "notification-area::notification-area") == 0)
@@ -65,6 +65,8 @@ gp_module_load (GpModule *module)
   gp_module_set_version (module, PACKAGE_VERSION);
 
   gp_module_set_applet_ids (module, "notification-area", NULL);
+
+  gp_module_set_compatibility (module, na_get_applet_id_from_iid);
 }
 
 void
@@ -73,7 +75,6 @@ gp_module_get_applet_vtable (GpAppletVTable *vtable)
   *vtable = (GpAppletVTable) {
     na_get_applet_info,
     na_get_applet_type,
-    na_get_applet_from_iid,
     NULL
   };
 }
diff --git a/modules/separator/separator-module.c b/modules/separator/separator-module.c
index 025fb26..0ada658 100644
--- a/modules/separator/separator-module.c
+++ b/modules/separator/separator-module.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2017 Alberts Muktupāvels
+ * Copyright (C) 2016-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
@@ -37,7 +37,7 @@ separator_get_applet_type (const gchar *applet)
 }
 
 static const gchar *
-separator_get_applet_from_iid (const gchar *iid)
+separator_get_applet_id_from_iid (const gchar *iid)
 {
   if (g_strcmp0 (iid, "PanelInternalFactory::Separator") == 0 ||
       g_strcmp0 (iid, "separator::separator") == 0)
@@ -59,6 +59,8 @@ gp_module_load (GpModule *module)
   gp_module_set_version (module, PACKAGE_VERSION);
 
   gp_module_set_applet_ids (module, "separator", NULL);
+
+  gp_module_set_compatibility (module, separator_get_applet_id_from_iid);
 }
 
 void
@@ -67,7 +69,6 @@ gp_module_get_applet_vtable (GpAppletVTable *vtable)
   *vtable = (GpAppletVTable) {
     separator_get_applet_info,
     separator_get_applet_type,
-    separator_get_applet_from_iid,
     NULL
   };
 }
diff --git a/modules/status-notifier/sn-module.c b/modules/status-notifier/sn-module.c
index 5d1dc51..f3c0c8a 100644
--- a/modules/status-notifier/sn-module.c
+++ b/modules/status-notifier/sn-module.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2017 Alberts Muktupāvels
+ * Copyright (C) 2016-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
@@ -42,7 +42,7 @@ sn_get_applet_type (const gchar *applet)
 }
 
 static const gchar *
-sn_get_applet_from_iid (const gchar *iid)
+sn_get_applet_id_from_iid (const gchar *iid)
 {
   if (g_strcmp0 (iid, "status-notifier::status-notifier") == 0)
     return "status-notifier";
@@ -63,6 +63,8 @@ gp_module_load (GpModule *module)
   gp_module_set_version (module, PACKAGE_VERSION);
 
   gp_module_set_applet_ids (module, "status-notifier", NULL);
+
+  gp_module_set_compatibility (module, sn_get_applet_id_from_iid);
 }
 
 void
@@ -71,7 +73,6 @@ gp_module_get_applet_vtable (GpAppletVTable *vtable)
   *vtable = (GpAppletVTable) {
     sn_get_applet_info,
     sn_get_applet_type,
-    sn_get_applet_from_iid,
     NULL
   };
 }
diff --git a/modules/wncklet/wncklet-module.c b/modules/wncklet/wncklet-module.c
index b5516b6..b7def0b 100644
--- a/modules/wncklet/wncklet-module.c
+++ b/modules/wncklet/wncklet-module.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016-2017 Alberts Muktupāvels
+ * Copyright (C) 2016-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
@@ -96,7 +96,7 @@ wncklet_get_applet_type (const gchar *applet)
 }
 
 static const gchar *
-wncklet_get_applet_from_iid (const gchar *iid)
+wncklet_get_applet_id_from_iid (const gchar *iid)
 {
   if (g_strcmp0 (iid, "WnckletFactory::ShowDesktopApplet") == 0 ||
       g_strcmp0 (iid, "wncklet::show-desktop") == 0)
@@ -131,6 +131,8 @@ gp_module_load (GpModule *module)
   gp_module_set_applet_ids (module, "show-desktop", "window-list",
                             "window-menu", "workspace-switcher",
                             NULL);
+
+  gp_module_set_compatibility (module, wncklet_get_applet_id_from_iid);
 }
 
 void
@@ -139,7 +141,6 @@ gp_module_get_applet_vtable (GpAppletVTable *vtable)
   *vtable = (GpAppletVTable) {
     wncklet_get_applet_info,
     wncklet_get_applet_type,
-    wncklet_get_applet_from_iid,
     NULL
   };
 }


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