Date:2010-02-21 20:23:03 (10 years 5 months ago)
Author:Mirko Lindner
Commit:93a9bc198d4d8662431ca06dfae0fe560fbccf2f
Message:fix history

Signed-off-by: Mirko Lindner <mirko@sharism.cc>
Files: src/vido.cc (13 diffs)

Change Details

src/vido.cc
5252Gtk::Widget *html;
5353GtkWidget *html_wg;
5454std::vector < std::pair< std::string, std::string > > history;
55unsigned int position = 0;
55int position;
5656bool historyCall = false;
5757// variable to keep url of currently displayed article
5858std::string current_url = "";
...... 
6565
6666  if (!zimFile.good())
6767  {
68    log_debug("file not initialized:" << fileName);
68// log_debug("file not initialized:" << fileName);
6969    zimFile = zim::File(fileName);
70    log_debug("number of articles: " << zimFile.getCountArticles());
70// log_debug("number of articles: " << zimFile.getCountArticles());
7171  }
7272
73  log_debug("returning file.");
73// log_debug("returning file.");
7474  return zimFile;
7575}
7676
...... 
116116// fill gtkhtml widget with new content
117117
118118void fill_gtkhtml(std::string& html_str, std::string url, std::string title){
119    log_debug("fill gtkhtml called with " << url << " and " << title);
119    log_debug("fill gtkhtml called with " << position << " " << url << " and " << title);
120120    std::string ccontent;
121121    ccontent = "<a name=\"top\"></a>" + html_str;
122122    gtk_html_flush(GTK_HTML(html_wg));
123123    gtk_html_load_from_string(GTK_HTML(html_wg), ccontent.c_str(), -1);
124124    current_url = url;
125125    if ((url != "") && title != ""){
126      if (position == 0){
127        log_debug("adding " << title << " to history");
126      if ((!historyCall)){
127        if(position != 0){
128                    std::vector < std::pair< std::string, std::string > >::iterator iterator = history.begin();
129          log_debug("history size: " << history.size());
130                    for (int d=0; d < history.size(); d++){
131                        log_debug("history entry: " << d << " " << history[d].first);
132                    }
133                    for (int m=history.size()+position; m <= history.size(); m++){
134            log_debug("erasing history: number: "<< m << "title: " << history[m].first);
135                        history.erase(iterator+m);
136            }
137                }
138                log_debug("adding " << title << " to history \n" << "position: " << position);
128139        history.push_back( std::make_pair( url, title ) );
129        if (history.size() == 11){
140                if (history.size() == 11){
130141          history.erase(history.begin());
131142          }
143                log_debug("history size after stuff: " << history.size());
132144      }else{
133        if (!historyCall){
134          log_debug("clearing history");
135          std::vector < std::pair< std::string, std::string > >::iterator iterator = history.begin();
136          for (int m=0; m < position; m++){
137            history.erase(iterator+m);
138            }
139        }else{
145// if (!historyCall){
146// log_debug("clearing history");
147// std::vector < std::pair< std::string, std::string > >::iterator iterator = history.begin();
148// for (int m=0; m < position; m++){
149// history.erase(iterator+m);
150// }
151// }else{
140152          historyCall = false;
141        }
153// }
142154      }
143155
144156    }
...... 
157169    screenblock(1);
158170  std::string res, url, title;
159171  res += "<ul style=\"list-style-type:none;\">";
160
161  for(unsigned i=history.size()-1; i > 0; --i)
172    log_debug("history size: " << history.size());
173    for (int d=0; d < history.size(); d++){
174        log_debug("history entry: " << d << " " << history[d].first);
175    }
176  for(int i=history.size()-1; i >= 0; i--)
162177  {
163
178    log_debug("entry: " << i);
164179#if HAVE_ZIM_QUNICODE_H
165180    res += "<li><a href=" + history[i].first + ">" + history[i].second + "</a></li>";
166181#else
...... 
187202  log_debug("new_pos = " << new_pos);
188203  log_debug("history size = " << history.size());
189204  if ((new_pos > 0) && (new_pos <= history.size())){
205// position = new_rel_pos;
190206    historyCall = true;
191207    std::string url = history[new_pos-1].first;
192208    log_debug("url is = " << url);
193209// const char* uri = url.c_str();
194210// getArticleFromUrl(const_cast<char*>(url.c_str()), 1);
195211    const char* uri = url.c_str();
196    getArticleFromUrl(uri, 0);
212    getArticleFromUrl(uri, new_rel_pos);
197213    position = new_rel_pos;
198  }
214  }else{
215        log_debug("jump not possible");
216        window2->connect_all();
217    }
199218}
200219
201220//UNUSED
...... 
214233// window2->disconnect_all();
215234
216235        screenblock(1);
217    log_debug("random called. window all disconnected");
236// log_debug("random called. window all disconnected");
218237    zim::File m = get_file();
219238        zim::Article article;
220239    do
...... 
234253
235254    std::string res = article.getPage();
236255
237    log_debug("article size=" << res.size());
238    log_debug("article title=" << article.getTitle());
239    log_debug("article namespace=" << article.getNamespace());
240    position = 0;
256// log_debug("article size=" << res.size());
257// log_debug("article title=" << article.getTitle());
258// log_debug("article namespace=" << article.getNamespace());
259// position = 0;
241260    fill_gtkhtml(res, article.getUrl(), article.getTitle());
242        log_debug("random called. window all connected");
261// log_debug("random called. window all connected");
243262
244263}
245264
...... 
264283
265284// // set displayed html to given url
266285// // FIXME: returns several articles and displays on one page ... why?
267void getArticleFromUrl(const gchar *url, int pos = 0)
286void getArticleFromUrl(const gchar *url, int pos)
268287{
269288    // TODO unescape url
270289
271290// // create ZIM file accessor
272291    zim::File m = get_file();
273
274292// // convert url to string
275    std::string term(url);
293    std::string term;
294        term.assign(url);
295// log_debug("str url" << term << "\n");
276296    std::string content;
277297// // replace '+' signs with spaces in url
278298    std::replace(term.begin(), term.end(), '+', ' ');
...... 
315335        if (article.good()) // check if article is really found
316336        {
317337            content = article.getPage();
318            if (pos == 0){
319              position = 0;
320            }
338                        position = pos;
321339            fill_gtkhtml(content, article.getUrl(), article.getTitle());
322340        }
323341        else
...... 
336354// // test functions
337355void getArticleFromTitle(const gchar *phrase)
338356{
357        historyCall = false;
339358    screenblock(1);
340359        char ns;
341360    ns = 'A';
...... 
367386        res = article.getPage(false, 10);
368387        url = article.getUrl();
369388        title = article.getTitle();
389                log_debug("set article from title position = 0");
370390        position = 0;
371391      }
372392      else
...... 
408428        term = term.substr(0, found);
409429        //TODO make "set_html" func accept anchor name
410430        const char* uri = term.c_str();
411        getArticleFromUrl(uri, 0);
431        getArticleFromUrl(uri, position);
412432      }
413433
414434    }else{
415      getArticleFromUrl(url,0);
435      getArticleFromUrl(url,position);
416436    }
417437
418438    return true;
...... 
460480
461481      window.add(scrolled_window);
462482      window.show_all();
463
483            position = 0;
464484      show_random();
465485      gtk_html_edit_make_cursor_visible(GTK_HTML(html_wg));
466486      Gtk::Main::run(window);

Archive Download the corresponding diff file

Branches:
development
master



interactive