mirror of
git://projects.qi-hardware.com/vido.git
synced 2024-12-22 14:23:19 +02:00
add support for newer zim libraries
fix crash when link clicked is not found
This commit is contained in:
parent
a3a1b3a3b1
commit
ffdd227df7
@ -1,3 +1 @@
|
|||||||
SUBDIRS = src
|
SUBDIRS = src
|
||||||
|
|
||||||
EXTRA_DIST = AUTHORS TODO README configure
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
AC_INIT(configure.in)
|
AC_INIT(configure.in)
|
||||||
AM_INIT_AUTOMAKE(vido, 0.1)
|
AM_INIT_AUTOMAKE(vido, 0.1)
|
||||||
AC_CONFIG_HEADER(config.h)
|
AC_CONFIG_HEADER(src/config.h)
|
||||||
|
|
||||||
AC_ISC_POSIX
|
AC_ISC_POSIX
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
@ -16,4 +16,7 @@ AC_LANG_CPLUSPLUS
|
|||||||
PKG_CHECK_MODULES([GTKMM], [gtkmm-2.4 >= 2.8.0])
|
PKG_CHECK_MODULES([GTKMM], [gtkmm-2.4 >= 2.8.0])
|
||||||
PKG_CHECK_MODULES([GTKHTML], [libgtkhtml-3.14 >= 3.28.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 <zim/qunicode.h> is found])])
|
||||||
|
|
||||||
AC_OUTPUT(Makefile src/Makefile )
|
AC_OUTPUT(Makefile src/Makefile )
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
bin_PROGRAMS = vido
|
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
|
noinst_HEADERS = main_window.hh search_dialog.hh
|
||||||
|
|
||||||
|
@ -25,46 +25,37 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "main_window.hh"
|
#include "main_window.hh"
|
||||||
|
#include "vido.hh"
|
||||||
|
#include <cxxtools/log.h>
|
||||||
|
|
||||||
|
log_define("vido.main_window");
|
||||||
extern void show_random();
|
|
||||||
extern void search_window(main_window *window);
|
|
||||||
|
|
||||||
main_window::main_window()
|
main_window::main_window()
|
||||||
{
|
{
|
||||||
|
signal_key_press_event().connect(sigc::mem_fun(*this,&main_window::on_my_key_press_event));
|
||||||
this->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));
|
||||||
|
|
||||||
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)
|
bool main_window::actions(int key)
|
||||||
{
|
{
|
||||||
|
static int key_q = 113;
|
||||||
|
static int key_r = 114;
|
||||||
|
static int key_s = 115;
|
||||||
|
|
||||||
// // 115 == s
|
if (key == key_q)
|
||||||
// // 114 == r
|
|
||||||
|
|
||||||
printf("actions key:%i q:%i",int(key), 113);
|
|
||||||
if (key == int(113))
|
|
||||||
{
|
{
|
||||||
printf("quit requested");
|
log_debug("quit requested");
|
||||||
this->quit();
|
quit();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(key == int(114))
|
else if(key == key_r)
|
||||||
{
|
{
|
||||||
// gtk_html_load_from_string(GTK_HTML(html_wg), "<html><body>me</body></html>", -1);
|
log_debug("random");
|
||||||
|
|
||||||
show_random();
|
show_random();
|
||||||
printf("random");
|
|
||||||
}
|
}
|
||||||
else if(key == int(115))
|
else if(key == key_s)
|
||||||
{
|
{
|
||||||
|
log_debug("search");
|
||||||
search_window(this);
|
search_window(this);
|
||||||
printf("search");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -73,34 +64,34 @@ bool main_window::actions(int key)
|
|||||||
|
|
||||||
bool main_window::on_my_key_press_event(GdkEventKey *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;
|
ctrl_state = 1;
|
||||||
// printf("ctrl set value nows: %i\n", ctrl_state);
|
}
|
||||||
}else{
|
else
|
||||||
if (ctrl_state == 1){
|
{
|
||||||
// printf("key num: %i", Key->keyval);
|
if (ctrl_state == 1)
|
||||||
this->actions(Key->keyval);
|
{
|
||||||
// printf("\n Key Presssed is %s with ctrl held\n",gdk_keyval_name(Key->keyval));
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool main_window::on_my_key_release_event(GdkEventKey *Key)
|
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;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool main_window::quit()
|
bool main_window::quit()
|
||||||
{
|
{
|
||||||
hide();
|
hide();
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -18,25 +18,22 @@
|
|||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef MAIN_WINDOW_HH
|
||||||
|
#define MAIN_WINDOW_HH
|
||||||
|
|
||||||
#include <gtkmm.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <gdkmm/gc.h>
|
|
||||||
#include <gdk/gdkkeysyms.h>
|
|
||||||
#include <gtkmm/window.h>
|
#include <gtkmm/window.h>
|
||||||
|
|
||||||
class main_window : public Gtk::Window
|
class main_window : public Gtk::Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
main_window();
|
main_window();
|
||||||
~main_window();
|
|
||||||
bool actions(int);
|
|
||||||
int ctrl_state;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool actions(int);
|
||||||
|
int ctrl_state;
|
||||||
bool on_my_key_press_event(GdkEventKey *event);
|
bool on_my_key_press_event(GdkEventKey *event);
|
||||||
bool on_my_key_release_event(GdkEventKey *event);
|
bool on_my_key_release_event(GdkEventKey *event);
|
||||||
bool quit();
|
bool quit();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // MAIN_WINDOW_HH
|
||||||
|
@ -20,12 +20,11 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "search_dialog.hh"
|
#include "search_dialog.hh"
|
||||||
|
#include "vido.hh"
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
|
|
||||||
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);
|
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.add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
|
||||||
dialog.show_all();
|
dialog.show_all();
|
||||||
int result = dialog.run();
|
int result = dialog.run();
|
||||||
if (result == Gtk::RESPONSE_OK) {
|
if (result == Gtk::RESPONSE_OK)
|
||||||
|
{
|
||||||
set_search(entry.get_text().c_str());
|
set_search(entry.get_text().c_str());
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
search_dialog::~search_dialog()
|
|
||||||
{ }
|
|
@ -18,17 +18,17 @@
|
|||||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef SEARCH_DIALOG_HH
|
||||||
|
#define SEARCH_DIALOG_HH
|
||||||
|
|
||||||
#include <gtkmm/dialog.h>
|
#include <gtkmm/dialog.h>
|
||||||
// #include <gtkmm.h>
|
|
||||||
#include <gtkmm/window.h>
|
|
||||||
#include <main_window.hh>
|
|
||||||
|
|
||||||
extern main_window parent;
|
class main_window;
|
||||||
|
|
||||||
class search_dialog : public Gtk::Dialog{
|
|
||||||
|
|
||||||
|
class search_dialog : public Gtk::Dialog
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
search_dialog(main_window* parent, Glib::ustring);
|
search_dialog(main_window* parent, const Glib::ustring&);
|
||||||
~search_dialog();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // SEARCH_DIALOG_HH
|
||||||
|
251
src/vido.cc
251
src/vido.cc
@ -21,54 +21,47 @@
|
|||||||
|
|
||||||
#include <gtkmm.h>
|
#include <gtkmm.h>
|
||||||
#include <zim/file.h>
|
#include <zim/file.h>
|
||||||
#include <zim/fileiterator.h>
|
|
||||||
#include <zim/search.h>
|
#include <zim/search.h>
|
||||||
#include <zim/articlesearch.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <fstream>
|
#include "config.h"
|
||||||
|
#include "vido.hh"
|
||||||
// #include "main_window.hh"
|
#include "main_window.hh"
|
||||||
#include "search_dialog.hh"
|
#include "search_dialog.hh"
|
||||||
|
|
||||||
|
#include <cxxtools/loginit.h>
|
||||||
|
|
||||||
|
log_define("vido.main")
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "gtkhtml/gtkhtml.h"
|
#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 content;
|
||||||
std::string file;
|
std::string fileName;
|
||||||
zim::File f;
|
|
||||||
Window *window;
|
|
||||||
|
|
||||||
Widget *html;
|
Gtk::Widget *html;
|
||||||
GtkWidget *html_wg;
|
GtkWidget *html_wg;
|
||||||
|
|
||||||
static zim::File zimFile;
|
|
||||||
static bool initialized = false;
|
|
||||||
|
|
||||||
// // // misc functions
|
// // // misc functions
|
||||||
|
|
||||||
const zim::File get_file()
|
const zim::File& get_file()
|
||||||
{
|
{
|
||||||
if (!initialized){
|
static zim::File zimFile;
|
||||||
std::cout<<"file not initialized :"<<file<<".\n";
|
if (!zimFile.good())
|
||||||
zim::File zimFile(file);
|
{
|
||||||
initialized = true;
|
log_debug("file not initialized:" << fileName);
|
||||||
}else{
|
zimFile = zim::File(fileName);
|
||||||
std::cout<<"file initialized :"<<file<<".\n";
|
log_debug("number of articles: " << zimFile.getCountArticles());
|
||||||
}
|
}
|
||||||
std::cout<<"returning file"<<".\n";
|
|
||||||
|
log_debug("returning file.");
|
||||||
return zimFile;
|
return zimFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
// // copy article html from while loop into global variable
|
// // copy article html from while loop into global variable
|
||||||
void set_article(std::string txt)
|
void set_article(const std::string& txt)
|
||||||
{
|
{
|
||||||
content = txt;
|
content = txt;
|
||||||
}
|
}
|
||||||
@ -76,47 +69,52 @@ void set_article(std::string txt)
|
|||||||
// // // externally called functions
|
// // // externally called functions
|
||||||
|
|
||||||
// // display random article
|
// // display random article
|
||||||
void show_random(){
|
void show_random()
|
||||||
|
{
|
||||||
|
|
||||||
std::cout<<"random called"<<".\n";
|
log_debug("random called.");
|
||||||
zim::File m = get_file();
|
zim::File m = get_file();
|
||||||
std::cout<<"random got file"<<".\n";
|
|
||||||
|
|
||||||
while(true){
|
static unsigned int seed = static_cast<unsigned int>(time(0));
|
||||||
std::cout<<"random running loop"<<".\n";
|
|
||||||
|
zim::Article article;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
log_debug("random running loop");
|
||||||
zim::size_type idx = static_cast<zim::size_type>(static_cast<double>(m.getCountArticles()) * rand_r(&seed) / RAND_MAX);
|
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);
|
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_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), content.c_str(), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// // display search dialog
|
// // display search dialog
|
||||||
void search_window(main_window *window_x){
|
void search_window(main_window *window_x)
|
||||||
|
{
|
||||||
search_dialog(window_x, " ");
|
search_dialog(window_x, " ");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// // // meta functions
|
// // // meta functions
|
||||||
|
|
||||||
// // set displayed html to given url
|
// // set displayed html to given url
|
||||||
// // FIXME: returns several articles and displays on one page ... why?
|
// // 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
|
// // create ZIM file accessor
|
||||||
zim::File m = get_file();
|
zim::File m = get_file();
|
||||||
|
|
||||||
// // convert url to string
|
// // convert url to string
|
||||||
std::string term;
|
std::string term(url);
|
||||||
term.assign( url );
|
|
||||||
|
|
||||||
// // replace '+' signs with spaces in url
|
// // replace '+' signs with spaces in url
|
||||||
std::replace(term.begin(), term.end(), '+', ' ');
|
std::replace(term.begin(), term.end(), '+', ' ');
|
||||||
@ -124,121 +122,104 @@ void set_html(const gchar *url){
|
|||||||
// // find and declare namespace
|
// // find and declare namespace
|
||||||
size_t found;
|
size_t found;
|
||||||
size_t found2;
|
size_t found2;
|
||||||
char *ns;
|
char ns;
|
||||||
|
|
||||||
found=term.find("/");
|
found=term.find("/");
|
||||||
if (found!=std::string::npos){
|
if (found != std::string::npos)
|
||||||
if (found != (int) 0){
|
{
|
||||||
ns = &term[0];
|
if (found)
|
||||||
term = term.substr(found + 1, strlen(url));
|
{
|
||||||
}else{
|
ns = term[0];
|
||||||
term = term.substr(1, strlen(url));
|
term.erase(found + 1);
|
||||||
ns = &term[0];
|
|
||||||
found2 = term.find("/");
|
|
||||||
term = term.substr(found2 + 1, strlen(url));
|
|
||||||
}
|
}
|
||||||
}else{
|
else
|
||||||
ns = "A";
|
{
|
||||||
|
term.erase(1);
|
||||||
|
ns = term[0];
|
||||||
|
found2 = term.find("/");
|
||||||
|
term.erase(found2 + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ns = 'A';
|
||||||
}
|
}
|
||||||
|
|
||||||
// // try to retrieve article
|
// // try to retrieve article
|
||||||
try {
|
try
|
||||||
zim::File::const_iterator iterator = m.find(ns[0], zim::QUnicodeString(term));
|
{
|
||||||
zim::Article article = m.getArticle(iterator.getIndex());
|
#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.good()) // check if article is really found
|
||||||
if (article.isRedirect())
|
|
||||||
{
|
{
|
||||||
article = article.getRedirectArticle();
|
|
||||||
}
|
|
||||||
|
|
||||||
// // get content html
|
// // get content html
|
||||||
content = article.getData().data();
|
content = article.getPage();
|
||||||
|
|
||||||
// // get article length
|
|
||||||
int length = article.getArticleSize();
|
|
||||||
|
|
||||||
// // limit html output to article length
|
|
||||||
std::string str2 = content.substr (0,length);
|
|
||||||
|
|
||||||
// // emtpy gtkhtml widget
|
// // emtpy gtkhtml widget
|
||||||
gtk_html_flush(GTK_HTML(html_wg));
|
gtk_html_flush(GTK_HTML(html_wg));
|
||||||
|
|
||||||
// // load new data into gtkhtml widget
|
// // load new data into gtkhtml widget
|
||||||
gtk_html_load_from_string(GTK_HTML(html_wg), str2.c_str(), -1);
|
gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1);
|
||||||
std::cout<<"term:"<<term<<".\n";
|
log_debug("term=" << term << " url=" << url);
|
||||||
std::cout<<"url:"<<url<<".\n";
|
}
|
||||||
}catch(...){
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "article \"" << url << "\" not found" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// // test functions
|
// // test functions
|
||||||
void set_search(const gchar *url){
|
void set_search(const gchar *url)
|
||||||
// std::cout<<"url"<<url<<".";
|
{
|
||||||
zim::File z = get_file();
|
zim::File z = get_file();
|
||||||
|
|
||||||
zim::Search::Results result;
|
zim::Search::Results result;
|
||||||
result.clear();
|
|
||||||
zim::Search search(z);
|
zim::Search search(z);
|
||||||
std::string term;
|
std::string term(url);
|
||||||
term.assign( url );
|
|
||||||
std::replace(term.begin(), term.end(), '+', ' ');
|
std::replace(term.begin(), term.end(), '+', ' ');
|
||||||
search.search(result, term);
|
search.search(result, term);
|
||||||
if(result.size() == 0) {
|
if(result.size() == 0)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
else if (result.size() == 1){
|
else if (result.size() == 1)
|
||||||
|
{
|
||||||
zim::Article article = z.getArticle(result[0].getArticle().getIndex());
|
zim::Article article = z.getArticle(result[0].getArticle().getIndex());
|
||||||
|
|
||||||
std::string content = article.getPage(false, 10);
|
content = article.getPage(false, 10);
|
||||||
|
|
||||||
gtk_html_flush(GTK_HTML(html_wg));
|
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), content.c_str(), -1);
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
std::string res;
|
std::string res;
|
||||||
for (unsigned i = 0; i < result.size(); ++i) {
|
for (unsigned i = 0; i < result.size(); ++i)
|
||||||
|
{
|
||||||
|
#if HAVE_ZIM_QUNICODE_H
|
||||||
res += "<li><a href=" + result[i].getArticle().getUrl().toXML() + ">" + result[i].getArticle().getTitle().toXML() + "</a></li>";
|
res += "<li><a href=" + result[i].getArticle().getUrl().toXML() + ">" + result[i].getArticle().getTitle().toXML() + "</a></li>";
|
||||||
|
#else
|
||||||
|
res += "<li><a href=" + result[i].getArticle().getUrl() + ">" + result[i].getArticle().getTitle() + "</a></li>";
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_html_flush(GTK_HTML(html_wg));
|
gtk_html_flush(GTK_HTML(html_wg));
|
||||||
gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1);
|
gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1);
|
||||||
|
|
||||||
}
|
}
|
||||||
// char* ns = "A";
|
|
||||||
|
|
||||||
// try {
|
log_debug(url);
|
||||||
// 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<<".\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void articles2file(){
|
|
||||||
|
|
||||||
std::ofstream myfile;
|
|
||||||
myfile.open ("articles.txt");
|
|
||||||
zim::File f = get_file();
|
|
||||||
for (zim::File::const_iterator it = f.begin(); it != f.end(); ++it)
|
|
||||||
{
|
|
||||||
myfile << it->getUrl() << '\n';
|
|
||||||
}
|
|
||||||
myfile.close();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // // window response functions
|
// // // window response functions
|
||||||
|
|
||||||
// // open requested link
|
// // open requested link
|
||||||
@ -255,13 +236,17 @@ bool on_link_clicked(GtkHTML *html, const gchar *url)
|
|||||||
// // main function
|
// // main function
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
log_init();
|
||||||
|
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
{
|
{
|
||||||
file = argv[1];
|
fileName = argv[1];
|
||||||
|
|
||||||
std::cout<<"vido is here file:"<<file<<".\n";
|
log_debug("vido is here file: " << fileName);
|
||||||
|
|
||||||
Main kit(argc, argv);
|
Gtk::Main kit(argc, argv);
|
||||||
|
|
||||||
main_window window;
|
main_window window;
|
||||||
window.set_title("Vido");
|
window.set_title("Vido");
|
||||||
@ -276,23 +261,27 @@ int main(int argc, char **argv)
|
|||||||
gtk_html_set_caret_mode(GTK_HTML(html_wg),true);
|
gtk_html_set_caret_mode(GTK_HTML(html_wg),true);
|
||||||
|
|
||||||
|
|
||||||
ScrolledWindow scrolled_window;
|
Gtk::ScrolledWindow scrolled_window;
|
||||||
|
|
||||||
scrolled_window.add(*html);
|
scrolled_window.add(*html);
|
||||||
scrolled_window.set_policy(POLICY_NEVER, POLICY_AUTOMATIC);
|
scrolled_window.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
|
||||||
|
|
||||||
window.add(scrolled_window);
|
window.add(scrolled_window);
|
||||||
window.show_all();
|
window.show_all();
|
||||||
|
|
||||||
show_random();
|
show_random();
|
||||||
// articles2file();
|
Gtk::Main::run(window);
|
||||||
// set_berlin();
|
|
||||||
Main::run(window);
|
|
||||||
}else{
|
|
||||||
std::cout<<"You provided too many or too few arguments("<< argc <<").\n";
|
|
||||||
std::cout<<"Vido is to be used as follows:"<<".\n";
|
|
||||||
std::cout<<"vido [PATH TO ZIM FILE]"<<".\n";
|
|
||||||
}
|
}
|
||||||
return 0;
|
else
|
||||||
|
{
|
||||||
|
std::cout << "usage: " << argv[0] << " [PATH TO ZIM FILE]" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user