219
void KUrl::List::populateMimeData( QMimeData* mimeData,
220
const KUrl::MetaDataMap& metaData,
221
MimeDataFlags flags ) const
217
static QByteArray uriListData(const KUrl::List& urls)
223
219
QList<QByteArray> urlStringList;
224
KUrl::List::ConstIterator uit = begin();
225
const KUrl::List::ConstIterator uEnd = end();
226
for ( ; uit != uEnd ; ++uit )
220
KUrl::List::ConstIterator uit = urls.constBegin();
221
const KUrl::List::ConstIterator uEnd = urls.constEnd();
222
for (; uit != uEnd ; ++uit) {
228
223
// Get each URL encoded in utf8 - and since we get it in escaped
229
224
// form on top of that, .toLatin1() is fine.
230
urlStringList.append( (*uit).toMimeDataString().toLatin1() );
225
urlStringList.append((*uit).toMimeDataString().toLatin1());
233
228
QByteArray uriListData;
237
232
uriListData += "\r\n";
239
mimeData->setData( "text/uri-list", uriListData );
237
static const char* s_kdeUriListMime = "application/x-kde4-urilist";
239
void KUrl::List::populateMimeData( QMimeData* mimeData,
240
const KUrl::MetaDataMap& metaData,
241
MimeDataFlags flags ) const
243
mimeData->setData("text/uri-list", uriListData(*this));
241
245
if ( ( flags & KUrl::NoTextExport ) == 0 )
243
247
QStringList prettyURLsList;
244
for ( uit = begin(); uit != uEnd ; ++uit ) {
248
KUrl::List::ConstIterator uit = constBegin();
249
const KUrl::List::ConstIterator uEnd = constEnd();
250
for ( ; uit != uEnd ; ++uit ) {
245
251
QString prettyURL = (*uit).prettyUrl();
246
252
if ( (*uit).protocol() == "mailto" ) {
247
253
prettyURL = (*uit).path(); // remove mailto: when pasting into konsole
279
void KUrl::List::populateMimeData(const KUrl::List& mostLocalUrls,
281
const KUrl::MetaDataMap& metaData,
282
MimeDataFlags flags) const
284
// Export the most local urls as text/uri-list and plain text.
285
mostLocalUrls.populateMimeData(mimeData, metaData, flags);
287
mimeData->setData(s_kdeUriListMime, uriListData(*this));
272
290
bool KUrl::List::canDecode( const QMimeData *mimeData )
274
return mimeData->hasFormat( "text/uri-list" ) || mimeData->hasFormat( "application/x-kde-urilist" );
292
return mimeData->hasFormat("text/uri-list") ||
293
mimeData->hasFormat(s_kdeUriListMime);
277
296
QStringList KUrl::List::mimeDataTypes()
279
return QStringList()<<( "application/x-kde-urilist" )<<( "text/uri-list" );
298
return QStringList() << s_kdeUriListMime << "text/uri-list";
282
301
KUrl::List KUrl::List::fromMimeData( const QMimeData *mimeData, KUrl::MetaDataMap* metaData )
285
304
// x-kde-urilist is the same format as text/uri-list, but contains
286
// KDE-aware urls, like media:/ and system:/, whereas text/uri-list is resolved to
287
// local files. So we look at it first for decoding, but we let apps set it when encoding.
288
QByteArray payload = mimeData->data( "application/x-kde-urilist" );
305
// KDE-aware urls, like desktop:/ and applications:/, whereas text/uri-list is resolved to
306
// local files. So we look at it first for decoding.
307
QByteArray payload = mimeData->data(s_kdeUriListMime);
289
308
if ( payload.isEmpty() )
290
payload = mimeData->data( "text/uri-list" );
309
payload = mimeData->data("text/uri-list");
291
310
if ( !payload.isEmpty() ) {
293
312
const char* d = payload.data();
766
785
QString KUrl::encodedPathAndQuery( AdjustPathOption trailing , const EncodedPathAndQueryOptions &options) const
770
if (!m_strPath_encoded.isEmpty())
772
tmp = trailingSlash( _trailing, m_strPath_encoded );
777
tmp = path( trailing );
778
if ( (options & AvoidEmptyPath) && tmp.isEmpty() )
781
if (m_iUriMode == Mailto)
783
tmp = encode( tmp, 2 ); // encode neither @ nor /
787
tmp = encode( tmp, 1 ); // encode @ but not /
790
// The list of chars to exclude comes from QUrlPrivate::toEncoded
791
tmp = QString::fromLatin1( QUrl::toPercentEncoding( tmp, "!$&'()*+,;=:@/" ) );
796
tmp += query(); // includes the '?'
791
// ### this is probably broken
792
encodedPath = trailingSlash(trailing, QUrl::toLocalFile());
793
encodedPath = QString::fromLatin1(QUrl::toPercentEncoding(encodedPath, "!$&'()*+,;=:@/"));
795
encodedPath = trailingSlash(trailing, QUrl::encodedPath());
798
encodedPath = trailingSlash(trailing, QUrl::encodedPath());
801
if ((options & AvoidEmptyPath) && encodedPath.isEmpty()) {
802
encodedPath.append('/');
806
return encodedPath + '?' + encodedQuery();
1091
1102
if ( isLocalFile() )
1094
// return url(0, KGlobal::locale()->fileEncodingMib());
1095
// Can't do that anymore with QUrl....
1096
// return url( 0, QTextCodec::codecForLocale()->mibEnum() );
1099
1107
// According to the XDND spec, file:/ URLs for DND must have
1816
1829
return QUrl::isParentOf( u ) || equals( u, CompareWithoutTrailingSlash );
1832
uint qHash(const KUrl& kurl)
1834
// qHash(kurl.url()) was the worse implementation possible, since QUrl::toEncoded()
1835
// had to concatenate the bits of the url into the full url every time.
1837
return qHash(kurl.protocol()) ^ qHash(kurl.path()) ^ qHash(kurl.fragment()) ^ qHash(kurl.query());