Date:2010-01-24 14:54:33 (10 years 6 months ago)
Author:Mirko Lindner
Commit:5d30ead071fc7f5f38e439824e97aa5d9ccea67a
Message:start implemting back and forward in history

Signed-off-by: Mirko Lindner <mirko@sharism.cc>
Files: src/main_window.cc (2 diffs)
src/vido.cc (10 diffs)
src/vido.hh (1 diff)

Change Details

src/main_window.cc
3939bool main_window::actions(int key)
4040{
4141    static int key_b = 98;
42    static int key_f = 102;
4243    static int key_h = 104;
4344    static int key_q = 113;
4445    static int key_r = 114;
...... 
6364        GoToTop();
6465    }else if(key == key_h){
6566        show_history();
67    }else if(key == key_f){
68        history_jump(1);
69    }else if(key == key_b){
70        history_jump(-1);
6671    }else{
6772      log_debug("key pressed: " << key);
6873    }
src/vido.cc
4848Gtk::Widget *html;
4949GtkWidget *html_wg;
5050std::vector < std::pair< std::string, std::string > > history;
51
51unsigned int position = 0;
52bool historyCall = false;
5253
5354// // // misc functions
5455// get zimFile, if not already opened, open file
...... 
7576// fill gtkhtml widget with new content
7677//TODO prepend "top" anchor on html
7778void fill_gtkhtml(std::string& html, std::string url, std::string title){
78    log_debug("fill gtkhtml called");
79    log_debug("fill gtkhtml called with " << url << " and " << title);
7980    std::string ccontent;
8081    ccontent = "<a name=\"top\"></a>" + html;
8182    gtk_html_flush(GTK_HTML(html_wg));
8283    gtk_html_load_from_string(GTK_HTML(html_wg), ccontent.c_str(), -1);
8384
8485    if ((url != "") && title != ""){
85      log_debug("adding " << title << " to history");
86      history.push_back( std::make_pair( url, title ) );
87      if (history.size() == 11){
88        history.erase(history.begin());
86      if (position == 0){
87        log_debug("adding " << title << " to history");
88        history.push_back( std::make_pair( url, title ) );
89        if (history.size() == 11){
90          history.erase(history.begin());
91          }
92      }else{
93        if (!historyCall){
94          log_debug("clearing history");
95          std::vector < std::pair< std::string, std::string > >::iterator iterator = history.begin();
96          for (int m=0; m < position; m++){
97            history.erase(iterator+m);
98            }
99        }else{
100          historyCall = false;
101        }
89102      }
90103
91104    }
...... 
97110  std::string res, url, title;
98111  res += "<ul style=\"list-style-type:none;\">";
99112
100  for(unsigned i=history.size(); i > 0; --i)
113  for(unsigned i=history.size()-1; i > 0; --i)
101114  {
102115
103116#if HAVE_ZIM_QUNICODE_H
104    res += "<li><a href=" + history[i-1].first + ">" + history[i-1].second + "</a></li>";
117    res += "<li><a href=" + history[i].first + ">" + history[i].second + "</a></li>";
105118#else
106    res += "<li><a href='" + history[i-1].first + "'>" + history[i-1].second + "</a></li>";
119    res += "<li><a href='" + history[i].first + "'>" + history[i].second + "</a>";
120    if (position == i){
121      res += "<--";
122    }
123    res += "</li>";
107124#endif
108125
109126  }
...... 
115132
116133}
117134
135void history_jump(int jumper){
136  int new_rel_pos = position + jumper;
137  log_debug("new_rel_pos = " << new_rel_pos);
138  int new_pos = history.size() + new_rel_pos;
139  log_debug("new_pos = " << new_pos);
140  log_debug("history size = " << history.size());
141  if ((new_pos > 0) && (new_pos <= history.size())){
142    historyCall = true;
143    std::string url = history[new_pos-1].first;
144    log_debug("url is = " << url);
145// const char* uri = url.c_str();
146// getArticleFromUrl(const_cast<char*>(url.c_str()), 1);
147    const char* uri = url.c_str();
148    getArticleFromUrl(uri, 0);
149    position = new_rel_pos;
150  }
151}
152
118153//UNUSED
119154// // copy article html from while loop into global variable
120155// void set_article(const std::string& txt)
...... 
148183    log_debug("article size=" << res.size());
149184    log_debug("article title=" << article.getTitle());
150185    log_debug("article namespace=" << article.getNamespace());
151
186    position = 0;
152187    fill_gtkhtml(res, article.getUrl(), article.getTitle());
153188}
154189
...... 
170205
171206// // set displayed html to given url
172207// // FIXME: returns several articles and displays on one page ... why?
173void getArticleFromUrl(const gchar *url)
208void getArticleFromUrl(const gchar *url, int pos = 0)
174209{
175210    // TODO unescape url
176211
...... 
221256        if (article.good()) // check if article is really found
222257        {
223258            content = article.getPage();
224
259            if (pos == 0){
260              position = 0;
261            }
225262            fill_gtkhtml(content, article.getUrl(), article.getTitle());
226263        }
227264        else
...... 
247284    zim::Search::Results result;
248285    zim::Search search(z);
249286    std::string term(phrase);
250    std::string res;
251    std::string url;
252    std::string title;
287    std::string res, url, title;
253288    search.setSearchLimit(25);
254289    search.find(result, ns, term);
255290    if( result.size() == 0)
...... 
272307        res = article.getPage(false, 10);
273308        url = article.getUrl();
274309        title = article.getTitle();
310        position = 0;
275311      }
276312      else
277313      {
...... 
311347      }else{
312348        term = term.substr(0, found);
313349        //TODO make "set_html" func accept anchor name
314        getArticleFromUrl(const_cast<char*>(term.c_str()));
350        const char* uri = term.c_str();
351        getArticleFromUrl(uri, 0);
315352      }
316353
317354    }else{
318      getArticleFromUrl(url);
355      getArticleFromUrl(url,0);
319356    }
320357
321358    return true;
src/vido.hh
2727
2828extern void show_random();
2929extern void show_history();
30extern void history_jump(int jumper);
3031extern void search_window(main_window *window);
31extern void getArticleFromUrl(const gchar *url);
32extern void getArticleFromUrl(const gchar *url, int pos);
3233extern void getArticleFromTitle(const gchar *url);
3334extern void GoToTop();
3435

Archive Download the corresponding diff file

Branches:
development
master



interactive