mirror of
git://projects.qi-hardware.com/vido.git
synced 2024-12-22 20:29:53 +02:00
adapt search to new zimlib and make anchor jump work
Signed-off-by: Mirko Lindner <mirko@sharism.cc>
This commit is contained in:
parent
f6d6448cfb
commit
c4b1f2b482
55
src/vido.cc
55
src/vido.cc
@ -24,6 +24,7 @@
|
|||||||
#include <zim/search.h>
|
#include <zim/search.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
// #include <fstream>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "message_dialog.hh"
|
#include "message_dialog.hh"
|
||||||
@ -56,6 +57,7 @@ const zim::File& get_file()
|
|||||||
log_debug("file not initialized:" << fileName);
|
log_debug("file not initialized:" << fileName);
|
||||||
zimFile = zim::File(fileName);
|
zimFile = zim::File(fileName);
|
||||||
log_debug("number of articles: " << zimFile.getCountArticles());
|
log_debug("number of articles: " << zimFile.getCountArticles());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log_debug("returning file.");
|
log_debug("returning file.");
|
||||||
@ -67,6 +69,13 @@ void show_message(std::string title, std::string txt)
|
|||||||
message_dialog(window, title, txt);
|
message_dialog(window, title, txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// void page_move(int val){
|
||||||
|
// Gtk::Adjustment *vertical = scrolled_window.get_vadjustment();
|
||||||
|
// double page_size = vertical->get_page_size();
|
||||||
|
// double value = vertical->get_value();
|
||||||
|
// vertical->set_value(value + (val * page_size));
|
||||||
|
// }
|
||||||
|
|
||||||
// // copy article html from while loop into global variable
|
// // copy article html from while loop into global variable
|
||||||
void set_article(const std::string& txt)
|
void set_article(const std::string& txt)
|
||||||
{
|
{
|
||||||
@ -82,7 +91,7 @@ void show_random()
|
|||||||
log_debug("random called.");
|
log_debug("random called.");
|
||||||
zim::File m = get_file();
|
zim::File m = get_file();
|
||||||
|
|
||||||
static unsigned int seed = static_cast<unsigned int>(time(0));
|
unsigned int seed = static_cast<unsigned int>(time(0));
|
||||||
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;
|
zim::Article article;
|
||||||
|
|
||||||
@ -98,9 +107,12 @@ void show_random()
|
|||||||
|
|
||||||
content = article.getPage();
|
content = article.getPage();
|
||||||
log_debug("article size=" << content.size());
|
log_debug("article size=" << content.size());
|
||||||
|
log_debug("article title=" << article.getTitle());
|
||||||
|
log_debug("article namespace=" << article.getNamespace());
|
||||||
|
|
||||||
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);
|
||||||
|
log_debug("html \n" << res.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// // display search dialog
|
// // display search dialog
|
||||||
@ -177,6 +189,7 @@ void set_html(const gchar *url)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "article \"" << url << "\" not found" << std::endl;
|
std::cerr << "article \"" << url << "\" not found" << std::endl;
|
||||||
|
show_message("Error", "The article you requested (" + term + ") was not found.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
@ -189,19 +202,20 @@ void set_html(const gchar *url)
|
|||||||
// // test functions
|
// // test functions
|
||||||
void set_search(const gchar *url)
|
void set_search(const gchar *url)
|
||||||
{
|
{
|
||||||
|
char ns;
|
||||||
|
ns = 'A';
|
||||||
zim::File z = get_file();
|
zim::File z = get_file();
|
||||||
|
|
||||||
zim::Search::Results result;
|
zim::Search::Results result;
|
||||||
zim::Search search(z);
|
zim::Search search(z);
|
||||||
std::string term(url);
|
std::string term(url);
|
||||||
std::replace(term.begin(), term.end(), '+', ' ');
|
search.setSearchLimit(25);
|
||||||
search.search(result, term);
|
search.find(result, ns, term);
|
||||||
if(result.size() == 0)
|
if( result.size() == 0)
|
||||||
{
|
{
|
||||||
show_message("Error", "The article you requested (" + term + ") was not found.");
|
show_message("Error", "The article you requested (" + term + ") was not found.");
|
||||||
}
|
|
||||||
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());
|
||||||
|
|
||||||
content = article.getPage(false, 10);
|
content = article.getPage(false, 10);
|
||||||
@ -215,15 +229,14 @@ void set_search(const gchar *url)
|
|||||||
for (unsigned i = 0; i < result.size(); ++i)
|
for (unsigned i = 0; i < result.size(); ++i)
|
||||||
{
|
{
|
||||||
#if HAVE_ZIM_QUNICODE_H
|
#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().getLongUrl().toXML() + ">" + result[i].getArticle().getLongUrl().toXML() + "</a></li>";
|
||||||
#else
|
#else
|
||||||
res += "<li><a href=" + result[i].getArticle().getUrl() + ">" + result[i].getArticle().getTitle() + "</a></li>";
|
res += "<li><a href='" + result[i].getArticle().getUrl() + "'>" + result[i].getArticle().getUrl() + "</a></li>";
|
||||||
#endif
|
#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);
|
||||||
// window.resize(220, 140);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,9 +249,25 @@ void set_search(const gchar *url)
|
|||||||
// FIXME show error window when dead-link requested
|
// FIXME show error window when dead-link requested
|
||||||
bool on_link_clicked(GtkHTML *html, const gchar *url)
|
bool on_link_clicked(GtkHTML *html, const gchar *url)
|
||||||
{
|
{
|
||||||
|
std::string term(url);
|
||||||
|
size_t found;
|
||||||
|
found=term.find("#");
|
||||||
|
if (found != std::string::npos){
|
||||||
|
|
||||||
|
if (found == 0){
|
||||||
|
term.erase(0, 1);
|
||||||
|
bool success = gtk_html_jump_to_anchor(GTK_HTML(html_wg), const_cast<char*>(term.c_str()));
|
||||||
|
log_debug("jump to " << term << "worked: " << success);
|
||||||
|
}else{
|
||||||
|
term = term.substr(0, found);
|
||||||
|
//TODO make "set_html" func accept anchor name
|
||||||
|
set_html(const_cast<char*>(term.c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
set_html(url);
|
set_html(url);
|
||||||
// window.resize(220, 140);
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,9 +299,7 @@ int main(int argc, char **argv)
|
|||||||
g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL );
|
g_signal_connect( G_OBJECT( html_wg ), "link_clicked", G_CALLBACK( on_link_clicked ), NULL );
|
||||||
gtk_html_set_caret_mode(GTK_HTML(html_wg),true);
|
gtk_html_set_caret_mode(GTK_HTML(html_wg),true);
|
||||||
|
|
||||||
|
static Gtk::ScrolledWindow scrolled_window;
|
||||||
Gtk::ScrolledWindow scrolled_window;
|
|
||||||
|
|
||||||
scrolled_window.add(*html);
|
scrolled_window.add(*html);
|
||||||
scrolled_window.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
|
scrolled_window.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user