1
/* functions related to selecting time zones */
8
#include "gworldclock.h"
12
#define _(A) gettext(A)
15
void DeleteZone( GtkWidget *w, gpointer clocklist )
19
gchar *button[]={"OK"};
20
GtkTreeModel *clocklistModel;
23
if ( gtk_tree_selection_get_selected(
24
gtk_tree_view_get_selection( clocklist ),
28
gtk_list_store_remove( GTK_LIST_STORE(clocklistModel), &iter );
30
resizeWindow( gtk_widget_get_toplevel( GTK_WIDGET(clocklist) ),
35
title = g_string_new(_("Delete Zone"));
36
msg = g_string_new(_("No zone chosen for deleting."));
37
showMessageDialog( msg->str, GTK_MESSAGE_WARNING );
38
g_string_free(msg,TRUE);
39
g_string_free(title,TRUE);
44
/* Save list of time zones to configfile */
45
gint SaveZones(GtkWidget *w, gpointer clocklist)
48
extern GString *configfile;
51
gchar *description, *timezone;
52
GtkTreeModel *clocklistModel;
54
gboolean gotIter = FALSE;
56
if ( !(cf=fopen(configfile->str,"w")) ) {
60
clocklistModel = gtk_tree_view_get_model( clocklist );
61
gotIter = gtk_tree_model_get_iter_first(clocklistModel, &iter);
65
gtk_tree_model_get( clocklistModel, &iter,
67
TZ_DESCRIPTION, &description,
70
/* only write description if there is one! */
71
if(strlen(description)==0)
72
fprintf(cf,"%s\n", timezone );
74
fprintf(cf,"%s \"%s\"\n", timezone, description );
78
gotIter = gtk_tree_model_iter_next( clocklistModel, &iter );
82
return ( ! fclose( cf ) );
85
/* Handle "rows_reordered" signal, indicating the rows in the clock have been
87
/* Note this callback function does not get called for some reason,
88
I don't know why. A bug in GTK+ ?
89
You will have to save the reordered list by hand for the time being.
91
void registerReorderedRows( GtkTreeModel* clocklistModel,
99
/* mark clocklist as "changed" */
103
gint CodeInList(gchar *code, GSList *List)
105
/* can't use g_slist_find, unfortunately, since the data in the list is both the
106
country code and (unknown) country name
113
if ( ! strcmp(code,((NameCodeType *)item->data)->code) )
114
return TRUE; /* found match */
120
GSList* AddNameCodeEntry(gchar *code, gchar *name, GSList *List)
124
entry = g_malloc0(sizeof(NameCodeType));
126
g_print(_("Could not create list: %s"),g_strerror(errno));
127
entry->name = g_strdup(name);
128
entry->code = g_strdup(code);
129
List = g_slist_append(List, (gpointer)entry);
131
/* we don't free entry here do we? It's on record and is only to be freed when
132
the item is released from the list */
136
/* the documentation is not too clear about allocating and free lists */
137
/* does g_slist_free deallocate all the links in the list, or just the first? */
138
/* I will assume it does the entire list */
139
void ClearNameCodeList(GSList **List)
146
g_free( ((NameCodeType *)item->data)->name );
147
g_free( ((NameCodeType *)item->data)->code );
155
/* for given continent, find corresponding countries as identified in ZONE_TABLE
156
and prepare list of country name using COUNTRY_TABLE
159
GSList* FetchCountries(gchar *continent)
162
GString *title, *msg;
163
gchar *button[]={"OK"};
165
gchar *codec, *codez, *name;
168
if (strlen(continent)==0 )
171
if ( !(fpz=fopen(ZONE_TABLE,"r")) ) {
172
title = g_string_new(_("Read Zone Table"));
173
msg = g_string_new(NULL);
174
g_string_sprintf(msg,_(" Error reading zone table \"%s\": \n %s \nHow very sad.\n"),
175
ZONE_TABLE , g_strerror(errno) );
176
showMessageDialog( msg->str, GTK_MESSAGE_ERROR );
177
g_string_free(msg,TRUE);
178
g_string_free(title,TRUE);
180
if ( !(fpc=fopen(COUNTRY_TABLE,"r")) ) {
181
title = g_string_new(_("Read Zone Table"));
182
msg = g_string_new(NULL);
183
g_string_sprintf(msg,_(" Error reading country table \"%s\": \n %s \nHow very sad.\n"),
184
COUNTRY_TABLE , g_strerror(errno) );
185
showMessageDialog( msg->str, GTK_MESSAGE_ERROR );
186
g_string_free(msg,TRUE);
187
g_string_free(title,TRUE);
191
while(fgets(line,500,fpz)) {
192
if (line[0] != '#') {
194
/* check for continent in TZ value (third item on the line in ZONE_TABLE)
195
Also read country code at beginning of zone table entry.
196
Strictly this is only 2 characters, but I will allow for a whole string
197
(in my opinion 3 character would be more meaningful. The standard sux */
198
sscanf(line,"%as %*s %as",&codez,&name);
199
if(strstr(name,continent)) {
200
if(!CodeInList(codez,Countries)) {
203
while(fgets(line,500,fpc)) {
204
if (line[0] != '#') {
206
/* first, identify country */
207
if(sscanf(line,"%as",&codec)==1) {
208
if (!strcmp(codez,codec)) {
210
/* then extract name as entire string to \0 after tab */
211
/* (first make sure \n in line is reset to \0) */
212
name = (gchar *) strchr(line,'\n');
214
name = (gchar *) strchr(line,'\t');
217
Countries = AddNameCodeEntry(codec,name,Countries);
238
/* from given country code ("*country"), find list of regions in ZONE_TABLE */
239
/* input: country is the two-letter country code from ISO3166 */
240
GSList* FetchRegions(gchar *country)
243
GString *title, *msg;
244
gchar *button[]={"OK"};
246
gchar *code, *TZvalue, *region, *ptr;
249
if (strlen(country)==0 )
252
if ( !(fp=fopen(ZONE_TABLE,"r")) ) {
253
title = g_string_new(_("Read Zone Table"));
254
msg = g_string_new(NULL);
255
g_string_sprintf(msg,_(" Error reading zone table \"%s\": \n %s \nHow very sad.\n"),
256
ZONE_TABLE , g_strerror(errno) );
257
showMessageDialog( msg->str, GTK_MESSAGE_ERROR );
258
g_string_free(msg,TRUE);
259
g_string_free(title,TRUE);
263
while(fgets(line,500,fp)) {
264
if (line[0] != '#') {
265
/* check for entries corresponding to country code value
266
(first item on the line in ZONE_TABLE)
267
Get name of region from third item on the line. */
268
/* alternatively we may want to get the description from the optional
269
fourth item, where available. Worry about that some other time */
270
sscanf(line,"%as %*s %as",&code,&TZvalue);
271
if(!strcmp(code,country)) {
272
/* region name is in format: continent/region
273
Extract the region part from the continent */
274
ptr = (gchar *) strchr(TZvalue,'/');
276
region = g_strdup((gchar*)(ptr+1));
278
region = g_strdup(TZvalue);
280
/* Some regions have an underscore '_' in place of space */
281
/* convert these to a real space */
282
while( (ptr=(gchar*)strchr(region,'_')) )
285
if(!CodeInList(TZvalue,Regions))
286
Regions = AddNameCodeEntry(TZvalue,region,Regions);
298
void UpdateCountries(GtkTreeSelection *selection, gpointer ZoneNotes)
305
GtkTreeModel *filteredStore;
308
GtkWidget *scrolled_window;
309
GtkTreeSelection *countrySelection;
311
AddZoneStruct *zoneData;
313
if (gtk_tree_selection_get_selected (selection, &model, &iter))
315
gtk_tree_model_get (model, &iter, CONTINENT_NAME, &continent, -1);
317
filteredStore = gtk_tree_view_get_model( gtk_tree_selection_get_tree_view(selection) );
318
store = gtk_tree_model_filter_get_model( GTK_TREE_MODEL_FILTER(filteredStore) );
319
path = gtk_tree_model_get_path( GTK_TREE_MODEL(filteredStore), &iter );
320
path = gtk_tree_model_filter_convert_path_to_child_path( GTK_TREE_MODEL_FILTER(filteredStore), path );
323
filteredStore = gtk_tree_model_filter_new( GTK_TREE_MODEL(store), path );
324
if ( path ) gtk_tree_path_free( path );
326
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(filteredStore),
330
GtkWidget *label = gtk_label_new( _("Countries") );
331
tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL(filteredStore));
332
gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(tree), FALSE );
333
gtk_widget_show(tree);
335
GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
336
GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes ("Name",
338
"text", COUNTRY_NAME,
340
gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
342
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
343
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
344
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
345
gtk_widget_show (scrolled_window);
346
gtk_container_add(GTK_CONTAINER(scrolled_window), tree);
348
gtk_notebook_remove_page( (GtkNotebook*)ZoneNotes, COUNTRY_NAME );
349
gtk_notebook_insert_page ( (GtkNotebook*)ZoneNotes, scrolled_window,
350
label, COUNTRY_NAME );
352
countrySelection = gtk_tree_view_get_selection( GTK_TREE_VIEW(tree) );
353
gtk_tree_selection_set_mode (countrySelection, GTK_SELECTION_SINGLE);
354
g_signal_connect (G_OBJECT (countrySelection), "changed",
355
G_CALLBACK (UpdateRegions),
358
zoneData = (AddZoneStruct*) g_object_get_data(G_OBJECT(ZoneNotes),ZONE_DATA);
359
zoneData->countryTreeView = GTK_TREE_VIEW(tree);
361
/* update region list straight away to match first country on
363
gtk_tree_model_get_iter_first(GTK_TREE_MODEL(filteredStore),
365
gtk_tree_selection_select_iter(countrySelection, &iter);
371
void UpdateRegions(GtkTreeSelection *selection, gpointer ZoneNotes)
378
GtkTreeModel *filteredStore;
381
GtkTreeSelection *regionSelection;
382
GtkWidget *scrolled_window;
384
AddZoneStruct *zoneData;
386
if (gtk_tree_selection_get_selected (selection, &model, &iter))
388
gtk_tree_model_get (model, &iter, COUNTRY_NAME, &country, -1);
390
filteredStore = gtk_tree_view_get_model( gtk_tree_selection_get_tree_view(selection) );
391
store = gtk_tree_model_filter_get_model( GTK_TREE_MODEL_FILTER(filteredStore) );
392
path = gtk_tree_model_get_path( GTK_TREE_MODEL(filteredStore), &iter );
393
path = gtk_tree_model_filter_convert_path_to_child_path( GTK_TREE_MODEL_FILTER(filteredStore), path );
396
filteredStore = gtk_tree_model_filter_new( GTK_TREE_MODEL(store), path );
397
if ( path ) gtk_tree_path_free( path );
399
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(filteredStore),
403
GtkWidget *label = gtk_label_new( _("Regions") );
404
tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL(filteredStore));
405
gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(tree), FALSE );
406
gtk_widget_show(tree);
408
GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
409
GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes ("Name",
413
gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
415
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
416
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
417
GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
418
gtk_widget_show (scrolled_window);
419
gtk_container_add(GTK_CONTAINER(scrolled_window), tree);
421
gtk_notebook_remove_page( (GtkNotebook*)ZoneNotes, REGION_NAME );
422
gtk_notebook_insert_page( (GtkNotebook*)ZoneNotes, scrolled_window,
423
label, REGION_NAME );
425
regionSelection = gtk_tree_view_get_selection(GTK_TREE_VIEW (tree));
426
gtk_tree_selection_set_mode (regionSelection, GTK_SELECTION_SINGLE);
427
g_signal_connect( G_OBJECT(regionSelection), "changed",
428
G_CALLBACK(SelectRegion),
429
g_object_get_data(G_OBJECT(ZoneNotes),ZONE_DATA));
431
g_signal_connect(G_OBJECT(tree),
432
"button_press_event",
433
G_CALLBACK(ButtonPressedInRegionList),
434
(gpointer)g_object_get_data(G_OBJECT(ZoneNotes),ZONE_DATA));
436
zoneData = (AddZoneStruct*) g_object_get_data(G_OBJECT(ZoneNotes),ZONE_DATA);
437
zoneData->regionTreeView = GTK_TREE_VIEW(tree);
443
void SelectRegion(GtkTreeSelection *selection, gpointer ZoneData)
447
gchar *description, *TZ;
449
if (gtk_tree_selection_get_selected (selection, &model, &iter))
451
gtk_tree_model_get (model, &iter, REGION_NAME, &description,
455
gtk_entry_set_text( (GtkEntry *)((AddZoneStruct*)ZoneData)->DescriptionEntry,
457
gtk_entry_set_text( (GtkEntry *)((AddZoneStruct*)ZoneData)->TZEntry, TZ);
459
g_free( description );
464
/* when left mouse button is double-clicked,
465
send "key-pressed-event" to one of the Entry boxes
466
which will be handled by adding the given zone.
467
We're assuming here that "select-row" preceded the double-click event */
468
gboolean ButtonPressedInRegionList (GtkWidget *regionTreeView,
469
GdkEventButton *event,
472
GdkEventKey *KeyEvent;
474
static GtkWidget *popup;
476
gboolean returnVal = FALSE;
478
if( (event->button==1) && ( event->type==GDK_2BUTTON_PRESS))
480
KeyEvent = (GdkEventKey*)g_malloc(sizeof(GdkEventKey));
481
KeyEvent->keyval=GDK_Return;
483
g_signal_emit_by_name( G_OBJECT( ((AddZoneStruct*)ZoneData)->TZEntry ),
484
"key-press-event", (GdkEvent*)KeyEvent, &return_val);
493
/* Initialises (preexisting) iter to the node for the given column
494
(whose value is identified by name) and returns TRUE. Iter is
495
invalid and FALSE returned, if there is no such name in the column.
497
gboolean findRow( GtkTreeModel *model, const gint column, const gchar *nameToMatch, GtkTreeIter *iter )
499
if( ! gtk_tree_model_get_iter_first( model, iter ) )
503
gtk_tree_model_get( model, iter, column, &name, -1 );
504
if ( name && !strcmp( nameToMatch, name ) )
511
while( gtk_tree_model_iter_next( model, iter) )
513
gtk_tree_model_get( model, iter, column, &name, -1 );
514
if ( name && !strcmp( nameToMatch, name ) )
526
/* Implements GtkTreeModelFilterVisibleFunc, making continent entries
529
gboolean FilterContinents(GtkTreeModel *model,
535
gchar *continentName;
539
gtk_tree_model_get( model, iter,
540
CONTINENT_NAME, &continentName,
541
COUNTRY_NAME, &countryName,
542
REGION_NAME, ®ionName,
545
visible = ( continentName && strlen(continentName)>0 ) &&
546
( (!countryName) || strlen(countryName)==0 ) &&
547
( (!regionName) || strlen(regionName)==0 ) ;
549
g_free( continentName );
550
g_free( countryName );
551
g_free( regionName );
556
gboolean FilterCountries(GtkTreeModel *model,
562
gtk_tree_model_get( model, iter,
563
COUNTRY_NAME, &countryName,
566
visible = ( countryName && strlen(countryName)>0 );
568
g_free( countryName );
573
gboolean FilterRegions(GtkTreeModel *model,
579
gtk_tree_model_get( model, iter,
580
REGION_NAME, ®ionName,
583
visible = ( regionName && strlen(regionName)>0 );
584
g_free( regionName );
590
/* zones are selected according to the method used in tzselect:
591
First the continent is chosen, then, if necessary, the country is chosen,
592
with countries being identified from the two-letter code in the
593
entries of [/usr/share/zoneinfo/]zone.tab (and country names taken from
594
iso3166.tab) Then the region (or city) of that country is identified, from
598
void PrepareZoneNotes(GtkWidget **ZoneNotes, AddZoneStruct *Zone)
601
GtkTreeIter continentIter, countryIter, regionIter, iter;
603
GtkTreeSelection *selection;
604
GSList *countryList, *countryItem;
605
GSList *regionList, *regionItem;
607
gchar *continentName, *ptr;
608
gchar *ContinentLabel=_("Continents");
609
gchar *CountryLabel=_("Countries");
610
gchar *RegionLabel=_("Regions");
613
/* collate date into a three-level tree.
614
The first level represents continents,
615
the second is regions/countries,
618
GtkTreeStore *store = gtk_tree_store_new (N_COLUMNS,
624
for( i=0; i<Ncontinents; i++)
626
gtk_tree_store_append (store, &continentIter, NULL);
627
gtk_tree_store_set (store, &continentIter,
628
CONTINENT_NAME, continents[i],
631
/* add countries within that continent */
632
continentName = g_strdup(continents[i]);
633
/* change "Americas" to "America" by wiping out the 's' */
634
if(!strcmp(continentName,"Americas"))
635
continentName[7]='\0';
637
/* similarly remove " Ocean" in "Pacific Ocean", etc
638
by making the ' ' a null character */
639
ptr = (gchar *) strchr(continentName,' ');
643
countryList=FetchCountries(continentName);
644
g_free(continentName);
645
countryItem = countryList;
648
name = ((NameCodeType *)countryItem->data)->name;
649
code = ((NameCodeType *)countryItem->data)->code;
650
gtk_tree_store_append (store, &countryIter, &continentIter);
651
gtk_tree_store_set (store, &countryIter,
657
/* add regions and cities within that country */
658
regionList=FetchRegions(code);
659
regionItem = regionList;
662
gtk_tree_store_append (store, ®ionIter, &countryIter);
663
name = ((NameCodeType *)regionItem->data)->name;
664
code = ((NameCodeType *)regionItem->data)->code;
666
gtk_tree_store_set (store, ®ionIter,
670
regionItem = regionItem->next;
672
ClearNameCodeList(®ionList);
674
countryItem = countryItem->next;
676
ClearNameCodeList(&countryList);
680
/* form the view of the tree */
683
GtkTreeModel* filteredStore = gtk_tree_model_filter_new( GTK_TREE_MODEL(store), NULL );
685
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(filteredStore),
690
*ZoneNotes = gtk_notebook_new ();
691
gtk_widget_show(*ZoneNotes);
692
g_object_set_data(G_OBJECT(*ZoneNotes), ZONE_DATA, Zone );
695
label = gtk_label_new (ContinentLabel);
698
tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL(filteredStore));
699
gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(tree), FALSE );
700
gtk_widget_show(tree);
702
GtkCellRenderer *renderer;
703
GtkTreeViewColumn *column;
705
renderer = gtk_cell_renderer_text_new ();
706
column = gtk_tree_view_column_new_with_attributes ("Name",
708
"text", CONTINENT_NAME,
710
gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
711
gtk_notebook_insert_page(GTK_NOTEBOOK(*ZoneNotes), tree,
712
label, CONTINENT_NAME );
714
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW (tree));
715
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
716
g_signal_connect (G_OBJECT (selection), "changed",
717
G_CALLBACK (UpdateCountries),
721
// countries, in default continent
722
gboolean gotIt = findRow( GTK_TREE_MODEL(filteredStore),
723
CONTINENT_NAME, defaultContinent, &continentIter );
726
gtk_tree_selection_select_iter( selection, &continentIter);
728
filteredStore = gtk_tree_view_get_model( Zone->countryTreeView );
729
selection = gtk_tree_view_get_selection( Zone->countryTreeView );
730
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
731
g_signal_connect (G_OBJECT (selection), "changed",
732
G_CALLBACK (UpdateRegions),
737
// regions, in default country
738
gotIt = findRow( GTK_TREE_MODEL(filteredStore), COUNTRY_NAME, defaultCountry, &countryIter );
740
gtk_tree_selection_select_iter( selection, &countryIter);
742
filteredStore = gtk_tree_view_get_model( Zone->regionTreeView );
743
selection = gtk_tree_view_get_selection( Zone->regionTreeView );
744
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
745
g_signal_connect (G_OBJECT(selection), "changed",
746
G_CALLBACK (SelectRegion),
747
g_object_get_data(G_OBJECT(*ZoneNotes),ZONE_DATA));
749
g_signal_connect(G_OBJECT(Zone->regionTreeView),
750
"button_press_event",
751
G_CALLBACK(ButtonPressedInRegionList),
754
/* default region/city */
755
gotIt = findRow( GTK_TREE_MODEL(filteredStore), REGION_NAME, defaultRegion, ®ionIter );
758
gtk_tree_selection_select_iter( selection, ®ionIter);
765
void AddZoneToList(GtkWidget *w, gpointer NewZone)
770
GtkTreeView *clocklist;
771
GtkListStore *clocklistModel;
772
GString *description;
776
description = g_string_new(
777
gtk_entry_get_text((GtkEntry *)((AddZoneStruct *)NewZone)->DescriptionEntry));
779
gtk_entry_get_text((GtkEntry *)((AddZoneStruct *)NewZone)->TZEntry));
781
/* check a time zone was given, if not, set to GMT */
782
/* GST-0 is the "formal" TZ value for GMT */
784
g_string_assign(TZ,"GST-0");
786
clocklist = (GtkTreeView *)((AddZoneStruct *)NewZone)->clocklist;
787
clocklistModel = GTK_LIST_STORE(gtk_tree_view_get_model( clocklist ));
788
gtk_list_store_append ( clocklistModel, &iter);
789
gtk_list_store_set ( clocklistModel, &iter,
791
TZ_DESCRIPTION, description->str,
794
/* make new zone visible */
795
gtk_tree_view_scroll_to_cell (clocklist,
796
gtk_tree_model_get_path(GTK_TREE_MODEL(clocklistModel), &iter),
798
/* attn: non use_align not implemented yet in GTK+
801
gtk_tree_selection_select_iter(
802
gtk_tree_view_get_selection( clocklist ),
805
SetTime((gpointer)clocklist);
808
g_string_free(description,TRUE);
809
g_string_free(TZ,TRUE);
812
void AddZone( GtkWidget *w, gpointer clocklist )
815
GtkWidget *vbox, *hbox;
816
GtkWidget *AddButton, *DoneButton;
817
GtkWidget *ZoneNotes;
819
GtkWidget *EntryDescription, *EntryTZ;
820
static AddZoneStruct NewZone;
822
NewZone.clocklist = (GObject *) clocklist;
824
EntryDescription = gtk_entry_new();
825
NewZone.DescriptionEntry = (GtkWidget *)EntryDescription;
826
EntryTZ = gtk_entry_new();
827
NewZone.TZEntry = (GtkWidget *) EntryTZ;
829
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
830
gtk_window_set_title ((GtkWindow *)window, _("Add Time Zone"));
831
gtk_window_position((GtkWindow *)window,GTK_WIN_POS_CENTER);
832
gtk_container_set_border_width (GTK_CONTAINER (window), 5);
834
vbox = gtk_vbox_new (FALSE, 0);
835
gtk_container_add (GTK_CONTAINER (window), vbox);
836
gtk_widget_show (vbox);
839
/* display zone choices as notebook:
840
Continents on one page, cities/countries on other
842
PrepareZoneNotes(&ZoneNotes,&NewZone);
843
gtk_box_pack_start (GTK_BOX (vbox), ZoneNotes, TRUE, FALSE, 5);
846
/* place zone in text entry box (allowing for manual entry if desired) */
847
hbox = gtk_hbox_new (FALSE, 0);
848
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 5);
849
gtk_widget_show (hbox);
852
/* box for text description of zone */
853
Frame = gtk_frame_new (_("Description"));
854
gtk_frame_set_shadow_type( (GtkFrame *)Frame, GTK_SHADOW_NONE);
855
gtk_box_pack_start (GTK_BOX (hbox), Frame, TRUE, FALSE, 5);
856
gtk_widget_show (Frame);
857
gtk_container_add (GTK_CONTAINER (Frame), EntryDescription);
858
/* where did the entry boxes get their default size from?
859
Not setting the size here (and below for TZ) makes the dialog box too large
860
Arguably too large, anyway - this is a question of taste of course */
861
gtk_widget_set_usize( GTK_WIDGET(EntryDescription),125,0);
862
gtk_widget_show (EntryDescription);
865
/* box for TZ value of zone */
866
Frame = gtk_frame_new (_("TZ value"));
867
gtk_frame_set_shadow_type( (GtkFrame *)Frame, GTK_SHADOW_NONE);
868
gtk_box_pack_start (GTK_BOX (hbox), Frame, TRUE, FALSE, 5);
869
gtk_widget_show (Frame);
870
gtk_container_add (GTK_CONTAINER (Frame), EntryTZ);
871
gtk_widget_set_usize( GTK_WIDGET(EntryTZ),125,0);
872
gtk_widget_show (EntryTZ);
874
/* buttons to accept zone, or exit */
875
hbox = gtk_hbox_new (FALSE, 0);
876
gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 5);
877
gtk_widget_show (hbox);
879
AddButton = gtk_button_new_with_label (_("Add Zone"));
880
g_signal_connect (G_OBJECT (AddButton), "clicked",
881
G_CALLBACK (AddZoneToList), (gpointer)&NewZone );
882
gtk_box_pack_start (GTK_BOX (hbox), AddButton, TRUE, FALSE, 0);
883
g_signal_connect (G_OBJECT (EntryDescription), "key-press-event",
884
G_CALLBACK (GotOK), (gpointer)AddButton);
885
g_signal_connect (G_OBJECT (EntryTZ), "key-press-event",
886
G_CALLBACK (GotOK), (gpointer)AddButton);
887
gtk_widget_show (AddButton);
889
DoneButton = gtk_button_new_with_label (_("Done"));
890
g_signal_connect (G_OBJECT (DoneButton), "clicked",
891
G_CALLBACK (DestroyWindow), (gpointer)window);
892
gtk_box_pack_start (GTK_BOX (hbox), DoneButton, TRUE, FALSE, 0);
893
gtk_widget_show (DoneButton);
895
gtk_widget_show(window);
898
void WriteZoneDescription(GtkDialog *dialog, gint responseId, gpointer Zone)
901
GString *description;
902
GtkTreeView *clocklist;
903
GtkTreeModel *clocklistModel;
906
if ( responseId == OK_BUTTON )
908
clocklist = GTK_TREE_VIEW(((AddZoneStruct *)Zone)->clocklist);
909
if ( gtk_tree_selection_get_selected(
910
gtk_tree_view_get_selection(clocklist),
915
description = g_string_new(
916
gtk_entry_get_text((GtkEntry *)((AddZoneStruct *)Zone)->DescriptionEntry));
918
gtk_list_store_set ( GTK_LIST_STORE(clocklistModel),
920
TZ_DESCRIPTION, description->str,
924
/* gtk_tree_model_row_changed( clocklistModel,
925
gtk_tree_model_get_path( clocklistModel, &iter),
927
// resizeWindow( gtk_widget_get_toplevel( GTK_WIDGET(clocklist) ),
932
if ( responseId > 0 )
934
gtk_widget_destroy(GTK_WIDGET(dialog));
938
void ChangeZoneDescription(GtkWidget *w, gpointer clocklist)
941
GtkWidget *window, *vbox, *hbox;
942
GtkWidget *DescriptionEntry, *OKButton, *CancelButton;
943
static AddZoneStruct Zone;
944
GString *title, *msg;
945
gchar *button[]={"OK"};
946
GtkTreeModel *clocklistModel;
947
GtkTreeIter selectedRowIter;
949
if ( ! gtk_tree_selection_get_selected(
950
gtk_tree_view_get_selection( clocklist ),
954
/* is this dialog box useful? */
955
showMessageDialog( _("No zone chosen for changing."), GTK_MESSAGE_WARNING );
959
gtk_tree_model_get( GTK_TREE_MODEL(clocklistModel), &selectedRowIter,
960
TZ_DESCRIPTION, &description,
963
Zone.clocklist = (GObject *) clocklist;
965
window = gtk_dialog_new_with_buttons ( _("Change Zone Description"),
967
GTK_DIALOG_NO_SEPARATOR,
969
"Cancel", CANCEL_BUTTON,
972
gtk_window_position((GtkWindow *)window,GTK_WIN_POS_CENTER);
973
gtk_container_set_border_width (GTK_CONTAINER (window), 5);
975
DescriptionEntry = gtk_entry_new();
976
Zone.DescriptionEntry = DescriptionEntry;
977
gtk_entry_set_text( (GtkEntry *) DescriptionEntry, description);
978
g_signal_connect (G_OBJECT (DescriptionEntry), "key-press-event",
979
G_CALLBACK (GotOKInDialog), (gpointer)window);
980
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(window)->vbox), DescriptionEntry);
981
gtk_widget_show (DescriptionEntry);
983
g_signal_connect (G_OBJECT (window), "response",
984
G_CALLBACK(WriteZoneDescription),
987
gtk_widget_show(window);