void KWalletItem::processDropEvent(QDropEvent *e) { const QMimeData *em = e->mimeData(); if (em->hasFormat(QLatin1String("application/x-kwallet-folder")) || em->hasFormat(QLatin1String("text/uri-list"))) { // FIXME: don't allow the drop if the wallet name is the same KWallet::Wallet *_wallet = KWallet::Wallet::openWallet(text(), listWidget()->topLevelWidget()->winId()); if (!_wallet) { e->ignore(); return; } const QString saveFolder = _wallet->currentFolder(); QDataStream *ds = 0L; if (em->hasFormat(QLatin1String("application/x-kwallet-folder"))) { QByteArray edata = em->data(QLatin1String("application/x-kwallet-folder")); if (!edata.isEmpty()) { ds = new QDataStream(&edata, QIODevice::ReadOnly); } } else { // text/uri-list const QList<QUrl> urls = e->mimeData()->urls(); if (urls.isEmpty()) { e->ignore(); return; } KUrl u(urls.first()); if (u.fileName().isEmpty()) { e->ignore(); return; } QString tmpFile; if (KIO::NetAccess::download(u, tmpFile, 0L)) { QFile file; file.setFileName(tmpFile); file.open(QIODevice::ReadOnly); ds = new QDataStream(&file); KIO::NetAccess::removeTempFile(tmpFile); } else { KMessageBox::error(listWidget(), KIO::NetAccess::lastErrorString()); } } if (ds) { decodeFolder(_wallet, *ds); delete ds; } _wallet->setFolder(saveFolder); delete _wallet; //delete the folder from the source if we were moving Qt::MouseButtons state = QApplication::mouseButtons(); if (e->source() && e->source()->parent() && !strcmp(e->source()->parent()->metaObject()->className(), "KWalletEntryList") && !(state & Qt::ControlModifier)) { KWalletEntryList *el = dynamic_cast<KWalletEntryList*>(e->source()->parent()); if (el) { KWalletFolderItem *fi = dynamic_cast<KWalletFolderItem*>(el->currentItem()); if (fi) { el->_wallet->removeFolder(fi->name()); } } } e->accept(); } else { e->ignore(); return; } }
void KWalletItem::dropped(QDropEvent *e, const QValueList<QIconDragItem>& lst) { Q_UNUSED(lst); if (e->provides("application/x-kwallet-folder") || e->provides("text/uri-list")) { // FIXME: don't allow the drop if the wallet name is the same KWallet::Wallet *_wallet = KWallet::Wallet::openWallet(text()); if (!_wallet) { e->ignore(); return; } QString saveFolder = _wallet->currentFolder(); QFile file; QDataStream *ds = 0L; if (e->provides("application/x-kwallet-folder")) { QByteArray edata = e->encodedData("application/x-kwallet-folder"); if (!edata.isEmpty()) { ds = new QDataStream(edata, IO_ReadOnly); } } else { // text/uri-list QStrList urls; QUriDrag::decode(e, urls); if (urls.isEmpty()) { e->ignore(); return; } KURL u(urls.first()); if (u.fileName().isEmpty()) { e->ignore(); return; } QString tmpFile; if (KIO::NetAccess::download(u, tmpFile, 0L)) { file.setName(tmpFile); file.open(IO_ReadOnly); ds = new QDataStream(&file); KIO::NetAccess::removeTempFile(tmpFile); } else { KMessageBox::error(iconView(), KIO::NetAccess::lastErrorString()); } } if (ds) { decodeFolder(_wallet, *ds); delete ds; } _wallet->setFolder(saveFolder); delete _wallet; //delete the folder from the source if we were moving Qt::ButtonState state = kapp->keyboardMouseState(); if (e->source() && e->source()->parent() && !strcmp(e->source()->parent()->className(), "KWalletEntryList") && !(state & Qt::ControlButton)) { KWalletEntryList *el = dynamic_cast<KWalletEntryList*>(e->source()->parent()); if (el) { KWalletFolderItem *fi = dynamic_cast<KWalletFolderItem*>(el->selectedItem()); if (fi) { el->_wallet->removeFolder(fi->name()); } } } e->accept(); } else { e->ignore(); return; } }