akregator/src

storagedummyimpl.cpp
1 /*
2  This file is part of Akregator.
3 
4  2005 Frank Osterfeld <frank.osterfeld@kdemail.net>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 #include "storagedummyimpl.h"
25 #include "feedstoragedummyimpl.h"
26 
27 #include <tqmap.h>
28 #include <tqstring.h>
29 #include <tqstringlist.h>
30 
31 namespace Akregator {
32 namespace Backend {
33 
34 class StorageDummyImpl::StorageDummyImplPrivate
35 {
36  public:
37  class Entry
38  {
39  public:
40  int unread;
41  int totalCount;
42  int lastFetch;
43  FeedStorage* feedStorage;
44  };
45 
46  void addEntry(const TQString& url, int unread, int totalCount, int lastFetch)
47  {
48  Entry entry;
49  entry.unread = unread;
50  entry.totalCount = totalCount;
51  entry.lastFetch = lastFetch;
52  entry.feedStorage = 0;
53  feeds[url] = entry;
54 
55  }
56  TQString tagSet;
57  TQString feedList;
58  TQMap<TQString, Entry> feeds;
59 };
60 
61 StorageDummyImpl::StorageDummyImpl() : d(new StorageDummyImplPrivate)
62 {
63 }
64 
65 StorageDummyImpl::~StorageDummyImpl()
66 {
67  delete d; d = 0;
68 }
69 void StorageDummyImpl::initialize(const TQStringList&) {}
70 
71 bool StorageDummyImpl::open(bool /*autoCommit*/)
72 {
73  return true;
74 }
75 
76 bool StorageDummyImpl::autoCommit() const
77 {
78  return false;
79 }
80 
81 bool StorageDummyImpl::close()
82 {
83  for (TQMap<TQString, StorageDummyImplPrivate::Entry>::ConstIterator it = d->feeds.begin(); it != d->feeds.end(); ++it)
84  {
85  (*it).feedStorage->close();
86  delete (*it).feedStorage;
87  }
88  return true;
89 }
90 
91 bool StorageDummyImpl::commit()
92 {
93  return true;
94 }
95 
96 bool StorageDummyImpl::rollback()
97 {
98  return true;
99 }
100 
101 int StorageDummyImpl::unreadFor(const TQString &url)
102 {
103  return d->feeds.contains(url) ? d->feeds[url].unread : 0;
104 }
105 
106 void StorageDummyImpl::setUnreadFor(const TQString &url, int unread)
107 {
108  if (!d->feeds.contains(url))
109  d->addEntry(url, unread, unread, 0);
110  else
111  d->feeds[url].unread = unread;
112 }
113 
114 int StorageDummyImpl::totalCountFor(const TQString &url)
115 {
116  return d->feeds.contains(url) ? d->feeds[url].totalCount : 0;
117 }
118 
119 void StorageDummyImpl::setTotalCountFor(const TQString &url, int total)
120 {
121  if (!d->feeds.contains(url))
122  d->addEntry(url, 0, total, 0);
123  else
124  d->feeds[url].totalCount = total;
125 }
126 
127 int StorageDummyImpl::lastFetchFor(const TQString& url)
128 {
129  return d->feeds.contains(url) ? d->feeds[url].lastFetch : 0;
130 }
131 
132 void StorageDummyImpl::setLastFetchFor(const TQString& url, int lastFetch)
133 {
134  if (!d->feeds.contains(url))
135  d->addEntry(url, 0, 0, lastFetch);
136  else
137  d->feeds[url].lastFetch = lastFetch;
138 }
139 
140 void StorageDummyImpl::slotCommit()
141 {
142 }
143 
144 FeedStorage* StorageDummyImpl::archiveFor(const TQString& url)
145 {
146  if (!d->feeds.contains(url))
147  d->feeds[url].feedStorage = new FeedStorageDummyImpl(url, this);
148 
149  return d->feeds[url].feedStorage;
150 }
151 
152 TQStringList StorageDummyImpl::feeds() const
153 {
154  return d->feeds.keys();
155 }
156 
157 void StorageDummyImpl::add(Storage* source)
158 {
159  TQStringList feeds = source->feeds();
160  for (TQStringList::ConstIterator it = feeds.begin(); it != feeds.end(); ++it)
161  {
162  FeedStorage* fa = archiveFor(*it);
163  fa->add(source->archiveFor(*it));
164  }
165 }
166 
167 void StorageDummyImpl::clear()
168 {
169  for (TQMap<TQString, StorageDummyImplPrivate::Entry>::ConstIterator it = d->feeds.begin(); it != d->feeds.end(); ++it)
170  {
171  delete (*it).feedStorage;
172  }
173  d->feeds.clear();
174 
175 }
176 
177 void StorageDummyImpl::storeFeedList(const TQString& opmlStr)
178 {
179  d->feedList = opmlStr;
180 }
181 
182 TQString StorageDummyImpl::restoreFeedList() const
183 {
184  return d->feedList;
185 }
186 
187 void StorageDummyImpl::storeTagSet(const TQString& xmlStr)
188 {
189  d->tagSet = xmlStr;
190 }
191 
192 TQString StorageDummyImpl::restoreTagSet() const
193 {
194  return d->tagSet;
195 }
196 
197 } // namespace Backend
198 } // namespace Akregator
199 
200 #include "storagedummyimpl.moc"
virtual TQStringList feeds() const
returns a list of all feeds (URLs) stored in this archive
Storage is the main interface to the article archive.
Definition: storage.h:45
virtual FeedStorage * archiveFor(const TQString &url)=0
virtual TQStringList feeds() const =0
returns a list of all feeds (URLs) stored in this archive