summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/LinHES-timezone/linhes_timezone.c
diff options
context:
space:
mode:
authorGreg Frost <gregfrost1@bigpond.com>2009-08-04 01:21:58 (GMT)
committerGreg Frost <gregfrost1@bigpond.com>2009-08-04 01:21:58 (GMT)
commit82af083e07eb189ac930678224a5748551cf69f8 (patch)
treec958be20706d612e7286b1ddb63d35b7d2e703b1 /abs/core-testing/LinHES-timezone/linhes_timezone.c
parent05c9c17a7faab67c2473efec556d9f5527dfe089 (diff)
downloadlinhes_pkgbuild-82af083e07eb189ac930678224a5748551cf69f8.zip
linhes_pkgbuild-82af083e07eb189ac930678224a5748551cf69f8.tar.gz
linhes_pkgbuild-82af083e07eb189ac930678224a5748551cf69f8.tar.bz2
LinHES-timezone: add help option. add guess failure handling. add title
Diffstat (limited to 'abs/core-testing/LinHES-timezone/linhes_timezone.c')
-rw-r--r--abs/core-testing/LinHES-timezone/linhes_timezone.c107
1 files changed, 96 insertions, 11 deletions
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 ();
}