1 /* 2 * Copyright 2011 kubtek <kubtek@mail.com> 3 * 4 * This file is part of StarDict. 5 * 6 * StarDict is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * StarDict is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with StarDict. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef __STAR_DICT_H__ 21 #define __STAR_DICT_H__ 22 23 #ifdef HAVE_CONFIG_H 24 #include <config.h> 25 #endif 26 27 #include <gtk/gtk.h> 28 29 #ifdef CONFIG_GNOME 30 # include <bonobo/bonobo-object.h> 31 # include <libgnome/libgnome.h> 32 #endif 33 34 35 class AppCore; 36 37 #include "conf.h" 38 #include "lib/utils.h" 39 #include "lib/stardict_client.h" 40 #include "lib/pluginmanager.h" 41 #include "lib/httpmanager.h" 42 #include "skin.h" 43 #include "mainwin.h" 44 #ifdef _WIN32 45 # include "win32/clipboard.h" 46 # include "win32/mouseover.h" 47 #endif 48 49 #include "tray.h" 50 #include "floatwin.h" 51 #include "selection.h" 52 #include "readword.h" 53 #include "iskeyspressed.h" 54 #include "dictmanage.h" 55 #include "globalhotkeys.h" 56 #include "lib/compositelookup.h" 57 #include "lib/full_text_trans.h" 58 #include "lib/stddict.h" 59 #include "lib/treedict.h" 60 61 extern AppCore *gpAppFrame; 62 63 //notice!!! when you change these DEFAULT const value,remember that you'd better change data/stardict.schemas.in too! 64 65 const int MAX_FUZZY_MATCH_ITEM=100; 66 const int MAX_FLOAT_WINDOW_FUZZY_MATCH_ITEM=5; 67 68 const int LIST_WIN_ROW_NUM = 30; //how many words show in the list win. 69 70 class DictManageDlg; 71 class PluginManageDlg; 72 class PrefsDlg; 73 74 class AppCore : public sigc::trackable { 75 private: 76 DictManageDlg *dict_manage_dlg; 77 PluginManageDlg *plugin_manage_dlg; 78 PrefsDlg *prefs_dlg; 79 guint word_change_timeout_id; 80 std::string delayed_word_; 81 CompositeLookup composite_lookup_float_win; 82 83 static int MatchWordCompare(const void * s1, const void * s2); 84 static void on_mainwin_show_event(GtkWidget * window, AppCore *app); 85 static gboolean on_delete_event(GtkWidget * window, GdkEvent *event , AppCore *oAppCore); 86 static gboolean on_window_state_event(GtkWidget * window, GdkEventWindowState *event , AppCore *oAppCore); 87 static gboolean vKeyPressReleaseCallback(GtkWidget * window, GdkEventKey *event , AppCore *oAppCore); 88 void reload_dicts(); 89 void on_main_win_hide_list_changed(const baseconfval*); 90 void on_dict_scan_select_changed(const baseconfval*); 91 void on_scan_modifier_key_changed(const baseconfval*); 92 static gboolean on_word_change_timeout(gpointer data); 93 void stop_word_change_timer(); 94 void on_change_scan(bool val); 95 void on_maximize(); 96 void on_docklet_middle_button_click(); 97 bool SimpleLookupToFloatLocal(const gchar* sWord); 98 #ifdef _WIN32 99 bool LocalSmartLookupToFloat(const gchar* sWord, int BeginPos); 100 #endif 101 public: 102 CurrentIndex *iCurrentIndex; 103 unsigned int waiting_mainwin_lookupcmd_seq; 104 /* last directory selected in save/open file and similar dialogs */ 105 std::string last_selected_directory; 106 GtkWidget *window; 107 108 TopWin oTopWin; 109 MidWin oMidWin; 110 BottomWin oBottomWin; 111 112 Selection oSelection; 113 #ifdef _WIN32 114 Clipboard oClipboard; 115 Mouseover oMouseover; 116 #endif 117 GlobalHotkeys oHotkey; 118 FloatWin oFloatWin; 119 std::auto_ptr<TrayBase> oDockLet; 120 121 Libs oLibs; 122 TreeDicts oTreeDicts; 123 StarDictClient oStarDictClient; 124 StarDictPlugins *oStarDictPlugins; 125 HttpManager oHttpManager; 126 std::auto_ptr<hotkeys> unlock_keys; 127 AppSkin oAppSkin; 128 ReadWord oReadWord; 129 FullTextTrans oFullTextTrans; 130 131 #ifdef CONFIG_GNOME 132 BonoboObject *stardict_app_server; 133 #endif 134 135 DictManageInfo dictinfo; 136 std::vector<InstantDictIndex> query_dictmask; 137 std::vector<InstantDictIndex> scan_dictmask; 138 139 AppCore(); 140 ~AppCore(); 141 void Init(const gchar *queryword); 142 void Quit(); 143 void Create(const gchar *queryword); 144 void End(); 145 void Query(const gchar *word); 146 void BuildResultData(std::vector<InstantDictIndex> &dictmask, const char* sWord, CurrentIndex *iIndex, const gchar *piIndexValidStr, int iLib, gchar ***pppWord, gchar ****ppppWordData, bool &bFound, gint Method); 147 void BuildVirtualDictData(std::vector<InstantDictIndex> &dictmask, const char* sWord, int iLib, gchar ***pppWord, gchar ****ppppWordData, bool &bFound); 148 static void FreeResultData(size_t dictmask_size, gchar ***pppWord, gchar ****ppppWordData); 149 void SimpleLookupToFloat(const char* sToken, bool IgnoreScanModifierKey = false); 150 #ifdef _WIN32 151 void SmartLookupToFloat(const gchar* sWord, int BeginPos, bool IgnoreScanModifierKey); 152 #endif 153 bool SimpleLookupToTextWin(const gchar* sWord, CurrentIndex* piIndex, const gchar *piIndexValidStr = NULL, bool bTryMoreIfNotFound = false, bool bShowNotfound = true, bool isShowFirst = false); 154 void LookupDataToMainWin(const gchar *sWord); 155 void LookupDataWithDictMask(const gchar *sWord, std::vector<InstantDictIndex> &dictmask); 156 void LookupWithFuzzyToMainWin(const gchar* word); 157 void LookupWithFuzzyToFloatWin(const gchar * word); 158 void LookupWithRuleToMainWin(const gchar* word); 159 void LookupWithRegexToMainWin(const gchar* word); 160 void LookupNetDict(const char *word, bool ismainwin); 161 void ShowDataToTextWin(gchar ***pppWord, gchar ****ppppWordData,const gchar * sOriginWord, bool isShowFirst); 162 void ShowTreeDictDataToTextWin(guint32 offset, guint32 size, gint iTreeDict); 163 void ShowNotFoundToTextWin(const char* sWord,const char* sReason, TextWinQueryResult query_result); 164 165 void TopWinEnterWord(); 166 void TopWinWordChange(const gchar* sWord); 167 void ListWords(CurrentIndex* iStartIndex); 168 void ListPreWords(const char*sWord); 169 void ListNextWords(const char*sWord); 170 171 void ListClick(const gchar *word); 172 void PopupPrefsDlg(); 173 void PopupDictManageDlg(); 174 void PopupPluginManageDlg(); 175 void on_link_click(const std::string &link); 176 177 void on_stardict_client_error(const char *); 178 void on_stardict_client_lookup_end(const struct STARDICT::LookupResponse *lookup_response, unsigned int seq); 179 void on_stardict_client_floatwin_lookup_end(const struct STARDICT::LookupResponse *lookup_response, unsigned int seq); 180 void on_stardict_client_register_end(const char *); 181 void on_stardict_client_getdictmask_end(const char *); 182 void on_stardict_client_getadinfo_end(const char *); 183 void on_stardict_client_dirinfo_end(const char *); 184 void on_stardict_client_dictinfo_end(const char *); 185 void on_stardict_client_maxdictcount_end(int); 186 void on_stardict_client_previous_end(std::list<char *> *wordlist_response); 187 void on_stardict_client_next_end(std::list<char *> *wordlist_response); 188 189 void on_http_client_error(HttpClient*, const char *); 190 void on_http_client_response(HttpClient*); 191 static void do_send_http_request(const char* shost, const char* sfile, get_http_response_func_t callback_func, gpointer userdata); 192 static void set_news(const char *news, const char *links); 193 static void show_netdict_resp(const char *dict, NetDictResponse *resp, bool ismainwin); 194 static void lookup_dict(size_t dictid, const char *sWord, char ****Word, char *****WordData); 195 static void ShowPangoTips(const char *word, const char *text); 196 }; 197 198 extern gchar* GetPureEnglishAlpha(gchar *str); 199 extern gchar* GetHeadWord(gchar *str); 200 extern gboolean stardict_on_enter_notify (GtkWidget * widget, GdkEventCrossing * event, gpointer data); 201 202 #ifdef _WIN32 203 #if BUILDING_DLL 204 # define DLLIMPORT __declspec (dllexport) 205 #else /* Not BUILDING_DLL */ 206 # define DLLIMPORT __declspec (dllimport) 207 #endif /* Not BUILDING_DLL */ 208 209 extern "C" { 210 DLLIMPORT extern int stardict_main(HINSTANCE hInstance, int argc, char **argv); 211 } 212 #endif 213 214 #endif 215