From 8e8144a4bb8690a694c8b05049194ca20777281d Mon Sep 17 00:00:00 2001 From: Mirko Lindner Date: Fri, 30 Oct 2009 09:04:39 +0100 Subject: [PATCH] make links clickable clicking on links now returns a new page --- but with several articles ... Signed-off-by: Mirko Lindner --- src/vido.cc | 140 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 103 insertions(+), 37 deletions(-) diff --git a/src/vido.cc b/src/vido.cc index 1ffcbe8..cdaee23 100644 --- a/src/vido.cc +++ b/src/vido.cc @@ -28,6 +28,8 @@ #include #include +#include + extern "C" { #include "gtkhtml/gtkhtml.h" } @@ -44,11 +46,17 @@ zim::File f; Widget *html; GtkWidget *html_wg; +// // // misc functions + +// // copy article html from while loop into global variable void set_article(std::string txt) { content = txt; } +// // // externally called functions + +// // display random article void show_random(){ while(true){ @@ -58,73 +66,128 @@ void show_random(){ zim::Article article = m.getArticle(idx); std::string res = article.getPage(false, 10); - std::cout<<"Diese Zeile läuft so lange bis "< 0){ set_article(res); break; } } - std::cout<<"nach while "< 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); +// zim::Search::Results result; +// result.clear(); +// zim::Search search(m); + std::string term; + term.assign( url ); +// search.search(result, term); +// if (result.size() > 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(...){ } -// std::cout<<"url"<<<<"."; +// std::cout<getUrl() << '\n'; + } + myfile.close(); + + } + + + +// // // window response functions + +// // open requested link +// FIXME show error window when dead-link requested bool on_link_clicked(GtkHTML *html, const gchar *url) { - + set_html(url); -// set_berlin(); +// set_berlin(url); return true; } + + +// // main function int main(int argc, char **argv) { @@ -142,6 +205,8 @@ int main(int argc, char **argv) html = Glib::wrap(html_wg); g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL ); + gtk_html_set_caret_mode(GTK_HTML(html_wg),true); + ScrolledWindow scrolled_window; @@ -152,6 +217,7 @@ int main(int argc, char **argv) window.show_all(); show_random(); + // set_berlin(); Main::run(window); return 0;