00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00031 #include <fcntl.h>
00032 #include <stdio.h>
00033 #include <string.h>
00034 #include <sys/ioctl.h>
00035 #include <sys/soundcard.h>
00036 #include <unistd.h>
00037
00038 #include <gtk/gtk.h>
00039
00040 #include <liberregxml/erregapi.h>
00041
00042 #include "setupLog.h"
00043 #include "iLiadPCConnectData.h"
00044 #include "settings.h"
00045
00046
00047
00048 static regPCConfig_t *g_pc_connect_config = NULL;
00049 static regPCProfile_t **g_pc_connect_settings = NULL;
00050
00051 static gboolean g_pc_connect_changed = FALSE;
00052
00053
00054 static guint iLiad_pc_connect_add_profile(void);
00055
00056
00057
00058 void iLiad_pc_connect_data_init(void)
00059 {
00060 regPCProfile_t* setting = NULL;
00061
00062 ST_LOGPRINTF("entry");
00063
00064 iLiad_pc_connect_data_destroy();
00065
00066
00067 erRegGetPCProfiles(&g_pc_connect_config, &g_pc_connect_settings);
00068
00069
00070 if (g_pc_connect_config->size == 0)
00071 {
00072 ST_WARNPRINTF("no PC profiles, create one empty profile");
00073 iLiad_pc_connect_add_profile();
00074 setting = g_new0(regPCProfile_t, 1);
00075 g_assert(setting != NULL);
00076 setting->name = strdup("");
00077 setting->pcname = strdup("");
00078 setting->sharename = strdup("");
00079 setting->workgroup = strdup("");
00080 setting->username = strdup("");
00081 setting->password = strdup("");
00082 g_pc_connect_settings[0] = setting;
00083 }
00084 }
00085
00086 void iLiad_pc_connect_data_destroy(void)
00087 {
00088 ST_LOGPRINTF("entry");
00089
00090 if (g_pc_connect_config)
00091 {
00092 erRegFreePCProfiles(g_pc_connect_config, g_pc_connect_settings);
00093 g_pc_connect_settings = NULL;
00094 g_pc_connect_config = NULL;
00095 }
00096 }
00097
00098 const regPCProfile_t *iLiad_pc_connect_get_profiledata(const gint profile_index)
00099 {
00100 ST_LOGPRINTF("entry: index [%d]", profile_index);
00101
00102 g_return_val_if_fail((g_pc_connect_config != NULL), NULL);
00103
00104 if (profile_index < g_pc_connect_config->size)
00105 {
00106 return g_pc_connect_settings[profile_index];
00107 }
00108 else
00109 {
00110 return NULL;
00111 }
00112 }
00113
00114 gboolean iLiad_pc_connect_set_profile_field(gint profile_index, pc_fieldtype_t field, const char* value)
00115 {
00116 gchar** cpp;
00117
00118 ST_LOGPRINTF("entry: index [%d] field [%d] value [%s] size [%d]", profile_index, field, value, g_pc_connect_config->size);
00119
00120 g_return_val_if_fail((g_pc_connect_config != NULL), FALSE);
00121 g_return_val_if_fail((profile_index < g_pc_connect_config->size), FALSE);
00122
00123 if (value == NULL)
00124 {
00125 value = "";
00126 }
00127
00128
00129 switch (field)
00130 {
00131 case e_pcfield_profile_name:
00132 cpp = &(g_pc_connect_settings[profile_index]->name);
00133 break;
00134 case e_pcfield_pcname:
00135 cpp = &(g_pc_connect_settings[profile_index]->pcname);
00136 break;
00137 case e_pcfield_sharename:
00138 cpp = &(g_pc_connect_settings[profile_index]->sharename);
00139 break;
00140 case e_pcfield_workgroup:
00141 cpp = &(g_pc_connect_settings[profile_index]->workgroup);
00142 break;
00143 case e_pcfield_username:
00144 cpp = &(g_pc_connect_settings[profile_index]->username);
00145 break;
00146 case e_pcfield_password:
00147 cpp = &(g_pc_connect_settings[profile_index]->password);
00148 break;
00149 default:
00150 g_assert_not_reached();
00151 return FALSE;
00152 }
00153 if (*cpp)
00154 {
00155 g_free(*cpp);
00156 }
00157 *cpp = g_strdup(value);
00158
00159 g_pc_connect_changed = TRUE;
00160 return TRUE;
00161 }
00162
00163 void iLiad_pc_connect_data_store(void)
00164 {
00165 ST_LOGPRINTF("entry");
00166
00167 if (g_pc_connect_changed == FALSE)
00168 {
00169
00170 ST_LOGPRINTF("nothing to save");
00171 return;
00172 }
00173
00174
00175 prepare_registry_write();
00176
00177 const regPCProfile_t** p = (const regPCProfile_t**)g_pc_connect_settings;
00178 erRegSetPCProfiles(g_pc_connect_config, p);
00179
00180 g_pc_connect_changed = FALSE;
00181
00182 do_registry_write();
00183 }
00184
00185 static guint iLiad_pc_connect_add_profile()
00186 {
00187 ST_LOGPRINTF("entry");
00188
00189 guint profile_index = g_pc_connect_config->size;
00190
00191
00192 gchar **newList = g_renew(gchar *, g_pc_connect_config->pcList, profile_index + 1);
00193 g_pc_connect_config->pcList = newList;
00194 g_pc_connect_config->pcList[profile_index] = g_strdup_printf("PC_%d", profile_index);
00195
00196
00197 regPCProfile_t **newSettings = g_renew(regPCProfile_t *, g_pc_connect_settings, profile_index + 1);
00198 g_pc_connect_settings = newSettings;
00199 g_pc_connect_settings[profile_index] = NULL;
00200 g_pc_connect_config->size = profile_index + 1;
00201
00202
00203 ST_LOGPRINTF("g_pc_connect_config->size=%d", g_pc_connect_config->size);
00204 return g_pc_connect_config->size;
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237