Date:2010-01-23 17:58:51 (10 years 6 months ago)
Author:Mirko Lindner
Commit:556e12ff0dcf111e43fe0d6bb20c1d9c9f3d0e04
Message:refactoring and function rename

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

Change Details

src/search_dialog.cc
4040    int result = dialog.run();
4141    if (result == Gtk::RESPONSE_OK)
4242    {
43             set_search(entry.get_text().c_str());
43        getArticleFromTitle(entry.get_text().c_str());
4444    }
4545
4646}
src/vido.cc
4848GtkWidget *html_wg;
4949
5050// // // misc functions
51
51// get zimFile, if not already opened, open file
5252const zim::File& get_file()
5353{
5454  static zim::File zimFile;
...... 
6464  return zimFile;
6565}
6666
67// display message in gtk window
6768void show_message(std::string title, std::string txt)
6869{
6970    message_dialog(window, title, txt);
7071}
7172
72// void page_move(int val){
73// Gtk::Adjustment *vertical = scrolled_window.get_vadjustment();
74// double page_size = vertical->get_page_size();
75// double value = vertical->get_value();
76// vertical->set_value(value + (val * page_size));
77// }
73// fill gtkhtml widget with new content
74//TODO prepend "top" anchor on html
75void fill_gtkhtml(std::string& html){
76    log_debug("fill gtkhtml called");
77    gtk_html_flush(GTK_HTML(html_wg));
78    gtk_html_load_from_string(GTK_HTML(html_wg), html.c_str(), -1);
79}
7880
81//UNUSED
7982// // copy article html from while loop into global variable
8083void set_article(const std::string& txt)
8184{
...... 
110113    log_debug("article title=" << article.getTitle());
111114    log_debug("article namespace=" << article.getNamespace());
112115
113    gtk_html_flush(GTK_HTML(html_wg));
114    gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1);
115    log_debug("html \n" << res.c_str());
116    fill_gtkhtml(res);
117// gtk_html_flush(GTK_HTML(html_wg));
118// gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1);
119    //log_debug("html \n" << res.c_str());
116120}
117121
118122// // display search dialog
...... 
125129
126130// // set displayed html to given url
127131// // FIXME: returns several articles and displays on one page ... why?
128void set_html(const gchar *url)
132void getArticleFromUrl(const gchar *url)
129133{
130134    // TODO unescape url
131135
...... 
175179
176180        if (article.good()) // check if article is really found
177181        {
178// // get content html
179182            content = article.getPage();
180183
181// // emtpy gtkhtml widget
182            gtk_html_flush(GTK_HTML(html_wg));
183
184// // load new data into gtkhtml widget
185            gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1);
186// window.resize(220, 140);
187            log_debug("term=" << term << " url=" << url);
184            fill_gtkhtml(content);
188185        }
189186        else
190187        {
...... 
200197
201198
202199// // test functions
203void set_search(const gchar *url)
200void getArticleFromTitle(const gchar *url)
204201{
205202    char ns;
206203    ns = 'A';
...... 
209206    zim::Search::Results result;
210207    zim::Search search(z);
211208    std::string term(url);
209    std::string res;
212210    search.setSearchLimit(25);
213211    search.find(result, ns, term);
214212    if( result.size() == 0)
215213    {
216214        show_message("Error", "The article you requested (" + term + ") was not found.");
217215
218    }else if (result.size() == 1){
216    }else{
217
218      if (result.size() == 1){
219        log_debug("one article in result");
220
219221        zim::Article article = z.getArticle(result[0].getArticle().getIndex());
220222
221        content = article.getPage(false, 10);
223        //loop in case article is redirect
224        do
225        {
226            article = article.getRedirectArticle();
227        }while(article.isRedirect());
222228
223        gtk_html_flush(GTK_HTML(html_wg));
224        gtk_html_load_from_string(GTK_HTML(html_wg), content.c_str(), -1);
225    }
226    else
227    {
228        std::string res;
229        res = article.getPage(false, 10);
230
231      }
232      else
233      {
234        log_debug("more than one article in result");
229235        for (unsigned i = 0; i < result.size(); ++i)
230236        {
231237#if HAVE_ZIM_QUNICODE_H
...... 
234240          res += "<li><a href='" + result[i].getArticle().getUrl() + "'>" + result[i].getArticle().getUrl() + "</a></li>";
235241#endif
236242        }
237
238        gtk_html_flush(GTK_HTML(html_wg));
239        gtk_html_load_from_string(GTK_HTML(html_wg), res.c_str(), -1);
240243
244      }
245
246      fill_gtkhtml(res);
241247    }
242
243    log_debug(url);
244248}
245249
246250// // // window response functions
...... 
261265      }else{
262266        term = term.substr(0, found);
263267        //TODO make "set_html" func accept anchor name
264        set_html(const_cast<char*>(term.c_str()));
268        getArticleFromUrl(const_cast<char*>(term.c_str()));
265269      }
266270
267271    }else{
268      set_html(url);
272      getArticleFromUrl(url);
269273    }
270274
271275    return true;
src/vido.hh
2727
2828extern void show_random();
2929extern void search_window(main_window *window);
30extern void set_html(const gchar *url);
31extern void set_search(const gchar *url);
30extern void getArticleFromUrl(const gchar *url);
31extern void getArticleFromTitle(const gchar *url);
3232
3333#endif // VIDO_HH

Archive Download the corresponding diff file

Branches:
development
master



interactive