static bool HasSomethingToPaste (kpMainWindow *mw) { #if DEBUG_KP_MAIN_WINDOW kdDebug () << "kpMainWindow(" << mw->name () << "):HasSomethingToPaste()" << endl; QTime timer; timer.start (); #else (void) mw; #endif bool hasSomething = false; QMimeSource *ms = QApplication::clipboard ()->data (QClipboard::Clipboard); if (ms) { // It's faster to test for QTextDrag::canDecode() first due to the // lazy evaluation of the '||' operator. hasSomething = (QTextDrag::canDecode (ms) || kpSelectionDrag::canDecode (ms)); #if DEBUG_KP_MAIN_WINDOW kdDebug () << "\t" << mw->name () << "***canDecode=" << timer.restart () << endl; for (int i = 0; ; i++) { const char *fmt = ms->format (i); if (!fmt) break; kdDebug () << "\t'" << fmt << "'" << endl; } #endif } return hasSomething; }
// The main method for pasting KIO_EXPORT KIO::Job *KIO::pasteClipboard(const KURL &dest_url, bool move) { if(!dest_url.isValid()) { KMessageBox::error(0L, i18n("Malformed URL\n%1").arg(dest_url.url())); return 0; } #ifndef QT_NO_MIMECLIPBOARD QMimeSource *data = QApplication::clipboard()->data(); // First check for URLs. KURL::List urls; if(KURLDrag::canDecode(data) && KURLDrag::decode(data, urls)) { if(urls.count() == 0) { KMessageBox::error(0L, i18n("The clipboard is empty")); return 0; } KIO::Job *res = 0; if(move) res = KIO::move(urls, dest_url); else res = KIO::copy(urls, dest_url); // If moving, erase the clipboard contents, the original files don't exist anymore if(move) QApplication::clipboard()->clear(); return res; } return pasteMimeSource(data, dest_url, QString::null, 0 /*TODO parent widget*/, true /*clipboard*/); #else QByteArray ba; QTextStream txtStream(ba, IO_WriteOnly); QStringList data = QStringList::split("\n", QApplication::clipboard()->text()); KURL::List urls; KURLDrag::decode(data, urls); QStringList::Iterator end(data.end()); for(QStringList::Iterator it = data.begin(); it != end; ++it) txtStream << *it; if(ba.size() == 0) { KMessageBox::sorry(0, i18n("The clipboard is empty")); return 0; } return pasteDataAsync(dest_url, ba); #endif }
// KDE4: remove KIO_EXPORT bool KIO::isClipboardEmpty() { #ifndef QT_NO_MIMECLIPBOARD QMimeSource *data = QApplication::clipboard()->data(); if(data->provides("text/uri-list") && data->encodedData("text/uri-list").size() > 0) return false; #else // Happens with some versions of Qt Embedded... :/ // Guess. QString data = QApplication::clipboard()->text(); if(data.contains("://")) return false; #endif return true; }
KIO_EXPORT QString KIO::pasteActionText() { QMimeSource *data = QApplication::clipboard()->data(); KURL::List urls; if(KURLDrag::canDecode(data) && KURLDrag::decode(data, urls)) { if(urls.isEmpty()) return QString::null; // nothing to paste else if(urls.first().isLocalFile()) return i18n("&Paste File", "&Paste %n Files", urls.count()); else return i18n("&Paste URL", "&Paste %n URLs", urls.count()); } else if(data->format(0) != 0) { return i18n("&Paste Clipboard Contents"); } else { return QString::null; } }
// public slot void kpMainWindow::slotPaste () { #if DEBUG_KP_MAIN_WINDOW && 1 kdDebug () << "kpMainWindow::slotPaste() CALLED" << endl; #endif // sync: restoreOverrideCursor() in all exit paths QApplication::setOverrideCursor (Qt::waitCursor); if (toolHasBegunShape ()) tool ()->endShapeInternal (); if (!::HasSomethingToPasteWithDialogIfNot (this)) { QApplication::restoreOverrideCursor (); return; } // // Acquire the pixmap // QMimeSource *ms = QApplication::clipboard ()->data (QClipboard::Clipboard); if (!ms) { kdError () << "kpMainWindow::slotPaste() without mimeSource" << endl; QApplication::restoreOverrideCursor (); return; } kpSelection sel; QString text; if (kpSelectionDrag::decode (ms, sel/*ref*/, pasteWarnAboutLossInfo ())) { sel.setTransparency (selectionTransparency ()); paste (sel); } else if (QTextDrag::decode (ms, text/*ref*/)) { pasteText (text); } else { QApplication::restoreOverrideCursor (); kdDebug () << "kpMainWindow::slotPaste() could not decode selection" << endl; kdDebug () << "\tFormats supported:" << endl; for (int i = 0; ms->format (i); i++) { kdDebug () << "\t\t" << i << ":" << ms->format (i) << endl; } // TODO: fix Klipper KMessageBox::sorry (this, i18n ("<qt><p>KolourPaint cannot paste the contents of" " the clipboard as the data unexpectedly disappeared.</p>" "<p>This usually occurs if the application which was" " responsible" " for the clipboard contents has been closed.</p></qt>"), i18n ("Cannot Paste")); // TODO: PROPAGATE: interprocess if (KMainWindow::memberList) { #if DEBUG_KP_MAIN_WINDOW kdDebug () << "\thave memberList" << endl; #endif for (QPtrList <KMainWindow>::const_iterator it = KMainWindow::memberList->begin (); it != KMainWindow::memberList->end (); it++) { kpMainWindow *mw = dynamic_cast <kpMainWindow *> (*it); if (!mw) { kdError () << "kpMainWindow::slotPaste() given fake kpMainWindow: " << (*it) << endl; continue; } #if DEBUG_KP_MAIN_WINDOW kdDebug () << "\t\tmw=" << mw << endl; #endif mw->slotEnablePaste (); } } return; } QApplication::restoreOverrideCursor (); }