Debian Codegraph @

code/datastructures/NewsSource.cpp

raw
1 /*
2 Copyright (C) 2009-2013 wxLauncher Team
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include <wx/intl.h> // for _()
20 #include <wx/log.h>
21 #include "NewsSource.h"
22
23 using std::vector;
24
25 vector<NewsSource> NewsSource::newsSources;
26
27 NewsSource::NewsSource(const NewsSourceId id, const wxString& name,
28 const wxString& newsUrl, const wxString& label)
29 : id(id), name(name), newsUrl(newsUrl), label(label) {
30 wxASSERT(!name.IsEmpty());
31 wxASSERT(!newsUrl.IsEmpty());
32 wxASSERT(!label.IsEmpty());
33 }
34
35 const NewsSource* NewsSource::FindSource(const NewsSourceId id) {
36 wxCHECK_MSG(id != NEWS_SOURCE_ID_INVALID, NULL,
37 _T("FindSource given NEWS_SOURCE_ID_INVALID!"));
38
39 if (newsSources.empty()) {
40 InitializeSources();
41 }
42
43 for (vector<NewsSource>::const_iterator it = newsSources.begin(),
44 end = newsSources.end(); it != end; ++it) {
45 if (it->GetId() == id) {
46 return &(*it);
47 }
48 }
49
50 wxLogWarning(_T("FindSource(): Unknown news source ID %d, returning NULL"), id);
51
52 return NULL;
53 }
54
55 const NewsSource* NewsSource::FindSource(const wxString& name) {
56 wxCHECK_MSG(!name.IsEmpty(), NULL,
57 _T("FindSource() given empty name!"));
58
59 if (newsSources.empty()) {
60 InitializeSources();
61 }
62
63 for (vector<NewsSource>::const_iterator it = newsSources.begin(),
64 end = newsSources.end(); it != end; ++it) {
65 if (!it->GetName().CmpNoCase(name)) {
66 return &(*it);
67 }
68 }
69
70 wxLogWarning(_T("FindSource(): Unknown name %s, returning NULL"), name.c_str());
71
72 return NULL;
73 }
74
75 void NewsSource::InitializeSources() {
76 wxASSERT_MSG(newsSources.empty(),
77 _T("news sources have already been initialized"));
78
79 // NOTE: According to http://docs.wxwidgets.org/stable/wx_wxcontrol.html#wxcontrolsetlabel ,
80 // individual '&'s will be interpreted to indicate keyboard shortcuts
81 // so if anyone wants a & to appear in the news box label, write it as &&
82 newsSources.push_back(
83 NewsSource(
84 NEWS_SOURCE_ID_HLP,
85 _T("hlp"),
86 _T("http://www.audiozone.ro/hl/"),
87 _("Latest highlights from Hard Light Productions")));
88 newsSources.push_back(
89 NewsSource(
90 NEWS_SOURCE_ID_DIASPORA,
91 _T("diaspora"),
92 _T("http://diaspora.hard-light.net/hl.htm"),
93 _("Latest Diaspora news")));
94 }