diff options
Diffstat (limited to 'src/core/drophandler.cpp')
-rw-r--r-- | src/core/drophandler.cpp | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/src/core/drophandler.cpp b/src/core/drophandler.cpp index e609e7b..8d4875d 100644 --- a/src/core/drophandler.cpp +++ b/src/core/drophandler.cpp @@ -15,9 +15,13 @@ #include "../mainwindow.h" #include "../tellico_kernel.h" #include "../tellico_debug.h" +#include "../translators/bibteximporter.h" +#include "../translators/risimporter.h" #include <kurldrag.h> #include <kmimetype.h> +#include <tdeio/netaccess.h> +#include <tdeio/job.h> using Tellico::DropHandler; @@ -62,18 +66,37 @@ bool DropHandler::handleURL(const KURL::List& urls_) { bool hasUnknown = false; KURL::List tc, pdf, bib, ris; for(KURL::List::ConstIterator it = urls_.begin(); it != urls_.end(); ++it) { - KMimeType::Ptr ptr = KMimeType::findByURL(*it); + const KURL& url = *it; + KMimeType::Ptr ptr; + // findByURL doesn't work for http, so actually query + // the url itself + if(url.protocol() != TQString::fromLatin1("http")) { + ptr = KMimeType::findByURL(url); + } else { + TDEIO::MimetypeJob* job = TDEIO::mimetype(url, false /*progress*/); + TDEIO::NetAccess::synchronousRun(job, Kernel::self()->widget()); + ptr = KMimeType::mimeType(job->mimetype()); + } if(ptr->is(TQString::fromLatin1("application/x-tellico"))) { - tc << *it; + tc << url; } else if(ptr->is(TQString::fromLatin1("application/pdf"))) { - pdf << *it; + pdf << url; } else if(ptr->is(TQString::fromLatin1("text/x-bibtex")) || - ptr->is(TQString::fromLatin1("application/x-bibtex"))) { - bib << *it; + ptr->is(TQString::fromLatin1("application/x-bibtex")) || + ptr->is(TQString::fromLatin1("application/bibtex"))) { + bib << url; } else if(ptr->is(TQString::fromLatin1("application/x-research-info-systems"))) { - ris << *it; + ris << url; + } else if(url.fileName().endsWith(TQString::fromLatin1(".bib"))) { + bib << url; + } else if(url.fileName().endsWith(TQString::fromLatin1(".ris"))) { + ris << url; + } else if(ptr->is(TQString::fromLatin1("text/plain")) && Import::BibtexImporter::maybeBibtex(url)) { + bib << url; + } else if(ptr->is(TQString::fromLatin1("text/plain")) && Import::RISImporter::maybeRIS(url)) { + ris << url; } else { - myDebug() << "DropHandler::handleURL() - unrecognized type: " << ptr->name() << " (" << *it << ")" << endl; + myDebug() << "DropHandler::handleURL() - unrecognized type: " << ptr->name() << " (" << url << ")" << endl; hasUnknown = true; } } |