Date:2010-02-20 20:45:52 (10 years 5 months ago)
Author:Mirko Lindner
Commit:e7a817a3c761458affaf9b3f5e677a6cbe47d5d4
Message:implement help function

Signed-off-by: Mirko Lindner <mirko@sharism.cc>
Files: src/vido.cc (8 diffs)

Change Details

src/vido.cc
4444// std::string content;
4545std::string fileName;
4646
47main_window *window;
47//TODO this can't be right
48main_window *window2;
49Gtk::ScrolledWindow *scrolled_window2;
50
51
4852Gtk::Widget *html;
4953GtkWidget *html_wg;
5054std::vector < std::pair< std::string, std::string > > history;
5155unsigned int position = 0;
5256bool historyCall = false;
57// variable to keep url of currently displayed article
58std::string current_url = "";
5359
5460// // // misc functions
5561// get zimFile, if not already opened, open file
5662const zim::File& get_file()
5763{
5864  static zim::File zimFile;
65
5966  if (!zimFile.good())
6067  {
6168    log_debug("file not initialized:" << fileName);
...... 
7077// display message in gtk window
7178void show_message(std::string title, std::string txt)
7279{
73    message_dialog(window, title, txt);
80    message_dialog(window2, title, txt);
81}
82
83void show_help()
84{
85        log_debug("displaying help");
86        std::string title = "Help";
87        std::string txt = "Usage: \n";
88        txt += "Ctrl + R = Display random article\n";
89        txt += "Ctrl + S = Search for article\n";
90        txt += "Ctrl + T = Go to articles top\n";
91        txt += "Tab = Rotate through links\n";
92        txt += "Enter = Activate link\n";
93        txt += "Ctrl + H = Display history\n";
94        txt += "Ctrl + B = Go back in history\n";
95        txt += "Ctrl + F = Go forward in history\n";
96        txt += "Ctrl + Q = Quit Vido\n";
97        txt += "F1 = Display this help\n";
98        show_message(title, txt);
7499}
75100
76101// fill gtkhtml widget with new content
77//TODO prepend "top" anchor on html
102
78103void fill_gtkhtml(std::string& html, std::string url, std::string title){
79104    log_debug("fill gtkhtml called with " << url << " and " << title);
80105    std::string ccontent;
81106    ccontent = "<a name=\"top\"></a>" + html;
82107    gtk_html_flush(GTK_HTML(html_wg));
83108    gtk_html_load_from_string(GTK_HTML(html_wg), ccontent.c_str(), -1);
84
109    current_url = url;
85110    if ((url != "") && title != ""){
86111      if (position == 0){
87112        log_debug("adding " << title << " to history");
...... 
102127      }
103128
104129    }
130// gtk_html_get_selection_html(GTK_HTML(html_wg), )
131        while( Gtk::Main::events_pending() ){
132                Gtk::Main::iteration();
133        }
134        window2->connect_all();
105135
106136}
107137
...... 
162192// // display random article
163193void show_random()
164194{
165
166    log_debug("random called.");
195// window2->disconnect_all();
196    log_debug("random called. window all disconnected");
167197    zim::File m = get_file();
168
169    unsigned int seed = static_cast<unsigned int>(time(0));
170    zim::size_type idx = static_cast<zim::size_type>(static_cast<double>(m.getCountArticles()) * rand_r(&seed) / RAND_MAX);
171    zim::Article article;
172
173    article = m.getArticle(idx);
174
175    //loop in case article is redirect
176    do
177    {
178        article = article.getRedirectArticle();
179    }while(article.isRedirect());
198        zim::Article article;
199    do
200        {
201                unsigned int seed = static_cast<unsigned int>(time(0));
202                zim::size_type idx = static_cast<zim::size_type>(static_cast<double>(m.getCountArticles()) * rand_r(&seed) / RAND_MAX);
203
204                article = m.getArticle(idx);
205
206                //loop in case article is redirect
207                do
208                {
209                        article = article.getRedirectArticle();
210                }while(article.isRedirect());
180211
212        }while(article.getUrl() == current_url);
213
181214    std::string res = article.getPage();
182215
183216    log_debug("article size=" << res.size());
...... 
185218    log_debug("article namespace=" << article.getNamespace());
186219    position = 0;
187220    fill_gtkhtml(res, article.getUrl(), article.getTitle());
221        log_debug("random called. window all connected");
188222}
189223
190224// // display search dialog
191225void search_window(main_window *window_x)
192226{
227// html_color = html_color_new_from_rgb('255','0','0');
228// gtk_html_set_color(GTK_HTML(html_wg),html_color);
193229    search_dialog(window_x, " ");
194230}
195231
...... 
247283// // try to retrieve article
248284    try
249285    {
250#if HAVE_ZIM_QUNICODE_H
251        zim::Article article = m.getArticle(ns, zim::QUnicodeString(term));
252#else
286// #if HAVE_ZIM_QUNICODE_H
287// zim::Article article = m.getArticle(ns, zim::QUnicodeString(term));
288// #else
253289        zim::Article article = m.getArticle(ns, term);
254#endif
290// #endif
255291
256292        if (article.good()) // check if article is really found
257293        {
...... 
314350        log_debug("more than one article in result");
315351        for (unsigned i = 0; i < result.size(); ++i)
316352        {
317#if HAVE_ZIM_QUNICODE_H
318          res += "<li><a href=" + result[i].getArticle().getLongUrl().toXML() + ">" + result[i].getArticle().getLongUrl().toXML() + "</a></li>";
319#else
353// #if HAVE_ZIM_QUNICODE_H
354// res += "<li><a href=" + result[i].getArticle().getLongUrl().toXML() + ">" + result[i].getArticle().getLongUrl().toXML() + "</a></li>";
355// #else
320356          res += "<li><a href='" + result[i].getArticle().getUrl() + "'>" + result[i].getArticle().getUrl() + "</a></li>";
321#endif
357// #endif
322358        }
323359        url = "";
324360        title = "";
...... 
385421  // window.set_border_width(0);
386422      window.set_default_size(220, 240);
387423  // window.set_resizable(0);
388
424            window.connect_all();
389425      html_wg = gtk_html_new();
390
426      window2 = &window;
391427      html = Glib::wrap(html_wg);
392428      g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL );
393429      g_signal_connect( G_OBJECT( html_wg ), "scroll", G_CALLBACK( scrolled ), NULL );
394430      gtk_html_set_caret_mode(GTK_HTML(html_wg),false);
395431// gtk_html_adjust_cursor_position(GTK_HTML(html_wg));
396      static Gtk::ScrolledWindow scrolled_window;
432      Gtk::ScrolledWindow scrolled_window;
433            scrolled_window2 = &scrolled_window;
397434      scrolled_window.add(*html);
398435      scrolled_window.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
399436
400437      window.add(scrolled_window);
401438      window.show_all();
402
439
403440      show_random();
404441      gtk_html_edit_make_cursor_visible(GTK_HTML(html_wg));
405442      Gtk::Main::run(window);

Archive Download the corresponding diff file

Branches:
development
master



interactive