[monkey-bubble: 9/753] Added clock/time measurement widget - Pista
- From: Sven Herzberg <herzi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [monkey-bubble: 9/753] Added clock/time measurement widget - Pista
- Date: Wed, 14 Jul 2010 21:56:26 +0000 (UTC)
commit 71eb1ce7b88acfa97d04a548e7441d0d60242048
Author: Szekeres István <szekeres src gnome org>
Date: Wed Dec 17 00:10:41 1997 +0000
Added clock/time measurement widget - Pista
libgnomeui/Makefile.am | 9 +-
libgnomeui/gtk-clock.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++
libgnomeui/gtk-clock.h | 61 +++++++++++++++
libgnomeui/libgnomeui.h | 1 +
4 files changed, 255 insertions(+), 4 deletions(-)
---
diff --git a/libgnomeui/Makefile.am b/libgnomeui/Makefile.am
index 46c619c..abab3b8 100644
--- a/libgnomeui/Makefile.am
+++ b/libgnomeui/Makefile.am
@@ -15,7 +15,8 @@ libgnomeui_la_SOURCES = \
gnome-pixmap.c \
gnome-toolbar.c \
gnome-colors.c \
- gnome-session.c
+ gnome-session.c \
+ gtk-clock.c
libgnomeuiinclude_HEADERS = \
gnome-actionarea.h \
@@ -25,9 +26,9 @@ libgnomeuiinclude_HEADERS = \
gnome-properties.h \
gnome-pixmap.h \
gnome-toolbar.h \
- libgnomeui.h \
- gnome-session.h
-
+ gnome-session.h \
+ gtk-clock.h \
+ libgnomeui.h
libgnomeui_la_LDFLAGS = -version-info 0:0:0 -rpath $(libdir)
libgnomeui_la_LIBADD = $(GTK_LIBS)
diff --git a/libgnomeui/gtk-clock.c b/libgnomeui/gtk-clock.c
new file mode 100644
index 0000000..fd02f84
--- /dev/null
+++ b/libgnomeui/gtk-clock.c
@@ -0,0 +1,188 @@
+
+/*
+ * gtk-clock: The GTK clock widget
+ * (C)1998 The Free Software Foundation
+ *
+ * Author: Szekeres István (szekeres cyberspace mht bme hu)
+ */
+
+#include <time.h>
+#include <gtk/gtk.h>
+#include <string.h>
+#include "gtk-clock.h"
+
+static void gtk_clock_class_init(GtkClockClass *klass);
+static void gtk_clock_init(GtkClock *clock);
+
+guint gtk_clock_get_type(void)
+{
+ static guint gtkclock_type = 0;
+ if (!gtkclock_type) {
+ GtkTypeInfo gtkclock_info = {
+ "GtkClock",
+ sizeof(GtkClock),
+ sizeof(GtkClockClass),
+ (GtkClassInitFunc) gtk_clock_class_init,
+ (GtkObjectInitFunc) gtk_clock_init,
+ (GtkArgFunc) NULL,
+ };
+ gtkclock_type = gtk_type_unique(gtk_label_get_type(), >kclock_info);
+ }
+
+ return gtkclock_type;
+}
+
+static void gtk_clock_class_init(GtkClockClass *klass)
+{
+}
+
+static void gtk_clock_init(GtkClock *clock)
+{
+ clock->timer_id = -1;
+ clock->update_interval = 1;
+ clock->seconds = time(NULL);
+ clock->stopped = 0;
+}
+
+static void gtk_clock_gen_str(GtkClock *clock)
+{
+ gchar timestr[64];
+ time_t secs;
+
+ switch (clock->type) {
+ case GTK_CLOCK_DECREASING:
+ secs = clock->seconds-time(NULL);
+ break;
+ case GTK_CLOCK_INCREASING:
+ secs = time(NULL)-clock->seconds;
+ break;
+ case GTK_CLOCK_REALTIME:
+ secs = time(NULL);
+ break;
+ }
+
+
+ if (clock->type == GTK_CLOCK_REALTIME) {
+ clock->tm = localtime(&secs);
+ } else {
+ clock->tm->tm_hour = secs/3600;
+ secs -= clock->tm->tm_hour*3600;
+ clock->tm->tm_min = secs/60;
+ clock->tm->tm_sec = secs - clock->tm->tm_min*60;
+ }
+
+ strftime(timestr, 64, clock->fmt, clock->tm);
+ gtk_label_set(GTK_LABEL(clock), timestr);
+}
+
+static gint gtk_clock_timer_callback(gpointer data)
+{
+ GtkClock *clock = (GtkClock *)data;
+
+ gtk_clock_gen_str(clock);
+
+ return TRUE;
+}
+
+static gint gtk_clock_timer_first_callback(gpointer data)
+{
+ GtkClock *clock = (GtkClock *)data;
+ gint tmpid;
+
+ gtk_clock_gen_str(clock);
+
+ tmpid = gtk_timeout_add(1000*clock->update_interval,
+ gtk_clock_timer_callback, clock);
+
+ gtk_clock_stop(clock);
+
+ clock->timer_id = tmpid;
+
+ return FALSE;
+}
+
+GtkWidget *gtk_clock_new(GtkClockType type)
+{
+ GtkClock *clock = gtk_type_new(gtk_clock_get_type());
+
+ if (type == GTK_CLOCK_REALTIME) {
+ clock->fmt = g_strdup("%H:%M");
+ clock->update_interval = 60;
+ clock->tm = localtime(&clock->seconds);
+ clock->timer_id = gtk_timeout_add(1000*(60-clock->tm->tm_sec),
+ gtk_clock_timer_first_callback, clock);
+ } else {
+ clock->fmt = g_strdup("%H:%M:%S");
+ clock->tm = g_new(struct tm, 1);
+ bzero(clock->tm, sizeof(struct tm));
+ clock->update_interval = 1;
+ }
+
+ gtk_clock_gen_str(clock);
+
+ return GTK_WIDGET(clock);
+}
+
+void gtk_clock_set_format(GtkClock *clock, gchar *fmt)
+{
+ g_return_if_fail(clock != NULL);
+ g_return_if_fail(fmt != NULL);
+
+ g_free(clock->fmt);
+ clock->fmt = g_strdup(fmt);
+}
+
+void gtk_clock_set_seconds(GtkClock *clock, time_t seconds)
+{
+ g_return_if_fail(clock != NULL);
+
+ if (clock->type == GTK_CLOCK_INCREASING) {
+ clock->seconds = time(NULL)-seconds;
+ } else if (clock->type == GTK_CLOCK_DECREASING) {
+ clock->seconds = time(NULL)+seconds;
+ }
+ if (clock->timer_id == -1) clock->stopped = seconds;
+ gtk_clock_gen_str(clock);
+}
+
+void gtk_clock_set_update_interval(GtkClock *clock, gint seconds)
+{
+ guint tmp;
+
+ g_return_if_fail(clock != NULL);
+
+ tmp = clock->update_interval;
+
+ clock->update_interval = seconds;
+
+ if (tmp > seconds && clock->timer_id != -1) {
+ gtk_clock_stop(clock);
+ gtk_clock_start(clock);
+ }
+}
+
+void gtk_clock_start(GtkClock *clock)
+{
+ g_return_if_fail(clock != NULL);
+
+ if (clock->timer_id != -1) return;
+
+ gtk_clock_set_seconds(clock, clock->stopped);
+ clock->timer_id = gtk_timeout_add(1000*clock->update_interval, gtk_clock_timer_callback, clock);
+}
+
+void gtk_clock_stop(GtkClock *clock)
+{
+ g_return_if_fail(clock != NULL);
+
+ if (clock->timer_id == -1 || clock->type == GTK_CLOCK_REALTIME) return;
+
+ if (clock->type == GTK_CLOCK_INCREASING) {
+ clock->stopped = time(NULL)-clock->seconds;
+ } else if (clock->type == GTK_CLOCK_DECREASING) {
+ clock->stopped = clock->seconds-time(NULL);
+ }
+
+ gtk_timeout_remove(clock->timer_id);
+ clock->timer_id = -1;
+}
diff --git a/libgnomeui/gtk-clock.h b/libgnomeui/gtk-clock.h
new file mode 100644
index 0000000..9285d5e
--- /dev/null
+++ b/libgnomeui/gtk-clock.h
@@ -0,0 +1,61 @@
+
+/*
+ * gtk-clock: The GTK clock widget
+ * (C)1998 The Free Software Foundation
+ *
+ * Author: Szekeres István (szekeres cyberspace mht bme hu)
+ */
+
+#ifndef __GTK_CLOCK_H__
+#define __GTK_CLOCK_H__
+
+#include <time.h>
+#include <gtk/gtk.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define GTK_CLOCK(obj) GTK_CHECK_CAST(obj, gtk_clock_get_type(), GtkClock)
+#define GTK_CLOCK_CLASS(class) GTK_CHECK_CAST_CLASS(class, gtk_clock_get_type(), GtkClockClass)
+#define GTK_IS_CLOCK(obj) GTK_CHECK_TYPE(obj, gtk_clock_get_type())
+
+typedef struct _GtkClock GtkClock;
+typedef struct _GtkClockClass GtkClockClass;
+
+typedef enum _GtkClockType GtkClockType;
+
+enum _GtkClockType {
+ GTK_CLOCK_INCREASING,
+ GTK_CLOCK_DECREASING,
+ GTK_CLOCK_REALTIME
+};
+
+struct _GtkClock {
+ GtkLabel widget;
+ GtkClockType type;
+ gint timer_id;
+ gint update_interval;
+ time_t seconds;
+ time_t stopped;
+ gchar *fmt;
+ struct tm *tm;
+};
+
+struct _GtkClockClass {
+ GtkLabelClass parent_class;
+};
+
+guint gtk_clock_get_type(void);
+GtkWidget *gtk_clock_new(GtkClockType type);
+void gtk_clock_set_format(GtkClock *clock, gchar *fmt);
+void gtk_clock_set_seconds(GtkClock *clock, time_t seconds);
+void gtk_clock_set_update_interval(GtkClock *clock, gint seconds);
+void gtk_clock_start(GtkClock *clock);
+void gtk_clock_stop(GtkClock *clock);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __GTK_CLOCK_H__ */
diff --git a/libgnomeui/libgnomeui.h b/libgnomeui/libgnomeui.h
index 49ecea0..7b1b242 100644
--- a/libgnomeui/libgnomeui.h
+++ b/libgnomeui/libgnomeui.h
@@ -9,6 +9,7 @@
#include "libgnomeui/gnome-pixmap.h"
#include "libgnomeui/gnome-toolbar.h"
#include "libgnomeui/gnome-actionarea.h"
+#include "libgnomeui/gtk-clock.h"
BEGIN_GNOME_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]