commit a025d15ca30727c730defb9b633bfd8d2e8523e2 Author: Mirko Lindner Date: Wed Oct 28 14:47:25 2009 +0100 initial import diff --git a/src/main_window.cc b/src/main_window.cc new file mode 100644 index 0000000..3117715 --- /dev/null +++ b/src/main_window.cc @@ -0,0 +1,105 @@ +/*************************************************************************** + * Copyright (C) 2009 by Mirko Lindner,,, * + * vegyraupe@mira * + * * + * 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. * + ***************************************************************************/ + + +// newer (non customized) versions of this file go to main_window.cc_new + +// This file is for your program, I won't touch it again! + +#include "config.h" +#include "main_window.hh" + + +extern void show_random(); + +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)); +} + + main_window::~main_window() +{ } + +bool main_window::actions(int key) +{ + +// // 115 == s +// // 114 == r + + printf("actions key:%i q:%i",int(key), 113); + if (key == int(113)) + { + printf("quit requested"); + this->quit(); + + } + else if(key == int(114)) + { +// gtk_html_load_from_string(GTK_HTML(html_wg), "me", -1); + + show_random(); + printf("random"); + } + else if(key == int(115)) + { + + printf("search"); + } + + return true; + +} + +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")){ + 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)); + } + } + printf("\n Key Presssed is %s\n",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")){ + 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; +} diff --git a/src/main_window.hh b/src/main_window.hh new file mode 100644 index 0000000..3a9bc97 --- /dev/null +++ b/src/main_window.hh @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (C) 2009 by Mirko Lindner,,, * + * vegyraupe@mira * + * * + * 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 +#include +#include +#include +#include +#include + +class main_window : public Gtk::Window +{ + public: + main_window(); + ~main_window(); + bool actions(int); + int ctrl_state; + + private: + bool on_my_key_press_event(GdkEventKey *event); + bool on_my_key_release_event(GdkEventKey *event); + bool quit(); +}; + diff --git a/src/vido.cc b/src/vido.cc new file mode 100644 index 0000000..1ffcbe8 --- /dev/null +++ b/src/vido.cc @@ -0,0 +1,159 @@ +/*************************************************************************** + * Copyright (C) 2009 by Mirko Lindner,,, * + * vegyraupe@mira * + * * + * 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 +#include +#include +#include +#include +#include "main_window.hh" +#include +#include + +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; + +Widget *html; +GtkWidget *html_wg; + +void set_article(std::string txt) +{ + content = txt; +} + +void show_random(){ + + while(true){ + zim::File m(file); + zim::size_type idx = static_cast(static_cast(m.getCountArticles()) * rand_r(&seed) / RAND_MAX); + + 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); + } + +// std::cout<<"url"<<<<"."; +} + +bool on_link_clicked(GtkHTML *html, const gchar *url) +{ + + set_html(url); +// set_berlin(); + return true; +} + +int main(int argc, char **argv) +{ + + file = argv[1]; + + Main kit(argc, argv); + + main_window window; + window.set_title("Vido"); + window.set_border_width(0); + window.set_default_size(320, 240); +// window.set_resizable(0); + + html_wg = gtk_html_new(); + + html = Glib::wrap(html_wg); + g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL ); + + ScrolledWindow scrolled_window; + + scrolled_window.add(*html); + scrolled_window.set_policy(POLICY_NEVER, POLICY_AUTOMATIC); + + window.add(scrolled_window); + window.show_all(); + + show_random(); +// set_berlin(); + Main::run(window); + return 0; + +} diff --git a/src/vido.cc~ b/src/vido.cc~ new file mode 100644 index 0000000..e2d759c --- /dev/null +++ b/src/vido.cc~ @@ -0,0 +1,159 @@ +/*************************************************************************** + * Copyright (C) 2009 by Mirko Lindner,,, * + * vegyraupe@mira * + * * + * 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 +#include +#include +#include +#include +#include "main_window.hh" +#include +#include + +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; + +Widget *html; +GtkWidget *html_wg; + +void set_article(std::string txt) +{ + content = txt; +} + +void show_random(){ + + while(true){ + zim::File m(file); + zim::size_type idx = static_cast(static_cast(m.getCountArticles()) * rand_r(&seed) / RAND_MAX); + + 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); + } + +// std::cout<<"url"<<<<"."; +} + +bool on_link_clicked(GtkHTML *html, const gchar *url) +{ + + set_html(url); +// set_berlin(); + return true; +} + +int main(int argc, char **argv) +{ + + file = argv[1]; + + Main kit(argc, argv); + + main_window window; + window.set_title("Wiki Viewer"); + window.set_border_width(0); + window.set_default_size(320, 240); +// window.set_resizable(0); + + html_wg = gtk_html_new(); + + html = Glib::wrap(html_wg); + g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL ); + + ScrolledWindow scrolled_window; + + scrolled_window.add(*html); + scrolled_window.set_policy(POLICY_NEVER, POLICY_AUTOMATIC); + + window.add(scrolled_window); + window.show_all(); + + show_random(); +// set_berlin(); + Main::run(window); + return 0; + +}