25 #include "feedstoragedummyimpl.h"
26 #include "storagedummyimpl.h"
32 #include <tqstringlist.h>
33 #include <tqvaluelist.h>
39 class FeedStorageDummyImpl::FeedStorageDummyImplPrivate
45 Entry() : guidIsHash(false), guidIsPermaLink(false), status(0), pubDate(0), hash(0) {}
46 StorageDummyImpl* mainStorage;
47 TQValueList<Category> categories;
52 TQString commentsLink;
61 TQString enclosureUrl;
62 TQString enclosureType;
65 TQMap<TQString, Entry> entries;
71 TQMap<TQString, TQStringList > taggedArticles;
73 TQValueList<Category> categories;
74 TQMap<Category, TQStringList> categorizedArticles;
81 void FeedStorageDummyImpl::convertOldArchive()
85 FeedStorageDummyImpl::FeedStorageDummyImpl(
const TQString& url, StorageDummyImpl* main) : d(new FeedStorageDummyImplPrivate)
88 d->mainStorage = main;
91 FeedStorageDummyImpl::~FeedStorageDummyImpl()
96 void FeedStorageDummyImpl::commit()
100 void FeedStorageDummyImpl::rollback()
104 void FeedStorageDummyImpl::close()
108 int FeedStorageDummyImpl::unread()
110 return d->mainStorage->unreadFor(d->url);
113 void FeedStorageDummyImpl::setUnread(
int unread)
115 d->mainStorage->setUnreadFor(d->url, unread);
118 int FeedStorageDummyImpl::totalCount()
120 return d->mainStorage->totalCountFor(d->url);
123 void FeedStorageDummyImpl::setTotalCount(
int total)
125 d->mainStorage->setTotalCountFor(d->url, total);
128 int FeedStorageDummyImpl::lastFetch()
130 return d->mainStorage->lastFetchFor(d->url);
133 void FeedStorageDummyImpl::setLastFetch(
int lastFetch)
135 d->mainStorage->setLastFetchFor(d->url, lastFetch);
138 TQStringList FeedStorageDummyImpl::articles(
const TQString& tag)
140 return tag.isNull() ? TQStringList(d->entries.keys()) : d->taggedArticles[tag];
143 TQStringList FeedStorageDummyImpl::articles(
const Category& cat)
145 return d->categorizedArticles[cat];
148 void FeedStorageDummyImpl::addEntry(
const TQString& guid)
150 if (!d->entries.contains(guid))
152 d->entries[guid] = FeedStorageDummyImplPrivate::Entry();
153 setTotalCount(totalCount()+1);
157 bool FeedStorageDummyImpl::contains(
const TQString& guid)
159 return d->entries.contains(guid);
162 void FeedStorageDummyImpl::deleteArticle(
const TQString& guid)
164 if (!d->entries.contains(guid))
169 d->entries.remove(guid);
172 int FeedStorageDummyImpl::comments(
const TQString& guid)
175 return contains(guid) ? d->entries[guid].comments : 0;
178 TQString FeedStorageDummyImpl::commentsLink(
const TQString& guid)
180 return contains(guid) ? d->entries[guid].commentsLink :
"";
183 bool FeedStorageDummyImpl::guidIsHash(
const TQString& guid)
185 return contains(guid) ? d->entries[guid].guidIsHash :
false;
188 bool FeedStorageDummyImpl::guidIsPermaLink(
const TQString& guid)
190 return contains(guid) ? d->entries[guid].guidIsPermaLink :
false;
193 uint FeedStorageDummyImpl::hash(
const TQString& guid)
195 return contains(guid) ? d->entries[guid].hash : 0;
199 void FeedStorageDummyImpl::setDeleted(
const TQString& guid)
204 FeedStorageDummyImplPrivate::Entry entry = d->entries[guid];
207 TQStringList::ConstIterator it = entry.tags.begin();
208 TQStringList::ConstIterator end = entry.tags.end();
210 for ( ; it != end; ++it)
212 d->taggedArticles[*it].remove(guid);
213 if (d->taggedArticles[*it].count() == 0)
218 TQValueList<Category>::ConstIterator it2 = entry.categories.begin();
219 TQValueList<Category>::ConstIterator end2 = entry.categories.end();
221 for ( ; it2 != end2; ++it2)
223 d->categorizedArticles[*it2].remove(guid);
224 if (d->categorizedArticles[*it2].count() == 0)
225 d->categories.remove(*it2);
228 entry.description =
"";
231 entry.commentsLink =
"";
234 TQString FeedStorageDummyImpl::link(
const TQString& guid)
236 return contains(guid) ? d->entries[guid].link :
"";
239 uint FeedStorageDummyImpl::pubDate(
const TQString& guid)
241 return contains(guid) ? d->entries[guid].pubDate : 0;
244 int FeedStorageDummyImpl::status(
const TQString& guid)
246 return contains(guid) ? d->entries[guid].status : 0;
249 void FeedStorageDummyImpl::setStatus(
const TQString& guid,
int status)
252 d->entries[guid].status = status;
255 TQString FeedStorageDummyImpl::title(
const TQString& guid)
257 return contains(guid) ? d->entries[guid].title :
"";
260 TQString FeedStorageDummyImpl::description(
const TQString& guid)
262 return contains(guid) ? d->entries[guid].description :
"";
266 void FeedStorageDummyImpl::setPubDate(
const TQString& guid, uint pubdate)
269 d->entries[guid].pubDate = pubdate;
272 void FeedStorageDummyImpl::setGuidIsHash(
const TQString& guid,
bool isHash)
275 d->entries[guid].guidIsHash = isHash;
278 void FeedStorageDummyImpl::setLink(
const TQString& guid,
const TQString& link)
281 d->entries[guid].link = link;
284 void FeedStorageDummyImpl::setHash(
const TQString& guid, uint hash)
287 d->entries[guid].hash = hash;
290 void FeedStorageDummyImpl::setTitle(
const TQString& guid,
const TQString& title)
293 d->entries[guid].title = title;
296 void FeedStorageDummyImpl::setDescription(
const TQString& guid,
const TQString& description)
299 d->entries[guid].description = description;
302 void FeedStorageDummyImpl::setCommentsLink(
const TQString& guid,
const TQString& commentsLink)
305 d->entries[guid].commentsLink = commentsLink;
308 void FeedStorageDummyImpl::setComments(
const TQString& guid,
int comments)
311 d->entries[guid].comments = comments;
315 void FeedStorageDummyImpl::setGuidIsPermaLink(
const TQString& guid,
bool isPermaLink)
318 d->entries[guid].guidIsPermaLink = isPermaLink;
321 void FeedStorageDummyImpl::addTag(
const TQString& guid,
const TQString& tag)
325 d->entries[guid].tags.append(tag);
326 if (!d->taggedArticles[tag].contains(guid))
327 d->taggedArticles[tag].append(guid);
328 if (!d->tags.contains(tag))
334 void FeedStorageDummyImpl::addCategory(
const TQString& guid,
const Category& cat)
339 d->entries[guid].categories.append(cat);
341 if (d->categorizedArticles[cat].count() == 0)
342 d->categories.append(cat);
343 d->categorizedArticles[cat].append(guid);
346 void FeedStorageDummyImpl::setAuthor(
const TQString& guid,
const TQString& author)
349 d->entries[guid].author = author;
352 TQString FeedStorageDummyImpl::author(
const TQString& guid)
354 return contains(guid) ? d->entries[guid].author : TQString();
357 TQValueList<Category> FeedStorageDummyImpl::categories(
const TQString& guid)
360 return contains(guid) ? d->entries[guid].categories : TQValueList<Category>();
362 return d->categories;
366 void FeedStorageDummyImpl::removeTag(
const TQString& guid,
const TQString& tag)
370 d->entries[guid].tags.remove(tag);
371 d->taggedArticles[tag].remove(guid);
372 if (d->taggedArticles[tag].count() == 0)
377 TQStringList FeedStorageDummyImpl::tags(
const TQString& guid)
380 return contains(guid) ? d->entries[guid].tags : TQStringList();
387 void FeedStorageDummyImpl::add(FeedStorage* source)
389 TQStringList articles = source->articles();
390 for (TQStringList::ConstIterator it = articles.begin(); it != articles.end(); ++it)
391 copyArticle(*it, source);
392 setUnread(source->unread());
393 setLastFetch(source->lastFetch());
394 setTotalCount(source->totalCount());
397 void FeedStorageDummyImpl::copyArticle(
const TQString& guid, FeedStorage* source)
402 setComments(guid, source->comments(guid));
403 setCommentsLink(guid, source->commentsLink(guid));
404 setDescription(guid, source->description(guid));
405 setGuidIsHash(guid, source->guidIsHash(guid));
406 setGuidIsPermaLink(guid, source->guidIsPermaLink(guid));
407 setHash(guid, source->hash(guid));
408 setLink(guid, source->link(guid));
409 setPubDate(guid, source->pubDate(guid));
410 setStatus(guid, source->status(guid));
411 setTitle(guid, source->title(guid));
412 TQStringList tags = source->tags(guid);
414 for (TQStringList::ConstIterator it = tags.begin(); it != tags.end(); ++it)
418 void FeedStorageDummyImpl::clear()
425 void FeedStorageDummyImpl::setEnclosure(
const TQString& guid,
const TQString& url,
const TQString& type,
int length)
429 FeedStorageDummyImplPrivate::Entry entry = d->entries[guid];
430 entry.hasEnclosure =
true;
431 entry.enclosureUrl = url;
432 entry.enclosureType = type;
433 entry.enclosureLength = length;
437 void FeedStorageDummyImpl::removeEnclosure(
const TQString& guid)
441 FeedStorageDummyImplPrivate::Entry entry = d->entries[guid];
442 entry.hasEnclosure =
false;
443 entry.enclosureUrl = TQString();
444 entry.enclosureType = TQString();
445 entry.enclosureLength = -1;
449 void FeedStorageDummyImpl::enclosure(
const TQString& guid,
bool& hasEnclosure, TQString& url, TQString& type,
int& length)
453 FeedStorageDummyImplPrivate::Entry entry = d->entries[guid];
454 hasEnclosure = entry.hasEnclosure;
455 url = entry.enclosureUrl;
456 type = entry.enclosureType;
457 length = entry.enclosureLength;
461 hasEnclosure =
false;