diff --git a/Makefile.am b/Makefile.am index 23173a8..948a117 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1 @@ SUBDIRS = src - -EXTRA_DIST = AUTHORS TODO README configure diff --git a/configure.in b/configure.in index 9cad555..1b6a43c 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ AC_INIT(configure.in) AM_INIT_AUTOMAKE(vido, 0.1) -AC_CONFIG_HEADER(config.h) +AC_CONFIG_HEADER(src/config.h) AC_ISC_POSIX AC_PROG_CC @@ -16,4 +16,7 @@ AC_LANG_CPLUSPLUS PKG_CHECK_MODULES([GTKMM], [gtkmm-2.4 >= 2.8.0]) PKG_CHECK_MODULES([GTKHTML], [libgtkhtml-3.14 >= 3.28.0]) +AC_CHECK_HEADER([zim/qunicode.h], + [AC_DEFINE([HAVE_ZIM_QUNICODE_H], [1], [Defined if header is found])]) + AC_OUTPUT(Makefile src/Makefile ) diff --git a/src/Makefile.am b/src/Makefile.am index 861c70f..abbb2f6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ bin_PROGRAMS = vido -vido_SOURCES = main_window.cc search_dialog.cc vido.cc vido.cc_bkp +vido_SOURCES = main_window.cc search_dialog.cc vido.cc noinst_HEADERS = main_window.hh search_dialog.hh diff --git a/src/main_window.cc b/src/main_window.cc index b803f0b..474e2f6 100644 --- a/src/main_window.cc +++ b/src/main_window.cc @@ -25,46 +25,37 @@ #include "config.h" #include "main_window.hh" +#include "vido.hh" +#include - -extern void show_random(); -extern void search_window(main_window *window); +log_define("vido.main_window"); main_window::main_window() { - - this->signal_key_press_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_press_event)); - - this->signal_key_release_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_release_event)); + signal_key_press_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_press_event)); + signal_key_release_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_release_event)); } - main_window::~main_window() -{ } - bool main_window::actions(int key) { + static int key_q = 113; + static int key_r = 114; + static int key_s = 115; -// // 115 == s -// // 114 == r - - printf("actions key:%i q:%i",int(key), 113); - if (key == int(113)) + if (key == key_q) { - printf("quit requested"); - this->quit(); - + log_debug("quit requested"); + quit(); } - else if(key == int(114)) + else if(key == key_r) { -// gtk_html_load_from_string(GTK_HTML(html_wg), "me", -1); - + log_debug("random"); show_random(); - printf("random"); } - else if(key == int(115)) + else if(key == key_s) { + log_debug("search"); search_window(this); - printf("search"); } return true; @@ -73,34 +64,34 @@ bool main_window::actions(int key) bool main_window::on_my_key_press_event(GdkEventKey *Key) { -// printf("ctrl set value nows: %i\n", *ctrl_state); - if (Key->keyval == gdk_keyval_from_name("Control_L")){ + if (Key->keyval == gdk_keyval_from_name("Control_L")) + { ctrl_state = 1; -// printf("ctrl set value nows: %i\n", ctrl_state); - }else{ - if (ctrl_state == 1){ -// printf("key num: %i", Key->keyval); - this->actions(Key->keyval); -// printf("\n Key Presssed is %s with ctrl held\n",gdk_keyval_name(Key->keyval)); + } + else + { + if (ctrl_state == 1) + { + actions(Key->keyval); } } - printf("\n Key Presssed is %s\n",gdk_keyval_name(Key->keyval)); + + log_debug("Key Presssed is " << gdk_keyval_name(Key->keyval)); return true; } bool main_window::on_my_key_release_event(GdkEventKey *Key) { -// printf("ctrl set value nows: %i\n", *ctrl_state); - if (Key->keyval == gdk_keyval_from_name("Control_L")){ + if (Key->keyval == gdk_keyval_from_name("Control_L")) + { ctrl_state = 0; -// printf("ctrl set value nows: %i\n", ctrl_state); } -// printf("\n Key released is %s\n",gdk_keyval_name(Key->keyval)); + return true; } bool main_window::quit() { hide(); - return 0; + return false; } diff --git a/src/main_window.hh b/src/main_window.hh index 3a9bc97..3d1ee3e 100644 --- a/src/main_window.hh +++ b/src/main_window.hh @@ -18,25 +18,22 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#ifndef MAIN_WINDOW_HH +#define MAIN_WINDOW_HH -#include -#include -#include -#include -#include #include class main_window : public Gtk::Window { public: main_window(); - ~main_window(); - bool actions(int); - int ctrl_state; private: + bool actions(int); + int ctrl_state; bool on_my_key_press_event(GdkEventKey *event); bool on_my_key_release_event(GdkEventKey *event); bool quit(); }; +#endif // MAIN_WINDOW_HH diff --git a/src/search_dialog.cc b/src/search_dialog.cc index b8b89f7..21fe65c 100644 --- a/src/search_dialog.cc +++ b/src/search_dialog.cc @@ -20,12 +20,11 @@ #include "config.h" #include "search_dialog.hh" +#include "vido.hh" #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="") +search_dialog::search_dialog(main_window* parent, const Glib::ustring& input) { Gtk::Dialog dialog("Search", parent, true); @@ -39,13 +38,9 @@ search_dialog::search_dialog(main_window* parent, Glib::ustring input="") dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); dialog.show_all(); int result = dialog.run(); - if (result == Gtk::RESPONSE_OK) { + if (result == Gtk::RESPONSE_OK) + { set_search(entry.get_text().c_str()); - } else { - } } - - search_dialog::~search_dialog() -{ } \ No newline at end of file diff --git a/src/search_dialog.hh b/src/search_dialog.hh index ff8632e..00c3629 100644 --- a/src/search_dialog.hh +++ b/src/search_dialog.hh @@ -18,17 +18,17 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#ifndef SEARCH_DIALOG_HH +#define SEARCH_DIALOG_HH + #include -// #include -#include -#include -extern main_window parent; - -class search_dialog : public Gtk::Dialog{ +class main_window; +class search_dialog : public Gtk::Dialog +{ public: - search_dialog(main_window* parent, Glib::ustring); - ~search_dialog(); + search_dialog(main_window* parent, const Glib::ustring&); +}; -}; \ No newline at end of file +#endif // SEARCH_DIALOG_HH diff --git a/src/vido.cc b/src/vido.cc index e8d4b80..799c783 100644 --- a/src/vido.cc +++ b/src/vido.cc @@ -21,54 +21,47 @@ #include #include -#include #include -#include #include #include -#include - -// #include "main_window.hh" +#include "config.h" +#include "vido.hh" +#include "main_window.hh" #include "search_dialog.hh" +#include + +log_define("vido.main") + extern "C" { #include "gtkhtml/gtkhtml.h" } -using namespace Gtk; -Glib::RefPtr buffer; -unsigned int seed = static_cast(time(0)); -zim::Search::Results result; -std::string res; std::string content; -std::string file; -zim::File f; -Window *window; +std::string fileName; -Widget *html; +Gtk::Widget *html; GtkWidget *html_wg; -static zim::File zimFile; -static bool initialized = false; - // // // misc functions -const zim::File get_file() +const zim::File& get_file() { - if (!initialized){ - std::cout<<"file not initialized :"<(time(0)); + + zim::Article article; + do + { + log_debug("random running loop"); zim::size_type idx = static_cast(static_cast(m.getCountArticles()) * rand_r(&seed) / RAND_MAX); - zim::Article article = m.getArticle(idx); + log_debug("random index " << idx << " number of articles: " << m.getCountArticles()); + + article = m.getArticle(idx); + + } while(article.isRedirect()); + + content = article.getPage(); + log_debug("article size=" << content.size()); - std::string res = article.getPage(false, 10); - if (res.size() > 0){ - set_article(res); - break; - } - } gtk_html_flush(GTK_HTML(html_wg)); gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1); } // // display search dialog -void search_window(main_window *window_x){ - +void search_window(main_window *window_x) +{ search_dialog(window_x, " "); - } // // // meta functions // // set displayed html to given url // // FIXME: returns several articles and displays on one page ... why? -void set_html(const gchar *url){ +void set_html(const gchar *url) +{ + // TODO unescape url // // create ZIM file accessor zim::File m = get_file(); // // convert url to string - std::string term; - term.assign( url ); + std::string term(url); // // replace '+' signs with spaces in url std::replace(term.begin(), term.end(), '+', ' '); @@ -124,121 +122,104 @@ void set_html(const gchar *url){ // // find and declare namespace size_t found; size_t found2; - char *ns; + char ns; found=term.find("/"); - 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]; - found2 = term.find("/"); - term = term.substr(found2 + 1, strlen(url)); + if (found != std::string::npos) + { + if (found) + { + ns = term[0]; + term.erase(found + 1); } - }else{ - ns = "A"; + else + { + term.erase(1); + ns = term[0]; + found2 = term.find("/"); + term.erase(found2 + 1); + } + } + else + { + ns = 'A'; } // // try to retrieve article - try { - zim::File::const_iterator iterator = m.find(ns[0], zim::QUnicodeString(term)); - zim::Article article = m.getArticle(iterator.getIndex()); + try + { +#if HAVE_ZIM_QUNICODE_H + zim::Article article = m.getArticle(ns, zim::QUnicodeString(term)); +#else + zim::Article article = m.getArticle(ns, term); +#endif -// // get redirect article if needed - if (article.isRedirect()) + if (article.good()) // check if article is really found { - article = article.getRedirectArticle(); - } - // // get content html - content = article.getData().data(); - -// // get article length - int length = article.getArticleSize(); - -// // limit html output to article length - std::string str2 = content.substr (0,length); + content = article.getPage(); // // emtpy gtkhtml widget - gtk_html_flush(GTK_HTML(html_wg)); + gtk_html_flush(GTK_HTML(html_wg)); // // load new data into gtkhtml widget - gtk_html_load_from_string(GTK_HTML(html_wg), str2.c_str(), -1); - std::cout<<"term:"<" + result[i].getArticle().getTitle().toXML() + ""; +#else + res += "
  • " + result[i].getArticle().getTitle() + "
  • "; +#endif } 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<getUrl() << '\n'; - } - myfile.close(); - - } - - - // // // window response functions // // open requested link @@ -255,13 +236,17 @@ bool on_link_clicked(GtkHTML *html, const gchar *url) // // main function int main(int argc, char **argv) { + try + { + log_init(); + if (argc == 2) { - file = argv[1]; + fileName = argv[1]; - std::cout<<"vido is here file:"<