From 9434c8a9f162cab1f525ed892a133a688bb3e223 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 4 Jan 2010 22:38:47 -0600 Subject: Building a very basic indicator. --- .bzrignore | 2 ++ src/Makefile.am | 13 +++++++++++++ src/indicator-datetime.c | 0 3 files changed, 15 insertions(+) create mode 100644 src/indicator-datetime.c diff --git a/.bzrignore b/.bzrignore index 41f8025..89bbfee 100644 --- a/.bzrignore +++ b/.bzrignore @@ -1,2 +1,4 @@ compile m4 +src/libdatetime.la +src/libdatetime_la-indicator-datetime.lo diff --git a/src/Makefile.am b/src/Makefile.am index e69de29..390f89a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -0,0 +1,13 @@ + +datetimelibdir = $(INDICATORDIR) +datetimelib_LTLIBRARIES = libdatetime.la +libdatetime_la_SOURCES = \ + indicator-datetime.c +libdatetime_la_CFLAGS = \ + $(INDICATOR_CFLAGS) \ + -Wall -Werror +libdatetime_la_LIBADD = \ + $(INDICATOR_LIBS) +libdatetime_la_LDFLAGS = \ + -module \ + -avoid-version diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 7c0f72c69aeacbfe8bd06f63ef0b0af6f61f4d82 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 4 Jan 2010 22:52:08 -0600 Subject: The base object for the indicator --- src/indicator-datetime.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index e69de29..9cb78dc 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -0,0 +1,85 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* GStuff */ +#include +#include + +/* Indicator Stuff */ +#include +#include + + +#define INDICATOR_DATETIME_TYPE (indicator_datetime_get_type ()) +#define INDICATOR_DATETIME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_DATETIME_TYPE, IndicatorDatetime)) +#define INDICATOR_DATETIME_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_DATETIME_TYPE, IndicatorDatetimeClass)) +#define IS_INDICATOR_DATETIME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_DATETIME_TYPE)) +#define IS_INDICATOR_DATETIME_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_DATETIME_TYPE)) +#define INDICATOR_DATETIME_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_DATETIME_TYPE, IndicatorDatetimeClass)) + +typedef struct _IndicatorDatetime IndicatorDatetime; +typedef struct _IndicatorDatetimeClass IndicatorDatetimeClass; +typedef struct _IndicatorDatetimePrivate IndicatorDatetimePrivate; + +struct _IndicatorDatetimeClass { + IndicatorObjectClass parent_class; +}; + +struct _IndicatorDatetime { + IndicatorObject parent; + IndicatorDatetimePrivate * priv; +}; + +struct _IndicatorDatetimePrivate { + int dummy; +}; + +#define INDICATOR_DATETIME_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_DATETIME_TYPE, IndicatorDatetimePrivate)) + +GType indicator_datetime_get_type (void); + +static void indicator_datetime_class_init (IndicatorDatetimeClass *klass); +static void indicator_datetime_init (IndicatorDatetime *self); +static void indicator_datetime_dispose (GObject *object); +static void indicator_datetime_finalize (GObject *object); + +G_DEFINE_TYPE (IndicatorDatetime, indicator_datetime, INDICATOR_OBJECT_TYPE); + +static void +indicator_datetime_class_init (IndicatorDatetimeClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (IndicatorDatetimePrivate)); + + object_class->dispose = indicator_datetime_dispose; + object_class->finalize = indicator_datetime_finalize; + + return; +} + +static void +indicator_datetime_init (IndicatorDatetime *self) +{ + self->priv = INDICATOR_DATETIME_GET_PRIVATE(self); + + return; +} + +static void +indicator_datetime_dispose (GObject *object) +{ + + G_OBJECT_CLASS (indicator_datetime_parent_class)->dispose (object); + return; +} + +static void +indicator_datetime_finalize (GObject *object) +{ + + G_OBJECT_CLASS (indicator_datetime_parent_class)->finalize (object); + return; +} -- cgit v1.2.3 From 0479341e4f14f5ee564cd1c7605e893510bfe3fe Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 4 Jan 2010 22:54:29 -0600 Subject: Adding in the indicator defines --- src/indicator-datetime.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 9cb78dc..dc86c1c 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -45,6 +45,10 @@ static void indicator_datetime_init (IndicatorDatetime *self); static void indicator_datetime_dispose (GObject *object); static void indicator_datetime_finalize (GObject *object); +/* Indicator Module Config */ +INDICATOR_SET_VERSION +INDICATOR_SET_TYPE(INDICATOR_DATETIME_TYPE) + G_DEFINE_TYPE (IndicatorDatetime, indicator_datetime, INDICATOR_OBJECT_TYPE); static void -- cgit v1.2.3 From 881335a532a8e82191c02df22e661fefbd0d47a3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 4 Jan 2010 22:58:24 -0600 Subject: Linking in the get_label function --- src/indicator-datetime.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index dc86c1c..c022a99 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -44,6 +44,7 @@ static void indicator_datetime_class_init (IndicatorDatetimeClass *klass); static void indicator_datetime_init (IndicatorDatetime *self); static void indicator_datetime_dispose (GObject *object); static void indicator_datetime_finalize (GObject *object); +static GtkLabel * get_label (IndicatorObject * io); /* Indicator Module Config */ INDICATOR_SET_VERSION @@ -61,6 +62,10 @@ indicator_datetime_class_init (IndicatorDatetimeClass *klass) object_class->dispose = indicator_datetime_dispose; object_class->finalize = indicator_datetime_finalize; + IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass); + + io_class->get_label = get_label; + return; } @@ -87,3 +92,11 @@ indicator_datetime_finalize (GObject *object) G_OBJECT_CLASS (indicator_datetime_parent_class)->finalize (object); return; } + +static GtkLabel * +get_label (IndicatorObject * io) +{ + + + return NULL; +} -- cgit v1.2.3 From 81c0869a03e3429685eed1a5598e7d0ea6975bcf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 4 Jan 2010 23:14:04 -0600 Subject: Making a label --- src/indicator-datetime.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index c022a99..16a792c 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -32,7 +32,7 @@ struct _IndicatorDatetime { }; struct _IndicatorDatetimePrivate { - int dummy; + GtkLabel * label; }; #define INDICATOR_DATETIME_GET_PRIVATE(o) \ @@ -96,7 +96,12 @@ indicator_datetime_finalize (GObject *object) static GtkLabel * get_label (IndicatorObject * io) { + IndicatorDatetime * self = INDICATOR_DATETIME(io); + if (self->priv->label == NULL) { + self->priv->label = GTK_LABEL(gtk_label_new("Time")); + gtk_widget_show(GTK_WIDGET(self->priv->label)); + } - return NULL; + return self->priv->label; } -- cgit v1.2.3 From 1b1e09892912bec1d76d91ae4b7de42f28c186fd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 5 Jan 2010 09:24:36 -0600 Subject: Updating the label with the time --- src/indicator-datetime.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 16a792c..253c86a 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -5,6 +5,7 @@ /* GStuff */ #include #include +#include /* Indicator Stuff */ #include @@ -93,13 +94,42 @@ indicator_datetime_finalize (GObject *object) return; } +static void +update_label (GtkLabel * label) +{ + if (label == NULL) return; + + gchar longstr[128]; + time_t t; + struct tm *ltime; + + t = time(NULL); + ltime = localtime(&t); + if (ltime == NULL) { + g_debug("Error getting local time"); + gtk_label_set_label(label, _("Error getting time")); + return; + } + + strftime(longstr, 128, "%I:%M %p", ltime); + + gchar * utf8 = g_locale_to_utf8(longstr, -1, NULL, NULL, NULL); + gtk_label_set_label(label, utf8); + g_free(utf8); + + return; +} + static GtkLabel * get_label (IndicatorObject * io) { IndicatorDatetime * self = INDICATOR_DATETIME(io); + /* If there's not a label, we'll build ourselves one */ if (self->priv->label == NULL) { self->priv->label = GTK_LABEL(gtk_label_new("Time")); + g_object_ref(G_OBJECT(self->priv->label)); + update_label(self->priv->label); gtk_widget_show(GTK_WIDGET(self->priv->label)); } -- cgit v1.2.3 From e154d9e960566730478182bae00405c8f00d4f32 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 5 Jan 2010 15:27:28 -0600 Subject: Adding comments. --- src/indicator-datetime.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 253c86a..1112536 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -94,6 +94,7 @@ indicator_datetime_finalize (GObject *object) return; } +/* Updates the label to be the current time. */ static void update_label (GtkLabel * label) { @@ -120,6 +121,8 @@ update_label (GtkLabel * label) return; } +/* Grabs the label. Creates it if it doesn't + exist already */ static GtkLabel * get_label (IndicatorObject * io) { -- cgit v1.2.3 From a324b57d5d79f7a081fc4d8ad0fa2f9d36e72beb Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 5 Jan 2010 15:41:53 -0600 Subject: Adding in a timer to update --- src/indicator-datetime.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 1112536..1dbd6ce 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -34,6 +34,7 @@ struct _IndicatorDatetime { struct _IndicatorDatetimePrivate { GtkLabel * label; + guint timer; }; #define INDICATOR_DATETIME_GET_PRIVATE(o) \ @@ -121,6 +122,23 @@ update_label (GtkLabel * label) return; } +/* Runs every minute and updates the time */ +gboolean +minute_timer_func (gpointer user_data) +{ + IndicatorDatetime * self = INDICATOR_DATETIME(user_data); + + if (self->priv->label != NULL) { + update_label(self->priv->label); + return TRUE; + } else { + self->priv->timer = 0; + return FALSE; + } + + return FALSE; +} + /* Grabs the label. Creates it if it doesn't exist already */ static GtkLabel * @@ -135,6 +153,10 @@ get_label (IndicatorObject * io) update_label(self->priv->label); gtk_widget_show(GTK_WIDGET(self->priv->label)); } + + if (self->priv->timer == 0) { + self->priv->timer = g_timeout_add_seconds(60, minute_timer_func, self); + } return self->priv->label; } -- cgit v1.2.3 From 51208eb3ccbaa0388a340b74191e3d0890fd166c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 5 Jan 2010 15:44:33 -0600 Subject: Initalizing and disposing of the label and timer --- src/indicator-datetime.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 1dbd6ce..3e16e07 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -76,12 +76,26 @@ indicator_datetime_init (IndicatorDatetime *self) { self->priv = INDICATOR_DATETIME_GET_PRIVATE(self); + self->priv->label = NULL; + self->priv->timer = 0; + return; } static void indicator_datetime_dispose (GObject *object) { + IndicatorDatetime * self = INDICATOR_DATETIME(object); + + if (self->priv->label != NULL) { + g_object_unref(self->priv->label); + self->priv->label = NULL; + } + + if (self->priv->timer != 0) { + g_source_remove(self->priv->timer); + self->priv->timer = 0; + } G_OBJECT_CLASS (indicator_datetime_parent_class)->dispose (object); return; -- cgit v1.2.3 From 5c079eafcd0d20554dcdd7a6f39ec600e04c8aac Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 6 Jan 2010 10:00:01 -0600 Subject: Building a simple menu. --- src/indicator-datetime.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 3e16e07..9b4bec4 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -47,6 +47,7 @@ static void indicator_datetime_init (IndicatorDatetime *self); static void indicator_datetime_dispose (GObject *object); static void indicator_datetime_finalize (GObject *object); static GtkLabel * get_label (IndicatorObject * io); +static GtkMenu * get_menu (IndicatorObject * io); /* Indicator Module Config */ INDICATOR_SET_VERSION @@ -67,6 +68,7 @@ indicator_datetime_class_init (IndicatorDatetimeClass *klass) IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass); io_class->get_label = get_label; + io_class->get_menu = get_menu; return; } @@ -174,3 +176,21 @@ get_label (IndicatorObject * io) return self->priv->label; } + +/* Build a dummy menu for now */ +static GtkMenu * +get_menu (IndicatorObject * io) +{ + GtkWidget * menu = NULL; + GtkWidget * item = NULL; + + menu = gtk_menu_new(); + + item = gtk_menu_item_new_with_label("No menu yet."); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); + gtk_widget_show(item); + + gtk_widget_show(menu); + + return GTK_MENU(menu); +} -- cgit v1.2.3 From bee422b477bf7148a538ca065cbfe9e9c0e3167e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 6 Jan 2010 11:12:09 -0600 Subject: releasing version 0.0.1~dev-0ubuntu1~ppa2~indicator1 --- debian/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 5b16951..7a55eb7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,9 +1,9 @@ -indicator-datetime (0.0.1~dev-0ubuntu1~ppa2~indicator1) UNRELEASED; urgency=low +indicator-datetime (0.0.1~dev-0ubuntu1~ppa2~indicator1) karmic; urgency=low * Upstream merge * Adding in an indicator - -- Ted Gould Wed, 06 Jan 2010 11:10:49 -0600 + -- Ted Gould Wed, 06 Jan 2010 11:12:02 -0600 indicator-datetime (0.0.1~dev-0ubuntu1~ppa1) karmic; urgency=low -- cgit v1.2.3