mDictionary Manager

mDictionary Manager. More...


Files

file  untar.h
 Exctracting *.tar.bz2 archives header.
file  ws_manager.h
 mDictionary Manager main module header.
file  ws_mng_bookmarks_utils.h
 Utilities for Manager connected with managing bookmarks - header.
file  ws_mng_callbacks.h
 Callback functions called by other modules - header.
file  ws_mng_dictionary_utils.h
 Dictionaries common routines - header.
file  ws_mng_gconf_utils.h
 Utilities connected with GConf configuration - header.
file  ws_mng_searching_threads.h
 Thread generation and thread functions - header.
file  ws_mng_threads_utils.h
 Thread utilities - header.
file  untar.c
 Exctracting *.tar.bz2 archives function code.
file  whitestork.c
 Entry point for mDictionary Manager module.
file  ws_manager.c
 mDictionary Manager main module code.
file  ws_mng_bookmarks_utils.c
 Utilities for Manager connected with managing bookmarks - code.
file  ws_mng_callbacks.c
 Callback functions called by other modules - code.
file  ws_mng_dictionary_utils.c
 Dictionaries common routines - code.
file  ws_mng_gconf_utils.c
 Utilities connected with GConf configuration - coder.
file  ws_mng_searching_threads.c
 Thread generation and thread functions - code.
file  ws_mng_threads_utils.c
 Thread utilities - code.

Data Structures

struct  _TarHeader
 Structure of entry in tar header. More...
struct  _WSMngSearchData
 Structure holding all data needed by manager to work. More...
struct  _WSMngSearchAtom
 Structure holding all data for each thread to properly run. More...
struct  _WSMngSearchAtom
 Structure holding all data for each thread to properly run. More...

Handling *.tar.bz2 files routines.

Every dictionary downloaded from Internet is compressed with bz2 algorithm. To allow user adding new dictionary downloaded from Internet directly to the device, we need to add exctracting *.tar.bz2 archives support.

enum  _RecordType
 Enumerate possible entries types in tar file. More...
typedef _TarHeader TarHeader
 Structure of entry in tar header.
typedef enum _RecordType RecordType
 Enumerate possible entries types in tar file.
gint decompress_file (gchar *in_file, gchar **out_path)
 Uncompress bz2 archive and extract tar file.
#define BLOCK_SIZE   512
 Define block size used in the header of archive.
#define BUFFER_SIZE   BLOCK_SIZE*32
 Define buffer size for blocks.
#define ASCII_NR(NR)   (NR + 0x30)
 Translate number into its ASCI code.

Thread utilities

typedef _WSMngSearchAtom WSMngSearchAtom
 Structure holding all data for each thread to properly run.
gboolean try_lock_was_locked (WSMngSearchData *data, gchar *fun)
 Try to lock mutex and tell if it was locked before.
gboolean is_rec_locked (GStaticRecMutex *m)
 Tell if given mutex is locked.
void stop_if_needed (WSMngSearchAtom *data)
 Check if current thread should be terminated.
void free_search_atom (WSMngSearchAtom *data)
 Clear memmory after not neede anymore WSMngSearchAtom structure.
WSMngSearchAtomcreate_search_atom (WSMngSearchData *app_data, gchar *word)
 Create new WSMngSearchAtom structure.

Bookmarks Utils

void ws_mng_add_bookmark (GError *error, GArray *param, gpointer user_data)
 Add new word to bookmark dictionary.
void ws_mng_remove_bookmark (GError *error, GArray *param, gpointer user_data)
 Remove specified word from bookmark engine.
void ws_mng_load_bookmark (WSMngSearchData *data)
 Load bookmarks dictionary engine.

Callback function called by other modules (GUI and engines).

void ws_mng_progress_bar (double progress, gpointer user_data, EngineStatus error)
 Function used to send information about progress of caching (engines).
void ws_mng_on_search_word (GError *error, GArray *word, gpointer user_data)
 Called when find word event occurs (UI).
void ws_mng_on_search_translation (GError *error, GArray *word, gpointer user_data)
 Called when find translation event occurs (UI).
void ws_mng_signal_handling (GError *error, GArray *signal, gpointer user_data)
 Function used for handling signals sent by user interface (UI).

Dictionaries routines

void ws_mng_extract_dictionary (GError *error, GArray *param, gpointer app_data)
 Extracting compressed dictionary file.
void ws_mng_load_dict (GArray *dict_directory, WSMngSearchData *data)
 Function used to load dictionaries engines.

GConf configuration routines.

GArray * ws_mng_read_gconf ()
 Function used to get the dictionaries location read fron GConf.
GArray * ws_mng_get_engines_location ()
 Function used to get plugins location read from GConf.
gchar * ws_mng_get_boomark_location ()
 Function used to get bookmark library location.
gboolean ws_mng_if_optimized (gchar *dict)
 Function used to check if optimized flag in GConf is set.
#define GCONF_KEY   "/apps/maemo/mdictionary/dictionaries"
 GConf path to dictionaries locations.
#define GCONF_LIB_PATH   "/apps/maemo/mdictionary/engines"
 GConf path to dictionary engines locations.

Thread common routines.

gpointer ws_mng_search_word (gpointer search_data)
 Function executed by thread - search for word list.
void ws_mng_on_found_word (GArray *list, gchar *pattern, gpointer user_data, EngineStatus error)
 Used to return results of found words from threads.
gpointer ws_mng_search_translation (gpointer search_data)
 Function executed by thread - search for particular word.
void ws_mng_on_found_translation (gchar *translation, gchar *pattern, gpointer user_data, EngineStatus error)
 Used to return results of transaltion from threads.
gint ws_mng_compare_strings (gconstpointer a, gconstpointer b)
 Function used to compare string. Used in sorting GArray object.
void ws_remove_multiple_words (WSMngSearchAtom *user_data)
 Removes repeating words on the returned words list.

Defines

#define LIBRARY   "/usr/lib/libsqlite.so.0"
 SQLite library version.
#define g_strlen(string)   ( NULL == (string) ? 0 : strlen(string) )
 Calculate length of given string.

Typedefs

typedef _WSMngSearchData WSMngSearchData

Functions

WSMngSearchDataws_manager_create ()
 Creates new instance of WSMngSearchData structure.
void ws_mng_init_dbus (WSMngSearchData *data)
 Function used to initialize D-BUS.
void ws_mng_init (WSMngSearchData *data)
 Function used to initialize manager.
void ws_mng_close (WSMngSearchData *data)
 Function used to close dictionaries and modules.
gboolean ws_mng_start_main_loop (WSMngSearchData *serach_data)
 Function used to run and initialize main loop.
static gint unpack_file_contents (BZFILE *bz2_file, TarHeader *header, gchar *out_name)
 Unpack particular file from *.tar.bz2 archive.
int main (gint argc, gchar **argv)
 Entry point for manager proccess.

Detailed Description

mDictionary Manager.

Manager module is managing plugins, and separate searching proccess from GUI module. It handles all dictionary engines and all dictionaries.

Author:
Ɓukasz Pawlik <lukasz.pawlik@comarch.com>

Define Documentation

#define ASCII_NR ( NR   )     (NR + 0x30)

Translate number into its ASCI code.

Definition at line 55 of file untar.h.

#define BLOCK_SIZE   512

Define block size used in the header of archive.

Definition at line 47 of file untar.h.

Referenced by decompress_file(), and unpack_file_contents().

#define BUFFER_SIZE   BLOCK_SIZE*32

Define buffer size for blocks.

Definition at line 51 of file untar.h.

#define g_strlen ( string   )     ( NULL == (string) ? 0 : strlen(string) )

Calculate length of given string.

Parameters:
string pointer to the array of chars (string)
Returns:
integer telling how many chars there were in the given array. (if string was NULL it returns 0)

Definition at line 68 of file ws_manager.h.

Referenced by ws_mng_extract_dictionary().

#define GCONF_KEY   "/apps/maemo/mdictionary/dictionaries"

GConf path to dictionaries locations.

Definition at line 43 of file ws_mng_gconf_utils.h.

Referenced by ws_mng_get_boomark_location(), ws_mng_if_optimized(), and ws_mng_read_gconf().

#define GCONF_LIB_PATH   "/apps/maemo/mdictionary/engines"

GConf path to dictionary engines locations.

Definition at line 47 of file ws_mng_gconf_utils.h.

Referenced by ws_mng_get_engines_location().

#define LIBRARY   "/usr/lib/libsqlite.so.0"

SQLite library version.

There were two versions of libsqlite: libsqlite (OS2006) and libsqlite3 (>=OS2007). According to system to which You are going to build mDictionary You should specyfy SQLITE to 0 or 3. LIBRARY specify destination path for used library.

Definition at line 57 of file ws_manager.h.

Referenced by ws_mng_init().


Typedef Documentation

typedef enum _RecordType RecordType

Enumerate possible entries types in tar file.

In mDictionary only File and Dir are supported. This values are used as a typeflag field in TarHeader structure.

See tar file specyfication for more information.

typedef struct _TarHeader TarHeader

Structure of entry in tar header.

See tar file specyfication for more information.

typedef struct _WSMngSearchAtom WSMngSearchAtom

Structure holding all data for each thread to properly run.

See also:
_WSMngSearchAtom

Definition at line 62 of file ws_mng_threads_utils.h.


Enumeration Type Documentation

enum _RecordType

Enumerate possible entries types in tar file.

In mDictionary only File and Dir are supported. This values are used as a typeflag field in TarHeader structure.

See tar file specyfication for more information.

Definition at line 91 of file untar.h.

00092 {
00093         File = ASCII_NR (0),
00094         ARCHLINK = ASCII_NR (1),
00095         SYMLINK = ASCII_NR (2),
00096         CHARDEV = ASCII_NR (3),
00097         BLOCKDEV = ASCII_NR (4),
00098         Dir = ASCII_NR (5),
00099         FIFO = ASCII_NR (6),
00100         RESERVED = ASCII_NR (7)
00101 } RecordType;


Function Documentation

WSMngSearchAtom * create_search_atom ( WSMngSearchData app_data,
gchar *  word 
)

Create new WSMngSearchAtom structure.

Parameters:
app_data manager data
word word to search

Definition at line 142 of file ws_mng_threads_utils.c.

References _WSMngSearchAtom::data, _WSMngSearchAtom::trans, _WSMngSearchAtom::word, and _WSMngSearchAtom::word_list.

Referenced by ws_mng_on_search_translation(), and ws_mng_on_search_word().

00143 {
00144         WSMngSearchAtom* search_data = NULL;
00145         search_data = (WSMngSearchAtom*)g_try_malloc(sizeof(WSMngSearchAtom));
00146         if (NULL == search_data)
00147         {
00148                 g_debug("[L-*] allocatting memmory for data failed!");
00149                 return NULL;
00150         }
00151         /* get the word sended by dbus */
00152         search_data->word = g_strdup(word);
00153         search_data->data = app_data;
00154         search_data->word_list = NULL;
00155         search_data->trans = NULL;
00156 
00157         return search_data;
00158 }

gint decompress_file ( gchar *  in_file,
gchar **  out_path 
)

Uncompress bz2 archive and extract tar file.

If user is trying to add archive with dictionary (tar.bz2 file) then there is need to uncompress this dictionary before use. Function decompress_file could do this.

Usage example:

 char* path = g_strdup("./");
 decompress_file ("comn_dictd04_wn.tar.bz2", &path);
The above example extracts a given archive, to the current directory

Parameters:
in_file path to file to exctract
out_path pointer to path (string) to output directory. After function finished work in this parameter function return path to the exctracted dictionary
Returns:
0 if exctracting of whole archive was succesfull

Definition at line 119 of file untar.c.

References BLOCK_SIZE, _TarHeader::name, _TarHeader::typeflag, and unpack_file_contents().

Referenced by ws_mng_extract_dictionary().

00120 {
00121         FILE *file;
00122         BZFILE  *bz2_file;
00123         guint result;
00124         gint ret = 0;
00125         TarHeader* header;
00126         gint bzerror;
00127         gchar* dest_dir = NULL;
00128 
00129         header = (TarHeader*) g_try_malloc (BLOCK_SIZE * sizeof(gchar));
00130         if (NULL == header)
00131         {
00132                 g_debug("\nCould not allocate memory\n");
00133                 return -1;
00134         }
00135 
00136         file = fopen (in_file, "rb");
00137         if (NULL == file)
00138         {
00139                 g_debug("There was an error while trying to read archive file");
00140                 g_free(header); header = NULL;
00141                 return -2;
00142         };
00143 
00144         bz2_file = BZ2_bzReadOpen (&bzerror, file, 0, 0, NULL, 0);
00145         if ( BZ_OK != bzerror )
00146         {
00147                 fclose(file);
00148                 g_free(header); header = NULL;
00149                 g_debug("There was an error while reading compressed file\n");
00150                 return -3;
00151         }
00152 
00153         /* read archive and exctract all files in it */
00154         while (TRUE)
00155         {
00156                 /* get info about next file/directory in the archive */
00157                 result = BZ2_bzRead( &bzerror,
00158                                      bz2_file,
00159                                      header,
00160                                      BLOCK_SIZE * sizeof (char) );
00161                 if ( BZ_OK == bzerror )
00162                 {
00163                         if (strlen(header->name) == 0)
00164                         {
00165                                 g_debug("\nFilename length is 0, exitting\n");
00166                                 break;
00167                         };
00168                         gchar *temp = g_strconcat( *out_path,
00169                                                    header->name,
00170                                                    NULL );
00171 
00172                         /* exctract file or create new directory */
00173                         switch (header->typeflag)
00174                         {
00175                                 case File:
00176                                         unpack_file_contents( bz2_file,
00177                                                               header,
00178                                                               temp );
00179                                 break;
00180                                 case Dir:
00181                                         if (0 !=
00182                                                 mkdir( temp,
00183                                                        S_IRUSR|S_IWUSR|S_IXUSR )
00184                                         ) {
00185                                                 g_debug("Couldnt create dir:%s",
00186                                                          temp);
00187                                                 g_free(header);
00188                                                 BZ2_bzReadClose( &bzerror,
00189                                                                  bz2_file );
00190                                                 fclose(file);
00191                                                 return -4;
00192                                         }
00193                                         else {
00194                                                 /* get last created directory */
00195                                                 if(NULL != dest_dir) {
00196                                                         g_free(dest_dir);
00197                                                 }
00198                                                 dest_dir = g_strdup(temp);
00199                                                 g_debug( "dest_dir %s \n",
00200                                                          dest_dir );
00201                                         }
00202                                 break;
00203                                 default:
00204                                         g_debug("Untar:Wrong type of content!");
00205                                 break;
00206                         }
00207                         g_free(temp);
00208                         temp = NULL;
00209                 }
00210                 else if ( bzerror != BZ_STREAM_END )
00211                 {
00212                         g_debug("\nBZ2 READ_CLOSE(stream end) %d\n", bzerror);
00213                         BZ2_bzReadClose ( &bzerror, bz2_file );
00214                         break;
00215                 }
00216                 else
00217                 {
00218                         g_debug("\nExitting, error nr %d\n", bzerror);
00219                         BZ2_bzReadClose ( &bzerror, bz2_file );
00220                         ret = -5;
00221                         break;
00222                 };
00223         };
00224 
00225         /* put newly created directory path into out_path parameter */
00226         if ((0 == ret) && (dest_dir != NULL))
00227         {
00228                 g_free(*out_path); *out_path = NULL;
00229                 *out_path = g_strdup(dest_dir);
00230                 g_free(dest_dir); dest_dir = NULL;
00231         }
00232 
00233         g_free(header); header = NULL;
00234         fclose(file);
00235         return ret;
00236 };

void free_search_atom ( WSMngSearchAtom data  ) 

Clear memmory after not neede anymore WSMngSearchAtom structure.

Parameters:
data search atom data for current thread

Definition at line 111 of file ws_mng_threads_utils.c.

References _WSMngSearchAtom::data, _WSMngSearchData::trans, _WSMngSearchData::word, and _WSMngSearchData::word_list.

Referenced by stop_if_needed().

00112 {
00113         g_debug("[T-clear] Cleaning after thread\n");
00114         g_assert(NULL != data);
00115         if (NULL != data->word)
00116         {
00117                 g_free(data->word);
00118         }
00119         if (NULL != data->trans)
00120         {
00121                 g_free(data->trans);
00122         }
00123         if (NULL != data->word_list)
00124         {
00125                 /* free memory used by each word from word list */
00126                 gint i = 0;
00127                 for (; i < data->word_list->len; i++)
00128                 {
00129                         g_free(g_array_index(data->word_list,gchar* ,i));
00130                 }
00131                 /* free memory used by GArray */
00132                 g_array_free(data->word_list, TRUE);
00133                 data->word_list = NULL;
00134         }
00135         g_free(data);
00136 }

gboolean is_rec_locked ( GStaticRecMutex *  m  ) 

Tell if given mutex is locked.

If mutex was not locked it is not locked by this function. It only check if given mutex is already locked.

Parameters:
m mutex to be checked

Definition at line 60 of file ws_mng_threads_utils.c.

Referenced by stop_if_needed().

00061 {
00062         gboolean r = !g_static_rec_mutex_trylock(m);
00063         if (FALSE == r)
00064         {
00065                 g_static_rec_mutex_unlock(m);
00066                 g_debug("[M-stop] STOP mutex is UNLOCKED!");
00067         }
00068         else
00069         {
00070                 g_debug("[M-stop] STOP mutex is LOCKED");
00071         }
00072         return r;
00073 }

int main ( gint  argc,
gchar **  argv 
)

Entry point for manager proccess.

Create and initialize all data needed for manager to work and start main loop for its proccess.

Definition at line 39 of file whitestork.c.

References ws_manager_create(), ws_mng_close(), ws_mng_init(), ws_mng_init_dbus(), and ws_mng_start_main_loop().

00040 {
00041         /* initialize GType and GObject's functions capabilities for proccess */
00042         g_type_init();
00043 
00044         WSMngSearchData* search_data = ws_manager_create();
00045 
00046         ws_mng_init_dbus(search_data);
00047 
00048         ws_mng_init(search_data);
00049 
00050         ws_mng_start_main_loop(search_data);
00051 
00052         ws_mng_close(search_data);
00053 
00054         return 0;
00055 }

void stop_if_needed ( WSMngSearchAtom data  ) 

Check if current thread should be terminated.

Parameters:
data search atom data for current thread

Definition at line 80 of file ws_mng_threads_utils.c.

References _WSMngSearchData::action_stop, _WSMngSearchData::action_working, _WSMngSearchAtom::data, _WSMngSearchData::dbus_data, free_search_atom(), is_rec_locked(), ws_dbus_notify, WS_DBUS_TRANSLATION_FINISHED, and WS_DBUS_WORDS_LIST_FINISHED.

Referenced by ws_mng_init(), ws_mng_search_translation(), and ws_mng_search_word().

00081 {
00082         static GStaticMutex _loc;
00083         static GStaticMutex* loc = NULL;
00084         if(NULL == loc && NULL == data)
00085         {
00086                 g_debug("Initializing static mutex. function:%s\n",__FUNCTION__);
00087                 g_static_mutex_init (loc);
00088                 loc = &_loc;
00089                 return;
00090         }
00091 
00092         WSMngSearchData* app_data = data->data;
00093         /* critical section for calling is_rec_locked() function*/
00094         g_static_mutex_lock(loc);
00095         if ( is_rec_locked(app_data->action_stop) )
00096         {
00097                 g_debug("[T-leaving] <---- Leaving thread (not finished).\n");
00098                 ws_dbus_notify(app_data->dbus_data, WS_DBUS_WORDS_LIST_FINISHED);
00099                 ws_dbus_notify(app_data->dbus_data, WS_DBUS_TRANSLATION_FINISHED);
00100                 free_search_atom(data);
00101                 g_static_mutex_unlock(app_data->action_working);
00102                 g_static_mutex_unlock(loc);
00103                 g_thread_exit (NULL);
00104         }
00105         g_static_mutex_unlock(loc);
00106 }

gboolean try_lock_was_locked ( WSMngSearchData data,
gchar *  fun 
)

Try to lock mutex and tell if it was locked before.

Parameters:
data manager data
fun string to display in logs - it intentionaly this should be caller function name

Definition at line 36 of file ws_mng_threads_utils.c.

References _WSMngSearchData::action_working, and _WSMngSearchAtom::data.

Referenced by ws_mng_search_translation(), ws_mng_search_word(), and ws_mng_signal_handling().

00037 {
00038         gboolean res = !g_static_mutex_trylock(data->action_working);
00039         if (res)
00040         {
00041                 g_debug("[M-action] %s - FAILED - locked already!", fun);
00042         }
00043         else
00044         {
00045                 g_debug("[M-action] %s - SUCCESS - locked!", fun);
00046         }
00047 
00048         return res;
00049 }

static gint unpack_file_contents ( BZFILE *  bz2_file,
TarHeader header,
gchar *  out_name 
) [static]

Unpack particular file from *.tar.bz2 archive.

Parameters:
bz2_file pointer to file with data (compressed with bz2 algorithm
header *.tar header with information about data in bz2_file
out_name string specifying destination path for uncompressed data
Returns:
0 if exctracting was succesfull

Definition at line 38 of file untar.c.

References BLOCK_SIZE, and _TarHeader::size.

Referenced by decompress_file().

00041 {
00042         gchar* buffer = NULL;
00043         guint i = 0;
00044         gint im = 0;
00045         FILE *file_out;
00046         gulong length = 0;
00047         guint result = 0;
00048         gint bzerror = 0;
00049 
00050         file_out = fopen(out_name, "w");
00051 
00052         if (file_out == NULL) return -1;
00053 
00054         sscanf(header->size, "%12lo", &length);
00055         g_debug("File size: %ld\n", length);
00056 
00057         im = length / BLOCK_SIZE;
00058         for (i = 0; i < im; ++i)
00059         {
00060                 buffer = (gchar*) g_try_malloc(BLOCK_SIZE * sizeof(gchar));
00061                 
00062                 result = BZ2_bzRead( &bzerror,
00063                                      bz2_file,
00064                                      buffer,
00065                                      BLOCK_SIZE * sizeof (gchar) );
00066 
00067                 fwrite (buffer, BLOCK_SIZE * sizeof(gchar), 1, file_out);
00068                 g_free (buffer);
00069         }
00070 
00071         i = length % BLOCK_SIZE;
00072         if (i != 0)
00073         {
00074                 buffer = (gchar*) g_try_malloc (BLOCK_SIZE * sizeof(gchar));
00075                 if (NULL == buffer)
00076                 {
00077                         g_debug("Memory not allocated");
00078                         return -100;
00079                 };
00080                 
00081                 result = BZ2_bzRead( &bzerror,
00082                                      bz2_file,
00083                                      buffer,
00084                                      BLOCK_SIZE * sizeof(gchar) );
00085                 if (BZ_OK == bzerror)
00086                 {
00087                         fwrite (buffer, i * sizeof(gchar), 1, file_out);
00088                 }
00089                 else
00090                 {
00091                         g_debug("bzerror = %d", bzerror);
00092                         return -200;
00093                 };
00094                 g_free(buffer);
00095         }
00096 
00097         fclose(file_out);
00098         return 0;
00099 };

WSMngSearchData * ws_manager_create (  ) 

Creates new instance of WSMngSearchData structure.

Returns:
new instance of WSMngSearchData structure

Definition at line 42 of file ws_manager.c.

Referenced by main().

00042                                      {
00043         g_debug("<--> %s", __FUNCTION__);
00044         WSMngSearchData* tmp = g_try_new(WSMngSearchData, 1);
00045 
00046         if (NULL == tmp)
00047         {
00048                 g_debug("Not enough memory !");
00049         }
00050         return tmp;
00051 }

void ws_mng_add_bookmark ( GError *  error,
GArray *  param,
gpointer  user_data 
)

Add new word to bookmark dictionary.

Function used to add bookmarks.

Parameters:
error error messages
param word and translation of word to adding
user_data structure holding nedded parameters

Definition at line 33 of file ws_mng_bookmarks_utils.c.

References _WSMngSearchData::bookmark, _WSMngSearchAtom::data, _WSMngSearchData::dbus_data, dict_eng_add_word, _WSMngSearchAtom::word, WS_DBUS_BOOKMARKS_ADDED_FAIL, WS_DBUS_BOOKMARKS_ADDED_OK, and ws_dbus_notify.

Referenced by ws_mng_init_dbus().

00034 {
00035         g_debug("->%s", __FUNCTION__);
00036 
00037         WSMngSearchData* data = (WSMngSearchData *) user_data;
00038         osso_rpc_t* osso_data = NULL;
00039         osso_rpc_t* osso_data_trans = NULL;
00040         gchar* word = NULL;
00041         gchar* translation = NULL;
00042 
00043         if (data->bookmark != NULL)
00044         {
00045                 /* get the word passed by dbus */
00046                 osso_data = &g_array_index (param, osso_rpc_t, 0); 
00047                 word = g_strdup(osso_data->value.s);
00048                 osso_data_trans = &g_array_index (param, osso_rpc_t, 1); 
00049                 translation = g_strdup(osso_data_trans->value.s);
00050 
00051                 /* try to add word to bookmarks */
00052                 gboolean is_added = dict_eng_add_word( data->bookmark,
00053                                                        word,
00054                                                        translation );
00055                 if (is_added == TRUE) 
00056                 {
00057                         ws_dbus_notify( data->dbus_data,
00058                                         WS_DBUS_BOOKMARKS_ADDED_OK );
00059                 }
00060                 else
00061                 {
00062                         ws_dbus_notify( data->dbus_data, 
00063                                         WS_DBUS_BOOKMARKS_ADDED_FAIL );
00064                 }
00065                 /* free memmory */
00066                 osso_rpc_free_val(osso_data);
00067                 g_free(translation);
00068                 g_free(word);
00069         }
00070         else
00071         {
00072                 ws_dbus_notify( data->dbus_data,
00073                                 WS_DBUS_BOOKMARKS_ADDED_FAIL );
00074                 g_debug("-> %s - there is no bookmark engine!\n", __FUNCTION__);
00075         }
00076 
00077         g_debug("<-%s", __FUNCTION__);
00078 }

void ws_mng_close ( WSMngSearchData data  ) 

Function used to close dictionaries and modules.

Parameters:
data structure holds pointers to data which need to be freed from memory

Definition at line 296 of file ws_manager.c.

References _WSMngSearchData::action_stop, _WSMngSearchData::action_working, _WSMngSearchData::bookmark, _WSMngSearchAtom::data, _WSMngSearchData::dbus_data, _WSMngSearchData::dict, dict_eng_destroy, _WSMngSearchData::last_search, _WSMngSearchData::libraries, _WSMngSearchData::library_path, _WSMngSearchData::loop, _WSMngSearchData::modules, _WSMngSearchData::thread_creation, and ws_dbus_destroy().

Referenced by main(), and ws_mng_init().

00297 {
00298         int i = 0;
00299         g_debug("->%s", __FUNCTION__);
00300 
00301         ws_dbus_destroy (data->dbus_data);
00302         if (data->bookmark != NULL)
00303         {
00304                 dict_eng_destroy(data->bookmark);
00305         }
00306 
00307         for (i = 0; i < data->dict->len; i++) 
00308         {
00309                 dict_eng_destroy(g_array_index (data->dict, Engine*,i));
00310         }
00311         g_array_free(data->dict, TRUE);
00312 
00313         g_free(data->last_search);
00314         g_free(data->loop);
00315         g_static_mutex_free(data->thread_creation);
00316         g_static_mutex_free(data->action_working);
00317         g_static_rec_mutex_free(data->action_stop);
00318 
00319         for (i=0; i<data->library_path->len; i++)
00320         {
00321                 g_free(g_array_index(data->library_path, gchar*, i));
00322         }
00323         g_array_free(data->library_path, TRUE); 
00324         g_array_free(data->modules, TRUE); data->modules = NULL;
00325         
00326         for (i=0; i< data->libraries->len; i++)
00327         {
00328                 if (g_array_index(data->libraries, GModule*, i) != NULL)
00329                 {
00330                         g_module_close(g_array_index( data->libraries,
00331                                                       GModule*,
00332                                                       i ));
00333                 }
00334         }
00335         g_array_free(data->libraries, TRUE);
00336         g_free(data);
00337         g_debug("<-%s", __FUNCTION__);
00338 }

gint ws_mng_compare_strings ( gconstpointer  a,
gconstpointer  b 
)

Function used to compare string. Used in sorting GArray object.

Parameters:
a first argument to compare
b second argument to compare
Returns:
result of compare <0 if the second is greater than first 0 if the strings are the same >0 if the first string is greater than second

Definition at line 263 of file ws_mng_searching_threads.c.

00264 {
00265         gchar** str1 = (gchar**)(a);
00266         gchar** str2 = (gchar**)(b);
00267 
00268         gchar* stra = g_utf8_strdown(str1[0], -1);
00269         gchar* strb = g_utf8_strdown(str2[0], -1);
00270 
00271         gint result = g_utf8_collate(stra, strb);
00272 
00273         g_free(stra); 
00274         g_free(strb);
00275         return result;
00276 }

void ws_mng_extract_dictionary ( GError *  error,
GArray *  param,
gpointer  user_data 
)

Extracting compressed dictionary file.

Parameters:
error after excuting it contains error messages if any was
param parameters given by D-Bus
app_data manager data

Definition at line 33 of file ws_mng_dictionary_utils.c.

References _WSMngSearchAtom::data, _WSMngSearchData::dbus_data, decompress_file(), g_strlen, WS_DBUS_EXTRACT_FILE, WS_DBUS_EXTRACT_FILE_FINISHED, ws_dbus_notify, and ws_dbus_server_return_extracted_dict.

Referenced by ws_mng_init_dbus().

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 }

gchar * ws_mng_get_boomark_location (  ) 

Function used to get bookmark library location.

Returns:
path to bookmark location

Definition at line 134 of file ws_mng_gconf_utils.c.

References GCONF_KEY.

Referenced by ws_mng_load_bookmark().

00135 {
00136         g_debug("->%s", __FUNCTION__);
00137         GConfClient* client = NULL;
00138         gchar* path = NULL;
00139         guint i = 0;
00140         client = gconf_client_get_default();
00141 
00142         GSList* list = gconf_client_all_dirs(client, GCONF_KEY, NULL);
00143         for (i=0; i<g_slist_length(list); i++)
00144         {
00145                 path = (gchar* ) g_slist_nth_data(list, i);
00146                 gchar* name = g_strconcat(path, "/name",NULL);
00147                 gchar* new_path = g_strconcat(path, "/path",NULL);
00148                 gchar* key_value = gconf_client_get_string( client,
00149                                                             name,
00150                                                             NULL );
00151 
00152                 if (key_value != NULL)
00153                 {
00154                         if (g_ascii_strcasecmp(key_value, "Bookmarks") == 0)
00155                         {
00156                                 gchar* key_value_path = 
00157                                         gconf_client_get_string( client,
00158                                                                  new_path,
00159                                                                  NULL );
00160 
00161                                 if (key_value_path != NULL)
00162                                 {
00163                                         g_free(key_value);
00164                                         key_value = NULL;
00165                                         g_free(new_path);
00166                                         new_path = NULL;
00167                                         g_free(name); name = NULL;      
00168                                         for (i=0; i<g_slist_length(list); i++)
00169                                         {
00170                                                 g_free(
00171                                                 g_slist_nth_data(list, i));
00172                                         }
00173                                         g_slist_free(list);
00174                                         g_object_unref(client);
00175                                         return key_value_path;
00176                                 }
00177                         }
00178                 }
00179                 g_free(name); name = NULL;
00180                 g_free(key_value);
00181                 key_value = NULL;
00182                 g_free(new_path);
00183                 new_path = NULL;
00184         }
00185 
00186         g_debug("<-%s", __FUNCTION__);
00187         return NULL;
00188 }

GArray * ws_mng_get_engines_location (  ) 

Function used to get plugins location read from GConf.

Returns:
libraries with dictionary engines location

Definition at line 81 of file ws_mng_gconf_utils.c.

References GCONF_LIB_PATH.

Referenced by ws_mng_init().

00082 {
00083         g_debug("->%s", __FUNCTION__);
00084         GConfClient* client = NULL;
00085         GArray* path_to_dir = g_array_new(TRUE, TRUE, sizeof(gchar *));
00086         gchar* path = NULL;
00087         gint i = 0;
00088         client = gconf_client_get_default();
00089 
00090         GSList* list = gconf_client_all_dirs(client, GCONF_LIB_PATH, NULL);
00091         for (i=0; i<g_slist_length(list); i++)
00092         {
00093                 path = (gchar* ) g_slist_nth_data(list, i);
00094                 gchar* new_path = g_strconcat(path, "/path",NULL);
00095                 gchar* key_value = gconf_client_get_string( client,
00096                                                             new_path,
00097                                                             NULL);
00098                 gchar** tmp = g_strsplit(key_value, "/", -1);
00099                 guint i = 0;
00100                 gboolean bookmark_engine = FALSE;
00101                 while(NULL != tmp[i])
00102                 {
00103                         g_debug("Comapred string %s", tmp[i]);
00104                         if (g_ascii_strcasecmp(tmp[i], "ws_bookmark.so") == 0)
00105                         {
00106                                 bookmark_engine = TRUE;
00107                                 break;
00108                         }
00109                         i++;
00110                 }
00111                 g_strfreev(tmp);
00112                 
00113                 if (key_value != NULL)
00114                 {
00115                         g_debug("Added library path %s", key_value);
00116                         g_array_append_val(path_to_dir, key_value);
00117                 }
00118                 g_free(new_path);
00119         }
00120 
00121         for (i=0; i<g_slist_length(list); i++)
00122         {
00123                 g_free(g_slist_nth_data(list, i));
00124         }
00125         g_slist_free(list);
00126         g_object_unref (client);
00127         return path_to_dir;
00128 }

gboolean ws_mng_if_optimized ( gchar *  dict  ) 

Function used to check if optimized flag in GConf is set.

Parameters:
dict path to dictionary file
Returns:
TRUE if dictionary is optimize, FALSE otherwise

Definition at line 194 of file ws_mng_gconf_utils.c.

References GCONF_KEY.

Referenced by ws_mng_load_dict().

00195 {
00196         g_debug("->%s", __FUNCTION__);
00197 
00198         GConfClient* client;
00199         gchar* path = NULL;
00200         gboolean key_optimized = FALSE;
00201         gboolean key_found = FALSE;
00202         gint i = 0;
00203 
00204         client = gconf_client_get_default();
00205         GSList* list = gconf_client_all_dirs(client, GCONF_KEY, NULL);
00206         for (i=0; i<g_slist_length(list); i++)
00207         {
00208                 path = (gchar *) g_slist_nth_data(list, i);
00209                 gchar* new_path = g_strconcat(path, "/path",NULL);
00210                 gchar* new_optimized = g_strconcat(path, "/optimized",NULL);
00211                 gchar* key_value = gconf_client_get_string( client,
00212                                                             new_path,
00213                                                             NULL );
00214 
00215                 if (g_ascii_strcasecmp(key_value, dict) == 0)
00216                 {
00217                         key_optimized = gconf_client_get_bool( client,
00218                                                                new_optimized,
00219                                                                NULL );
00220                         key_found = TRUE;
00221                 }
00222                 g_free(new_path);
00223                 g_free(new_optimized);
00224                 g_free(key_value);
00225 
00226                 if ( TRUE == key_found )
00227                 {
00228                         break;
00229                 }
00230         }
00231 
00232         for (i=0; i<g_slist_length(list); i++)
00233         {
00234                 g_free(g_slist_nth_data(list, i));
00235         }
00236         g_slist_free(list);
00237         g_object_unref (client);
00238 
00239         g_debug("<-%s", __FUNCTION__);
00240         return key_optimized;
00241 }

void ws_mng_init ( WSMngSearchData data  ) 

Function used to initialize manager.

Fuction loads from modules pointers to functions used to service searching in dictionaries and stores them in WSMngSearchData structure

Parameters:
data pointer to structure WSMngSearchData which stores variables needed to service manager

Definition at line 181 of file ws_manager.c.

References _WSMngSearchData::action_stop, _WSMngSearchData::action_working, _WSMngSearchData::bookmark, _WSMngSearchData::bookmark_mode, _WSMngSearchAtom::data, _WSMngSearchData::dbus_data, _WSMngSearchData::dict, GLOBAL_FUNCTIONS_NAME, _WSMngSearchData::last_search, _WSMngSearchData::libraries, LIBRARY, _WSMngSearchData::library_path, _WSMngSearchData::modules, _WSMngSearchData::search_in_history, stop_if_needed(), _WSMngSearchData::thread_creation, _WSMngSearchData::trans, _WSMngSearchData::word, _WSMngSearchData::word_list, WS_DBUS_ERROR_ENGINE_NOT_FOUND, WS_DBUS_ERROR_FILE_NOT_FOUND, WS_DBUS_LOAD_BOOKMARK_FAILED, ws_dbus_notify, ws_mng_close(), ws_mng_get_engines_location(), ws_mng_load_bookmark(), ws_mng_load_dict(), and ws_mng_read_gconf().

Referenced by main().

00182 {
00183         g_debug("->%s", __FUNCTION__);
00184 
00185         /* create and initialize all data in WSMngSearchData structure */
00186         data->dict = g_array_new(TRUE, TRUE, sizeof(Engine *));
00187         data->modules = g_array_new(TRUE, TRUE, sizeof(EngineModule));
00188         data->libraries = g_array_new(TRUE, TRUE, sizeof(GModule*));
00189         data->word_list = NULL;
00190         data->last_search = NULL;
00191         data->trans = NULL;
00192         data->search_in_history = FALSE;
00193         data->word = NULL;
00194         data->bookmark = NULL;
00195         data->bookmark_mode = FALSE;
00196         /* added by Dariusz Wiechecki
00197          * mutex initialization */
00198         data->action_working =
00199                        (GStaticMutex*)g_try_malloc(sizeof(GStaticMutex));
00200         data->thread_creation =
00201                        (GStaticMutex*)g_try_malloc(sizeof(GStaticMutex));
00202         data->action_stop =
00203                        (GStaticRecMutex*)g_try_malloc(sizeof(GStaticRecMutex));
00204         g_assert(NULL != (data->action_working) );
00205         g_assert(NULL != (data->action_stop) );
00206         g_static_mutex_init (data->action_working);
00207         g_static_mutex_init (data->thread_creation);
00208         g_static_rec_mutex_init (data->action_stop);
00209         /* initialize static stop_if_needed function mutex*/
00210         stop_if_needed (NULL);
00211 
00212         /* send signal if there is not proper sqlite library */
00213         #ifdef SQLITE
00214         if( FALSE == g_file_test(LIBRARY, G_FILE_TEST_EXISTS) )
00215         {
00216                 ws_dbus_notify(data->dbus_data, WS_DBUS_LOAD_BOOKMARK_FAILED);
00217         }
00218         #endif
00219 
00220         /* load GConf configuration */
00221         GArray* dict_directory = ws_mng_read_gconf();
00222         data->library_path = ws_mng_get_engines_location();
00223 
00224         gint i = 0;
00225         for (; i < data->library_path->len; ++i)
00226         {
00227                 gchar* path= g_array_index(data->library_path, gchar*, i);
00228                 GModule* library = g_module_open(path, G_MODULE_BIND_LAZY);
00229                 g_array_append_val(data->libraries, library);
00230                 g_debug("%p library pinter %d iter", library, i);
00231         }
00232 
00233         getting_additional_t get_functions = NULL;
00234         for (i=0; i<data->libraries->len; i++)
00235         {
00236                 g_debug("%p", g_array_index(data->libraries, GModule*, i));
00237                 g_module_symbol( g_array_index(data->libraries, GModule*, i),
00238                                  GLOBAL_FUNCTIONS_NAME,
00239                                  (gpointer)&get_functions );
00240                 g_debug("%d     %p", i, &get_functions);
00241 
00242                 /* if function was not properly imported close manager */
00243                 if (NULL == get_functions)
00244                 {
00245                         ws_dbus_notify( data->dbus_data,
00246                                         WS_DBUS_ERROR_ENGINE_NOT_FOUND );
00247                         for (i=0; i<dict_directory->len; i++)
00248                         {
00249                                 g_free(g_array_index( dict_directory,
00250                                                       gchar*,
00251                                                       i ));
00252                         }
00253                         g_array_free(dict_directory, TRUE);
00254                         ws_mng_close(data);
00255                         exit(0);
00256                 }
00257 
00258                 /* get EngineModule struct and append it to the array*/
00259                 EngineModule module =  get_functions();
00260                 g_array_append_val(data->modules, module);
00261         }
00262 
00263         /* load each dictionary */
00264         ws_mng_load_bookmark(data);
00265         if (dict_directory->len > 0)
00266         {
00267                 ws_mng_load_dict(dict_directory, data);
00268                 guint i = 0;
00269                 g_debug("Trace bookmark engine %p", data->bookmark);
00270                 for (i=0; i<data->dict->len; i++)
00271                 {
00272                         g_debug( "dict engines at %p",
00273                                  g_array_index(data->dict, Engine*, i) );
00274                 }
00275         }
00276         else
00277         {
00278                 ws_dbus_notify( data->dbus_data,
00279                                 WS_DBUS_ERROR_FILE_NOT_FOUND );
00280         }
00281 
00282         /* free memory used by dictionaries path array */
00283         for (i=0; i<dict_directory->len; i++)
00284         {
00285                 g_free(g_array_index(dict_directory, gchar*, i));
00286         }
00287         g_array_free(dict_directory, TRUE);
00288 
00289         g_debug("<-%s", __FUNCTION__);
00290 }

void ws_mng_init_dbus ( WSMngSearchData data  ) 

Function used to initialize D-BUS.

Parameters:
data structure stores variables which are need to comunicate by D-BUS.

Definition at line 73 of file ws_manager.c.

References _WSMngSearchAtom::data, _WSMngSearchData::dbus_data, GUI_IFACE, GUI_OBJECT, GUI_SERVICE, MANAGER_IFACE, MANAGER_OBJECT, MANAGER_SERVICE, ws_dbus_add_method(), ws_dbus_config(), ws_dbus_connect(), ws_dbus_create(), ws_dbus_set_cb(), ws_mng_add_bookmark(), ws_mng_extract_dictionary(), ws_mng_on_search_translation(), ws_mng_on_search_word(), ws_mng_remove_bookmark(), and ws_mng_signal_handling().

Referenced by main().

00074 {
00075         g_debug("->%s", __FUNCTION__);
00076 
00077         /* initialize GThread support if it is not initialized yet */
00078         if (!g_thread_supported ()) g_thread_init (NULL);
00079 
00080         /* create data structure needed to comunicate with dbus wrapper */
00081         data->dbus_data = ws_dbus_create ("mdictionaryManager", "v1.0");
00082 
00083         /* set data used to comunicate with gui */
00084         ws_dbus_config(data->dbus_data,
00085                        WS_DBUS_CONFIG_SERVICE,
00086                        MANAGER_SERVICE);
00087         ws_dbus_config(data->dbus_data,
00088                         WS_DBUS_CONFIG_OBJECT,
00089                         MANAGER_OBJECT);
00090         ws_dbus_config(data->dbus_data,
00091                         WS_DBUS_CONFIG_IFACE,
00092                         MANAGER_IFACE);
00093         ws_dbus_config(data->dbus_data, 
00094                         WS_DBUS_CONFIG_REMOTE_SERVICE,
00095                         GUI_SERVICE);
00096         ws_dbus_config(data->dbus_data, 
00097                         WS_DBUS_CONFIG_REMOTE_OBJECT,
00098                         GUI_OBJECT);
00099         ws_dbus_config(data->dbus_data, 
00100                         WS_DBUS_CONFIG_REMOTE_IFACE,
00101                         GUI_IFACE);
00102 
00103         /* defines all methods which could be called through D-Bus */
00104         ws_dbus_add_method ( data->dbus_data,
00105                              "find_word",
00106                              WS_DBUS_TYPE_STRING,
00107                              WS_DBUS_TYPE_INVALID );
00108         ws_dbus_add_method ( data->dbus_data,
00109                              "find_translation",
00110                              WS_DBUS_TYPE_STRING,
00111                              WS_DBUS_TYPE_INVALID );
00112         ws_dbus_add_method ( data->dbus_data,
00113                              "signal",
00114                              WS_DBUS_TYPE_SIGNAL,
00115                              WS_DBUS_TYPE_INVALID );
00116         ws_dbus_add_method ( data->dbus_data,
00117                              "add_bookmark",
00118                              WS_DBUS_TYPE_STRING,
00119                              WS_DBUS_TYPE_STRING,
00120                              WS_DBUS_TYPE_INVALID );
00121         ws_dbus_add_method ( data->dbus_data,
00122                              "remove_bookmark",
00123                              WS_DBUS_TYPE_STRING,
00124                              WS_DBUS_TYPE_INVALID );
00125         ws_dbus_add_method ( data->dbus_data,
00126                              "extract_dictionary",
00127                              WS_DBUS_TYPE_STRING,
00128                              WS_DBUS_TYPE_INVALID );
00129 
00130         /* set callback for find word signal */
00131         ws_dbus_set_cb( data->dbus_data,
00132                         "find_word",
00133                         ws_mng_on_search_word,
00134                         data );
00135 
00136         /* set callback for find translation signal */
00137          ws_dbus_set_cb( data->dbus_data,
00138                          "find_translation",
00139                          ws_mng_on_search_translation,
00140                          data );
00141 
00142         /* set callback for close program signal */
00143         ws_dbus_set_cb( data->dbus_data,
00144                         "signal",
00145                         ws_mng_signal_handling,
00146                         data );
00147 
00148          /* set callback for add bookmarks signal */
00149         ws_dbus_set_cb( data->dbus_data,
00150                         "add_bookmark",
00151                         ws_mng_add_bookmark,
00152                         data );
00153 
00154         /* set callback for remove bookmarks signal */
00155         ws_dbus_set_cb( data->dbus_data,
00156                         "remove_bookmark",
00157                         ws_mng_remove_bookmark,
00158                         data );
00159 
00160         /* set callback for extracting dictionary */
00161         ws_dbus_set_cb( data->dbus_data,
00162                         "extract_dictionary",
00163                         ws_mng_extract_dictionary,
00164                         data );
00165 
00166         /* initialize d-bus connection with remote service - UI */
00167         ws_dbus_connect(data->dbus_data);
00168 
00169         g_debug("<-%s", __FUNCTION__);
00170 }

void ws_mng_load_bookmark ( WSMngSearchData data  ) 

Load bookmarks dictionary engine.

Function used to load bookmark module

Parameters:
data structure which holds the loaded module

Definition at line 130 of file ws_mng_bookmarks_utils.c.

References _WSMngSearchData::bookmark, _WSMngSearchAtom::data, dict_eng_module_check, dict_eng_module_create_ext, dict_eng_set_callback, ENGINE_CREATE, ENGINE_WORD_LIST_SIGNAL, ENGINE_WORD_TRANSLATION_SIGNAL, _WSMngSearchData::modules, ws_mng_get_boomark_location(), ws_mng_on_found_translation(), ws_mng_on_found_word(), and ws_mng_progress_bar().

Referenced by ws_mng_init().

00131 {
00132         g_debug("->%s", __FUNCTION__);
00133         guint i = 0;
00134         data->bookmark = NULL;
00135         gchar* current_directory = ws_mng_get_boomark_location();
00136 
00137         if (NULL != current_directory)
00138         {
00139                 for (i = 0; i < data->modules->len; ++i)
00140                 {
00141                         /* check each engine module to be compatible with 
00142                          * bookmark dictionary - searching for bookmark module*/
00143                         if (TRUE == dict_eng_module_check(
00144                                  g_array_index(data->modules, EngineModule, i),
00145                                  current_directory ))
00146                         {
00147                                 /* create engine for handling bookmarks */
00148                                 data->bookmark =
00149                                 dict_eng_module_create_ext(
00150                                                 g_array_index(data->modules,
00151                                                               EngineModule,
00152                                                               i),
00153                                                current_directory,
00154                                                ENGINE_CREATE,
00155                                                ws_mng_progress_bar,
00156                                                data,
00157                                                0.02 );
00158                                 /* set callbacks */
00159                                 dict_eng_set_callback( data->bookmark,
00160                                                        ENGINE_WORD_LIST_SIGNAL,
00161                                                        ws_mng_on_found_word,
00162                                                        data );
00163                                 dict_eng_set_callback(data->bookmark,
00164                                                  ENGINE_WORD_TRANSLATION_SIGNAL,
00165                                                  ws_mng_on_found_translation,
00166                                                  data);
00167                                 /* bookmark engine found - stop searching */
00168                                 break;
00169                         }
00170                 }
00171                 g_free(current_directory);
00172         }
00173         g_debug("<-%s", __FUNCTION__);
00174 }

void ws_mng_load_dict ( GArray *  dict_directory,
WSMngSearchData data 
)

Function used to load dictionaries engines.

Function used to load dictionaries engines

Parameters:
dict_directory path to dictionaries
data structure which contains all data of program

Definition at line 87 of file ws_mng_dictionary_utils.c.

References _WSMngSearchAtom::data, _WSMngSearchData::dict, dict_eng_module_check, dict_eng_module_create_ext, dict_eng_set_callback, ENGINE_CREATE, ENGINE_NO, ENGINE_WORD_LIST_SIGNAL, ENGINE_WORD_TRANSLATION_SIGNAL, _WSMngSearchData::modules, ws_mng_if_optimized(), ws_mng_on_found_translation(), ws_mng_on_found_word(), and ws_mng_progress_bar().

Referenced by ws_mng_init(), and ws_mng_signal_handling().

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 }

void ws_mng_on_found_translation ( gchar *  translation,
gchar *  pattern,
gpointer  user_data,
EngineStatus  error 
)

Used to return results of transaltion from threads.

Parameters:
translation translation of word found in dictionaries
pattern a word which is being serch for in dictionaries
user_data data passed to function
error engine status information

Definition at line 217 of file ws_mng_searching_threads.c.

References _WSMngSearchAtom::trans.

Referenced by ws_mng_load_bookmark(), and ws_mng_load_dict().

00222 {
00223         g_debug("->%s", __FUNCTION__);
00224         WSMngSearchAtom* search_atom = (WSMngSearchAtom*)user_data;
00225 
00226         /* we get already the first translation */
00227         if ((NULL != translation) && (NULL == search_atom->trans))
00228         {
00229                 /* concatenate tags and searched word and translation */
00230                 search_atom->trans = g_strconcat("<PATTERN_OPEN>",
00231                                           pattern,
00232                                           "<PATTERN_CLOSED><TRANSLATION_OPEN>",
00233                                           translation,
00234                                           "<TRANSLATION_CLOSED>",
00235                                           NULL
00236                                          );
00237         }
00238         else if (NULL != translation)
00239         {
00240                 /* if there was stored translation
00241                  * copy stored translation to temporary variable */
00242                 gchar* tmp = g_strconcat(search_atom->trans,
00243                                          "<TRANSLATION_OPEN>",
00244                                          translation,
00245                                          "<TRANSLATION_CLOSED>",
00246                                          NULL);
00247                 /* free memory used by stored old translation */
00248                 gchar* loc_tmp = search_atom->trans;
00249                 search_atom->trans = tmp;
00250                 g_free(loc_tmp);
00251                 tmp = loc_tmp = NULL;
00252         }
00253 
00254         g_debug("<-%s", __FUNCTION__);
00255 }

void ws_mng_on_found_word ( GArray *  list,
gchar *  pattern,
gpointer  user_data,
EngineStatus  error 
)

Used to return results of found words from threads.

Parameters:
list word list found in dictionaries
pattern a word which is being search for in dictionaries
user_data data passed to function
error engine status information

Definition at line 126 of file ws_mng_searching_threads.c.

References _WSMngSearchAtom::word_list.

Referenced by ws_mng_load_bookmark(), and ws_mng_load_dict().

00130 {
00131         g_debug("[T-word-ret]-> %s", __FUNCTION__);
00132 
00133         WSMngSearchAtom* search_atom = (WSMngSearchAtom*)user_data;
00134         static gint i = 0;
00135         for (i = 0; i < list->len; i++)
00136         {
00137                 /* copy word found by search engine */
00138                 gchar* new_word = g_strdup(g_array_index(list, gchar*, i));
00139                 g_array_append_val(search_atom->word_list, new_word); 
00140                 
00141         }
00142 
00143         g_debug("[T-word-ret]<- %s", __FUNCTION__);
00144 }

void ws_mng_on_search_translation ( GError *  error,
GArray *  word,
gpointer  user_data 
)

Called when find translation event occurs (UI).

Parameters:
word word to search
error error messages
user_data user data passed to function

Definition at line 110 of file ws_mng_callbacks.c.

References create_search_atom(), _WSMngSearchAtom::data, _WSMngSearchAtom::thread, _WSMngSearchData::thread_creation, and ws_mng_search_translation().

Referenced by ws_mng_init_dbus().

00113 {
00114         g_debug("[L-tran] ->%s", __FUNCTION__);
00115 
00116         WSMngSearchData *data = (WSMngSearchData *) user_data;
00117 
00118         /* ---> CRITICAL SECTION for this function */
00119         g_static_mutex_lock(data->thread_creation);
00120 
00121         /* get the data sended by dbus */
00122         osso_rpc_t *osso_data;
00123         osso_data = &g_array_index (word, osso_rpc_t, 0);
00124 
00125         /* create and init searching data - separate for each thread */
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         /* <--- end of CRITICAL SECTION for this function */
00143 
00144         g_debug("[L-tran] <-%s", __FUNCTION__);
00145 }

void ws_mng_on_search_word ( GError *  error,
GArray *  word,
gpointer  user_data 
)

Called when find word event occurs (UI).

Parameters:
word word to search
error error messages
user_data user data passed to function

Definition at line 50 of file ws_mng_callbacks.c.

References create_search_atom(), _WSMngSearchAtom::thread, _WSMngSearchData::thread_creation, and ws_mng_search_word().

Referenced by ws_mng_init_dbus().

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         /* ---> CRITICAL SECTION for this function */
00059         g_static_mutex_lock( search->thread_creation );
00060 
00061         /* get the word passed by dbus */
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                 /* check if we need add wildcard '*' at the end of the word */
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         /* create and init searching data - separate for each thread */
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         /* <--- end of CRITICAL SECTION for this function */
00101 
00102         g_debug("[L-word] <-%s", __FUNCTION__);
00103 }

void ws_mng_progress_bar ( double  progress,
gpointer  user_data,
EngineStatus  error 
)

Function used to send information about progress of caching (engines).

Parameters:
progess how much file is cached
user_data data needed to send information to UI
error error messages

Definition at line 34 of file ws_mng_callbacks.c.

References _WSMngSearchAtom::data, _WSMngSearchData::dbus_data, and ws_dbus_server_update_progressbar.

Referenced by ws_mng_load_bookmark(), and ws_mng_load_dict().

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 }

GArray * ws_mng_read_gconf (  ) 

Function used to get the dictionaries location read fron GConf.

Function read from GConf locations of every dictionary and return them in GArray to make it possible to load them.

Returns:
path to dictionaries location

Definition at line 36 of file ws_mng_gconf_utils.c.

References GCONF_KEY.

Referenced by ws_mng_init(), and ws_mng_signal_handling().

00037 {
00038         g_debug("--%s", __FUNCTION__);
00039         GConfClient* client = NULL;
00040         client = gconf_client_get_default();
00041         GArray* path_to_dir = g_array_new(TRUE, TRUE, sizeof(gchar *));
00042         gchar* path = NULL;
00043         gboolean key_active = FALSE;
00044         gint i = 0;
00045 
00046         /* get location of every dictionary */
00047         GSList* list = gconf_client_all_dirs(client, GCONF_KEY, NULL);
00048         for (i = 0; i < g_slist_length(list); ++i)
00049         {
00050                 path = (gchar* ) g_slist_nth_data(list, i);
00051                 gchar* new_path = g_strconcat(path, "/path", NULL);
00052                 gchar* new_active = g_strconcat(path, "/active", NULL);
00053                 key_active = gconf_client_get_bool(client, new_active, NULL);
00054                 if (key_active == TRUE)
00055                 {
00056                         gchar* key_value = gconf_client_get_string( client,
00057                                                                     new_path,
00058                                                                     NULL );
00059                         if (key_value != NULL){
00060                                 g_array_append_val(path_to_dir, key_value);
00061                         }
00062                 }
00063                 g_free(new_path);
00064                 g_free(new_active);
00065         }
00066 
00067         /* free memmory */
00068         for (i=0; i<g_slist_length(list); i++)
00069         {
00070                 g_free(g_slist_nth_data(list, i));
00071         }
00072         g_slist_free(list);
00073         g_object_unref (client);
00074         return path_to_dir;
00075 }

void ws_mng_remove_bookmark ( GError *  error,
GArray *  param,
gpointer  user_data 
)

Remove specified word from bookmark engine.

Function used to remove bookmarks.

Parameters:
error error messages
param word and translation of word to remove
user_data structure holding nedded parameters

Definition at line 86 of file ws_mng_bookmarks_utils.c.

References _WSMngSearchData::bookmark, _WSMngSearchAtom::data, _WSMngSearchData::dbus_data, dict_eng_remove_word, _WSMngSearchAtom::word, WS_DBUS_BOOKMARKS_ADDED_FAIL, WS_DBUS_BOOKMARKS_REMOVED_FAIL, WS_DBUS_BOOKMARKS_REMOVED_OK, and ws_dbus_notify.

Referenced by ws_mng_init_dbus().

00087 {
00088         g_debug("->%s", __FUNCTION__);
00089 
00090         WSMngSearchData* data = (WSMngSearchData *) user_data;
00091         osso_rpc_t* osso_data = NULL;
00092         gchar* word = NULL;
00093 
00094         if (data->bookmark != NULL)
00095         {
00096                 /* get the word passed by dbus */
00097                 osso_data = &g_array_index(param, osso_rpc_t, 0); 
00098                 word = g_strdup(osso_data->value.s);
00099 
00100                 gboolean is_remove  = dict_eng_remove_word( data->bookmark,
00101                                                             word );
00102                 if (TRUE == is_remove)
00103                 {
00104                         ws_dbus_notify( data->dbus_data, 
00105                                         WS_DBUS_BOOKMARKS_REMOVED_OK );
00106                 }
00107                 else 
00108                 {
00109                         ws_dbus_notify( data->dbus_data, 
00110                                         WS_DBUS_BOOKMARKS_REMOVED_FAIL );
00111                 }
00112 
00113                 osso_rpc_free_val(osso_data);
00114         }
00115         else
00116         {       
00117                 ws_dbus_notify( data->dbus_data,
00118                                 WS_DBUS_BOOKMARKS_ADDED_FAIL );
00119                 g_debug("-> %s - there is no bookmark engine!\n", __FUNCTION__);
00120         }
00121 
00122         g_debug("<-%s", __FUNCTION__);
00123 }

gpointer ws_mng_search_translation ( gpointer  data  ) 

Function executed by thread - search for particular word.

Parameters:
data required data for search translation
Returns:
gpointer return value

Definition at line 150 of file ws_mng_searching_threads.c.

References _WSMngSearchData::action_stop, _WSMngSearchData::action_working, _WSMngSearchData::bookmark, _WSMngSearchData::bookmark_mode, _WSMngSearchAtom::data, _WSMngSearchData::dbus_data, _WSMngSearchData::dict, dict_eng_search_word_translation, stop_if_needed(), try_lock_was_locked(), _WSMngSearchAtom::word, ws_dbus_notify, and WS_DBUS_TRANSLATION_STARTED.

Referenced by ws_mng_on_search_translation().

00151 {
00152         g_debug("[T-tran] %s: Entering thread...", __FUNCTION__);
00153         WSMngSearchAtom* search_atom = (WSMngSearchAtom*)data;
00154         WSMngSearchData* search = search_atom->data;
00155 
00156         /* ---> CRITICAL SECTION for this function */
00157         if (try_lock_was_locked(search,(gchar*)__FUNCTION__))
00158         {
00159                 g_printf("[T-tran] STOP mutex is locked! Aborting others!");
00160                 g_static_rec_mutex_lock(search->action_stop);
00161                 g_static_mutex_lock(search->action_working);
00162         }
00163         g_static_rec_mutex_unlock(search->action_stop);
00164         /* if another thread was run after this one - exit */
00165         stop_if_needed(search_atom);
00166 
00167         g_debug( "[T-tran] %s - from now this thread is \'singleton\' ",
00168                  __FUNCTION__ );
00169         ws_dbus_notify(search->dbus_data, WS_DBUS_TRANSLATION_STARTED);
00170 
00171         /* run search for translation for every dictionary */
00172         if (search->bookmark_mode)
00173         {
00174                 dict_eng_search_word_translation( search->bookmark,
00175                                                   search_atom->word,
00176                                                   search_atom );
00177         }
00178         else
00179         {
00180                 gint i;
00181                 for (i = 0; i < search->dict->len; i++)
00182                 {
00183                         stop_if_needed(search_atom);
00184                         if (NULL == g_array_index(search->dict, Engine*, i) )
00185                         {
00186                                 continue;
00187                         }
00188                         dict_eng_search_word_translation(
00189                                         g_array_index(search->dict, Engine*, i),
00190                                         search_atom->word,
00191                                         search_atom);
00192                 }
00193         }
00194         g_debug("[T-tran] %s - searching finished.",__FUNCTION__);
00195 
00196         /* if another thread was run after this one - exit */
00197         stop_if_needed(search_atom);
00198 
00199         /* send translation to gui */
00200         ws_dbus_server_return_translations(search->dbus_data, search_atom->trans);
00201         ws_dbus_notify(search->dbus_data, WS_DBUS_TRANSLATION_FINISHED);
00202 
00203         g_free(search->trans);
00204         search->trans = NULL;
00205 
00206         g_debug("[T-word] %s - leaving thread!", __FUNCTION__);
00207         g_static_mutex_unlock(search->action_working);
00208         return NULL;
00209 }

gpointer ws_mng_search_word ( gpointer  user_data  ) 

Function executed by thread - search for word list.

Parameters:
data required data for search word event
Returns:
gpointer return value

Definition at line 33 of file ws_mng_searching_threads.c.

References _WSMngSearchData::action_stop, _WSMngSearchData::action_working, _WSMngSearchData::bookmark, _WSMngSearchData::bookmark_mode, _WSMngSearchAtom::data, _WSMngSearchData::dbus_data, _WSMngSearchData::dict, dict_eng_search_word_list, stop_if_needed(), try_lock_was_locked(), _WSMngSearchAtom::word, _WSMngSearchAtom::word_list, ws_dbus_notify, and WS_DBUS_WORDS_LIST_STARTED.

Referenced by ws_mng_on_search_word().

00034 {
00035         g_debug("[T-word] %s: Entering thread...", __FUNCTION__);
00036         WSMngSearchAtom *search_atom = (WSMngSearchAtom*)user_data;
00037         WSMngSearchData *search = search_atom->data;
00038 
00039         /* enter into CRITICAL SECTION */
00040         if (try_lock_was_locked(search,(gchar*)__FUNCTION__))
00041         {
00042                 g_printf("[T-word] STOP mutex is locked! Aborting others!");
00043                 g_static_rec_mutex_lock(search->action_stop);
00044                 g_static_mutex_lock(search->action_working);
00045         }
00046         g_static_rec_mutex_unlock(search->action_stop);
00047 
00048         /* if another thread was run after this one - exit */
00049         stop_if_needed(search_atom);
00050 
00051         g_debug( "[T-word] %s - from now this thread is \'singleton\' ",
00052                  __FUNCTION__ );
00053         ws_dbus_notify(search->dbus_data, WS_DBUS_WORDS_LIST_STARTED);
00054         /* creating new GArray for word list */
00055         search_atom->word_list = g_array_new(TRUE, TRUE, sizeof(gchar*));
00056 
00057         g_debug("[T-word] %s - start searching... ",__FUNCTION__);
00058         if (search->bookmark_mode)
00059         {
00060                 /* search only in user bookmarks */
00061                 dict_eng_search_word_list( search->bookmark,
00062                                            search_atom->word,
00063                                            search_atom );
00064         }
00065         else
00066         {
00067                 /* search for word in each dictionary */
00068                 gint i = 0;
00069                 for (i = 0; i < search->dict->len; i++)
00070                 {
00071                         if (NULL == g_array_index(search->dict, Engine *, i))
00072                         {
00073                                 continue;
00074                         }
00075 
00076                         stop_if_needed(search_atom);
00077                         Engine* dict = g_array_index(search->dict,Engine *,i);
00078                         dict_eng_search_word_list( dict,
00079                                                    search_atom->word,
00080                                                    search_atom );
00081                 }
00082         }
00083         g_debug("[T-word] %s - searching finished.",__FUNCTION__);
00084 
00085         /* if another thread was run after this one - exit */
00086         stop_if_needed(search_atom);
00087 
00088         /* sort and cleaning words list - only if there were more than one
00089          * dictionary loaded */
00090         if ((FALSE == search->bookmark_mode) || (1 < search->dict->len))
00091         {
00092                 g_array_sort(search_atom->word_list, ws_mng_compare_strings);
00093                 ws_remove_multiple_words(search_atom);
00094         }
00095 
00096         /* if another thread was run after this one - exit */
00097         stop_if_needed(search_atom);
00098 
00099         ws_dbus_server_return_words(search->dbus_data, search_atom->word_list);
00100         ws_dbus_notify(search->dbus_data, WS_DBUS_WORDS_LIST_FINISHED);
00101 
00102         /* free memory used by each word from word list */
00103         gint i = 0;
00104         for (; i < search_atom->word_list->len; ++i)
00105         {
00106                 g_free(g_array_index(search_atom->word_list,gchar* ,i));
00107         }
00108 
00109         /* free memory used by GArray */
00110         g_array_free(search_atom->word_list, TRUE);
00111         search_atom->word_list = NULL;
00112 
00113         g_free(search_atom->word);
00114         g_free(search_atom);
00115         g_debug("[T-word] %s - leaving thread!", __FUNCTION__);
00116         g_static_mutex_unlock(search->action_working);
00117         return NULL;
00118 }

void ws_mng_signal_handling ( GError *  error,
GArray *  signal,
gpointer  user_data 
)

Function used for handling signals sent by user interface (UI).

Parameters:
error error messages
signal type of signal
user_data data passed to function

Definition at line 153 of file ws_mng_callbacks.c.

References _WSMngSearchData::action_stop, _WSMngSearchData::action_working, _WSMngSearchData::bookmark_mode, _WSMngSearchAtom::data, _WSMngSearchData::dbus_data, _WSMngSearchData::dict, dict_eng_destroy, _WSMngSearchData::last_search, _WSMngSearchData::loop, try_lock_was_locked(), _WSMngSearchData::word, _WSMngSearchData::word_list, WS_DBUS_BOOKMARK_MODE_OFF, WS_DBUS_BOOKMARK_MODE_ON, WS_DBUS_ERROR_FILE_NOT_FOUND, WS_DBUS_INFO_CACHING, WS_DBUS_INFO_CACHING_FINISHED, WS_DBUS_INFO_CONFIG_CHANGED, WS_DBUS_INFO_STOP_SEARCH, WS_DBUS_INFO_TERMINATE, ws_dbus_notify, WS_DBUS_TRANSLATION_FINISHED, WS_DBUS_WORDS_LIST_FINISHED, ws_mng_load_dict(), and ws_mng_read_gconf().

Referenced by ws_mng_init_dbus().

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                         /* added by Dariusz Wiechecki
00165                          * canceling GLib Threads if any is working */
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                         /* end current proccess */
00175                         g_main_loop_quit (data->loop);
00176                 break;
00177                 case WS_DBUS_INFO_STOP_SEARCH:
00178                         /* added by Dariusz Wiechecki
00179                          * canceling GLib Threads if any is working */
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                         /* first remove all dictionaries */
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                         /* load dictionaries again in the new configuration */
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                         /* check if there was loaded any dictionary */
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                                 /*if there was typed word search for word list*/
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                                 /* signal end of dictionary load to gui */
00236                                 ws_dbus_notify( data->dbus_data,
00237                                                 WS_DBUS_INFO_CACHING_FINISHED );
00238                         }
00239 
00240                         /* free memmory */
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 }

gboolean ws_mng_start_main_loop ( WSMngSearchData search_data  ) 

Function used to run and initialize main loop.

Parameters:
serach_data structure which contains all data of program
Returns:
TRUE if successfully run main loop, FALSE otherwise

Definition at line 57 of file ws_manager.c.

References _WSMngSearchData::loop.

Referenced by main().

00058 {
00059         g_debug("<--> %s", __FUNCTION__);
00060         search_data->loop = g_main_loop_new (NULL, FALSE);
00061         if (search_data->loop == NULL)
00062         {
00063                 g_debug("Couldn't create new g_main_loop for Manager!");
00064                 return FALSE;
00065         }
00066         g_main_loop_run (search_data->loop);
00067         return TRUE;
00068 }

void ws_remove_multiple_words ( WSMngSearchAtom user_data  ) 

Removes repeating words on the returned words list.

The same word could be existed in few dictionaries. Each of this dictionaries will return this word and manager will add it to the wrods list. But finally there should not be repeating words on the list, so we have to remove repeated one (leave only one).

Parameters:
user_data WSMngSearchAtom with array of all words returned from all dictionaries

Definition at line 286 of file ws_mng_searching_threads.c.

References _WSMngSearchAtom::data, _WSMngSearchData::dbus_data, _WSMngSearchAtom::word_list, ws_dbus_notify, WS_DBUS_WORDS_LIST_FILLED_NOT_FULL, and WS_DBUS_WORDS_LIST_FULL.

00287 {
00288         WSMngSearchAtom* search = (WSMngSearchAtom*)user_data;
00289         gint j = 0;
00290         gint i = 0;
00291         gint result = -1;
00292         gint temp = 256;
00293         gchar* tmp1 = NULL;
00294         gchar* tmp2 = NULL;
00295 
00296         /* check if words list is longer than 256 words */
00297         if (search->word_list->len < 256)
00298         {
00299                 temp = search->word_list->len;
00300                 if (temp >0)
00301                 {
00302                         ws_dbus_notify( search->data->dbus_data,
00303                                         WS_DBUS_WORDS_LIST_FILLED_NOT_FULL );
00304                 }
00305         }
00306         else
00307         {
00308                 ws_dbus_notify( search->data->dbus_data,
00309                                 WS_DBUS_WORDS_LIST_FULL );
00310         }
00311 
00312         /* remove repeating words in the first 256 places in the array - words
00313          * in places further than 256 are not being sent to UI so we do not need
00314          * to filter them for searching repeating words */
00315         for (i = 0; i < temp-1; i++)
00316         {
00317                 tmp1 = g_utf8_casefold(
00318                                g_array_index(search->word_list,gchar*,i),
00319                                -1     );
00320                 for (j = i + 1; j < temp; j++)
00321                 {
00322                         /* search if there is a word on word list */
00323                         tmp2 = g_utf8_casefold(
00324                                     g_array_index(search->word_list,gchar*,j),
00325                                     -1 );
00326                         result = g_utf8_collate(tmp1,tmp2);
00327                         g_free(tmp2);
00328                         tmp2 = NULL;
00329 
00330                         /* if there is a word on the word list 
00331                          * remove that word */
00332                         if (result == 0)
00333                         {
00334                                 g_array_remove_index(search->word_list, j);
00335                                 --j;
00336                                 --temp;
00337                                 if (search->word_list->len >= 256)
00338                                 {
00339                                         temp = 256;
00340                                 }
00341                         }
00342                         else {
00343                                 /* there is no possiblity that further
00344                                  * will be the same word, check next word */
00345                                 break;
00346                         }
00347                 }
00348                 g_free(tmp1);
00349                 tmp1 = NULL;
00350         }
00351 }


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