Do not crash if QApplication::clipboard()->mimeData() is a null pointer

According to a recent bug report, this can happen on Wayland. The root
cause of the problem might be a problem in Qt's Wayland support itself,
but this patch at least prevents that Dolphin and other applications
which check the clipboard state to determine the text of the paste
action crash on startup.

BUG: 335053
REVIEW: 118450
This commit is contained in:
Frank Reininghaus 2014-06-01 14:44:57 +02:00
parent de197075a7
commit 7828b057da

View file

@ -1031,8 +1031,17 @@ QPair<bool, QString> KonqOperations::pasteInfo(const KUrl& targetUrl)
QClipboard* clipboard = QApplication::clipboard();
const QMimeData* mimeData = clipboard->mimeData();
const bool canPasteData = KIO::canPasteMimeSource(mimeData);
KUrl::List urls = KUrl::List::fromMimeData(mimeData);
bool canPasteData = false;
KUrl::List urls;
// mimeData can be 0 according to https://bugs.kde.org/show_bug.cgi?id=335053
if (mimeData) {
canPasteData = KIO::canPasteMimeSource(mimeData);
urls = KUrl::List::fromMimeData(mimeData);
} else {
kWarning(1203) << "QApplication::clipboard()->mimeData() is 0!";
}
if (!urls.isEmpty() || canPasteData) {
// disable the paste action if no writing is supported
KFileItem item(KFileItem::Unknown, KFileItem::Unknown, targetUrl);