summaryrefslogtreecommitdiff
path: root/von-wait.c
diff options
context:
space:
mode:
Diffstat (limited to 'von-wait.c')
-rw-r--r--von-wait.c80
1 files changed, 65 insertions, 15 deletions
diff --git a/von-wait.c b/von-wait.c
index 23cf802..60a263c 100644
--- a/von-wait.c
+++ b/von-wait.c
@@ -1,10 +1,13 @@
-#include <gdk/gdkkeysyms.h>
-#include <gtk/gtk.h>
-#include <cairo.h>
+#define _XOPEN_SOURCE /* glibc2 needs this */
#include <time.h>
#include <sys/time.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <getopt.h>
#include <glib/gprintf.h>
+#include <gdk/gdkkeysyms.h>
+#include <gtk/gtk.h>
+#include <cairo.h>
#define SECOND_INTERVAL 1000
@@ -15,6 +18,8 @@ struct private {
time_t time;
time_t von_arrives;
struct timeval tv_now;
+ gchar *ts;
+ gchar *msg;
};
static gboolean time_handler (GtkWidget* w)
@@ -40,8 +45,6 @@ gboolean on_key_press (GtkWidget *widget, GdkEventKey *key, gpointer p) {
static void paint (GtkWidget *widget, GdkEventExpose *eev, struct private *p) {
gint width, height;
cairo_t *cr;
- gchar *gc_time;
-
gint sec, min, hour, day;
@@ -61,9 +64,10 @@ static void paint (GtkWidget *widget, GdkEventExpose *eev, struct private *p) {
sec = p->time;
- gc_time = g_strdup_printf("Von arrives in %02dd %02d:%02d:%02d:%02d",
- day, hour, min, sec,
- (int) ((p->tv_now.tv_usec)/10e3));
+ g_sprintf(p->ts,
+ "Von arrives in %02dd %02d:%02d:%02d:%02d",
+ day, hour, min, sec,
+ (int) (99 - ((p->tv_now.tv_usec)/10e3)));
width = widget->allocation.width;
height = widget->allocation.height;
@@ -82,7 +86,7 @@ static void paint (GtkWidget *widget, GdkEventExpose *eev, struct private *p) {
cairo_set_font_size (cr, 10);
cairo_move_to (cr, 10, 10);
cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 1.0f);
- cairo_show_text (cr, gc_time);
+ cairo_show_text (cr, p->ts);
cairo_restore (cr);
cairo_destroy (cr);
@@ -97,21 +101,66 @@ static void install_colormap (GtkWidget *w) {
gtk_widget_set_colormap (w, colormap);
}
-
+
+
+gint usage (char *name) {
+ return printf ("usage: %s [TIME[+FMT]].\n", name);
+}
+
gint main (gint argc, gchar **argv) {
+ int c;
+
+ char *s_time = NULL;
+ char *s_res = NULL;
+ char *fmt = "%Y-%m-%d";
+
GtkWidget *window;
struct private *p = malloc(sizeof(struct private));
+
struct tm von_time = {
.tm_min = 40,
.tm_hour = 9,
.tm_mday = 14,
.tm_mon = 1,
.tm_year = 107,
- };
+ };
- p->von_arrives = mktime(&von_time);
+ for (c = 1; c < argc; c++) {
+ switch (*argv[c]) {
+ case '+':
+ fmt = argv[c] + 1;
+ break;
+ case '-':
+ switch (*(argv[c] + 1)) {
+ case 'h':
+ return usage(argv[0]);
+ case '-':
+ break;
+ }
+ break;
+ default:
+ if (s_time != NULL)
+ printf ("WARNING: overriding previously given time \n"
+ "'%s'\n"
+ "with '%s'.\n", s_time, argv[c]);
+ s_time = argv[c];
+ }
+ }
+
+ if (s_time) {
+ s_res = strptime(s_time, fmt, &von_time);
+ if (*s_res != '\0')
+ printf("WARNING: processing stoped at '%s'\n", s_res);
+ }
+ if (time(NULL) > mktime(&von_time))
+ printf("WARNING: given a date in the past !\n");
+
+ p->ts = g_strdup_printf("Von arrives in 00d 00:00:00:00");
+
+ p->von_arrives = mktime(&von_time);
+
gtk_init(&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@@ -146,11 +195,12 @@ gint main (gint argc, gchar **argv) {
gtk_widget_show_all (window);
- gtk_timeout_add (SECOND_INTERVAL/100, (GtkFunction) time_handler, window);
+ gtk_timeout_add (SECOND_INTERVAL/9, (GtkFunction) time_handler, window);
gtk_main ();
+
+ g_free(p->ts);
+ free(p);
return 0;
}
-
-