aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-07-25 15:53:36 -0500
committerCharles Kerr <charles.kerr@canonical.com>2013-07-25 15:53:36 -0500
commit124564dd1632b5a05a9665bae2d6c6afa7d9eb46 (patch)
treea9d1c01648f7be1eb7078da3b711896eb997ff54
parent8a9b4b895d4cf4930ff6dd6865639397aed05c54 (diff)
downloadayatana-ido-124564dd1632b5a05a9665bae2d6c6afa7d9eb46.tar.gz
ayatana-ido-124564dd1632b5a05a9665bae2d6c6afa7d9eb46.tar.bz2
ayatana-ido-124564dd1632b5a05a9665bae2d6c6afa7d9eb46.zip
subclass IdoLocationMenuItem from IdoBasicMenuItem
-rw-r--r--example/menus.c2
-rw-r--r--src/idolocationmenuitem.c89
-rw-r--r--src/idolocationmenuitem.h8
3 files changed, 13 insertions, 86 deletions
diff --git a/example/menus.c b/example/menus.c
index 66bc2f2..ab070ac 100644
--- a/example/menus.c
+++ b/example/menus.c
@@ -138,7 +138,7 @@ main (int argc, char *argv[])
for (i=0; i<G_N_ELEMENTS(locations); i++)
{
GtkWidget * w = g_object_new (IDO_LOCATION_MENU_ITEM_TYPE,
- "name", locations[i].name,
+ "text", locations[i].name,
"timezone", locations[i].timezone,
"format", locations[i].format,
NULL);
diff --git a/src/idolocationmenuitem.c b/src/idolocationmenuitem.c
index 5c4f0e6..df7c210 100644
--- a/src/idolocationmenuitem.c
+++ b/src/idolocationmenuitem.c
@@ -31,7 +31,6 @@
enum
{
PROP_0,
- PROP_NAME,
PROP_TIMEZONE,
PROP_FORMAT,
PROP_LAST
@@ -41,19 +40,15 @@ static GParamSpec *properties[PROP_LAST];
struct _IdoLocationMenuItemPrivate
{
- char * name;
char * timezone;
char * format;
guint timestamp_timer;
-
- GtkWidget * name_label;
- GtkWidget * timestamp_label;
};
typedef IdoLocationMenuItemPrivate priv_t;
-G_DEFINE_TYPE (IdoLocationMenuItem, ido_location_menu_item, GTK_TYPE_MENU_ITEM);
+G_DEFINE_TYPE (IdoLocationMenuItem, ido_location_menu_item, IDO_TYPE_BASIC_MENU_ITEM);
/***
**** Timestamp Label
@@ -62,30 +57,32 @@ G_DEFINE_TYPE (IdoLocationMenuItem, ido_location_menu_item, GTK_TYPE_MENU_ITEM);
static void
update_timestamp_label (IdoLocationMenuItem * self)
{
+ char * str;
priv_t * p = self->priv;
if (p->format && *p->format)
{
GTimeZone * tz;
GDateTime * now;
- char * str;
tz = g_time_zone_new (p->timezone);
if (tz == NULL)
tz = g_time_zone_new_local ();
now = g_date_time_new_now (tz);
- str = g_date_time_format (now, p->format);
- gtk_label_set_text (GTK_LABEL(p->timestamp_label), str);
+ str = g_date_time_format (now, p->format);
- g_free (str);
g_date_time_unref (now);
g_time_zone_unref (tz);
}
else
{
- gtk_label_set_text (GTK_LABEL(p->timestamp_label), "");
+ str = NULL;
}
+
+ ido_basic_menu_item_set_secondary_text (IDO_BASIC_MENU_ITEM(self), str);
+
+ g_free (str);
}
static void
@@ -181,10 +178,6 @@ my_get_property (GObject * o,
switch (property_id)
{
- case PROP_NAME:
- g_value_set_string (value, p->name);
- break;
-
case PROP_TIMEZONE:
g_value_set_string (value, p->timezone);
break;
@@ -209,10 +202,6 @@ my_set_property (GObject * o,
switch (property_id)
{
- case PROP_NAME:
- ido_location_menu_item_set_name (self, g_value_get_string (value));
- break;
-
case PROP_TIMEZONE:
ido_location_menu_item_set_timezone (self, g_value_get_string (value));
break;
@@ -242,7 +231,6 @@ my_finalize (GObject * object)
priv_t * p = self->priv;
g_free (p->format);
- g_free (p->name);
g_free (p->timezone);
G_OBJECT_CLASS (ido_location_menu_item_parent_class)->finalize (object);
@@ -269,13 +257,6 @@ ido_location_menu_item_class_init (IdoLocationMenuItemClass *klass)
| G_PARAM_READWRITE
| G_PARAM_STATIC_STRINGS;
- properties[PROP_NAME] = g_param_spec_string (
- "name",
- "The location's name",
- "The name to display; eg, 'Oklahoma City'",
- "Location",
- prop_flags);
-
properties[PROP_TIMEZONE] = g_param_spec_string (
"timezone",
"timezone identifier",
@@ -296,43 +277,11 @@ ido_location_menu_item_class_init (IdoLocationMenuItemClass *klass)
static void
ido_location_menu_item_init (IdoLocationMenuItem *self)
{
- priv_t * p;
- GtkWidget * w;
- GtkGrid * grid;
-
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
IDO_LOCATION_MENU_ITEM_TYPE,
IdoLocationMenuItemPrivate);
-
- p = self->priv;
-
- p->name_label = gtk_label_new (NULL);
- gtk_misc_set_alignment (GTK_MISC(p->name_label), 0.0, 0.5);
-
- p->timestamp_label = gtk_label_new (NULL);
- gtk_misc_set_alignment (GTK_MISC(p->timestamp_label), 1.0, 0.5);
-
- w = gtk_grid_new ();
- grid = GTK_GRID (w);
- gtk_grid_attach (grid, p->name_label, 0, 0, 1, 1);
- gtk_grid_attach (grid, p->timestamp_label, 1, 0, 1, 1);
- g_object_set (p->name_label,
- "halign", GTK_ALIGN_START,
- "hexpand", TRUE,
- "margin-right", 6,
- "valign", GTK_ALIGN_CENTER,
- NULL);
- g_object_set (p->timestamp_label,
- "halign", GTK_ALIGN_END,
- "hexpand", FALSE,
- "valign", GTK_ALIGN_CENTER,
- NULL);
-
- gtk_widget_show_all (w);
- gtk_container_add (GTK_CONTAINER (self), w);
}
-
/***
**** Public API
***/
@@ -345,26 +294,6 @@ ido_location_menu_item_new (void)
}
/**
- * ido_location_menu_item_set_name:
- * @name: human-readable name, such as a city (eg: "Oklahoma City")
- *
- * Sets this location's name, for display in the menuitem's primary label.
- */
-void
-ido_location_menu_item_set_name (IdoLocationMenuItem * self,
- const char * name)
-{
- priv_t * p;
-
- g_return_if_fail (IDO_IS_LOCATION_MENU_ITEM (self));
- p = self->priv;
-
- g_free (p->name);
- p->name = g_strdup (name);
- gtk_label_set_text (GTK_LABEL(p->name_label), p->name);
-}
-
-/**
* ido_location_menu_item_set_timezone:
* @timezone: timezone identifier (eg: "America/Chicago")
*
@@ -436,7 +365,7 @@ ido_location_menu_item_new_from_model (GMenuItem * menu_item,
if (g_menu_item_get_attribute (menu_item, "label", "s", &str))
{
- GParameter p = { "name", G_VALUE_INIT };
+ GParameter p = { "text", G_VALUE_INIT };
g_value_init (&p.value, G_TYPE_STRING);
g_value_take_string (&p.value, str);
parameters[n++] = p;
diff --git a/src/idolocationmenuitem.h b/src/idolocationmenuitem.h
index 08a97af..53fe063 100644
--- a/src/idolocationmenuitem.h
+++ b/src/idolocationmenuitem.h
@@ -21,6 +21,7 @@
#define __IDO_LOCATION_MENU_ITEM_H__
#include <gtk/gtk.h>
+#include "idobasicmenuitem.h"
G_BEGIN_DECLS
@@ -34,7 +35,7 @@ typedef struct _IdoLocationMenuItemPrivate IdoLocationMenuItemPrivate;
struct _IdoLocationMenuItemClass
{
- GtkMenuItemClass parent_class;
+ IdoBasicMenuItemClass parent_class;
};
/**
@@ -46,7 +47,7 @@ struct _IdoLocationMenuItemClass
struct _IdoLocationMenuItem
{
/*< private >*/
- GtkMenuItem parent;
+ IdoBasicMenuItem parent;
IdoLocationMenuItemPrivate * priv;
};
@@ -58,9 +59,6 @@ GtkWidget * ido_location_menu_item_new (void);
GtkMenuItem * ido_location_menu_item_new_from_model (GMenuItem * menuitem,
GActionGroup * actions);
-void ido_location_menu_item_set_name (IdoLocationMenuItem * menuitem,
- const char * name);
-
void ido_location_menu_item_set_timezone (IdoLocationMenuItem * menuitem,
const char * timezone);