From c019b0d72c2a30983817149bf27ce5201e05a8d7 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 22 Jul 2007 15:02:19 +0000 Subject: [PATCH] - Added some debug in rss --- src/downloadThread.h | 29 +++++++++++++++++------------ src/rss.h | 11 +++++++++++ src/rss_imp.cpp | 3 +++ 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/downloadThread.h b/src/downloadThread.h index 28678c0fd..54e1f2d97 100644 --- a/src/downloadThread.h +++ b/src/downloadThread.h @@ -45,7 +45,7 @@ class downloadThread : public QThread { QMutex mutex; QWaitCondition condition; bool abort; - URLStream url_stream; + URLStream *url_stream; QList subThreads; bool subThread; @@ -58,10 +58,11 @@ class downloadThread : public QThread { public: downloadThread(QObject* parent, bool subThread = false) : QThread(parent){ - mutex.lock(); + qDebug("Creating downloadThread"); abort = false; - mutex.unlock(); this->subThread = subThread; + url_stream = 0; + qDebug("downloadThread created"); } ~downloadThread(){ @@ -69,10 +70,14 @@ class downloadThread : public QThread { abort = true; condition.wakeOne(); mutex.unlock(); + if(url_stream != 0) + delete url_stream; wait(); } void downloadUrl(QString url){ + if(url_stream == 0) + url_stream = new URLStream(); QMutexLocker locker(&mutex); url_list << url; if(!isRunning()){ @@ -139,31 +144,31 @@ class downloadThread : public QThread { std::cerr << "Error: could't create temporary file: " << (const char*)filePath.toUtf8() << '\n'; continue; } - URLStream::Error status = url_stream.get((const char*)url.toUtf8()); + URLStream::Error status = url_stream->get((const char*)url.toUtf8()); if(status){ // Failure - QString error_msg = QString(misc::toString(status).c_str()); + QString error_msg = errorCodeToString(status); qDebug("Download failed for %s, reason: %s", (const char*)url.toUtf8(), (const char*)error_msg.toUtf8()); - url_stream.close(); - emit downloadFailureST(this, url, errorCodeToString(status)); + url_stream->close(); + emit downloadFailureST(this, url, error_msg); continue; } qDebug("Downloading %s...", (const char*)url.toUtf8()); char cbuf[1024]; int len; - while(!url_stream.eof()) { - url_stream.read(cbuf, sizeof(cbuf)); - len = url_stream.gcount(); + while(!url_stream->eof()) { + url_stream->read(cbuf, sizeof(cbuf)); + len = url_stream->gcount(); if(len > 0) dest_file.write(cbuf, len); if(abort){ dest_file.close(); - url_stream.close(); + url_stream->close(); return; } } dest_file.close(); - url_stream.close(); + url_stream->close(); emit downloadFinishedST(this, url, filePath); qDebug("download completed here: %s", (const char*)filePath.toUtf8()); }else{ diff --git a/src/rss.h b/src/rss.h index 54e249f95..d48311c8b 100644 --- a/src/rss.h +++ b/src/rss.h @@ -161,18 +161,26 @@ class RssStream : public QObject{ public: RssStream(QString _url) { + qDebug("New rss stream created"); url = _url; alias = url; read = true; + qDebug("Creating rss & ico downloadThreads"); downloaderRss = new downloadThread(this); downloaderIcon = new downloadThread(this); + qDebug("RSS & ico downloaders created"); connect(downloaderRss, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString))); connect(downloaderRss, SIGNAL(downloadFailure(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString))); + qDebug("RSS is calling downloadUrl"); downloaderRss->downloadUrl(url); + qDebug("downloadUrl called, ok"); // XXX: remove it when gif can be displayed iconPath = ":/Icons/rss.png"; + qDebug("Calling getIcon"); getIcon(); + qDebug("getIcon called"); lastRefresh.start(); + qDebug("RSSStream constructed"); } ~RssStream(){ @@ -451,10 +459,13 @@ class RssManager : public QObject{ unsigned int streamListUrlSize = streamListUrl.size(); for(unsigned int i=0; isetAlias(streamListAlias.at(i)); + qDebug("RSS Alias set"); streamList.append(stream); connect(stream, SIGNAL(refreshFinished(QString, const unsigned short&)), this, SLOT(streamNeedRefresh(QString, const unsigned short&))); } + qDebug("Streams loaded"); } // save the list of the rss stream for the next session diff --git a/src/rss_imp.cpp b/src/rss_imp.cpp index 5115ca579..8989e8466 100644 --- a/src/rss_imp.cpp +++ b/src/rss_imp.cpp @@ -182,6 +182,7 @@ // fills the streamList void RSSImp::refreshStreamList() { + qDebug("Refreshing stream list"); unsigned short nbstream = rssmanager.getNbStreams(); listStreams->clear(); QList streams; @@ -190,6 +191,7 @@ updateStreamName(i, NEWS); stream->setToolTip(0, QString("")+tr("Description:")+QString(" ")+rssmanager.getStream(i)->getDescription()+QString("
")+tr("url:")+QString(" ")+rssmanager.getStream(i)->getUrl()+QString("
")+tr("Last refresh:")+QString(" ")+rssmanager.getStream(i)->getLastRefreshElapsedString()); } + qDebug("Stream list refreshed"); } // fills the newsList @@ -294,6 +296,7 @@ refreshTimeTimer.start(60000); // 1min refreshStreamList(); refreshTextBrowser(); + qDebug("RSSImp constructed"); } RSSImp::~RSSImp(){