00001 /* 00002 * This file is part of settings. 00003 * 00004 * settings is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * settings is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00031 #include <stdio.h> 00032 #include <string.h> 00033 00034 #include <gtk/gtk.h> 00035 00036 #include "setupLog.h" 00037 #include "iLiadTimediDSData.h" 00038 #include "settings.h" 00039 00040 00041 // Global variables 00042 static regTimedIds_t* g_timedids_settings = NULL; 00043 static regTimedIds_t* g_stored_settings = NULL; 00044 00045 // Internal functions 00046 static gboolean compare_settings(regTimedIds_t* settings_l, regTimedIds_t* settings_r); 00047 00048 void iLiad_timedids_data_init(void) 00049 { 00050 ST_LOGPRINTF("entry"); 00051 00052 iLiad_timedids_data_destroy(); 00053 00054 g_timedids_settings = erRegGetTimedIds(); 00055 if (NULL == g_timedids_settings) 00056 { 00057 ST_WARNPRINTF("use default values"); 00058 00059 g_timedids_settings = g_new0(regTimedIds_t, 1); 00060 g_timedids_settings->enable = FALSE; 00061 g_timedids_settings->timeCnt = 0; 00062 g_timedids_settings->timeSet[0] = 46800; 00063 g_timedids_settings->swUpdate = FALSE; 00064 g_timedids_settings->switchOff = FALSE; 00065 } 00066 else 00067 { 00068 g_stored_settings = g_new0(regTimedIds_t, 1); 00069 *g_stored_settings = *g_timedids_settings; 00070 } 00071 } 00072 00073 void iLiad_timedids_data_destroy(void) 00074 { 00075 ST_LOGPRINTF("entry"); 00076 00077 if (g_timedids_settings) 00078 { 00079 erRegFreeTimedIds(g_timedids_settings); 00080 g_timedids_settings = NULL; 00081 } 00082 if (g_stored_settings) 00083 { 00084 erRegFreeTimedIds(g_stored_settings); 00085 g_stored_settings = NULL; 00086 } 00087 } 00088 00089 // Return TRUE if two settings are equal 00090 gboolean compare_settings(regTimedIds_t* settings_l, regTimedIds_t* settings_r) 00091 { 00092 if (settings_l->enable != settings_r->enable) 00093 { 00094 return FALSE; 00095 } 00096 00097 if (settings_l->timeCnt != settings_r->timeCnt) 00098 { 00099 return FALSE; 00100 } 00101 00102 int i; 00103 for (i=0; i<g_stored_settings->timeCnt; i++) 00104 { 00105 if (settings_l->timeSet[i] != settings_r->timeSet[i]) 00106 { 00107 return FALSE; 00108 } 00109 } 00110 00111 if (settings_l->swUpdate != settings_r->swUpdate) 00112 { 00113 return FALSE; 00114 } 00115 00116 if (settings_l->switchOff != settings_r->switchOff) 00117 { 00118 return FALSE; 00119 } 00120 00121 return TRUE; 00122 } 00123 00124 void iLiad_timedids_data_store(void) 00125 { 00126 ST_LOGPRINTF("entry"); 00127 g_return_if_fail(NULL != g_timedids_settings); 00128 00129 // Check if anything changed 00130 if (g_stored_settings != NULL && compare_settings(g_stored_settings, g_timedids_settings)) 00131 { 00132 // Nothing changed, nothing to save 00133 return; 00134 } 00135 00136 prepare_registry_write(); 00137 00138 ST_STOREPRINTF("calling erRegSetTimediDS"); 00139 erRegSetTimedIds(g_timedids_settings); 00140 00141 *g_stored_settings = *g_timedids_settings; 00142 00143 do_registry_write(); 00144 } 00145 00146 regTimedIds_t* get_current_timedids_settings(void) 00147 { 00148 return g_timedids_settings; 00149 } 00150
1.5.6