aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-05-25 11:25:37 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-05-25 11:25:37 +0200
commit982bf2ed9cec576b599f0f87f3201675757eda05 (patch)
tree9480ca69c9310651ed6fb7cc0a8ed0df0e84b78a /src
parent2c113b49296184a057bd64e89d2e3240c8262f44 (diff)
downloadayatana-indicator-messages-982bf2ed9cec576b599f0f87f3201675757eda05.tar.gz
ayatana-indicator-messages-982bf2ed9cec576b599f0f87f3201675757eda05.tar.bz2
ayatana-indicator-messages-982bf2ed9cec576b599f0f87f3201675757eda05.zip
appmenuitem: make app-info a construct-only property
Diffstat (limited to 'src')
-rw-r--r--src/app-menu-item.c103
-rw-r--r--src/app-menu-item.h1
2 files changed, 90 insertions, 14 deletions
diff --git a/src/app-menu-item.c b/src/app-menu-item.c
index b18b7c9..7638eb5 100644
--- a/src/app-menu-item.c
+++ b/src/app-menu-item.c
@@ -46,13 +46,31 @@ struct _AppMenuItemPrivate
#define APP_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), APP_MENU_ITEM_TYPE, AppMenuItemPrivate))
+enum {
+ PROP_0,
+ PROP_APPINFO,
+ NUM_PROPERTIES
+};
+
+static GParamSpec *properties[NUM_PROPERTIES];
+
/* Prototypes */
-static void app_menu_item_class_init (AppMenuItemClass *klass);
-static void app_menu_item_init (AppMenuItem *self);
-static void app_menu_item_dispose (GObject *object);
-static void activate_cb (GSimpleAction *action,
- GVariant *param,
- gpointer userdata);
+static void app_menu_item_class_init (AppMenuItemClass *klass);
+static void app_menu_item_init (AppMenuItem *self);
+static void app_menu_item_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void app_menu_item_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void app_menu_item_dispose (GObject *object);
+static void activate_cb (GSimpleAction *action,
+ GVariant *param,
+ gpointer userdata);
+static void app_menu_item_set_app_info (AppMenuItem *self,
+ GDesktopAppInfo *appinfo);
/* GObject Boilerplate */
G_DEFINE_TYPE (AppMenuItem, app_menu_item, G_TYPE_OBJECT);
@@ -64,7 +82,17 @@ app_menu_item_class_init (AppMenuItemClass *klass)
g_type_class_add_private (klass, sizeof (AppMenuItemPrivate));
+ object_class->get_property = app_menu_item_get_property;
+ object_class->set_property = app_menu_item_set_property;
object_class->dispose = app_menu_item_dispose;
+
+ properties[PROP_APPINFO] = g_param_spec_object ("app-info",
+ "AppInfo",
+ "The GAppInfo for the app that this menu represents",
+ G_TYPE_APP_INFO,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+ g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
}
static void
@@ -83,6 +111,43 @@ app_menu_item_init (AppMenuItem *self)
}
static void
+app_menu_item_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ AppMenuItem *self = APP_MENU_ITEM (object);
+
+ switch (property_id)
+ {
+ case PROP_APPINFO:
+ g_value_set_object (value, app_menu_item_get_app_info (self));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+app_menu_item_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ AppMenuItem *self = APP_MENU_ITEM (object);
+
+ switch (property_id)
+ {
+ case PROP_APPINFO:
+ app_menu_item_set_app_info (self, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+static void
app_menu_item_dispose (GObject *object)
{
AppMenuItem * self = APP_MENU_ITEM(object);
@@ -123,8 +188,8 @@ nick_activate_cb (GSimpleAction *action,
}
static void
-app_menu_item_set_appinfo (AppMenuItem *self,
- GDesktopAppInfo *appinfo)
+app_menu_item_set_app_info (AppMenuItem *self,
+ GDesktopAppInfo *appinfo)
{
AppMenuItemPrivate *priv = APP_MENU_ITEM_GET_PRIVATE (self);
GSimpleAction *launch;
@@ -133,9 +198,13 @@ app_menu_item_set_appinfo (AppMenuItem *self,
gchar *iconstr = NULL;
gchar *label;
- g_return_if_fail (appinfo != NULL);
+ g_return_if_fail (priv->appinfo == NULL);
+
+ if (appinfo == NULL) {
+ g_warning ("appinfo must not be NULL");
+ return;
+ }
- g_clear_object (&priv->appinfo);
priv->appinfo = g_object_ref (appinfo);
icon = g_app_info_get_icon (G_APP_INFO(priv->appinfo));
@@ -185,10 +254,9 @@ app_menu_item_set_appinfo (AppMenuItem *self,
AppMenuItem *
app_menu_item_new (GDesktopAppInfo *appinfo)
{
- AppMenuItem *self = g_object_new(APP_MENU_ITEM_TYPE, NULL);
- if (appinfo)
- app_menu_item_set_appinfo (self, appinfo);
- return self;
+ return g_object_new (APP_MENU_ITEM_TYPE,
+ "app-info", appinfo,
+ NULL);
}
static void
@@ -245,3 +313,10 @@ app_menu_item_get_menu (AppMenuItem *appitem)
return G_MENU_MODEL (priv->menu);
}
+GAppInfo *
+app_menu_item_get_app_info (AppMenuItem *appitem)
+{
+ AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(appitem);
+ return G_APP_INFO (priv->appinfo);
+}
+
diff --git a/src/app-menu-item.h b/src/app-menu-item.h
index cec5bb0..1fb2762 100644
--- a/src/app-menu-item.h
+++ b/src/app-menu-item.h
@@ -50,6 +50,7 @@ guint app_menu_item_get_count (AppMenuItem * appitem);
const gchar * app_menu_item_get_name (AppMenuItem * appitem);
const gchar * app_menu_item_get_desktop (AppMenuItem * appitem);
GMenuModel * app_menu_item_get_menu (AppMenuItem *appitem);
+GAppInfo * app_menu_item_get_app_info (AppMenuItem *appitem);
G_END_DECLS