akregator
akregator.cpp
Go to the documentation of this file.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 "akregator.h"
00026 #include "subscriptionlist.h"
00027
00028 #include "feedlistmanagementinterface.h"
00029
00030 #include <kdebug.h>
00031 #include <QStringList>
00032 #include <QTimer>
00033
00034 namespace feedsync {
00035
00036 Akregator::Akregator( QObject* p ) : Aggregator( p )
00037 {
00038 kDebug();
00039 }
00040
00041 Akregator::~Akregator()
00042 {
00043 kDebug();
00044 }
00045
00046 SubscriptionList Akregator::getSubscriptionList() const
00047 {
00048 kDebug();
00049 return _subscriptionList;
00050 }
00051
00052 void Akregator::load()
00053 {
00054 kDebug();
00055
00056 using namespace Akregator;
00057
00058 FeedListManagementInterface * ak_feedlist = FeedListManagementInterface::instance();
00059 QStringList catlist = ak_feedlist->categories();
00060 for (int idcat=0;idcat<catlist.size();idcat++) {
00061 QStringList feedlist = ak_feedlist->feeds(catlist.at(idcat));
00062 for (int idfeed=0;idfeed<feedlist.size();idfeed++) {
00063 QString tmpcat;
00064 if (catlist.at(idcat).compare("1/")==0) {
00065 tmpcat = "";
00066 } else {
00067 tmpcat = ak_feedlist->getCategoryName(catlist.at(idcat));
00068 }
00069 _subscriptionList.add( feedlist.at(idfeed),
00070 feedlist.at(idfeed),
00071 tmpcat );
00072 }
00073 }
00074
00075
00076 QTimer::singleShot( 0, this, SLOT(sendSignalLoadDone()) );
00077 }
00078
00079 void Akregator::sendSignalLoadDone()
00080 {
00081 emit loadDone();
00082 }
00083
00084 void Akregator::add( const SubscriptionList & list)
00085 {
00086 kDebug();
00087
00088 using namespace Akregator;
00089
00090 for (int i=0; i<list.count(); i++) {
00091 kDebug() << list.getRss(i).left(20);
00092
00093 FeedListManagementInterface * ak_feedlist = FeedListManagementInterface::instance();
00094
00095
00096 QString foundCatId;
00097 if (list.getCat(i).isEmpty()) {
00098 foundCatId = "1";
00099 } else {
00100 QStringList catlist = ak_feedlist->categories();
00101 int idcat = 0;
00102 while (idcat<catlist.size() && foundCatId.isEmpty()) {
00103 QString ak_catId = catlist.at(idcat).split("/",QString::SkipEmptyParts).last();
00104 QString ak_cat = ak_feedlist->getCategoryName(ak_catId).split("/",QString::SkipEmptyParts).last();
00105 if (ak_cat.compare(list.getCat(i),Qt::CaseInsensitive)==0) {
00106 foundCatId = ak_catId;
00107 }
00108 idcat++;
00109 }
00110 }
00111
00112
00113 if (foundCatId.isEmpty()) {
00114 foundCatId = ak_feedlist->addCategory( list.getCat(i), "1" );
00115 }
00116
00117
00118 kDebug() << "Cat:" << foundCatId;
00119 ak_feedlist->addFeed(list.getRss(i),foundCatId);
00120 }
00121
00122
00123 emit addDone();
00124 }
00125
00126 void Akregator::update(const SubscriptionList & list)
00127 {
00128 kDebug();
00129
00130
00131 emit updateDone();
00132 }
00133
00134 void Akregator::remove(const SubscriptionList & list)
00135 {
00136 kDebug();
00137
00138 for (int i=0; i<list.count(); i++) {
00139 kDebug() << list.getRss(i).left(20);
00140
00141 using namespace Akregator;
00142
00143 FeedListManagementInterface * ak_feedlist = FeedListManagementInterface::instance();
00144
00145
00146 QString foundCatId;
00147 QStringList catlist = ak_feedlist->categories();
00148 int idcat = 0;
00149 while (idcat<catlist.size() && foundCatId.isEmpty()) {
00150 QString ak_catId = catlist.at(idcat).split("/",QString::SkipEmptyParts).last();
00151 QString ak_cat = ak_feedlist->getCategoryName(ak_catId).split("/",QString::SkipEmptyParts).last();
00152 if (ak_cat.compare(list.getCat(i),Qt::CaseInsensitive)==0) {
00153 foundCatId = ak_catId;
00154 }
00155 idcat++;
00156 }
00157
00158
00159 ak_feedlist->removeFeed(list.getRss(i),foundCatId);
00160 }
00161
00162
00163 emit removeDone();
00164 }
00165
00166 }