00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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 "iLiadUserScreen.h"
00037 #include "iLiadUserData.h"
00038 #include "languages.h"
00039 #include "settings.h"
00040
00041
00042 static regUserProfile_t* g_user_profile = NULL;
00043 static regUserProfile_t* g_stored_profile = NULL;
00044
00045
00046 static regUserProfile_t* user_profile_dup(const regUserProfile_t* profile);
00047
00048
00049 void iLiad_user_data_init(void)
00050 {
00051 ST_LOGPRINTF("entry");
00052
00053 iLiad_user_data_destroy();
00054
00055 g_user_profile = erRegGetUserProfile();
00056
00057 if (g_user_profile == NULL)
00058 {
00059 ST_WARNPRINTF("use default values");
00060 g_user_profile = g_new0(regUserProfile_t, 1);
00061
00062 g_user_profile->name = g_strdup("iRex");
00063 g_user_profile->email = g_strdup("i@r.x");
00064 g_user_profile->password = g_strdup("98In4w5tg");
00065 g_user_profile->redirectUrl = g_strdup("https://ids.irexnet.com:443/redirector");
00066 }
00067 else
00068 {
00069 g_stored_profile = user_profile_dup(g_user_profile);
00070 }
00071 }
00072
00073 void iLiad_user_data_destroy(void)
00074 {
00075 ST_LOGPRINTF("entry");
00076
00077 if (g_user_profile)
00078 {
00079 erRegFreeUserProfile(g_user_profile);
00080 g_user_profile = NULL;
00081 }
00082
00083 if (g_stored_profile)
00084 {
00085 erRegFreeUserProfile(g_stored_profile);
00086 g_stored_profile = NULL;
00087 }
00088 }
00089
00090 void iLiad_user_data_display(void)
00091 {
00092 ST_LOGPRINTF("entry");
00093
00094 g_return_if_fail(NULL != g_user_profile);
00095 g_assert(NULL != g_user_profile);
00096
00097
00098 if (g_user_profile->name)
00099 {
00100 iLiad_user_set_name(g_user_profile->name);
00101 }
00102
00103
00104 if (g_user_profile->email)
00105 {
00106 iLiad_user_set_email(g_user_profile->email);
00107 }
00108
00109
00110 if (g_user_profile->password)
00111 {
00112 iLiad_user_set_password(g_user_profile->password);
00113 }
00114
00115
00116
00117 display_update_request_screen_refresh(SETTING_ITEM_CHANGE, WAVEFORM_FULLSCREEN);
00118 }
00119
00120
00121
00122 void on_user_name_changed(GtkWidget* item, const gchar* text)
00123 {
00124 g_return_if_fail(NULL != g_user_profile);
00125
00126 if (g_user_profile->name)
00127 {
00128 g_free(g_user_profile->name);
00129 }
00130 g_user_profile->name = strdup(text);
00131 }
00132
00133 void on_user_email_changed(GtkWidget* item, const gchar* text)
00134 {
00135 g_return_if_fail(NULL != g_user_profile);
00136
00137 if (g_user_profile->email)
00138 {
00139 g_free(g_user_profile->email);
00140 }
00141 g_user_profile->email = strdup(text);
00142
00143
00144 char* cp;
00145 while ( (cp = strchr(g_user_profile->email, ' ')) != NULL )
00146 {
00147 strcpy(cp, cp+1);
00148 }
00149 }
00150
00151 void on_user_password_changed(GtkWidget* item, const gchar* text)
00152 {
00153 g_return_if_fail(NULL != g_user_profile);
00154
00155 if (g_user_profile->password)
00156 {
00157 g_free(g_user_profile->password);
00158 }
00159 g_user_profile->password = strdup(text);
00160 }
00161
00162
00163
00164
00165 void iLiad_user_data_store(void)
00166 {
00167 ST_LOGPRINTF("entry");
00168
00169 g_return_if_fail(NULL != g_user_profile);
00170 g_assert(NULL != g_user_profile);
00171 g_assert(NULL != g_user_profile->name);
00172 g_assert(NULL != g_user_profile->email);
00173 g_assert(NULL != g_user_profile->password);
00174 g_assert(NULL != g_user_profile->redirectUrl);
00175
00176 if ( g_stored_profile != NULL
00177 && strcmp(g_user_profile->name, g_stored_profile->name ) == 0
00178 && strcmp(g_user_profile->email, g_stored_profile->email ) == 0
00179 && strcmp(g_user_profile->password, g_stored_profile->password ) == 0
00180 && strcmp(g_user_profile->redirectUrl, g_stored_profile->redirectUrl) == 0 )
00181 {
00182
00183 return;
00184 }
00185
00186 prepare_registry_write();
00187
00188 ST_STOREPRINTF("calling erRegSetUserProfile");
00189 erRegSetUserProfile(g_user_profile);
00190
00191 erRegFreeUserProfile(g_stored_profile);
00192 g_stored_profile = user_profile_dup(g_user_profile);
00193
00194 do_registry_write();
00195 }
00196
00197
00198 static regUserProfile_t* user_profile_dup(const regUserProfile_t* profile)
00199 {
00200 regUserProfile_t* dup = NULL;
00201
00202 if (profile != NULL)
00203 {
00204 dup = g_new0(regUserProfile_t, 1);
00205 dup->name = strdup(profile->name);
00206 dup->email = strdup(profile->email);
00207 dup->password = strdup(profile->password);
00208 dup->redirectUrl = strdup(profile->redirectUrl);
00209 }
00210
00211 return dup;
00212 }
00213
00214 regUserProfile_t* get_user_profile_ptr()
00215 {
00216 return g_user_profile;
00217 }
00218