~ubuntu-branches/ubuntu/trusty/newsbeuter/trusty-proposed

« back to all changes in this revision

Viewing changes to src/view.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Nico Golde
  • Date: 2008-05-01 14:51:20 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080501145120-i65avsclnrpl2cfq
Tags: 0.9-1
* New upstream release.
  - Fix problem displaying titles when using zh_CN.UTF-8
    locale (Closes: #471434).
* Add default configuration to set sensible-browser as browser and
  add dirs file to create /etc/newsbeuter (Closes: #470833).
* remove libnxml-depends and libmrss-depends calls in rules and
  related dependency lines in control since they are not needed
  anymore (Closes: #467201).

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include <exception.h>
20
20
#include <exceptions.h>
21
21
#include <keymap.h>
 
22
#include <utils.h>
22
23
 
23
24
#include <iostream>
24
25
#include <iomanip>
45
46
#include <htmlrenderer.h>
46
47
#include <cstring>
47
48
#include <cstdio>
48
 
#include <sstream>
49
49
 
50
50
namespace newsbeuter {
51
51
 
116
116
        GetLogger().log(LOG_DEBUG, "view::set_bindings: itemview bind_page_up = %s bind_page_down = %s", itemview->get_form()->get("bind_page_up").c_str(), itemview->get_form()->get("bind_page_down").c_str());
117
117
}
118
118
 
119
 
void view::set_status_unlocked(const char * msg) {
 
119
void view::set_status_unlocked(const std::string& msg) {
120
120
        if (formaction_stack.size() > 0 && (*formaction_stack.begin()) != NULL) {
121
121
                stfl::form * form = (*formaction_stack.begin())->get_form();
122
 
                // GetLogger().log(LOG_DEBUG, "view::set_status: form = %p", form);
123
122
                form->set("msg",msg);
124
 
                // GetLogger().log(LOG_DEBUG, "view::set_status: after form.set");
125
123
                form->run(-1);
126
 
                // GetLogger().log(LOG_DEBUG, "view::set_status: after form.run");
127
124
        }
128
125
}
129
126
 
130
 
void view::set_status(const char * msg) {
 
127
void view::set_status(const std::string& msg) {
131
128
        scope_mutex lock(mtx);
132
129
        set_status_unlocked(msg);
133
130
}
134
131
 
135
 
void view::show_error(const char * msg) {
 
132
void view::show_error(const std::string& msg) {
136
133
        set_status(msg);
137
134
}
138
135
 
257
254
        return retval;  
258
255
}
259
256
 
260
 
void view::write_item(const rss_item& item, const std::string& filename) {
261
 
        // TODO: move this to the controller.
262
 
        std::vector<std::string> lines;
263
 
        std::vector<linkpair> links; // not used
264
 
        
265
 
        std::string title(_("Title: "));
266
 
        title.append(item.title());
267
 
        lines.push_back(title);
268
 
        
269
 
        std::string author(_("Author: "));
270
 
        author.append(item.author());
271
 
        lines.push_back(author);
272
 
        
273
 
        std::string date(_("Date: "));
274
 
        date.append(item.pubDate());
275
 
        lines.push_back(date);
276
 
 
277
 
        std::string link(_("Link: "));
278
 
        link.append(item.link());
279
 
        lines.push_back(link);
280
 
        
281
 
        lines.push_back(std::string(""));
282
 
        
283
 
        unsigned int width = cfg->get_configvalue_as_int("text-width");
284
 
        if (width == 0)
285
 
                width = 80;
286
 
        htmlrenderer rnd(width);
287
 
        rnd.render(item.description(), lines, links, item.feedurl());
288
 
 
289
 
        std::fstream f;
290
 
        f.open(filename.c_str(),std::fstream::out);
291
 
        if (!f.is_open())
292
 
                throw exception(errno);
293
 
                
294
 
        for (std::vector<std::string>::iterator it=lines.begin();it!=lines.end();++it) {
295
 
                f << *it << std::endl;  
296
 
        }
297
 
}
298
257
 
299
258
void view::open_in_browser(const std::string& url) {
300
259
        formaction_stack.push_front(NULL); // we don't want a thread to write over the browser
313
272
        formaction_stack.pop_front();
314
273
}
315
274
 
 
275
void view::update_visible_feeds(std::vector<rss_feed>& feeds) {
 
276
        scope_mutex lock(mtx);
 
277
        try {
 
278
                feedlist->update_visible_feeds(feeds);
 
279
        } catch (matcherexception e) {
 
280
                set_status_unlocked(utils::strprintf(_("Error: applying the filter failed: %s"), e.what()));
 
281
                GetLogger().log(LOG_DEBUG, "view::update_visible_feeds: inside catch: %s", e.what());
 
282
        }
 
283
}
 
284
 
316
285
void view::set_feedlist(std::vector<rss_feed>& feeds) {
317
286
        scope_mutex lock(mtx);
318
287
 
325
294
        try {
326
295
                feedlist->set_feedlist(feeds);
327
296
        } catch (matcherexception e) {
328
 
                char buf[1024];
329
 
                snprintf(buf,sizeof(buf), _("Error: applying the filter failed: %s"), e.what());
330
 
                set_status_unlocked(buf);
331
 
                GetLogger().log(LOG_DEBUG, "view::set_feedlist: inside catch: %s", buf);
 
297
                set_status_unlocked(utils::strprintf(_("Error: applying the filter failed: %s"), e.what()));
 
298
                GetLogger().log(LOG_DEBUG, "view::set_feedlist: inside catch: %s", e.what());
332
299
        }
333
300
}
334
301
 
406
373
        selecttag->set_type(select_formaction::SELECTTAG);
407
374
        selecttag->set_tags(tags);
408
375
        run_modal(selecttag, "");
409
 
        return selecttag->get_value();
 
376
        return selecttag->get_selected_value();
410
377
}
411
378
 
412
379
std::string view::select_filter(const std::vector<filter_name_expr_pair>& filters) {
413
380
        selecttag->set_type(select_formaction::SELECTFILTER);
414
381
        selecttag->set_filters(filters);
415
382
        run_modal(selecttag, "");
416
 
        return selecttag->get_value();
 
383
        return selecttag->get_selected_value();
417
384
}
418
385
 
419
386
char view::confirm(const std::string& prompt, const std::string& charset) {
598
565
        return (*formaction_stack.begin())->get_qna_response(0);
599
566
}
600
567
 
 
568
void view::feedlist_mark_pos_if_visible(unsigned int pos) {
 
569
        feedlist->mark_pos_if_visible(pos);
 
570
}
 
571
 
601
572
 
602
573
}