From bc6773928157113c5ed97e2e0cd800c63d8a6716 Mon Sep 17 00:00:00 2001 From: Mirko Lindner Date: Fri, 30 Oct 2009 14:13:07 +0100 Subject: [PATCH] add search function and display for list of results Signed-off-by: Mirko Lindner --- src/main_window.hh | 1 - src/search_dialog.cc | 3 +- src/vido.cc | 65 +++++++++++++++++++++++++++----------------- 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/src/main_window.hh b/src/main_window.hh index 123cc98..3a9bc97 100644 --- a/src/main_window.hh +++ b/src/main_window.hh @@ -33,7 +33,6 @@ class main_window : public Gtk::Window ~main_window(); bool actions(int); int ctrl_state; -// void search_dialog(); private: bool on_my_key_press_event(GdkEventKey *event); diff --git a/src/search_dialog.cc b/src/search_dialog.cc index 2a062cc..b8b89f7 100644 --- a/src/search_dialog.cc +++ b/src/search_dialog.cc @@ -23,6 +23,7 @@ #include extern void set_html(const gchar *url); +extern void set_search(const gchar *url); search_dialog::search_dialog(main_window* parent, Glib::ustring input="") { @@ -39,7 +40,7 @@ search_dialog::search_dialog(main_window* parent, Glib::ustring input="") dialog.show_all(); int result = dialog.run(); if (result == Gtk::RESPONSE_OK) { - set_html(entry.get_text().c_str()); + set_search(entry.get_text().c_str()); } else { } diff --git a/src/vido.cc b/src/vido.cc index b587160..e2e1483 100644 --- a/src/vido.cc +++ b/src/vido.cc @@ -110,6 +110,7 @@ void set_html(const gchar *url){ if (found!=std::string::npos){ if (found != (int) 0){ ns = &term[0]; + term = term.substr(found + 1, strlen(url)); }else{ term = term.substr(1, strlen(url)); ns = &term[0]; @@ -153,38 +154,52 @@ void set_html(const gchar *url){ // // test functions -void set_berlin(const gchar *url){ +void set_search(const gchar *url){ // std::cout<<"url"< 0){ -// zim::Article article = m.getArticle(result[0].getArticle().getIndex()); -// -// std::string content = article.getPage(false, 10); -// -// gtk_html_flush(GTK_HTML(html_wg)); -// gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1); -// } std::replace(term.begin(), term.end(), '+', ' '); - char* ns = "A"; - try { - zim::File::const_iterator iterator = z.find(ns[0], zim::QUnicodeString(term)); - zim::Article article = z.getArticle(iterator.getIndex()); - if (article.isRedirect()) - { - article = article.getRedirectArticle(); - } - content = article.getData().data(); - gtk_html_flush(GTK_HTML(html_wg)); - gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1); - }catch(...){ + search.search(result, term); + if(result.size() == 0) { + } + else if (result.size() == 1){ + + zim::Article article = z.getArticle(result[0].getArticle().getIndex()); + + std::string content = article.getPage(false, 10); + + gtk_html_flush(GTK_HTML(html_wg)); + gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1); + }else{ + std::string res; + for (unsigned i = 0; i < result.size(); ++i) { + res += "
  • " + result[i].getArticle().getTitle().toXML() + "
  • "; + } + + gtk_html_flush(GTK_HTML(html_wg)); + gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1); + + } +// char* ns = "A"; + +// try { +// zim::File::const_iterator iterator = z.find(ns[0], zim::QUnicodeString(term)); +// zim::Article article = z.getArticle(iterator.getIndex()); +// if (article.isRedirect()) +// { +// article = article.getRedirectArticle(); +// } +// content = article.getData().data(); +// gtk_html_flush(GTK_HTML(html_wg)); +// gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1); +// }catch(...){ +// } std::cout<