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

« back to all changes in this revision

Viewing changes to src/itemview_formaction.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:
5
5
#include <exceptions.h>
6
6
#include <utils.h>
7
7
#include <formatstring.h>
 
8
#include <listformatter.h>
8
9
 
9
10
#include <sstream>
10
11
 
36
37
         */
37
38
        if (do_redraw) {
38
39
                rss_item& item = feed->get_item_by_guid(guid);
39
 
                std::string code = "{list";
 
40
                listformatter listfmt;
40
41
 
41
42
                rss_feed * feedptr = item.get_feedptr();
42
43
 
43
 
                std::ostringstream feedtitle;
44
 
                feedtitle << _("Feed: ");
 
44
                std::string title, feedtitle;
45
45
                if (feedptr->title().length() > 0) {
46
 
                        feedtitle << feedptr->title();
 
46
                        title = feedptr->title();
47
47
                } else if (feedptr->link().length() > 0) {
48
 
                        feedtitle << feedptr->link();
 
48
                        title = feedptr->link();
49
49
                } else if (feedptr->rssurl().length() > 0) {
50
 
                        feedtitle << feedptr->rssurl();
51
 
                }
52
 
                if (feedtitle.str().length() > 0) {
53
 
                        code.append("{listitem text:");
54
 
                        code.append(stfl::quote(feedtitle.str().c_str()));
55
 
                        code.append("}");
56
 
                }
 
50
                        title = feedptr->rssurl();
 
51
                }
 
52
                feedtitle = utils::strprintf("%s%s", _("Feed: "), title.c_str());
 
53
                listfmt.add_line(feedtitle);
57
54
 
58
55
                if (item.title().length() > 0) {
59
 
                        code.append("{listitem text:");
60
 
                        std::ostringstream title;
61
 
                        title << _("Title: ");
62
 
                        title << item.title();
63
 
                        code.append(stfl::quote(title.str()));
64
 
                        code.append("}");
 
56
                        title = utils::strprintf("%s%s", _("Title: "), item.title().c_str());
 
57
                        listfmt.add_line(title);
65
58
                }
66
59
 
67
60
                if (item.author().length() > 0) {
68
 
                        code.append("{listitem text:");
69
 
                        std::ostringstream author;
70
 
                        author << _("Author: ");
71
 
                        author << item.author();
72
 
                        code.append(stfl::quote(author.str()));
73
 
                        code.append("}");
 
61
                        std::string author = utils::strprintf("%s%s", _("Author: "), item.author().c_str());
 
62
                        listfmt.add_line(author);
74
63
                }
75
64
 
76
65
                if (item.link().length() > 0) {
77
 
                        code.append("{listitem text:");
78
 
                        std::ostringstream link;
79
 
                        link << _("Link: ");
80
 
                        link << item.link();
81
 
                        code.append(stfl::quote(link.str()));
82
 
                        code.append("}");
 
66
                        std::string link = utils::strprintf("%s%s", _("Link: "), item.link().c_str());
 
67
                        listfmt.add_line(link);
83
68
                }
84
 
                
85
 
                code.append("{listitem text:");
86
 
                std::ostringstream date;
87
 
                date << _("Date: ");
88
 
                date << item.pubDate();
89
 
                code.append(stfl::quote(date.str()));
90
 
                code.append("}");
 
69
 
 
70
                std::string date = utils::strprintf("%s%s", _("Date: "), item.pubDate().c_str());
 
71
                listfmt.add_line(date);
91
72
 
92
73
                if (item.flags().length() > 0) {
93
 
                        code.append("{listitem text:");
94
 
                        std::ostringstream flags;
95
 
                        flags << _("Flags: ");
96
 
                        flags << item.flags();
97
 
                        code.append(stfl::quote(flags.str()));
98
 
                        code.append("}");
 
74
                        std::string flags = utils::strprintf("%s%s", _("Flags: "), item.flags().c_str());
 
75
                        listfmt.add_line(flags);
99
76
                }
100
77
 
101
78
                if (item.enclosure_url().length() > 0) {
102
 
                        code.append("{listitem text:");
103
 
                        std::ostringstream enc_url;
104
 
                        enc_url << _("Podcast Download URL: ");
105
 
                        enc_url << item.enclosure_url() << " (" << _("type: ") << item.enclosure_type() << ")";
106
 
                        code.append(stfl::quote(enc_url.str()));
107
 
                        code.append("}");
 
79
                        std::string enc_url = utils::strprintf("%s%s (%s%s)", _("Podcast Download URL: "), item.enclosure_url().c_str(), _("type: "), item.enclosure_type().c_str());
 
80
                        listfmt.add_line(enc_url);
108
81
                }
109
82
 
110
 
                code.append("{listitem text:\"\"}");
111
 
                
 
83
                listfmt.add_line("");
 
84
 
112
85
                set_head(item.title());
113
86
 
114
87
                if (!render_hack) {
137
110
                        lines = render_html(item.description(), links, item.feedurl(), render_width);
138
111
                }
139
112
 
140
 
                for (std::vector<std::string>::iterator it = lines.begin(); it != lines.end(); ++it) {
141
 
                        std::string line("{listitem text:");
142
 
                        line.append(stfl::quote(*it));
143
 
                        line.append(1,'}');
144
 
                        code.append(line);
145
 
                }
146
 
 
147
 
                code.append("}");
148
 
 
149
 
                f->modify("article","replace_inner",code);
 
113
                listfmt.add_lines(lines);
 
114
 
 
115
                f->modify("article","replace_inner",listfmt.format_list());
150
116
                f->set("articleoffset","0");
151
117
 
152
118
                do_redraw = false;
167
133
        try {
168
134
                item.set_unread(false);
169
135
        } catch (const dbexception& e) {
170
 
                char buf[1024];
171
 
                snprintf(buf, sizeof(buf), _("Error while marking article as read: %s"), e.what());
172
 
                v->show_error(buf);
 
136
                v->show_error(utils::strprintf(_("Error while marking article as read: %s"), e.what()));
173
137
        }
174
138
 
175
139
        switch (op) {
182
146
                        do_redraw = true;
183
147
                        break;
184
148
                case OP_ENQUEUE: {
185
 
                                char buf[1024];
186
149
                                if (item.enclosure_url().length() > 0) {
187
 
                                        snprintf(buf, sizeof(buf), _("Added %s to download queue."), item.enclosure_url().c_str());
188
150
                                        v->get_ctrl()->enqueue_url(item.enclosure_url());
189
 
                                        v->set_status(buf);
 
151
                                        v->set_status(utils::strprintf(_("Added %s to download queue."), item.enclosure_url().c_str()));
190
152
                                }
191
153
                        }
192
154
                        break;
193
155
                case OP_SAVE:
194
156
                        {
195
 
                                char buf[1024];
196
157
                                GetLogger().log(LOG_INFO, "view::run_itemview: saving article");
197
158
                                std::string filename;
198
159
                                if (automatic) {
205
166
                                        v->show_error(_("Aborted saving."));
206
167
                                } else {
207
168
                                        try {
208
 
                                                v->write_item(item, filename);
209
 
                                                snprintf(buf, sizeof(buf), _("Saved article to %s."), filename.c_str());
210
 
                                                v->show_error(buf);
 
169
                                                v->get_ctrl()->write_item(item, filename);
 
170
                                                v->show_error(utils::strprintf(_("Saved article to %s."), filename.c_str()));
211
171
                                        } catch (...) {
212
 
                                                snprintf(buf, sizeof(buf), _("Error: couldn't write article to file %s"), filename.c_str());
213
 
                                                v->show_error(buf);
 
172
                                                v->show_error(utils::strprintf(_("Error: couldn't write article to file %s"), filename.c_str()));
214
173
                                        }
215
174
                                }
216
175
                        }
354
313
                if (tokens[0] == "save" && tokens.size() >= 2) {
355
314
                        std::string filename = utils::resolve_tilde(tokens[1]);
356
315
                        rss_item& item = feed->get_item_by_guid(guid);
357
 
                        char buf[1024];
358
316
 
359
317
                        if (filename == "") {
360
318
                                v->show_error(_("Aborted saving."));
361
319
                        } else {
362
320
                                try {
363
 
                                        v->write_item(item, filename);
364
 
                                        snprintf(buf, sizeof(buf), _("Saved article to %s"), filename.c_str());
365
 
                                        v->show_error(buf);
 
321
                                        v->get_ctrl()->write_item(item, filename);
 
322
                                        v->show_error(utils::strprintf(_("Saved article to %s"), filename.c_str()));
366
323
                                } catch (...) {
367
 
                                        snprintf(buf, sizeof(buf), _("Error: couldn't save article to %s"), filename.c_str());
368
 
                                        v->show_error(buf);
 
324
                                        v->show_error(utils::strprintf(_("Error: couldn't save article to %s"), filename.c_str()));
369
325
                                }
370
326
                        }
371
327