+/*******************************************************************************
+This file is part of mDictionary
+
+mDictionary is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+mDictionary is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with WhiteStork; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Copyright 2006-2008 ComArch S.A.
+*******************************************************************************/
+/** \addtogroup Manager
+ */
+/*@{*/
+/** \file untar.h
+ * \brief Exctracting *.tar.bz2 archives header.
+ */
#ifndef _WS_UNTAR
#define _WS_UNTAR
#include <glib.h>
-/*
-Usage example:
+#include <untar.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <bzlib.h>
+#include <sys/stat.h>
+
+/** \name 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.
+ */
+/*@{*/
-decompress_file ("comn_dictd04_wn.tar.bz2", "./");
+/** \brief Define block size used in the header of archive.
+ */
+#define BLOCK_SIZE 512
-The above example extracts a given archive, to the current directory
-*/
+/** \brief Define buffer size for blocks.
+ */
+#define BUFFER_SIZE BLOCK_SIZE*32
+/** \brief Translate number into its ASCI code.
+ */
+#define ASCII_NR(NR) (NR + 0x30)
+
+/** \brief Structure of entry in tar header.
+ *
+ * See tar file specyfication for more information.
+ */
+typedef struct _TarHeader
+{
+ gchar name[100];
+ gchar mode[8];
+ gchar uid[8];
+ gchar gid[8];
+ gchar size[12];
+ gchar mtime[12];
+ gchar chksum[8];
+ gchar typeflag;
+ gchar linkname[100];
+ gchar magic[6];
+ gchar version[2];
+ gchar uname[32];
+ gchar gname[32];
+ gchar devmajor[8];
+ gchar devminor[8];
+ gchar prefix[155];
+ gchar padding[12];
+ gchar *gnu_longname;
+ gchar *gnu_longlink;
+} TarHeader;
+
+/** \brief 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 enum _RecordType
+{
+ File = ASCII_NR (0),
+ ARCHLINK = ASCII_NR (1),
+ SYMLINK = ASCII_NR (2),
+ CHARDEV = ASCII_NR (3),
+ BLOCKDEV = ASCII_NR (4),
+ Dir = ASCII_NR (5),
+ FIFO = ASCII_NR (6),
+ RESERVED = ASCII_NR (7)
+} RecordType;
+
+/** \brief Uncompress bz2 archive and extract tar file.
+ *
+ */
gint decompress_file(gchar *in_file, gchar **out_path);
+/*@}*/
#endif /*_WS_UNTAR*/
+/*@}*/
+
Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
-/** \file ws_manager.h
- * \brief mDictionary Manager main module header.
- *
- * \author Łukasz Pawlik \<lukasz.pawlik\@comarch.com\>
- */
-
/** \brief mDictionary Manager.
* \defgroup Manager mDictionary Manager
*
*/
/*@{*/
+/** \file ws_manager.h
+ * \brief mDictionary Manager main module header.
+ *
+ * \author Łukasz Pawlik \<lukasz.pawlik\@comarch.com\>
+ */
+
#ifndef _WS_MANAGER
#define _WS_MANAGER
#ifdef __cplusplus
}
#endif
-
#endif
-
/*@}*/
along with mdictionary; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-Copyright 2006-2007 ComArch S.A.
+Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
+/** \addtogroup Manager */
+/*@{*/
+/** \file ws_mng_bookmarks_utils.h
+ * \brief Utilities for Manager connected with managing bookmarks - header.
+ *
+ */
+
#ifndef _WS_MANAGER_BOOKMARKS
#define _WS_MANAGER_BOOKMARKS
extern "C" {
#endif
-/**
- * Function used to add bookmarks
- * @param error error messages
- * @param param word and translation of word to adding
- * @param user_data structure holding nedded parameters
+/** \name Bookmarks Utils */
+/*@{*/
+
+/** \brief Add new word to bookmark dictionary.
*/
void ws_mng_add_bookmark(GError *error, GArray* param, gpointer user_data);
-/**
- * Function used to remove bookmarks
- * @param error error messages
- * @param param word and translation of word to remove
- * @param user_data structure holding nedded parameters
+/** \brief Remove specified word from bookmark engine.
*/
void ws_mng_remove_bookmark(GError *error, GArray* param, gpointer user_data);
-/**
- * Function used to load bookmark module
- * @param data structure which holds the loaded module
+/** \brief Load bookmarks dictionary engine.
*/
void ws_mng_load_bookmark(WSMngSearchData* data);
+/*@}*/
+
#ifdef __cplusplus
}
#endif
#endif
+/*@{*/
along with mdictionary; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-Copyright 2006-2007 ComArch S.A.
+Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
+/** \addtogroup Manager */
+/*@{*/
+/** \file ws_mng_callbacks.h
+ * \brief Callback functions called by other modules - header.
+ */
#ifndef _WS_MANAGER_CALLBACKS
#define _WS_MANAGER_CALLBACKS
#include <ws_manager.h>
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
-void ws_mng_progress_bar (double progress,
- gpointer user_data,
- EngineStatus error);
+/** \name Callback function called by other modules (GUI and engines).
+ */
+/*@{*/
-void ws_mng_on_search_word (GError *error,
- GArray *word,
- gpointer user_data);
-void ws_mng_on_search_translation (GError *error,
- GArray *word,
- gpointer user_data);
+/** \brief Function used to send information about progress of caching (engines)
+ */
+void ws_mng_progress_bar( double progress,
+ gpointer user_data,
+ EngineStatus error );
-void ws_mng_signal_handling (GError *error,
- GArray *signal,
- gpointer user_data);
+/** \brief Called when find word event occurs (UI)
+ */
+void ws_mng_on_search_word( GError *error,
+ GArray *word,
+ gpointer user_data );
+/** \brief Called when find translation event occurs (UI)
+ */
+void ws_mng_on_search_translation( GError *error,
+ GArray *word,
+ gpointer user_data );
+/** \brief Function used for handling signals sent by user interface (UI)
+ */
+void ws_mng_signal_handling( GError *error,
+ GArray *signal,
+ gpointer user_data );
+
+/*@}*/
#ifdef __cplusplus
- }
+}
#endif
#endif
+/*@}*/
+
along with mdictionary; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-Copyright 2006-2007 ComArch S.A.
+Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
+/** \addtogroup Manager */
+/*@{*/
+/** \file ws_mng_dictionary_utils.h
+ * \brief Dictionaries common routines - header.
+ */
#ifndef _WS_MANAGER_DICTIONARY_UTILS
#define _WS_MANAGER_DICTIONARY_UTILS
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
+/** \name Dictionaries routines */
+/*@{*/
+
/** \brief Extracting compressed dictionary file
- *
- * @param error after excuting it contains error messages if any was
- * @param param parameters given by D-Bus
- * @param app_data manager data
*/
void ws_mng_extract_dictionary(GError *error, GArray* param, gpointer app_data);
-/**
- * Function used to load dictionaries engines
- * @param dict_directory path to dictionaries
- * @param data structure which contains all data of program
-*/
+/** \brief Function used to load dictionaries engines
+ */
void ws_mng_load_dict(GArray* dict_directory, WSMngSearchData* data);
+/*@}*/
#ifdef __cplusplus
- }
+}
#endif
#endif
+
+/*@}*/
along with mdictionary; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-Copyright 2006-2007 ComArch S.A.
+Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
+/** \addtogroup Manager
+ */
+/*@{*/
+/** \file ws_mng_gconf_utils.h
+ * \brief Utilities connected with GConf configuration - header.
+ */
#ifndef _WS_MANAGER_GCONF_UTILS
#define _WS_MANAGER_GCONF_UTILS
#include <ws_manager.h>
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
+/** \name GConf configuration routines.
+ */
+/*@{*/
+
+/** \brief GConf path to dictionaries locations.
+ */
#define GCONF_KEY "/apps/maemo/mdictionary/dictionaries"
+
+/** \brief GConf path to dictionary engines locations.
+ */
#define GCONF_LIB_PATH "/apps/maemo/mdictionary/engines"
-/**
- *Function used to get the dictionaries location read fron GConf
- *@return path to dictionaries location
- */
+/** \brief Function used to get the dictionaries location read fron GConf.
+ */
GArray* ws_mng_read_gconf();
-/**
- *Function used to get plugins location read from GConf
- *@return libraries location
+/** \brief Function used to get plugins location read from GConf
*/
GArray* ws_mng_get_engines_location();
-/**
- *Function used to get bookmark library location
- *@return path to bookmark location
+/** \brief Function used to get bookmark library location
*/
gchar* ws_mng_get_boomark_location();
-/**
- *Function used to check if optimized flag in GConf is set
- *@param dict path to dictionary file
- *@return TRUE if dictionary is optimize, FALSE otherwise
+/** \brief Function used to check if optimized flag in GConf is set
*/
gboolean ws_mng_if_optimized(gchar* dict);
+/*@}*/
+
#ifdef __cplusplus
- }
+}
#endif
#endif
+/*@}*/
along with mdictionary; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-Copyright 2006-2007 ComArch S.A.
+Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
+/** \addtogroup Manager
+ */
+/*@{*/
+/** \file ws_mng_searching_threads.h
+ * \brief Thread generation and thread functions - header.
+ */
#ifndef _WS_MANAGER_SEARCHING_THREADS
#define _WS_MANAGER_SEARCHING_THREADS
#include <ws_manager.h>
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
-
+/** \name Thread common routines. */
+/*@{*/
/** \brief Function executed by thread - search for word list
- *
- * @param search_data - pointer to search data structure
- * @return - result of thread - always NULL
*/
gpointer ws_mng_search_word (gpointer search_data);
-/**
- * \brief Used to return results of found words from threads
- *
- * @param list word list found in dictionaries
- * @param pattern a word which is being search for in dictionaries
- * @param user_data data passed to function
- * @param error engine status information
+/** \brief Used to return results of found words from threads
*/
void ws_mng_on_found_word (GArray* list,
gchar* pattern,
EngineStatus error);
/** \brief Function executed by thread - search for particular word
- *
- * @param search_data - pointer to search data structure
- * @return - result of thread - always NULL
*/
gpointer ws_mng_search_translation (gpointer search_data);
-/**
- * \brief Used to return results of transaltion from threads
- *
- * @param translation translation of word found in dictionaries
- * @param pattern a word which is being serch for in dictionaries
- * @param user_data data passed to function
- * @param error engine status information
+/** \brief Used to return results of transaltion from threads
*/
void ws_mng_on_found_translation (gchar* translation,
gchar* pattern,
gpointer user_data,
EngineStatus error);
-/**
- * \brief Function used to compare string. Used in sorting GArray object
- *
- * @param a first argument to compere
- * @param b second argument to compere
- * @return 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
+/** \brief Function used to compare string. Used in sorting GArray object
*/
gint ws_mng_compare_strings (gconstpointer a, gconstpointer b);
+/** \brief Removes repeating words on the returned words list.
+ */
void ws_remove_multiple_words(WSMngSearchAtom* user_data);
+/*@}*/
+
#ifdef __cplusplus
- }
+}
#endif
#endif
+/*@}*/
along with mdictionary; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-Copyright 2006-2007 ComArch S.A.
+Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
+/** \addtogroup Manager
+ */
+/*@{*/
+/** \file ws_mng_threads_utils.h
+ * \brief Thread utilities - header.
+ */
#ifndef _WS_MANAGER_THREADS_UTILS
#define _WS_MANAGER_THREADS_UTILS
#include <ws_manager.h>
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
+/** \name Thread utilities */
+/*@{*/
+/** \brief Structure holding all data for each thread to properly run.
+ *
+ * Each thread gets one instance of this strucutre in which are information
+ * about what to do and with what. This make it possible to run simultaneously
+ * few thread - they will not interrput each other.
+ */
struct _WSMngSearchAtom {
WSMngSearchData *data;
+ /**< pointer to global data holding by manager */
gchar *word;
+ /**< word to search by this thread */
GThread *thread;
-
- GArray *word_list;
- gchar *trans;
+ /**< pointer to thread handler */
+ GArray *word_list;
+ /**< GArray in which owner thread will keep words list -
+ * if is searching for words list */
+ gchar *trans;
+ /**< buffer in which owner thread will keep word's translation -
+ * if is searching for word's translation */
};
+
+/** \brief Structure holding all data for each thread to properly run.
+ * \sa _WSMngSearchAtom
+ */
typedef struct _WSMngSearchAtom WSMngSearchAtom;
/* functions for critical sections and thread handling */
+/** \brief Try to lock mutex and tell if it was locked before.
+ */
gboolean try_lock_was_locked(WSMngSearchData* data, gchar* fun);
+
+/** \brief Tell if given mutex is locked.
+ */
gboolean is_rec_locked(GStaticRecMutex* m);
+
+/** \brief Check if current thread should be terminated.
+ */
void stop_if_needed(WSMngSearchAtom* data);
+
+/** \brief Clear memmory after not neede anymore WSMngSearchAtom structure.
+ */
void free_search_atom(WSMngSearchAtom* data);
+
+/** \brief Create new WSMngSearchAtom structure.
+ */
WSMngSearchAtom *create_search_atom(WSMngSearchData* app_data, gchar* word);
+
+/*@}*/
+
#ifdef __cplusplus
- }
+}
#endif
#endif
+
+/*@}*/
+/*******************************************************************************
+This file is part of mDictionary
+
+mDictionary is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+mDictionary is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with WhiteStork; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+Copyright 2006-2008 ComArch S.A.
+*******************************************************************************/
+/** \addtogroup Manager
+ */
+/*@{*/
+
+/** \file untar.c
+ * \brief Exctracting *.tar.bz2 archives function code.
+ */
#include <untar.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <bzlib.h>
-#include <sys/stat.h>
-//#include <glib-2.0/glib.h>
-
-#define BLOCK_SIZE 512
-#define BUFFER_SIZE BLOCK_SIZE*32
-#define ASCII_NR(NR) (NR + 0x30)
-
-typedef struct _TarHeader
-{
- gchar name[100];
- gchar mode[8];
- gchar uid[8];
- gchar gid[8];
- gchar size[12];
- gchar mtime[12];
- gchar chksum[8];
- gchar typeflag;
- gchar linkname[100];
- gchar magic[6];
- gchar version[2];
- gchar uname[32];
- gchar gname[32];
- gchar devmajor[8];
- gchar devminor[8];
- gchar prefix[155];
- gchar padding[12];
- gchar *gnu_longname;
- gchar *gnu_longlink;
-} TarHeader;
-
-typedef enum _RecordType
-{
- File = ASCII_NR (0),
- ARCHLINK = ASCII_NR (1),
- SYMLINK = ASCII_NR (2),
- CHARDEV = ASCII_NR (3),
- BLOCKDEV = ASCII_NR (4),
- Dir = ASCII_NR (5),
- FIFO = ASCII_NR (6),
- RESERVED = ASCII_NR (7)
-} RecordType;
-
-static gint unpack_file_contents(BZFILE *bz2_file,
- TarHeader *header,
- gchar *out_name);
-
-
-static gint unpack_file_contents(BZFILE *bz2_file,
- TarHeader *header,
- gchar *out_name)
+
+
+
+/** \brief Unpack particular file from *.tar.bz2 archive
+ *
+ * \param bz2_file pointer to file with data (compressed with bz2 algorithm
+ * \param header *.tar header with information about data in bz2_file
+ * \param out_name string specifying destination path for uncompressed data
+ * \return 0 if exctracting was succesfull
+ */
+static gint unpack_file_contents( BZFILE *bz2_file,
+ TarHeader *header,
+ gchar *out_name )
{
- gchar* buffer;
- guint i;
+ gchar* buffer = NULL;
+ guint i = 0;
+ gint im = 0;
FILE *file_out;
- gulong length;
- guint result;
- gint bzerror;
-
+ gulong length = 0;
+ guint result = 0;
+ gint bzerror = 0;
+
file_out = fopen(out_name, "w");
-
+
if (file_out == NULL) return -1;
-
+
sscanf(header->size, "%12lo", &length);
g_debug("File size: %ld\n", length);
-
- for (i=0; i < (length / BLOCK_SIZE); ++i)
+
+ im = length / BLOCK_SIZE;
+ for (i = 0; i < im; ++i)
{
- buffer = (gchar*) g_try_malloc (BLOCK_SIZE * sizeof(gchar));
-
- result = BZ2_bzRead ( &bzerror, bz2_file, buffer, BLOCK_SIZE *
- sizeof (gchar));
+ buffer = (gchar*) g_try_malloc(BLOCK_SIZE * sizeof(gchar));
+ result = BZ2_bzRead( &bzerror,
+ bz2_file,
+ buffer,
+ BLOCK_SIZE * sizeof (gchar) );
+
fwrite (buffer, BLOCK_SIZE * sizeof(gchar), 1, file_out);
g_free (buffer);
- };
-
+ }
+
i = length % BLOCK_SIZE;
-
if (i != 0)
{
buffer = (gchar*) g_try_malloc (BLOCK_SIZE * sizeof(gchar));
-
- if (buffer == NULL)
+ if (NULL == buffer)
{
g_debug("Memory not allocated");
return -100;
};
- result = BZ2_bzRead(&bzerror, bz2_file, buffer,
- BLOCK_SIZE * sizeof(gchar));
-
- if (bzerror == BZ_OK)
+ result = BZ2_bzRead( &bzerror,
+ bz2_file,
+ buffer,
+ BLOCK_SIZE * sizeof(gchar) );
+ if (BZ_OK == bzerror)
{
fwrite (buffer, i * sizeof(gchar), 1, file_out);
}
-
- else
+ else
{
g_debug("bzerror = %d", bzerror);
- return -100;
+ return -200;
};
-
g_free(buffer);
-
- };
-
+ }
+
fclose(file_out);
-
return 0;
};
+/**
+ * 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:
+ * \code
+ * char* path = g_strdup("./");
+ * decompress_file ("comn_dictd04_wn.tar.bz2", &path);
+ * \endcode
+ * The above example extracts a given archive, to the current directory
+ *
+ * \param in_file path to file to exctract
+ * \param out_path pointer to path (string) to output directory. After function
+ * finished work in this parameter function return path to the exctracted
+ * dictionary
+ * \return 0 if exctracting of whole archive was succesfull
+ */
gint decompress_file (gchar *in_file, gchar **out_path)
{
- FILE *file;
+ FILE *file;
BZFILE *bz2_file;
- guint result;
+ guint result;
+ gint ret = 0;
TarHeader* header;
gint bzerror;
gchar* dest_dir = NULL;
- header = (TarHeader*) g_try_malloc (BLOCK_SIZE * sizeof(gchar));
-
- if (header == NULL) g_debug("\nCould not allocate memory\n");
-
+
+ header = (TarHeader*) g_try_malloc (BLOCK_SIZE * sizeof(gchar));
+ if (NULL == header)
+ {
+ g_debug("\nCould not allocate memory\n");
+ return -1;
+ }
+
file = fopen (in_file, "rb");
-
- if (file != NULL)
+ if (NULL == file)
+ {
+ g_debug("There was an error while trying to read archive file");
+ g_free(header); header = NULL;
+ return -2;
+ };
+ bz2_file = BZ2_bzReadOpen (&bzerror, file, 0, 0, NULL, 0);
+ if ( BZ_OK != bzerror )
{
- bz2_file = BZ2_bzReadOpen (&bzerror, file, 0, 0, NULL, 0);
+ fclose(file);
+ g_free(header); header = NULL;
+ g_debug("There was an error while reading compressed file\n");
+ return -3;
+ }
- if ( bzerror != BZ_OK )
- {
- BZ2_bzReadClose ( &bzerror, bz2_file );
- g_debug("There was an error while reading the compressed file\n");
- }
-
- bzerror = BZ_OK;
- while (1)
+ /* read archive and exctract all files in it */
+ while (TRUE)
+ {
+ /* get info about next file/directory in the archive */
+ result = BZ2_bzRead( &bzerror,
+ bz2_file,
+ header,
+ BLOCK_SIZE * sizeof (char) );
+ if ( BZ_OK == bzerror )
{
-
- result = BZ2_bzRead ( &bzerror, bz2_file, header,
- BLOCK_SIZE * sizeof (char));
- if ( bzerror == BZ_OK )
+ if (strlen(header->name) == 0)
{
- if (strlen (header->name) == 0)
- {
- g_debug("\nFilename length is 0, exitting\n");
- break;
- };
-
- g_debug("Name: %s\n", header->name);
- g_debug("Prefix: %s\n", header->prefix);
-
-
- gchar *temp = g_strconcat (*out_path,
- header->name, NULL);
- g_debug("Temp path %s\n", temp);
- switch (header->typeflag)
- {
- case File:
- g_debug("File\n");
- unpack_file_contents (bz2_file,
- header, temp);
- break;
-
- case Dir:
-
- g_debug("Dir %s\n", temp);
- if (mkdir (temp, S_IRUSR|
- S_IWUSR|S_IXUSR) != 0)
- {
- g_debug("Couldn't create directory %s",
- temp);
- g_free(header);
- BZ2_bzReadClose(&bzerror,
- bz2_file);
- fclose(file);
- return -100;
- };
- break;
-
- default:
- g_debug("Only files and dirs can be unpacked");
- }
- dest_dir = g_strdup(temp);
- g_debug("dest_dir %s \n", dest_dir);
- g_free (temp);
-
- }
-
- else if ( bzerror != BZ_STREAM_END )
- {
- g_debug("\nBZ2 READ_CLOSE(stream end) %d\n", bzerror);
- BZ2_bzReadClose ( &bzerror, bz2_file );
+ g_debug("\nFilename length is 0, exitting\n");
break;
- }
-
- else
+ };
+ gchar *temp = g_strconcat( *out_path,
+ header->name,
+ NULL );
+
+ /* exctract file or create new directory */
+ switch (header->typeflag)
{
- g_debug("\nExitting, error nr %d\n", bzerror);
- BZ2_bzReadClose ( &bzerror, bz2_file );
+ case File:
+ unpack_file_contents( bz2_file,
+ header,
+ temp );
break;
- };
-
+ case Dir:
+ if (0 !=
+ mkdir( temp,
+ S_IRUSR|S_IWUSR|S_IXUSR )
+ ) {
+ g_debug("Couldnt create dir:%s",
+ temp);
+ g_free(header);
+ BZ2_bzReadClose( &bzerror,
+ bz2_file );
+ fclose(file);
+ return -4;
+ }
+ else {
+ /* get last created directory */
+ if(NULL != dest_dir) {
+ g_free(dest_dir);
+ }
+ dest_dir = g_strdup(temp);
+ g_debug( "dest_dir %s \n",
+ dest_dir );
+ }
+ break;
+ default:
+ g_debug("Untar:Wrong type of content!");
+ break;
+ }
+ g_free(temp);
+ temp = NULL;
+ }
+ else if ( bzerror != BZ_STREAM_END )
+ {
+ g_debug("\nBZ2 READ_CLOSE(stream end) %d\n", bzerror);
+ BZ2_bzReadClose ( &bzerror, bz2_file );
+ break;
+ }
+ else
+ {
+ g_debug("\nExitting, error nr %d\n", bzerror);
+ BZ2_bzReadClose ( &bzerror, bz2_file );
+ ret = -5;
+ break;
};
-
- }
- else
- {
- g_debug("There was an error while trying to read the archive file");
- g_free(header); header = NULL;
- fclose(file);
- return -100;
};
- if (dest_dir != NULL)
+
+ /* put newly created directory path into out_path parameter */
+ if ((0 == ret) && (dest_dir != NULL))
{
g_free(*out_path); *out_path = NULL;
*out_path = g_strdup(dest_dir);
g_free(dest_dir); dest_dir = NULL;
}
+
g_free(header); header = NULL;
fclose(file);
- return 100;
-
-
+ return ret;
};
+
+/*@}*/
+
along with mdictionary; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-Copyright 2006 ComArch S.A.
+Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
-#ifdef __cplusplus
-extern "C" {
-#endif
-#include <glib.h>
-#include <stdlib.h>
+/** \addtogroup Manager
+ */
+/*@{*/
+
+/** \file whitestork.c
+ * \brief Entry point for mDictionary Manager module.
+ *
+ * \author Łukasz Pawlik \<lukasz.pawlik\@comarch.com\>
+ * \see Manager
+ */
+
#include <ws_manager.h>
-//#include <gconf/gconf-client.h>
-//#include <gconf/gconf.h>
+/** \brief Entry point for manager proccess.
+ *
+ * Create and initialize all data needed for manager to work and start main loop
+ * for its proccess.
+ *
+ */
int main (gint argc, gchar** argv)
{
+ /* initialize GType and GObject's functions capabilities for proccess */
g_type_init();
-
+
WSMngSearchData* search_data = ws_manager_create();
-
+
ws_mng_init_dbus(search_data);
+
ws_mng_init(search_data);
-
+
ws_mng_start_main_loop(search_data);
-
+
ws_mng_close(search_data);
-
- //g_free(search_data);
-
+
return 0;
}
-#ifdef __cplusplus
-}
-#endif
+
+/*@}*/
Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
+/** \addtogroup Manager
+ */
+/*@{*/
/** \file ws_manager.c
* \brief mDictionary Manager main module code.
*
* \author Łukasz Pawlik \<lukasz.pawlik\@comarch.com\>
*/
-/** \addtogroup Manager
- *
- */
-/*@{*/
-
#include <ws_manager.h>
#include <ws_mng_searching_threads.h>
data->bookmark_mode = FALSE;
/* added by Dariusz Wiechecki
* mutex initialization */
- data->action_working = (GStaticMutex*)g_try_malloc(sizeof(GStaticMutex));
- data->thread_creation = (GStaticMutex*)g_try_malloc(sizeof(GStaticMutex));
- data->action_stop = (GStaticRecMutex*)g_try_malloc(sizeof(GStaticRecMutex));
+ data->action_working =
+ (GStaticMutex*)g_try_malloc(sizeof(GStaticMutex));
+ data->thread_creation =
+ (GStaticMutex*)g_try_malloc(sizeof(GStaticMutex));
+ data->action_stop =
+ (GStaticRecMutex*)g_try_malloc(sizeof(GStaticRecMutex));
g_assert(NULL != (data->action_working) );
g_assert(NULL != (data->action_stop) );
g_static_mutex_init (data->action_working);
WS_DBUS_ERROR_ENGINE_NOT_FOUND );
for (i=0; i<dict_directory->len; i++)
{
- g_free(g_array_index(dict_directory, gchar*, i));
+ g_free(g_array_index( dict_directory,
+ gchar*,
+ i ));
}
g_array_free(dict_directory, TRUE);
ws_mng_close(data);
/* get EngineModule struct and append it to the array*/
EngineModule module = get_functions();
g_array_append_val(data->modules, module);
- }
+ }
/* load each dictionary */
ws_mng_load_bookmark(data);
{
ws_dbus_notify( data->dbus_data,
WS_DBUS_ERROR_FILE_NOT_FOUND );
- }
+ }
/* free memory used by dictionaries path array */
for (i=0; i<dict_directory->len; i++)
along with mdictionary; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-Copyright 2006 ComArch S.A.
+Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
+/** \addtogroup Manager */
+/*@{*/
+/** \file ws_mng_bookmarks_utils.c
+ * \brief Utilities for Manager connected with managing bookmarks - code.
+ */
#include <ws_mng_bookmarks_utils.h>
/**
- *Function used to add bookmarks
- *@param error error messages
- *@param param word and translation of word to adding
- *@param user_data structure holding nedded parameters
+ * Function used to add bookmarks.
+ * \param error error messages
+ * \param param word and translation of word to adding
+ * \param user_data structure holding nedded parameters
*/
void ws_mng_add_bookmark(GError *error, GArray* param, gpointer user_data)
{
g_debug("->%s", __FUNCTION__);
-
+
WSMngSearchData* data = (WSMngSearchData *) user_data;
- osso_rpc_t* osso_data = NULL;
+ osso_rpc_t* osso_data = NULL;
osso_rpc_t* osso_data_trans = NULL;
- gchar* word = NULL;
+ gchar* word = NULL;
gchar* translation = NULL;
- //get the word passed by dbus
- if (data->bookmark != NULL)
+
+ if (data->bookmark != NULL)
{
- //g_debug("adding bookmarks...%p locataion", data->bookmark);
+ /* get the word passed by dbus */
osso_data = &g_array_index (param, osso_rpc_t, 0);
- word = g_strdup(osso_data->value.s);
+ word = g_strdup(osso_data->value.s);
osso_data_trans = &g_array_index (param, osso_rpc_t, 1);
translation = g_strdup(osso_data_trans->value.s);
- //do not free translation and word
- gboolean is_added = dict_eng_add_word(data->bookmark,
- word, translation);
+
+ /* try to add word to bookmarks */
+ gboolean is_added = dict_eng_add_word( data->bookmark,
+ word,
+ translation );
if (is_added == TRUE)
{
- ws_dbus_notify(data->dbus_data,
- WS_DBUS_BOOKMARKS_ADDED_OK);
+ ws_dbus_notify( data->dbus_data,
+ WS_DBUS_BOOKMARKS_ADDED_OK );
}
- else
+ else
{
- ws_dbus_notify(data->dbus_data,
- WS_DBUS_BOOKMARKS_ADDED_FAIL);
+ ws_dbus_notify( data->dbus_data,
+ WS_DBUS_BOOKMARKS_ADDED_FAIL );
}
+ /* free memmory */
osso_rpc_free_val(osso_data);
g_free(translation);
g_free(word);
}
else
{
- ws_dbus_notify(data->dbus_data,
- WS_DBUS_BOOKMARKS_ADDED_FAIL);
+ ws_dbus_notify( data->dbus_data,
+ WS_DBUS_BOOKMARKS_ADDED_FAIL );
g_debug("-> %s - there is no bookmark engine!\n", __FUNCTION__);
}
+
g_debug("<-%s", __FUNCTION__);
}
/**
- *Function used to remove bookmarks
- *@param error error messages
- *@param param word and translation of word to remove
- *@param user_data structure holding nedded parameters
+ * Function used to remove bookmarks.
+ * \param error error messages
+ * \param param word and translation of word to remove
+ * \param user_data structure holding nedded parameters
*/
void ws_mng_remove_bookmark(GError *error, GArray* param, gpointer user_data)
{
g_debug("->%s", __FUNCTION__);
WSMngSearchData* data = (WSMngSearchData *) user_data;
- osso_rpc_t* osso_data = NULL;
- gchar* word = NULL;
- //get the word passed by dbus
+ osso_rpc_t* osso_data = NULL;
+ gchar* word = NULL;
+
if (data->bookmark != NULL)
{
- g_debug("removing bookmarks...");
+ /* get the word passed by dbus */
osso_data = &g_array_index(param, osso_rpc_t, 0);
- word = g_strdup(osso_data->value.s);
+ word = g_strdup(osso_data->value.s);
- gboolean is_remove = dict_eng_remove_word(data->bookmark, word);
- if (is_remove == TRUE)
+ gboolean is_remove = dict_eng_remove_word( data->bookmark,
+ word );
+ if (TRUE == is_remove)
{
- ws_dbus_notify(data->dbus_data,
- WS_DBUS_BOOKMARKS_REMOVED_OK);
+ ws_dbus_notify( data->dbus_data,
+ WS_DBUS_BOOKMARKS_REMOVED_OK );
}
else
{
- ws_dbus_notify(data->dbus_data,
- WS_DBUS_BOOKMARKS_REMOVED_FAIL);
+ ws_dbus_notify( data->dbus_data,
+ WS_DBUS_BOOKMARKS_REMOVED_FAIL );
}
-
+
osso_rpc_free_val(osso_data);
}
else
{
- ws_dbus_notify(data->dbus_data,
- WS_DBUS_BOOKMARKS_ADDED_FAIL);
+ ws_dbus_notify( data->dbus_data,
+ WS_DBUS_BOOKMARKS_ADDED_FAIL );
g_debug("-> %s - there is no bookmark engine!\n", __FUNCTION__);
}
+
g_debug("<-%s", __FUNCTION__);
}
/**
- *Function used to load bookmark module
- *@param data structure which holds the loaded module
+ * Function used to load bookmark module
+ * \param data structure which holds the loaded module
*/
void ws_mng_load_bookmark(WSMngSearchData* data)
{
guint i = 0;
data->bookmark = NULL;
gchar* current_directory = ws_mng_get_boomark_location();
- if (current_directory != NULL)
- {
- #ifdef SQLITE
- if (g_file_test(LIBRARY, G_FILE_TEST_EXISTS))
+
+ if (NULL != current_directory)
{
- #endif
- for (i=0; i<data->modules->len; i++)
+ for (i = 0; i < data->modules->len; ++i)
{
- if (dict_eng_module_check(
- g_array_index(data->modules, EngineModule, i),
- current_directory) == TRUE)
+ /* check each engine module to be compatible with
+ * bookmark dictionary - searching for bookmark module*/
+ if (TRUE == dict_eng_module_check(
+ g_array_index(data->modules, EngineModule, i),
+ current_directory ))
{
- data->bookmark =
- dict_eng_module_create_ext(
- g_array_index(data->modules,
- EngineModule,
- i),
- current_directory,
- ENGINE_CREATE,
- ws_mng_progress_bar,
- data,
- 0.02);
+ /* create engine for handling bookmarks */
+ data->bookmark =
+ dict_eng_module_create_ext(
+ g_array_index(data->modules,
+ EngineModule,
+ i),
+ current_directory,
+ ENGINE_CREATE,
+ ws_mng_progress_bar,
+ data,
+ 0.02 );
+ /* set callbacks */
+ dict_eng_set_callback( data->bookmark,
+ ENGINE_WORD_LIST_SIGNAL,
+ ws_mng_on_found_word,
+ data );
dict_eng_set_callback(data->bookmark,
- ENGINE_WORD_LIST_SIGNAL,
- ws_mng_on_found_word,
- data);
- //set callback for return translation
- dict_eng_set_callback(data->bookmark,
- ENGINE_WORD_TRANSLATION_SIGNAL,
- ws_mng_on_found_translation,
- data);
-
+ ENGINE_WORD_TRANSLATION_SIGNAL,
+ ws_mng_on_found_translation,
+ data);
+ /* bookmark engine found - stop searching */
break;
}
}
-
- #ifdef SQLITE
- }
- #endif
- g_free(current_directory);
+ g_free(current_directory);
}
g_debug("<-%s", __FUNCTION__);
}
+
+
+/*@}*/
Copyright 2006 ComArch S.A.
*******************************************************************************/
+/** \addtogroup Manager */
+/*@{*/
+/** \file ws_mng_callbacks.c
+ * \brief Callback functions called by other modules - code.
+ */
+
#include <ws_mng_callbacks.h>
#include <glib/gstdio.h>
/**
- * Function used to send inforamtion about progress of caching XDXF file to UI
- * @param progess how much file is cached
- * @param user_data data needed to send information to UI
- * @param error error messages
+ * \param progess how much file is cached
+ * \param user_data data needed to send information to UI
+ * \param error error messages
*/
-void ws_mng_progress_bar(double progress,
- gpointer user_data,
- EngineStatus error
- )
+void ws_mng_progress_bar( double progress,
+ gpointer user_data,
+ EngineStatus error )
{
g_debug("<--> %s - progress=%f", __FUNCTION__, progress);
WSMngSearchData *data = (WSMngSearchData *) user_data;
/**
-* \brief Called when find word event occurs
-*
-* @param word word to search
-* @param error error messages
-* @param user_data user data passed to function
-*/
-void ws_mng_on_search_word(GError *error,
- GArray *word,
- gpointer user_data
- )
+ * \param word word to search
+ * \param error error messages
+ * \param user_data user data passed to function
+ */
+void ws_mng_on_search_word( GError *error,
+ GArray *word,
+ gpointer user_data )
{
g_debug("[L-word] -> %s: reading parameters...", __FUNCTION__);
WSMngSearchData *search = (WSMngSearchData *) user_data;
/* get the word passed by dbus */
osso_data = &g_array_index (word, osso_rpc_t, 0);
gchar* tmp = NULL;
-
+
if (osso_data->value.s != NULL)
{
-
+ /* check if we need add wildcard '*' at the end of the word */
if (( g_utf8_strchr(osso_data->value.s, -1, '*') == NULL ) &&
- ( g_utf8_strchr(osso_data->value.s, -1, '?') == NULL ))
+ ( g_utf8_strchr(osso_data->value.s, -1, '?') == NULL ))
{
tmp = g_strconcat(osso_data->value.s, "*", NULL);
}
tmp = g_strdup(osso_data->value.s);
}
}
-
- else tmp = g_strdup ("*");
+ else
+ {
+ tmp = g_strdup ("*");
+ }
/* create and init searching data - separate for each thread */
WSMngSearchAtom* search_data = NULL;
}
g_debug("[L-word] creating GThread object...");
- search_data->thread = g_thread_create (ws_mng_search_word,
+ search_data->thread = g_thread_create( ws_mng_search_word,
search_data,
TRUE,
- NULL);
+ NULL );
g_debug("[L-word] GThread object created. Exiting from CREATOR.");
g_static_mutex_unlock( search->thread_creation );
}
/**
-* \brief Called when find translation event occurs
-*
-* @param word word to search
-* @param error error messages
-* @param user_data user data passed to function
-*/
+ * \param word word to search
+ * \param error error messages
+ * \param user_data user data passed to function
+ */
void ws_mng_on_search_translation (GError *error,
GArray *word,
gpointer user_data)
{
- g_debug("[L-tran] ->%s", __FUNCTION__);
+ g_debug("[L-tran] ->%s", __FUNCTION__);
- WSMngSearchData *data = (WSMngSearchData *) user_data;
+ WSMngSearchData *data = (WSMngSearchData *) user_data;
/* ---> CRITICAL SECTION for this function */
g_static_mutex_lock(data->thread_creation);
- /* get the data sended by dbus */
- osso_rpc_t *osso_data;
- osso_data = &g_array_index (word, osso_rpc_t, 0);
+ /* get the data sended by dbus */
+ osso_rpc_t *osso_data;
+ osso_data = &g_array_index (word, osso_rpc_t, 0);
/* create and init searching data - separate for each thread */
WSMngSearchAtom* search_data = NULL;
return;
}
- g_debug("[L-tran] creating GThread object...");
- search_data->thread = g_thread_create (ws_mng_search_translation,
+ g_debug("[L-tran] creating GThread object...");
+ search_data->thread = g_thread_create( ws_mng_search_translation,
search_data,
TRUE,
- NULL);
+ NULL );
g_debug("[L-tran] GThread object created. Exiting from CREATOR.");
/**
-* \brief Function used for handling signals sent by user interface
-*
* @param error error messages
* @param signal type of signal
* @param user_data data passed to function
*/
void ws_mng_signal_handling(GError *error, GArray *signal, gpointer user_data)
{
- g_debug("->%s", __FUNCTION__);
- osso_rpc_t osss_data;
- osss_data = g_array_index (signal, osso_rpc_t, 0);
- WSMngSearchData *data = (WSMngSearchData *) user_data;
- gint i = 0;
- switch(osss_data.value.i)
- {
- case WS_DBUS_INFO_TERMINATE:
+ g_debug("->%s", __FUNCTION__);
+ osso_rpc_t osss_data;
+ osss_data = g_array_index (signal, osso_rpc_t, 0);
+ WSMngSearchData *data = (WSMngSearchData *) user_data;
+ gint i = 0;
+
+ switch(osss_data.value.i)
+ {
+ case WS_DBUS_INFO_TERMINATE:
/* added by Dariusz Wiechecki
- * canceling GLib Threads */
+ * canceling GLib Threads if any is working */
if (try_lock_was_locked(data,(gchar*)__FUNCTION__))
{
g_printf("[S] STOP ACTION! %s\n",__FUNCTION__);
g_static_mutex_lock(data->action_working);
}
g_static_rec_mutex_unlock(data->action_stop);
-/* ws_dbus_notify(data->dbus_data,
- WS_DBUS_WORDS_LIST_FINISHED);
- ws_dbus_notify(data->dbus_data,
- WS_DBUS_TRANSLATION_FINISHED);*/
g_static_mutex_unlock(data->action_working);
- g_main_loop_quit (data->loop);
+ /* end current proccess */
+ g_main_loop_quit (data->loop);
break;
case WS_DBUS_INFO_STOP_SEARCH:
/* added by Dariusz Wiechecki
- * canceling GLib Threads */
+ * canceling GLib Threads if any is working */
if (try_lock_was_locked(data,(gchar*)__FUNCTION__))
{
g_printf("[S] STOP ACTION! %s\n",__FUNCTION__);
ws_dbus_notify(data->dbus_data,
WS_DBUS_TRANSLATION_FINISHED);
g_static_mutex_unlock(data->action_working);
- break;
-
- case WS_DBUS_INFO_CONFIG_CHANGED:
- ws_dbus_notify(data->dbus_data, WS_DBUS_INFO_CACHING);
-
- for (i=0; i<data->dict->len; i++)
- {
- if (g_array_index(data->dict, Engine*,i) != NULL)
+ break;
+ case WS_DBUS_INFO_CONFIG_CHANGED:
+ ws_dbus_notify(data->dbus_data, WS_DBUS_INFO_CACHING);
+ /* first remove all dictionaries */
+ for (i=0; i<data->dict->len; i++)
+ {
+ if(g_array_index(data->dict, Engine*,i) != NULL)
{
- dict_eng_destroy(
- g_array_index(
- data->dict, Engine*,i
- )
- );
+ dict_eng_destroy( g_array_index(
+ data->dict,
+ Engine*,
+ i ) );
}
- }
- g_array_free(data->dict, TRUE);
-
- data->dict = g_array_new (TRUE, TRUE, sizeof(Engine*));;
- //paths to directories
- GArray* dir_array = ws_mng_read_gconf();
- //fill the table again with new dicnioraries
- ws_mng_load_dict(dir_array, data);
- //if there is no dictionary selected
- // signal this fact to gui
+ }
+ g_array_free(data->dict, TRUE);
+
+ /* load dictionaries again in the new configuration */
+ data->dict = g_array_new (TRUE, TRUE, sizeof(Engine*));
+ GArray* dir_array = ws_mng_read_gconf();
+ ws_mng_load_dict(dir_array, data);
+
+ /* check if there was loaded any dictionary */
if (data->dict->len <= 0)
- {
- ws_dbus_notify(data->dbus_data,
- WS_DBUS_INFO_CACHING_FINISHED);
- ws_dbus_notify(data->dbus_data,
- WS_DBUS_ERROR_FILE_NOT_FOUND);
- }else
- {
- //if there was typed word search for word list
- if (data->last_search != NULL)
- {
- data->word_list = g_array_new(TRUE, TRUE,
- sizeof(gchar*));//creating new word list
-
- g_free(data->word); data->word = NULL;
- data->word = g_strdup(data->last_search);
- }
- //signal end of dictionary load to gui
- ws_dbus_notify(data->dbus_data,
- WS_DBUS_INFO_CACHING_FINISHED);
- }
- //free memory
- for (i=0; i<dir_array->len; i++)
- {
- g_free(g_array_index(dir_array, gchar*, i));
- }
- g_array_free(dir_array, TRUE);
- break;
+ {
+ ws_dbus_notify( data->dbus_data,
+ WS_DBUS_INFO_CACHING_FINISHED );
+ ws_dbus_notify( data->dbus_data,
+ WS_DBUS_ERROR_FILE_NOT_FOUND);
+ }
+ else
+ {
+ /*if there was typed word search for word list*/
+ if (data->last_search != NULL)
+ {
+ data->word_list =
+ g_array_new( TRUE,
+ TRUE,
+ sizeof(gchar*));
+
+ g_free(data->word); data->word = NULL;
+ data->word =
+ g_strdup(data->last_search);
+ }
+ /* signal end of dictionary load to gui */
+ ws_dbus_notify( data->dbus_data,
+ WS_DBUS_INFO_CACHING_FINISHED );
+ }
+
+ /* free memmory */
+ for (i=0; i<dir_array->len; i++)
+ {
+ g_free(g_array_index(dir_array, gchar*, i));
+ }
+ g_array_free(dir_array, TRUE);
+ break;
case WS_DBUS_BOOKMARK_MODE_ON:
data->bookmark_mode = TRUE;
break;
case WS_DBUS_BOOKMARK_MODE_OFF:
data->bookmark_mode = FALSE;
break;
- }
- g_debug("<-%s", __FUNCTION__);
+ }
+ g_debug("<-%s", __FUNCTION__);
}
+
+/*@}*/
along with mdictionary; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-Copyright 2006 ComArch S.A.
+Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
+/** \addtogroup Manager */
+/*@{*/
+/** \file ws_mng_dictionary_utils.c
+ * \brief Dictionaries common routines - code.
+ */
+
#include <ws_mng_dictionary_utils.h>
-void ws_mng_extract_dictionary(GError *error,
- GArray* param,
- gpointer user_data)
+/**
+ * \param error after excuting it contains error messages if any was
+ * \param param parameters given by D-Bus
+ * \param app_data manager data
+ */
+void ws_mng_extract_dictionary( GError *error,
+ GArray* param,
+ gpointer user_data )
{
g_debug("->%s", __FUNCTION__);
WSMngSearchData *data = (WSMngSearchData *) user_data;
- osso_rpc_t *osso_data;
- //get the data sended by dbus
- osso_data = &g_array_index (param, osso_rpc_t, 0);
- //get the path sended by dbus
- gchar* path = g_strdup(osso_data->value.s);
+ osso_rpc_t *osso_data;
+
+ /* get the data sended by dbus */
+ osso_data = &g_array_index (param, osso_rpc_t, 0);
+ gchar* path = g_strdup(osso_data->value.s);
gint result = -1;
-
+
gchar* dest = NULL;
if (path != NULL)
{
gint count = 0;
- gchar** tmp = g_strsplit(path,
- "/",
- 0);
- while(tmp[count++] != NULL);
+ gchar** tmp = g_strsplit(path, "/", 0);
+ while(tmp[count] != NULL)
+ {
+ ++count;
+ }
dest = g_strndup(path, g_strlen(path)- g_strlen(tmp[count -2]));
g_strfreev(tmp);
- }
+ };
+
if (dest != NULL)
- { ws_dbus_notify(data->dbus_data, WS_DBUS_EXTRACT_FILE);
- result = decompress_file(path, &dest);
+ {
+ ws_dbus_notify(data->dbus_data, WS_DBUS_EXTRACT_FILE);
+ result = decompress_file(path, &dest);
ws_dbus_notify(data->dbus_data, WS_DBUS_EXTRACT_FILE_FINISHED);
- }
-
- if (result > 0)
+ };
+
+ if (result > 0)
{
ws_dbus_server_return_extracted_dict(data->dbus_data, dest);
}
- else
- {
+ else
+ {
dest = "";
ws_dbus_server_return_extracted_dict(data->dbus_data, dest);
}
-
+
g_free(path);
+ path = NULL;
g_debug("<-%s", __FUNCTION__);
}
/**
- *Function used to load dictionaries engines
- *@param dict_directory path to dictionaries
- *@param data structure which contains all data of program
-*/
+ * Function used to load dictionaries engines
+ * \param dict_directory path to dictionaries
+ * \param data structure which contains all data of program
+ */
void ws_mng_load_dict(GArray* dict_directory, WSMngSearchData* data)
{
+ gint i = 0;
+ gint j = 0;
+ Engine* xdxf = NULL;
+ g_debug("->%s", __FUNCTION__);
+ EngineOptimizationFlag flag = ENGINE_NO;
+ gchar* current_directory = NULL;
+
+ for (i =0; i<dict_directory->len; i++)
+ {
+ current_directory = strdup(g_array_index( dict_directory,
+ gchar*,
+ i ));
+ flag = ENGINE_NO;
+ for (j=0; j<data->modules->len; j++)
+ {
+ if (dict_eng_module_check( g_array_index( data->modules,
+ EngineModule,
+ j),
+ current_directory ) == TRUE)
+ {
+ /* set correct flag for engine */
+ if(ws_mng_if_optimized(current_directory))
+ {
+ flag = ENGINE_CREATE;
+ }
+
+ /* create engine with correct flag */
+ xdxf = dict_eng_module_create_ext(
+ g_array_index( data->modules,
+ EngineModule,
+ j ),
+ current_directory,
+ flag,
+ ws_mng_progress_bar,
+ data,
+ 0.02 );
- gint i = 0;
- gint j = 0;
- Engine* xdxf = NULL;
- g_debug("->%s", __FUNCTION__);
- for (i =0; i<dict_directory->len; i++)
- {
- gchar* current_directory = strdup(g_array_index(dict_directory,
- gchar*,
- i)
- );
- for (j=0; j<data->modules->len; j++)
- {
- if (dict_eng_module_check(g_array_index(data->modules,
- EngineModule,
- j),
- current_directory) == TRUE)
- {
- if(ws_mng_if_optimized(current_directory))
- {
- xdxf = dict_eng_module_create_ext(
- g_array_index(data->modules,
- EngineModule,
- j),
- current_directory,
- ENGINE_CREATE,
- ws_mng_progress_bar,
- data,
- 0.02); //create engine module
- }
- else
- {
- xdxf = dict_eng_module_create_ext(
- g_array_index(data->modules,
- EngineModule,
- j),
- current_directory,
- ENGINE_NO,
- ws_mng_progress_bar,
- data,
- 0.02); //create engine module
- }
- //set callback for return words list function
- dict_eng_set_callback(xdxf,
- ENGINE_WORD_LIST_SIGNAL,
- ws_mng_on_found_word,
- data);
- //set callback for return translation
- dict_eng_set_callback(xdxf,
- ENGINE_WORD_TRANSLATION_SIGNAL,
- ws_mng_on_found_translation,
- data);
- //adding newly created engine to Garray
- g_array_append_val (data->dict, xdxf);
- g_free(current_directory);
- }
+ /*set callbacks functions */
+ dict_eng_set_callback( xdxf,
+ ENGINE_WORD_LIST_SIGNAL,
+ ws_mng_on_found_word,
+ data );
+
+ dict_eng_set_callback( xdxf,
+ ENGINE_WORD_TRANSLATION_SIGNAL,
+ ws_mng_on_found_translation,
+ data );
+
+ /* adding newly created engine to Garray */
+ g_array_append_val (data->dict, xdxf);
+
+ g_free(current_directory);
+ current_directory = NULL;
+ xdxf = NULL;
+
+ /* do not check next module - move directly to
+ * next dictionary */
+ break;
+ }
}
}
g_debug("<-%s", __FUNCTION__);
}
-
+/*@}*/
along with mdictionary; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-Copyright 2006 ComArch S.A.
+Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
+/** \addtogroup Manager
+ */
+/*@{*/
+/** \file ws_mng_gconf_utils.c
+ * \brief Utilities connected with GConf configuration - coder.
+ */
#include <ws_mng_gconf_utils.h>
/**
- *Function used to get the dictionaries location read fron GConf
- *@return path to dictionaries location
- */
+ *
+ * Function read from GConf locations of every dictionary and return them in
+ * GArray to make it possible to load them.
+ *
+ * \return path to dictionaries location
+ */
GArray* ws_mng_read_gconf()
{
- //g_type_init();
- g_debug("--%s", __FUNCTION__);
- GConfClient* client = NULL;
- GArray* path_to_dir = g_array_new(TRUE, TRUE, sizeof(gchar *));
- gchar* path = NULL;
- //gchar* key_value = NULL;
- gboolean key_active = FALSE;
- gint i = 0;
-
- client = gconf_client_get_default();
- GSList* list = gconf_client_all_dirs(client, GCONF_KEY, NULL);
- for (i=0; i<g_slist_length(list); i++)
- {
- //path = g_strdup((gchar *) g_slist_nth_data(list, i));
- path = (gchar* ) g_slist_nth_data(list, i);
- gchar* new_path = g_strconcat(path, "/path", NULL);
- gchar* new_acitve = g_strconcat(path, "/active", NULL);
- key_active = gconf_client_get_bool(client, new_acitve, NULL);
- if (key_active == TRUE)
- {
- gchar* key_value = gconf_client_get_string(client,
- new_path,
- NULL);
+ g_debug("--%s", __FUNCTION__);
+ GConfClient* client = NULL;
+ client = gconf_client_get_default();
+ GArray* path_to_dir = g_array_new(TRUE, TRUE, sizeof(gchar *));
+ gchar* path = NULL;
+ gboolean key_active = FALSE;
+ gint i = 0;
+
+ /* get location of every dictionary */
+ GSList* list = gconf_client_all_dirs(client, GCONF_KEY, NULL);
+ for (i = 0; i < g_slist_length(list); ++i)
+ {
+ path = (gchar* ) g_slist_nth_data(list, i);
+ gchar* new_path = g_strconcat(path, "/path", NULL);
+ gchar* new_active = g_strconcat(path, "/active", NULL);
+ key_active = gconf_client_get_bool(client, new_active, NULL);
+ if (key_active == TRUE)
+ {
+ gchar* key_value = gconf_client_get_string( client,
+ new_path,
+ NULL );
if (key_value != NULL){
g_array_append_val(path_to_dir, key_value);
}
- }
- g_free(new_path);
- g_free(new_acitve);
-
- }
- for (i=0; i<g_slist_length(list); i++)
- {
- g_free(g_slist_nth_data(list, i));
- }
- g_slist_free(list);
- g_object_unref (client);
- return path_to_dir;
+ }
+ g_free(new_path);
+ g_free(new_active);
+ }
+
+ /* free memmory */
+ for (i=0; i<g_slist_length(list); i++)
+ {
+ g_free(g_slist_nth_data(list, i));
+ }
+ g_slist_free(list);
+ g_object_unref (client);
+ return path_to_dir;
}
/**
- *Function used to get plugins location read from GConf
- *@return libraries location
+ * \return libraries with dictionary engines location
*/
GArray* ws_mng_get_engines_location()
{
+ g_debug("->%s", __FUNCTION__);
+ GConfClient* client = NULL;
+ GArray* path_to_dir = g_array_new(TRUE, TRUE, sizeof(gchar *));
+ gchar* path = NULL;
+ gint i = 0;
+ client = gconf_client_get_default();
- //g_type_init();
- g_debug("->%s", __FUNCTION__);
- GConfClient* client = NULL;
- GArray* path_to_dir = g_array_new(TRUE, TRUE, sizeof(gchar *));
- gchar* path = NULL;
- gint i = 0;
- client = gconf_client_get_default();
- GSList* list = gconf_client_all_dirs(client, GCONF_LIB_PATH, NULL);
- for (i=0; i<g_slist_length(list); i++)
- {
- //path = g_strdup((gchar *) g_slist_nth_data(list, i));
- path = (gchar* ) g_slist_nth_data(list, i);
- gchar* new_path = g_strconcat(path, "/path",NULL);
- gchar* key_value = gconf_client_get_string(client,
- new_path,
- NULL);
- gchar** tmp = g_strsplit(key_value,
- "/",
- -1);
+ GSList* list = gconf_client_all_dirs(client, GCONF_LIB_PATH, NULL);
+ for (i=0; i<g_slist_length(list); i++)
+ {
+ path = (gchar* ) g_slist_nth_data(list, i);
+ gchar* new_path = g_strconcat(path, "/path",NULL);
+ gchar* key_value = gconf_client_get_string( client,
+ new_path,
+ NULL);
+ gchar** tmp = g_strsplit(key_value, "/", -1);
guint i = 0;
- gboolean bookmark_engin = FALSE;
- while(tmp[i] != NULL)
+ gboolean bookmark_engine = FALSE;
+ while(NULL != tmp[i])
{
g_debug("Comapred string %s", tmp[i]);
if (g_ascii_strcasecmp(tmp[i], "ws_bookmark.so") == 0)
{
- bookmark_engin = TRUE;
+ bookmark_engine = TRUE;
break;
}
i++;
}
g_strfreev(tmp);
- #ifdef SQLITE
- if (bookmark_engin)
- {
- gboolean result = g_file_test(
- LIBRARY,
- G_FILE_TEST_EXISTS);
- if (result == FALSE)
- {
- g_debug("sqlite not installed !");
- g_free(new_path);
- continue;
- }
- }
- #endif
if (key_value != NULL)
{
g_debug("Added library path %s", key_value);
g_array_append_val(path_to_dir, key_value);
}
- g_free(new_path);
- }
- for (i=0; i<g_slist_length(list); i++)
- {
- g_free(g_slist_nth_data(list, i));
- }
- g_slist_free(list);
- g_object_unref (client);
-
- return path_to_dir;
+ g_free(new_path);
+ }
+
+ for (i=0; i<g_slist_length(list); i++)
+ {
+ g_free(g_slist_nth_data(list, i));
+ }
+ g_slist_free(list);
+ g_object_unref (client);
+ return path_to_dir;
}
/**
- *Function used to get bookmark library location
- *@return path to bookmark location
+ * \return path to bookmark location
*/
gchar* ws_mng_get_boomark_location()
{
g_debug("->%s", __FUNCTION__);
- //g_type_init();
- GConfClient* client = NULL;
- gchar* path = NULL;
- guint i = 0;
- client = gconf_client_get_default();
- GSList* list = gconf_client_all_dirs(client, GCONF_KEY, NULL);
- for (i=0; i<g_slist_length(list); i++)
- {
- //path = g_strdup((gchar *) g_slist_nth_data(list, i));
- path = (gchar* ) g_slist_nth_data(list, i);
- gchar* name = g_strconcat(path, "/name",NULL);
+ GConfClient* client = NULL;
+ gchar* path = NULL;
+ guint i = 0;
+ client = gconf_client_get_default();
+
+ GSList* list = gconf_client_all_dirs(client, GCONF_KEY, NULL);
+ for (i=0; i<g_slist_length(list); i++)
+ {
+ path = (gchar* ) g_slist_nth_data(list, i);
+ gchar* name = g_strconcat(path, "/name",NULL);
gchar* new_path = g_strconcat(path, "/path",NULL);
- gchar* key_value = gconf_client_get_string(
- client,
- name,
- NULL);
- //g_debug("Try this: %s and the path is %s", key_value, path);
+ gchar* key_value = gconf_client_get_string( client,
+ name,
+ NULL );
+
if (key_value != NULL)
{
if (g_ascii_strcasecmp(key_value, "Bookmarks") == 0)
{
- gchar* key_value_path = gconf_client_get_string(
- client,
- new_path,
- NULL);
-
+ gchar* key_value_path =
+ gconf_client_get_string( client,
+ new_path,
+ NULL );
+
if (key_value_path != NULL)
{
g_free(key_value);
{
g_free(
g_slist_nth_data(list, i));
- }
- g_slist_free(list);
- g_object_unref(client);
+ }
+ g_slist_free(list);
+ g_object_unref(client);
return key_value_path;
}
}
key_value = NULL;
g_free(new_path);
new_path = NULL;
- }
-
+ }
+
g_debug("<-%s", __FUNCTION__);
- return NULL;
+ return NULL;
}
/**
- *Function used to check if optimized flag in GConf is set
- *@param dict path to dictionary file
- *@return TRUE if dictionary is optimize, FALSE otherwise
+ * \param dict path to dictionary file
+ * \return TRUE if dictionary is optimize, FALSE otherwise
*/
gboolean ws_mng_if_optimized(gchar* dict)
{
GConfClient* client;
gchar* path = NULL;
- gboolean key_optimized = FALSE;
+ gboolean key_optimized = FALSE;
gboolean key_found = FALSE;
- gint i = 0;
+ gint i = 0;
+
+ client = gconf_client_get_default();
+ GSList* list = gconf_client_all_dirs(client, GCONF_KEY, NULL);
+ for (i=0; i<g_slist_length(list); i++)
+ {
+ path = (gchar *) g_slist_nth_data(list, i);
+ gchar* new_path = g_strconcat(path, "/path",NULL);
+ gchar* new_optimized = g_strconcat(path, "/optimized",NULL);
+ gchar* key_value = gconf_client_get_string( client,
+ new_path,
+ NULL );
- client = gconf_client_get_default();
- GSList* list = gconf_client_all_dirs(client, GCONF_KEY, NULL);
- for (i=0; i<g_slist_length(list); i++)
- {
- path = (gchar *) g_slist_nth_data(list, i);
- gchar* new_path = g_strconcat(path, "/path",NULL);
- gchar* new_optimized = g_strconcat(path, "/optimized",NULL);
- gchar* key_value = gconf_client_get_string(client,
- new_path,
- NULL
- );
- if (g_ascii_strcasecmp(key_value, dict)==0)
+ if (g_ascii_strcasecmp(key_value, dict) == 0)
{
- key_optimized = gconf_client_get_bool(client,
- new_optimized,
- NULL
- );
+ key_optimized = gconf_client_get_bool( client,
+ new_optimized,
+ NULL );
key_found = TRUE;
- }
- g_free(new_path);
- g_free(new_optimized);
- g_free(key_value);
+ }
+ g_free(new_path);
+ g_free(new_optimized);
+ g_free(key_value);
+
if ( TRUE == key_found )
{
break;
}
- }
- for (i=0; i<g_slist_length(list); i++)
- {
- g_free(g_slist_nth_data(list, i));
- }
- g_slist_free(list);
- g_object_unref (client);
+ }
+
+ for (i=0; i<g_slist_length(list); i++)
+ {
+ g_free(g_slist_nth_data(list, i));
+ }
+ g_slist_free(list);
+ g_object_unref (client);
g_debug("<-%s", __FUNCTION__);
return key_optimized;
}
-
+/*@}*/
along with mdictionary; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-Copyright 2006 ComArch S.A.
+Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
+/** \addtogroup Manager
+ */
+/*@{*/
+/** \file ws_mng_searching_threads.c
+ * \brief Thread generation and thread functions - code.
+ */
#include <ws_mng_searching_threads.h>
#include <glib/gstdio.h>
/**
-* \brief Function used to run search for word engine in threads
-*
-* @param data required data for search word event
-* @return gpointer return value
-*/
+ * \param data required data for search word event
+ * \return gpointer return value
+ */
gpointer ws_mng_search_word (gpointer user_data)
{
- g_debug("[T-word] %s: Entering thread...", __FUNCTION__);
+ g_debug("[T-word] %s: Entering thread...", __FUNCTION__);
WSMngSearchAtom *search_atom = (WSMngSearchAtom*)user_data;
- WSMngSearchData *search = search_atom->data;
+ WSMngSearchData *search = search_atom->data;
/* enter into CRITICAL SECTION */
if (try_lock_was_locked(search,(gchar*)__FUNCTION__))
/* if another thread was run after this one - exit */
stop_if_needed(search_atom);
- g_debug("[T-word] %s - from now this thread is \'singleton\' ",
- __FUNCTION__
- );
+ g_debug( "[T-word] %s - from now this thread is \'singleton\' ",
+ __FUNCTION__ );
ws_dbus_notify(search->dbus_data, WS_DBUS_WORDS_LIST_STARTED);
/* creating new GArray for word list */
search_atom->word_list = g_array_new(TRUE, TRUE, sizeof(gchar*));
g_debug("[T-word] %s - start searching... ",__FUNCTION__);
if (search->bookmark_mode)
- { /* search only in user bookmarks */
- dict_eng_search_word_list(search->bookmark,
- search_atom->word,
- search_atom);
+ {
+ /* search only in user bookmarks */
+ dict_eng_search_word_list( search->bookmark,
+ search_atom->word,
+ search_atom );
}
else
- { /* search for word in each dictionary */
+ {
+ /* search for word in each dictionary */
gint i = 0;
for (i = 0; i < search->dict->len; i++)
{
stop_if_needed(search_atom);
Engine* dict = g_array_index(search->dict,Engine *,i);
- dict_eng_search_word_list(dict, search_atom->word, search_atom);
+ dict_eng_search_word_list( dict,
+ search_atom->word,
+ search_atom );
}
}
g_debug("[T-word] %s - searching finished.",__FUNCTION__);
* dictionary loaded */
if ((FALSE == search->bookmark_mode) || (1 < search->dict->len))
{
- g_array_sort(search_atom->word_list, ws_mng_compare_strings);
+ g_array_sort(search_atom->word_list, ws_mng_compare_strings);
ws_remove_multiple_words(search_atom);
}
/* free memory used by each word from word list */
gint i = 0;
- for (; i < search_atom->word_list->len; i++)
+ for (; i < search_atom->word_list->len; ++i)
{
g_free(g_array_index(search_atom->word_list,gchar* ,i));
}
}
/**
-* \brief Used to return results of found word from threads
-*
-* @param list word list found in dictionaries
-* @param pattern a word which is being search for in dictionaries
-* @param user_data data passed to function
-* @param error engine status information
-*/
+ * \param list word list found in dictionaries
+ * \param pattern a word which is being search for in dictionaries
+ * \param user_data data passed to function
+ * \param error engine status information
+ */
void ws_mng_on_found_word(GArray* list,
gchar* pattern,
gpointer user_data,
EngineStatus error)
{
- g_debug("[T-word-ret]-> %s", __FUNCTION__);
+ g_debug("[T-word-ret]-> %s", __FUNCTION__);
- WSMngSearchAtom* search_atom = (WSMngSearchAtom*)user_data;
+ WSMngSearchAtom* search_atom = (WSMngSearchAtom*)user_data;
static gint i = 0;
for (i = 0; i < list->len; i++)
{
/* copy word found by search engine */
gchar* new_word = g_strdup(g_array_index(list, gchar*, i));
- //g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "new_word: %s", new_word);
g_array_append_val(search_atom->word_list, new_word);
- }
+ }
g_debug("[T-word-ret]<- %s", __FUNCTION__);
}
/**
-* \brief Function used to run search for transaltion of word engine in threads
-*
-* @param data required data for search translation
-* @return gpointer return value
-*/
+ * \param data required data for search translation
+ * \return gpointer return value
+ */
gpointer ws_mng_search_translation (gpointer data)
{
- g_debug("[T-tran] %s: Entering thread...", __FUNCTION__);
+ g_debug("[T-tran] %s: Entering thread...", __FUNCTION__);
WSMngSearchAtom* search_atom = (WSMngSearchAtom*)data;
- WSMngSearchData* search = search_atom->data;
+ WSMngSearchData* search = search_atom->data;
/* ---> CRITICAL SECTION for this function */
if (try_lock_was_locked(search,(gchar*)__FUNCTION__))
/* if another thread was run after this one - exit */
stop_if_needed(search_atom);
- g_debug("[T-tran] %s - from now this thread is \'singleton\' ",
- __FUNCTION__
- );
+ g_debug( "[T-tran] %s - from now this thread is \'singleton\' ",
+ __FUNCTION__ );
ws_dbus_notify(search->dbus_data, WS_DBUS_TRANSLATION_STARTED);
/* run search for translation for every dictionary */
if (search->bookmark_mode)
{
- dict_eng_search_word_translation(search->bookmark,
- search_atom->word,
- search_atom);
+ dict_eng_search_word_translation( search->bookmark,
+ search_atom->word,
+ search_atom );
}
else
{
gint i;
for (i = 0; i < search->dict->len; i++)
- {
+ {
stop_if_needed(search_atom);
- if (NULL == g_array_index(search->dict, Engine*, i) )
+ if (NULL == g_array_index(search->dict, Engine*, i) )
{
continue;
}
g_array_index(search->dict, Engine*, i),
search_atom->word,
search_atom);
- }
+ }
}
g_debug("[T-tran] %s - searching finished.",__FUNCTION__);
}
/**
-* \brief Used to return results of transaltion from threads
-*
-* @param translation translation of word found in dictionaries
-* @param pattern a word which is being serch for in dictionaries
-* @param user_data data passed to function
-* @param error engine status information
+* \param translation translation of word found in dictionaries
+* \param pattern a word which is being serch for in dictionaries
+* \param user_data data passed to function
+* \param error engine status information
*/
void ws_mng_on_found_translation(gchar* translation,
gchar* pattern,
EngineStatus error
)
{
- g_debug("->%s", __FUNCTION__);
- WSMngSearchAtom* search_atom = (WSMngSearchAtom*)user_data;
+ g_debug("->%s", __FUNCTION__);
+ WSMngSearchAtom* search_atom = (WSMngSearchAtom*)user_data;
/* we get already the first translation */
if ((NULL != translation) && (NULL == search_atom->trans))
- { /* concatenate tags and searched word and translation */
+ {
+ /* concatenate tags and searched word and translation */
search_atom->trans = g_strconcat("<PATTERN_OPEN>",
pattern,
"<PATTERN_CLOSED><TRANSLATION_OPEN>",
);
}
else if (NULL != translation)
- { /* if there was stored translation *
- * copy stored translation to temporary variable*/
+ {
+ /* if there was stored translation
+ * copy stored translation to temporary variable */
gchar* tmp = g_strconcat(search_atom->trans,
"<TRANSLATION_OPEN>",
translation,
g_debug("<-%s", __FUNCTION__);
}
-
/**
-* \brief Function used to compare string. Used in sorting GArray object
-*
-*@param a first argument to compere
-*@param b second argument to compere
-*@return 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
-*/
+ * \param a first argument to compare
+ * \param b second argument to compare
+ * \return 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
+ */
gint ws_mng_compare_strings (gconstpointer a, gconstpointer b)
{
gchar** str1 = (gchar**)(a);
return result;
}
+/**
+ * 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).
+ * \param user_data WSMngSearchAtom with array of all words returned from all
+ * dictionaries
+ */
void ws_remove_multiple_words(WSMngSearchAtom* user_data)
{
WSMngSearchAtom* search = (WSMngSearchAtom*)user_data;
gchar* tmp1 = NULL;
gchar* tmp2 = NULL;
- if (search->word_list->len < 256)
+ /* check if words list is longer than 256 words */
+ if (search->word_list->len < 256)
{
temp = search->word_list->len;
if (temp >0)
- {
- ws_dbus_notify(search->data->dbus_data, WS_DBUS_WORDS_LIST_FILLED_NOT_FULL);
+ {
+ ws_dbus_notify( search->data->dbus_data,
+ WS_DBUS_WORDS_LIST_FILLED_NOT_FULL );
}
}
else
{
- ws_dbus_notify(search->data->dbus_data, WS_DBUS_WORDS_LIST_FULL);
+ ws_dbus_notify( search->data->dbus_data,
+ WS_DBUS_WORDS_LIST_FULL );
}
+ /* remove repeating words in the first 256 places in the array - words
+ * in places further than 256 are not being sent to UI so we do not need
+ * to filter them for searching repeating words */
for (i = 0; i < temp-1; i++)
{
tmp1 = g_utf8_casefold(
- g_array_index(search->word_list,gchar*,i),
- -1
- );
+ g_array_index(search->word_list,gchar*,i),
+ -1 );
for (j = i + 1; j < temp; j++)
{
/* search if there is a word on word list */
tmp2 = g_utf8_casefold(
- g_array_index(search->word_list,gchar*,j),
- -1
- );
- result = g_utf8_collate(tmp1,tmp2);
+ g_array_index(search->word_list,gchar*,j),
+ -1 );
+ result = g_utf8_collate(tmp1,tmp2);
g_free(tmp2);
tmp2 = NULL;
+
/* if there is a word on the word list
* remove that word */
if (result == 0)
g_array_remove_index(search->word_list, j);
--j;
--temp;
- if (search->word_list->len >= 256){
+ if (search->word_list->len >= 256)
+ {
temp = 256;
}
}
}
}
+/*@}*/
along with mdictionary; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-Copyright 2006 ComArch S.A.
+Copyright 2006-2008 ComArch S.A.
*******************************************************************************/
+/** \addtogroup Manager
+ */
+/*@{*/
+/** \file ws_mng_threads_utils.c
+ * \brief Thread utilities - code.
+ */
#include <ws_mng_threads_utils.h>
/* added by Dariusz Wiechecki
* trying to lock mutext and tells if it was locked */
+/**
+ * \param data manager data
+ * \param fun string to display in logs - it intentionaly this should be caller
+ * function name
+ */
gboolean try_lock_was_locked(WSMngSearchData* data, gchar* fun)
{
gboolean res = !g_static_mutex_trylock(data->action_working);
/* added by Dariusz Wiechecki
* check if recursive mutex is already locked
* must be call from critical section!!! */
+/**
+ * If mutex was not locked it is not locked by this function. It only check
+ * if given mutex is already locked.
+ *
+ * \param m mutex to be checked
+ */
gboolean is_rec_locked(GStaticRecMutex* m)
{
gboolean r = !g_static_rec_mutex_trylock(m);
/* added by Dariusz Wiechecki
* stop current thread if there is such a need - newer thread is waiting */
+/**
+ * \param data search atom data for current thread
+ */
void stop_if_needed(WSMngSearchAtom* data)
{
static GStaticMutex _loc;
g_static_mutex_unlock(loc);
}
+/**
+ * \param data search atom data for current thread
+ */
void free_search_atom(WSMngSearchAtom* data)
{
g_debug("[T-clear] Cleaning after thread\n");
g_free(data);
}
+/**
+ * \param app_data manager data
+ * \param word word to search
+ */
WSMngSearchAtom *create_search_atom(WSMngSearchData* app_data, gchar* word)
{
WSMngSearchAtom* search_data = NULL;
return search_data;
}
+
+/*@}*/