From 509559df890277771acec400a49fbc29e096f4e0 Mon Sep 17 00:00:00 2001 From: Karel Matas Date: Sun, 30 Jun 2013 17:36:19 +0200 Subject: [PATCH] added Show word as a temp. proxy for EditWord --- src/aoi.cxx | 92 ++++++++++++++++++++++++++++++++++++++------ src/aoi.hxx | 14 ++++--- src/datatypes.hxx | 108 ++++++++++++++++++++++++++++++++++++++++++---------- src/gui.cxx | 11 ++---- src/gui.hxx | 7 +++- src/gui_dialogs.cxx | 17 +++++++-- src/gui_dialogs.hxx | 27 +++++++++++-- src/main.cxx | 4 +- src/parsers.hxx | 2 +- 9 files changed, 225 insertions(+), 57 deletions(-) diff --git a/src/aoi.cxx b/src/aoi.cxx index 53e2631..a0589fc 100755 --- a/src/aoi.cxx +++ b/src/aoi.cxx @@ -64,7 +64,7 @@ App::App () #ifdef DEBUG // ui_->progress(90, "DEBUG query..." ); -// parse_dic_input("ana*"); + parse_dic_input("ana*"); // cb_kanji_search(); // ui_->cb_toggle_group(nullptr); #endif @@ -157,7 +157,7 @@ vector App::query ( const char *q, bool log_query, bool replace_separato log( "App::query(): " + msg); if ( replace_separator ) for ( string &s: result ) - utils::replace_all(s, parsers::SEPARATOR_SQL, ", "); + utils::replace_all(s, SEPARATOR_SQL, ", "); ui_->cursor_default(); return result; } @@ -328,7 +328,7 @@ void App::cb_kanji_search () ) ); components.push_back(q[i+2]); - for ( string &s: utils::split_string( q[i+3], parsers::SEPARATOR_SQL) ) + for ( string &s: utils::split_string( q[i+3], SEPARATOR_SQL) ) flags.insert(s); } @@ -436,12 +436,13 @@ void App::on_dic_selected ( int id ) log_d("App::on_dic_selected()"); } -void App::cb_edit_word ( int id ) +void App::cb_edit_word () { std::stringstream ss; + int id = ui_->dicview_selected_rowid(); ss << "App::edit_word( " << id << " )"; log_d(ss); - ui_->edit_word(); + ui_->edit_word( db_get_word(id)); } @@ -451,7 +452,7 @@ void App::cb_popup_kanji ( const string &kanji ) ss << "App::on_kanji_clicked()" << kanji; Kanji k = db_get_kanji(kanji); ui_->popup_kanji( k ); - // XXX: this should be somewhere else (it is not logical here) + // XXX: this should be somewhere else (it is ilogical here) ui_->highlight_components( k.components() ); log(ss); } @@ -557,6 +558,75 @@ void App::parse_dic_input ( const char *str ) } +DicWord App::db_get_word ( int id ) +{ + DicWord w(id); + std::stringstream ss; + +/* + ElementSense( int sid, const vector &gloss, const vector &stagk, + const vector &stagr, const vector &pos, + const vector &xref, const vector &ant, + const vector &field, const vector &misc, + const vector &dial, const vector &s_inf ) + : sid_(sid), gloss_(gloss), stagk_(stagk), stagr_(stagr), pos_(pos), + xref_(xref), ant_(ant), field_(field), misc_(misc), dial_(dial), + s_inf_(s_inf) + {} + ~ElementSense(){} + + string sql ( int did, const char *sep ){ + std::stringstream ss; + ss << "INSERT INTO d_sense (sid,did,gloss,xref,ant,inf,pos,field,misc,dial)" + << " VALUES (" << sid_ << "," << did << ",'" +*/ + // kanji + ss << "select kid,kanji,inf,freq from d_kanji where did=" << id <<";"; + vector res = query( ss.str().c_str() ); + for ( size_t i=0; i inf = utils::split_string(res[i+2],SEPARATOR_SQL); + bool freq = std::stoi(res[i+3]); + w.k_ele( ElementKanji( kid, kanji, inf, freq ) ); + } + + // reading + ss.str(""); + ss.clear(); + ss << "select rid,reading,inf,nokanji,freq from d_reading where did=" << id << ";"; + res = query( ss.str().c_str() ); + for ( size_t i=0; i inf = utils::split_string(res[i+2],SEPARATOR_SQL); + bool nokanji = std::stoi(res[i+3]); + bool freq = std::stoi(res[i+4]); + w.r_ele( ElementReading( rid, reading, nokanji, {/*restr*/}, inf, freq ) ); + } + + // sense + ss.str(""); + ss.clear(); + ss << "select sid,gloss,xref,ant,inf,pos,field,misc,dial from d_sense where did=" << id << ";"; + res = query( ss.str().c_str() ); + for ( size_t i=0; i gloss = utils::split_string(res[i+1],SEPARATOR_SQL); + vector xref = utils::split_string(res[i+2],SEPARATOR_SQL); + vector ant = utils::split_string(res[i+3],SEPARATOR_SQL); + vector inf = utils::split_string(res[i+4],SEPARATOR_SQL); + vector pos = utils::split_string(res[i+5],SEPARATOR_SQL); + vector field = utils::split_string(res[i+6],SEPARATOR_SQL); + vector misc = utils::split_string(res[i+7],SEPARATOR_SQL); + vector dial = utils::split_string(res[i+8],SEPARATOR_SQL); + w.s_ele( ElementSense( sid, gloss, {/*stagk*/}, {/*stagr*/}, pos, xref, + ant, field, misc, dial, inf) ); + } + + return w; +} + Kanji App::db_get_kanji ( const string &kanji ) { @@ -575,11 +645,11 @@ Kanji App::db_get_kanji ( const string &kanji ) kk.jlpt(std::stoi(res[5])); kk.grade(std::stoi(res[6])); kk.freq(std::stoi(res[7])); - kk.onyomi( utils::split_string(res[8],parsers::SEPARATOR_SQL) ); - kk.kunyomi( utils::split_string(res[9],parsers::SEPARATOR_SQL) ); - kk.nanori( utils::split_string(res[10],parsers::SEPARATOR_SQL) ); - kk.meaning( utils::split_string(res[11],parsers::SEPARATOR_SQL) ); - kk.flags( utils::split_string(res[12],parsers::SEPARATOR_SQL) ); + kk.onyomi( utils::split_string(res[8],SEPARATOR_SQL) ); + kk.kunyomi( utils::split_string(res[9],SEPARATOR_SQL) ); + kk.nanori( utils::split_string(res[10],SEPARATOR_SQL) ); + kk.meaning( utils::split_string(res[11],SEPARATOR_SQL) ); + kk.flags( utils::split_string(res[12],SEPARATOR_SQL) ); kk.components( res[13] ); string qq = "select skip1,skip2,skip3,misclass from k_skip where kanji='"+kanji+"';"; diff --git a/src/aoi.hxx b/src/aoi.hxx index d4fc0b5..17c1112 100755 --- a/src/aoi.hxx +++ b/src/aoi.hxx @@ -203,9 +203,12 @@ class App vector query ( const char *q, bool log_query=true, bool replace_separator = true ); - //! Gets ne kanji from database. + //! Gets one kanji from database. Kanji db_get_kanji ( const string &kanji ); + //! Gets one word(record) from database + DicWord db_get_word( int did ); + //! Returns whole config as map. inline std::map get_config_map () { return cfg_->get_map(); }; @@ -295,7 +298,7 @@ class App // Dictionary functions void cb_dic_input (); void on_dic_selected ( int id ); - void cb_edit_word ( int id ); + void cb_edit_word (); void parse_dic_input ( const char *str ); // Kanjidic functions @@ -330,14 +333,13 @@ class App } } inline static void scb_dicview_doubleclick ( Fl_Widget *w, void *p ){ - aoi_ui::DicView *v = (aoi_ui::DicView*)w; - ((App*)p)->cb_edit_word( v->cell_id(v->callback_row(),v->callback_col()) ); - } + ((App*)p)->cb_edit_word(); } + inline static void scb_edit_word ( Fl_Widget *w, void *p ){ + ((App*)p)->cb_edit_word(); } inline static void scb_dicview_rightclick ( Fl_Widget *w, void *p ){ aoi_ui::DicView *v = (aoi_ui::DicView*)w; ((App*)p)->cb_dicview_rightclick( v->selected_row_id() ); } - inline static void scb_set_components ( Fl_Widget *w, void *p ) { ((App*)p)->cb_set_components(); } }; diff --git a/src/datatypes.hxx b/src/datatypes.hxx index 3a36c90..4afddde 100755 --- a/src/datatypes.hxx +++ b/src/datatypes.hxx @@ -23,6 +23,8 @@ namespace aoi { +const char *const SEPARATOR_SQL = "|"; + struct SKIP { int s1 = 0; @@ -180,6 +182,7 @@ struct ElementReading return ss.str(); } + inline int rid() const {return rid_;}; inline string reading() const {return reading_;}; inline bool nokanji() const {return nokanji_;}; @@ -211,8 +214,8 @@ struct ElementSense : sid_(sid), gloss_(gloss), stagk_(stagk), stagr_(stagr), pos_(pos), xref_(xref), ant_(ant), field_(field), misc_(misc), dial_(dial), s_inf_(s_inf) - {}; - ~ElementSense(){}; + {} + ~ElementSense(){} string sql ( int did, const char *sep ){ std::stringstream ss; @@ -231,20 +234,20 @@ struct ElementSense return ss.str(); } - inline int sid() const {return sid_;}; - inline vector gloss() const {return gloss_;}; - inline vector stagk() const {return stagk_;}; - inline vector stagr() const {return stagr_;}; - inline vector pos() const {return pos_;}; - inline vector xref() const {return xref_;}; - inline vector ant() const {return ant_;}; - inline vector field() const {return field_;}; - inline vector misc() const {return misc_;}; - inline vector dial() const {return dial_;}; - inline vector s_inf() const {return s_inf_;}; + inline int sid() const {return sid_;} + inline vector gloss() const {return gloss_;} + inline vector stagk() const {return stagk_;} + inline vector stagr() const {return stagr_;} + inline vector pos() const {return pos_;} + inline vector xref() const {return xref_;} + inline vector ant() const {return ant_;} + inline vector field() const {return field_;} + inline vector misc() const {return misc_;} + inline vector dial() const {return dial_;} + inline vector s_inf() const {return s_inf_;} }; -struct DicWord +class DicWord { private: int did_; @@ -254,13 +257,78 @@ struct DicWord public: DicWord( int i=-1, const vector &k={}, const vector &r={}, const vector &s={} ) - : did_(i), k_ele_(k), r_ele_(r), s_ele_(s) {}; - ~DicWord(){}; + : did_(i), k_ele_(k), r_ele_(r), s_ele_(s) {} + ~DicWord(){} + + // setters + inline void r_ele ( const ElementReading &rele ) + { r_ele_.push_back(rele); } + inline void k_ele ( const ElementKanji &kele ) + { k_ele_.push_back(kele); } + inline void s_ele ( const ElementSense &sele ) + { s_ele_.push_back(sele); } + + // getters + inline int did() const {return did_;} + inline vector k_ele () const {return k_ele_;} + inline vector r_ele () const {return r_ele_;} + inline vector s_ele () const {return s_ele_;} - inline int did() const {return did_;}; - inline vector k_ele () const {return k_ele_;}; - inline vector r_ele () const {return r_ele_;}; - inline vector s_ele () const {return s_ele_;}; + string html () const { + std::stringstream ss; + // kanji + if ( !k_ele_.empty() ) + ss << " 
"; // to compensate kanji's size + for ( auto &k: k_ele_ ){ + ss << "" << k.kanji() << ""; + if ( !k.inf().empty() ) + ss << "[" << utils::to_string(k.inf()) << "]"; + ss << "
"; + } + // reading + for ( auto &r: r_ele_ ){ + ss << "" << r.reading() << ""; + if ( !r.inf().empty() ) + ss << "[" << utils::to_string(r.inf()) << "]"; + if ( r.nokanji() ) + ss << "[NOKANJI]"; + ss << "
"; + } + // sense + for ( auto &s: s_ele_ ){ + ss << "- "; + if ( !s.pos().empty() ) + ss << "" + << utils::to_string( s.pos() ) << " "; + if ( !s.misc().empty() ) + ss << "" + << utils::to_string( s.misc() ) << " "; + ss << utils::to_string( s.gloss() ); + if ( !s.field().empty() ) + ss << "" + << utils::to_string( s.field() ) << " "; + if ( !s.dial().empty() ) + ss << "" + << utils::to_string( s.dial() ) << " "; + ss << "
"; + if ( !s.ant().empty() ) + ss << "  Antonyms: " << "" + << utils::to_string( s.ant() ) << "
"; + if ( !s.xref().empty() ) + ss << "  See also: " << "" + << utils::to_string( s.xref() ) << "
"; + if ( !s.s_inf().empty() ) + ss << "  Note: " << "" + << utils::to_string( s.s_inf() ) << "
"; + } + return ss.str(); + } }; } // namespace aoi diff --git a/src/gui.cxx b/src/gui.cxx index a0fd8f2..30436cd 100755 --- a/src/gui.cxx +++ b/src/gui.cxx @@ -175,8 +175,7 @@ GUI::GUI ( aoi::App *parent ):parent_(parent) dlg_fonts_ = new DialogFontTest(); dlg_progress_ = new DialogProgress(300,50); dlg_help_ = new Fl_Help_Dialog(); - dlg_edit_word_ = new EditWordDialog(0,0,400,550); - dlg_edit_word_->end(); + dlg_edit_word_ = new DialogEditWord(); dlg_manage_db_ = new ManageDBDialog(); dlg_download_ = new DialogDownload(400,125); @@ -308,15 +307,13 @@ void GUI::dicview_menu ( int did, const vector &v, bool notes, bool exam } menu.add("Notes",0,0,0, notes ? 0:FL_MENU_INACTIVE); menu.add("Examples",0,0,0, examples ? 0:FL_MENU_INACTIVE); - menu.add("Edit"); + menu.add("Show", 0, App::scb_edit_word, (void*)parent_); menu.popup(); } -void GUI::edit_word () +void GUI::edit_word ( const aoi::DicWord &w ) { - // center on parent - dlg_edit_word_->resize( main_window_->x()*1.5, main_window_->y(), - dlg_edit_word_->w(), dlg_edit_word_->h() ); + dlg_edit_word_->set(w); dlg_edit_word_->show(); } diff --git a/src/gui.hxx b/src/gui.hxx index 994f0b9..92a098b 100755 --- a/src/gui.hxx +++ b/src/gui.hxx @@ -213,7 +213,7 @@ class GUI DialogProgress *dlg_progress_ = nullptr; KanjiPopupWindow *popup_ = nullptr; Fl_Help_Dialog *dlg_help_ = nullptr; - EditWordDialog *dlg_edit_word_ = nullptr; + DialogEditWord *dlg_edit_word_ = nullptr; ManageDBDialog *dlg_manage_db_ = nullptr; //! Prevents closing MainWindow when ESC pressed. @@ -349,7 +349,7 @@ class GUI void dicview_menu ( int did, const vector &things, bool notes=false, bool examples=false ); // XXX - void edit_word (); + void edit_word ( const aoi::DicWord &w ); //! Popups KanjiPopupWindow in KanjiView. void popup_kanji ( const Kanji &k ); @@ -388,6 +388,9 @@ class GUI vector listview_filters (); + inline int dicview_selected_rowid () const + { return main_window_->dic_view_->selected_row_id(); }; + inline void set_components ( const vector &v ) { main_window_->compo_view_->set_data(v); }; diff --git a/src/gui_dialogs.cxx b/src/gui_dialogs.cxx index 61f29c7..7c7770e 100755 --- a/src/gui_dialogs.cxx +++ b/src/gui_dialogs.cxx @@ -166,12 +166,21 @@ void DialogDownload::cb_fname_callback ( ) ////////////////////////////////////////////////////////////////////////// -// EditWordDialog +// DialogEditWord -EditWordDialog::EditWordDialog ( int x, int y, int w, int h, const char *l ) - : Fl_Double_Window(x,y,w,h,l) +DialogEditWord::DialogEditWord ( int w, int h, const char *l ) + : Fl_Double_Window(w,h,l) { - set_modal(); + Fl_Box *tmp1 = new Fl_Box( 5, 5, 100, 30, "JMDict id:"); + l_did_ = new Label( 105, 5, 60, 30 ); + view_ = new Fl_Help_View(5, 35, w-10, h-80); + b_cancel_ = new Fl_Button( w-65, h-35, 60, 30, "Close"); + end(); + tmp1->align( FL_ALIGN_INSIDE|FL_ALIGN_LEFT ); + tmp1->labelfont( FL_BOLD ); + b_cancel_->callback( scb_cancel, (void*)this ); + view_->textsize(16); +// set_modal(); } ////////////////////////////////////////////////////////////////////////// diff --git a/src/gui_dialogs.hxx b/src/gui_dialogs.hxx index f9a353c..0a69536 100755 --- a/src/gui_dialogs.hxx +++ b/src/gui_dialogs.hxx @@ -31,6 +31,7 @@ #include #include #include +#include #include "logger.hxx" #include "gui_widgets.hxx" @@ -258,16 +259,34 @@ class DialogDownload : public Fl_Double_Window }; -class EditWordDialog : public Fl_Double_Window +/*! +* Shows all known informations about word. +* \todo change to true edit word dialog +*/ +class DialogEditWord : public Fl_Double_Window { - private: + private: + Fl_Button *b_cancel_ = nullptr; + Fl_Help_View *view_ = nullptr; + Label *l_did_ = nullptr; public: - EditWordDialog ( int x, int y, int w, int h, const char *l="Edit word" ); - ~EditWordDialog(){}; + DialogEditWord ( int w=400, int h=500, const char *l="Edit word" ); + ~DialogEditWord(){}; + + inline void set ( const aoi::DicWord &w ){ + l_did_->set( std::to_string(w.did()) ); + view_->value( w.html().c_str() ); + }; + + inline static void scb_cancel ( Fl_Widget *w, void *p ) + { ((DialogEditWord*)p)->hide(); }; + + // run(); }; + class ManageDBDialog : public Fl_Double_Window { private: diff --git a/src/main.cxx b/src/main.cxx index 3ac64aa..97b02f9 100755 --- a/src/main.cxx +++ b/src/main.cxx @@ -60,7 +60,7 @@ void parse_jmdict ( const char *fname ) printf("Decompressing file: %s -> %s\n", fname, TEMP_JMDICT); utils::gzip_decompress_file( fname, TEMP_JMDICT); parsers::JmdictParser jmp(TEMP_JMDICT); - const char *SEP = parsers::SEPARATOR_SQL; + const char *SEP = aoi::SEPARATOR_SQL; // tables for ( auto &mi: aoi_config::db_tables.at("main") ){ @@ -124,7 +124,7 @@ void parse_jmdict ( const char *fname ) void parse_kanjidic ( const char *fname ) { printf("Loading kanjidic file: %s\n", fname); - const char *SEP = parsers::SEPARATOR_SQL; + const char *SEP = aoi::SEPARATOR_SQL; int n_kanji = 0; try { diff --git a/src/parsers.hxx b/src/parsers.hxx index 8739244..ab5d48d 100755 --- a/src/parsers.hxx +++ b/src/parsers.hxx @@ -31,6 +31,7 @@ #include "utils.hxx" #include "datatypes.hxx" +using aoi::SEPARATOR_SQL; using aoi::ElementKanji; using aoi::ElementReading; using aoi::ElementSense; @@ -44,7 +45,6 @@ using rapidxml::xml_document; namespace parsers { -const char *const SEPARATOR_SQL = "|"; class BaseParser { -- 2.11.4.GIT