akregator/src
storagedummyimpl.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "storagedummyimpl.h"
00025 #include "feedstoragedummyimpl.h"
00026
00027 #include <qmap.h>
00028 #include <qstring.h>
00029 #include <qstringlist.h>
00030
00031 namespace Akregator {
00032 namespace Backend {
00033
00034 class StorageDummyImpl::StorageDummyImplPrivate
00035 {
00036 public:
00037 class Entry
00038 {
00039 public:
00040 int unread;
00041 int totalCount;
00042 int lastFetch;
00043 FeedStorage* feedStorage;
00044 };
00045
00046 void addEntry(const QString& url, int unread, int totalCount, int lastFetch)
00047 {
00048 Entry entry;
00049 entry.unread = unread;
00050 entry.totalCount = totalCount;
00051 entry.lastFetch = lastFetch;
00052 entry.feedStorage = 0;
00053 feeds[url] = entry;
00054
00055 }
00056 QString tagSet;
00057 QString feedList;
00058 QMap<QString, Entry> feeds;
00059 };
00060
00061 StorageDummyImpl::StorageDummyImpl() : d(new StorageDummyImplPrivate)
00062 {
00063 }
00064
00065 StorageDummyImpl::~StorageDummyImpl()
00066 {
00067 delete d; d = 0;
00068 }
00069 void StorageDummyImpl::initialize(const QStringList&) {}
00070
00071 bool StorageDummyImpl::open(bool )
00072 {
00073 return true;
00074 }
00075
00076 bool StorageDummyImpl::autoCommit() const
00077 {
00078 return false;
00079 }
00080
00081 bool StorageDummyImpl::close()
00082 {
00083 for (QMap<QString, StorageDummyImplPrivate::Entry>::ConstIterator it = d->feeds.begin(); it != d->feeds.end(); ++it)
00084 {
00085 (*it).feedStorage->close();
00086 delete (*it).feedStorage;
00087 }
00088 return true;
00089 }
00090
00091 bool StorageDummyImpl::commit()
00092 {
00093 return true;
00094 }
00095
00096 bool StorageDummyImpl::rollback()
00097 {
00098 return true;
00099 }
00100
00101 int StorageDummyImpl::unreadFor(const QString &url)
00102 {
00103 return d->feeds.contains(url) ? d->feeds[url].unread : 0;
00104 }
00105
00106 void StorageDummyImpl::setUnreadFor(const QString &url, int unread)
00107 {
00108 if (!d->feeds.contains(url))
00109 d->addEntry(url, unread, unread, 0);
00110 else
00111 d->feeds[url].unread = unread;
00112 }
00113
00114 int StorageDummyImpl::totalCountFor(const QString &url)
00115 {
00116 return d->feeds.contains(url) ? d->feeds[url].totalCount : 0;
00117 }
00118
00119 void StorageDummyImpl::setTotalCountFor(const QString &url, int total)
00120 {
00121 if (!d->feeds.contains(url))
00122 d->addEntry(url, 0, total, 0);
00123 else
00124 d->feeds[url].totalCount = total;
00125 }
00126
00127 int StorageDummyImpl::lastFetchFor(const QString& url)
00128 {
00129 return d->feeds.contains(url) ? d->feeds[url].lastFetch : 0;
00130 }
00131
00132 void StorageDummyImpl::setLastFetchFor(const QString& url, int lastFetch)
00133 {
00134 if (!d->feeds.contains(url))
00135 d->addEntry(url, 0, 0, lastFetch);
00136 else
00137 d->feeds[url].lastFetch = lastFetch;
00138 }
00139
00140 void StorageDummyImpl::slotCommit()
00141 {
00142 }
00143
00144 FeedStorage* StorageDummyImpl::archiveFor(const QString& url)
00145 {
00146 if (!d->feeds.contains(url))
00147 d->feeds[url].feedStorage = new FeedStorageDummyImpl(url, this);
00148
00149 return d->feeds[url].feedStorage;
00150 }
00151
00152 QStringList StorageDummyImpl::feeds() const
00153 {
00154 return d->feeds.keys();
00155 }
00156
00157 void StorageDummyImpl::add(Storage* source)
00158 {
00159 QStringList feeds = source->feeds();
00160 for (QStringList::ConstIterator it = feeds.begin(); it != feeds.end(); ++it)
00161 {
00162 FeedStorage* fa = archiveFor(*it);
00163 fa->add(source->archiveFor(*it));
00164 }
00165 }
00166
00167 void StorageDummyImpl::clear()
00168 {
00169 for (QMap<QString, StorageDummyImplPrivate::Entry>::ConstIterator it = d->feeds.begin(); it != d->feeds.end(); ++it)
00170 {
00171 delete (*it).feedStorage;
00172 }
00173 d->feeds.clear();
00174
00175 }
00176
00177 void StorageDummyImpl::storeFeedList(const QString& opmlStr)
00178 {
00179 d->feedList = opmlStr;
00180 }
00181
00182 QString StorageDummyImpl::restoreFeedList() const
00183 {
00184 return d->feedList;
00185 }
00186
00187 void StorageDummyImpl::storeTagSet(const QString& xmlStr)
00188 {
00189 d->tagSet = xmlStr;
00190 }
00191
00192 QString StorageDummyImpl::restoreTagSet() const
00193 {
00194 return d->tagSet;
00195 }
00196
00197 }
00198 }
00199
00200 #include "storagedummyimpl.moc"
|