1
0
mirror of git://projects.qi-hardware.com/vido.git synced 2024-11-01 06:33:09 +02:00

add search function and display for list of results

Signed-off-by: Mirko Lindner <mirko@qi-hardware.com>
This commit is contained in:
Mirko Lindner 2009-10-30 14:13:07 +01:00
parent d82627dc08
commit bc67739281
3 changed files with 42 additions and 27 deletions

View File

@ -33,7 +33,6 @@ class main_window : public Gtk::Window
~main_window();
bool actions(int);
int ctrl_state;
// void search_dialog();
private:
bool on_my_key_press_event(GdkEventKey *event);

View File

@ -23,6 +23,7 @@
#include <gtkmm.h>
extern void set_html(const gchar *url);
extern void set_search(const gchar *url);
search_dialog::search_dialog(main_window* parent, Glib::ustring input="")
{
@ -39,7 +40,7 @@ search_dialog::search_dialog(main_window* parent, Glib::ustring input="")
dialog.show_all();
int result = dialog.run();
if (result == Gtk::RESPONSE_OK) {
set_html(entry.get_text().c_str());
set_search(entry.get_text().c_str());
} else {
}

View File

@ -110,6 +110,7 @@ void set_html(const gchar *url){
if (found!=std::string::npos){
if (found != (int) 0){
ns = &term[0];
term = term.substr(found + 1, strlen(url));
}else{
term = term.substr(1, strlen(url));
ns = &term[0];
@ -153,39 +154,53 @@ void set_html(const gchar *url){
// // test functions
void set_berlin(const gchar *url){
void set_search(const gchar *url){
// std::cout<<"url"<<url<<".";
zim::File z(file);
// zim::Search::Results result;
// result.clear();
// zim::Search search(m);
zim::Search::Results result;
result.clear();
zim::Search search(z);
std::string term;
term.assign( url );
// search.search(result, term);
// if (result.size() > 0){
// zim::Article article = m.getArticle(result[0].getArticle().getIndex());
//
// std::string content = article.getPage(false, 10);
//
// gtk_html_flush(GTK_HTML(html_wg));
// gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1);
// }
std::replace(term.begin(), term.end(), '+', ' ');
char* ns = "A";
try {
zim::File::const_iterator iterator = z.find(ns[0], zim::QUnicodeString(term));
zim::Article article = z.getArticle(iterator.getIndex());
if (article.isRedirect())
{
article = article.getRedirectArticle();
search.search(result, term);
if(result.size() == 0) {
}
content = article.getData().data();
else if (result.size() == 1){
zim::Article article = z.getArticle(result[0].getArticle().getIndex());
std::string content = article.getPage(false, 10);
gtk_html_flush(GTK_HTML(html_wg));
gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1);
}catch(...){
}else{
std::string res;
for (unsigned i = 0; i < result.size(); ++i) {
res += "<li><a href=" + result[i].getArticle().getUrl().toXML() + ">" + result[i].getArticle().getTitle().toXML() + "</a></li>";
}
gtk_html_flush(GTK_HTML(html_wg));
gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1);
}
// char* ns = "A";
// try {
// zim::File::const_iterator iterator = z.find(ns[0], zim::QUnicodeString(term));
// zim::Article article = z.getArticle(iterator.getIndex());
// if (article.isRedirect())
// {
// article = article.getRedirectArticle();
// }
// content = article.getData().data();
// gtk_html_flush(GTK_HTML(html_wg));
// gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1);
// }catch(...){
// }
std::cout<<url<<".\n";
}