diff --git a/src/Makefile.am b/src/Makefile.am index abbb2f6..4d1c926 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,8 +1,8 @@ bin_PROGRAMS = vido -vido_SOURCES = main_window.cc search_dialog.cc vido.cc +vido_SOURCES = main_window.cc search_dialog.cc message_dialog.cc vido.cc -noinst_HEADERS = main_window.hh search_dialog.hh +noinst_HEADERS = main_window.hh search_dialog.hh message_dialog.hh AM_CXXFLAGS = @CXXFLAGS@ @GTKMM_CFLAGS@ @GTKHTML_CFLAGS@ diff --git a/src/main_window.cc b/src/main_window.cc index 474e2f6..2131a2b 100644 --- a/src/main_window.cc +++ b/src/main_window.cc @@ -64,7 +64,7 @@ bool main_window::actions(int key) bool main_window::on_my_key_press_event(GdkEventKey *Key) { - if (Key->keyval == gdk_keyval_from_name("Control_L")) + if (Key->keyval == gdk_keyval_from_name("Control_R")) { ctrl_state = 1; } @@ -82,7 +82,7 @@ bool main_window::on_my_key_press_event(GdkEventKey *Key) bool main_window::on_my_key_release_event(GdkEventKey *Key) { - if (Key->keyval == gdk_keyval_from_name("Control_L")) + if (Key->keyval == gdk_keyval_from_name("Control_R")) { ctrl_state = 0; } diff --git a/src/message_dialog.cc b/src/message_dialog.cc new file mode 100644 index 0000000..f20e856 --- /dev/null +++ b/src/message_dialog.cc @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2009 by Mirko Lindner * + * mirko@qi-hardware.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "config.h" +#include "message_dialog.hh" +#include "vido.hh" +#include + +message_dialog::message_dialog(main_window* parent, std::string title, std::string txt) +{ + Gtk::Dialog dialog(title, parent, true); + + Gtk::Label label(txt); + dialog.get_vbox()->pack_start(label, true, true); +// Gtk::Entry entry; +// entry.set_text(""); +// dialog.get_vbox()->pack_start(entry, true, true); + +// dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); + dialog.show_all(); + int result = dialog.run(); + if (result == Gtk::RESPONSE_OK) { + + } else { + + } + +} \ No newline at end of file diff --git a/src/message_dialog.hh b/src/message_dialog.hh new file mode 100644 index 0000000..8ab5f67 --- /dev/null +++ b/src/message_dialog.hh @@ -0,0 +1,35 @@ +/*************************************************************************** + * Copyright (C) 2009 by Mirko Lindner * + * mirko@qi-hardware.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + + +#ifndef MESSAGE_DIALOG_HH +#define MESSAGE_DIALOG_HH +#include + +class main_window; + +class message_dialog : public Gtk::Dialog{ + + public: + message_dialog(main_window* parent, std::string, std::string); + +}; + +#endif // MESSAGE_DIALOG_HH \ No newline at end of file diff --git a/src/vido.cc b/src/vido.cc index 799c783..37e86b8 100644 --- a/src/vido.cc +++ b/src/vido.cc @@ -26,6 +26,7 @@ #include #include "config.h" +#include "message_dialog.hh" #include "vido.hh" #include "main_window.hh" #include "search_dialog.hh" @@ -41,6 +42,7 @@ extern "C" { std::string content; std::string fileName; +main_window *window; Gtk::Widget *html; GtkWidget *html_wg; @@ -60,6 +62,11 @@ const zim::File& get_file() return zimFile; } +void show_message(std::string title, std::string txt) +{ + message_dialog(window, title, txt); +} + // // copy article html from while loop into global variable void set_article(const std::string& txt) { @@ -76,24 +83,24 @@ void show_random() zim::File m = get_file(); static unsigned int seed = static_cast(time(0)); - + zim::size_type idx = static_cast(static_cast(m.getCountArticles()) * rand_r(&seed) / RAND_MAX); zim::Article article; - do + + article = m.getArticle(idx); + + //loop in case article is redirect + do { - log_debug("random running loop"); - zim::size_type idx = static_cast(static_cast(m.getCountArticles()) * rand_r(&seed) / RAND_MAX); - - log_debug("random index " << idx << " number of articles: " << m.getCountArticles()); - - article = m.getArticle(idx); - - } while(article.isRedirect()); + article = article.getRedirectArticle(); + }while(article.isRedirect()); + + std::string res = article.getPage(); content = article.getPage(); log_debug("article size=" << content.size()); gtk_html_flush(GTK_HTML(html_wg)); - gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1); + gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1); } // // display search dialog @@ -164,6 +171,7 @@ void set_html(const gchar *url) // // load new data into gtkhtml widget gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1); +// window.resize(220, 140); log_debug("term=" << term << " url=" << url); } else @@ -190,6 +198,7 @@ void set_search(const gchar *url) search.search(result, term); if(result.size() == 0) { + show_message("Error", "The article you requested (" + term + ") was not found."); } else if (result.size() == 1) { @@ -214,6 +223,7 @@ void set_search(const gchar *url) gtk_html_flush(GTK_HTML(html_wg)); gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1); +// window.resize(220, 140); } @@ -228,7 +238,7 @@ bool on_link_clicked(GtkHTML *html, const gchar *url) { set_html(url); -// set_berlin(url); +// window.resize(220, 140); return true; } @@ -251,7 +261,7 @@ int main(int argc, char **argv) main_window window; window.set_title("Vido"); // window.set_border_width(0); - window.set_default_size(320, 240); + window.set_default_size(220, 240); // window.set_resizable(0); html_wg = gtk_html_new(); diff --git a/src/vido.hh b/src/vido.hh index 66fcf7b..22fcf86 100644 --- a/src/vido.hh +++ b/src/vido.hh @@ -19,6 +19,7 @@ #ifndef VIDO_HH #define VIDO_HH +#include #include