akregator/src

storagedummyimpl.cpp

00001 /*
00002     This file is part of Akregator.
00003 
00004     2005 Frank Osterfeld <frank.osterfeld@kdemail.net>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
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 /*autoCommit*/)
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 } // namespace Backend
00198 } // namespace Akregator
00199 
00200 #include "storagedummyimpl.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys