ImageThread* ThreadHandler::addThread() { ImageThread* ret; ret = new ImageThread(this); threadList.append(ret); ret->setBlackList(blackList); connect(ret, SIGNAL(closeRequest(ImageThread*,int)), this, SLOT(processCloseRequest(ImageThread*,int))); connect(ret, SIGNAL(createThreadRequest(QString)), this, SLOT(createThread(QString))); QLOG_TRACE() << "ThreadHandler :: adding thread"; return ret; }
void ImageThread::processRequestResponse(QUrl url, QByteArray ba, bool cached) { QString requestURI; QList<_IMAGE> imageList; QList<QUrl> threadList; ParsingStatus status; QString path; qint64 bytesWritten; QLOG_TRACE() << "ImageThread :: processRequestResponse (" << url.toString() << ", " << QString(ba); requestURI = url.toString(); path = url.path(); if (isImage(url)) { QFile f; QRegExp rx(__IMAGEFILE_REGEXP__, Qt::CaseInsensitive, QRegExp::RegExp2); QStringList res; int pos; pos = 0; pos = rx.indexIn(requestURI); res = rx.capturedTexts(); if (pos != -1) { f.setFileName(getSavepath()+"/"+res.at(1)+res.at(2)); if (_saveWithOriginalFilename) { _IMAGE tmp; for (int i=0; i<images.count(); i++) { if (images.at(i).largeURI.endsWith("/"+res.at(1)+res.at(2))) { tmp = images.at(i); f.setFileName(getSavepath()+"/"+tmp.originalFilename); break; } } } f.open(QIODevice::ReadWrite); bytesWritten = f.write(ba); f.close(); if (bytesWritten == ba.size()) { setCompleted(requestURI, f.fileName()); } else { QLOG_ERROR() << "UIImageOverview :: Couldn't save file from URI " << url.toString(); } } } else { iParser->setURL(url); status = iParser->parseHTML(ba); if (status.hasErrors) { QLOG_ERROR() << "ImageOverview :: Parser error " << iParser->getErrorCode(); switch (iParser->getErrorCode()) { case 404: stopDownload(); processCloseRequest(); break; default: break; } } else { if (status.isFrontpage) { QStringList newTab; QString v; v = getValues(); newTab = v.split(";;"); threadList = iParser->getUrlList(); foreach (QUrl u, threadList) { newTab.replace(0, u.toString()); emit createThreadRequest(newTab.join(";;")); } if (settings->value("options/close_overview_threads", true).toBool()) { emit closeRequest(this, 0); } } else { if (status.hasImages) {