From 82af083e07eb189ac930678224a5748551cf69f8 Mon Sep 17 00:00:00 2001 From: Greg Frost Date: Tue, 4 Aug 2009 01:21:58 +0000 Subject: LinHES-timezone: add help option. add guess failure handling. add title --- abs/core-testing/LinHES-timezone/PKGBUILD | 5 +- abs/core-testing/LinHES-timezone/linhes_timezone.c | 107 ++++++++++++++++++--- 2 files changed, 98 insertions(+), 14 deletions(-) diff --git a/abs/core-testing/LinHES-timezone/PKGBUILD b/abs/core-testing/LinHES-timezone/PKGBUILD index eedc364..4c72659 100644 --- a/abs/core-testing/LinHES-timezone/PKGBUILD +++ b/abs/core-testing/LinHES-timezone/PKGBUILD @@ -2,7 +2,7 @@ # Maintainer: Greg Frost pkgname=LinHES-timezone pkgver=1 -pkgrel=7 +pkgrel=8 pkgdesc="GUI timezone selector used by LinHES-config." arch=i686 depends=() @@ -26,5 +26,4 @@ md5sums=('53976e51e938c555f84b43c933339051' '0710658b3b46cc659f56260c03b904ed' '0d9e51af5f650dd329edce4531c42a58' 'c01e2335603d8395004e32bae9060fde' - 'b20bd68272644f607fbfe7d50e7be42a' - '8629268a4f2ca8391e4d1087a9734088') + 'b20bd68272644f607fbfe7d50e7be42a') diff --git a/abs/core-testing/LinHES-timezone/linhes_timezone.c b/abs/core-testing/LinHES-timezone/linhes_timezone.c index d295091..4ab4ab0 100644 --- a/abs/core-testing/LinHES-timezone/linhes_timezone.c +++ b/abs/core-testing/LinHES-timezone/linhes_timezone.c @@ -52,6 +52,11 @@ double acceleration = 0.01; char input_keys[200]; int guessing_timezone = FALSE; +time_t guess_timeout = 0; +int guess_failed = FALSE; +time_t guess_failed_timeout = 0; +int show_information = FALSE; +int info_displayed = FALSE; void select_place (int place) { @@ -186,7 +191,7 @@ void draw_zone ( } } -void draw_string (int x, int y, char*s, unsigned long colour) +void draw_string (int x, int y, const char*s, unsigned long colour) { XSetForeground (display, gc, BlackPixel (display, screen)); for (int x_pos = x - 3; x_pos <= x + 3; x_pos++) @@ -296,12 +301,39 @@ void redraw_map () for (int zone = 0; zone < NUM_ZONES - 1; zone++) draw_zone (pixmap, zone, 0, 0); - if (guessing_timezone) + if (show_information) + { + info_displayed = TRUE; + char *s[4] = {"Left/Right: Change Offset", + "Up/Down: Change Location", + "Enter: Select Location", + "Esc: Abort"}; + int num = XtNumber(s); + for (int i = 0; i < num; i++) + { + int text_width = XTextWidth (font, s[i], strlen (s[i])); + draw_string (width/2 - text_width/2, + height/2 + (-2 + i) * (font->ascent + font->descent), + s[i], name_colour.pixel); + } + } + else if (guessing_timezone || (info_displayed = FALSE)) { char *s = "Guessing Timezone"; int text_width = XTextWidth (font, s, strlen (s)); draw_string (width/2 - text_width/2, height/2, s, name_colour.pixel); } + else if (guess_failed) + { + char *s = "Unable to Guess Timezone"; + char *s2 = "Please Select Timezone Manually"; + int text_width = XTextWidth (font, s, strlen (s)); + draw_string (width/2 - text_width/2, height/2, s, name_colour.pixel); + text_width = XTextWidth (font, s2, strlen (s2)); + draw_string (width/2 - text_width/2, + height/2 + font->ascent + font->descent, + s2, name_colour.pixel); + } else { draw_zone (pixmap, selected_zone, 1, 1); @@ -332,14 +364,28 @@ void redraw_map () char zone_offset[100]; sprintf (zone_offset, "UTC%s", zone_data[selected_zone].offset); draw_string ( - ((width * 0.95 - XTextWidth (font, zone_offset, strlen (zone_offset))) + + ((width * 0.95 - XTextWidth (font, "UTC+88", strlen ("UTC+88"))) + ((width / 2) + radius / sqrt (2))) / 2, ((lrint (height * 0.05) + font->ascent) + (height / 2 - radius / sqrt (2))) / 2, zone_offset, name_colour.pixel); } } - + + if (!guessing_timezone && !guess_failed) + { + const char *title = "Select Your Time Zone"; + const char *help = "Help = i"; + + draw_string (width / 2 - XTextWidth (font, title, strlen (title)) / 2, + ((lrint (height * 0.05) + font->ascent) + + (height / 2 - radius / sqrt (2))) / 2, + title, WhitePixel (display,screen)); + + draw_string (width * 0.05, height * 0.95 - font->descent - font->ascent, + help, name_colour.pixel); + } + XCopyArea (display, pixmap, window, gc, 0, 0, width, height, 0, 0); } @@ -393,6 +439,10 @@ void handle_key (char key) select_place (nearest_z (selected_z)); break; + case 'I': + show_information = !show_information; + break; + case 'X': printf ("%s\n", zone_data[selected_zone].place_info[selected_place].zonename); exit (0); @@ -434,7 +484,12 @@ void handle_event (XEvent *xevent) break; case XK_Escape: - handle_key('E'); + handle_key ('E'); + break; + + case XK_I: + case XK_i: + handle_key ('I'); break; } @@ -588,7 +643,12 @@ void *timezone_guess (void *unused) if (!guess_data) { fprintf (stderr, "error parsing web page for timezone guess\n"); - guessing_timezone = FALSE; + if (guessing_timezone) + { + guessing_timezone = FALSE; + guess_failed = TRUE; + guess_failed_timeout = time (NULL) + 3; + } return NULL; } @@ -648,7 +708,12 @@ void *timezone_guess (void *unused) if (zone == NUM_ZONES) { fprintf (stderr, "couldnt find zone %s\n", guess_zone); - default_zone (""); + if (guessing_timezone) + { + guessing_timezone = FALSE; + guess_failed = TRUE; + guess_failed_timeout = time (NULL) + 3; + } } else { @@ -699,7 +764,12 @@ void *timezone_guess (void *unused) } else { - default_zone (""); + if (guessing_timezone) + { + guessing_timezone = FALSE; + guess_failed = TRUE; + guess_failed_timeout = time (NULL) + 3; + } } guessing_timezone = FALSE; @@ -882,8 +952,9 @@ int main (int argc, char *argv[]) // Load the font. - font = XLoadQueryFont (display, (width > 800) ? "-*-lucida-bold-r-*-*-34-*-*-*-*-*-*-*" : - "-*-lucida-bold-r-*-*-20-*-*-*-*-*-*-*"); + font = XLoadQueryFont (display, (width > 800) ? + "-*-lucida-bold-r-*-*-34-*-*-*-*-*-*-*" : + "-*-lucida-bold-r-*-*-20-*-*-*-*-*-*-*"); if (!font) fprintf (stderr,"error loading font\n"); @@ -967,6 +1038,7 @@ int main (int argc, char *argv[]) if (guessing_timezone) { pthread_create (&tid, NULL, timezone_guess, NULL); + guess_timeout = time (NULL) + 10; displayed_lat = M_PI/2; displayed_lon = 0; } @@ -986,9 +1058,22 @@ int main (int argc, char *argv[]) while (1) { + if (guessing_timezone && (time (NULL) > guess_timeout)) + { + guessing_timezone = FALSE; + guess_failed_timeout = time (NULL) + 3; + guess_failed = TRUE; + } + if ((displayed_lat != target_lat) || (displayed_lon != target_lon) || - guessing_timezone) + guessing_timezone || guess_failed || + (info_displayed ^ show_information)) { + if (guess_failed && (time (NULL) > guess_failed_timeout)) + { + guess_failed = FALSE; + } + next_view (); redraw_map (); } -- cgit v0.12