void UnTiny::parse(QPointer<Choqok::UI::PostWidget> postToParse) { if(!postToParse) return; QStringList redirectList, pureList = postToParse->urls(); QString content = postToParse->currentPost()->content; for (int i=0; i < pureList.count(); ++i) { if(pureList[i].length() > 30){ continue; } if(!pureList[i].startsWith(QLatin1String("http"), Qt::CaseInsensitive)){ pureList[i].prepend(QLatin1String("http://")); } redirectList << pureList[i]; } for (const QString &url: redirectList) { KIO::MimetypeJob *job = KIO::mimetype( QUrl::fromUserInput(url), KIO::HideProgressInfo ); if ( !job ) { qCritical() << "Cannot create a http header request!"; break; } connect( job, &KIO::MimetypeJob::permanentRedirection, this, &UnTiny::slot301Redirected ); mParsingList.insert(job, postToParse); job->start(); } }
bool DropHandler::handleURL(const QList<QUrl>& urls_) { bool hasUnknown = false; QList<QUrl> tc, pdf, bib, ris, ciw; foreach(const QUrl& url, urls_) { QMimeType ptr; // findByURL doesn't work for http, so actually query // the url itself if(url.scheme() != QLatin1String("http")) { QMimeDatabase db; ptr = db.mimeTypeForUrl(url); } else { KIO::MimetypeJob* job = KIO::mimetype(url, KIO::HideProgressInfo); KJobWidgets::setWindow(job, GUI::Proxy::widget()); job->exec(); QMimeDatabase db; ptr = db.mimeTypeForName(job->mimetype()); } if(ptr.inherits(QLatin1String("application/x-tellico"))) { tc << url; } else if(ptr.inherits(QLatin1String("application/pdf"))) { pdf << url; } else if(ptr.inherits(QLatin1String("text/x-bibtex")) || ptr.inherits(QLatin1String("application/x-bibtex")) || ptr.inherits(QLatin1String("application/bibtex"))) { bib << url; } else if(ptr.inherits(QLatin1String("application/x-research-info-systems"))) { ris << url; } else if(url.fileName().endsWith(QLatin1String(".bib"))) { bib << url; } else if(url.fileName().endsWith(QLatin1String(".ris"))) { ris << url; } else if(url.fileName().endsWith(QLatin1String(".ciw"))) { ciw << url; } else if(ptr.inherits(QLatin1String("text/plain")) && Import::BibtexImporter::maybeBibtex(url)) { bib << url; } else if(ptr.inherits(QLatin1String("text/plain")) && Import::RISImporter::maybeRIS(url)) { ris << url; } else if(ptr.inherits(QLatin1String("text/plain")) && Import::CIWImporter::maybeCIW(url)) { ciw << url; } else { myDebug() << "unrecognized type: " << ptr.name() << " (" << url << ")"; hasUnknown = true; } }
void ShareProvider::onMimetypeJobFinished(KJob* job) { KIO::MimetypeJob *mjob = qobject_cast<KIO::MimetypeJob *>(job); if (!mjob) { return; } if (mjob->error()) { Q_EMIT finishedError(this, mjob->errorString()); return; } QString mimeType = mjob->mimetype(); if (mimeType.isEmpty()) { Q_EMIT finishedError(this, i18n("Could not detect the file's mimetype")); return; } if (!mimeType.startsWith(QLatin1String("image/"))) { Q_EMIT finishedError(this, i18n("File Type is not an image")); return; } KIO::FileJob *fjob = KIO::open(mjob->url(), QIODevice::ReadOnly); connect(fjob, SIGNAL(open(KIO::Job*)), this, SLOT(onFileOpened(KIO::Job*))); mjob->deleteLater(); }