00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifdef MAKE_KDECORE_LIB //needed for proper linkage (win32)
00020 #undef KIO_EXPORT
00021 #define KIO_EXPORT KDE_EXPORT
00022 #endif
00023
00024 #define KPROTOCOLINFO_KDECORE
00025 #include "kprotocolinfo.h"
00026 #include "kprotocolinfofactory.h"
00027
00028 #include <kstandarddirs.h>
00029 #include <kglobal.h>
00030 #include <kapplication.h>
00031 #include <kdebug.h>
00032 #include <ksimpleconfig.h>
00033 #include <kconfig.h>
00034 #include <kstringhandler.h>
00035
00036 class KProtocolInfo::KProtocolInfoPrivate
00037 {
00038 public:
00039 QString docPath;
00040 QString protClass;
00041 KProtocolInfo::ExtraFieldList extraFields;
00042 bool showPreviews;
00043 bool canRenameFromFile;
00044 bool canRenameToFile;
00045 bool canDeleteRecursive;
00046 bool fileNameUsedForCopying;
00047 KURL::URIMode uriMode;
00048 QStringList capabilities;
00049 QString proxyProtocol;
00050 };
00051
00052
00053
00054
00055 KProtocolInfo::KProtocolInfo(const QString &path)
00056 : KSycocaEntry(path)
00057 {
00058 d = new KProtocolInfoPrivate;
00059 QString fullPath = locate("services", path);
00060
00061 KSimpleConfig config( fullPath, true );
00062 config.setGroup( "Protocol" );
00063
00064 m_name = config.readEntry( "protocol" );
00065 m_exec = config.readPathEntry( "exec" );
00066 m_isSourceProtocol = config.readBoolEntry( "source", true );
00067 m_isHelperProtocol = config.readBoolEntry( "helper", false );
00068 m_supportsReading = config.readBoolEntry( "reading", false );
00069 m_supportsWriting = config.readBoolEntry( "writing", false );
00070 m_supportsMakeDir = config.readBoolEntry( "makedir", false );
00071 m_supportsDeleting = config.readBoolEntry( "deleting", false );
00072 m_supportsLinking = config.readBoolEntry( "linking", false );
00073 m_supportsMoving = config.readBoolEntry( "moving", false );
00074 m_canCopyFromFile = config.readBoolEntry( "copyFromFile", false );
00075 m_canCopyToFile = config.readBoolEntry( "copyToFile", false );
00076 d->canRenameFromFile = config.readBoolEntry( "renameFromFile", false );
00077 d->canRenameToFile = config.readBoolEntry( "renameToFile", false );
00078 d->canDeleteRecursive = config.readBoolEntry( "deleteRecursive", false );
00079 d->fileNameUsedForCopying = config.readEntry( "fileNameUsedForCopying", "FromURL" ) == "Name";
00080
00081 m_listing = config.readListEntry( "listing" );
00082
00083 if ( m_listing.count() == 1 && m_listing.first() == "false" )
00084 m_listing.clear();
00085 m_supportsListing = ( m_listing.count() > 0 );
00086 m_defaultMimetype = config.readEntry( "defaultMimetype" );
00087 m_determineMimetypeFromExtension = config.readBoolEntry( "determineMimetypeFromExtension", true );
00088 m_icon = config.readEntry( "Icon", "unknown" );
00089 m_config = config.readEntry( "config", m_name );
00090 m_maxSlaves = config.readNumEntry( "maxInstances", 1);
00091
00092 QString tmp = config.readEntry( "input" );
00093 if ( tmp == "filesystem" )
00094 m_inputType = KProtocolInfo::T_FILESYSTEM;
00095 else if ( tmp == "stream" )
00096 m_inputType = KProtocolInfo::T_STREAM;
00097 else
00098 m_inputType = KProtocolInfo::T_NONE;
00099
00100 tmp = config.readEntry( "output" );
00101 if ( tmp == "filesystem" )
00102 m_outputType = KProtocolInfo::T_FILESYSTEM;
00103 else if ( tmp == "stream" )
00104 m_outputType = KProtocolInfo::T_STREAM;
00105 else
00106 m_outputType = KProtocolInfo::T_NONE;
00107
00108 d->docPath = config.readPathEntry( "DocPath" );
00109 d->protClass = config.readEntry( "Class" ).lower();
00110 if (d->protClass[0] != ':')
00111 d->protClass.prepend(':');
00112
00113 QStringList extraNames = config.readListEntry( "ExtraNames" );
00114 QStringList extraTypes = config.readListEntry( "ExtraTypes" );
00115 QStringList::Iterator it = extraNames.begin();
00116 QStringList::Iterator typeit = extraTypes.begin();
00117 for( ; it != extraNames.end() && typeit != extraTypes.end(); ++it, ++typeit ) {
00118 d->extraFields.append( ExtraField( *it, *typeit ) );
00119 }
00120
00121 d->showPreviews = config.readBoolEntry( "ShowPreviews", d->protClass == ":local" );
00122
00123 tmp = config.readEntry( "URIMode", QString::null ).lower();
00124 if (tmp == "rawuri")
00125 d->uriMode = KURL::RawURI;
00126 else if (tmp == "mailto")
00127 d->uriMode = KURL::Mailto;
00128 else if (tmp == "url")
00129 d->uriMode = KURL::URL;
00130 else
00131 d->uriMode = KURL::Auto;
00132
00133 d->capabilities = config.readListEntry( "Capabilities" );
00134 d->proxyProtocol = config.readEntry( "ProxiedBy" );
00135 }
00136
00137 KProtocolInfo::KProtocolInfo( QDataStream& _str, int offset) :
00138 KSycocaEntry( _str, offset)
00139 {
00140 d = new KProtocolInfoPrivate;
00141 load( _str );
00142 }
00143
00144 KProtocolInfo::~KProtocolInfo()
00145 {
00146 delete d;
00147 }
00148
00149 void
00150 KProtocolInfo::load( QDataStream& _str)
00151 {
00152
00153
00154 Q_INT32 i_inputType, i_outputType;
00155 Q_INT8 i_isSourceProtocol, i_isHelperProtocol,
00156 i_supportsListing, i_supportsReading,
00157 i_supportsWriting, i_supportsMakeDir,
00158 i_supportsDeleting, i_supportsLinking,
00159 i_supportsMoving, i_determineMimetypeFromExtension,
00160 i_canCopyFromFile, i_canCopyToFile, i_showPreviews,
00161 i_uriMode, i_canRenameFromFile, i_canRenameToFile,
00162 i_canDeleteRecursive, i_fileNameUsedForCopying;
00163
00164 _str >> m_name >> m_exec >> m_listing >> m_defaultMimetype
00165 >> i_determineMimetypeFromExtension
00166 >> m_icon
00167 >> i_inputType >> i_outputType
00168 >> i_isSourceProtocol >> i_isHelperProtocol
00169 >> i_supportsListing >> i_supportsReading
00170 >> i_supportsWriting >> i_supportsMakeDir
00171 >> i_supportsDeleting >> i_supportsLinking
00172 >> i_supportsMoving
00173 >> i_canCopyFromFile >> i_canCopyToFile
00174 >> m_config >> m_maxSlaves >> d->docPath >> d->protClass
00175 >> d->extraFields >> i_showPreviews >> i_uriMode
00176 >> d->capabilities >> d->proxyProtocol
00177 >> i_canRenameFromFile >> i_canRenameToFile
00178 >> i_canDeleteRecursive >> i_fileNameUsedForCopying;
00179
00180 m_inputType = (Type) i_inputType;
00181 m_outputType = (Type) i_outputType;
00182 m_isSourceProtocol = (i_isSourceProtocol != 0);
00183 m_isHelperProtocol = (i_isHelperProtocol != 0);
00184 m_supportsListing = (i_supportsListing != 0);
00185 m_supportsReading = (i_supportsReading != 0);
00186 m_supportsWriting = (i_supportsWriting != 0);
00187 m_supportsMakeDir = (i_supportsMakeDir != 0);
00188 m_supportsDeleting = (i_supportsDeleting != 0);
00189 m_supportsLinking = (i_supportsLinking != 0);
00190 m_supportsMoving = (i_supportsMoving != 0);
00191 m_canCopyFromFile = (i_canCopyFromFile != 0);
00192 m_canCopyToFile = (i_canCopyToFile != 0);
00193 d->canRenameFromFile = (i_canRenameFromFile != 0);
00194 d->canRenameToFile = (i_canRenameToFile != 0);
00195 d->canDeleteRecursive = (i_canDeleteRecursive != 0);
00196 d->fileNameUsedForCopying = (i_fileNameUsedForCopying != 0);
00197 m_determineMimetypeFromExtension = (i_determineMimetypeFromExtension != 0);
00198 d->showPreviews = (i_showPreviews != 0);
00199 d->uriMode = (KURL::URIMode) i_uriMode;
00200 }
00201
00202 void
00203 KProtocolInfo::save( QDataStream& _str)
00204 {
00205 KSycocaEntry::save( _str );
00206
00207
00208
00209 Q_INT32 i_inputType, i_outputType;
00210 Q_INT8 i_isSourceProtocol, i_isHelperProtocol,
00211 i_supportsListing, i_supportsReading,
00212 i_supportsWriting, i_supportsMakeDir,
00213 i_supportsDeleting, i_supportsLinking,
00214 i_supportsMoving, i_determineMimetypeFromExtension,
00215 i_canCopyFromFile, i_canCopyToFile, i_showPreviews,
00216 i_uriMode, i_canRenameFromFile, i_canRenameToFile,
00217 i_canDeleteRecursive, i_fileNameUsedForCopying;
00218
00219 i_inputType = (Q_INT32) m_inputType;
00220 i_outputType = (Q_INT32) m_outputType;
00221 i_isSourceProtocol = m_isSourceProtocol ? 1 : 0;
00222 i_isHelperProtocol = m_isHelperProtocol ? 1 : 0;
00223 i_supportsListing = m_supportsListing ? 1 : 0;
00224 i_supportsReading = m_supportsReading ? 1 : 0;
00225 i_supportsWriting = m_supportsWriting ? 1 : 0;
00226 i_supportsMakeDir = m_supportsMakeDir ? 1 : 0;
00227 i_supportsDeleting = m_supportsDeleting ? 1 : 0;
00228 i_supportsLinking = m_supportsLinking ? 1 : 0;
00229 i_supportsMoving = m_supportsMoving ? 1 : 0;
00230 i_canCopyFromFile = m_canCopyFromFile ? 1 : 0;
00231 i_canCopyToFile = m_canCopyToFile ? 1 : 0;
00232 i_canRenameFromFile = d->canRenameFromFile ? 1 : 0;
00233 i_canRenameToFile = d->canRenameToFile ? 1 : 0;
00234 i_canDeleteRecursive = d->canDeleteRecursive ? 1 : 0;
00235 i_fileNameUsedForCopying = d->fileNameUsedForCopying ? 1 : 0;
00236 i_determineMimetypeFromExtension = m_determineMimetypeFromExtension ? 1 : 0;
00237 i_showPreviews = d->showPreviews ? 1 : 0;
00238 i_uriMode = d->uriMode;
00239
00240 _str << m_name << m_exec << m_listing << m_defaultMimetype
00241 << i_determineMimetypeFromExtension
00242 << m_icon
00243 << i_inputType << i_outputType
00244 << i_isSourceProtocol << i_isHelperProtocol
00245 << i_supportsListing << i_supportsReading
00246 << i_supportsWriting << i_supportsMakeDir
00247 << i_supportsDeleting << i_supportsLinking
00248 << i_supportsMoving
00249 << i_canCopyFromFile << i_canCopyToFile
00250 << m_config << m_maxSlaves << d->docPath << d->protClass
00251 << d->extraFields << i_showPreviews << i_uriMode
00252 << d->capabilities << d->proxyProtocol
00253 << i_canRenameFromFile << i_canRenameToFile
00254 << i_canDeleteRecursive << i_fileNameUsedForCopying;
00255 }
00256
00257
00258
00259
00260
00261
00262 QStringList KProtocolInfo::protocols()
00263 {
00264 return KProtocolInfoFactory::self()->protocols();
00265 }
00266
00267 bool KProtocolInfo::isSourceProtocol( const QString& _protocol )
00268 {
00269 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00270 if ( !prot )
00271 return false;
00272
00273 return prot->m_isSourceProtocol;
00274 }
00275
00276 bool KProtocolInfo::isFilterProtocol( const QString& _protocol )
00277 {
00278 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00279 if ( !prot )
00280 return false;
00281
00282 return !prot->m_isSourceProtocol;
00283 }
00284
00285 bool KProtocolInfo::isHelperProtocol( const QString& _protocol )
00286 {
00287 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00288 if ( !prot )
00289 return false;
00290
00291 return prot->m_isHelperProtocol;
00292 }
00293
00294 bool KProtocolInfo::isKnownProtocol( const QString& _protocol )
00295 {
00296 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00297 return ( prot != 0);
00298 }
00299
00300 bool KProtocolInfo::supportsListing( const QString& _protocol )
00301 {
00302 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00303 if ( !prot )
00304 return false;
00305
00306 return prot->m_supportsListing;
00307 }
00308
00309 QStringList KProtocolInfo::listing( const QString& _protocol )
00310 {
00311 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00312 if ( !prot )
00313 return QStringList();
00314
00315 return prot->m_listing;
00316 }
00317
00318 bool KProtocolInfo::supportsReading( const QString& _protocol )
00319 {
00320 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00321 if ( !prot )
00322 return false;
00323
00324 return prot->m_supportsReading;
00325 }
00326
00327 bool KProtocolInfo::supportsWriting( const QString& _protocol )
00328 {
00329 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00330 if ( !prot )
00331 return false;
00332
00333 return prot->m_supportsWriting;
00334 }
00335
00336 bool KProtocolInfo::supportsMakeDir( const QString& _protocol )
00337 {
00338 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00339 if ( !prot )
00340 return false;
00341
00342 return prot->m_supportsMakeDir;
00343 }
00344
00345 bool KProtocolInfo::supportsDeleting( const QString& _protocol )
00346 {
00347 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00348 if ( !prot )
00349 return false;
00350
00351 return prot->m_supportsDeleting;
00352 }
00353
00354 bool KProtocolInfo::supportsLinking( const QString& _protocol )
00355 {
00356 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00357 if ( !prot )
00358 return false;
00359
00360 return prot->m_supportsLinking;
00361 }
00362
00363 bool KProtocolInfo::supportsMoving( const QString& _protocol )
00364 {
00365 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00366 if ( !prot )
00367 return false;
00368
00369 return prot->m_supportsMoving;
00370 }
00371
00372 bool KProtocolInfo::canCopyFromFile( const QString& _protocol )
00373 {
00374 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00375 if ( !prot )
00376 return false;
00377
00378 return prot->m_canCopyFromFile;
00379 }
00380
00381
00382 bool KProtocolInfo::canCopyToFile( const QString& _protocol )
00383 {
00384 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00385 if ( !prot )
00386 return false;
00387
00388 return prot->m_canCopyToFile;
00389 }
00390
00391 QString KProtocolInfo::icon( const QString& _protocol )
00392 {
00393 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00394 if ( !prot )
00395 return QString::fromLatin1("unknown");
00396
00397 return prot->m_icon;
00398 }
00399
00400 QString KProtocolInfo::config( const QString& _protocol )
00401 {
00402 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00403 if ( !prot )
00404 return QString::null;
00405
00406 return QString("kio_%1rc").arg(prot->m_config);
00407 }
00408
00409 int KProtocolInfo::maxSlaves( const QString& _protocol )
00410 {
00411 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00412 if ( !prot )
00413 return 1;
00414
00415 return prot->m_maxSlaves;
00416 }
00417
00418 QString KProtocolInfo::defaultMimetype( const QString& _protocol )
00419 {
00420 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00421 if ( !prot )
00422 return QString::null;
00423
00424 return prot->m_defaultMimetype;
00425 }
00426
00427 bool KProtocolInfo::determineMimetypeFromExtension( const QString &_protocol )
00428 {
00429 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol( _protocol );
00430 if ( !prot )
00431 return true;
00432
00433 return prot->m_determineMimetypeFromExtension;
00434 }
00435
00436 QString KProtocolInfo::exec( const QString& _protocol )
00437 {
00438 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00439 if ( !prot )
00440 return QString::null;
00441
00442 return prot->m_exec;
00443 }
00444
00445 KProtocolInfo::Type KProtocolInfo::inputType( const QString& _protocol )
00446 {
00447 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00448 if ( !prot )
00449 return T_NONE;
00450
00451 return prot->m_inputType;
00452 }
00453
00454 KProtocolInfo::Type KProtocolInfo::outputType( const QString& _protocol )
00455 {
00456 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00457 if ( !prot )
00458 return T_NONE;
00459
00460 return prot->m_outputType;
00461 }
00462
00463 KProtocolInfo::ExtraFieldList KProtocolInfo::extraFields( const KURL &url )
00464 {
00465 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url.protocol());
00466 if ( !prot )
00467 return ExtraFieldList();
00468
00469 return prot->d->extraFields;
00470 }
00471
00472 QString KProtocolInfo::docPath( const QString& _protocol )
00473 {
00474 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00475 if ( !prot )
00476 return QString::null;
00477
00478 return prot->d->docPath;
00479 }
00480
00481 QString KProtocolInfo::protocolClass( const QString& _protocol )
00482 {
00483 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00484 if ( !prot )
00485 return QString::null;
00486
00487 return prot->d->protClass;
00488 }
00489
00490 bool KProtocolInfo::showFilePreview( const QString& _protocol )
00491 {
00492 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00493 if ( !prot )
00494 return false;
00495
00496 return prot->d->showPreviews;
00497 }
00498
00499 KURL::URIMode KProtocolInfo::uriParseMode( const QString& _protocol )
00500 {
00501 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00502 if ( !prot )
00503 return KURL::Auto;
00504
00505 return prot->d->uriMode;
00506 }
00507
00508 QStringList KProtocolInfo::capabilities( const QString& _protocol )
00509 {
00510 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00511 if ( !prot )
00512 return QStringList();
00513
00514 return prot->d->capabilities;
00515 }
00516
00517 QString KProtocolInfo::proxiedBy( const QString& _protocol )
00518 {
00519 KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
00520 if ( !prot )
00521 return QString::null;
00522
00523 return prot->d->proxyProtocol;
00524 }
00525
00526 bool KProtocolInfo::canRenameFromFile() const
00527 {
00528 return d->canRenameFromFile;
00529 }
00530
00531 bool KProtocolInfo::canRenameToFile() const
00532 {
00533 return d->canRenameToFile;
00534 }
00535
00536 bool KProtocolInfo::canDeleteRecursive() const
00537 {
00538 return d->canDeleteRecursive;
00539 }
00540
00541 KProtocolInfo::FileNameUsedForCopying KProtocolInfo::fileNameUsedForCopying() const
00542 {
00543 return d->fileNameUsedForCopying ? Name : FromURL;
00544 }
00545
00546 QDataStream& operator>>( QDataStream& s, KProtocolInfo::ExtraField& field ) {
00547 s >> field.name;
00548 s >> field.type;
00549 return s;
00550 }
00551
00552 QDataStream& operator<<( QDataStream& s, const KProtocolInfo::ExtraField& field ) {
00553 s << field.name;
00554 s << field.type;
00555 return s;
00556 }
00557
00558
00559
00560 void KProtocolInfo::virtual_hook( int id, void* data )
00561 { KSycocaEntry::virtual_hook( id, data ); }
00562