Date:2010-01-22 17:33:35 (10 years 6 months ago)
Author:Mirko Lindner
Commit:c4b1f2b48298f187cb18255220c191fc404e1203
Message:adapt search to new zimlib and make anchor jump work

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

Change Details

src/vido.cc
2424#include <zim/search.h>
2525#include <iostream>
2626#include <string>
27// #include <fstream>
2728
2829#include "config.h"
2930#include "message_dialog.hh"
...... 
5657    log_debug("file not initialized:" << fileName);
5758    zimFile = zim::File(fileName);
5859    log_debug("number of articles: " << zimFile.getCountArticles());
60
5961  }
6062
6163  log_debug("returning file.");
...... 
6769    message_dialog(window, title, txt);
6870}
6971
72// void page_move(int val){
73// Gtk::Adjustment *vertical = scrolled_window.get_vadjustment();
74// double page_size = vertical->get_page_size();
75// double value = vertical->get_value();
76// vertical->set_value(value + (val * page_size));
77// }
78
7079// // copy article html from while loop into global variable
7180void set_article(const std::string& txt)
7281{
...... 
8291    log_debug("random called.");
8392    zim::File m = get_file();
8493
85    static unsigned int seed = static_cast<unsigned int>(time(0));
94    unsigned int seed = static_cast<unsigned int>(time(0));
8695    zim::size_type idx = static_cast<zim::size_type>(static_cast<double>(m.getCountArticles()) * rand_r(&seed) / RAND_MAX);
8796    zim::Article article;
8897
...... 
98107
99108    content = article.getPage();
100109    log_debug("article size=" << content.size());
101
110    log_debug("article title=" << article.getTitle());
111    log_debug("article namespace=" << article.getNamespace());
112
102113    gtk_html_flush(GTK_HTML(html_wg));
103114    gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1);
115    log_debug("html \n" << res.c_str());
104116}
105117
106118// // display search dialog
...... 
177189        else
178190        {
179191            std::cerr << "article \"" << url << "\" not found" << std::endl;
192            show_message("Error", "The article you requested (" + term + ") was not found.");
180193        }
181194    }
182195    catch (const std::exception& e)
...... 
189202// // test functions
190203void set_search(const gchar *url)
191204{
205    char ns;
206    ns = 'A';
192207    zim::File z = get_file();
193208
194209    zim::Search::Results result;
195210    zim::Search search(z);
196211    std::string term(url);
197    std::replace(term.begin(), term.end(), '+', ' ');
198    search.search(result, term);
199    if(result.size() == 0)
212    search.setSearchLimit(25);
213    search.find(result, ns, term);
214    if( result.size() == 0)
200215    {
201216        show_message("Error", "The article you requested (" + term + ") was not found.");
202    }
203    else if (result.size() == 1)
204    {
217
218    }else if (result.size() == 1){
205219        zim::Article article = z.getArticle(result[0].getArticle().getIndex());
206220
207221        content = article.getPage(false, 10);
...... 
215229        for (unsigned i = 0; i < result.size(); ++i)
216230        {
217231#if HAVE_ZIM_QUNICODE_H
218          res += "<li><a href=" + result[i].getArticle().getUrl().toXML() + ">" + result[i].getArticle().getTitle().toXML() + "</a></li>";
232          res += "<li><a href=" + result[i].getArticle().getLongUrl().toXML() + ">" + result[i].getArticle().getLongUrl().toXML() + "</a></li>";
219233#else
220          res += "<li><a href=" + result[i].getArticle().getUrl() + ">" + result[i].getArticle().getTitle() + "</a></li>";
234          res += "<li><a href='" + result[i].getArticle().getUrl() + "'>" + result[i].getArticle().getUrl() + "</a></li>";
221235#endif
222236        }
223237
224238        gtk_html_flush(GTK_HTML(html_wg));
225239        gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1);
226// window.resize(220, 140);
227240
228241    }
229242
...... 
236249// FIXME show error window when dead-link requested
237250bool on_link_clicked(GtkHTML *html, const gchar *url)
238251{
239
240    set_html(url);
241// window.resize(220, 140);
252    std::string term(url);
253    size_t found;
254    found=term.find("#");
255    if (found != std::string::npos){
256
257      if (found == 0){
258        term.erase(0, 1);
259        bool success = gtk_html_jump_to_anchor(GTK_HTML(html_wg), const_cast<char*>(term.c_str()));
260        log_debug("jump to " << term << "worked: " << success);
261      }else{
262        term = term.substr(0, found);
263        //TODO make "set_html" func accept anchor name
264        set_html(const_cast<char*>(term.c_str()));
265      }
266
267    }else{
268      set_html(url);
269    }
270
242271    return true;
243272}
244273
...... 
269298      html = Glib::wrap(html_wg);
270299      g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL );
271300      gtk_html_set_caret_mode(GTK_HTML(html_wg),true);
272
273
274      Gtk::ScrolledWindow scrolled_window;
275
301
302      static Gtk::ScrolledWindow scrolled_window;
276303      scrolled_window.add(*html);
277304      scrolled_window.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
278305

Archive Download the corresponding diff file

Branches:
development
master



interactive