00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "feedstoragedummyimpl.h"
00026 #include "storagedummyimpl.h"
00027
00028 #include <feed.h>
00029
00030 #include <qmap.h>
00031 #include <qstring.h>
00032 #include <qstringlist.h>
00033 #include <qvaluelist.h>
00034
00035
00036 namespace Akregator {
00037 namespace Backend {
00038
00039 class FeedStorageDummyImpl::FeedStorageDummyImplPrivate
00040 {
00041 public:
00042 class Entry
00043 {
00044 public:
00045 Entry() : guidIsHash(false), guidIsPermaLink(false), status(0), pubDate(0), hash(0) {}
00046 StorageDummyImpl* mainStorage;
00047 QValueList<Category> categories;
00048 QString title;
00049 QString description;
00050 QString link;
00051 QString author;
00052 QString commentsLink;
00053 bool guidIsHash;
00054 bool guidIsPermaLink;
00055 int comments;
00056 int status;
00057 uint pubDate;
00058 uint hash;
00059 QStringList tags;
00060 bool hasEnclosure;
00061 QString enclosureUrl;
00062 QString enclosureType;
00063 int enclosureLength;
00064 };
00065 QMap<QString, Entry> entries;
00066
00067
00068 QStringList tags;
00069
00070
00071 QMap<QString, QStringList > taggedArticles;
00072
00073 QValueList<Category> categories;
00074 QMap<Category, QStringList> categorizedArticles;
00075
00076 Storage* mainStorage;
00077 QString url;
00078 };
00079
00080
00081 void FeedStorageDummyImpl::convertOldArchive()
00082 {
00083 }
00084
00085 FeedStorageDummyImpl::FeedStorageDummyImpl(const QString& url, StorageDummyImpl* main) : d(new FeedStorageDummyImplPrivate)
00086 {
00087 d->url = url;
00088 d->mainStorage = main;
00089 }
00090
00091 FeedStorageDummyImpl::~FeedStorageDummyImpl()
00092 {
00093 delete d; d = 0;
00094 }
00095
00096 void FeedStorageDummyImpl::commit()
00097 {
00098 }
00099
00100 void FeedStorageDummyImpl::rollback()
00101 {
00102 }
00103
00104 void FeedStorageDummyImpl::close()
00105 {
00106 }
00107
00108 int FeedStorageDummyImpl::unread()
00109 {
00110 return d->mainStorage->unreadFor(d->url);
00111 }
00112
00113 void FeedStorageDummyImpl::setUnread(int unread)
00114 {
00115 d->mainStorage->setUnreadFor(d->url, unread);
00116 }
00117
00118 int FeedStorageDummyImpl::totalCount()
00119 {
00120 return d->mainStorage->totalCountFor(d->url);
00121 }
00122
00123 void FeedStorageDummyImpl::setTotalCount(int total)
00124 {
00125 d->mainStorage->setTotalCountFor(d->url, total);
00126 }
00127
00128 int FeedStorageDummyImpl::lastFetch()
00129 {
00130 return d->mainStorage->lastFetchFor(d->url);
00131 }
00132
00133 void FeedStorageDummyImpl::setLastFetch(int lastFetch)
00134 {
00135 d->mainStorage->setLastFetchFor(d->url, lastFetch);
00136 }
00137
00138 QStringList FeedStorageDummyImpl::articles(const QString& tag)
00139 {
00140 return tag.isNull() ? QStringList(d->entries.keys()) : d->taggedArticles[tag];
00141 }
00142
00143 QStringList FeedStorageDummyImpl::articles(const Category& cat)
00144 {
00145 return d->categorizedArticles[cat];
00146 }
00147
00148 void FeedStorageDummyImpl::addEntry(const QString& guid)
00149 {
00150 if (!d->entries.contains(guid))
00151 {
00152 d->entries[guid] = FeedStorageDummyImplPrivate::Entry();
00153 setTotalCount(totalCount()+1);
00154 }
00155 }
00156
00157 bool FeedStorageDummyImpl::contains(const QString& guid)
00158 {
00159 return d->entries.contains(guid);
00160 }
00161
00162 void FeedStorageDummyImpl::deleteArticle(const QString& guid)
00163 {
00164 if (!d->entries.contains(guid))
00165 return;
00166
00167 setDeleted(guid);
00168
00169 d->entries.remove(guid);
00170 }
00171
00172 int FeedStorageDummyImpl::comments(const QString& guid)
00173 {
00174
00175 return contains(guid) ? d->entries[guid].comments : 0;
00176 }
00177
00178 QString FeedStorageDummyImpl::commentsLink(const QString& guid)
00179 {
00180 return contains(guid) ? d->entries[guid].commentsLink : "";
00181 }
00182
00183 bool FeedStorageDummyImpl::guidIsHash(const QString& guid)
00184 {
00185 return contains(guid) ? d->entries[guid].guidIsHash : false;
00186 }
00187
00188 bool FeedStorageDummyImpl::guidIsPermaLink(const QString& guid)
00189 {
00190 return contains(guid) ? d->entries[guid].guidIsPermaLink : false;
00191 }
00192
00193 uint FeedStorageDummyImpl::hash(const QString& guid)
00194 {
00195 return contains(guid) ? d->entries[guid].hash : 0;
00196 }
00197
00198
00199 void FeedStorageDummyImpl::setDeleted(const QString& guid)
00200 {
00201 if (!contains(guid))
00202 return;
00203
00204 FeedStorageDummyImplPrivate::Entry entry = d->entries[guid];
00205
00206
00207 QStringList::ConstIterator it = entry.tags.begin();
00208 QStringList::ConstIterator end = entry.tags.end();
00209
00210 for ( ; it != end; ++it)
00211 {
00212 d->taggedArticles[*it].remove(guid);
00213 if (d->taggedArticles[*it].count() == 0)
00214 d->tags.remove(*it);
00215 }
00216
00217
00218 QValueList<Category>::ConstIterator it2 = entry.categories.begin();
00219 QValueList<Category>::ConstIterator end2 = entry.categories.end();
00220
00221 for ( ; it2 != end2; ++it2)
00222 {
00223 d->categorizedArticles[*it2].remove(guid);
00224 if (d->categorizedArticles[*it2].count() == 0)
00225 d->categories.remove(*it2);
00226 }
00227
00228 entry.description = "";
00229 entry.title = "";
00230 entry.link = "";
00231 entry.commentsLink = "";
00232 }
00233
00234 QString FeedStorageDummyImpl::link(const QString& guid)
00235 {
00236 return contains(guid) ? d->entries[guid].link : "";
00237 }
00238
00239 uint FeedStorageDummyImpl::pubDate(const QString& guid)
00240 {
00241 return contains(guid) ? d->entries[guid].pubDate : 0;
00242 }
00243
00244 int FeedStorageDummyImpl::status(const QString& guid)
00245 {
00246 return contains(guid) ? d->entries[guid].status : 0;
00247 }
00248
00249 void FeedStorageDummyImpl::setStatus(const QString& guid, int status)
00250 {
00251 if (contains(guid))
00252 d->entries[guid].status = status;
00253 }
00254
00255 QString FeedStorageDummyImpl::title(const QString& guid)
00256 {
00257 return contains(guid) ? d->entries[guid].title : "";
00258 }
00259
00260 QString FeedStorageDummyImpl::description(const QString& guid)
00261 {
00262 return contains(guid) ? d->entries[guid].description : "";
00263 }
00264
00265
00266 void FeedStorageDummyImpl::setPubDate(const QString& guid, uint pubdate)
00267 {
00268 if (contains(guid))
00269 d->entries[guid].pubDate = pubdate;
00270 }
00271
00272 void FeedStorageDummyImpl::setGuidIsHash(const QString& guid, bool isHash)
00273 {
00274 if (contains(guid))
00275 d->entries[guid].guidIsHash = isHash;
00276 }
00277
00278 void FeedStorageDummyImpl::setLink(const QString& guid, const QString& link)
00279 {
00280 if (contains(guid))
00281 d->entries[guid].link = link;
00282 }
00283
00284 void FeedStorageDummyImpl::setHash(const QString& guid, uint hash)
00285 {
00286 if (contains(guid))
00287 d->entries[guid].hash = hash;
00288 }
00289
00290 void FeedStorageDummyImpl::setTitle(const QString& guid, const QString& title)
00291 {
00292 if (contains(guid))
00293 d->entries[guid].title = title;
00294 }
00295
00296 void FeedStorageDummyImpl::setDescription(const QString& guid, const QString& description)
00297 {
00298 if (contains(guid))
00299 d->entries[guid].description = description;
00300 }
00301
00302 void FeedStorageDummyImpl::setCommentsLink(const QString& guid, const QString& commentsLink)
00303 {
00304 if (contains(guid))
00305 d->entries[guid].commentsLink = commentsLink;
00306 }
00307
00308 void FeedStorageDummyImpl::setComments(const QString& guid, int comments)
00309 {
00310 if (contains(guid))
00311 d->entries[guid].comments = comments;
00312 }
00313
00314
00315 void FeedStorageDummyImpl::setGuidIsPermaLink(const QString& guid, bool isPermaLink)
00316 {
00317 if (contains(guid))
00318 d->entries[guid].guidIsPermaLink = isPermaLink;
00319 }
00320
00321 void FeedStorageDummyImpl::addTag(const QString& guid, const QString& tag)
00322 {
00323 if (contains(guid))
00324 {
00325 d->entries[guid].tags.append(tag);
00326 if (!d->taggedArticles[tag].contains(guid))
00327 d->taggedArticles[tag].append(guid);
00328 if (!d->tags.contains(tag))
00329 d->tags.append(tag);
00330 }
00331
00332 }
00333
00334 void FeedStorageDummyImpl::addCategory(const QString& guid, const Category& cat)
00335 {
00336 if (!contains(guid))
00337 return;
00338
00339 d->entries[guid].categories.append(cat);
00340
00341 if (d->categorizedArticles[cat].count() == 0)
00342 d->categories.append(cat);
00343 d->categorizedArticles[cat].append(guid);
00344 }
00345
00346 void FeedStorageDummyImpl::setAuthor(const QString& guid, const QString& author)
00347 {
00348 if (contains(guid))
00349 d->entries[guid].author = author;
00350 }
00351
00352 QString FeedStorageDummyImpl::author(const QString& guid)
00353 {
00354 return contains(guid) ? d->entries[guid].author : QString();
00355 }
00356
00357 QValueList<Category> FeedStorageDummyImpl::categories(const QString& guid)
00358 {
00359 if (!guid.isNull())
00360 return contains(guid) ? d->entries[guid].categories : QValueList<Category>();
00361 else
00362 return d->categories;
00363 }
00364
00365
00366 void FeedStorageDummyImpl::removeTag(const QString& guid, const QString& tag)
00367 {
00368 if (contains(guid))
00369 {
00370 d->entries[guid].tags.remove(tag);
00371 d->taggedArticles[tag].remove(guid);
00372 if (d->taggedArticles[tag].count() == 0)
00373 d->tags.remove(tag);
00374 }
00375 }
00376
00377 QStringList FeedStorageDummyImpl::tags(const QString& guid)
00378 {
00379 if (!guid.isNull())
00380 return contains(guid) ? d->entries[guid].tags : QStringList();
00381 else
00382 {
00383 return d->tags;
00384 }
00385 }
00386
00387 void FeedStorageDummyImpl::add(FeedStorage* source)
00388 {
00389 QStringList articles = source->articles();
00390 for (QStringList::ConstIterator it = articles.begin(); it != articles.end(); ++it)
00391 copyArticle(*it, source);
00392 setUnread(source->unread());
00393 setLastFetch(source->lastFetch());
00394 setTotalCount(source->totalCount());
00395 }
00396
00397 void FeedStorageDummyImpl::copyArticle(const QString& guid, FeedStorage* source)
00398 {
00399 if (!contains(guid))
00400 addEntry(guid);
00401
00402 setComments(guid, source->comments(guid));
00403 setCommentsLink(guid, source->commentsLink(guid));
00404 setDescription(guid, source->description(guid));
00405 setGuidIsHash(guid, source->guidIsHash(guid));
00406 setGuidIsPermaLink(guid, source->guidIsPermaLink(guid));
00407 setHash(guid, source->hash(guid));
00408 setLink(guid, source->link(guid));
00409 setPubDate(guid, source->pubDate(guid));
00410 setStatus(guid, source->status(guid));
00411 setTitle(guid, source->title(guid));
00412 QStringList tags = source->tags(guid);
00413
00414 for (QStringList::ConstIterator it = tags.begin(); it != tags.end(); ++it)
00415 addTag(guid, *it);
00416 }
00417
00418 void FeedStorageDummyImpl::clear()
00419 {
00420 d->entries.clear();
00421 setUnread(0);
00422 setTotalCount(0);
00423 }
00424
00425 void FeedStorageDummyImpl::setEnclosure(const QString& guid, const QString& url, const QString& type, int length)
00426 {
00427 if (contains(guid))
00428 {
00429 FeedStorageDummyImplPrivate::Entry entry = d->entries[guid];
00430 entry.hasEnclosure = true;
00431 entry.enclosureUrl = url;
00432 entry.enclosureType = type;
00433 entry.enclosureLength = length;
00434 }
00435 }
00436
00437 void FeedStorageDummyImpl::removeEnclosure(const QString& guid)
00438 {
00439 if (contains(guid))
00440 {
00441 FeedStorageDummyImplPrivate::Entry entry = d->entries[guid];
00442 entry.hasEnclosure = false;
00443 entry.enclosureUrl = QString::null;
00444 entry.enclosureType = QString::null;
00445 entry.enclosureLength = -1;
00446 }
00447 }
00448
00449 void FeedStorageDummyImpl::enclosure(const QString& guid, bool& hasEnclosure, QString& url, QString& type, int& length)
00450 {
00451 if (contains(guid))
00452 {
00453 FeedStorageDummyImplPrivate::Entry entry = d->entries[guid];
00454 hasEnclosure = entry.hasEnclosure;
00455 url = entry.enclosureUrl;
00456 type = entry.enclosureType;
00457 length = entry.enclosureLength;
00458 }
00459 else
00460 {
00461 hasEnclosure = false;
00462 url = QString::null;
00463 type = QString::null;
00464 length = -1;
00465 }
00466 }
00467
00468 }
00469 }