Skip to content
Snippets Groups Projects
Commit cde87d91 authored by Frank Reininghaus's avatar Frank Reininghaus
Browse files

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

This removes the remaining unchecked accesses to the clipboard mime
data after commit 7828b057. According
to a bug report, it can be a null pointer on Wayland.

BUG: 335053
REVIEW: 118649
parent 73944822
No related branches found
No related tags found
No related merge requests found
......@@ -429,10 +429,9 @@ QAction* DolphinContextMenu::createPasteAction()
QAction* action = 0;
const bool isDir = !m_fileInfo.isNull() && m_fileInfo.isDir();
if (isDir && (m_selectedItems.count() == 1)) {
const QPair<bool, QString> pasteInfo = KonqOperations::pasteInfo(m_fileInfo.url());
action = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste Into Folder"), this);
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData);
action->setEnabled(!pasteData.isEmpty() && selectedItemsProperties().supportsWriting());
action->setEnabled(pasteInfo.first);
connect(action, SIGNAL(triggered()), m_mainWindow, SLOT(pasteIntoFolder()));
} else {
action = m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
......
......@@ -55,6 +55,14 @@ KFileItemClipboard::~KFileItemClipboard()
void KFileItemClipboard::updateCutItems()
{
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
// mimeData can be 0 according to https://bugs.kde.org/show_bug.cgi?id=335053
if (!mimeData) {
m_cutItems.clear();
emit cutItemsChanged();
return;
}
const QByteArray data = mimeData->data("application/x-kde-cutselection");
const bool isCutSelection = (!data.isEmpty() && data.at(0) == QLatin1Char('1'));
if (isCutSelection) {
......
......@@ -62,11 +62,10 @@ void TreeViewContextMenu::open()
QAction* copyAction = new QAction(KIcon("edit-copy"), i18nc("@action:inmenu", "Copy"), this);
connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
QAction* pasteAction = new QAction(KIcon("edit-paste"), i18nc("@action:inmenu", "Paste"), this);
const QMimeData* mimeData = QApplication::clipboard()->mimeData();
const KUrl::List pasteData = KUrl::List::fromMimeData(mimeData);
const QPair<bool, QString> pasteInfo = KonqOperations::pasteInfo(m_fileItem.url());
QAction* pasteAction = new QAction(KIcon("edit-paste"), pasteInfo.second, this);
connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
pasteAction->setEnabled(!pasteData.isEmpty() && capabilities.supportsWriting());
pasteAction->setEnabled(pasteInfo.first);
popup->addAction(cutAction);
popup->addAction(copyAction);
......@@ -172,17 +171,7 @@ void TreeViewContextMenu::copy()
void TreeViewContextMenu::paste()
{
QClipboard* clipboard = QApplication::clipboard();
const QMimeData* mimeData = clipboard->mimeData();
const KUrl::List source = KUrl::List::fromMimeData(mimeData);
const KUrl& dest = m_fileItem.url();
if (KonqMimeData::decodeIsCutSelection(mimeData)) {
KonqOperations::copy(m_parent, KonqOperations::MOVE, source, dest);
clipboard->clear();
} else {
KonqOperations::copy(m_parent, KonqOperations::COPY, source, dest);
}
KonqOperations::doPaste(m_parent, m_fileItem.url());
}
void TreeViewContextMenu::rename()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment