mirror of
git://projects.qi-hardware.com/vido.git
synced 2024-12-22 14:13:21 +02:00
make links clickable
clicking on links now returns a new page --- but with several articles ... Signed-off-by: Mirko Lindner <mirko@qi-hardware.com>
This commit is contained in:
parent
a138d4b770
commit
8e8144a4bb
128
src/vido.cc
128
src/vido.cc
@ -28,6 +28,8 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
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 "<<res.size()<<".";
|
||||
// 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()<<".";
|
||||
// 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);
|
||||
|
||||
}
|
||||
|
||||
// // // meta functions
|
||||
|
||||
// // set displayed html to given url
|
||||
// // FIXME: returns several articles and displays on one page ... why?
|
||||
void set_html(const gchar *url){
|
||||
// std::cout<<"url"<<url<<".";
|
||||
|
||||
// // create ZIM file accessor
|
||||
zim::File m(file);
|
||||
|
||||
zim::Search::Results result;
|
||||
result.clear();
|
||||
zim::Search search(m);
|
||||
// // convert url to string
|
||||
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);
|
||||
// // replace '+' signs with spaces in url
|
||||
std::replace(term.begin(), term.end(), '+', ' ');
|
||||
|
||||
// // declare namespace
|
||||
char* 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());
|
||||
|
||||
// // get redirect article if needed
|
||||
if (article.isRedirect())
|
||||
{
|
||||
article = article.getRedirectArticle();
|
||||
}
|
||||
|
||||
// // get content html
|
||||
content = article.getData().data();
|
||||
|
||||
// // emtpy gtkhtml widget
|
||||
gtk_html_flush(GTK_HTML(html_wg));
|
||||
|
||||
// // load new data into gtkhtml widget
|
||||
gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1);
|
||||
|
||||
}catch(...){
|
||||
}
|
||||
}
|
||||
|
||||
void set_berlin(){
|
||||
|
||||
// // test functions
|
||||
void set_berlin(const gchar *url){
|
||||
// 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);
|
||||
zim::File z(file);
|
||||
|
||||
// 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<<content<<".\n";
|
||||
}
|
||||
|
||||
void articles2file(){
|
||||
|
||||
std::ofstream myfile;
|
||||
myfile.open ("articles.txt");
|
||||
zim::File f(file);
|
||||
for (zim::File::const_iterator it = f.begin(); it != f.end(); ++it)
|
||||
{
|
||||
myfile << it->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;
|
||||
|
Loading…
Reference in New Issue
Block a user