1
0
mirror of git://projects.qi-hardware.com/vido.git synced 2024-12-22 15:34:35 +02:00

refactoring and function rename

Signed-off-by: Mirko Lindner <mirko@sharism.cc>
This commit is contained in:
Mirko Lindner 2010-01-23 17:58:51 +01:00
parent c4b1f2b482
commit 556e12ff0d
3 changed files with 42 additions and 38 deletions

View File

@ -40,7 +40,7 @@ search_dialog::search_dialog(main_window* parent, const Glib::ustring& input)
int result = dialog.run();
if (result == Gtk::RESPONSE_OK)
{
set_search(entry.get_text().c_str());
getArticleFromTitle(entry.get_text().c_str());
}
}

View File

@ -48,7 +48,7 @@ Gtk::Widget *html;
GtkWidget *html_wg;
// // // misc functions
// get zimFile, if not already opened, open file
const zim::File& get_file()
{
static zim::File zimFile;
@ -64,18 +64,21 @@ const zim::File& get_file()
return zimFile;
}
// display message in gtk window
void show_message(std::string title, std::string 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));
// }
// fill gtkhtml widget with new content
//TODO prepend "top" anchor on html
void fill_gtkhtml(std::string& html){
log_debug("fill gtkhtml called");
gtk_html_flush(GTK_HTML(html_wg));
gtk_html_load_from_string(GTK_HTML(html_wg), html.c_str(), -1);
}
//UNUSED
// // copy article html from while loop into global variable
void set_article(const std::string& txt)
{
@ -110,9 +113,10 @@ void show_random()
log_debug("article title=" << article.getTitle());
log_debug("article namespace=" << article.getNamespace());
gtk_html_flush(GTK_HTML(html_wg));
gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1);
log_debug("html \n" << res.c_str());
fill_gtkhtml(res);
// gtk_html_flush(GTK_HTML(html_wg));
// gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1);
//log_debug("html \n" << res.c_str());
}
// // display search dialog
@ -125,7 +129,7 @@ void search_window(main_window *window_x)
// // set displayed html to given url
// // FIXME: returns several articles and displays on one page ... why?
void set_html(const gchar *url)
void getArticleFromUrl(const gchar *url)
{
// TODO unescape url
@ -175,16 +179,9 @@ void set_html(const gchar *url)
if (article.good()) // check if article is really found
{
// // get content html
content = article.getPage();
// // emtpy gtkhtml widget
gtk_html_flush(GTK_HTML(html_wg));
// // load new data into gtkhtml widget
gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1);
// window.resize(220, 140);
log_debug("term=" << term << " url=" << url);
fill_gtkhtml(content);
}
else
{
@ -200,7 +197,7 @@ void set_html(const gchar *url)
// // test functions
void set_search(const gchar *url)
void getArticleFromTitle(const gchar *url)
{
char ns;
ns = 'A';
@ -209,23 +206,32 @@ void set_search(const gchar *url)
zim::Search::Results result;
zim::Search search(z);
std::string term(url);
std::string res;
search.setSearchLimit(25);
search.find(result, ns, term);
if( result.size() == 0)
{
show_message("Error", "The article you requested (" + term + ") was not found.");
}else if (result.size() == 1){
}else{
if (result.size() == 1){
log_debug("one article in result");
zim::Article article = z.getArticle(result[0].getArticle().getIndex());
content = article.getPage(false, 10);
//loop in case article is redirect
do
{
article = article.getRedirectArticle();
}while(article.isRedirect());
res = article.getPage(false, 10);
gtk_html_flush(GTK_HTML(html_wg));
gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1);
}
else
{
std::string res;
log_debug("more than one article in result");
for (unsigned i = 0; i < result.size(); ++i)
{
#if HAVE_ZIM_QUNICODE_H
@ -235,12 +241,10 @@ void set_search(const gchar *url)
#endif
}
gtk_html_flush(GTK_HTML(html_wg));
gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1);
}
log_debug(url);
fill_gtkhtml(res);
}
}
// // // window response functions
@ -261,11 +265,11 @@ bool on_link_clicked(GtkHTML *html, const gchar *url)
}else{
term = term.substr(0, found);
//TODO make "set_html" func accept anchor name
set_html(const_cast<char*>(term.c_str()));
getArticleFromUrl(const_cast<char*>(term.c_str()));
}
}else{
set_html(url);
getArticleFromUrl(url);
}
return true;

View File

@ -27,7 +27,7 @@ class main_window;
extern void show_random();
extern void search_window(main_window *window);
extern void set_html(const gchar *url);
extern void set_search(const gchar *url);
extern void getArticleFromUrl(const gchar *url);
extern void getArticleFromTitle(const gchar *url);
#endif // VIDO_HH