source: trunk/third/gnome-applets/gweather/gweather-pref.c @ 21373

Revision 21373, 43.2 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21372, which included commits to RCS files with non-trunk default branches.
Line 
1/* $Id: gweather-pref.c,v 1.1.1.4 2005-03-10 19:44:36 ghudson Exp $ */
2
3/*
4 *  Papadimitriou Spiros <spapadim+@cs.cmu.edu>
5 *
6 *  This code released under the GNU GPL.
7 *  Read the file COPYING for more information.
8 *
9 *  Preferences dialog
10 *
11 */
12
13/* Radar map on by default. */
14#define RADARMAP
15
16#ifdef HAVE_CONFIG_H
17#  include <config.h>
18#endif
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <assert.h>
23#include <ctype.h>
24#include <langinfo.h>
25#include <locale.h>
26
27#include <gnome.h>
28#include <panel-applet.h>
29#include <panel-applet-gconf.h>
30#include <gconf/gconf-client.h>
31
32#include <libxml/parser.h>
33#include <libxml/tree.h>
34
35#include "gweather.h"
36#include "gweather-pref.h"
37#include "gweather-applet.h"
38#include "gweather-xml.h"
39
40#define NEVER_SENSITIVE         "never_sensitive"
41
42
43/* gconf keys */
44#define GCONF_TEMP_UNIT     "temperature_unit"
45#define GCONF_SPEED_UNIT    "speed_unit"
46#define GCONF_PRESSURE_UNIT "pressure_unit"
47#define GCONF_DISTANCE_UNIT "distance_unit"
48
49enum
50{
51    COL_LOC = 0,
52    COL_POINTER,
53    NUM_COLUMNS
54};
55
56
57static GConfEnumStringPair temp_unit_enum_map [] = {
58    { TEMP_UNIT_DEFAULT,    "Default" },
59    { TEMP_UNIT_KELVIN,     "K"       },
60    { TEMP_UNIT_CENTIGRADE, "C"       },
61    { TEMP_UNIT_FAHRENHEIT, "F"       },
62    { 0, NULL }
63};     
64
65static GConfEnumStringPair speed_unit_enum_map [] = {
66    { SPEED_UNIT_DEFAULT, "Default" },
67    { SPEED_UNIT_MS,      "m/s"     },
68    { SPEED_UNIT_KPH,     "km/h"    },
69    { SPEED_UNIT_MPH,     "mph"     },
70    { SPEED_UNIT_KNOTS,   "knots"   },
71        { 0, NULL }
72};
73
74static GConfEnumStringPair pressure_unit_enum_map [] = {
75    { PRESSURE_UNIT_DEFAULT, "Default" },
76        { PRESSURE_UNIT_KPA,     "kPa"     },
77        { PRESSURE_UNIT_HPA,     "hPa"     },
78        { PRESSURE_UNIT_MB,      "mb"      },
79    { PRESSURE_UNIT_MM_HG,   "mmHg"    },
80        { PRESSURE_UNIT_INCH_HG, "inHg"    },
81    { 0, NULL }
82};
83
84static GConfEnumStringPair distance_unit_enum_map [] = {
85    { DISTANCE_UNIT_DEFAULT, "Default" },
86    { DISTANCE_UNIT_METERS,  "m"       },
87    { DISTANCE_UNIT_KM,      "km"      },
88    { DISTANCE_UNIT_MILES,   "mi"      },
89    { 0, NULL }
90};
91
92static void gweather_pref_set_accessibility (GWeatherApplet *gw_applet);
93static void help_cb (GtkDialog *dialog);
94
95/* set sensitive and setup NEVER_SENSITIVE appropriately */
96static void
97hard_set_sensitive (GtkWidget *w, gboolean sensitivity)
98{
99        gtk_widget_set_sensitive (w, sensitivity);
100        g_object_set_data (G_OBJECT (w), NEVER_SENSITIVE,
101                           GINT_TO_POINTER ( ! sensitivity));
102}
103
104
105/* set sensitive, but always insensitive if NEVER_SENSITIVE is set */
106static void
107soft_set_sensitive (GtkWidget *w, gboolean sensitivity)
108{
109        if (g_object_get_data (G_OBJECT (w), NEVER_SENSITIVE))
110                gtk_widget_set_sensitive (w, FALSE);
111        else
112                gtk_widget_set_sensitive (w, sensitivity);
113}
114
115
116static gboolean
117key_writable (PanelApplet *applet, const char *key)
118{
119        gboolean writable;
120        char *fullkey;
121        static GConfClient *client = NULL;
122        if (client == NULL)
123                client = gconf_client_get_default ();
124
125        fullkey = panel_applet_gconf_get_full_key (applet, key);
126
127        writable = gconf_client_key_is_writable (client, fullkey, NULL);
128
129        g_free (fullkey);
130
131        return writable;
132}
133
134/* sets up ATK Relation between the widgets */
135
136void
137add_atk_relation (GtkWidget *widget1, GtkWidget *widget2, AtkRelationType type)
138{
139    AtkObject *atk_obj1, *atk_obj2;
140    AtkRelationSet *relation_set;
141    AtkRelation *relation;
142   
143    atk_obj1 = gtk_widget_get_accessible (widget1);
144    if (! GTK_IS_ACCESSIBLE (atk_obj1))
145       return;
146    atk_obj2 = gtk_widget_get_accessible (widget2);
147
148    relation_set = atk_object_ref_relation_set (atk_obj1);
149    relation = atk_relation_new (&atk_obj2, 1, type);
150    atk_relation_set_add (relation_set, relation);
151    g_object_unref (G_OBJECT (relation));
152}
153
154/* sets accessible name and description */
155
156void
157set_access_namedesc (GtkWidget *widget, const gchar *name, const gchar *desc)
158{
159    AtkObject *obj;
160
161    obj = gtk_widget_get_accessible (widget);
162    if (! GTK_IS_ACCESSIBLE (obj))
163       return;
164
165    if ( desc )
166       atk_object_set_description (obj, desc);
167    if ( name )
168       atk_object_set_name (obj, name);
169}
170
171/* sets accessible name, description, CONTROLLED_BY
172 * and CONTROLLER_FOR relations for the components
173 * in gweather preference dialog.
174 */
175
176static void gweather_pref_set_accessibility (GWeatherApplet *gw_applet)
177{
178
179    /* Relation between components in General page */
180
181    add_atk_relation (gw_applet->pref_basic_update_btn, gw_applet->pref_basic_update_spin,                                             ATK_RELATION_CONTROLLER_FOR);
182    add_atk_relation (gw_applet->pref_basic_radar_btn, gw_applet->pref_basic_radar_url_btn,                                            ATK_RELATION_CONTROLLER_FOR);
183    add_atk_relation (gw_applet->pref_basic_radar_btn, gw_applet->pref_basic_radar_url_entry                                            , ATK_RELATION_CONTROLLER_FOR);
184
185    add_atk_relation (gw_applet->pref_basic_update_spin, gw_applet->pref_basic_update_btn,                                             ATK_RELATION_CONTROLLED_BY);
186    add_atk_relation (gw_applet->pref_basic_radar_url_btn, gw_applet->pref_basic_radar_btn,                                            ATK_RELATION_CONTROLLED_BY);
187    add_atk_relation (gw_applet->pref_basic_radar_url_entry, gw_applet->pref_basic_radar_btn                                            , ATK_RELATION_CONTROLLED_BY);
188
189    /* Accessible Name and Description for the components in Preference Dialog */
190   
191    set_access_namedesc (gw_applet->pref_tree, _("Location view"),                                                       _("Select Location from the list"));
192   
193    set_access_namedesc (gw_applet->pref_basic_update_spin, _("Update spin button"),                                      _("Spinbutton for updating"));
194    set_access_namedesc (gw_applet->pref_basic_radar_url_entry, _("Address Entry"),                                        _("Enter the URL"));
195
196}
197
198static gint cmp_loc (const WeatherLocation *l1, const WeatherLocation *l2)
199{
200    return (l1 && l2 && weather_location_equal(l1, l2)) ? 0 : 1;
201}
202
203/* Update pref dialog from gweather_pref */
204static gboolean update_dialog (GWeatherApplet *gw_applet)
205{
206    GtkCTreeNode *node;
207   
208    g_return_val_if_fail(gw_applet->gweather_pref.location != NULL, FALSE);
209
210    gtk_spin_button_set_value(GTK_SPIN_BUTTON(gw_applet->pref_basic_update_spin),
211                              gw_applet->gweather_pref.update_interval / 60);
212    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gw_applet->pref_basic_update_btn),
213                                 gw_applet->gweather_pref.update_enabled);
214    soft_set_sensitive(gw_applet->pref_basic_update_spin,
215                             gw_applet->gweather_pref.update_enabled);
216
217    if ( gw_applet->gweather_pref.use_temperature_default) {
218        gtk_combo_box_set_active (GTK_COMBO_BOX(gw_applet->pref_basic_temp_combo), 0);
219    } else {
220                gtk_combo_box_set_active (GTK_COMBO_BOX(gw_applet->pref_basic_temp_combo),
221                         gw_applet->gweather_pref.temperature_unit -1);
222    }
223       
224    if ( gw_applet->gweather_pref.use_speed_default) {
225        gtk_combo_box_set_active (GTK_COMBO_BOX(gw_applet->pref_basic_speed_combo), 0);
226    } else {
227        gtk_combo_box_set_active (GTK_COMBO_BOX(gw_applet->pref_basic_speed_combo),
228                         gw_applet->gweather_pref.speed_unit -1);
229    }
230       
231    if ( gw_applet->gweather_pref.use_pressure_default) {
232        gtk_combo_box_set_active (GTK_COMBO_BOX(gw_applet->pref_basic_pres_combo), 0);
233    } else {
234        gtk_combo_box_set_active (GTK_COMBO_BOX(gw_applet->pref_basic_pres_combo),
235                         gw_applet->gweather_pref.pressure_unit -1);
236    }
237    if ( gw_applet->gweather_pref.use_distance_default) {
238        gtk_combo_box_set_active (GTK_COMBO_BOX(gw_applet->pref_basic_dist_combo), 0);
239    } else {
240        gtk_combo_box_set_active (GTK_COMBO_BOX(gw_applet->pref_basic_dist_combo),
241                         gw_applet->gweather_pref.distance_unit -1);
242    }
243
244#if 0
245    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gw_applet->pref_basic_detailed_btn),
246                                 gw_applet->gweather_pref.detailed);
247#endif
248#ifdef RADARMAP
249    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gw_applet->pref_basic_radar_btn),
250                                 gw_applet->gweather_pref.radar_enabled);
251                                 
252    soft_set_sensitive (gw_applet->pref_basic_radar_url_btn,
253                              gw_applet->gweather_pref.radar_enabled);
254    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gw_applet->pref_basic_radar_url_btn),
255                                 gw_applet->gweather_pref.use_custom_radar_url);
256    soft_set_sensitive (gw_applet->pref_basic_radar_url_hbox,
257                              gw_applet->gweather_pref.radar_enabled);
258    if (gw_applet->gweather_pref.radar)
259        gtk_entry_set_text (GTK_ENTRY (gw_applet->pref_basic_radar_url_entry),
260                            gw_applet->gweather_pref.radar);
261#endif /* RADARMAP */
262   
263   
264    return TRUE;
265}
266
267static inline void update_string (gchar *val, gchar **str)
268{
269    g_return_if_fail(str != NULL);
270
271    g_free(*str);
272    *str = NULL;
273    if (val && (strlen(val) > 0))
274        *str = g_strdup(val);
275}
276
277static gboolean check_proxy_uri (const gchar *uri)
278{
279    char *pcolon, *pslash;
280
281    g_return_val_if_fail(uri != NULL, FALSE);
282
283    /* Check if uri starts with "http://" */
284    if ((strlen(uri) < 7) || (strncmp(uri, "http://", 7) != 0))
285        return FALSE;
286
287    /* Check for slashes */
288    pslash = strchr(uri+7, '/');
289    if (pslash && (strcmp(pslash, "/") != 0))
290        return FALSE;
291
292    /* Check for port number after second colon */
293    if ((pcolon = strchr(uri+7, ':')) != NULL) {
294        if (!isdigit(pcolon[1]))
295            return FALSE;
296        for (++pcolon ;  *pcolon;  pcolon++)
297            if (!isdigit(*pcolon))
298                break;
299        return (!strcmp(pcolon, "") || !strcmp(pcolon, "/"));
300    }
301
302    return TRUE;
303}
304
305static void change_cb (GtkButton *button, gpointer user_data)
306{
307    GWeatherApplet *gw_applet = user_data;
308   
309    soft_set_sensitive(gw_applet->pref_basic_update_spin, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gw_applet->pref_basic_update_btn)));
310   
311    return;
312}
313
314static void row_selected_cb (GtkTreeSelection *selection, gpointer data)
315{
316    GWeatherApplet *gw_applet = data;
317    GtkTreeModel *model;
318    WeatherLocation *loc = NULL;
319    GtkTreeIter iter;
320   
321    if (!gtk_tree_selection_get_selected (selection, &model, &iter))
322        return;
323       
324    gtk_tree_model_get (model, &iter, GWEATHER_PREF_COL_POINTER, &loc, -1);
325   
326    if (!loc)
327        return;
328
329    panel_applet_gconf_set_string(gw_applet->applet, "location0", loc->untrans_name, NULL);
330    panel_applet_gconf_set_string(gw_applet->applet, "location1", loc->code, NULL);
331    panel_applet_gconf_set_string(gw_applet->applet, "location2", loc->zone, NULL);
332    panel_applet_gconf_set_string(gw_applet->applet, "location3", loc->radar, NULL);
333    panel_applet_gconf_set_string(gw_applet->applet, "location4", loc->trans_name, NULL);
334    if (gw_applet->gweather_pref.location) {
335       weather_location_free (gw_applet->gweather_pref.location);
336    }
337   
338    gw_applet->gweather_pref.location = weather_location_config_read (gw_applet->applet);
339    gweather_update (gw_applet);
340}
341
342static void load_locations (GWeatherApplet *gw_applet)
343{
344    GtkTreeView *tree = GTK_TREE_VIEW(gw_applet->pref_tree);
345    GtkTreeViewColumn *column;
346    GtkCellRenderer *cell_renderer;
347    WeatherLocation *current_location;
348       
349    /* Add a colum for the locations */
350    cell_renderer = gtk_cell_renderer_text_new ();
351    column = gtk_tree_view_column_new_with_attributes ("not used", cell_renderer,
352                                                       "text", GWEATHER_PREF_COL_LOC, NULL);
353    gtk_tree_view_append_column (tree, column);
354    gtk_tree_view_set_expander_column (GTK_TREE_VIEW (tree), column);
355   
356    /* load locations from xml file */
357    current_location = weather_location_clone (gw_applet->gweather_pref.location);
358    gweather_xml_load_locations(tree, current_location);
359    weather_location_free (current_location);
360}
361
362static void
363auto_update_toggled (GtkToggleButton *button, gpointer data)
364{
365    GWeatherApplet *gw_applet = data;
366    gboolean toggled;
367   
368    toggled = gtk_toggle_button_get_active(button);
369    gw_applet->gweather_pref.update_enabled = toggled;
370    soft_set_sensitive (gw_applet->pref_basic_update_spin, toggled);
371    panel_applet_gconf_set_bool(gw_applet->applet, "auto_update", toggled, NULL);
372    if (gw_applet->timeout_tag > 0)
373        gtk_timeout_remove(gw_applet->timeout_tag);
374    if (gw_applet->gweather_pref.update_enabled)
375        gw_applet->timeout_tag = 
376                gtk_timeout_add (gw_applet->gweather_pref.update_interval * 1000,
377                                 timeout_cb, gw_applet);
378}
379
380static void
381detailed_toggled (GtkToggleButton *button, gpointer data)
382{
383    GWeatherApplet *gw_applet = data;
384    gboolean toggled;
385   
386    toggled = gtk_toggle_button_get_active(button);
387    gw_applet->gweather_pref.detailed = toggled;
388    panel_applet_gconf_set_bool(gw_applet->applet, "enable_detailed_forecast",
389                                toggled, NULL);   
390}
391
392static void parse_temp_string (const gchar *gconf_str, GWeatherPrefs *prefs)
393{
394    gint value = 0;
395    char *imperial = NULL;
396       
397    prefs->use_temperature_default = TRUE;
398       
399    if ( gconf_str && gconf_string_to_enum (temp_unit_enum_map, gconf_str, &value) ) {
400        prefs->temperature_unit = value;
401               
402                if ((prefs->temperature_unit == TEMP_UNIT_DEFAULT) &&
403                    (gconf_string_to_enum (temp_unit_enum_map, _("DEFAULT_TEMP_UNIT"), &value)) ) {
404              prefs->temperature_unit = value;
405                } else {
406            prefs->use_temperature_default = FALSE;
407        }
408    }   
409    else {
410        /* TRANSLATOR: This is the default unit to use for temperature measurements. */
411        /* Valid values are: "K" (Kelvin), "C" (Celsius) and "F" (Fahrenheit) */
412        if (gconf_string_to_enum (temp_unit_enum_map, _("DEFAULT_TEMP_UNIT"), &value) ) {
413            prefs->temperature_unit = value;
414        }
415    }
416    if (!prefs->temperature_unit || prefs->temperature_unit == TEMP_UNIT_DEFAULT ) {
417#ifdef _NL_MEASUREMENT_MEASUREMENT
418        imperial = nl_langinfo(_NL_MEASUREMENT_MEASUREMENT);
419        if ( imperial && imperial[0] == 2 )  {
420            /* imperial */
421            prefs->temperature_unit = TEMP_UNIT_FAHRENHEIT;
422        } else
423#endif
424            prefs->temperature_unit = TEMP_UNIT_CENTIGRADE;
425    }
426}
427
428static void parse_speed_string (const gchar *gconf_str, GWeatherPrefs *prefs)
429{
430    gint value = 0;
431    char *imperial = NULL;
432       
433    prefs->use_speed_default = TRUE;
434       
435    if ( gconf_str && gconf_string_to_enum (speed_unit_enum_map, gconf_str, &value) ) {
436        prefs->speed_unit = value;
437                if ((prefs->speed_unit == SPEED_UNIT_DEFAULT) &&
438                        (gconf_string_to_enum (speed_unit_enum_map, _("DEFAULT_SPEED_UNIT"), &value)) ) {
439              prefs->speed_unit = value;
440                } else {
441            prefs->use_speed_default = FALSE;
442        }
443    }   
444    else {
445        /* TRANSLATOR: This is the default unit to use for wind speed. */
446        /* Valid values are: "m/s" (meters per second), "km/h" (kilometers per hour), */
447        /* "mph" (miles per hour) and "knots"  */
448        if (gconf_string_to_enum (speed_unit_enum_map, _("DEFAULT_SPEED_UNIT"), &value) ) {
449            prefs->speed_unit = value;
450        }
451    }
452    if ( (!prefs->speed_unit) || prefs->speed_unit == SPEED_UNIT_DEFAULT ) {
453#ifdef _NL_MEASUREMENT_MEASUREMENT
454        imperial = nl_langinfo(_NL_MEASUREMENT_MEASUREMENT);
455        if ( imperial && imperial[0] == 2 )  {
456            /* imperial */
457            prefs->speed_unit = SPEED_UNIT_KNOTS;
458        } else
459#endif
460            prefs->speed_unit = SPEED_UNIT_MS;
461    }
462}
463
464
465static void parse_pressure_string (const gchar *gconf_str, GWeatherPrefs *prefs)
466{
467    gint value = 0;
468    char *imperial = NULL;
469       
470    prefs->use_pressure_default = TRUE;
471       
472    if ( gconf_str && gconf_string_to_enum (pressure_unit_enum_map, gconf_str, &value) ) {
473        prefs->pressure_unit = value;
474
475        if ((prefs->pressure_unit == PRESSURE_UNIT_DEFAULT) &&
476                        (gconf_string_to_enum (pressure_unit_enum_map, _("DEFAULT_PRESSURE_UNIT"), &value)) ) {
477              prefs->pressure_unit = value;
478                } else {
479            prefs->use_pressure_default = FALSE;
480        }
481    }   
482    else {
483        /* TRANSLATOR: This is the default unit to use for atmospheric pressure. */
484        /* Valid values are: "kPa" (kiloPascals), "hPa" (hectoPascals),
485           "mb" (millibars), "mmHg" (millimeters of mercury) and
486           "inHg" (inches of mercury) */
487        if (gconf_string_to_enum (pressure_unit_enum_map, _("DEFAULT_PRESSURE_UNIT"), &value) ) {
488            prefs->pressure_unit = value;
489        }
490    }
491    if ( (!prefs->pressure_unit) || prefs->pressure_unit == PRESSURE_UNIT_DEFAULT ) {
492#ifdef _NL_MEASUREMENT_MEASUREMENT
493        imperial = nl_langinfo(_NL_MEASUREMENT_MEASUREMENT);
494        if ( imperial && imperial[0] == 2 )  {
495            /* imperial */
496            prefs->pressure_unit = PRESSURE_UNIT_INCH_HG;
497        } else
498#endif
499            prefs->pressure_unit = PRESSURE_UNIT_HPA;
500    }   
501}
502
503static void parse_distance_string (const gchar *gconf_str, GWeatherPrefs *prefs)
504{
505    gint value = 0;
506    char *imperial = NULL;
507       
508    prefs->use_distance_default = TRUE;
509    if ( gconf_str && gconf_string_to_enum (distance_unit_enum_map, gconf_str, &value) ) {
510        prefs->distance_unit = value;
511
512                if ((prefs->distance_unit == DISTANCE_UNIT_DEFAULT) &&
513                        (gconf_string_to_enum (distance_unit_enum_map, _("DEFAULT_DISTANCE_UNIT"), &value)) ) {
514              prefs->distance_unit = value;
515                } else {
516            prefs->use_distance_default = FALSE;
517        }
518    }   
519    else {
520        /* TRANSLATOR: This is the default unit to use for visibility distance. */
521        /* Valid values are: "m" (meters), "km" (kilometers) and "mi" (miles)   */
522        if (gconf_string_to_enum (distance_unit_enum_map, _("DEFAULT_DISTANCE_UNIT"), &value) ) {
523            prefs->distance_unit = value;
524        }
525    }
526
527        if ((!prefs->distance_unit) || prefs->distance_unit == DISTANCE_UNIT_DEFAULT ) {
528#ifdef _NL_MEASUREMENT_MEASUREMENT
529        imperial = nl_langinfo(_NL_MEASUREMENT_MEASUREMENT);
530        if ( imperial && imperial[0] == 2 )  {
531            /* imperial */
532            prefs->distance_unit = DISTANCE_UNIT_MILES;
533        } else
534#endif
535            prefs->distance_unit = DISTANCE_UNIT_METERS;
536    }
537
538    return;
539}       
540static void temp_combo_changed_cb (GtkComboBox *combo, gpointer data)
541{
542    GWeatherApplet *gw_applet = data;
543    TempUnit       new_unit, *old_unit;
544       
545        g_return_if_fail(gw_applet != NULL);
546   
547        old_unit = &gw_applet->gweather_pref.temperature_unit; 
548        new_unit = gtk_combo_box_get_active(combo) + 1;
549
550        if (new_unit == *old_unit)
551        return;
552
553    parse_temp_string (gconf_enum_to_string (temp_unit_enum_map, new_unit), &(gw_applet->gweather_pref));
554
555    panel_applet_gconf_set_string(gw_applet->applet, GCONF_TEMP_UNIT,
556                                  gconf_enum_to_string (temp_unit_enum_map, new_unit),
557                                  NULL);
558       
559    gtk_label_set_text(GTK_LABEL(gw_applet->label),
560                           weather_info_get_temp_summary(gw_applet->gweather_info));
561    gweather_dialog_update (gw_applet);
562}
563
564static void speed_combo_changed_cb (GtkComboBox *combo, gpointer data)
565{
566    GWeatherApplet *gw_applet = data;
567    SpeedUnit      new_unit, *old_unit;
568       
569        g_return_if_fail(gw_applet != NULL);
570   
571        old_unit = &gw_applet->gweather_pref.speed_unit;       
572        new_unit = gtk_combo_box_get_active(combo) + 1;
573
574        if (new_unit == *old_unit)
575        return;
576
577    parse_speed_string (gconf_enum_to_string (speed_unit_enum_map, new_unit), &(gw_applet->gweather_pref));
578
579    panel_applet_gconf_set_string(gw_applet->applet, GCONF_SPEED_UNIT,
580                                  gconf_enum_to_string (speed_unit_enum_map, new_unit),
581                                  NULL);
582       
583    gweather_dialog_update (gw_applet);
584}
585
586static void pres_combo_changed_cb (GtkComboBox *combo, gpointer data)
587{
588    GWeatherApplet *gw_applet = data;
589    PressureUnit   new_unit, *old_unit;
590       
591        g_return_if_fail(gw_applet != NULL);
592   
593        old_unit = &gw_applet->gweather_pref.pressure_unit;     
594        new_unit = gtk_combo_box_get_active(combo) + 1;
595
596        if (new_unit == *old_unit)
597        return;
598
599    parse_pressure_string (gconf_enum_to_string (pressure_unit_enum_map, new_unit), &(gw_applet->gweather_pref));
600
601    panel_applet_gconf_set_string(gw_applet->applet, GCONF_PRESSURE_UNIT,
602                                  gconf_enum_to_string (pressure_unit_enum_map, new_unit),
603                                  NULL);
604       
605    gweather_dialog_update (gw_applet);
606}
607
608static void dist_combo_changed_cb (GtkComboBox *combo, gpointer data)
609{
610    GWeatherApplet *gw_applet = data;
611    DistanceUnit   new_unit, *old_unit;
612       
613        g_return_if_fail(gw_applet != NULL);
614   
615        old_unit = &gw_applet->gweather_pref.distance_unit;     
616        new_unit = gtk_combo_box_get_active(combo) + 1;
617
618        if (new_unit == *old_unit)
619        return;
620
621    parse_distance_string (gconf_enum_to_string (distance_unit_enum_map, new_unit), &(gw_applet->gweather_pref));
622
623    panel_applet_gconf_set_string(gw_applet->applet, GCONF_DISTANCE_UNIT,
624                                  gconf_enum_to_string (distance_unit_enum_map, new_unit),
625                                  NULL);
626       
627    gweather_dialog_update (gw_applet);
628}
629
630static void
631radar_toggled (GtkToggleButton *button, gpointer data)
632{
633    GWeatherApplet *gw_applet = data;
634    gboolean toggled;
635   
636    toggled = gtk_toggle_button_get_active(button);
637    gw_applet->gweather_pref.radar_enabled = toggled;
638    panel_applet_gconf_set_bool(gw_applet->applet, "enable_radar_map", toggled, NULL);
639    soft_set_sensitive (gw_applet->pref_basic_radar_url_btn, toggled);
640    if (toggled == FALSE || gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (gw_applet->pref_basic_radar_url_btn)) == TRUE)
641            soft_set_sensitive (gw_applet->pref_basic_radar_url_hbox, toggled);
642}
643
644static void
645use_radar_url_toggled (GtkToggleButton *button, gpointer data)
646{
647    GWeatherApplet *gw_applet = data;
648    gboolean toggled;
649   
650    toggled = gtk_toggle_button_get_active(button);
651    gw_applet->gweather_pref.use_custom_radar_url = toggled;
652    panel_applet_gconf_set_bool(gw_applet->applet, "use_custom_radar_url", toggled, NULL);
653    soft_set_sensitive (gw_applet->pref_basic_radar_url_hbox, toggled);
654}
655
656static gboolean
657radar_url_changed (GtkWidget *widget, GdkEventFocus *event, gpointer data)
658{
659    GWeatherApplet *gw_applet = data;
660    gchar *text;
661   
662    text = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1);
663   
664    if (gw_applet->gweather_pref.radar)
665        g_free (gw_applet->gweather_pref.radar);
666       
667    if (text) {
668        gw_applet->gweather_pref.radar = g_strdup (text);
669        g_free (text);
670    }
671    else
672        gw_applet->gweather_pref.radar = NULL;
673       
674    panel_applet_gconf_set_string (gw_applet->applet, "radar",
675                                   gw_applet->gweather_pref.radar, NULL);
676                                   
677    return FALSE;
678                                   
679}
680
681static void
682update_interval_changed (GtkSpinButton *button, gpointer data)
683{
684    GWeatherApplet *gw_applet = data;
685   
686    gw_applet->gweather_pref.update_interval = gtk_spin_button_get_value_as_int(button)*60;
687    panel_applet_gconf_set_int(gw_applet->applet, "auto_update_interval",
688                               gw_applet->gweather_pref.update_interval, NULL);
689    if (gw_applet->timeout_tag > 0)
690        gtk_timeout_remove(gw_applet->timeout_tag);
691    if (gw_applet->gweather_pref.update_enabled)
692        gw_applet->timeout_tag = 
693                gtk_timeout_add (gw_applet->gweather_pref.update_interval * 1000,
694                                 timeout_cb, gw_applet);
695}
696
697static gboolean
698free_data (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
699{
700   GWeatherApplet *gw_applet = data;
701   WeatherLocation *location;
702   
703   gtk_tree_model_get (model, iter, GWEATHER_PREF_COL_POINTER, &location, -1);
704   if (!location)
705        return FALSE;
706
707   weather_location_free (location);
708   
709   return FALSE;
710}
711
712static void
713free_tree (GWeatherApplet *gw_applet)
714{
715   GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (gw_applet->pref_tree));
716   
717   gtk_tree_model_foreach (model, free_data, gw_applet);
718}
719
720static void
721response_cb (GtkDialog *dialog, gint id, gpointer data)
722{
723    GWeatherApplet *gw_applet = data;
724 
725    if(id == GTK_RESPONSE_HELP){
726        help_cb (dialog);
727        return;
728    }
729    free_tree (gw_applet);
730    gtk_widget_destroy (GTK_WIDGET (dialog));
731    gw_applet->pref = NULL;
732#if 0
733    /* refresh the applet incase the location has changed */
734    gweather_update(gw_applet);
735#endif
736}
737
738static GtkWidget *
739create_hig_catagory (GtkWidget *main_box, gchar *title)
740{
741        GtkWidget *vbox, *vbox2, *hbox;
742        GtkWidget *label;
743        gchar *tmp;
744       
745        vbox = gtk_vbox_new (FALSE, 6);
746        gtk_box_pack_start (GTK_BOX (main_box), vbox, FALSE, FALSE, 0);
747
748        tmp = g_strdup_printf ("<b>%s</b>", title);
749        label = gtk_label_new (NULL);
750        gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
751        gtk_label_set_markup (GTK_LABEL (label), tmp);
752        g_free (tmp);
753        gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, FALSE, 0);
754       
755        hbox = gtk_hbox_new (FALSE, 0);
756        gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
757       
758        label = gtk_label_new ("    ");
759        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
760       
761        vbox2 = gtk_vbox_new (FALSE, 6);
762        gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
763
764        return vbox2;           
765}
766
767static void gweather_pref_create (GWeatherApplet *gw_applet)
768{
769    GtkWidget *pref_vbox;
770    GtkWidget *pref_notebook;
771#ifdef RADARMAP
772    GtkWidget *radar_toggle_hbox;
773#endif /* RADARMAP */
774    GtkWidget *pref_basic_update_alignment;
775    GtkWidget *pref_basic_update_lbl;
776    GtkWidget *pref_basic_update_hbox;
777    GtkObject *pref_basic_update_spin_adj;
778    GtkWidget *pref_basic_update_sec_lbl;
779    GtkWidget *pref_basic_note_lbl;
780    GtkWidget *pref_net_note_lbl;   
781    GtkWidget *pref_loc_hbox;
782    GtkWidget *pref_loc_note_lbl;
783    GtkWidget *scrolled_window;
784    GtkWidget *label, *value_hbox, *tree_label;
785    GtkTreeStore *model;
786    GtkTreeSelection *selection;
787    GtkWidget *pref_basic_vbox;
788    GtkWidget *vbox;
789    GtkWidget *frame;
790    GtkWidget *temp_label;
791    GtkWidget *temp_combo;
792    GtkWidget *speed_label;
793    GtkWidget *speed_combo;     
794    GtkWidget *pres_label;
795    GtkWidget *pres_combo;
796    GtkWidget *dist_label;
797    GtkWidget *dist_combo;
798    GtkWidget *unit_table;     
799   
800    gw_applet->pref = gtk_dialog_new_with_buttons (_("Weather Preferences"), NULL,
801                                                   GTK_DIALOG_DESTROY_WITH_PARENT,
802                                                   GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
803                                                   GTK_STOCK_HELP, GTK_RESPONSE_HELP,
804                                                   NULL);
805
806    gtk_dialog_set_default_response (GTK_DIALOG (gw_applet->pref), GTK_RESPONSE_CLOSE);
807    gtk_dialog_set_has_separator (GTK_DIALOG (gw_applet->pref), FALSE);
808    gtk_container_set_border_width (GTK_CONTAINER (gw_applet->pref), 5);
809    gtk_window_set_resizable (GTK_WINDOW (gw_applet->pref), FALSE);
810    gtk_window_set_screen (GTK_WINDOW (gw_applet->pref),
811                           gtk_widget_get_screen (GTK_WIDGET (gw_applet->applet)));
812
813    pref_vbox = GTK_DIALOG (gw_applet->pref)->vbox;
814    gtk_box_set_spacing (GTK_BOX (pref_vbox), 2);
815    gtk_widget_show (pref_vbox);
816
817    pref_notebook = gtk_notebook_new ();
818    gtk_container_set_border_width (GTK_CONTAINER (pref_notebook), 5);
819    gtk_widget_show (pref_notebook);
820    gtk_box_pack_start (GTK_BOX (pref_vbox), pref_notebook, TRUE, TRUE, 0);
821
822  /*
823   * General settings page.
824   */
825
826    pref_basic_vbox = gtk_vbox_new (FALSE, 18);
827    gtk_container_set_border_width (GTK_CONTAINER (pref_basic_vbox), 12);
828    gtk_container_add (GTK_CONTAINER (pref_notebook), pref_basic_vbox);
829
830    pref_basic_update_alignment = gtk_alignment_new (0, 0.5, 0, 1);
831    gtk_widget_show (pref_basic_update_alignment);
832
833    gw_applet->pref_basic_update_btn = gtk_check_button_new_with_mnemonic (_("_Automatically update every:"));
834    gtk_widget_show (gw_applet->pref_basic_update_btn);
835    gtk_container_add (GTK_CONTAINER (pref_basic_update_alignment), gw_applet->pref_basic_update_btn);
836    g_signal_connect (G_OBJECT (gw_applet->pref_basic_update_btn), "toggled",
837                      G_CALLBACK (auto_update_toggled), gw_applet);
838    if ( ! key_writable (gw_applet->applet, "auto_update"))
839            hard_set_sensitive (gw_applet->pref_basic_update_btn, FALSE);
840
841    /* Temperature Unit */
842    temp_label = gtk_label_new_with_mnemonic (_("_Temperature Unit:"));
843    gtk_label_set_use_markup (GTK_LABEL (temp_label), TRUE);
844    gtk_label_set_justify (GTK_LABEL (temp_label), GTK_JUSTIFY_LEFT);
845    gtk_misc_set_alignment (GTK_MISC (temp_label), 0, 0.5);
846    gtk_widget_show (temp_label);
847
848    temp_combo = gtk_combo_box_new_text ();
849        gw_applet->pref_basic_temp_combo = temp_combo;
850    gtk_label_set_mnemonic_widget (GTK_LABEL (temp_label), temp_combo);
851    gtk_combo_box_append_text (GTK_COMBO_BOX (temp_combo), _("Default"));
852    gtk_combo_box_append_text (GTK_COMBO_BOX (temp_combo), _("Kelvin"));
853    /* TRANSLATORS: Celsius is sometimes referred Centigrade */
854    gtk_combo_box_append_text (GTK_COMBO_BOX (temp_combo), _("Celsius"));
855    gtk_combo_box_append_text (GTK_COMBO_BOX (temp_combo), _("Fahrenheit"));
856        gtk_widget_show (temp_combo);
857               
858    if ( ! key_writable (gw_applet->applet, GCONF_TEMP_UNIT))
859        hard_set_sensitive (gw_applet->pref_basic_temp_combo, FALSE);
860       
861    /* Speed Unit */
862    speed_label = gtk_label_new_with_mnemonic (_("_Wind Speed Unit:"));
863    gtk_label_set_use_markup (GTK_LABEL (speed_label), TRUE);
864    gtk_label_set_justify (GTK_LABEL (speed_label), GTK_JUSTIFY_LEFT);
865    gtk_misc_set_alignment (GTK_MISC (speed_label), 0, 0.5);
866    gtk_widget_show (speed_label);
867
868    speed_combo = gtk_combo_box_new_text ();
869    gw_applet->pref_basic_speed_combo = speed_combo;
870    gtk_label_set_mnemonic_widget (GTK_LABEL (speed_label), speed_combo);
871    gtk_combo_box_append_text (GTK_COMBO_BOX (speed_combo), _("Default"));
872    /* TRANSLATOR: The wind speed unit "meters per second" */   
873    gtk_combo_box_append_text (GTK_COMBO_BOX (speed_combo), _("m/s"));
874    /* TRANSLATOR: The wind speed unit "kilometers per hour" */
875    gtk_combo_box_append_text (GTK_COMBO_BOX (speed_combo), _("km/h"));
876    /* TRANSLATOR: The wind speed unit "miles per hour" */
877    gtk_combo_box_append_text (GTK_COMBO_BOX (speed_combo), _("mph"));
878    /* TRANSLATOR: The wind speed unit "knots" */
879        gtk_combo_box_append_text (GTK_COMBO_BOX (speed_combo), _("knots"));
880        gtk_widget_show (speed_combo);
881
882    if ( ! key_writable (gw_applet->applet, GCONF_SPEED_UNIT))
883        hard_set_sensitive (gw_applet->pref_basic_speed_combo, FALSE);
884
885    /* Pressure Unit */
886    pres_label = gtk_label_new_with_mnemonic (_("_Pressure Unit:"));
887    gtk_label_set_use_markup (GTK_LABEL (pres_label), TRUE);
888    gtk_label_set_justify (GTK_LABEL (pres_label), GTK_JUSTIFY_LEFT);
889    gtk_misc_set_alignment (GTK_MISC (pres_label), 0, 0.5);
890    gtk_widget_show (pres_label);
891
892    pres_combo = gtk_combo_box_new_text ();
893        gw_applet->pref_basic_pres_combo = pres_combo;
894    gtk_label_set_mnemonic_widget (GTK_LABEL (pres_label), pres_combo);
895    gtk_combo_box_append_text (GTK_COMBO_BOX (pres_combo), _("Default"));
896    /* TRANSLATOR: The pressure unit "kiloPascals" */
897    gtk_combo_box_append_text (GTK_COMBO_BOX (pres_combo), _("kPa"));
898    /* TRANSLATOR: The pressure unit "hectoPascals" */
899    gtk_combo_box_append_text (GTK_COMBO_BOX (pres_combo), _("hPa"));
900    /* TRANSLATOR: The pressure unit "millibars" */
901    gtk_combo_box_append_text (GTK_COMBO_BOX (pres_combo), _("mb"));
902    /* TRANSLATOR: The pressure unit "millibars of mercury" */
903    gtk_combo_box_append_text (GTK_COMBO_BOX (pres_combo), _("mmHg"));
904    /* TRANSLATOR: The pressure unit "inches of mercury" */
905    gtk_combo_box_append_text (GTK_COMBO_BOX (pres_combo), _("inHg"));
906    gtk_widget_show (pres_combo);
907
908    if ( ! key_writable (gw_applet->applet, GCONF_PRESSURE_UNIT))
909        hard_set_sensitive (gw_applet->pref_basic_pres_combo, FALSE);
910
911    /* Distance Unit */
912    dist_label = gtk_label_new_with_mnemonic (_("_Visibility Unit:"));
913    gtk_label_set_use_markup (GTK_LABEL (dist_label), TRUE);
914    gtk_label_set_justify (GTK_LABEL (dist_label), GTK_JUSTIFY_LEFT);
915    gtk_misc_set_alignment (GTK_MISC (dist_label), 0, 0.5);
916    gtk_widget_show (dist_label);
917
918    dist_combo = gtk_combo_box_new_text ();
919        gw_applet->pref_basic_dist_combo = dist_combo;
920    gtk_label_set_mnemonic_widget (GTK_LABEL (dist_label), dist_combo);
921    gtk_combo_box_append_text (GTK_COMBO_BOX (dist_combo), _("Default"));
922    /* TRANSLATOR: The distance unit "meters" */
923    gtk_combo_box_append_text (GTK_COMBO_BOX (dist_combo), _("meters"));
924    /* TRANSLATOR: The distance unit "kilometers" */
925    gtk_combo_box_append_text (GTK_COMBO_BOX (dist_combo), _("km"));
926    /* TRANSLATOR: The distance unit "miles" */
927    gtk_combo_box_append_text (GTK_COMBO_BOX (dist_combo), _("miles"));
928        gtk_widget_show (dist_combo);
929
930    if ( ! key_writable (gw_applet->applet, GCONF_DISTANCE_UNIT))
931        hard_set_sensitive (gw_applet->pref_basic_dist_combo, FALSE);
932       
933        unit_table = gtk_table_new(5, 3, FALSE);
934        gtk_table_set_row_spacings(GTK_TABLE(unit_table), 6);
935        gtk_table_attach_defaults(GTK_TABLE(unit_table), temp_label,  0, 1, 0, 1);
936        gtk_table_attach_defaults(GTK_TABLE(unit_table), temp_combo,  1, 2, 0, 1);
937        gtk_table_attach_defaults(GTK_TABLE(unit_table), speed_label, 0, 1, 1, 2);
938        gtk_table_attach_defaults(GTK_TABLE(unit_table), speed_combo, 1, 2, 1, 2);
939        gtk_table_attach_defaults(GTK_TABLE(unit_table), pres_label,  0, 1, 2, 3);
940        gtk_table_attach_defaults(GTK_TABLE(unit_table), pres_combo,  1, 2, 2, 3);
941        gtk_table_attach_defaults(GTK_TABLE(unit_table), dist_label,  0, 1, 3, 4);
942        gtk_table_attach_defaults(GTK_TABLE(unit_table), dist_combo,  1, 2, 3, 4);
943        gtk_widget_show(unit_table);
944       
945        g_signal_connect (temp_combo, "changed", G_CALLBACK (temp_combo_changed_cb), gw_applet);
946        g_signal_connect (speed_combo, "changed", G_CALLBACK (speed_combo_changed_cb), gw_applet);
947        g_signal_connect (dist_combo, "changed", G_CALLBACK (dist_combo_changed_cb), gw_applet);
948        g_signal_connect (pres_combo, "changed", G_CALLBACK (pres_combo_changed_cb), gw_applet);
949
950       
951#ifdef RADARMAP
952    gw_applet->pref_basic_radar_btn = gtk_check_button_new_with_mnemonic (_("Enable _radar map"));
953    gtk_widget_show (gw_applet->pref_basic_radar_btn);
954    g_signal_connect (G_OBJECT (gw_applet->pref_basic_radar_btn), "toggled",
955                      G_CALLBACK (radar_toggled), gw_applet);
956    if ( ! key_writable (gw_applet->applet, "enable_radar_map"))
957            hard_set_sensitive (gw_applet->pref_basic_radar_btn, FALSE);
958   
959    radar_toggle_hbox = gtk_hbox_new (FALSE, 12);
960    gtk_widget_show (radar_toggle_hbox);
961   
962    label = gtk_label_new ("    ");
963    gtk_widget_show (label);
964    gtk_box_pack_start (GTK_BOX (radar_toggle_hbox), label, FALSE, FALSE, 0);
965                                             
966    gw_applet->pref_basic_radar_url_btn = gtk_check_button_new_with_mnemonic (_("Use _custom address for radar map"));
967    gtk_widget_show (gw_applet->pref_basic_radar_url_btn);
968    gtk_box_pack_start (GTK_BOX (radar_toggle_hbox), gw_applet->pref_basic_radar_url_btn, FALSE, FALSE, 0);
969
970    g_signal_connect (G_OBJECT (gw_applet->pref_basic_radar_url_btn), "toggled",
971                      G_CALLBACK (use_radar_url_toggled), gw_applet);
972    if ( ! key_writable (gw_applet->applet, "use_custom_radar_url"))
973            hard_set_sensitive (gw_applet->pref_basic_radar_url_btn, FALSE);
974                     
975    gw_applet->pref_basic_radar_url_hbox = gtk_hbox_new (FALSE, 12);
976    gtk_widget_show (gw_applet->pref_basic_radar_url_hbox);
977
978    label = gtk_label_new ("    ");
979    gtk_widget_show (label);
980    gtk_box_pack_start (GTK_BOX (gw_applet->pref_basic_radar_url_hbox),
981                        label, FALSE, FALSE, 0);
982                       
983    label = gtk_label_new_with_mnemonic (_("A_ddress:"));
984    gtk_widget_show (label);
985    gtk_box_pack_start (GTK_BOX (gw_applet->pref_basic_radar_url_hbox),
986                        label, FALSE, FALSE, 0);
987    gw_applet->pref_basic_radar_url_entry = gtk_entry_new ();
988    gtk_widget_show (gw_applet->pref_basic_radar_url_entry);
989    gtk_box_pack_start (GTK_BOX (gw_applet->pref_basic_radar_url_hbox),
990                        gw_applet->pref_basic_radar_url_entry, TRUE, TRUE, 0);   
991    g_signal_connect (G_OBJECT (gw_applet->pref_basic_radar_url_entry), "focus_out_event",
992                      G_CALLBACK (radar_url_changed), gw_applet);
993    if ( ! key_writable (gw_applet->applet, "radar"))
994            hard_set_sensitive (gw_applet->pref_basic_radar_url_entry, FALSE);
995#endif /* RADARMAP */
996
997    frame = create_hig_catagory (pref_basic_vbox, _("Update"));
998
999    pref_basic_update_hbox = gtk_hbox_new (FALSE, 12);
1000
1001    pref_basic_update_lbl = gtk_label_new_with_mnemonic (_("_Automatically update every:"));
1002    gtk_widget_show (pref_basic_update_lbl);
1003   
1004
1005/*
1006    gtk_label_set_justify (GTK_LABEL (pref_basic_update_lbl), GTK_JUSTIFY_RIGHT);
1007    gtk_misc_set_alignment (GTK_MISC (pref_basic_update_lbl), 1, 0.5);
1008*/
1009
1010    gtk_widget_show (pref_basic_update_hbox);
1011
1012    pref_basic_update_spin_adj = gtk_adjustment_new (30, 1, 3600, 5, 25, 1);
1013    gw_applet->pref_basic_update_spin = gtk_spin_button_new (GTK_ADJUSTMENT (pref_basic_update_spin_adj), 1, 0);
1014    gtk_widget_show (gw_applet->pref_basic_update_spin);
1015
1016    gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (gw_applet->pref_basic_update_spin), TRUE);
1017    gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (gw_applet->pref_basic_update_spin), GTK_UPDATE_IF_VALID);
1018    g_signal_connect (G_OBJECT (gw_applet->pref_basic_update_spin), "value_changed",
1019                      G_CALLBACK (update_interval_changed), gw_applet);
1020   
1021    pref_basic_update_sec_lbl = gtk_label_new (_("minutes"));
1022    gtk_widget_show (pref_basic_update_sec_lbl);
1023    if ( ! key_writable (gw_applet->applet, "auto_update_interval")) {
1024            hard_set_sensitive (gw_applet->pref_basic_update_spin, FALSE);
1025            hard_set_sensitive (pref_basic_update_sec_lbl, FALSE);
1026    }
1027
1028    value_hbox = gtk_hbox_new (FALSE, 6);
1029
1030    gtk_box_pack_start (GTK_BOX (pref_basic_update_hbox), pref_basic_update_alignment, FALSE, TRUE, 0);
1031    gtk_box_pack_start (GTK_BOX (pref_basic_update_hbox), value_hbox, FALSE, FALSE, 0);
1032    gtk_box_pack_start (GTK_BOX (value_hbox), gw_applet->pref_basic_update_spin, FALSE, FALSE, 0);
1033    gtk_box_pack_start (GTK_BOX (value_hbox), pref_basic_update_sec_lbl, FALSE, FALSE, 0);
1034
1035    gtk_container_add (GTK_CONTAINER (frame), pref_basic_update_hbox);
1036
1037    frame = create_hig_catagory (pref_basic_vbox, _("Display"));
1038
1039    vbox = gtk_vbox_new (FALSE, 6);
1040
1041        gtk_box_pack_start (GTK_BOX (vbox), unit_table, TRUE, TRUE, 0);
1042
1043#ifdef RADARMAP
1044    gtk_box_pack_start (GTK_BOX (vbox), gw_applet->pref_basic_radar_btn, TRUE, TRUE, 0);
1045    gtk_box_pack_start (GTK_BOX (vbox), radar_toggle_hbox, TRUE, TRUE, 0);
1046    gtk_box_pack_start (GTK_BOX (vbox), gw_applet->pref_basic_radar_url_hbox, TRUE,
1047                        TRUE, 0);
1048#endif /* RADARMAP */
1049
1050    gtk_container_add (GTK_CONTAINER (frame), vbox);
1051
1052    pref_basic_note_lbl = gtk_label_new (_("General"));
1053    gtk_widget_show (pref_basic_note_lbl);
1054    gtk_notebook_set_tab_label (GTK_NOTEBOOK (pref_notebook),
1055                                gtk_notebook_get_nth_page (GTK_NOTEBOOK (pref_notebook), 0),
1056                                pref_basic_note_lbl);
1057
1058  /*
1059   * Location page.
1060   */
1061    pref_loc_hbox = gtk_vbox_new (FALSE, 6);
1062    gtk_container_set_border_width (GTK_CONTAINER (pref_loc_hbox), 12);
1063    gtk_container_add (GTK_CONTAINER (pref_notebook), pref_loc_hbox);
1064
1065    tree_label = gtk_label_new_with_mnemonic (_("_Select a location:"));
1066    gtk_misc_set_alignment (GTK_MISC (tree_label), 0.0, 0.5);
1067    gtk_box_pack_start (GTK_BOX (pref_loc_hbox), tree_label, FALSE, FALSE, 0);
1068
1069    scrolled_window = gtk_scrolled_window_new (NULL, NULL);
1070    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN);
1071    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
1072                                    GTK_POLICY_AUTOMATIC,
1073                                    GTK_POLICY_AUTOMATIC);
1074
1075    model = gtk_tree_store_new (GWEATHER_PREF_NUM_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER);
1076    gw_applet->pref_tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
1077    gtk_label_set_mnemonic_widget (GTK_LABEL (tree_label), GTK_WIDGET (gw_applet->pref_tree));
1078    gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (gw_applet->pref_tree), FALSE);
1079    g_object_unref (G_OBJECT (model));
1080   
1081    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gw_applet->pref_tree));
1082    g_signal_connect (G_OBJECT (selection), "changed",
1083                      G_CALLBACK (row_selected_cb), gw_applet);
1084   
1085    gtk_container_add (GTK_CONTAINER (scrolled_window), gw_applet->pref_tree);
1086    gtk_widget_show (gw_applet->pref_tree);
1087    gtk_widget_show (scrolled_window);
1088    gtk_box_pack_start (GTK_BOX (pref_loc_hbox), scrolled_window, TRUE, TRUE, 0);
1089    load_locations(gw_applet);
1090   
1091    if ( ! key_writable (gw_applet->applet, "location0")) {
1092            hard_set_sensitive (scrolled_window, FALSE);
1093    }
1094
1095    pref_loc_note_lbl = gtk_label_new (_("Location"));
1096    gtk_widget_show (pref_loc_note_lbl);
1097    gtk_notebook_set_tab_label (GTK_NOTEBOOK (pref_notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (pref_notebook), 1), pref_loc_note_lbl);
1098
1099
1100    g_signal_connect (G_OBJECT (gw_applet->pref), "response",
1101                      G_CALLBACK (response_cb), gw_applet);
1102   
1103    gweather_pref_set_accessibility (gw_applet);
1104    gtk_label_set_mnemonic_widget (GTK_LABEL (pref_basic_update_sec_lbl), gw_applet->pref_basic_update_spin);
1105    gtk_label_set_mnemonic_widget (GTK_LABEL (label), gw_applet->pref_basic_radar_url_entry);
1106
1107    gtk_widget_show_all (gw_applet->pref);
1108}
1109
1110void gweather_pref_load (GWeatherApplet *gw_applet)
1111{
1112    GError *error = NULL;
1113        gchar  *gconf_str = NULL;
1114        gint   value = 0;
1115        GWeatherPrefs *prefs = &(gw_applet->gweather_pref);
1116
1117        /* Assume we use unit defaults */
1118        prefs->use_temperature_default = TRUE;
1119    prefs->use_speed_default = TRUE;
1120    prefs->use_pressure_default = TRUE;
1121    prefs->use_distance_default = TRUE;
1122       
1123    gw_applet->gweather_pref.update_interval =
1124        panel_applet_gconf_get_int(gw_applet->applet, "auto_update_interval", &error);
1125    if (error) {
1126        g_print ("%s \n", error->message);
1127        g_error_free (error);
1128        error = NULL;
1129    }
1130    gw_applet->gweather_pref.update_interval = MAX (gw_applet->gweather_pref.update_interval, 60);
1131    gw_applet->gweather_pref.update_enabled =
1132        panel_applet_gconf_get_bool(gw_applet->applet, "auto_update", NULL);
1133    gw_applet->gweather_pref.detailed =
1134        panel_applet_gconf_get_bool(gw_applet->applet, "enable_detailed_forecast", NULL);
1135    gw_applet->gweather_pref.radar_enabled =
1136        panel_applet_gconf_get_bool(gw_applet->applet, "enable_radar_map", NULL);
1137    gw_applet->gweather_pref.location = weather_location_config_read(gw_applet->applet);
1138    gw_applet->gweather_pref.use_custom_radar_url =
1139        panel_applet_gconf_get_bool(gw_applet->applet, "use_custom_radar_url", NULL);
1140    gw_applet->gweather_pref.radar = panel_applet_gconf_get_string (gw_applet->applet,
1141                                                                    "radar",
1142                                                                    NULL);
1143   
1144    gconf_str = panel_applet_gconf_get_string (gw_applet->applet, GCONF_TEMP_UNIT, NULL);
1145    parse_temp_string(gconf_str, prefs);
1146        g_free (gconf_str);
1147   
1148               
1149    gconf_str = panel_applet_gconf_get_string (gw_applet->applet, GCONF_SPEED_UNIT, NULL);
1150        parse_speed_string(gconf_str, prefs);
1151        g_free (gconf_str);
1152                       
1153    gconf_str = panel_applet_gconf_get_string (gw_applet->applet, GCONF_PRESSURE_UNIT, NULL);
1154        parse_pressure_string(gconf_str, prefs);
1155        g_free (gconf_str);
1156
1157    gconf_str = panel_applet_gconf_get_string (gw_applet->applet, GCONF_DISTANCE_UNIT, NULL);
1158        parse_distance_string(gconf_str, prefs);
1159        g_free (gconf_str);
1160       
1161    return;
1162}
1163
1164static void help_cb (GtkDialog *dialog)
1165{
1166    GError *error = NULL;
1167
1168    gnome_help_display_on_screen (
1169                "gweather", "gweather-settings",
1170                gtk_window_get_screen (GTK_WINDOW (dialog)),
1171                &error);
1172
1173    if (error) { /* FIXME: the user needs to see this error */
1174        g_warning ("help error: %s\n", error->message);
1175        g_error_free (error);
1176        error = NULL;
1177    }
1178}
1179
1180void gweather_pref_run (GWeatherApplet *gw_applet)
1181{
1182    /* Only one preferences window at a time */
1183    if (gw_applet->pref) {
1184        gtk_window_present (GTK_WINDOW (gw_applet->pref));
1185        return;
1186    }
1187
1188    gweather_pref_create(gw_applet);
1189    update_dialog(gw_applet);
1190
1191   
1192}
Note: See TracBrowser for help on using the repository browser.