mirror of
git://projects.qi-hardware.com/vido.git
synced 2024-11-01 09:16:18 +02:00
initial import
This commit is contained in:
commit
a025d15ca3
105
src/main_window.cc
Normal file
105
src/main_window.cc
Normal file
@ -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), "<html><body>me</body></html>", -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;
|
||||||
|
}
|
42
src/main_window.hh
Normal file
42
src/main_window.hh
Normal file
@ -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 <gtkmm.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <gdkmm/gc.h>
|
||||||
|
#include <gdk/gdkkeysyms.h>
|
||||||
|
#include <gtkmm/window.h>
|
||||||
|
|
||||||
|
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();
|
||||||
|
};
|
||||||
|
|
159
src/vido.cc
Normal file
159
src/vido.cc
Normal file
@ -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 <gtkmm.h>
|
||||||
|
#include <zim/file.h>
|
||||||
|
#include <zim/fileiterator.h>
|
||||||
|
#include <zim/search.h>
|
||||||
|
#include <zim/articlesearch.h>
|
||||||
|
#include "main_window.hh"
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "gtkhtml/gtkhtml.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace Gtk;
|
||||||
|
Glib::RefPtr<Gtk::TextBuffer> buffer;
|
||||||
|
unsigned int seed = static_cast<unsigned int>(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<zim::size_type>(static_cast<double>(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 "<<res.size()<<".";
|
||||||
|
if (res.size() > 0){
|
||||||
|
set_article(res);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout<<"nach while "<<content.size()<<".";
|
||||||
|
gtk_html_flush(GTK_HTML(html_wg));
|
||||||
|
gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1);
|
||||||
|
// gtk_html_set_editable(GTK_HTML(html_wg),false);
|
||||||
|
// gtk_html_allow_selection(GTK_HTML(html_wg),true);
|
||||||
|
// gtk_html_set_magic_links(GTK_HTML(html_wg),true);
|
||||||
|
// gtk_html_set_caret_mode(GTK_HTML(html_wg),true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_html(const gchar *url){
|
||||||
|
// std::cout<<"url"<<url<<".";
|
||||||
|
zim::File m(file);
|
||||||
|
|
||||||
|
zim::Search::Results result;
|
||||||
|
result.clear();
|
||||||
|
zim::Search search(m);
|
||||||
|
std::string term;
|
||||||
|
term.assign( url );
|
||||||
|
search.search(result, term);
|
||||||
|
std::cout<<"url"<<result.size()<<".";
|
||||||
|
if (!result.empty()){
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_berlin(){
|
||||||
|
// std::cout<<"url"<<url<<".";
|
||||||
|
zim::File m(file);
|
||||||
|
|
||||||
|
zim::Search::Results result;
|
||||||
|
result.clear();
|
||||||
|
zim::Search search(m);
|
||||||
|
std::string term = "Geographische+Koordinaten";
|
||||||
|
// 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::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;
|
||||||
|
|
||||||
|
}
|
159
src/vido.cc~
Normal file
159
src/vido.cc~
Normal file
@ -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 <gtkmm.h>
|
||||||
|
#include <zim/file.h>
|
||||||
|
#include <zim/fileiterator.h>
|
||||||
|
#include <zim/search.h>
|
||||||
|
#include <zim/articlesearch.h>
|
||||||
|
#include "main_window.hh"
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "gtkhtml/gtkhtml.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace Gtk;
|
||||||
|
Glib::RefPtr<Gtk::TextBuffer> buffer;
|
||||||
|
unsigned int seed = static_cast<unsigned int>(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<zim::size_type>(static_cast<double>(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 "<<res.size()<<".";
|
||||||
|
if (res.size() > 0){
|
||||||
|
set_article(res);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout<<"nach while "<<content.size()<<".";
|
||||||
|
gtk_html_flush(GTK_HTML(html_wg));
|
||||||
|
gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1);
|
||||||
|
// gtk_html_set_editable(GTK_HTML(html_wg),false);
|
||||||
|
// gtk_html_allow_selection(GTK_HTML(html_wg),true);
|
||||||
|
// gtk_html_set_magic_links(GTK_HTML(html_wg),true);
|
||||||
|
// gtk_html_set_caret_mode(GTK_HTML(html_wg),true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_html(const gchar *url){
|
||||||
|
// std::cout<<"url"<<url<<".";
|
||||||
|
zim::File m(file);
|
||||||
|
|
||||||
|
zim::Search::Results result;
|
||||||
|
result.clear();
|
||||||
|
zim::Search search(m);
|
||||||
|
std::string term;
|
||||||
|
term.assign( url );
|
||||||
|
search.search(result, term);
|
||||||
|
std::cout<<"url"<<result.size()<<".";
|
||||||
|
if (!result.empty()){
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_berlin(){
|
||||||
|
// std::cout<<"url"<<url<<".";
|
||||||
|
zim::File m(file);
|
||||||
|
|
||||||
|
zim::Search::Results result;
|
||||||
|
result.clear();
|
||||||
|
zim::Search search(m);
|
||||||
|
std::string term = "Geographische+Koordinaten";
|
||||||
|
// 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::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;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user