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 ComArch S.A. 00019 *******************************************************************************/ 00020 #ifndef _DICTIONARY_ENGINE_BOOKMARK 00021 #define _DICTIONARY_ENGINE_BOOKMARK 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 //______________________________________________________________________________ 00028 // ***************************************************************************** 00029 //************************************************************* HEADERS SECTION: 00030 //------------------------------------------------------------------------------ 00031 // headers with unix types/functions - only for timers 00032 #include <sys/types.h> 00033 #include <sys/stat.h> 00034 #include <sys/time.h> 00035 #include <fcntl.h> 00036 #include <unistd.h> 00037 //------------------------------------------------------------------------------ 00038 // header with GLIB definitions/functions/types 00039 #include <glib.h> 00040 //------------------------------------------------------------------------------ 00041 // header wit engine API 00042 #include "dictionary_engine.h" 00043 //------------------------------------------------------------------------------ 00044 // header wit sqlite 2.x API 00045 #include <db/db.h> 00046 //------------------------------------------------------------------------------ 00047 #include <string.h> 00048 00049 //______________________________________________________________________________ 00050 // ***************************************************************************** 00051 //********************************************************* DEFINITIONS SECTION: 00052 //------------------------------------------------------------------------------ 00053 // definitions for timer function - flag telling if we want to start or stop 00054 // timing 00055 #define TIMER_START TRUE 00056 #define TIMER_STOP FALSE 00057 //------------------------------------------------------------------------------ 00058 // definitions of version and format which engine handles 00059 static const gchar* DIC_ENG_VERSION = "0.2"; 00060 static const gchar* DIC_ENG_FORMAT = "Users' Bookmarks"; 00061 static const gchar* DIC_ENG_DESCRIPTION = "This module handles users' " 00062 "bookmarks. Based on Berkeley DB 1.85"; 00063 00064 //------------------------------------------------------------------------------ 00065 // macro for "printing" gboolean statement - "TRUE" or "FALSE" 00066 #define PRINT_STATE(state) ( (state) ? "TRUE" : "FALSE" ) 00067 //------------------------------------------------------------------------------ 00068 00069 00070 //______________________________________________________________________________ 00071 // ***************************************************************************** 00072 //****************************************** DATA STRUCTURE DEFINITIONS SECTION: 00073 //------------------------------------------------------------------------------ 00076 struct _BookData { 00077 DB* db_words; 00078 DB* db_trans; 00079 BTREEINFO info_words; 00080 BTREEINFO info_trans; 00081 guint freeID; 00082 00083 00084 00085 gchar* dict_path; 00086 EngineStatus last_error; 00087 gboolean auto_free; 00088 00089 cb_progress cb_progress_caching; 00090 gpointer cb_progress_caching_data; 00091 gdouble cb_progress_caching_seed; 00092 00093 cb_progress cb_progress_word_list; 00094 gpointer cb_progress_word_list_data; 00095 gdouble cb_progress_word_list_seed; 00096 00097 cb_progress cb_progress_word_trans; 00098 gpointer cb_progress_word_trans_data; 00099 gdouble cb_progress_word_trans_seed; 00100 00101 cb_word_list cb_search_word_list; 00102 gpointer cb_search_word_list_data; 00103 00104 cb_word_translation cb_search_word_trans; 00105 gpointer cb_search_word_trans_data; 00106 }; 00107 typedef struct _BookData BookData; 00108 //------------------------------------------------------------------------------ 00109 00110 00111 //______________________________________________________________________________ 00112 // ***************************************************************************** 00113 //************************************************ ADDITIONAL FUNCTIONS SECTION: 00114 //------------------------------------------------------------------------------ 00115 // returning concrete part of file 00116 //static gchar* read_file_part(FilePart* part, GnomeVFSHandle* file); 00117 //------------------------------------------------------------------------------ 00118 // convert string to proper path name (no filename, no "/" at the ned, file 00119 // exist) 00120 static gchar* string_to_path(gchar** string); 00121 //------------------------------------------------------------------------------ 00122 // tells if file is in Bookark Berkeley DB format (file should exist) 00123 static gboolean is_Bookmark_db_file(gchar* file); 00124 //------------------------------------------------------------------------------ 00125 // start/stop timers - returnet -1.0 if we start or seconds passed from start 00126 // if we want to stop timer 00127 static double bm_timer(gboolean start, gchar* message); 00128 //------------------------------------------------------------------------------ 00129 // create and add new entry to databases 00130 static gboolean bm_add_new_entry(gchar* word, 00131 gchar* translation, 00132 BookData* data); 00133 //------------------------------------------------------------------------------ 00134 // load current minimal available free ID fortranslations 00135 static void bm_load_freeID(BookData* data); 00136 //------------------------------------------------------------------------------ 00137 // save current minimal available free ID fortranslations 00138 static void bm_save_freeID(BookData* data); 00139 //------------------------------------------------------------------------------ 00140 // save translation in database under id 00141 static gboolean bm_add_only_translation(BookData* data, 00142 gchar* translation, 00143 guint id); 00144 //------------------------------------------------------------------------------ 00145 static gint bm_compare_key_trans(const DBT *a, const DBT *b); 00146 static gint bm_compare_key_words(const DBT *a, const DBT *b); 00147 //______________________________________________________________________________ 00148 // ***************************************************************************** 00149 //****************************************************** MAIN FUNCTIONS SECTION: 00150 //------------------------------------------------------------------------------ 00151 gboolean bm_engine_add_word(Engine* engine, 00152 gchar* word, 00153 gchar* translation); 00154 //------------------------------------------------------------------------------ 00155 gboolean bm_engine_remove_word(Engine* engine, 00156 gchar* word); 00157 //------------------------------------------------------------------------------ 00158 gchar* bm_engine_get_lang_from(Engine* engine); 00159 //------------------------------------------------------------------------------ 00160 gchar* bm_engine_get_lang_to(Engine* engine); 00161 //------------------------------------------------------------------------------ 00162 gchar* bm_engine_get_title(Engine* engine); 00163 //------------------------------------------------------------------------------ 00164 gchar* bm_engine_get_icon_path(Engine* engine); 00165 00166 00167 00168 //------------------------------------------------------------------------------ 00169 // implementation of dict_eng_module_check(module,location) function 00170 gboolean bm_engine_check(gchar* location); 00171 //------------------------------------------------------------------------------ 00172 // implementation of dict_eng_module_get_description(module) function 00173 gchar* bm_engine_description(); 00174 //------------------------------------------------------------------------------ 00175 // implementation of dict_eng_module_get_format(module) function 00176 gchar* bm_engine_format(); 00177 //------------------------------------------------------------------------------ 00178 // implementation of dict_eng_module_get_version(module) function 00179 gchar* bm_engine_version(); 00180 //------------------------------------------------------------------------------ 00181 // implementation of dict_eng_module_create(module,location,flags) and 00182 // dict_eng_module_create_ext(module,location,flags) functions 00183 Engine* bm_engine_create(gchar* location, 00184 EngineOptimizationFlag flags, 00185 cb_progress progress_handler, 00186 gpointer progress_data, 00187 gdouble seed); 00188 //------------------------------------------------------------------------------ 00189 // implementation of dict_eng_destroy(engine) function 00190 void bm_engine_close(Engine* engine); 00191 //------------------------------------------------------------------------------ 00192 // implementation of dict_eng_get_location(engine) function 00193 gchar* bm_engine_location(Engine* engine); 00194 //------------------------------------------------------------------------------ 00195 // implementation of dict_eng_optimize(engine) function 00196 void bm_engine_optimize(Engine* engine); 00197 //------------------------------------------------------------------------------ 00198 // implementation of dict_eng_is_optimized( engine ) function 00199 gboolean bm_engine_is_optimized(Engine* engine); 00200 //------------------------------------------------------------------------------ 00201 // implementation of dict_eng_set_auto_free(engine, state) function 00202 void bm_engine_set_auto_free(Engine* engine, gboolean state); 00203 //------------------------------------------------------------------------------ 00204 // implementation of dict_eng_set_callback(engine,signal,c_handler,data) 00205 // function 00206 gpointer bm_engine_set_callback(Engine* engine, 00207 gchar* event, 00208 gpointer c_handler, 00209 gpointer user_data); 00210 //------------------------------------------------------------------------------ 00211 // implementation of dict_eng_set_progress_seed(engine, signal, val) function 00212 void bm_engine_set_progress_seed(Engine* engine, 00213 gchar* signal, 00214 gdouble seed); 00215 //------------------------------------------------------------------------------ 00216 // implementation ofdict_eng_search_word_list(engine,pattern) function 00217 void bm_engine_search_word_list(Engine* engine, 00218 gchar* pattern, 00219 gpointer data); 00220 //------------------------------------------------------------------------------ 00221 // implementation of dict_eng_search_word_translation(engine,word) function 00222 void bm_engine_search_word_translation(Engine* engine, 00223 gchar* word, 00224 gpointer data); 00225 //------------------------------------------------------------------------------ 00226 // implementation of dict_eng_get_last_state(engine) function 00227 EngineStatus bm_engine_status(Engine* engine); 00228 //------------------------------------------------------------------------------ 00229 // implementation of dict_eng_state_message(error) function 00230 gchar* bm_engine_status_message(EngineStatus error); 00231 //------------------------------------------------------------------------------ 00232 // implementation of engine_global_functions(void) function 00233 EngineModule engine_global_functions(); 00234 00235 #ifdef __cplusplus 00236 } 00237 #endif 00238 #endif /* #ifndef _DICTIONARY_ENGINE_STARDICT */