1
/***************************************************************************
2
copyright : (C) 2007 by Robby Stephenson
3
email : robby@periapsis.org
4
***************************************************************************/
6
/***************************************************************************
8
* This program is free software; you can redistribute it and/or modify *
9
* it under the terms of version 2 of the GNU General Public License as *
10
* published by the Free Software Foundation; *
12
***************************************************************************/
14
#include "drophandler.h"
15
#include "../mainwindow.h"
16
#include "../tellico_kernel.h"
17
#include "../tellico_debug.h"
20
#include <kmimetype.h>
22
using Tellico::DropHandler;
24
DropHandler::DropHandler(QObject* parent_) : QObject(parent_) {
27
DropHandler::~DropHandler() {
30
// assume the object is always the main window, that's the
31
// only object with this event filter
32
bool DropHandler::eventFilter(QObject* obj_, QEvent* ev_) {
34
if(ev_->type() == QEvent::DragEnter) {
35
return dragEnter(static_cast<QDragEnterEvent*>(ev_));
36
} else if(ev_->type() == QEvent::Drop) {
37
return drop(static_cast<QDropEvent*>(ev_));
42
bool DropHandler::dragEnter(QDragEnterEvent* event_) {
43
bool accept = KURLDrag::canDecode(event_) || QTextDrag::canDecode(event_);
45
event_->accept(accept);
50
bool DropHandler::drop(QDropEvent* event_) {
54
if(KURLDrag::decode(event_, urls)) {
55
} else if(QTextDrag::decode(event_, text) && !text.isEmpty()) {
58
return !urls.isEmpty() && handleURL(urls);
61
bool DropHandler::handleURL(const KURL::List& urls_) {
62
bool hasUnknown = false;
63
KURL::List tc, pdf, bib, ris;
64
for(KURL::List::ConstIterator it = urls_.begin(); it != urls_.end(); ++it) {
65
KMimeType::Ptr ptr = KMimeType::findByURL(*it);
66
if(ptr->is(QString::fromLatin1("application/x-tellico"))) {
68
} else if(ptr->is(QString::fromLatin1("application/pdf"))) {
70
} else if(ptr->is(QString::fromLatin1("text/x-bibtex")) ||
71
ptr->is(QString::fromLatin1("application/x-bibtex"))) {
73
} else if(ptr->is(QString::fromLatin1("application/x-research-info-systems"))) {
76
myDebug() << "DropHandler::handleURL() - unrecognized type: " << ptr->name() << " (" << *it << ")" << endl;
80
MainWindow* mainWindow = ::qt_cast<MainWindow*>(Kernel::self()->widget());
82
myDebug() << "DropHandler::handleURL() - no main window!" << endl;
86
mainWindow->importFile(Import::TellicoXML, tc);
89
mainWindow->importFile(Import::PDF, pdf);
92
mainWindow->importFile(Import::Bibtex, bib);
95
mainWindow->importFile(Import::RIS, ris);
97
// any unknown urls get passed
101
#include "drophandler.moc"