00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00026 #include <ws_mng_callbacks.h>
00027 #include <glib/gstdio.h>
00028
00034 void ws_mng_progress_bar( double progress,
00035 gpointer user_data,
00036 EngineStatus error )
00037 {
00038 g_debug("<--> %s - progress=%f", __FUNCTION__, progress);
00039 WSMngSearchData *data = (WSMngSearchData *) user_data;
00040 ws_dbus_server_update_progressbar(data->dbus_data, progress);
00041 }
00042
00043
00044
00050 void ws_mng_on_search_word( GError *error,
00051 GArray *word,
00052 gpointer user_data )
00053 {
00054 g_debug("[L-word] -> %s: reading parameters...", __FUNCTION__);
00055 WSMngSearchData *search = (WSMngSearchData *) user_data;
00056 osso_rpc_t* osso_data = NULL;
00057
00058
00059 g_static_mutex_lock( search->thread_creation );
00060
00061
00062 osso_data = &g_array_index (word, osso_rpc_t, 0);
00063 gchar* tmp = NULL;
00064
00065 if (osso_data->value.s != NULL)
00066 {
00067
00068 if (( g_utf8_strchr(osso_data->value.s, -1, '*') == NULL ) &&
00069 ( g_utf8_strchr(osso_data->value.s, -1, '?') == NULL ))
00070 {
00071 tmp = g_strconcat(osso_data->value.s, "*", NULL);
00072 }
00073 else
00074 {
00075 tmp = g_strdup(osso_data->value.s);
00076 }
00077 }
00078 else
00079 {
00080 tmp = g_strdup ("*");
00081 }
00082
00083
00084 WSMngSearchAtom* search_data = NULL;
00085 search_data = create_search_atom(search, tmp);
00086 g_free(tmp);
00087 if (NULL == search_data)
00088 {
00089 return;
00090 }
00091
00092 g_debug("[L-word] creating GThread object...");
00093 search_data->thread = g_thread_create( ws_mng_search_word,
00094 search_data,
00095 TRUE,
00096 NULL );
00097 g_debug("[L-word] GThread object created. Exiting from CREATOR.");
00098
00099 g_static_mutex_unlock( search->thread_creation );
00100
00101
00102 g_debug("[L-word] <-%s", __FUNCTION__);
00103 }
00104
00110 void ws_mng_on_search_translation (GError *error,
00111 GArray *word,
00112 gpointer user_data)
00113 {
00114 g_debug("[L-tran] ->%s", __FUNCTION__);
00115
00116 WSMngSearchData *data = (WSMngSearchData *) user_data;
00117
00118
00119 g_static_mutex_lock(data->thread_creation);
00120
00121
00122 osso_rpc_t *osso_data;
00123 osso_data = &g_array_index (word, osso_rpc_t, 0);
00124
00125
00126 WSMngSearchAtom* search_data = NULL;
00127 search_data = create_search_atom(data, osso_data->value.s);
00128 if (NULL == search_data)
00129 {
00130 return;
00131 }
00132
00133 g_debug("[L-tran] creating GThread object...");
00134 search_data->thread = g_thread_create( ws_mng_search_translation,
00135 search_data,
00136 TRUE,
00137 NULL );
00138 g_debug("[L-tran] GThread object created. Exiting from CREATOR.");
00139
00140
00141 g_static_mutex_unlock(data->thread_creation);
00142
00143
00144 g_debug("[L-tran] <-%s", __FUNCTION__);
00145 }
00146
00147
00153 void ws_mng_signal_handling(GError *error, GArray *signal, gpointer user_data)
00154 {
00155 g_debug("->%s", __FUNCTION__);
00156 osso_rpc_t osss_data;
00157 osss_data = g_array_index (signal, osso_rpc_t, 0);
00158 WSMngSearchData *data = (WSMngSearchData *) user_data;
00159 gint i = 0;
00160
00161 switch(osss_data.value.i)
00162 {
00163 case WS_DBUS_INFO_TERMINATE:
00164
00165
00166 if (try_lock_was_locked(data,(gchar*)__FUNCTION__))
00167 {
00168 g_printf("[S] STOP ACTION! %s\n",__FUNCTION__);
00169 g_static_rec_mutex_lock(data->action_stop);
00170 g_static_mutex_lock(data->action_working);
00171 }
00172 g_static_rec_mutex_unlock(data->action_stop);
00173 g_static_mutex_unlock(data->action_working);
00174
00175 g_main_loop_quit (data->loop);
00176 break;
00177 case WS_DBUS_INFO_STOP_SEARCH:
00178
00179
00180 if (try_lock_was_locked(data,(gchar*)__FUNCTION__))
00181 {
00182 g_printf("[S] STOP ACTION! %s\n",__FUNCTION__);
00183 g_static_rec_mutex_lock(data->action_stop);
00184 g_static_mutex_lock(data->action_working);
00185 }
00186 g_static_rec_mutex_unlock(data->action_stop);
00187 ws_dbus_notify(data->dbus_data,
00188 WS_DBUS_WORDS_LIST_FINISHED);
00189 ws_dbus_notify(data->dbus_data,
00190 WS_DBUS_TRANSLATION_FINISHED);
00191 g_static_mutex_unlock(data->action_working);
00192 break;
00193 case WS_DBUS_INFO_CONFIG_CHANGED:
00194 ws_dbus_notify(data->dbus_data, WS_DBUS_INFO_CACHING);
00195
00196 for (i=0; i<data->dict->len; i++)
00197 {
00198 if(g_array_index(data->dict, Engine*,i) != NULL)
00199 {
00200 dict_eng_destroy( g_array_index(
00201 data->dict,
00202 Engine*,
00203 i ) );
00204 }
00205 }
00206 g_array_free(data->dict, TRUE);
00207
00208
00209 data->dict = g_array_new (TRUE, TRUE, sizeof(Engine*));
00210 GArray* dir_array = ws_mng_read_gconf();
00211 ws_mng_load_dict(dir_array, data);
00212
00213
00214 if (data->dict->len <= 0)
00215 {
00216 ws_dbus_notify( data->dbus_data,
00217 WS_DBUS_INFO_CACHING_FINISHED );
00218 ws_dbus_notify( data->dbus_data,
00219 WS_DBUS_ERROR_FILE_NOT_FOUND);
00220 }
00221 else
00222 {
00223
00224 if (data->last_search != NULL)
00225 {
00226 data->word_list =
00227 g_array_new( TRUE,
00228 TRUE,
00229 sizeof(gchar*));
00230
00231 g_free(data->word); data->word = NULL;
00232 data->word =
00233 g_strdup(data->last_search);
00234 }
00235
00236 ws_dbus_notify( data->dbus_data,
00237 WS_DBUS_INFO_CACHING_FINISHED );
00238 }
00239
00240
00241 for (i=0; i<dir_array->len; i++)
00242 {
00243 g_free(g_array_index(dir_array, gchar*, i));
00244 }
00245 g_array_free(dir_array, TRUE);
00246 break;
00247 case WS_DBUS_BOOKMARK_MODE_ON:
00248 data->bookmark_mode = TRUE;
00249 break;
00250
00251 case WS_DBUS_BOOKMARK_MODE_OFF:
00252 data->bookmark_mode = FALSE;
00253 break;
00254 }
00255 g_debug("<-%s", __FUNCTION__);
00256 }
00257