src/manager/src/ws_mng_bookmarks_utils.c

Go to the documentation of this file.
00001 /*******************************************************************************
00002 This file is part of mdictionary.
00003 
00004 mdictionary is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2 of the License, or
00007 (at your option) any later version.
00008 
00009 mdictionary is distributed in the hope that it will be useful, 
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License 
00015 along with mdictionary; if not, write to the Free Software
00016 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00017 
00018 Copyright 2006-2008 ComArch S.A.
00019 *******************************************************************************/
00025 #include <ws_mng_bookmarks_utils.h>
00026 
00033 void ws_mng_add_bookmark(GError *error, GArray* param, gpointer user_data)
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 }
00079 
00086 void ws_mng_remove_bookmark(GError *error, GArray* param, gpointer user_data)
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 }
00124 
00125 
00130 void ws_mng_load_bookmark(WSMngSearchData* data)
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 }
00175 
00176 

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