diff -bBurN stardict-cur-accepted/src/conf.cpp stardict/src/conf.cpp --- stardict-cur-accepted/src/conf.cpp 2005-02-01 16:44:50.132184808 +0300 +++ stardict/src/conf.cpp 2005-02-01 16:04:18.293880424 +0300 @@ -17,6 +17,7 @@ #include "conf.h" std::auto_ptr conf; +std::string gStarDictDataDir; inline void free_list(GSList *l){ if(l!=NULL){ diff -bBurN stardict-cur-accepted/src/conf.h stardict/src/conf.h --- stardict-cur-accepted/src/conf.h 2005-02-01 16:44:50.133184656 +0300 +++ stardict/src/conf.h 2005-02-01 16:04:16.004228504 +0300 @@ -3,6 +3,7 @@ #include #include +#include #if defined(_WIN32) || defined(WITHOUT_GNOME) struct ConfigLine { @@ -62,7 +63,7 @@ * all preference of stardict. */ -class AppConf : public TBaseConf { +class AppConf : private TBaseConf { private: gint hpaned_pos; gint window_width, window_height; @@ -98,58 +99,59 @@ ~AppConf(); void Load(void); - gint get_hpaned_pos(void){return hpaned_pos;} + gint get_hpaned_pos(void) const{return hpaned_pos;} void set_hpaned_pos(gint value); - gint get_window_width(void){return window_width;} + gint get_window_width(void) const{return window_width;} void set_window_width(gint value); - gint get_window_height(void){return window_height;} + gint get_window_height(void) const{return window_height;} void set_window_height(gint value); - gint get_lock_x(void){return lock_x;} + gint get_lock_x(void) const{return lock_x;} void set_lock_x(gint value); - gint get_lock_y(void){return lock_y;} + gint get_lock_y(void) const{return lock_y;} void set_lock_y(gint value); - gboolean get_maximized(void){return maximized;} + gboolean get_maximized(void) const{return maximized;} void set_maximized(gboolean value); - gboolean get_use_custom_font(void){return use_custom_font;} + gboolean get_use_custom_font(void) const{return use_custom_font;} void set_use_custom_font(gboolean value); - const gchar *get_custom_font(void){return custom_font;} + const gchar *get_custom_font(void) const{return custom_font;} void set_custom_font(const gchar *value); - gboolean get_hide_on_startup(void){return hide_on_startup;} + gboolean get_hide_on_startup(void) const{return hide_on_startup;} void set_hide_on_startup(gboolean value); - gboolean get_enable_sound_event(void){return enable_sound_event;} + gboolean get_enable_sound_event(void) const{return enable_sound_event;} void set_enable_sound_event(gboolean value); - gboolean get_hide_list(void){return hide_list;} + gboolean get_hide_list(void) const{return hide_list;} void set_hide_list(gboolean value); - const GSList *get_search_website_list(void){return search_website_list;} + const GSList *get_search_website_list(void) const{return search_website_list;} void set_search_website_list(GSList *value); - gboolean get_scan_selection(void){return scan_selection;} + gboolean get_scan_selection(void) const{return scan_selection;} void set_scan_selection(gboolean value); - gboolean get_query_in_floatwin(void){return query_in_floatwin;} + gboolean get_query_in_floatwin(void) const{return query_in_floatwin;} void set_query_in_floatwin(gboolean value); - gboolean get_only_scan_while_modifier_key(void){return only_scan_while_modifier_key;} + gboolean get_only_scan_while_modifier_key(void) const{return only_scan_while_modifier_key;} void set_only_scan_while_modifier_key(gboolean value); - gboolean get_hide_floatwin_when_modifier_key_released(void){return hide_floatwin_when_modifier_key_released;} + gboolean get_hide_floatwin_when_modifier_key_released(void) const{return hide_floatwin_when_modifier_key_released;} void set_hide_floatwin_when_modifier_key_released(gboolean value); - gint get_scan_modifier_key(void){return scan_modifier_key;} + gint get_scan_modifier_key(void) const{return scan_modifier_key;} void set_scan_modifier_key(gint value); - gboolean get_pronounce_when_popup(void){return pronounce_when_popup;} + gboolean get_pronounce_when_popup(void) const{return pronounce_when_popup;} void set_pronounce_when_popup(gboolean value); - gint get_max_window_width(void){return max_window_width;} + gint get_max_window_width(void) const{return max_window_width;} void set_max_window_width(gint value); - gint get_max_window_height(void){return max_window_height;} + gint get_max_window_height(void) const{return max_window_height;} void set_max_window_height(gint value); - const GSList *get_treedict_order_list(void){return treedict_order_list;} + const GSList *get_treedict_order_list(void) const{return treedict_order_list;} void set_treedict_order_list(GSList *value); - const GSList *get_treedict_disable_list(void){return treedict_disable_list;} + const GSList *get_treedict_disable_list(void) const{return treedict_disable_list;} void set_treedict_disable_list(GSList *value); - const GSList *get_dict_order_list(void){return dict_order_list;} + const GSList *get_dict_order_list(void) const{return dict_order_list;} void set_dict_order_list(GSList *value); - const GSList *get_dict_disable_list(void){return dict_disable_list;} + const GSList *get_dict_disable_list(void) const{return dict_disable_list;} void set_dict_disable_list(GSList *value); - gboolean get_lock(void){return lock;} + gboolean get_lock(void) const{return lock;} void set_lock(gboolean value); }; extern std::auto_ptr conf;//global exemplar of AppConf class +extern std::string gStarDictDataDir; #endif diff -bBurN stardict-cur-accepted/src/dictmanagedlg.cpp stardict/src/dictmanagedlg.cpp --- stardict-cur-accepted/src/dictmanagedlg.cpp 2005-02-01 16:44:50.134184504 +0300 +++ stardict/src/dictmanagedlg.cpp 2005-02-01 16:32:49.888678464 +0300 @@ -12,6 +12,7 @@ #include "stardict.h" #include "conf.h" +#include "utils.h" #include "dictmanagedlg.h" @@ -24,17 +25,8 @@ { switch (res_id) { case GTK_RESPONSE_HELP: - { -#ifdef _WIN32 - //gchar *filename = g_strdup_printf(_("file:///%s/help/C/stardict.html#stardict-dictmanage"), stardict_data_dir); - gchar *filename = g_strdup_printf(_("file:///%s/help/C/stardict.html"), stardict_data_dir); - ShellExecute((HWND)(GDK_WINDOW_HWND(gpAppFrame->oAppCore.window->window)), "OPEN", filename, NULL, NULL, SW_SHOWNORMAL); - g_free(filename); -#else - gnome_help_display ("stardict.xml", "stardict-dictmanage", NULL); -#endif + show_help("stardict-dictmanage"); break; - } default: oDictManageDlg->Close(); } @@ -156,7 +148,7 @@ return true; } -void DictManageDlg::load_dir(gboolean istreedict, gchar *dirname, const GSList *order_list, const GSList *disable_list, GtkListStore *model) +void DictManageDlg::load_dir(gboolean istreedict, const gchar *dirname, const GSList *order_list, const GSList *disable_list, GtkListStore *model) { GDir *dir = g_dir_open(dirname, 0, NULL); if (dir) @@ -263,13 +255,6 @@ } #ifdef _WIN32 - gchar *filename; - if (istreedict) - filename = g_build_filename(stardict_data_dir, "treedict", NULL); - else - filename = g_build_filename(stardict_data_dir, "dic", NULL); - load_dir(istreedict, filename, order_list, disable_list, model); - g_free(filename); #else gchar home_dir[256]; if (istreedict) @@ -277,12 +262,11 @@ else sprintf(home_dir, "%s/.stardict/dic", g_get_home_dir()); load_dir(istreedict, home_dir, order_list, disable_list, model); - if (istreedict) - load_dir(istreedict, STARDICT_DATA_DIR "/treedict", order_list, disable_list, model); - else - load_dir(istreedict, STARDICT_DATA_DIR "/dic", order_list, disable_list, model); #endif + std::string filename(gStarDictDataDir+G_DIR_SEPARATOR); + filename += (istreedict) ? "treedict" : "dic"; + load_dir(istreedict, filename.c_str(), order_list, disable_list, model); return GTK_TREE_MODEL (model); } diff -bBurN stardict-cur-accepted/src/dictmanagedlg.h stardict/src/dictmanagedlg.h --- stardict-cur-accepted/src/dictmanagedlg.h 2005-02-01 16:44:50.135184352 +0300 +++ stardict/src/dictmanagedlg.h 2005-01-27 20:14:06.000000000 +0300 @@ -13,7 +13,7 @@ GtkWidget *treedict_treeview; GtkTreeModel *treedict_tree_model; - static void load_dir(gboolean istreedict, gchar *dirname, const GSList *order_list, const GSList *disable_list, GtkListStore *model); + static void load_dir(gboolean istreedict, const gchar *dirname, const GSList *order_list, const GSList *disable_list, GtkListStore *model); static GtkTreeModel* create_dict_tree_model (gboolean istreedict); GtkWidget *create_dict_tree(gboolean istreedict); diff -bBurN stardict-cur-accepted/src/docklet.cpp stardict/src/docklet.cpp --- stardict-cur-accepted/src/docklet.cpp 2005-02-01 16:44:50.135184352 +0300 +++ stardict/src/docklet.cpp 2005-01-27 21:00:35.000000000 +0300 @@ -108,7 +108,6 @@ void DockLet::PopupMenu(GdkEventButton *event) { - //gnome_sound_play(STARDICT_DATA_DIR "/sounds/menushow.wav"); if (!menu) { menu = gtk_menu_new(); diff -bBurN stardict-cur-accepted/src/floatwin.cpp stardict/src/floatwin.cpp --- stardict-cur-accepted/src/floatwin.cpp 2005-02-01 16:44:50.137184048 +0300 +++ stardict/src/floatwin.cpp 2005-02-01 16:38:17.374892992 +0300 @@ -12,6 +12,7 @@ #include "stardict.h" #include "conf.h" +#include "utils.h" #include "floatwin.h" @@ -908,15 +909,9 @@ gtk_widget_show_all(oFloatWin->menu); gtk_menu_popup(GTK_MENU(oFloatWin->menu), NULL, NULL, NULL, NULL, event->button, event->time); - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "menushow.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/menushow.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"menushow.wav").c_str()); + } /*else if (event->button == 2) { gint start,end; @@ -975,15 +970,9 @@ void FloatWin::on_query_click(GtkWidget *widget, gpointer data) { - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "buttonactive.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/buttonactive.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"buttonactive.wav").c_str()); + if (!conf->get_lock()) gpAppFrame->oAppCore.oFloatWin.Hide(); gpAppFrame->oAppCore.Query(gpAppFrame->oAppCore.oFloatWin.QueryingWord.c_str()); @@ -996,15 +985,9 @@ void FloatWin::on_copy_click(GtkWidget *widget, gpointer data) { - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "buttonactive.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/buttonactive.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"buttonactive.wav").c_str()); + const gchar *text = gtk_label_get_text(GTK_LABEL(gpAppFrame->oAppCore.oFloatWin.label)); GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); gtk_clipboard_set_text(clipboard,text,-1); @@ -1017,65 +1000,34 @@ void FloatWin::on_stop_click(GtkWidget *widget, gpointer data) { - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "buttonactive.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/buttonactive.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"buttonactive.wav").c_str()); + conf->set_scan_selection(FALSE); } void FloatWin::on_help_click(GtkWidget *widget, gpointer data) { - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "buttonactive.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/buttonactive.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"buttonactive.wav").c_str()); + if (!conf->get_lock()) gpAppFrame->oAppCore.oFloatWin.Hide(); -#ifdef _WIN32 - //gchar *filename = g_strdup_printf(_("file:///%s/help/C/stardict.html#stardict-scan-selection"), stardict_data_dir); - gchar *filename = g_strdup_printf(_("file:///%s/help/C/stardict.html"), stardict_data_dir); - ShellExecute((HWND)(GDK_WINDOW_HWND(gpAppFrame->oAppCore.window->window)), "OPEN", filename, NULL, NULL, SW_SHOWNORMAL); - g_free(filename); -#else - gnome_help_display ("stardict.xml", "stardict-scan-selection", NULL); -#endif + show_help("stardict-scan-selection"); } void FloatWin::on_quit_click(GtkWidget *widget, gpointer data) { - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "buttonactive.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/buttonactive.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"buttonactive.wav").c_str()); + gpAppFrame->Quit(); } void FloatWin::vLockCallback(GtkWidget *widget, FloatWin *oFloatWin) { - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "buttonactive.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/buttonactive.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"buttonactive.wav").c_str()); + conf->set_lock(!conf->get_lock()); } diff -bBurN stardict-cur-accepted/src/lib.cpp stardict/src/lib.cpp --- stardict-cur-accepted/src/lib.cpp 2005-02-01 16:44:50.139183744 +0300 +++ stardict/src/lib.cpp 2005-02-01 16:39:15.466061792 +0300 @@ -597,7 +599,7 @@ return (oLib[iLib]->LookupWithRule(pspec,aiIndexes,iLen)); } -void Libs::LoadDir(gchar *dirname, const GSList *order_list, const GSList *disable_list) +void Libs::LoadDir(const gchar *dirname, const GSList *order_list, const GSList *disable_list) { GDir *dir = g_dir_open(dirname, 0, NULL); if (dir) @@ -656,7 +658,7 @@ } } -void Libs::Load(const GSList *order_list, const GSList *disable_list) +void Libs::Load(const gchar *dicts_dir, const GSList *order_list, const GSList *disable_list) { gchar *idxfilename; @@ -690,16 +692,12 @@ } } -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "dic", NULL); - LoadDir(filename, order_list, disable_list); - g_free(filename); -#else +#ifndef _WIN32 gchar home_dir[256]; sprintf(home_dir, "%s/.stardict/dic", g_get_home_dir()); LoadDir(home_dir, order_list, disable_list); - LoadDir(STARDICT_DATA_DIR "/dic", order_list, disable_list); #endif + LoadDir(dicts_dir, order_list, disable_list); } gchar * @@ -1349,7 +1347,7 @@ } } -GtkTreeStore* TreeDicts::Load(const GSList *order_list, const GSList *disable_list) +GtkTreeStore* TreeDicts::Load(const gchar *tree_dicts_dir, const GSList *order_list, const GSList *disable_list) { GtkTreeStore *model = gtk_tree_store_new (3, G_TYPE_STRING, G_TYPE_LONG, G_TYPE_LONG); //word, offset, size @@ -1384,21 +1382,16 @@ } } -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "treedict", NULL); - LoadDir(filename, order_list, disable_list, model); - g_free(filename); -#else +#ifndef _WIN32 gchar home_dir[256]; sprintf(home_dir, "%s/.stardict/treedict", g_get_home_dir()); LoadDir(home_dir, order_list, disable_list, model); - LoadDir(STARDICT_DATA_DIR "/treedict", order_list, disable_list, model); #endif - + LoadDir(tree_dicts_dir, order_list, disable_list, model); return model; } -void TreeDicts::LoadDir(gchar *dirname, const GSList *order_list, const GSList *disable_list, GtkTreeStore *model) +void TreeDicts::LoadDir(const gchar *dirname, const GSList *order_list, const GSList *disable_list, GtkTreeStore *model) { GDir *dir = g_dir_open(dirname, 0, NULL); if (dir) diff -bBurN stardict-cur-accepted/src/lib.h stardict/src/lib.h --- stardict-cur-accepted/src/lib.h 2005-02-01 16:44:50.139183744 +0300 +++ stardict/src/lib.h 2005-01-28 22:18:36.000000000 +0300 @@ -5,10 +5,11 @@ # include "config.h" #endif -#include "dictziplib.h" - #include #include +#include + +#include "dictziplib.h" struct cacheItem @@ -81,17 +82,16 @@ }; //============================================================================ -class Libs -{ +class Libs { private: Lib **oLib; // word library. gint libcount; - void LoadDir(gchar *dirname, const GSList *order_list, const GSList *disable_list); + void LoadDir(const gchar *dirname, const GSList *order_list, const GSList *disable_list); public: Libs(); ~Libs(); - void Load(const GSList *order_list, const GSList *disable_list); + void Load(const gchar *dicts_dir, const GSList *order_list, const GSList *disable_list); glong iLength(int iLib); gchar* GetBookname(int iLib); inline gint total_libs() { return(libcount); } @@ -117,18 +117,17 @@ gboolean load(const char *ifofilename, GtkTreeStore *model); }; -class TreeDicts -{ +class TreeDicts { public: TreeDicts(); ~TreeDicts(); - GtkTreeStore* Load(const GSList *order_list, const GSList *disable_list); + GtkTreeStore* Load(const gchar *tree_dicts_dir, const GSList *order_list, const GSList *disable_list); gchar * poGetWordData(glong offset, glong size, int iTreeDict); private: TreeDict **oTreeDict; gint treedictcount; - void LoadDir(gchar *dirname, const GSList *order_list, const GSList *disable_list, GtkTreeStore *model); + void LoadDir(const gchar *dirname, const GSList *order_list, const GSList *disable_list, GtkTreeStore *model); }; #endif diff -bBurN stardict-cur-accepted/src/mainwin.cpp stardict/src/mainwin.cpp --- stardict-cur-accepted/src/mainwin.cpp 2005-02-01 16:44:50.142183288 +0300 +++ stardict/src/mainwin.cpp 2005-02-01 16:31:24.280692856 +0300 @@ -16,6 +16,7 @@ #include "stardict.h" #include "conf.h" +#include "utils.h" #include "mainwin.h" @@ -207,15 +208,9 @@ void TopWin::ClearCallback(GtkWidget *widget, TopWin *oTopWin) { - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "buttonactive.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/buttonactive.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"buttonactive.wav").c_str()); + oTopWin->InsertHisList(oTopWin->GetText()); oTopWin->InsertBackList(); oTopWin->SetText(""); @@ -224,15 +219,9 @@ void TopWin::GoCallback(GtkWidget *widget, TopWin *oTopWin) { - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "buttonactive.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/buttonactive.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"buttonactive.wav").c_str()); + const gchar *text = oTopWin->GetText(); if (text[0]=='\0') return; @@ -276,15 +265,9 @@ void TopWin::BackCallback(GtkWidget *widget, TopWin *oTopWin) { - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "buttonactive.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/buttonactive.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"buttonactive.wav").c_str()); + oTopWin->do_back(); } @@ -348,15 +331,9 @@ void TopWin::PreviousCallback(GtkWidget *widget, TopWin *oTopWin) { - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "buttonactive.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/buttonactive.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"buttonactive.wav").c_str()); + oTopWin->do_previous(); } @@ -428,15 +405,9 @@ void TopWin::NextCallback(GtkWidget *widget, TopWin *oTopWin) { - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "buttonactive.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/buttonactive.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"buttonactive.wav").c_str()); + oTopWin->do_next(); } @@ -452,22 +423,12 @@ void TopWin::on_main_menu_newversion_activate(GtkMenuItem *menuitem, TopWin *oTopWin) { -#ifdef _WIN32 - ShellExecute((HWND)(GDK_WINDOW_HWND(gpAppFrame->oAppCore.window->window)), "OPEN", "http://stardict.sourceforge.net", NULL, NULL, SW_SHOWNORMAL); -#else - gnome_url_show("http://stardict.sourceforge.net", NULL); -#endif + show_url("http://stardict.sourceforge.net"); } void TopWin::on_main_menu_help_activate(GtkMenuItem *menuitem, TopWin *oTopWin) { -#ifdef _WIN32 - gchar *filename = g_strdup_printf(_("file:///%s/help/C/stardict.html"), stardict_data_dir); - ShellExecute((HWND)(GDK_WINDOW_HWND(gpAppFrame->oAppCore.window->window)), "OPEN", filename, NULL, NULL, SW_SHOWNORMAL); - g_free(filename); -#else - gnome_help_display ("stardict.xml", NULL, NULL); -#endif + show_help(NULL); } void TopWin::on_main_menu_about_activate(GtkMenuItem *menuitem, TopWin *oTopWin) @@ -510,15 +471,9 @@ void TopWin::do_menu() { - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "menushow.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/menushow.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"menushow.wav").c_str()); + if (!MainMenu) { MainMenu = gtk_menu_new(); @@ -855,7 +810,8 @@ void TreeWin::Create(GtkWidget *notebook) { - GtkTreeStore *model = gpAppFrame->oAppCore.oTreeDicts.Load(conf->get_treedict_order_list(), + GtkTreeStore *model = gpAppFrame->oAppCore.oTreeDicts.Load((gStarDictDataDir+G_DIR_SEPARATOR+"treedict").c_str(), + conf->get_treedict_order_list(), conf->get_treedict_disable_list()); treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL(model)); gtk_widget_show(treeview); @@ -1736,29 +1692,17 @@ void BottomWin::AboutCallback(GtkButton *button, gpointer data) { - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "buttonactive.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/buttonactive.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"buttonactive.wav").c_str()); + gpAppFrame->oAppCore.oMidWin.oTextWin.ShowInfo(); } void BottomWin::QuitCallback(GtkButton *button, gpointer data) { - if (conf->get_enable_sound_event()) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "buttonactive.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/buttonactive.wav"); -#endif - } + if (conf->get_enable_sound_event()) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"buttonactive.wav").c_str()); + gpAppFrame->Quit(); } @@ -1808,22 +1752,12 @@ const gchar *text; text = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(gpAppFrame->oAppCore.oTopWin.WordCombo)->entry)); if (text[0]) { - gchar *url; - url = g_strdup_printf(website_searchlink+1,text); -#ifdef _WIN32 - ShellExecute((HWND)(GDK_WINDOW_HWND(gpAppFrame->oAppCore.window->window)), "OPEN", url, NULL, NULL, SW_SHOWNORMAL); -#else - gnome_url_show(url, NULL); -#endif + gchar *url = g_strdup_printf(website_searchlink+1,text); + show_url(url); g_free(url); - } - else { -#ifdef _WIN32 - ShellExecute((HWND)(GDK_WINDOW_HWND(gpAppFrame->oAppCore.window->window)), "OPEN", website_link+1, NULL, NULL, SW_SHOWNORMAL); -#else - gnome_url_show(website_link+1, NULL); -#endif - } + } else + show_url(website_link+1); + *website_link = '\t'; *website_searchlink = '\t'; } @@ -1846,33 +1780,19 @@ const gchar *text; text = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(gpAppFrame->oAppCore.oTopWin.WordCombo)->entry)); if (text[0]) { - gchar *url; - url = g_strdup_printf(website_searchlink+1,text); -#ifdef _WIN32 - ShellExecute((HWND)(GDK_WINDOW_HWND(gpAppFrame->oAppCore.window->window)), "OPEN", url, NULL, NULL, SW_SHOWNORMAL); -#else - gnome_url_show(url, NULL); -#endif + gchar *url = g_strdup_printf(website_searchlink+1, text); + show_url(url); g_free(url); - } - else { -#ifdef _WIN32 - ShellExecute((HWND)(GDK_WINDOW_HWND(gpAppFrame->oAppCore.window->window)), "OPEN", website_link+1, NULL, NULL, SW_SHOWNORMAL); -#else - gnome_url_show(website_link+1, NULL); -#endif - } + } else + show_url(website_link+1); + *website_link = '\t'; *website_searchlink = '\t'; } void BottomWin::NewVersionCallback(GtkButton *button, BottomWin *oBottomWin) { -#ifdef _WIN32 - ShellExecute((HWND)(GDK_WINDOW_HWND(gpAppFrame->oAppCore.window->window)), "OPEN", "http://stardict.sourceforge.net", NULL, NULL, SW_SHOWNORMAL); -#else - gnome_url_show("http://stardict.sourceforge.net", NULL); -#endif + show_url("http://stardict.sourceforge.net"); } void BottomWin::DictManageCallback(GtkButton *button, BottomWin *oBottomWin) diff -bBurN stardict-cur-accepted/src/Makefile.am stardict/src/Makefile.am --- stardict-cur-accepted/src/Makefile.am 2004-10-19 07:00:03.000000000 +0400 +++ stardict/src/Makefile.am 2005-01-27 20:38:10.000000000 +0300 @@ -42,7 +42,8 @@ distance.cpp distance.h \ splash.cpp splash.h \ dictziplib.c dictziplib.h \ - lib.cpp lib.h + lib.cpp lib.h \ + utils.cpp utils.h $(IDL_SOURCES): $(IDL_FILE) diff -bBurN stardict-cur-accepted/src/prefsdlg.cpp stardict/src/prefsdlg.cpp --- stardict-cur-accepted/src/prefsdlg.cpp 2005-02-01 16:44:50.144182984 +0300 +++ stardict/src/prefsdlg.cpp 2005-01-27 22:14:07.000000000 +0300 @@ -9,6 +9,7 @@ #include "stardict.h" #include "conf.h" +#include "utils.h" #include "prefsdlg.h" @@ -91,17 +92,8 @@ { switch (res_id) { case GTK_RESPONSE_HELP: - { -#ifdef _WIN32 - //gchar *filename = g_strdup_printf(_("file:///%s/help/C/stardict.html#stardict-prefs"), stardict_data_dir); - gchar *filename = g_strdup_printf(_("file:///%s/help/C/stardict.html"), stardict_data_dir); - ShellExecute((HWND)(GDK_WINDOW_HWND(gpAppFrame->oAppCore.window->window)), "OPEN", filename, NULL, NULL, SW_SHOWNORMAL); - g_free(filename); -#else - gnome_help_display ("stardict.xml", "stardict-prefs", NULL); -#endif + show_help("stardict-prefs"); break; - } default: oPrefsDlg->Close(); } diff -bBurN stardict-cur-accepted/src/skin.cpp stardict/src/skin.cpp --- stardict-cur-accepted/src/skin.cpp 2003-09-23 17:54:54.000000000 +0400 +++ stardict/src/skin.cpp 2005-02-01 16:32:15.239945872 +0300 @@ -1,11 +1,14 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include "skin.h" -#include -#include + +#include +#include #include "stardict.h" +#include "conf.h" + +#include "skin.h" _Skin_cursor::_Skin_cursor() { @@ -41,27 +44,24 @@ { stardict.normal_cursor.cursor=(GdkCursor *)NULL; // NULL is the default cursor. stardict.watch_cursor.cursor= gdk_cursor_new(GDK_WATCH); - + std::string pixmaps_dir(gStarDictDataDir+G_DIR_SEPARATOR+"pixmaps"+G_DIR_SEPARATOR); + std::string filename; #ifdef _WIN32 - gchar *filename; - filename = g_build_filename(stardict_data_dir, "pixmaps", "stardict.png", NULL); - stardict.icon.p[0] = gdk_pixbuf_new_from_file (filename, NULL); - g_free(filename); - filename = g_build_filename(stardict_data_dir, "pixmaps", "about_menu.png", NULL); - stardict.about_menu.p[0] = gdk_pixbuf_new_from_file (filename, NULL); - g_free(filename); - filename = g_build_filename(stardict_data_dir, "pixmaps", "index_wazard.png", NULL); - stardict.index_wazard.p[0] = gdk_pixbuf_new_from_file (filename, NULL); - g_free(filename); - filename = g_build_filename(stardict_data_dir, "pixmaps", "index_appendix.png", NULL); - stardict.index_appendix.p[0] = gdk_pixbuf_new_from_file (filename, NULL); - g_free(filename); + filename=pixmaps_dir+"stardict.png"; + stardict.icon.p[0] = gdk_pixbuf_new_from_file(filename.c_str(), NULL); + filename=pixmaps_dir+"about_menu.png"; + stardict.about_menu.p[0] = gdk_pixbuf_new_from_file(filename.c_str(), NULL); #else - stardict.icon.p[0] = gdk_pixbuf_new_from_file (GNOME_ICONDIR "/stardict.png", NULL); - stardict.docklet_normal_icon.p[0] = gdk_pixbuf_new_from_file (STARDICT_DATA_DIR "/pixmaps/docklet_normal.png", NULL); - stardict.docklet_scan_icon.p[0] = gdk_pixbuf_new_from_file (STARDICT_DATA_DIR "/pixmaps/docklet_scan.png", NULL); - stardict.docklet_stop_icon.p[0] = gdk_pixbuf_new_from_file (STARDICT_DATA_DIR "/pixmaps/docklet_stop.png", NULL); - stardict.index_wazard.p[0] = gdk_pixbuf_new_from_file (STARDICT_DATA_DIR "/pixmaps/index_wazard.png", NULL); - stardict.index_appendix.p[0] = gdk_pixbuf_new_from_file (STARDICT_DATA_DIR "/pixmaps/index_appendix.png", NULL); + stardict.icon.p[0] = gdk_pixbuf_new_from_file(GNOME_ICONDIR"/stardict.png", NULL); + filename=pixmaps_dir+"docklet_normal.png"; + stardict.docklet_normal_icon.p[0] = gdk_pixbuf_new_from_file(filename.c_str(), NULL); + filename=pixmaps_dir+"docklet_scan.png"; + stardict.docklet_scan_icon.p[0] = gdk_pixbuf_new_from_file(filename.c_str(), NULL); + filename=pixmaps_dir+"docklet_stop.png"; + stardict.docklet_stop_icon.p[0] = gdk_pixbuf_new_from_file(filename.c_str(), NULL); #endif + filename=pixmaps_dir+"index_wazard.png"; + stardict.index_wazard.p[0] = gdk_pixbuf_new_from_file(filename.c_str(), NULL); + filename=pixmaps_dir+"index_appendix.png"; + stardict.index_appendix.p[0] = gdk_pixbuf_new_from_file(filename.c_str(), NULL); } diff -bBurN stardict-cur-accepted/src/splash.cpp stardict/src/splash.cpp --- stardict-cur-accepted/src/splash.cpp 2003-09-23 14:19:48.000000000 +0400 +++ stardict/src/splash.cpp 2005-02-01 16:38:00.712426072 +0300 @@ -2,9 +2,6 @@ # include "config.h" #endif -#include "splash.h" -#include "stardict.h" - #include #ifndef _WIN32 # include @@ -14,6 +11,11 @@ # include "win32/intl.h" #endif +#include "stardict.h" +#include "conf.h" + +#include "splash.h" + // this is the callback which will destroy the splash screen window. static void @@ -26,13 +28,8 @@ { gtk_window_set_auto_startup_notification(false); -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "pixmaps", "splash.png", NULL); - GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(filename, NULL); - g_free(filename); -#else - GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(STARDICT_DATA_DIR "/pixmaps/splash.png", NULL); -#endif + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file((gStarDictDataDir+G_DIR_SEPARATOR+"pixmaps"+G_DIR_SEPARATOR+"splash.png").c_str(), NULL); + gint w = gdk_pixbuf_get_width(pixbuf); gint h = gdk_pixbuf_get_height(pixbuf); diff -bBurN stardict-cur-accepted/src/stardict.cpp stardict/src/stardict.cpp --- stardict-cur-accepted/src/stardict.cpp 2005-02-01 16:44:50.147182528 +0300 +++ stardict/src/stardict.cpp 2005-02-01 16:07:41.836937176 +0300 @@ -50,10 +50,10 @@ #include #include HINSTANCE stardictexe_hInstance; - gchar stardict_data_dir[256]; #endif #include "conf.h" +#include "utils.h" #include "stardict.h" @@ -102,7 +102,7 @@ void AppCore::Create(gchar *queryword) { - oLibs.Load(conf->get_dict_order_list(), conf->get_dict_disable_list()); + oLibs.Load((gStarDictDataDir+G_DIR_SEPARATOR+"dic").c_str(), conf->get_dict_order_list(), conf->get_dict_disable_list()); iCurrentIndex = (glong*)g_malloc0(sizeof(glong) * oLibs.total_libs()); gboolean use_custom_font=conf->get_use_custom_font(); @@ -274,15 +274,8 @@ } } else if (event->keyval==GDK_F1) { - if (event->type==GDK_KEY_PRESS) { -#ifdef _WIN32 - gchar *filename = g_strdup_printf(_("file:///%s/help/C/stardict.html"), stardict_data_dir); - ShellExecute((HWND)(GDK_WINDOW_HWND(gpAppFrame->oAppCore.window->window)), "OPEN", filename, NULL, NULL, SW_SHOWNORMAL); - g_free(filename); -#else - gnome_help_display ("stardict.xml", NULL, NULL); -#endif - } + if (event->type==GDK_KEY_PRESS) + show_help(NULL); } else if ((event->keyval==GDK_f || event->keyval==GDK_F) && only_ctrl_pressed) { if (event->type==GDK_KEY_PRESS) @@ -1309,15 +1302,10 @@ gboolean stardict_on_enter_notify (GtkWidget * widget, GdkEventCrossing * event, gpointer data) { - if (conf->get_enable_sound_event() && event->mode == GDK_CROSSING_NORMAL) { -#ifdef _WIN32 - gchar *filename = g_build_filename(stardict_data_dir, "sounds", "buttonactive.wav", NULL); - PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); - g_free(filename); -#else - gnome_sound_play(STARDICT_DATA_DIR "/sounds/buttonactive.wav"); -#endif - } + if (conf->get_enable_sound_event() && + event->mode == GDK_CROSSING_NORMAL) + play_wav_file((gStarDictDataDir+G_DIR_SEPARATOR+"sounds"+G_DIR_SEPARATOR+"buttonactive.wav").c_str()); + return false; } @@ -1419,23 +1407,6 @@ gpointer user_data) { return; } - -static gboolean set_stardict_data_dir(void) { - HMODULE hmod; - - hmod = GetModuleHandle(NULL); - if( hmod == 0 ) { - return true; - } - if(GetModuleFileName( hmod, (char*)&stardict_data_dir, 256 ) == 0) { - return true; - } - gchar* buf; - buf = g_path_get_dirname( stardict_data_dir ); - strcpy( (char*)&stardict_data_dir, buf ); - g_free( buf ); - return false; -} #endif #ifdef _WIN32 @@ -1444,13 +1415,25 @@ int main(int argc,char **argv) #endif { + //set gStarDictDataDir; #ifdef _WIN32 - if (set_stardict_data_dir()) - return EXIT_SUCCESS; - gchar *locale_dir; - locale_dir = g_strdup_printf("%s" G_DIR_SEPARATOR_S "locale", stardict_data_dir); - bindtextdomain (GETTEXT_PACKAGE, locale_dir); - g_free(locale_dir); + HMODULE hmod; + + if ((hmod = GetModuleHandle(NULL))==0) + return EXIT_FAILURE; + char tmp_buf[256]; + if (GetModuleFileName(hmod, tmp_buf, sizeof(tmp_buf))==0) + return EIXT_FAILURE; + + gchar* buf = g_path_get_dirname(tmp_buf); + gStarDictDataDir=buf; + g_free(buf); +#else + gStarDictDataDir=STARDICT_DATA_DIR; +#endif + +#ifdef _WIN32 + bindtextdomain (GETTEXT_PACKAGE, (gStarDictDataDir+G_DIR_SEPARATOR_S+"locale").c_str()); #else bindtextdomain (GETTEXT_PACKAGE, STARDICT_LOCALEDIR); #endif @@ -1471,19 +1454,19 @@ gtk_set_locale (); gtk_init (&argc, &argv); - g_log_set_handler (NULL, (enum GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), + g_log_set_handler (NULL, (GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), stardict_dummy_log_handler, NULL); - g_log_set_handler ("Gdk", (enum GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), + g_log_set_handler ("Gdk", (GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), stardict_dummy_log_handler, NULL); - g_log_set_handler ("Gtk", (enum GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), + g_log_set_handler ("Gtk", (GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), stardict_dummy_log_handler, NULL); - g_log_set_handler ("GLib", (enum GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), + g_log_set_handler ("GLib", (GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), stardict_dummy_log_handler, NULL); - g_log_set_handler ("GModule", (enum GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), + g_log_set_handler ("GModule", (GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), stardict_dummy_log_handler, NULL); - g_log_set_handler ("GLib-GObject", (enum GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), + g_log_set_handler ("GLib-GObject", (GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), stardict_dummy_log_handler, NULL); - g_log_set_handler ("GThread", (enum GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), + g_log_set_handler ("GThread", (GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION), stardict_dummy_log_handler, NULL); g_set_print_handler( stardict_dummy_print ); @@ -1494,13 +1477,11 @@ if (strcmp(argv[i], "-h") == 0) { hide_option = TRUE; } - } - else { + } else { if (!queryword) { if (g_utf8_validate (argv[i], -1, NULL)) { queryword= g_strdup(argv[i]); - } - else + } else queryword = g_locale_to_utf8(argv[i],-1,NULL,NULL,NULL); } } diff -bBurN stardict-cur-accepted/src/utils.cpp stardict/src/utils.cpp --- stardict-cur-accepted/src/utils.cpp 1970-01-01 03:00:00.000000000 +0300 +++ stardict/src/utils.cpp 2005-02-01 17:03:39.904433320 +0300 @@ -0,0 +1,56 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include + +#if !defined(_WIN32) && !defined(WITHOUT_GNOME) +# include +# include +#elif defined(_WIN32) +# include +#endif + +#include "conf.h" +#include "stardict.h" + +#include "utils.h" + +void play_wav_file(const gchar *filename) +{ +#ifdef _WIN32 + PlaySound(filename, 0, SND_ASYNC | SND_FILENAME); +#elif !defined(WITHOUT_GNOME) + gnome_sound_play(filename); +#else + gchar *wavname=g_strdup(filename); + gchar *argv[]={"play", wavname, NULL}; + if (!g_spawn_async(NULL, argv, NULL, + GSpawnFlags(G_SPAWN_SEARCH_PATH|G_SPAWN_STDOUT_TO_DEV_NULL|G_SPAWN_STDERR_TO_DEV_NULL), + NULL, NULL, NULL, NULL)) + g_message("g_spawn_async failes!\n"); + + g_free(wavname); +#endif +} + +void show_help(const gchar *section) +{ +#ifdef _WIN32 + gchar *filename = g_strdup_printf(_("file:///%s/help/C/stardict.html"), gStarDictDataDir.c_str()); + ShellExecute((HWND)(GDK_WINDOW_HWND(gpAppFrame->oAppCore.window->window)), "OPEN", filename, NULL, NULL, SW_SHOWNORMAL); + g_free(filename); +#elif !defined(WITHOUT_GNOME) + gnome_help_display ("stardict.xml", section, NULL); +#endif +} + +void show_url(const gchar *url) +{ +#ifdef _WIN32 + ShellExecute((HWND)(GDK_WINDOW_HWND(gpAppFrame->oAppCore.window->window)), "OPEN", url, NULL, NULL, SW_SHOWNORMAL); +#elif !defined(WITHOUT_GNOME) + gnome_url_show(url, NULL); +#endif +} diff -bBurN stardict-cur-accepted/src/utils.h stardict/src/utils.h --- stardict-cur-accepted/src/utils.h 1970-01-01 03:00:00.000000000 +0300 +++ stardict/src/utils.h 2005-01-27 22:15:59.000000000 +0300 @@ -0,0 +1,8 @@ +#ifndef UTILS_H +#define UTILS_H + +extern void play_wav_file(const gchar *filename); +extern void show_help(const gchar *section); +extern void show_url(const gchar *url); + +#endif/*UTILS_H*/ diff -bBurN stardict-cur-accepted/src/win32/configfile.cpp stardict/src/win32/configfile.cpp --- stardict-cur-accepted/src/win32/configfile.cpp 2003-09-23 14:09:55.000000000 +0400 +++ stardict/src/win32/configfile.cpp 1970-01-01 03:00:00.000000000 +0300 @@ -1,343 +0,0 @@ -/* -this file is copy form x11amp,i changed it for some place. -这个文件是我从x11amp(现在叫xmms)拷来的,增删了几个函数. -*/ - -#include -#include -#include -#include -#include -#include "configfile.h" - -#include - -static ConfigSection *rw_cfg_create_section (ConfigFile * cfg, gchar * name); -static ConfigLine *rw_cfg_create_string (ConfigSection * section, gchar * key, - const gchar * value); -static ConfigSection *rw_cfg_find_section (ConfigFile * cfg, gchar * name); -static ConfigLine *rw_cfg_find_string (ConfigSection * section, gchar * key); - -ConfigFile * -rw_cfg_open_file (gchar * filename) -{ - ConfigFile *cfg; - - FILE *file; - gchar *buffer, **lines, *tmp; - gint i; - struct stat stats; - ConfigSection *section = NULL; - - if (stat (filename, &stats) == -1) - return NULL; - if (!(file = fopen (filename, "rb"))) - return NULL; - - buffer = (gchar *)g_malloc (stats.st_size + 1); - fread (buffer, 1, stats.st_size, file); -/* if (fread (buffer, 1, stats.st_size, file) != stats.st_size) - { - g_free (buffer); - fclose (file); - return NULL; - } -*/ - fclose (file); - buffer[stats.st_size] = '\0'; - - cfg = (ConfigFile *)g_malloc0 (sizeof (ConfigFile)); - cfg->cfgfilename = g_strdup (filename); - cfg->changed = 0; - lines = g_strsplit (buffer, "\n", 0); - g_free (buffer); - i = 0; - while (lines[i]) - { - if (lines[i][0] == '[') - { - if ((tmp = strchr (lines[i], ']'))) - { - *tmp = '\0'; - section = - rw_cfg_create_section (cfg, - &lines[i][1]); - } - } - else if (lines[i][0] != '#' && section) - { - if ((tmp = strchr (lines[i], '='))) - { - *tmp = '\0'; - tmp++; - rw_cfg_create_string (section, lines[i], tmp); - } - } - i++; - } - g_strfreev (lines); - return cfg; -} - - -gboolean -rw_cfg_write_file (ConfigFile * cfg, gchar * filename) -{ - FILE *file; - GList *section_list, *line_list; - ConfigSection *section; - ConfigLine *line; - - if (!(file = fopen (filename, "wb"))) - return FALSE; - - section_list = cfg->sections; - while (section_list) - { - section = (ConfigSection *) section_list->data; - if (section->lines) - { - fprintf (file, "[%s]\n", section->name); - line_list = section->lines; - while (line_list) - { - line = (ConfigLine *) line_list->data; - fprintf (file, "%s=%s\n", line->key, - line->value); - line_list = g_list_next (line_list); - } - fprintf (file, "\n"); - } - section_list = g_list_next (section_list); - } - fclose (file); - return TRUE; -} - -gboolean -rw_cfg_read_string (ConfigFile * cfg, gchar * section, gchar * key, - gchar ** value) -{ - ConfigSection *sect; - ConfigLine *line; - - *value = NULL; - if (!(sect = rw_cfg_find_section (cfg, section))) - return FALSE; - if (!(line = rw_cfg_find_string (sect, key))) - return FALSE; - *value = g_strdup (line->value); - return TRUE; -} - -gboolean -rw_cfg_read_int (ConfigFile * cfg, gchar * section, gchar * key, gint * value) -{ - gchar *str; - - if (!rw_cfg_read_string (cfg, section, key, &str)) - { - *value = 0; - return FALSE; - } - *value = atoi (str); - g_free (str); - - return TRUE; -} - -gboolean -rw_cfg_read_boolean (ConfigFile * cfg, gchar * section, gchar * key, - gboolean * value) -{ - gchar *str; - - if (!rw_cfg_read_string (cfg, section, key, &str)) - { - *value = FALSE; - return FALSE; - } - if (!strcmp (str, "0")) - *value = FALSE; - else - *value = TRUE; - g_free (str); - return TRUE; -} - -const char STRING_SEP = (const char) 0xff; - -static GSList * str_to_list(gchar *str) -{ - GSList *list = NULL; - gchar *p; - while ((p = strchr(str, STRING_SEP))!=NULL) { - list = g_slist_append(list, g_strndup(str, p - str)); - str = p+1; - } - if (str[0]) - list = g_slist_append(list, g_strdup(str)); - return list; -} - -gboolean -rw_cfg_read_strlist (ConfigFile * cfg, gchar * section, gchar * key, - GSList ** list) -{ - gchar *str; - - if (!rw_cfg_read_string (cfg, section, key, &str)) - { - *list = NULL; - return FALSE; - } - *list = str_to_list(str); - g_free (str); - return TRUE; -} - -void -rw_cfg_write_string (ConfigFile * cfg, gchar * section, gchar * key, - const gchar * value) -{ - ConfigSection *sect; - ConfigLine *line; - - cfg->changed = 1; - sect = rw_cfg_find_section (cfg, section); - if (!sect) - sect = rw_cfg_create_section (cfg, section); - if ((line = rw_cfg_find_string (sect, key))) - { - g_free (line->value); - line->value = g_strchug (g_strchomp (g_strdup (value))); - } - else - rw_cfg_create_string (sect, key, value); -} - -void -rw_cfg_write_int (ConfigFile * cfg, gchar * section, gchar * key, gint value) -{ - gchar *strvalue; - strvalue = g_strdup_printf ("%d", value); - rw_cfg_write_string (cfg, section, key, strvalue); - g_free (strvalue); -} - -void -rw_cfg_write_boolean (ConfigFile * cfg, gchar * section, gchar * key, - gboolean value) -{ - if (value) - rw_cfg_write_string (cfg, section, key, "1"); - else - rw_cfg_write_string (cfg, section, key, "0"); -} - -void -rw_cfg_write_strlist (ConfigFile * cfg, gchar * section, gchar * key, - GSList * list) -{ - std::string string; - if (list) { - string += (gchar *)(list->data); - list = list->next; - } - while (list) { - string += STRING_SEP; - string += (gchar *)(list->data); - list = list->next; - } - rw_cfg_write_string (cfg, section, key, string.c_str()); -} - -void -rw_cfg_free (ConfigFile * cfg) -{ - ConfigSection *section; - ConfigLine *line; - GList *section_list, *line_list; - - g_free (cfg->cfgfilename); - section_list = cfg->sections; - while (section_list) - { - section = (ConfigSection *) section_list->data; - g_free (section->name); - - line_list = section->lines; - while (line_list) - { - line = (ConfigLine *) line_list->data; - g_free (line->key); - g_free (line->value); - g_free (line); - line_list = g_list_next (line_list); - } - g_list_free (section->lines); - g_free (section); - - section_list = g_list_next (section_list); - } - g_list_free (cfg->sections); - cfg->sections = NULL; /*这两行我加的,rw_cfg_free后可回到rw_cfg_new状态,可继续使用. */ - cfg->cfgfilename = NULL; -} - -static ConfigSection * -rw_cfg_create_section (ConfigFile * cfg, gchar * name) -{ - ConfigSection *section; - section = (ConfigSection *)g_malloc0 (sizeof (ConfigSection)); - section->name = g_strdup (name); - cfg->sections = g_list_append (cfg->sections, section); - - return section; -} - -static ConfigLine * -rw_cfg_create_string (ConfigSection * section, gchar * key, const gchar * value) -{ - ConfigLine *line; - line = (ConfigLine *)g_malloc0 (sizeof (ConfigLine)); - line->key = g_strchug (g_strchomp (g_strdup (key))); - line->value = g_strchug (g_strchomp (g_strdup (value))); - section->lines = g_list_append (section->lines, line); - - return line; -} - -static ConfigSection * -rw_cfg_find_section (ConfigFile * cfg, gchar * name) -{ - ConfigSection *section; - GList *list; - - list = cfg->sections; - while (list) - { - section = (ConfigSection *) list->data; - if (!strcasecmp (section->name, name)) - return section; - list = g_list_next (list); - } - return NULL; -} - -static ConfigLine * -rw_cfg_find_string (ConfigSection * section, gchar * key) -{ - ConfigLine *line; - GList *list; - - list = section->lines; - while (list) - { - line = (ConfigLine *) list->data; - if (!strcasecmp (line->key, key)) - return line; - list = g_list_next (list); - } - return NULL; -} diff -bBurN stardict-cur-accepted/src/win32/configfile.h stardict/src/win32/configfile.h --- stardict-cur-accepted/src/win32/configfile.h 2003-09-23 14:09:53.000000000 +0400 +++ stardict/src/win32/configfile.h 1970-01-01 03:00:00.000000000 +0300 @@ -1,52 +0,0 @@ -#ifndef __RW_CONFIGFILE_H__ -#define __RW_CONFIGFILE_H__ - -#include -#include - - - typedef struct - { - gchar *key; - gchar *value; - } - ConfigLine; - - typedef struct - { - gchar *name; - GList *lines; - } - ConfigSection; - - - typedef struct - { - GList *sections; - gchar *cfgfilename; - gboolean changed; - } - ConfigFile; - - ConfigFile *rw_cfg_open_file (gchar * filename); - gboolean rw_cfg_write_file (ConfigFile * cfg, gchar * filename); - void rw_cfg_free (ConfigFile * cfg); - - gboolean rw_cfg_read_string (ConfigFile * cfg, gchar * section, - gchar * key, gchar ** value); - gboolean rw_cfg_read_int (ConfigFile * cfg, gchar * section, - gchar * key, gint * value); - gboolean rw_cfg_read_boolean (ConfigFile * cfg, gchar * section, - gchar * key, gboolean * value); - gboolean rw_cfg_read_strlist (ConfigFile * cfg, gchar * section, - gchar * key, GSList ** list); - void rw_cfg_write_string (ConfigFile * cfg, gchar * section, - gchar * key, const gchar * value); - void rw_cfg_write_int (ConfigFile * cfg, gchar * section, gchar * key, - gint value); - void rw_cfg_write_boolean (ConfigFile * cfg, gchar * section, - gchar * key, gboolean value); - void rw_cfg_write_strlist (ConfigFile * cfg, gchar * section, - gchar * key, GSList * list); - -#endif diff -bBurN stardict-cur-accepted/src/win32/Makefile.am stardict/src/win32/Makefile.am --- stardict-cur-accepted/src/win32/Makefile.am 2003-11-13 13:24:54.000000000 +0300 +++ stardict/src/win32/Makefile.am 2005-01-27 22:55:20.000000000 +0300 @@ -1,7 +1,7 @@ SUBDIRS = nsis -EXTRA_DIST = configfile.cpp configfile.h intl.h MinimizeToTray.cpp \ +EXTRA_DIST = intl.h MinimizeToTray.cpp \ MinimizeToTray.h resource.h stardictrc.rc StdAfx.h systray.cpp \ systray.h systray-normal.ico systray-scan.ico systray-stop.ico \ - winconf.cpp winconf.h gnome-about.c gnome-about.h about_menu.png \ + gnome-about.c gnome-about.h about_menu.png \ clipboard.cpp clipboard.h diff -bBurN stardict-cur-accepted/src/win32/winconf.cpp stardict/src/win32/winconf.cpp --- stardict-cur-accepted/src/win32/winconf.cpp 2003-11-30 06:13:25.000000000 +0300 +++ stardict/src/win32/winconf.cpp 1970-01-01 03:00:00.000000000 +0300 @@ -1,168 +0,0 @@ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "winconf.h" -#include "../stardict.h" -#include "intl.h" - -#include -#include -#include - -// Notice: once you changed this file, try to change src/conf.cpp too. - -ConfigFile *usercfgfile; - -void init_conf() -{ - struct stat st; - gchar *filename = g_build_filename(stardict_data_dir, "stardict.cfg", NULL); - if (stat (filename, &st)) - { - FILE *file; - if ((file = fopen (filename, "wb")) == NULL) { - g_free(filename); - return; - } - fprintf (file, "[preferences/dictionary]\n" - "scan_selection=1\n" - "only_scan_while_modifier_key=0\n" - "hide_floatwin_when_modifier_key_released=1\n" - "scan_modifier_key=0\n" - "enable_sound_event=1\n" - - ); - fprintf (file, _("use_custom_font=1\ncustom_font=sans 8\n")); - fprintf (file, "[preferences/main_window]\n" - "hide_on_startup=0\n" - "search_website_list=\n" - "maximized=0\n" - "hide_list=0\n" - ); - fprintf (file, _("window_width=551\nwindow_height=357\nhpaned_pos=165\n")); - fprintf (file, "[preferences/notification_area_icon]\n" - "query_in_floatwin=1\n" - ); - fprintf (file, "[preferences/floating_window]\n" - "pronounce_when_popup=0\n" - "max_window_width=320\n" - "max_window_height=240\n" - "lock=0\n" - "lock_x=0\n" - "lock_y=0\n" - ); - fprintf (file, "[manage_dictionaries]\n" - "dict_order_list=\n" - "dict_disable_list=\n" - "treedict_order_list=\n" - "treedict_disable_list=\n" - ); - fclose (file); - } - usercfgfile = rw_cfg_open_file (filename); - g_free(filename); -} - -void save_conf() -{ - if (usercfgfile->changed) - rw_cfg_write_file(usercfgfile,usercfgfile->cfgfilename); - rw_cfg_free (usercfgfile); - g_free (usercfgfile); -} - -void on_conf_dictionary_scan_selection_changed(gboolean scan) -{ - if (gpAppFrame->oAppCore.oSelection.bEnable == scan) - return; - gpAppFrame->oAppCore.oSelection.bEnable = scan; - gtk_widget_set_sensitive(gpAppFrame->oAppCore.oFloatWin.StopButton, scan); - if (scan != gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gpAppFrame->oAppCore.oBottomWin.ScanSelectionCheckButton))) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gpAppFrame->oAppCore.oBottomWin.ScanSelectionCheckButton),scan); - } - if (scan) { - if (!GTK_WIDGET_VISIBLE(gpAppFrame->oAppCore.window)) { - gpAppFrame->oAppCore.oDockLet.SetIcon(DOCKLET_SCAN_ICON); - } - if (gpAppFrame->oAppCore.oFloatWin.bIsLocked && (gpAppFrame->oAppCore.oFloatWin.QueryingWord.c_str())[0]!='\0') - gpAppFrame->oAppCore.oFloatWin.Show(); - } - else { - if (!GTK_WIDGET_VISIBLE(gpAppFrame->oAppCore.window)) { - gpAppFrame->oAppCore.oDockLet.SetIcon(DOCKLET_STOP_ICON); - } - gpAppFrame->oAppCore.oFloatWin.Hide(); - gpAppFrame->oAppCore.oSelection.LastClipWord.clear(); - } -} - -void on_conf_dictionary_only_scan_while_modifier_key_changed(gboolean only_scan) -{ - gpAppFrame->oAppCore.oSelection.only_scan_while_modifier_key = only_scan; -} - -void on_conf_dictionary_hide_floatwin_when_modifier_key_released_changed(gboolean hide) -{ - gpAppFrame->oAppCore.oFloatWin.hide_floatwin_when_modifier_key_released = hide; -} - -void on_conf_dictionary_scan_modifier_key_changed(gint key) -{ - gpAppFrame->oAppCore.oSelection.scan_modifier_key = key; -} - -void on_conf_dictionary_enable_sound_event_changed(gboolean enable) -{ - gpAppFrame->enable_sound_event = enable; -} - -void on_conf_main_window_searchwebsite_list_changed(GSList *list) -{ - g_slist_foreach (gpAppFrame->oAppCore.oBottomWin.searchwebsite_list, (GFunc)g_free, NULL); - g_slist_free (gpAppFrame->oAppCore.oBottomWin.searchwebsite_list); - gpAppFrame->oAppCore.oBottomWin.searchwebsite_list = list; -} - -void on_conf_main_window_hide_list_changed(gboolean hide) -{ - if (hide) { - gtk_widget_hide(gpAppFrame->oAppCore.oMidWin.oToolWin.HideListButton); - gtk_widget_show(gpAppFrame->oAppCore.oMidWin.oToolWin.ShowListButton); - gtk_widget_hide(gpAppFrame->oAppCore.oMidWin.oIndexWin.vbox); - } - else { - gtk_widget_hide(gpAppFrame->oAppCore.oMidWin.oToolWin.ShowListButton); - gtk_widget_show(gpAppFrame->oAppCore.oMidWin.oToolWin.HideListButton); - gtk_widget_show(gpAppFrame->oAppCore.oMidWin.oIndexWin.vbox); - } -} - -void on_conf_notification_area_icon_show_in_floatwin_changed(gboolean query_in_floatwin) -{ - gpAppFrame->oAppCore.oDockLet.query_in_floatwin = query_in_floatwin; -} - -void on_conf_floatwin_pronounce_when_popup_changed(gboolean pronounce_when_popup) -{ - gpAppFrame->oAppCore.oFloatWin.pronounce_when_popup = pronounce_when_popup; -} - -void on_conf_floatwin_max_window_width_changed(gint width) -{ - gpAppFrame->oAppCore.oFloatWin.Window_max_width = width; -} - -void on_conf_floatwin_max_window_height_changed(gint height) -{ - gpAppFrame->oAppCore.oFloatWin.Window_max_height = height; -} - -void on_conf_floatwin_lock_changed(gboolean lock) -{ - gpAppFrame->oAppCore.oFloatWin.bIsLocked = lock; - if (lock) - gtk_image_set_from_stock(GTK_IMAGE(gpAppFrame->oAppCore.oFloatWin.lock_image),GTK_STOCK_GOTO_LAST,GTK_ICON_SIZE_MENU); - else - gtk_image_set_from_stock(GTK_IMAGE(gpAppFrame->oAppCore.oFloatWin.lock_image),GTK_STOCK_GO_FORWARD,GTK_ICON_SIZE_MENU); -} diff -bBurN stardict-cur-accepted/src/win32/winconf.h stardict/src/win32/winconf.h --- stardict-cur-accepted/src/win32/winconf.h 2003-09-23 14:09:53.000000000 +0400 +++ stardict/src/win32/winconf.h 1970-01-01 03:00:00.000000000 +0300 @@ -1,25 +0,0 @@ -#ifndef __SD_WIN_CONF_H__ -#define __SD_WIN_CONF_H__ - -#include "configfile.h" - -extern ConfigFile *usercfgfile; - -extern void init_conf(); -extern void save_conf(); - -extern void on_conf_dictionary_scan_selection_changed(gboolean scan); -extern void on_conf_dictionary_only_scan_while_modifier_key_changed(gboolean only_scan); -extern void on_conf_dictionary_hide_floatwin_when_modifier_key_released_changed(gboolean hide); -extern void on_conf_dictionary_scan_modifier_key_changed(gint key); -extern void on_conf_dictionary_enable_sound_event_changed(gboolean enable); -extern void on_conf_main_window_searchwebsite_list_changed(GSList *list); -extern void on_conf_main_window_hide_list_changed(gboolean hide); -extern void on_conf_notification_area_icon_show_in_floatwin_changed(gboolean query_in_floatwin); -extern void on_conf_floatwin_pronounce_when_popup_changed(gboolean pronounce_when_popup); -extern void on_conf_floatwin_max_window_width_changed(gint width); -extern void on_conf_floatwin_max_window_height_changed(gint height); -extern void on_conf_floatwin_lock_changed(gboolean lock); - -#endif -