1.1 --- a/elmclock.c Fri Feb 19 07:49:00 2010 +1100
1.2 +++ b/elmclock.c Fri Feb 19 08:11:32 2010 +1100
1.3 @@ -22,22 +22,73 @@
1.4 Ecore_Timer *timer;
1.5 EAPI Evas_Object *timeZones;
1.6
1.7 +#define NUMBER_ZONES (24)
1.8 +struct zone
1.9 +{
1.10 + int offset;
1.11 + int customised;
1.12 + Elm_Genlist_Item *item;
1.13 + char description[FIELD_SIZE];
1.14 +} zones[NUMBER_ZONES];
1.15 +
1.16 +/* Configuration file name */
1.17 +char configurationFile[FIELD_SIZE];
1.18 +
1.19 +/* Read the configuration file */
1.20 +void readConfiguration()
1.21 +{
1.22 + FILE *fin;
1.23 + char line[FIELD_SIZE];
1.24 +
1.25 + sprintf(configurationFile,"%s/.elmclock",getenv("HOME"));
1.26 + fin = fopen(configurationFile,"r");
1.27 + if(fin)
1.28 + {
1.29 + while(fgets(line,FIELD_SIZE,fin))
1.30 + {
1.31 + int item;
1.32 + char desc[FIELD_SIZE];
1.33 +
1.34 + sscanf(line,"%d %s",&item,desc);
1.35 + strcpy(zones[item].description,desc);
1.36 + zones[item].customised = TRUE;
1.37 + }
1.38 + fclose(fin);
1.39 + }
1.40 +}
1.41 +
1.42 +int configurationModified = FALSE;
1.43 +
1.44 +/* Write the configuration file */
1.45 +void writeConfiguration()
1.46 +{
1.47 + FILE *fout;
1.48 +
1.49 + if(configurationModified)
1.50 + {
1.51 + int indx;
1.52 +
1.53 + fout = fopen(configurationFile,"w");
1.54 + for(indx = 0; indx < NUMBER_ZONES; indx++)
1.55 + {
1.56 + if(zones[indx].customised)
1.57 + {
1.58 + fprintf(fout,"%d %s\n",indx,zones[indx].description);
1.59 + }
1.60 + }
1.61 + fclose(fout);
1.62 + }
1.63 +}
1.64 +
1.65 static void handleDeleteRequest(void *data, Evas_Object * window, void *event_info)
1.66 {
1.67 ecore_timer_del(timer);
1.68 evas_object_hide(window);
1.69 ecore_shutdown();
1.70 + writeConfiguration();
1.71 exit(0);
1.72 }
1.73
1.74 -#define NUMBER_ZONES (24)
1.75 -struct zone
1.76 -{
1.77 - int offset;
1.78 - Elm_Genlist_Item *item;
1.79 - char description[FIELD_SIZE];
1.80 -} zones[NUMBER_ZONES];
1.81 -
1.82 time_t utctime = 0;
1.83 int selectedItem = -1;
1.84
1.85 @@ -47,6 +98,8 @@
1.86 if(selectedItem != -1)
1.87 {
1.88 strcpy(zones[selectedItem].description,desc);
1.89 + zones[selectedItem].customised = TRUE;
1.90 + configurationModified = TRUE;
1.91 elm_genlist_item_update(zones[selectedItem].item);
1.92 }
1.93 }
1.94 @@ -115,6 +168,8 @@
1.95 void resetDescription()
1.96 {
1.97 sprintf(zones[selectedItem].description,"UTC %+d",zones[selectedItem].offset / 3600);
1.98 + zones[selectedItem].customised = FALSE;
1.99 + configurationModified = TRUE;
1.100 elm_genlist_item_update(zones[selectedItem].item);
1.101 }
1.102
1.103 @@ -127,6 +182,7 @@
1.104 {
1.105 zones[indx].offset = (indx - (NUMBER_ZONES / 2)) * 3600;
1.106 sprintf(zones[indx].description,"UTC %+d",zones[indx].offset / 3600);
1.107 + zones[indx].customised = FALSE;
1.108 zones[indx].item = elm_genlist_item_append(timeZones,&itc,indx,NULL,ELM_GENLIST_ITEM_NONE,NULL,NULL);
1.109 }
1.110 }
1.111 @@ -204,6 +260,7 @@
1.112 {
1.113 elm_init(argc,argv);
1.114 createWindow();
1.115 + readConfiguration();
1.116 timerCallback(NULL);
1.117 timer = ecore_timer_add(TIMER_INTERVAL,timerCallback,NULL);
1.118 ecore_main_loop_begin();