Esempio n. 1
0
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();
}
Esempio n. 2
0
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;
    }
  }