1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "kfileitemclipboard.h"
22 #include <KUrlMimeData>
24 #include <QApplication>
28 class KFileItemClipboardSingleton
31 KFileItemClipboard instance
;
33 Q_GLOBAL_STATIC(KFileItemClipboardSingleton
, s_KFileItemClipboard
)
37 KFileItemClipboard
* KFileItemClipboard::instance()
39 return &s_KFileItemClipboard
->instance
;
42 bool KFileItemClipboard::isCut(const QUrl
& url
) const
44 return m_cutItems
.contains(url
);
47 QList
<QUrl
> KFileItemClipboard::cutItems() const
49 return m_cutItems
.values();
52 KFileItemClipboard::~KFileItemClipboard()
56 void KFileItemClipboard::updateCutItems()
58 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
60 // mimeData can be 0 according to https://bugs.kde.org/show_bug.cgi?id=335053
63 emit
cutItemsChanged();
67 const QByteArray data
= mimeData
->data(QStringLiteral("application/x-kde-cutselection"));
68 const bool isCutSelection
= (!data
.isEmpty() && data
.at(0) == QLatin1Char('1'));
70 m_cutItems
= KUrlMimeData::urlsFromMimeData(mimeData
).toSet();
74 emit
cutItemsChanged();
77 KFileItemClipboard::KFileItemClipboard() :
83 connect(QApplication::clipboard(), &QClipboard::dataChanged
,
84 this, &KFileItemClipboard::updateCutItems
);