[gnome-panel] libgnome-panel: add GpGetAppletTypeFunc
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] libgnome-panel: add GpGetAppletTypeFunc
- Date: Sat, 6 Jan 2018 17:49:55 +0000 (UTC)
commit 17d4f491ba59d67eb71b92ee194aded0ec64dd1d
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sat Jan 6 19:44:53 2018 +0200
libgnome-panel: add GpGetAppletTypeFunc
libgnome-panel/gp-applet-info-private.h | 2 +
libgnome-panel/gp-applet-info.c | 10 ++++++--
libgnome-panel/gp-applet-info.h | 14 +++++++++++-
libgnome-panel/gp-module.c | 26 +++++------------------
libgnome-panel/gp-module.h | 3 --
modules/clock/clock-module.c | 16 ++++++--------
modules/fish/fish-module.c | 16 ++++++--------
modules/notification-area/na-module.c | 20 ++++++++----------
modules/separator/separator-module.c | 22 +++++++++++---------
modules/status-notifier/sn-module.c | 17 ++++++---------
modules/wncklet/wncklet-module.c | 34 ++++++------------------------
11 files changed, 76 insertions(+), 104 deletions(-)
---
diff --git a/libgnome-panel/gp-applet-info-private.h b/libgnome-panel/gp-applet-info-private.h
index b188b1f..3ccce0b 100644
--- a/libgnome-panel/gp-applet-info-private.h
+++ b/libgnome-panel/gp-applet-info-private.h
@@ -24,6 +24,8 @@ G_BEGIN_DECLS
struct _GpAppletInfo
{
+ GpGetAppletTypeFunc get_applet_type_func;
+
gchar *name;
gchar *description;
gchar *icon_name;
diff --git a/libgnome-panel/gp-applet-info.c b/libgnome-panel/gp-applet-info.c
index f8a24d6..1fab7cf 100644
--- a/libgnome-panel/gp-applet-info.c
+++ b/libgnome-panel/gp-applet-info.c
@@ -30,6 +30,7 @@
/**
* gp_applet_info_new:
+ * @func: the function to call to get #GType of this applet
* @name: the name of this applet
* @description: the description of this applet
* @icon_name: the icon name for this applet
@@ -39,14 +40,17 @@
* Returns: (transfer full): a newly created #GpAppletInfo.
*/
GpAppletInfo *
-gp_applet_info_new (const gchar *name,
- const gchar *description,
- const gchar *icon_name)
+gp_applet_info_new (GpGetAppletTypeFunc func,
+ const gchar *name,
+ const gchar *description,
+ const gchar *icon_name)
{
GpAppletInfo *info;
info = g_new0 (GpAppletInfo, 1);
+ info->get_applet_type_func = func;
+
info->name = g_strdup (name);
info->description = g_strdup (description);
info->icon_name = g_strdup (icon_name);
diff --git a/libgnome-panel/gp-applet-info.h b/libgnome-panel/gp-applet-info.h
index b303441..3ae9aee 100644
--- a/libgnome-panel/gp-applet-info.h
+++ b/libgnome-panel/gp-applet-info.h
@@ -31,14 +31,24 @@ G_BEGIN_DECLS
typedef struct _GpAppletInfo GpAppletInfo;
/**
+ * GpGetAppletTypeFunc:
+ *
+ * Function for getting #GType of applet.
+ *
+ * Returns: the #GType of applet.
+ */
+typedef GType (* GpGetAppletTypeFunc) (void);
+
+/**
* GpSetupAboutDialogFunc:
* @dialog: a #GtkAboutDialog
*
* Function for setting up about dialog.
*/
-typedef void (* GpSetupAboutDialogFunc) (GtkAboutDialog *dialog);
+typedef void (* GpSetupAboutDialogFunc) (GtkAboutDialog *dialog);
-GpAppletInfo *gp_applet_info_new (const gchar *name,
+GpAppletInfo *gp_applet_info_new (GpGetAppletTypeFunc func,
+ const gchar *name,
const gchar *description,
const gchar *icon_name);
diff --git a/libgnome-panel/gp-module.c b/libgnome-panel/gp-module.c
index 1770723..ea1d9ad 100644
--- a/libgnome-panel/gp-module.c
+++ b/libgnome-panel/gp-module.c
@@ -39,7 +39,8 @@
*
* if (g_strcmp0 (applet, "example1") == 0)
* {
- * info = gp_applet_info_new (_("Example 1 name"),
+ * info = gp_applet_info_new (example1_get_type,
+ * _("Example 1 name"),
* _("Example 1 description"),
* "example1-icon");
*
@@ -48,7 +49,8 @@
* }
* else if (g_strcmp0 (applet, "example2") == 0)
* {
- * info = gp_applet_info_new (_("Example 2 name"),
+ * info = gp_applet_info_new (example2_get_type,
+ * _("Example 2 name"),
* _("Example 2 description"),
* "example2-icon");
*
@@ -62,21 +64,6 @@
* return info;
* }
*
- * static GType
- * example_get_applet_type (const gchar *applet)
- * {
- * if (g_strcmp0 (applet, "example1") == 0)
- * {
- * return EXAMPLE_TYPE_EXAMPLE1;
- * }
- * else if (g_strcmp0 (applet, "example2") == 0)
- * {
- * return EXAMPLE_TYPE_EXAMPLE2;
- * }
- *
- * return G_TYPE_NONE;
- * }
- *
* static const gchar *
* example_get_applet_id_from_iid (const gchar *iid)
* {
@@ -113,8 +100,7 @@
* gp_module_get_applet_vtable (GpAppletVTable *vtable)
* {
* *vtable = (GpAppletVTable) {
- * example_get_applet_info,
- * example_get_applet_type,
+ * example_get_applet_info
* };
* }
* ]|
@@ -627,7 +613,7 @@ gp_module_applet_new (GpModule *module,
return NULL;
}
- type = module->applet_vtable.get_applet_type (applet);
+ type = info->get_applet_type_func ();
if (type == G_TYPE_NONE)
{
g_set_error (error, GP_MODULE_ERROR, GP_MODULE_ERROR_MISSING_APPLET_INFO,
diff --git a/libgnome-panel/gp-module.h b/libgnome-panel/gp-module.h
index 4650df5..3ece866 100644
--- a/libgnome-panel/gp-module.h
+++ b/libgnome-panel/gp-module.h
@@ -44,7 +44,6 @@ typedef const gchar * (* GetAppletIdFromIidFunc) (const gchar *iid);
/**
* GpAppletVTable:
* @get_applet_info: (transfer full): returns a #GpAppletInfo.
- * @get_applet_type: returns a #GType.
*
* The #GpAppletVTable provides the functions required by the #GpModule.
*/
@@ -52,8 +51,6 @@ typedef struct _GpAppletVTable GpAppletVTable;
struct _GpAppletVTable
{
GpAppletInfo * (* get_applet_info) (const gchar *applet);
-
- GType (* get_applet_type) (const gchar *applet);
};
#define GP_TYPE_MODULE (gp_module_get_type ())
diff --git a/modules/clock/clock-module.c b/modules/clock/clock-module.c
index 830b060..e25c386 100644
--- a/modules/clock/clock-module.c
+++ b/modules/clock/clock-module.c
@@ -25,11 +25,16 @@
static GpAppletInfo *
clock_get_applet_info (const gchar *applet)
{
+ const gchar *name;
const gchar *description;
+ const gchar *icon;
GpAppletInfo *info;
+ name = _("Clock");
description = _("Get the current time and date");
- info = gp_applet_info_new (_("Clock"), description, "gnome-panel-clock");
+ icon = "gnome-panel-clock";
+
+ info = gp_applet_info_new (clock_applet_get_type, name, description, icon);
gp_applet_info_set_backends (info, "x11");
gp_applet_info_set_help_uri (info, "help:clock");
@@ -37,12 +42,6 @@ clock_get_applet_info (const gchar *applet)
return info;
}
-static GType
-clock_get_applet_type (const gchar *applet)
-{
- return CLOCK_TYPE_APPLET;
-}
-
static const gchar *
clock_get_applet_id_from_iid (const gchar *iid)
{
@@ -74,7 +73,6 @@ void
gp_module_get_applet_vtable (GpAppletVTable *vtable)
{
*vtable = (GpAppletVTable) {
- clock_get_applet_info,
- clock_get_applet_type
+ clock_get_applet_info
};
}
diff --git a/modules/fish/fish-module.c b/modules/fish/fish-module.c
index 3537ccb..6d02700 100644
--- a/modules/fish/fish-module.c
+++ b/modules/fish/fish-module.c
@@ -25,11 +25,16 @@
static GpAppletInfo *
fish_get_applet_info (const gchar *applet)
{
+ const gchar *name;
const gchar *description;
+ const gchar *icon;
GpAppletInfo *info;
+ name = _("Fish");
description = _("Display a swimming fish or another animated creature");
- info = gp_applet_info_new (_("Fish"), description, "gnome-panel-fish");
+ icon = "gnome-panel-fish";
+
+ info = gp_applet_info_new (fish_applet_get_type, name, description, icon);
gp_applet_info_set_backends (info, "x11");
gp_applet_info_set_help_uri (info, "help:fish");
@@ -37,12 +42,6 @@ fish_get_applet_info (const gchar *applet)
return info;
}
-static GType
-fish_get_applet_type (const gchar *applet)
-{
- return FISH_TYPE_APPLET;
-}
-
static const gchar *
fish_get_applet_id_from_iid (const gchar *iid)
{
@@ -74,7 +73,6 @@ void
gp_module_get_applet_vtable (GpAppletVTable *vtable)
{
*vtable = (GpAppletVTable) {
- fish_get_applet_info,
- fish_get_applet_type
+ fish_get_applet_info
};
}
diff --git a/modules/notification-area/na-module.c b/modules/notification-area/na-module.c
index e9ef412..5622bcf 100644
--- a/modules/notification-area/na-module.c
+++ b/modules/notification-area/na-module.c
@@ -25,23 +25,22 @@
static GpAppletInfo *
na_get_applet_info (const gchar *applet)
{
+ const gchar *name;
+ const gchar *description;
+ const gchar *icon;
GpAppletInfo *info;
- info = gp_applet_info_new (_("Notification Area"),
- _("Area where notification icons appear"),
- "gnome-panel-notification-area");
+ name = _("Notification Area");
+ description = _("Area where notification icons appear");
+ icon = "gnome-panel-notification-area";
+
+ info = gp_applet_info_new (na_applet_get_type, name, description, icon);
gp_applet_info_set_backends (info, "x11");
return info;
}
-static GType
-na_get_applet_type (const gchar *applet)
-{
- return NA_TYPE_APPLET;
-}
-
static const gchar *
na_get_applet_id_from_iid (const gchar *iid)
{
@@ -73,7 +72,6 @@ void
gp_module_get_applet_vtable (GpAppletVTable *vtable)
{
*vtable = (GpAppletVTable) {
- na_get_applet_info,
- na_get_applet_type
+ na_get_applet_info
};
}
diff --git a/modules/separator/separator-module.c b/modules/separator/separator-module.c
index ec62697..dfc6360 100644
--- a/modules/separator/separator-module.c
+++ b/modules/separator/separator-module.c
@@ -25,15 +25,18 @@
static GpAppletInfo *
separator_get_applet_info (const gchar *applet)
{
- return gp_applet_info_new (_("Separator"),
- _("A separator to organize the panel items"),
- "gnome-panel-separator");
-}
+ const gchar *name;
+ const gchar *description;
+ const gchar *icon;
+ GpAppletInfo *info;
-static GType
-separator_get_applet_type (const gchar *applet)
-{
- return SEPARATOR_TYPE_APPLET;
+ name = _("Separator");
+ description = _("A separator to organize the panel items");
+ icon = "gnome-panel-separator";
+
+ info = gp_applet_info_new (separator_applet_get_type, name, description, icon);
+
+ return info;
}
static const gchar *
@@ -67,7 +70,6 @@ void
gp_module_get_applet_vtable (GpAppletVTable *vtable)
{
*vtable = (GpAppletVTable) {
- separator_get_applet_info,
- separator_get_applet_type
+ separator_get_applet_info
};
}
diff --git a/modules/status-notifier/sn-module.c b/modules/status-notifier/sn-module.c
index 1d7a109..673db22 100644
--- a/modules/status-notifier/sn-module.c
+++ b/modules/status-notifier/sn-module.c
@@ -25,20 +25,18 @@
static GpAppletInfo *
sn_get_applet_info (const gchar *applet)
{
+ const gchar *name;
const gchar *description;
+ const gchar *icon;
GpAppletInfo *info;
+ name = _("Status Notifier Host");
description = _("Display all Status Notifier Items");
- info = gp_applet_info_new (_("Status Notifier Host"), description,
- "gnome-panel-notification-area");
+ icon = "gnome-panel-notification-area";
- return info;
-}
+ info = gp_applet_info_new (sn_applet_get_type, name, description, icon);
-static GType
-sn_get_applet_type (const gchar *applet)
-{
- return SN_TYPE_APPLET;
+ return info;
}
static const gchar *
@@ -71,7 +69,6 @@ void
gp_module_get_applet_vtable (GpAppletVTable *vtable)
{
*vtable = (GpAppletVTable) {
- sn_get_applet_info,
- sn_get_applet_type
+ sn_get_applet_info
};
}
diff --git a/modules/wncklet/wncklet-module.c b/modules/wncklet/wncklet-module.c
index 8e860b7..880c52b 100644
--- a/modules/wncklet/wncklet-module.c
+++ b/modules/wncklet/wncklet-module.c
@@ -29,6 +29,7 @@
static GpAppletInfo *
wncklet_get_applet_info (const gchar *applet)
{
+ GpGetAppletTypeFunc type_func;
const gchar *name;
const gchar *description;
const gchar *icon;
@@ -36,24 +37,28 @@ wncklet_get_applet_info (const gchar *applet)
if (g_strcmp0 (applet, "show-desktop") == 0)
{
+ type_func = show_desktop_applet_get_type;
name = _("Show Desktop");
description = _("Hide application windows and show the desktop");
icon = "user-desktop";
}
else if (g_strcmp0 (applet, "window-list") == 0)
{
+ type_func = window_list_applet_get_type;
name = _("Window List");
description = _("Switch between open windows using buttons");
icon = "gnome-panel-window-list";
}
else if (g_strcmp0 (applet, "window-menu") == 0)
{
+ type_func = window_menu_applet_get_type;
name = _("Window Selector");
description = _("Switch between open windows using a menu");
icon = "gnome-panel-window-menu";
}
else if (g_strcmp0 (applet, "workspace-switcher") == 0)
{
+ type_func = workspace_switcher_applet_get_type;
name = _("Workspace Switcher");
description = _("Switch between workspaces");
icon = "gnome-panel-workspace-switcher";
@@ -64,37 +69,13 @@ wncklet_get_applet_info (const gchar *applet)
return NULL;
}
- info = gp_applet_info_new (name, description, icon);
+ info = gp_applet_info_new (type_func, name, description, icon);
gp_applet_info_set_backends (info, "x11");
return info;
}
-static GType
-wncklet_get_applet_type (const gchar *applet)
-{
- if (g_strcmp0 (applet, "show-desktop") == 0)
- {
- return SHOW_DESKTOP_TYPE_APPLET;
- }
- else if (g_strcmp0 (applet, "window-list") == 0)
- {
- return WINDOW_LIST_TYPE_APPLET;
- }
- else if (g_strcmp0 (applet, "window-menu") == 0)
- {
- return WINDOW_MENU_TYPE_APPLET;
- }
- else if (g_strcmp0 (applet, "workspace-switcher") == 0)
- {
- return WORKSPACE_SWITCHER_TYPE_APPLET;
- }
-
- g_assert_not_reached ();
- return G_TYPE_NONE;
-}
-
static const gchar *
wncklet_get_applet_id_from_iid (const gchar *iid)
{
@@ -139,7 +120,6 @@ void
gp_module_get_applet_vtable (GpAppletVTable *vtable)
{
*vtable = (GpAppletVTable) {
- wncklet_get_applet_info,
- wncklet_get_applet_type
+ wncklet_get_applet_info
};
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]