~ubuntu-branches/ubuntu/jaunty/kde4libs/jaunty-updates

« back to all changes in this revision

Viewing changes to kdecore/io/kurl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2008-12-11 18:26:08 UTC
  • mfrom: (1.1.24 upstream)
  • Revision ID: james.westby@ubuntu.com-20081211182608-tsu6p8ncbw1gnqxt
Tags: 4:4.1.85-0ubuntu1
* New upstream release
* Patches:
  + Removed 15_kfreebsd_support.diff from patches/series (doesn't apply and
    has no use for Ubuntu)
  + Redid 20_use_dejavu_as_default_font.diff
  + Completely removed kubuntu_09_fix_application_menu.diff (applied upstream)
  + Refreshed kubuntu_54_use_xdg_menu_prefix.diff
  + Dropped plasma/widgets/toolbutton.cpp from kubuntu_qt_ftbfs.diff (applied
    upstream)
  + Global quilt refresh

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- c-basic-offset: 2 -*-
2
1
/*
3
2
    Copyright (C) 1999 Torben Weis <weis@kde.org>
4
3
    Copyright (C) 2005-2006 David Faure <faure@kde.org>
215
214
   return lst;
216
215
}
217
216
 
218
 
 
219
 
void KUrl::List::populateMimeData( QMimeData* mimeData,
220
 
                                   const KUrl::MetaDataMap& metaData,
221
 
                                   MimeDataFlags flags ) const
 
217
static QByteArray uriListData(const KUrl::List& urls)
222
218
{
223
219
    QList<QByteArray> urlStringList;
224
 
    KUrl::List::ConstIterator uit = begin();
225
 
    const KUrl::List::ConstIterator uEnd = end();
226
 
    for ( ; uit != uEnd ; ++uit )
227
 
    {
 
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());
231
226
    }
232
227
 
233
228
    QByteArray uriListData;
236
231
        if (i < n-1)
237
232
          uriListData += "\r\n";
238
233
    }
239
 
    mimeData->setData( "text/uri-list", uriListData );
 
234
    return uriListData;
 
235
}
 
236
 
 
237
static const char* s_kdeUriListMime = "application/x-kde4-urilist";
 
238
 
 
239
void KUrl::List::populateMimeData( QMimeData* mimeData,
 
240
                                   const KUrl::MetaDataMap& metaData,
 
241
                                   MimeDataFlags flags ) const
 
242
{
 
243
    mimeData->setData("text/uri-list", uriListData(*this));
240
244
 
241
245
    if ( ( flags & KUrl::NoTextExport ) == 0 )
242
246
    {
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
269
275
    }
270
276
}
271
277
 
 
278
 
 
279
void KUrl::List::populateMimeData(const KUrl::List& mostLocalUrls,
 
280
                                  QMimeData* mimeData,
 
281
                                  const KUrl::MetaDataMap& metaData,
 
282
                                  MimeDataFlags flags) const
 
283
{
 
284
    // Export the most local urls as text/uri-list and plain text.
 
285
    mostLocalUrls.populateMimeData(mimeData, metaData, flags);
 
286
 
 
287
    mimeData->setData(s_kdeUriListMime, uriListData(*this));
 
288
}
 
289
 
272
290
bool KUrl::List::canDecode( const QMimeData *mimeData )
273
291
{
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);
275
294
}
276
295
 
277
296
QStringList KUrl::List::mimeDataTypes()
278
297
{
279
 
    return QStringList()<<( "application/x-kde-urilist" )<<( "text/uri-list" );
 
298
    return QStringList() << s_kdeUriListMime << "text/uri-list";
280
299
}
281
300
 
282
301
KUrl::List KUrl::List::fromMimeData( const QMimeData *mimeData, KUrl::MetaDataMap* metaData )
283
302
{
284
303
    KUrl::List uris;
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() ) {
292
311
        int c = 0;
293
312
        const char* d = payload.data();
765
784
 
766
785
QString KUrl::encodedPathAndQuery( AdjustPathOption trailing , const EncodedPathAndQueryOptions &options) const
767
786
{
768
 
  QString tmp;
769
 
#if 0
770
 
  if (!m_strPath_encoded.isEmpty())
771
 
  {
772
 
     tmp = trailingSlash( _trailing, m_strPath_encoded );
773
 
  }
774
 
  else
775
 
#endif
776
 
  {
777
 
     tmp = path( trailing );
778
 
     if ( (options & AvoidEmptyPath) && tmp.isEmpty() )
779
 
        tmp = "/";
780
 
#if 0
781
 
     if (m_iUriMode == Mailto)
782
 
     {
783
 
       tmp = encode( tmp, 2 ); // encode neither @ nor /
784
 
     }
785
 
     else
786
 
     {
787
 
       tmp = encode( tmp, 1 ); // encode @ but not /
788
 
     }
789
 
#endif
790
 
     // The list of chars to exclude comes from QUrlPrivate::toEncoded
791
 
     tmp = QString::fromLatin1( QUrl::toPercentEncoding( tmp, "!$&'()*+,;=:@/" ) );
792
 
  }
793
 
 
794
 
  if (hasQuery())
795
 
  {
796
 
      tmp += query(); // includes the '?'
797
 
  }
798
 
  return tmp;
 
787
    QString encodedPath;
 
788
#ifdef Q_OS_WIN
 
789
    // see KUrl::path()
 
790
    if (isLocalFile()) {
 
791
        // ### this is probably broken
 
792
        encodedPath = trailingSlash(trailing, QUrl::toLocalFile());
 
793
        encodedPath = QString::fromLatin1(QUrl::toPercentEncoding(encodedPath, "!$&'()*+,;=:@/"));
 
794
    } else {
 
795
        encodedPath = trailingSlash(trailing, QUrl::encodedPath());
 
796
    }
 
797
#else
 
798
    encodedPath = trailingSlash(trailing, QUrl::encodedPath());
 
799
#endif
 
800
 
 
801
    if ((options & AvoidEmptyPath) && encodedPath.isEmpty()) {
 
802
        encodedPath.append('/');
 
803
    }
 
804
 
 
805
    if (hasQuery()) {
 
806
        return encodedPath + '?' + encodedQuery();
 
807
    } else {
 
808
        return encodedPath;
 
809
    }
799
810
}
800
811
 
801
812
#if 0
1091
1102
  if ( isLocalFile() )
1092
1103
  {
1093
1104
#if 1
1094
 
//    return url(0, KGlobal::locale()->fileEncodingMib());
1095
 
// Can't do that anymore with QUrl....
1096
 
//      return url( 0, QTextCodec::codecForLocale()->mibEnum() );
1097
1105
    return url();
1098
1106
#else
1099
1107
    // According to the XDND spec, file:/ URLs for DND must have
1112
1120
#endif
1113
1121
  }
1114
1122
 
1115
 
  return url(/*0 , 106*/); // 106 is mib enum for utf8 codec
 
1123
  if (hasPass()) {
 
1124
    KUrl safeUrl(*this);
 
1125
    safeUrl.setPassword(QString());
 
1126
    return safeUrl.url();
 
1127
  }
 
1128
  return url();
1116
1129
}
1117
1130
 
1118
1131
KUrl KUrl::fromMimeDataByteArray( const QByteArray& str )
1815
1828
{
1816
1829
  return QUrl::isParentOf( u ) || equals( u, CompareWithoutTrailingSlash );
1817
1830
}
 
1831
 
 
1832
uint qHash(const KUrl& kurl)
 
1833
{
 
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.
 
1836
 
 
1837
  return qHash(kurl.protocol()) ^ qHash(kurl.path()) ^ qHash(kurl.fragment()) ^ qHash(kurl.query());
 
1838
}
 
1839