diff --git a/src/vido.cc b/src/vido.cc
index 29c7933..6757280 100644
--- a/src/vido.cc
+++ b/src/vido.cc
@@ -44,18 +44,25 @@ extern "C" {
// std::string content;
std::string fileName;
-main_window *window;
+//TODO this can't be right
+main_window *window2;
+Gtk::ScrolledWindow *scrolled_window2;
+
+
Gtk::Widget *html;
GtkWidget *html_wg;
std::vector < std::pair< std::string, std::string > > history;
unsigned int position = 0;
bool historyCall = false;
+// variable to keep url of currently displayed article
+std::string current_url = "";
// // // misc functions
// get zimFile, if not already opened, open file
const zim::File& get_file()
{
static zim::File zimFile;
+
if (!zimFile.good())
{
log_debug("file not initialized:" << fileName);
@@ -70,18 +77,36 @@ const zim::File& get_file()
// display message in gtk window
void show_message(std::string title, std::string txt)
{
- message_dialog(window, title, txt);
+ message_dialog(window2, title, txt);
+}
+
+void show_help()
+{
+ log_debug("displaying help");
+ std::string title = "Help";
+ std::string txt = "Usage: \n";
+ txt += "Ctrl + R = Display random article\n";
+ txt += "Ctrl + S = Search for article\n";
+ txt += "Ctrl + T = Go to articles top\n";
+ txt += "Tab = Rotate through links\n";
+ txt += "Enter = Activate link\n";
+ txt += "Ctrl + H = Display history\n";
+ txt += "Ctrl + B = Go back in history\n";
+ txt += "Ctrl + F = Go forward in history\n";
+ txt += "Ctrl + Q = Quit Vido\n";
+ txt += "F1 = Display this help\n";
+ show_message(title, txt);
}
// fill gtkhtml widget with new content
-//TODO prepend "top" anchor on html
+
void fill_gtkhtml(std::string& html, std::string url, std::string title){
log_debug("fill gtkhtml called with " << url << " and " << title);
std::string ccontent;
ccontent = "" + html;
gtk_html_flush(GTK_HTML(html_wg));
gtk_html_load_from_string(GTK_HTML(html_wg), ccontent.c_str(), -1);
-
+ current_url = url;
if ((url != "") && title != ""){
if (position == 0){
log_debug("adding " << title << " to history");
@@ -102,6 +127,11 @@ void fill_gtkhtml(std::string& html, std::string url, std::string title){
}
}
+// gtk_html_get_selection_html(GTK_HTML(html_wg), )
+ while( Gtk::Main::events_pending() ){
+ Gtk::Main::iteration();
+ }
+ window2->connect_all();
}
@@ -162,22 +192,25 @@ void history_jump(int jumper){
// // display random article
void show_random()
{
-
- log_debug("random called.");
+// window2->disconnect_all();
+ log_debug("random called. window all disconnected");
zim::File m = get_file();
-
- unsigned int seed = static_cast(time(0));
- zim::size_type idx = static_cast(static_cast(m.getCountArticles()) * rand_r(&seed) / RAND_MAX);
- zim::Article article;
-
- article = m.getArticle(idx);
-
- //loop in case article is redirect
- do
- {
- article = article.getRedirectArticle();
- }while(article.isRedirect());
+ zim::Article article;
+ do
+ {
+ unsigned int seed = static_cast(time(0));
+ zim::size_type idx = static_cast(static_cast(m.getCountArticles()) * rand_r(&seed) / RAND_MAX);
+
+ article = m.getArticle(idx);
+
+ //loop in case article is redirect
+ do
+ {
+ article = article.getRedirectArticle();
+ }while(article.isRedirect());
+ }while(article.getUrl() == current_url);
+
std::string res = article.getPage();
log_debug("article size=" << res.size());
@@ -185,11 +218,14 @@ void show_random()
log_debug("article namespace=" << article.getNamespace());
position = 0;
fill_gtkhtml(res, article.getUrl(), article.getTitle());
+ log_debug("random called. window all connected");
}
// // display search dialog
void search_window(main_window *window_x)
{
+// html_color = html_color_new_from_rgb('255','0','0');
+// gtk_html_set_color(GTK_HTML(html_wg),html_color);
search_dialog(window_x, " ");
}
@@ -247,11 +283,11 @@ void getArticleFromUrl(const gchar *url, int pos = 0)
// // try to retrieve article
try
{
-#if HAVE_ZIM_QUNICODE_H
- zim::Article article = m.getArticle(ns, zim::QUnicodeString(term));
-#else
+// #if HAVE_ZIM_QUNICODE_H
+// zim::Article article = m.getArticle(ns, zim::QUnicodeString(term));
+// #else
zim::Article article = m.getArticle(ns, term);
-#endif
+// #endif
if (article.good()) // check if article is really found
{
@@ -314,11 +350,11 @@ void getArticleFromTitle(const gchar *phrase)
log_debug("more than one article in result");
for (unsigned i = 0; i < result.size(); ++i)
{
-#if HAVE_ZIM_QUNICODE_H
- res += "" + result[i].getArticle().getLongUrl().toXML() + "";
-#else
+// #if HAVE_ZIM_QUNICODE_H
+// res += "" + result[i].getArticle().getLongUrl().toXML() + "";
+// #else
res += "" + result[i].getArticle().getUrl() + "";
-#endif
+// #endif
}
url = "";
title = "";
@@ -385,21 +421,22 @@ int main(int argc, char **argv)
// window.set_border_width(0);
window.set_default_size(220, 240);
// window.set_resizable(0);
-
+ window.connect_all();
html_wg = gtk_html_new();
-
+ window2 = &window;
html = Glib::wrap(html_wg);
g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL );
g_signal_connect( G_OBJECT( html_wg ), "scroll", G_CALLBACK( scrolled ), NULL );
gtk_html_set_caret_mode(GTK_HTML(html_wg),false);
// gtk_html_adjust_cursor_position(GTK_HTML(html_wg));
- static Gtk::ScrolledWindow scrolled_window;
+ Gtk::ScrolledWindow scrolled_window;
+ scrolled_window2 = &scrolled_window;
scrolled_window.add(*html);
scrolled_window.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
window.add(scrolled_window);
window.show_all();
-
+
show_random();
gtk_html_edit_make_cursor_visible(GTK_HTML(html_wg));
Gtk::Main::run(window);