aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-01-06 11:11:21 -0600
committerTed Gould <ted@gould.cx>2010-01-06 11:11:21 -0600
commit9709b21b472e4c6ed0a4d1ed843af21b3b47e255 (patch)
tree27bd585876cd510ceea305f48893919198e8099b
parentc7ec96e969401f0fb9e27d355e04a7db6a93e6ae (diff)
parent5c079eafcd0d20554dcdd7a6f39ec600e04c8aac (diff)
downloadayatana-indicator-datetime-9709b21b472e4c6ed0a4d1ed843af21b3b47e255.tar.gz
ayatana-indicator-datetime-9709b21b472e4c6ed0a4d1ed843af21b3b47e255.tar.bz2
ayatana-indicator-datetime-9709b21b472e4c6ed0a4d1ed843af21b3b47e255.zip
* Upstream merge
* Adding in an indicator
-rw-r--r--.bzrignore2
-rw-r--r--debian/changelog7
-rw-r--r--src/Makefile.am13
-rw-r--r--src/indicator-datetime.c196
4 files changed, 218 insertions, 0 deletions
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/debian/changelog b/debian/changelog
index 01714ee..5b16951 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+indicator-datetime (0.0.1~dev-0ubuntu1~ppa2~indicator1) UNRELEASED; urgency=low
+
+ * Upstream merge
+ * Adding in an indicator
+
+ -- Ted Gould <ted@ubuntu.com> Wed, 06 Jan 2010 11:10:49 -0600
+
indicator-datetime (0.0.1~dev-0ubuntu1~ppa1) karmic; urgency=low
* Initial release.
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..9b4bec4
--- /dev/null
+++ b/src/indicator-datetime.c
@@ -0,0 +1,196 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* GStuff */
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gi18n.h>
+
+/* Indicator Stuff */
+#include <libindicator/indicator.h>
+#include <libindicator/indicator-object.h>
+
+
+#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 {
+ GtkLabel * label;
+ guint timer;
+};
+
+#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);
+static GtkLabel * get_label (IndicatorObject * io);
+static GtkMenu * get_menu (IndicatorObject * io);
+
+/* Indicator Module Config */
+INDICATOR_SET_VERSION
+INDICATOR_SET_TYPE(INDICATOR_DATETIME_TYPE)
+
+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;
+
+ IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass);
+
+ io_class->get_label = get_label;
+ io_class->get_menu = get_menu;
+
+ return;
+}
+
+static void
+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;
+}
+
+static void
+indicator_datetime_finalize (GObject *object)
+{
+
+ G_OBJECT_CLASS (indicator_datetime_parent_class)->finalize (object);
+ return;
+}
+
+/* Updates the label to be the current time. */
+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;
+}
+
+/* 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 *
+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));
+ }
+
+ if (self->priv->timer == 0) {
+ self->priv->timer = g_timeout_add_seconds(60, minute_timer_func, self);
+ }
+
+ 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);
+}