src/manager/src/ws_mng_dictionary_utils.c

Go to the documentation of this file.
00001 /*******************************************************************************
00002 This file is part of mdictionary.
00003 
00004 mdictionary 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 mdictionary 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 mdictionary; if not, write to the Free Software
00016 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00017 
00018 Copyright 2006-2008 ComArch S.A.
00019 *******************************************************************************/
00026 #include <ws_mng_dictionary_utils.h>
00027 
00033 void ws_mng_extract_dictionary( GError *error,
00034                                 GArray* param,
00035                                 gpointer user_data )
00036 {
00037         g_debug("->%s", __FUNCTION__);
00038         WSMngSearchData *data = (WSMngSearchData *) user_data;
00039         osso_rpc_t *osso_data;
00040 
00041         /* get the data sended by dbus */
00042         osso_data = &g_array_index (param, osso_rpc_t, 0); 
00043         gchar* path = g_strdup(osso_data->value.s);
00044         gint result = -1;
00045 
00046         gchar* dest = NULL;
00047         if (path != NULL)
00048         {
00049                 gint count = 0;
00050                 gchar** tmp = g_strsplit(path, "/", 0);
00051                 while(tmp[count] != NULL)
00052                 {
00053                         ++count;
00054                 }
00055                 dest = g_strndup(path, g_strlen(path)- g_strlen(tmp[count -2]));
00056                 g_strfreev(tmp);
00057         };
00058 
00059         if (dest != NULL)
00060         {
00061                 ws_dbus_notify(data->dbus_data, WS_DBUS_EXTRACT_FILE);
00062                 result = decompress_file(path, &dest);
00063                 ws_dbus_notify(data->dbus_data, WS_DBUS_EXTRACT_FILE_FINISHED);
00064         };
00065 
00066         if (result == 0)
00067         {
00068                 ws_dbus_server_return_extracted_dict(data->dbus_data, dest);
00069         }
00070         else
00071         {
00072                 dest = "";
00073                 ws_dbus_server_return_extracted_dict(data->dbus_data, dest);
00074         }
00075 
00076         g_free(path);
00077         path = NULL;
00078         g_debug("<-%s", __FUNCTION__);
00079 }
00080 
00081 
00087 void ws_mng_load_dict(GArray* dict_directory, WSMngSearchData* data)
00088 {
00089         gint i = 0;
00090         gint j = 0;
00091         Engine* xdxf = NULL;
00092         g_debug("->%s", __FUNCTION__);
00093         EngineOptimizationFlag flag = ENGINE_NO;
00094         gchar* current_directory = NULL;
00095 
00096         for (i =0; i<dict_directory->len; i++)
00097         {
00098                 current_directory = strdup(g_array_index( dict_directory,
00099                                                           gchar*,
00100                                                           i ));
00101                 flag = ENGINE_NO;
00102                 for (j=0; j<data->modules->len; j++)
00103                 {
00104                         if (dict_eng_module_check( g_array_index( data->modules,
00105                                                                   EngineModule,
00106                                                                   j),
00107                                                    current_directory ) == TRUE)
00108                         {
00109                                 /* set correct flag for engine */
00110                                 if(ws_mng_if_optimized(current_directory))
00111                                 {
00112                                         flag = ENGINE_CREATE;
00113                                 }
00114 
00115                                 /* create engine with correct flag */
00116                                 xdxf = dict_eng_module_create_ext(
00117                                                    g_array_index( data->modules,
00118                                                                   EngineModule,
00119                                                                   j ),
00120                                                    current_directory,
00121                                                    flag,
00122                                                    ws_mng_progress_bar,
00123                                                    data,
00124                                                    0.02 );
00125 
00126                                 /*set callbacks functions */
00127                                 dict_eng_set_callback( xdxf,
00128                                                        ENGINE_WORD_LIST_SIGNAL,
00129                                                        ws_mng_on_found_word,
00130                                                        data );
00131 
00132                                 dict_eng_set_callback( xdxf,
00133                                                ENGINE_WORD_TRANSLATION_SIGNAL,
00134                                                ws_mng_on_found_translation,
00135                                                data );
00136 
00137                                 /* adding newly created engine to Garray */
00138                                 g_array_append_val (data->dict, xdxf);
00139 
00140                                 g_free(current_directory);
00141                                 current_directory = NULL;
00142                                 xdxf = NULL;
00143 
00144                                 /* do not check next module - move directly to 
00145                                  * next dictionary */
00146                                 break;
00147                         }
00148                 }
00149         }
00150         g_debug("<-%s", __FUNCTION__);
00151 }
00152 

Generated on Fri Jan 11 14:30:17 2008 for mDictionary Project by  doxygen 1.5.1