Commit d7538c85 authored by Jonny Lamb's avatar Jonny Lamb
Browse files

clocks: use GnomeWallClock to give time change updates

Use this to stop showing static times for both clocks.
parent 4352192c
......@@ -8,8 +8,13 @@
#include "clock.h"
#define GNOME_DESKTOP_USE_UNSTABLE_API
#include <libgnome-desktop/gnome-wall-clock.h>
struct WestonGtkClockPrivate {
GtkWidget *label;
GnomeWallClock *wall_clock;
};
G_DEFINE_TYPE(WestonGtkClock, weston_gtk_clock, GTK_TYPE_WINDOW)
......@@ -22,6 +27,25 @@ weston_gtk_clock_init (WestonGtkClock *self)
WestonGtkClockPrivate);
}
static void
wall_clock_notify_cb (GnomeWallClock *wall_clock,
GParamSpec *pspec,
WestonGtkClock *self)
{
GDateTime *datetime;
gchar *str;
datetime = g_date_time_new_now_local ();
str = g_date_time_format (datetime,
"<span font=\"Droid Sans 32\">%H:%M</span>\n"
"<span font=\"Droid Sans 12\">%d/%m/%Y</span>");
gtk_label_set_markup (GTK_LABEL (self->priv->label), str);
g_free (str);
g_date_time_unref (datetime);
}
static void
weston_gtk_clock_constructed (GObject *object)
{
......@@ -29,6 +53,10 @@ weston_gtk_clock_constructed (GObject *object)
G_OBJECT_CLASS (weston_gtk_clock_parent_class)->constructed (object);
self->priv->wall_clock = g_object_new (GNOME_TYPE_WALL_CLOCK, NULL);
g_signal_connect (self->priv->wall_clock, "notify::clock",
G_CALLBACK (wall_clock_notify_cb), self);
gtk_window_set_title (GTK_WINDOW (self), "gtk shell");
gtk_window_set_decorated (GTK_WINDOW (self), FALSE);
gtk_widget_realize (GTK_WIDGET (self));
......@@ -38,11 +66,10 @@ weston_gtk_clock_constructed (GObject *object)
"wgs-clock");
self->priv->label = gtk_label_new ("");
gtk_label_set_markup (GTK_LABEL (self->priv->label),
"<span font=\"Droid Sans 32\">11:47</span>\n"
"<span font=\"Droid Sans 12\">13/02/2014</span>");
gtk_label_set_justify (GTK_LABEL (self->priv->label), GTK_JUSTIFY_CENTER);
gtk_container_add (GTK_CONTAINER (self), self->priv->label);
wall_clock_notify_cb (self->priv->wall_clock, NULL, self);
}
static void
......@@ -50,6 +77,10 @@ weston_gtk_clock_dispose (GObject *object)
{
WestonGtkClock *self = WESTON_GTK_CLOCK (object);
if (self->priv->wall_clock)
g_object_unref (self->priv->wall_clock);
self->priv->wall_clock = NULL;
G_OBJECT_CLASS (weston_gtk_clock_parent_class)->dispose (object);
}
......
......@@ -8,10 +8,15 @@
#include "vertical-clock.h"
#define GNOME_DESKTOP_USE_UNSTABLE_API
#include <libgnome-desktop/gnome-wall-clock.h>
#include "panel.h"
struct WestonGtkVerticalClockPrivate {
GtkWidget *label;
GnomeWallClock *wall_clock;
};
G_DEFINE_TYPE(WestonGtkVerticalClock, weston_gtk_vertical_clock, GTK_TYPE_BOX)
......@@ -29,6 +34,26 @@ weston_gtk_vertical_clock_init (WestonGtkVerticalClock *self)
WestonGtkVerticalClockPrivate);
}
static void
wall_clock_notify_cb (GnomeWallClock *wall_clock,
GParamSpec *pspec,
WestonGtkVerticalClock *self)
{
GDateTime *datetime;
gchar *str;
datetime = g_date_time_new_now_local ();
str = g_date_time_format (datetime,
"<span font=\"Droid Sans 12\">%H\n"
":\n"
"%M</span>");
gtk_label_set_markup (GTK_LABEL (self->priv->label), str);
g_free (str);
g_date_time_unref (datetime);
}
static void
weston_gtk_vertical_clock_constructed (GObject *object)
{
......@@ -38,6 +63,10 @@ weston_gtk_vertical_clock_constructed (GObject *object)
G_OBJECT_CLASS (weston_gtk_vertical_clock_parent_class)->constructed (object);
self->priv->wall_clock = g_object_new (GNOME_TYPE_WALL_CLOCK, NULL);
g_signal_connect (self->priv->wall_clock, "notify::clock",
G_CALLBACK (wall_clock_notify_cb), self);
gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_HORIZONTAL);
/* a label just to pad things out to the correct width */
......@@ -51,16 +80,14 @@ weston_gtk_vertical_clock_constructed (GObject *object)
/* the actual clock label */
self->priv->label = gtk_label_new ("");
gtk_label_set_markup (GTK_LABEL (self->priv->label),
"<span font=\"Droid Sans 12\">11\n"
":\n"
"47</span>");
gtk_style_context_add_class (gtk_widget_get_style_context (self->priv->label),
"wgs-clock");
gtk_label_set_justify (GTK_LABEL (self->priv->label), GTK_JUSTIFY_CENTER);
gtk_widget_set_size_request (self->priv->label,
WESTON_GTK_VERTICAL_CLOCK_WIDTH, -1);
gtk_box_pack_start (GTK_BOX (self), self->priv->label, FALSE, FALSE, 0);
wall_clock_notify_cb (self->priv->wall_clock, NULL, self);
}
static void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment