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 00029 #include <gtk/gtk.h> 00030 #include <string.h> 00031 00032 #include <liberregxml/erregapi.h> 00033 00034 #include "setupLog.h" 00035 #include "displayStatus.h" 00036 #include "iLiadBgConnectScreen.h" 00037 #include "iLiadBgConnectData.h" 00038 #include "languages.h" 00039 #include "settings.h" 00040 00041 00042 static regAutoConnect_t* g_autoconnect = NULL; 00043 static regAutoConnect_t* g_stored_autoconnect = NULL; 00044 00045 static gboolean g_ac_wlan = TRUE; 00046 static gboolean g_stored_ac_wlan = TRUE; 00047 00048 void iLiad_autoconnect_data_init(void) 00049 { 00050 ST_LOGPRINTF("entry"); 00051 00052 iLiad_autoconnect_data_destroy(); 00053 00054 g_autoconnect = erRegGetAutoConnect(); 00055 if (g_autoconnect == NULL) 00056 { 00057 ST_WARNPRINTF("use default values"); 00058 g_autoconnect = g_new0(regAutoConnect_t, 1); 00059 00060 g_autoconnect->backgroundEnable = FALSE; 00061 } 00062 else 00063 { 00064 g_stored_autoconnect = g_new0(regAutoConnect_t, 1); 00065 *g_stored_autoconnect = *g_autoconnect; 00066 } 00067 00068 g_ac_wlan = erRegGetAutoConnectWlan(); 00069 g_stored_ac_wlan = g_ac_wlan; 00070 } 00071 00072 void iLiad_autoconnect_data_destroy(void) 00073 { 00074 ST_LOGPRINTF("entry"); 00075 00076 if (g_autoconnect) 00077 { 00078 g_free(g_autoconnect); 00079 g_autoconnect = NULL; 00080 } 00081 00082 if (g_stored_autoconnect) 00083 { 00084 g_free(g_stored_autoconnect); 00085 g_stored_autoconnect = NULL; 00086 } 00087 } 00088 00089 void iLiad_autoconnect_data_display(void) 00090 { 00091 ST_LOGPRINTF("entry"); 00092 00093 g_return_if_fail(g_autoconnect != NULL); 00094 00095 iLiad_ac_set_wlan_onoff(g_ac_wlan); 00096 iLiad_ac_set_background_onoff(g_autoconnect->backgroundEnable); 00097 iLiad_ac_set_background_idspc(g_autoconnect->backgroundConnectTo); 00098 iLiad_ac_set_background_interval(g_autoconnect->backgroundInterval); 00099 00100 display_update_request_screen_refresh(SETTING_ITEM_CHANGE, WAVEFORM_FULLSCREEN); 00101 } 00102 00103 // callback functions 00104 void iLiad_ac_wlan_onoff_changed(gboolean enable) 00105 { 00106 g_ac_wlan = enable; 00107 } 00108 00109 void iLiad_ac_background_onoff_changed(gboolean enable) 00110 { 00111 g_return_if_fail(NULL != g_autoconnect); 00112 00113 g_autoconnect->backgroundEnable = enable; 00114 } 00115 00116 void iLiad_ac_background_idspc_changed(gint connect_to) 00117 { 00118 g_return_if_fail(NULL != g_autoconnect); 00119 00120 g_autoconnect->backgroundConnectTo = connect_to; 00121 } 00122 00123 void iLiad_ac_background_interval_changed(gboolean interval) 00124 { 00125 g_return_if_fail(NULL != g_autoconnect); 00126 00127 g_autoconnect->backgroundInterval = interval; 00128 } 00129 00130 //store the autoconnect information in the registry 00131 void iLiad_autoconnect_data_store(void) 00132 { 00133 gboolean changedAutoConnect = TRUE; 00134 gboolean changedAutoConnectWlan = TRUE; 00135 00136 ST_LOGPRINTF("entry"); 00137 00138 g_return_if_fail(NULL != g_autoconnect); 00139 00140 if ( g_stored_autoconnect != NULL 00141 && g_autoconnect->backgroundEnable == g_stored_autoconnect->backgroundEnable 00142 && g_autoconnect->backgroundConnectTo == g_stored_autoconnect->backgroundConnectTo 00143 && g_autoconnect->backgroundInterval == g_stored_autoconnect->backgroundInterval) 00144 { 00145 changedAutoConnect = FALSE; 00146 } 00147 00148 if (g_ac_wlan == g_stored_ac_wlan) 00149 { 00150 changedAutoConnectWlan = FALSE; 00151 } 00152 00153 if (!changedAutoConnect && !changedAutoConnectWlan) 00154 { 00155 // Nothing changed, nothing to save 00156 return; 00157 } 00158 00159 prepare_registry_write(); 00160 00161 if (changedAutoConnect) 00162 { 00163 ST_STOREPRINTF("calling erRegSetAutoConnect"); 00164 erRegSetAutoConnect(g_autoconnect); 00165 g_free(g_stored_autoconnect); 00166 g_stored_autoconnect = g_new0(regAutoConnect_t, 1); 00167 *g_stored_autoconnect = *g_autoconnect; 00168 } 00169 00170 if (changedAutoConnectWlan) 00171 { 00172 ST_STOREPRINTF("calling erRegSetAutoConnectWlan"); 00173 erRegSetAutoConnectWlan(g_ac_wlan); 00174 } 00175 00176 do_registry_write(); 00177 } 00178 00179
1.5.6