Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Evergreen:11.1
kdelibs4
patch-r890187.diff
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File patch-r890187.diff of Package kdelibs4
Subject: url-mimedata fix From: wstephenson@suse.de Bug: kde#175910 Patch-upstream: 890187 --- kio/kio/kdirmodel.cpp (revision 890186) +++ kio/kio/kdirmodel.cpp (revision 890187) @@ -707,20 +707,21 @@ QModelIndex KDirModel::parent( const QMo QStringList KDirModel::mimeTypes( ) const { - return QStringList() << QLatin1String("text/uri-list") - << QLatin1String( "application/x-kde-cutselection" ) // TODO - << QLatin1String( "text/plain" ) - << QLatin1String( "application/x-kde-urilist" ); + return KUrl::List::mimeDataTypes() + << QLatin1String( "application/x-kde-cutselection" ); // TODO } QMimeData * KDirModel::mimeData( const QModelIndexList & indexes ) const { - KUrl::List urls; + KUrl::List urls, mostLocalUrls; foreach ( const QModelIndex &index, indexes ) { - urls << d->nodeForIndex( index )->item().url(); + const KFileItem& item = d->nodeForIndex( index )->item(); + urls << item.url(); + bool dummy; + mostLocalUrls << item.mostLocalUrl(dummy); } QMimeData *data = new QMimeData(); - urls.populateMimeData( data ); + urls.populateMimeData(mostLocalUrls, data); return data; } --- kdecore/tests/kurlmimetest.cpp (revision 890186) +++ kdecore/tests/kurlmimetest.cpp (revision 890187) @@ -52,7 +52,7 @@ void KUrlMimeTest::testURLList() expectedUrls[1] = KUrl("http://wstephenson@example.com/path"); // password removed QCOMPARE( expectedUrls.toStringList().join(" "), decodedURLs.toStringList().join(" ") ); - QList<QUrl> qurls = mimeData->urls(); + const QList<QUrl> qurls = mimeData->urls(); QCOMPARE(qurls.count(), urls.count()); for (int i = 0; i < qurls.count(); ++i ) QCOMPARE(qurls[i], static_cast<QUrl>(decodedURLs[i])); @@ -99,3 +99,32 @@ void KUrlMimeTest::testFromQUrl() QVERIFY( decodedMetaData.isEmpty() ); delete mimeData; } + +void KUrlMimeTest::testMostLocalUrlList() +{ + QMimeData* mimeData = new QMimeData; + KUrl::List urls; + urls.append(KUrl("desktop:/foo")); + urls.append(KUrl("desktop:/bar")); + KUrl::List localUrls; + localUrls.append(KUrl("file:/home/dfaure/Desktop/foo")); + localUrls.append(KUrl("file:/home/dfaure/Desktop/bar")); + + urls.populateMimeData(localUrls, mimeData); + + QVERIFY(KUrl::List::canDecode(mimeData)); + QVERIFY(mimeData->hasUrls()); + QVERIFY(mimeData->hasFormat("text/plain")); + + // KUrl decodes the real "kde" urls + const KUrl::List decodedURLs = KUrl::List::fromMimeData(mimeData); + QVERIFY(!decodedURLs.isEmpty()); + QCOMPARE(decodedURLs.toStringList().join(" "), urls.toStringList().join(" ") ); + + // QMimeData decodes the "most local" urls + const QList<QUrl> qurls = mimeData->urls(); + QCOMPARE(qurls.count(), localUrls.count()); + for (int i = 0; i < qurls.count(); ++i ) + QCOMPARE(qurls[i], static_cast<QUrl>(localUrls[i])); + +} --- kdecore/tests/kurlmimetest.h (revision 890186) +++ kdecore/tests/kurlmimetest.h (revision 890187) @@ -28,6 +28,7 @@ private Q_SLOTS: void testURLList(); void testOneURL(); void testFromQUrl(); + void testMostLocalUrlList(); }; --- kdecore/io/kurl.cpp (revision 890186) +++ kdecore/io/kurl.cpp (revision 890187) @@ -1,4 +1,3 @@ -// -*- c-basic-offset: 2 -*- /* Copyright (C) 1999 Torben Weis <weis@kde.org> Copyright (C) 2005-2006 David Faure <faure@kde.org> @@ -215,19 +214,15 @@ QStringList KUrl::List::toStringList() c return lst; } - -void KUrl::List::populateMimeData( QMimeData* mimeData, - const KUrl::MetaDataMap& metaData, - MimeDataFlags flags ) const +static QByteArray uriListData(const KUrl::List& urls) { QList<QByteArray> urlStringList; - KUrl::List::ConstIterator uit = begin(); - const KUrl::List::ConstIterator uEnd = end(); - for ( ; uit != uEnd ; ++uit ) - { + KUrl::List::ConstIterator uit = urls.constBegin(); + const KUrl::List::ConstIterator uEnd = urls.constEnd(); + for (; uit != uEnd ; ++uit) { // Get each URL encoded in utf8 - and since we get it in escaped // form on top of that, .toLatin1() is fine. - urlStringList.append( (*uit).toMimeDataString().toLatin1() ); + urlStringList.append((*uit).toMimeDataString().toLatin1()); } QByteArray uriListData; @@ -236,12 +231,23 @@ void KUrl::List::populateMimeData( QMime if (i < n-1) uriListData += "\r\n"; } - mimeData->setData( "text/uri-list", uriListData ); + return uriListData; +} + +static const char* s_kdeUriListMime = "application/x-kde4-urilist"; + +void KUrl::List::populateMimeData( QMimeData* mimeData, + const KUrl::MetaDataMap& metaData, + MimeDataFlags flags ) const +{ + mimeData->setData("text/uri-list", uriListData(*this)); if ( ( flags & KUrl::NoTextExport ) == 0 ) { QStringList prettyURLsList; - for ( uit = begin(); uit != uEnd ; ++uit ) { + KUrl::List::ConstIterator uit = constBegin(); + const KUrl::List::ConstIterator uEnd = constEnd(); + for ( ; uit != uEnd ; ++uit ) { QString prettyURL = (*uit).prettyUrl(); if ( (*uit).protocol() == "mailto" ) { prettyURL = (*uit).path(); // remove mailto: when pasting into konsole @@ -269,25 +275,38 @@ void KUrl::List::populateMimeData( QMime } } + +void KUrl::List::populateMimeData(const KUrl::List& mostLocalUrls, + QMimeData* mimeData, + const KUrl::MetaDataMap& metaData, + MimeDataFlags flags) const +{ + // Export the most local urls as text/uri-list and plain text. + mostLocalUrls.populateMimeData(mimeData, metaData, flags); + + mimeData->setData(s_kdeUriListMime, uriListData(*this)); +} + bool KUrl::List::canDecode( const QMimeData *mimeData ) { - return mimeData->hasFormat( "text/uri-list" ) || mimeData->hasFormat( "application/x-kde-urilist" ); + return mimeData->hasFormat("text/uri-list") || + mimeData->hasFormat(s_kdeUriListMime); } QStringList KUrl::List::mimeDataTypes() { - return QStringList()<<( "application/x-kde-urilist" )<<( "text/uri-list" ); + return QStringList() << s_kdeUriListMime << "text/uri-list"; } KUrl::List KUrl::List::fromMimeData( const QMimeData *mimeData, KUrl::MetaDataMap* metaData ) { KUrl::List uris; // x-kde-urilist is the same format as text/uri-list, but contains - // KDE-aware urls, like media:/ and system:/, whereas text/uri-list is resolved to - // local files. So we look at it first for decoding, but we let apps set it when encoding. - QByteArray payload = mimeData->data( "application/x-kde-urilist" ); + // KDE-aware urls, like desktop:/ and applications:/, whereas text/uri-list is resolved to + // local files. So we look at it first for decoding. + QByteArray payload = mimeData->data(s_kdeUriListMime); if ( payload.isEmpty() ) - payload = mimeData->data( "text/uri-list" ); + payload = mimeData->data("text/uri-list"); if ( !payload.isEmpty() ) { int c = 0; const char* d = payload.data(); @@ -1086,9 +1105,6 @@ QString KUrl::toMimeDataString() const / if ( isLocalFile() ) { #if 1 -// return url(0, KGlobal::locale()->fileEncodingMib()); -// Can't do that anymore with QUrl.... -// return url( 0, QTextCodec::codecForLocale()->mibEnum() ); return url(); #else // According to the XDND spec, file:/ URLs for DND must have --- kdecore/io/kurl.h (revision 890186) +++ kdecore/io/kurl.h (revision 890187) @@ -180,6 +180,19 @@ public: MimeDataFlags flags = DefaultMimeDataFlags ) const; /** + * Adds URLs into the given QMimeData, both the "kde version" of the URLs + * (e.g. desktop:/foo) and the "most local" version of the URLs + * (e.g. file:///home/dfaure/Desktop/foo). + * Call this method on the "kde" URLs. + * @param mostLocalUrls the "most local" urls. + * @since 4.2 + */ + void populateMimeData(const KUrl::List& mostLocalUrls, + QMimeData* mimeData, + const KUrl::MetaDataMap& metaData = MetaDataMap(), + MimeDataFlags flags = DefaultMimeDataFlags) const; + + /** * Return true if @p mimeData contains URI data */ static bool canDecode( const QMimeData *mimeData ); Index: kio/kio/kdirmodel.cpp =================================================================== Index: kdecore/tests/kurlmimetest.cpp =================================================================== Index: kdecore/tests/kurlmimetest.h =================================================================== Index: kdecore/io/kurl.cpp =================================================================== Index: kdecore/io/kurl.h ===================================================================
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor