2
* Copyright (C) 2011 Canonical, Ltd.
5
* Olivier Tilloy <olivier.tilloy@canonical.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; version 3.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#include "dragitemwithurl.h"
23
#include <gscopedpointer.h>
28
#include <gio/gdesktopappinfo.h>
34
DeclarativeDragItemWithUrl::DeclarativeDragItemWithUrl(QDeclarativeItem* parent)
35
: DeclarativeDragItem(parent)
39
DeclarativeDragItemWithUrl::~DeclarativeDragItemWithUrl()
43
const QString& DeclarativeDragItemWithUrl::url() const
48
void DeclarativeDragItemWithUrl::setUrl(const QString& url)
52
Q_EMIT urlChanged(m_url);
56
QMimeData* DeclarativeDragItemWithUrl::mimeData() const
58
QMimeData* data = new QMimeData;
59
if (!m_url.isEmpty()) {
61
urls.append(decodeUri(m_url));
67
QUrl DeclarativeDragItemWithUrl::decodeUri(const QString& uri)
69
if (uri.startsWith("application://")) {
70
QString desktopFileName = uri.mid(14);
71
QByteArray bytes = desktopFileName.toUtf8();
72
GObjectScopedPointer<GDesktopAppInfo> appInfo(g_desktop_app_info_new(bytes.constData()));
73
if (appInfo.isNull()) {
76
QString filePath = QString::fromUtf8(g_desktop_app_info_get_filename(appInfo.data()));
77
return QUrl("file://" + filePath);