mirror of
git://projects.qi-hardware.com/vido.git
synced 2024-12-22 19:59:52 +02:00
refactoring and function rename
Signed-off-by: Mirko Lindner <mirko@sharism.cc>
This commit is contained in:
parent
c4b1f2b482
commit
556e12ff0d
@ -40,7 +40,7 @@ search_dialog::search_dialog(main_window* parent, const Glib::ustring& input)
|
|||||||
int result = dialog.run();
|
int result = dialog.run();
|
||||||
if (result == Gtk::RESPONSE_OK)
|
if (result == Gtk::RESPONSE_OK)
|
||||||
{
|
{
|
||||||
set_search(entry.get_text().c_str());
|
getArticleFromTitle(entry.get_text().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
66
src/vido.cc
66
src/vido.cc
@ -48,7 +48,7 @@ Gtk::Widget *html;
|
|||||||
GtkWidget *html_wg;
|
GtkWidget *html_wg;
|
||||||
|
|
||||||
// // // misc functions
|
// // // misc functions
|
||||||
|
// get zimFile, if not already opened, open file
|
||||||
const zim::File& get_file()
|
const zim::File& get_file()
|
||||||
{
|
{
|
||||||
static zim::File zimFile;
|
static zim::File zimFile;
|
||||||
@ -64,18 +64,21 @@ const zim::File& get_file()
|
|||||||
return zimFile;
|
return zimFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// display message in gtk window
|
||||||
void show_message(std::string title, std::string txt)
|
void show_message(std::string title, std::string txt)
|
||||||
{
|
{
|
||||||
message_dialog(window, title, txt);
|
message_dialog(window, title, txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// void page_move(int val){
|
// fill gtkhtml widget with new content
|
||||||
// Gtk::Adjustment *vertical = scrolled_window.get_vadjustment();
|
//TODO prepend "top" anchor on html
|
||||||
// double page_size = vertical->get_page_size();
|
void fill_gtkhtml(std::string& html){
|
||||||
// double value = vertical->get_value();
|
log_debug("fill gtkhtml called");
|
||||||
// vertical->set_value(value + (val * page_size));
|
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
|
// // copy article html from while loop into global variable
|
||||||
void set_article(const std::string& txt)
|
void set_article(const std::string& txt)
|
||||||
{
|
{
|
||||||
@ -110,9 +113,10 @@ void show_random()
|
|||||||
log_debug("article title=" << article.getTitle());
|
log_debug("article title=" << article.getTitle());
|
||||||
log_debug("article namespace=" << article.getNamespace());
|
log_debug("article namespace=" << article.getNamespace());
|
||||||
|
|
||||||
gtk_html_flush(GTK_HTML(html_wg));
|
fill_gtkhtml(res);
|
||||||
gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1);
|
// gtk_html_flush(GTK_HTML(html_wg));
|
||||||
log_debug("html \n" << res.c_str());
|
// 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
|
||||||
@ -125,7 +129,7 @@ void search_window(main_window *window_x)
|
|||||||
|
|
||||||
// // set displayed html to given url
|
// // set displayed html to given url
|
||||||
// // FIXME: returns several articles and displays on one page ... why?
|
// // FIXME: returns several articles and displays on one page ... why?
|
||||||
void set_html(const gchar *url)
|
void getArticleFromUrl(const gchar *url)
|
||||||
{
|
{
|
||||||
// TODO unescape url
|
// TODO unescape url
|
||||||
|
|
||||||
@ -175,16 +179,9 @@ void set_html(const gchar *url)
|
|||||||
|
|
||||||
if (article.good()) // check if article is really found
|
if (article.good()) // check if article is really found
|
||||||
{
|
{
|
||||||
// // get content html
|
|
||||||
content = article.getPage();
|
content = article.getPage();
|
||||||
|
|
||||||
// // emtpy gtkhtml widget
|
fill_gtkhtml(content);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -200,7 +197,7 @@ void set_html(const gchar *url)
|
|||||||
|
|
||||||
|
|
||||||
// // test functions
|
// // test functions
|
||||||
void set_search(const gchar *url)
|
void getArticleFromTitle(const gchar *url)
|
||||||
{
|
{
|
||||||
char ns;
|
char ns;
|
||||||
ns = 'A';
|
ns = 'A';
|
||||||
@ -209,23 +206,32 @@ void set_search(const gchar *url)
|
|||||||
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::string res;
|
||||||
search.setSearchLimit(25);
|
search.setSearchLimit(25);
|
||||||
search.find(result, ns, 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){
|
||||||
|
log_debug("one article in result");
|
||||||
|
|
||||||
zim::Article article = z.getArticle(result[0].getArticle().getIndex());
|
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
|
else
|
||||||
{
|
{
|
||||||
std::string res;
|
log_debug("more than one article in result");
|
||||||
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
|
||||||
@ -235,12 +241,10 @@ void set_search(const gchar *url)
|
|||||||
#endif
|
#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
|
// // // window response functions
|
||||||
@ -261,11 +265,11 @@ bool on_link_clicked(GtkHTML *html, const gchar *url)
|
|||||||
}else{
|
}else{
|
||||||
term = term.substr(0, found);
|
term = term.substr(0, found);
|
||||||
//TODO make "set_html" func accept anchor name
|
//TODO make "set_html" func accept anchor name
|
||||||
set_html(const_cast<char*>(term.c_str()));
|
getArticleFromUrl(const_cast<char*>(term.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
set_html(url);
|
getArticleFromUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -27,7 +27,7 @@ class main_window;
|
|||||||
|
|
||||||
extern void show_random();
|
extern void show_random();
|
||||||
extern void search_window(main_window *window);
|
extern void search_window(main_window *window);
|
||||||
extern void set_html(const gchar *url);
|
extern void getArticleFromUrl(const gchar *url);
|
||||||
extern void set_search(const gchar *url);
|
extern void getArticleFromTitle(const gchar *url);
|
||||||
|
|
||||||
#endif // VIDO_HH
|
#endif // VIDO_HH
|
||||||
|
Loading…
Reference in New Issue
Block a user