diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2010-09-02 00:37:30 +0800 |
---|---|---|
committer | Philip Withnall <philip.withnall@collabora.co.uk> | 2010-09-02 18:09:18 +0800 |
commit | 3172fd7585eef696197237c9e0d7dbd910a7af9f (patch) | |
tree | a97d42a2f962ab332ec04370f593c03353ae1556 /libempathy-gtk/empathy-individual-menu.c | |
parent | a92e47dd31f74bcbbf50d6c2285b7d82bf82c4be (diff) | |
download | gsoc2013-empathy-3172fd7585eef696197237c9e0d7dbd910a7af9f.tar gsoc2013-empathy-3172fd7585eef696197237c9e0d7dbd910a7af9f.tar.gz gsoc2013-empathy-3172fd7585eef696197237c9e0d7dbd910a7af9f.tar.bz2 gsoc2013-empathy-3172fd7585eef696197237c9e0d7dbd910a7af9f.tar.lz gsoc2013-empathy-3172fd7585eef696197237c9e0d7dbd910a7af9f.tar.xz gsoc2013-empathy-3172fd7585eef696197237c9e0d7dbd910a7af9f.tar.zst gsoc2013-empathy-3172fd7585eef696197237c9e0d7dbd910a7af9f.zip |
Make EmpathyIndividualMenu a proper GObject, derived from GtkMenu
Diffstat (limited to 'libempathy-gtk/empathy-individual-menu.c')
-rw-r--r-- | libempathy-gtk/empathy-individual-menu.c | 155 |
1 files changed, 142 insertions, 13 deletions
diff --git a/libempathy-gtk/empathy-individual-menu.c b/libempathy-gtk/empathy-individual-menu.c index 69f0330f4..622d278ee 100644 --- a/libempathy-gtk/empathy-individual-menu.c +++ b/libempathy-gtk/empathy-individual-menu.c @@ -42,6 +42,7 @@ #include "empathy-images.h" #include "empathy-log-window.h" #include "empathy-contact-dialogs.h" +#include "empathy-gtk-enum-types.h" #include "empathy-individual-dialogs.h" #include "empathy-individual-edit-dialog.h" #include "empathy-individual-information-dialog.h" @@ -49,6 +50,20 @@ #include "empathy-share-my-desktop.h" #include "empathy-linking-dialog.h" +#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualMenu) + +typedef struct { + FolksIndividual *individual; /* owned */ + EmpathyIndividualFeatureFlags features; +} EmpathyIndividualMenuPriv; + +enum { + PROP_INDIVIDUAL = 1, + PROP_FEATURES, +}; + +G_DEFINE_TYPE (EmpathyIndividualMenu, empathy_individual_menu, GTK_TYPE_MENU); + static void individual_menu_add_personas (GtkMenuShell *menu, FolksIndividual *individual, @@ -173,21 +188,28 @@ individual_menu_add_personas (GtkMenuShell *menu, } } -GtkWidget * -empathy_individual_menu_new (FolksIndividual *individual, - EmpathyIndividualFeatureFlags features) +static void +empathy_individual_menu_init (EmpathyIndividualMenu *self) { - GtkWidget *menu; - GtkMenuShell *shell; - GtkWidget *item; + EmpathyIndividualMenuPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + EMPATHY_TYPE_INDIVIDUAL_MENU, EmpathyIndividualMenuPriv); - g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL); + self->priv = priv; +} - if (features == EMPATHY_INDIVIDUAL_FEATURE_NONE) - return NULL; +static void +constructed (GObject *object) +{ + EmpathyIndividualMenuPriv *priv = GET_PRIV (object); + GtkMenuShell *shell; + GtkWidget *item; + FolksIndividual *individual; + EmpathyIndividualFeatureFlags features; - menu = gtk_menu_new (); - shell = GTK_MENU_SHELL (menu); + /* Build the menu */ + shell = GTK_MENU_SHELL (object); + individual = priv->individual; + features = priv->features; /* Add Contact */ item = empathy_individual_add_menu_item_new (individual); @@ -247,7 +269,7 @@ empathy_individual_menu_new (FolksIndividual *individual, gtk_widget_show (item); /* Menu items to target specific contacts */ - individual_menu_add_personas (GTK_MENU_SHELL (menu), individual, features); + individual_menu_add_personas (GTK_MENU_SHELL (object), individual, features); /* Separator */ if (features & (EMPATHY_INDIVIDUAL_FEATURE_EDIT | @@ -291,8 +313,115 @@ empathy_individual_menu_new (FolksIndividual *individual, gtk_menu_shell_append (shell, item); gtk_widget_show (item); } +} + +static void +get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + EmpathyIndividualMenuPriv *priv; + + priv = GET_PRIV (object); + + switch (param_id) + { + case PROP_INDIVIDUAL: + g_value_set_object (value, priv->individual); + break; + case PROP_FEATURES: + g_value_set_flags (value, priv->features); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + } +} - return menu; +static void +set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + EmpathyIndividualMenuPriv *priv; + + priv = GET_PRIV (object); + + switch (param_id) + { + case PROP_INDIVIDUAL: + priv->individual = g_value_dup_object (value); + break; + case PROP_FEATURES: + priv->features = g_value_get_flags (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + } +} + +static void +dispose (GObject *object) +{ + EmpathyIndividualMenuPriv *priv = GET_PRIV (object); + + tp_clear_object (&priv->individual); + + G_OBJECT_CLASS (empathy_individual_menu_parent_class)->dispose (object); +} + +static void +empathy_individual_menu_class_init (EmpathyIndividualMenuClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructed = constructed; + object_class->get_property = get_property; + object_class->set_property = set_property; + object_class->dispose = dispose; + + /** + * EmpathyIndividualMenu:individual: + * + * The #FolksIndividual the menu is for. + */ + g_object_class_install_property (object_class, PROP_INDIVIDUAL, + g_param_spec_object ("individual", + "Individual", + "The #FolksIndividual the menu is for.", + FOLKS_TYPE_INDIVIDUAL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + + /** + * EmpathyIndividualMenu:features: + * + * A set of feature flags controlling which entries are shown. + */ + g_object_class_install_property (object_class, PROP_FEATURES, + g_param_spec_flags ("features", + "Features", + "A set of feature flags controlling which entries are shown.", + EMPATHY_TYPE_INDIVIDUAL_FEATURE_FLAGS, + EMPATHY_INDIVIDUAL_FEATURE_NONE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); + + g_type_class_add_private (object_class, sizeof (EmpathyIndividualMenuPriv)); +} + +GtkWidget * +empathy_individual_menu_new (FolksIndividual *individual, + EmpathyIndividualFeatureFlags features) +{ + g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL); + g_return_val_if_fail (features != EMPATHY_INDIVIDUAL_FEATURE_NONE, NULL); + + return g_object_new (EMPATHY_TYPE_INDIVIDUAL_MENU, + "individual", individual, + "features", features, + NULL); } static void |