mirror of
git://projects.qi-hardware.com/vido.git
synced 2024-12-22 13:55:30 +02:00
start implemting back and forward in history
Signed-off-by: Mirko Lindner <mirko@sharism.cc>
This commit is contained in:
parent
9387c0dd58
commit
5d30ead071
@ -39,6 +39,7 @@ main_window::main_window()
|
||||
bool main_window::actions(int key)
|
||||
{
|
||||
static int key_b = 98;
|
||||
static int key_f = 102;
|
||||
static int key_h = 104;
|
||||
static int key_q = 113;
|
||||
static int key_r = 114;
|
||||
@ -63,6 +64,10 @@ bool main_window::actions(int key)
|
||||
GoToTop();
|
||||
}else if(key == key_h){
|
||||
show_history();
|
||||
}else if(key == key_f){
|
||||
history_jump(1);
|
||||
}else if(key == key_b){
|
||||
history_jump(-1);
|
||||
}else{
|
||||
log_debug("key pressed: " << key);
|
||||
}
|
||||
|
63
src/vido.cc
63
src/vido.cc
@ -48,7 +48,8 @@ main_window *window;
|
||||
Gtk::Widget *html;
|
||||
GtkWidget *html_wg;
|
||||
std::vector < std::pair< std::string, std::string > > history;
|
||||
|
||||
unsigned int position = 0;
|
||||
bool historyCall = false;
|
||||
|
||||
// // // misc functions
|
||||
// get zimFile, if not already opened, open file
|
||||
@ -75,18 +76,30 @@ void show_message(std::string title, std::string txt)
|
||||
// fill gtkhtml widget with new content
|
||||
//TODO prepend "top" anchor on html
|
||||
void fill_gtkhtml(std::string& html, std::string url, std::string title){
|
||||
log_debug("fill gtkhtml called");
|
||||
log_debug("fill gtkhtml called with " << url << " and " << title);
|
||||
std::string ccontent;
|
||||
ccontent = "<a name=\"top\"></a>" + html;
|
||||
gtk_html_flush(GTK_HTML(html_wg));
|
||||
gtk_html_load_from_string(GTK_HTML(html_wg), ccontent.c_str(), -1);
|
||||
|
||||
if ((url != "") && title != ""){
|
||||
if (position == 0){
|
||||
log_debug("adding " << title << " to history");
|
||||
history.push_back( std::make_pair( url, title ) );
|
||||
if (history.size() == 11){
|
||||
history.erase(history.begin());
|
||||
}
|
||||
}else{
|
||||
if (!historyCall){
|
||||
log_debug("clearing history");
|
||||
std::vector < std::pair< std::string, std::string > >::iterator iterator = history.begin();
|
||||
for (int m=0; m < position; m++){
|
||||
history.erase(iterator+m);
|
||||
}
|
||||
}else{
|
||||
historyCall = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -97,13 +110,17 @@ void show_history()
|
||||
std::string res, url, title;
|
||||
res += "<ul style=\"list-style-type:none;\">";
|
||||
|
||||
for(unsigned i=history.size(); i > 0; --i)
|
||||
for(unsigned i=history.size()-1; i > 0; --i)
|
||||
{
|
||||
|
||||
#if HAVE_ZIM_QUNICODE_H
|
||||
res += "<li><a href=" + history[i-1].first + ">" + history[i-1].second + "</a></li>";
|
||||
res += "<li><a href=" + history[i].first + ">" + history[i].second + "</a></li>";
|
||||
#else
|
||||
res += "<li><a href='" + history[i-1].first + "'>" + history[i-1].second + "</a></li>";
|
||||
res += "<li><a href='" + history[i].first + "'>" + history[i].second + "</a>";
|
||||
if (position == i){
|
||||
res += "<--";
|
||||
}
|
||||
res += "</li>";
|
||||
#endif
|
||||
|
||||
}
|
||||
@ -115,6 +132,24 @@ void show_history()
|
||||
|
||||
}
|
||||
|
||||
void history_jump(int jumper){
|
||||
int new_rel_pos = position + jumper;
|
||||
log_debug("new_rel_pos = " << new_rel_pos);
|
||||
int new_pos = history.size() + new_rel_pos;
|
||||
log_debug("new_pos = " << new_pos);
|
||||
log_debug("history size = " << history.size());
|
||||
if ((new_pos > 0) && (new_pos <= history.size())){
|
||||
historyCall = true;
|
||||
std::string url = history[new_pos-1].first;
|
||||
log_debug("url is = " << url);
|
||||
// const char* uri = url.c_str();
|
||||
// getArticleFromUrl(const_cast<char*>(url.c_str()), 1);
|
||||
const char* uri = url.c_str();
|
||||
getArticleFromUrl(uri, 0);
|
||||
position = new_rel_pos;
|
||||
}
|
||||
}
|
||||
|
||||
//UNUSED
|
||||
// // copy article html from while loop into global variable
|
||||
// void set_article(const std::string& txt)
|
||||
@ -148,7 +183,7 @@ void show_random()
|
||||
log_debug("article size=" << res.size());
|
||||
log_debug("article title=" << article.getTitle());
|
||||
log_debug("article namespace=" << article.getNamespace());
|
||||
|
||||
position = 0;
|
||||
fill_gtkhtml(res, article.getUrl(), article.getTitle());
|
||||
}
|
||||
|
||||
@ -170,7 +205,7 @@ void GoToTop()
|
||||
|
||||
// // set displayed html to given url
|
||||
// // FIXME: returns several articles and displays on one page ... why?
|
||||
void getArticleFromUrl(const gchar *url)
|
||||
void getArticleFromUrl(const gchar *url, int pos = 0)
|
||||
{
|
||||
// TODO unescape url
|
||||
|
||||
@ -221,7 +256,9 @@ void getArticleFromUrl(const gchar *url)
|
||||
if (article.good()) // check if article is really found
|
||||
{
|
||||
content = article.getPage();
|
||||
|
||||
if (pos == 0){
|
||||
position = 0;
|
||||
}
|
||||
fill_gtkhtml(content, article.getUrl(), article.getTitle());
|
||||
}
|
||||
else
|
||||
@ -247,9 +284,7 @@ void getArticleFromTitle(const gchar *phrase)
|
||||
zim::Search::Results result;
|
||||
zim::Search search(z);
|
||||
std::string term(phrase);
|
||||
std::string res;
|
||||
std::string url;
|
||||
std::string title;
|
||||
std::string res, url, title;
|
||||
search.setSearchLimit(25);
|
||||
search.find(result, ns, term);
|
||||
if( result.size() == 0)
|
||||
@ -272,6 +307,7 @@ void getArticleFromTitle(const gchar *phrase)
|
||||
res = article.getPage(false, 10);
|
||||
url = article.getUrl();
|
||||
title = article.getTitle();
|
||||
position = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -311,11 +347,12 @@ bool on_link_clicked(GtkHTML *html, const gchar *url)
|
||||
}else{
|
||||
term = term.substr(0, found);
|
||||
//TODO make "set_html" func accept anchor name
|
||||
getArticleFromUrl(const_cast<char*>(term.c_str()));
|
||||
const char* uri = term.c_str();
|
||||
getArticleFromUrl(uri, 0);
|
||||
}
|
||||
|
||||
}else{
|
||||
getArticleFromUrl(url);
|
||||
getArticleFromUrl(url,0);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -27,8 +27,9 @@ class main_window;
|
||||
|
||||
extern void show_random();
|
||||
extern void show_history();
|
||||
extern void history_jump(int jumper);
|
||||
extern void search_window(main_window *window);
|
||||
extern void getArticleFromUrl(const gchar *url);
|
||||
extern void getArticleFromUrl(const gchar *url, int pos);
|
||||
extern void getArticleFromTitle(const gchar *url);
|
||||
extern void GoToTop();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user