00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "kprotocolmanager.h"
00023
00024 #include <string.h>
00025 #include <unistd.h>
00026 #include <sys/utsname.h>
00027 #include <QtCore/QCoreApplication>
00028 #include <QtDBus/QtDBus>
00029
00030 #include <kdeversion.h>
00031 #include <kdebug.h>
00032 #include <kglobal.h>
00033 #include <klocale.h>
00034 #include <kconfiggroup.h>
00035 #include <ksharedconfig.h>
00036 #include <kstandarddirs.h>
00037 #include <kstringhandler.h>
00038 #include <kurl.h>
00039 #include <kio/slaveconfig.h>
00040 #include <kio/ioslave_defaults.h>
00041 #include <kio/http_slave_defaults.h>
00042
00043 #include <kprotocolinfofactory.h>
00044
00045 class
00046 KProtocolManagerPrivate
00047 {
00048 public:
00049 KProtocolManagerPrivate();
00050
00051 ~KProtocolManagerPrivate();
00052
00053 KSharedConfig::Ptr config;
00054 KSharedConfig::Ptr http_config;
00055 KUrl url;
00056 QString protocol;
00057 QString proxy;
00058 QString modifiers;
00059 QString useragent;
00060
00061 QMap<QString , QString > protocolForArchiveMimetypes;
00062 };
00063
00064 K_GLOBAL_STATIC(KProtocolManagerPrivate, kProtocolManagerPrivate)
00065
00066 KProtocolManagerPrivate::KProtocolManagerPrivate()
00067 {
00068
00069 qAddPostRoutine(kProtocolManagerPrivate.destroy);
00070 }
00071
00072 KProtocolManagerPrivate::~KProtocolManagerPrivate()
00073 {
00074 qRemovePostRoutine(kProtocolManagerPrivate.destroy);
00075 }
00076
00077
00078
00079 #define CFG_DEFAULT_UAGENT(X) \
00080 QString("Mozilla/5.0 (compatible; Konqueror/%1.%2%3) KHTML/%4.%5.%6 (like Gecko) Red Hat Enterprise Linux/4.3.4-23.el6_6") \
00081 .arg(KDE_VERSION_MAJOR).arg(KDE_VERSION_MINOR).arg(X).arg(KDE_VERSION_MAJOR).arg(KDE_VERSION_MINOR).arg(KDE_VERSION_RELEASE)
00082
00083 #define PRIVATE_DATA \
00084 KProtocolManagerPrivate *d = kProtocolManagerPrivate
00085
00086 void KProtocolManager::reparseConfiguration()
00087 {
00088 PRIVATE_DATA;
00089 if (d->http_config) {
00090 d->http_config->reparseConfiguration();
00091 }
00092 if (d->config) {
00093 d->config->reparseConfiguration();
00094 }
00095 d->protocol.clear();
00096 d->proxy.clear();
00097 d->modifiers.clear();
00098 d->useragent.clear();
00099 d->url.clear();
00100
00101
00102 KIO::SlaveConfig::self()->reset ();
00103 }
00104
00105 KSharedConfig::Ptr KProtocolManager::config()
00106 {
00107 PRIVATE_DATA;
00108 if (!d->config)
00109 {
00110 d->config = KSharedConfig::openConfig("kioslaverc", KConfig::NoGlobals);
00111 }
00112 return d->config;
00113 }
00114
00115 static KConfigGroup http_config()
00116 {
00117 PRIVATE_DATA;
00118 if (!d->http_config) {
00119 d->http_config = KSharedConfig::openConfig("kio_httprc", KConfig::NoGlobals);
00120 }
00121 return KConfigGroup(d->http_config, QString());
00122 }
00123
00124
00125
00126 int KProtocolManager::readTimeout()
00127 {
00128 KConfigGroup cg( config(), QString() );
00129 int val = cg.readEntry( "ReadTimeout", DEFAULT_READ_TIMEOUT );
00130 return qMax(MIN_TIMEOUT_VALUE, val);
00131 }
00132
00133 int KProtocolManager::connectTimeout()
00134 {
00135 KConfigGroup cg( config(), QString() );
00136 int val = cg.readEntry( "ConnectTimeout", DEFAULT_CONNECT_TIMEOUT );
00137 return qMax(MIN_TIMEOUT_VALUE, val);
00138 }
00139
00140 int KProtocolManager::proxyConnectTimeout()
00141 {
00142 KConfigGroup cg( config(), QString() );
00143 int val = cg.readEntry( "ProxyConnectTimeout", DEFAULT_PROXY_CONNECT_TIMEOUT );
00144 return qMax(MIN_TIMEOUT_VALUE, val);
00145 }
00146
00147 int KProtocolManager::responseTimeout()
00148 {
00149 KConfigGroup cg( config(), QString() );
00150 int val = cg.readEntry( "ResponseTimeout", DEFAULT_RESPONSE_TIMEOUT );
00151 return qMax(MIN_TIMEOUT_VALUE, val);
00152 }
00153
00154
00155
00156 bool KProtocolManager::useProxy()
00157 {
00158 return proxyType() != NoProxy;
00159 }
00160
00161 bool KProtocolManager::useReverseProxy()
00162 {
00163 KConfigGroup cg(config(), "Proxy Settings" );
00164 return cg.readEntry("ReversedException", false);
00165 }
00166
00167 KProtocolManager::ProxyType KProtocolManager::proxyType()
00168 {
00169 KConfigGroup cg(config(), "Proxy Settings" );
00170 return static_cast<ProxyType>(cg.readEntry( "ProxyType" , 0));
00171 }
00172
00173 KProtocolManager::ProxyAuthMode KProtocolManager::proxyAuthMode()
00174 {
00175 KConfigGroup cg(config(), "Proxy Settings" );
00176 return static_cast<ProxyAuthMode>(cg.readEntry( "AuthMode" , 0));
00177 }
00178
00179
00180
00181 bool KProtocolManager::useCache()
00182 {
00183 return http_config().readEntry( "UseCache", true );
00184 }
00185
00186 KIO::CacheControl KProtocolManager::cacheControl()
00187 {
00188 QString tmp = http_config().readEntry("cache");
00189 if (tmp.isEmpty())
00190 return DEFAULT_CACHE_CONTROL;
00191 return KIO::parseCacheControl(tmp);
00192 }
00193
00194 QString KProtocolManager::cacheDir()
00195 {
00196 return http_config().readPathEntry("CacheDir", KGlobal::dirs()->saveLocation("cache","http"));
00197 }
00198
00199 int KProtocolManager::maxCacheAge()
00200 {
00201 return http_config().readEntry( "MaxCacheAge", DEFAULT_MAX_CACHE_AGE );
00202 }
00203
00204 int KProtocolManager::maxCacheSize()
00205 {
00206 return http_config().readEntry( "MaxCacheSize", DEFAULT_MAX_CACHE_SIZE );
00207 }
00208
00209 QString KProtocolManager::noProxyFor()
00210 {
00211 KProtocolManager::ProxyType type = proxyType();
00212
00213 QString noProxy = config()->group("Proxy Settings").readEntry( "NoProxyFor" );
00214 if (type == EnvVarProxy)
00215 noProxy = QString::fromLocal8Bit(qgetenv(noProxy.toLocal8Bit()));
00216
00217 return noProxy;
00218 }
00219
00220 QString KProtocolManager::proxyFor( const QString& protocol )
00221 {
00222 QString scheme = protocol.toLower();
00223
00224 if (scheme == "webdav")
00225 scheme = "http";
00226 else if (scheme == "webdavs")
00227 scheme = "https";
00228
00229 return config()->group("Proxy Settings" ).readEntry( scheme + "Proxy", QString() );
00230 }
00231
00232 QString KProtocolManager::proxyForUrl( const KUrl &url )
00233 {
00234 QString proxy;
00235 ProxyType pt = proxyType();
00236
00237 switch (pt)
00238 {
00239 case PACProxy:
00240 case WPADProxy:
00241 if (!url.host().isEmpty())
00242 {
00243 KUrl u (url);
00244 QString p = u.protocol().toLower();
00245
00246
00247
00248 if ( p == "webdav" )
00249 {
00250 p = "http";
00251 u.setProtocol( p );
00252 }
00253 else if ( p == "webdavs" )
00254 {
00255 p = "https";
00256 u.setProtocol( p );
00257 }
00258
00259 if ( p.startsWith("http") || p == "ftp" || p == "gopher" )
00260 {
00261 QDBusReply<QString> reply =
00262 QDBusInterface( "org.kde.kded", "/modules/proxyscout", "org.kde.KPAC.ProxyScout" )
00263 .call( "proxyForUrl", u.url() );
00264 proxy = reply;
00265 }
00266 }
00267 break;
00268 case EnvVarProxy:
00269 proxy = QString::fromLocal8Bit(qgetenv(proxyFor(url.protocol()).toLocal8Bit())).trimmed();
00270 break;
00271 case ManualProxy:
00272 proxy = proxyFor( url.protocol() );
00273 break;
00274 case NoProxy:
00275 default:
00276 break;
00277 }
00278
00279 return (proxy.isEmpty() ? QLatin1String("DIRECT") : proxy);
00280 }
00281
00282 void KProtocolManager::badProxy( const QString &proxy )
00283 {
00284 QDBusInterface( "org.kde.kded", "/modules/proxyscout" )
00285 .call( "blackListProxy", proxy );
00286 }
00287
00288
00289
00290
00291
00292
00293 static bool revmatch(const char *host, const char *nplist)
00294 {
00295 if (host == 0)
00296 return false;
00297
00298 const char *hptr = host + strlen( host ) - 1;
00299 const char *nptr = nplist + strlen( nplist ) - 1;
00300 const char *shptr = hptr;
00301
00302 while ( nptr >= nplist )
00303 {
00304 if ( *hptr != *nptr )
00305 {
00306 hptr = shptr;
00307
00308
00309 while(--nptr>=nplist && *nptr!=',' && *nptr!=' ') ;
00310
00311
00312 while(--nptr>=nplist && (*nptr==',' || *nptr==' ')) ;
00313 }
00314 else
00315 {
00316 if ( nptr==nplist || nptr[-1]==',' || nptr[-1]==' ')
00317 return true;
00318 if ( nptr[-1]=='/' && hptr == host )
00319 return true;
00320 if ( hptr == host )
00321 return false;
00322
00323 hptr--;
00324 nptr--;
00325 }
00326 }
00327
00328 return false;
00329 }
00330
00331 QString KProtocolManager::slaveProtocol(const KUrl &url, QString &proxy)
00332 {
00333 if (url.hasSubUrl())
00334 {
00335 KUrl::List list = KUrl::split(url);
00336 KUrl l = list.last();
00337 return slaveProtocol(l, proxy);
00338 }
00339
00340 PRIVATE_DATA;
00341 if (d->url == url)
00342 {
00343 proxy = d->proxy;
00344 return d->protocol;
00345 }
00346
00347 if (useProxy())
00348 {
00349 proxy = proxyForUrl(url);
00350 if ((proxy != "DIRECT") && (!proxy.isEmpty()))
00351 {
00352 bool isRevMatch = false;
00353 KProtocolManager::ProxyType type = proxyType();
00354 bool useRevProxy = ((type == ManualProxy) && useReverseProxy());
00355
00356 QString noProxy;
00357
00358
00359 if ( (type == ManualProxy) || (type == EnvVarProxy) )
00360 noProxy = noProxyFor();
00361
00362 if (!noProxy.isEmpty())
00363 {
00364 QString qhost = url.host().toLower();
00365 QByteArray host = qhost.toLatin1();
00366 QString qno_proxy = noProxy.trimmed().toLower();
00367 const QByteArray no_proxy = qno_proxy.toLatin1();
00368 isRevMatch = revmatch(host, no_proxy);
00369
00370
00371
00372
00373 if (!isRevMatch && url.port() > 0)
00374 {
00375 qhost += ':' + QString::number (url.port());
00376 host = qhost.toLatin1();
00377 isRevMatch = revmatch (host, no_proxy);
00378 }
00379
00380
00381
00382 if (!isRevMatch && !host.isEmpty() && (strchr(host, '.') == NULL))
00383 isRevMatch = revmatch("<local>", no_proxy);
00384 }
00385
00386 if ( (!useRevProxy && !isRevMatch) || (useRevProxy && isRevMatch) )
00387 {
00388 d->url = proxy;
00389 if (d->url.isValid() && !d->url.protocol().isEmpty())
00390 {
00391
00392
00393 QString protocol = url.protocol().toLower();
00394 if (protocol.startsWith("http") || protocol.startsWith("webdav"))
00395 d->protocol = protocol;
00396 else
00397 {
00398 d->protocol = d->url.protocol();
00399 kDebug () << "slaveProtocol: " << d->protocol;
00400 }
00401
00402 d->url = url;
00403 d->proxy = proxy;
00404 return d->protocol;
00405 }
00406 }
00407 }
00408 }
00409
00410 d->url = url;
00411 d->proxy.clear(); proxy.clear();
00412 d->protocol = url.protocol();
00413 return d->protocol;
00414 }
00415
00416
00417
00418 QString KProtocolManager::userAgentForHost( const QString& hostname )
00419 {
00420 QString sendUserAgent = KIO::SlaveConfig::self()->configData("http", hostname.toLower(), "SendUserAgent").toLower();
00421 if (sendUserAgent == "false")
00422 return QString();
00423
00424 QString useragent = KIO::SlaveConfig::self()->configData("http", hostname.toLower(), "UserAgent");
00425
00426
00427
00428 if (useragent.isEmpty())
00429 return defaultUserAgent();
00430
00431 return useragent;
00432 }
00433
00434 QString KProtocolManager::defaultUserAgent( )
00435 {
00436 QString modifiers = KIO::SlaveConfig::self()->configData("http", QString(), "UserAgentKeys");
00437 return defaultUserAgent(modifiers);
00438 }
00439
00440 QString KProtocolManager::defaultUserAgent( const QString &_modifiers )
00441 {
00442 PRIVATE_DATA;
00443 QString modifiers = _modifiers.toLower();
00444 if (modifiers.isEmpty())
00445 modifiers = DEFAULT_USER_AGENT_KEYS;
00446
00447 if (d->modifiers == modifiers)
00448 return d->useragent;
00449
00450 QString systemName, systemVersion, machine, supp;
00451 if (getSystemNameVersionAndMachine( systemName, systemVersion, machine ))
00452 {
00453 if( modifiers.contains('o') )
00454 {
00455 supp += QString("; %1").arg(systemName);
00456 if ( modifiers.contains('v') )
00457 supp += QString(" %1").arg(systemVersion);
00458 }
00459 #ifdef Q_WS_X11
00460 if( modifiers.contains('p') )
00461 {
00462 supp += QLatin1String("; X11");
00463 }
00464 #endif
00465 if( modifiers.contains('m') )
00466 {
00467 supp += QString("; %1").arg(machine);
00468 }
00469 if( modifiers.contains('l') )
00470 {
00471 supp += QString("; %1").arg(KGlobal::locale()->language());
00472 }
00473 }
00474 d->modifiers = modifiers;
00475 d->useragent = CFG_DEFAULT_UAGENT(supp);
00476 return d->useragent;
00477 }
00478
00479 QString KProtocolManager::userAgentForApplication( const QString &appName, const QString& appVersion,
00480 const QStringList& extraInfo )
00481 {
00482 QString systemName, systemVersion, machine;
00483 QStringList info;
00484 if (getSystemNameVersionAndMachine( systemName, systemVersion, machine ))
00485 info += QString::fromLatin1("%1/%2").arg(systemName).arg(systemVersion);
00486 info += QString::fromLatin1("KDE/%1.%2.%3").arg(KDE_VERSION_MAJOR)
00487 .arg(KDE_VERSION_MINOR).arg(KDE_VERSION_RELEASE);
00488 if (!machine.isEmpty())
00489 info += machine;
00490 info += extraInfo;
00491 return QString::fromLatin1("%1/%2 (%3)").arg(appName).arg(appVersion).arg(info.join("; "));
00492 }
00493
00494 bool KProtocolManager::getSystemNameVersionAndMachine(
00495 QString& systemName, QString& systemVersion, QString& machine )
00496 {
00497 struct utsname unameBuf;
00498 if ( 0 != uname( &unameBuf ) )
00499 return false;
00500 #ifdef Q_WS_WIN
00501
00502
00503 systemName = QLatin1String( "Windows" );
00504 OSVERSIONINFOEX versioninfo;
00505 ZeroMemory(&versioninfo, sizeof(OSVERSIONINFOEX));
00506
00507 versioninfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
00508 bool ok = GetVersionEx( (OSVERSIONINFO *) &versioninfo );
00509 if ( !ok ) {
00510 versioninfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
00511 ok = GetVersionEx( (OSVERSIONINFO *) &versioninfo );
00512 }
00513 if ( ok )
00514 systemVersion = QString::fromLatin1("%1.%2")
00515 .arg(versioninfo.dwMajorVersion).arg(versioninfo.dwMinorVersion);
00516 #else
00517 systemName = unameBuf.sysname;
00518 systemVersion = unameBuf.release;
00519 #endif
00520 machine = unameBuf.machine;
00521 return true;
00522 }
00523
00524 QString KProtocolManager::acceptLanguagesHeader()
00525 {
00526 static const QString &english = KGlobal::staticQString("en");
00527
00528
00529 QStringList languageList = KGlobal::locale()->languageList();
00530
00531
00532
00533
00534 int idx = languageList.indexOf(QString::fromLatin1("C"));
00535 if (idx != -1)
00536 {
00537 if (languageList.contains(english))
00538 languageList.removeAt(idx);
00539 else
00540 languageList[idx] = english;
00541 }
00542 if (!languageList.contains(english))
00543 languageList += english;
00544
00545
00546
00547 KConfig acclangConf("accept-languages.codes", KConfig::NoGlobals);
00548 KConfigGroup replacementCodes(&acclangConf, "ReplacementCodes");
00549 QStringList languageListFinal;
00550 foreach (const QString &lang, languageList)
00551 {
00552 QStringList langs = replacementCodes.readEntry(lang, QStringList());
00553 if (langs.isEmpty())
00554 languageListFinal += lang;
00555 else
00556 languageListFinal += langs;
00557 }
00558
00559
00560 QString header = languageListFinal.join(", ");
00561
00562
00563
00564
00565 header.replace('_', '-');
00566 header.replace('@', '-');
00567
00568 return header;
00569 }
00570
00571
00572
00573 bool KProtocolManager::markPartial()
00574 {
00575 return config()->group(QByteArray()).readEntry( "MarkPartial", true );
00576 }
00577
00578 int KProtocolManager::minimumKeepSize()
00579 {
00580 return config()->group(QByteArray()).readEntry( "MinimumKeepSize",
00581 DEFAULT_MINIMUM_KEEP_SIZE );
00582 }
00583
00584 bool KProtocolManager::autoResume()
00585 {
00586 return config()->group(QByteArray()).readEntry( "AutoResume", false );
00587 }
00588
00589 bool KProtocolManager::persistentConnections()
00590 {
00591 return config()->group(QByteArray()).readEntry( "PersistentConnections", true );
00592 }
00593
00594 bool KProtocolManager::persistentProxyConnection()
00595 {
00596 return config()->group(QByteArray()).readEntry( "PersistentProxyConnection", false );
00597 }
00598
00599 QString KProtocolManager::proxyConfigScript()
00600 {
00601 return config()->group("Proxy Settings").readEntry( "Proxy Config Script" );
00602 }
00603
00604
00605
00606 static KProtocolInfo::Ptr findProtocol(const KUrl &url)
00607 {
00608 QString protocol = url.protocol();
00609
00610 if ( !KProtocolInfo::proxiedBy( protocol ).isEmpty() )
00611 {
00612 QString dummy;
00613 protocol = KProtocolManager::slaveProtocol(url, dummy);
00614 }
00615
00616 return KProtocolInfoFactory::self()->findProtocol(protocol);
00617 }
00618
00619
00620 KProtocolInfo::Type KProtocolManager::inputType( const KUrl &url )
00621 {
00622 KProtocolInfo::Ptr prot = findProtocol(url);
00623 if ( !prot )
00624 return KProtocolInfo::T_NONE;
00625
00626 return prot->m_inputType;
00627 }
00628
00629 KProtocolInfo::Type KProtocolManager::outputType( const KUrl &url )
00630 {
00631 KProtocolInfo::Ptr prot = findProtocol(url);
00632 if ( !prot )
00633 return KProtocolInfo::T_NONE;
00634
00635 return prot->m_outputType;
00636 }
00637
00638
00639 bool KProtocolManager::isSourceProtocol( const KUrl &url )
00640 {
00641 KProtocolInfo::Ptr prot = findProtocol(url);
00642 if ( !prot )
00643 return false;
00644
00645 return prot->m_isSourceProtocol;
00646 }
00647
00648 bool KProtocolManager::supportsListing( const KUrl &url )
00649 {
00650 KProtocolInfo::Ptr prot = findProtocol(url);
00651 if ( !prot )
00652 return false;
00653
00654 return prot->m_supportsListing;
00655 }
00656
00657 QStringList KProtocolManager::listing( const KUrl &url )
00658 {
00659 KProtocolInfo::Ptr prot = findProtocol(url);
00660 if ( !prot )
00661 return QStringList();
00662
00663 return prot->m_listing;
00664 }
00665
00666 bool KProtocolManager::supportsReading( const KUrl &url )
00667 {
00668 KProtocolInfo::Ptr prot = findProtocol(url);
00669 if ( !prot )
00670 return false;
00671
00672 return prot->m_supportsReading;
00673 }
00674
00675 bool KProtocolManager::supportsWriting( const KUrl &url )
00676 {
00677 KProtocolInfo::Ptr prot = findProtocol(url);
00678 if ( !prot )
00679 return false;
00680
00681 return prot->m_supportsWriting;
00682 }
00683
00684 bool KProtocolManager::supportsMakeDir( const KUrl &url )
00685 {
00686 KProtocolInfo::Ptr prot = findProtocol(url);
00687 if ( !prot )
00688 return false;
00689
00690 return prot->m_supportsMakeDir;
00691 }
00692
00693 bool KProtocolManager::supportsDeleting( const KUrl &url )
00694 {
00695 KProtocolInfo::Ptr prot = findProtocol(url);
00696 if ( !prot )
00697 return false;
00698
00699 return prot->m_supportsDeleting;
00700 }
00701
00702 bool KProtocolManager::supportsLinking( const KUrl &url )
00703 {
00704 KProtocolInfo::Ptr prot = findProtocol(url);
00705 if ( !prot )
00706 return false;
00707
00708 return prot->m_supportsLinking;
00709 }
00710
00711 bool KProtocolManager::supportsMoving( const KUrl &url )
00712 {
00713 KProtocolInfo::Ptr prot = findProtocol(url);
00714 if ( !prot )
00715 return false;
00716
00717 return prot->m_supportsMoving;
00718 }
00719
00720 bool KProtocolManager::supportsOpening( const KUrl &url )
00721 {
00722 KProtocolInfo::Ptr prot = findProtocol(url);
00723 if ( !prot )
00724 return false;
00725
00726 return prot->m_supportsOpening;
00727 }
00728
00729 bool KProtocolManager::canCopyFromFile( const KUrl &url )
00730 {
00731 KProtocolInfo::Ptr prot = findProtocol(url);
00732 if ( !prot )
00733 return false;
00734
00735 return prot->m_canCopyFromFile;
00736 }
00737
00738
00739 bool KProtocolManager::canCopyToFile( const KUrl &url )
00740 {
00741 KProtocolInfo::Ptr prot = findProtocol(url);
00742 if ( !prot )
00743 return false;
00744
00745 return prot->m_canCopyToFile;
00746 }
00747
00748 bool KProtocolManager::canRenameFromFile( const KUrl &url )
00749 {
00750 KProtocolInfo::Ptr prot = findProtocol(url);
00751 if ( !prot )
00752 return false;
00753
00754 return prot->canRenameFromFile();
00755 }
00756
00757
00758 bool KProtocolManager::canRenameToFile( const KUrl &url )
00759 {
00760 KProtocolInfo::Ptr prot = findProtocol(url);
00761 if ( !prot )
00762 return false;
00763
00764 return prot->canRenameToFile();
00765 }
00766
00767 bool KProtocolManager::canDeleteRecursive( const KUrl &url )
00768 {
00769 KProtocolInfo::Ptr prot = findProtocol(url);
00770 if ( !prot )
00771 return false;
00772
00773 return prot->canDeleteRecursive();
00774 }
00775
00776 KProtocolInfo::FileNameUsedForCopying KProtocolManager::fileNameUsedForCopying( const KUrl &url )
00777 {
00778 KProtocolInfo::Ptr prot = findProtocol(url);
00779 if ( !prot )
00780 return KProtocolInfo::FromUrl;
00781
00782 return prot->fileNameUsedForCopying();
00783 }
00784
00785 QString KProtocolManager::defaultMimetype( const KUrl &url )
00786 {
00787 KProtocolInfo::Ptr prot = findProtocol(url);
00788 if ( !prot )
00789 return QString();
00790
00791 return prot->m_defaultMimetype;
00792 }
00793
00794 QString KProtocolManager::protocolForArchiveMimetype( const QString& mimeType )
00795 {
00796 PRIVATE_DATA;
00797 if (d->protocolForArchiveMimetypes.isEmpty()) {
00798 const KProtocolInfo::List allProtocols = KProtocolInfoFactory::self()->allProtocols();
00799 for (KProtocolInfo::List::const_iterator it = allProtocols.begin();
00800 it != allProtocols.end(); ++it) {
00801 const QStringList archiveMimetypes = (*it)->archiveMimeTypes();
00802 Q_FOREACH(const QString& mime, archiveMimetypes) {
00803 d->protocolForArchiveMimetypes.insert(mime, (*it)->name());
00804 }
00805 }
00806 }
00807 return d->protocolForArchiveMimetypes.value(mimeType);
00808 }
00809
00810 #undef PRIVATE_DATA