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 <libergtk/ergtk.h> 00037 #include <liberregxml/erregapi.h> 00038 00039 #include "setupLog.h" 00040 #include "iLiadStartUpData.h" 00041 #include "background.h" 00042 #include "displayStatus.h" 00043 #include "languages.h" 00044 #include "settings.h" 00045 00046 00047 static regStartUp_t *g_current_startup = NULL; 00048 static regStartUp_t *g_stored_startup = NULL; 00049 00050 00051 void iLiad_startup_data_init(void) 00052 { 00053 ST_LOGPRINTF("entry"); 00054 00055 iLiad_startup_data_destroy(); 00056 00057 g_current_startup = erRegGetStartUp(); 00058 if (g_current_startup == NULL) 00059 { 00060 ST_WARNPRINTF("use default values"); 00061 00062 g_current_startup = g_new0(regStartUp_t, 1); 00063 g_assert(NULL != g_current_startup); 00064 g_current_startup->behaviour = 0; 00065 } 00066 else 00067 { 00068 g_stored_startup = erRegDupStartUp(g_current_startup); 00069 } 00070 } 00071 00072 void iLiad_startup_data_destroy(void) 00073 { 00074 ST_LOGPRINTF("entry"); 00075 00076 if (g_current_startup) 00077 { 00078 g_free(g_current_startup); 00079 g_current_startup = NULL; 00080 } 00081 00082 if (g_stored_startup) 00083 { 00084 g_free(g_stored_startup); 00085 g_stored_startup = NULL; 00086 } 00087 } 00088 00089 void iLiad_startup_data_store(void) 00090 { 00091 gboolean bNeedSave = FALSE; 00092 00093 ST_LOGPRINTF("entry"); 00094 00095 g_return_if_fail(NULL != g_current_startup); 00096 00097 // need to save changes or not? 00098 if ( NULL == g_stored_startup 00099 || g_stored_startup->behaviour != g_current_startup->behaviour 00100 || (g_stored_startup->documentPath == NULL && g_current_startup->documentPath != NULL) 00101 || (g_stored_startup->documentPath != NULL && g_current_startup->documentPath == NULL) 00102 || (g_stored_startup->documentPath != NULL && g_current_startup->documentPath != NULL 00103 && strcmp(g_stored_startup->documentPath, g_current_startup->documentPath) != 0 ) ) 00104 { 00105 bNeedSave = TRUE; 00106 } 00107 ST_LOGPRINTF("Need save? %s.", bNeedSave ? "Yes":"No"); 00108 00109 if (bNeedSave) 00110 { 00111 prepare_registry_write(); 00112 00113 ST_STOREPRINTF("calling erRegSetStartUp"); 00114 erRegSetStartUp(g_current_startup); 00115 00116 erRegFreeStartUp(g_stored_startup); 00117 g_stored_startup = erRegDupStartUp(g_current_startup); 00118 00119 do_registry_write(); 00120 } 00121 } 00122 00123 startup_behaviour_t iLiad_startup_data_get_behaviour(void) 00124 { 00125 ST_LOGPRINTF("entry"); 00126 00127 if (g_current_startup) 00128 { 00129 return g_current_startup->behaviour; 00130 } 00131 else 00132 { 00133 ST_WARNPRINTF("g_current_startup == NULL"); 00134 return 0; 00135 } 00136 } 00137 00138 void iLiad_startup_data_set_behaviour(startup_behaviour_t behaviour, const gchar *document_path) 00139 { 00140 ST_LOGPRINTF("entry: behaviour [%d] document_path [%s]", behaviour, document_path); 00141 00142 g_return_if_fail(g_current_startup != NULL); 00143 00144 if ((behaviour < 0) || (behaviour >= behaviourUndefined_t)) 00145 { 00146 ST_WARNPRINTF("invalid value(%d), return immediately", behaviour); 00147 return; 00148 } 00149 00150 g_current_startup->behaviour = behaviour; 00151 g_free(g_current_startup->documentPath); 00152 if (document_path) 00153 { 00154 g_current_startup->documentPath = g_strdup(document_path); 00155 } 00156 else 00157 { 00158 g_current_startup->documentPath = NULL; 00159 } 00160 } 00161
1.5.6