Date: | 2010-01-22 17:33:35 (11 years 2 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 | ||
---|---|---|
24 | 24 | #include <zim/search.h> |
25 | 25 | #include <iostream> |
26 | 26 | #include <string> |
27 | // #include <fstream> | |
27 | 28 | |
28 | 29 | #include "config.h" |
29 | 30 | #include "message_dialog.hh" |
... | ... | |
56 | 57 | log_debug("file not initialized:" << fileName); |
57 | 58 | zimFile = zim::File(fileName); |
58 | 59 | log_debug("number of articles: " << zimFile.getCountArticles()); |
60 | ||
59 | 61 | } |
60 | 62 | |
61 | 63 | log_debug("returning file."); |
... | ... | |
67 | 69 | message_dialog(window, title, txt); |
68 | 70 | } |
69 | 71 | |
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 | ||
70 | 79 | // // copy article html from while loop into global variable |
71 | 80 | void set_article(const std::string& txt) |
72 | 81 | { |
... | ... | |
82 | 91 | log_debug("random called."); |
83 | 92 | zim::File m = get_file(); |
84 | 93 | |
85 | static unsigned int seed = static_cast<unsigned int>(time(0)); | |
94 | unsigned int seed = static_cast<unsigned int>(time(0)); | |
86 | 95 | zim::size_type idx = static_cast<zim::size_type>(static_cast<double>(m.getCountArticles()) * rand_r(&seed) / RAND_MAX); |
87 | 96 | zim::Article article; |
88 | 97 | |
... | ... | |
98 | 107 | |
99 | 108 | content = article.getPage(); |
100 | 109 | log_debug("article size=" << content.size()); |
101 | ||
110 | log_debug("article title=" << article.getTitle()); | |
111 | log_debug("article namespace=" << article.getNamespace()); | |
112 | ||
102 | 113 | gtk_html_flush(GTK_HTML(html_wg)); |
103 | 114 | gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1); |
115 | log_debug("html \n" << res.c_str()); | |
104 | 116 | } |
105 | 117 | |
106 | 118 | // // display search dialog |
... | ... | |
177 | 189 | else |
178 | 190 | { |
179 | 191 | std::cerr << "article \"" << url << "\" not found" << std::endl; |
192 | show_message("Error", "The article you requested (" + term + ") was not found."); | |
180 | 193 | } |
181 | 194 | } |
182 | 195 | catch (const std::exception& e) |
... | ... | |
189 | 202 | // // test functions |
190 | 203 | void set_search(const gchar *url) |
191 | 204 | { |
205 | char ns; | |
206 | ns = 'A'; | |
192 | 207 | zim::File z = get_file(); |
193 | 208 | |
194 | 209 | zim::Search::Results result; |
195 | 210 | zim::Search search(z); |
196 | 211 | 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) | |
200 | 215 | { |
201 | 216 | 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){ | |
205 | 219 | zim::Article article = z.getArticle(result[0].getArticle().getIndex()); |
206 | 220 | |
207 | 221 | content = article.getPage(false, 10); |
... | ... | |
215 | 229 | for (unsigned i = 0; i < result.size(); ++i) |
216 | 230 | { |
217 | 231 | #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>"; | |
219 | 233 | #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>"; | |
221 | 235 | #endif |
222 | 236 | } |
223 | 237 | |
224 | 238 | gtk_html_flush(GTK_HTML(html_wg)); |
225 | 239 | gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1); |
226 | // window.resize(220, 140); | |
227 | 240 | |
228 | 241 | } |
229 | 242 | |
... | ... | |
236 | 249 | // FIXME show error window when dead-link requested |
237 | 250 | bool on_link_clicked(GtkHTML *html, const gchar *url) |
238 | 251 | { |
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 | ||
242 | 271 | return true; |
243 | 272 | } |
244 | 273 | |
... | ... | |
269 | 298 | html = Glib::wrap(html_wg); |
270 | 299 | g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL ); |
271 | 300 | 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; | |
276 | 303 | scrolled_window.add(*html); |
277 | 304 | scrolled_window.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC); |
278 | 305 |
Branches:
development
master