kprotocolinfo.cpp Source File (kio Library)

| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kprotocolinfo.cpp

    00001 /* This file is part of the KDE libraries
    00002    Copyright (C) 1999 Torben Weis <weis@kde.org>
    00003
    00004    This library is free software; you can redistribute it and/or
    00005    modify it under the terms of the GNU Library General Public
    00006    License version 2 as published by the Free Software Foundation.
    00007
    00008    This library is distributed in the hope that it will be useful,
    00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
    00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00011    Library General Public License for more details.
    00012
    00013    You should have received a copy of the GNU Library General Public License
    00014    along with this library; see the file COPYING.LIB.  If not, write to
    00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00016    Boston, MA 02111-1307, USA.
    00017 */
    00018
    00019 #include "kprotocolinfo.h"
    00020 #include "kprotocolinfofactory.h"
    00021
    00022 #include <kstandarddirs.h>
    00023 #include <kglobal.h>
    00024 #include <kapplication.h>
    00025 #include <kdebug.h>
    00026 #include <ksimpleconfig.h>
    00027 #include <kconfig.h>
    00028 #include <kstringhandler.h>
    00029
    00030 #include <stdio.h> // WAAB remove me
    00031
    00032 //
    00033 // Internal functions:
    00034 //
    00035 KProtocolInfo::KProtocolInfo(const QString &path)
    00036  : KSycocaEntry(path)
    00037 {
    00038   QString fullPath = locate("services", path);
    00039
    00040   KSimpleConfig config( fullPath, true );
    00041   config.setGroup( "Protocol" );
    00042
    00043   m_name = config.readEntry( "protocol" );
    00044   m_exec = config.readPathEntry( "exec" );
    00045   m_isSourceProtocol = config.readBoolEntry( "source", true );
    00046   m_isHelperProtocol = config.readBoolEntry( "helper", false );
    00047   m_supportsReading = config.readBoolEntry( "reading", false );
    00048   m_supportsWriting = config.readBoolEntry( "writing", false );
    00049   m_supportsMakeDir = config.readBoolEntry( "makedir", false );
    00050   m_supportsDeleting = config.readBoolEntry( "deleting", false );
    00051   m_supportsLinking = config.readBoolEntry( "linking", false );
    00052   m_supportsMoving = config.readBoolEntry( "moving", false );
    00053   m_canCopyFromFile = config.readBoolEntry( "copyFromFile", false );
    00054   m_canCopyToFile = config.readBoolEntry( "copyToFile", false );
    00055   m_listing = config.readListEntry( "listing" );
    00056   // Many .protocol files say "Listing=false" when they really mean "Listing=" (i.e. unsupported)
    00057   if ( m_listing.count() == 1 && m_listing.first() == "false" )
    00058     m_listing.clear();
    00059   m_supportsListing = ( m_listing.count() > 0 );
    00060   m_defaultMimetype = config.readEntry( "defaultMimetype" );
    00061   m_determineMimetypeFromExtension = config.readBoolEntry( "determineMimetypeFromExtension", true );
    00062   m_icon = config.readEntry( "Icon", "mime_empty" );
    00063   m_config = config.readEntry( "config", m_name );
    00064   m_maxSlaves = config.readNumEntry( "maxInstances", 1);
    00065
    00066   QString tmp = config.readEntry( "input" );
    00067   if ( tmp == "filesystem" )
    00068     m_inputType = KProtocolInfo::T_FILESYSTEM;
    00069   else if ( tmp == "stream" )
    00070     m_inputType = KProtocolInfo::T_STREAM;
    00071   else
    00072     m_inputType = KProtocolInfo::T_NONE;
    00073
    00074   tmp = config.readEntry( "output" );
    00075   if ( tmp == "filesystem" )
    00076     m_outputType = KProtocolInfo::T_FILESYSTEM;
    00077   else if ( tmp == "stream" )
    00078     m_outputType = KProtocolInfo::T_STREAM;
    00079   else
    00080     m_outputType = KProtocolInfo::T_NONE;
    00081 }
    00082
    00083 KProtocolInfo::KProtocolInfo( QDataStream& _str, int offset) :
    00084         KSycocaEntry( _str, offset)
    00085 {
    00086    load( _str );
    00087 }
    00088
    00089 KProtocolInfo::~KProtocolInfo()
    00090 {
    00091 }
    00092
    00093 void
    00094 KProtocolInfo::load( QDataStream& _str)
    00095 {
    00096    Q_INT32 i_inputType, i_outputType;
    00097    Q_INT8 i_isSourceProtocol, i_isHelperProtocol,
    00098           i_supportsListing, i_supportsReading,
    00099           i_supportsWriting, i_supportsMakeDir,
    00100           i_supportsDeleting, i_supportsLinking,
    00101           i_supportsMoving, i_determineMimetypeFromExtension,
    00102           i_canCopyFromFile, i_canCopyToFile;
    00103    _str >> m_name >> m_exec >> m_listing >> m_defaultMimetype
    00104         >> i_determineMimetypeFromExtension
    00105         >> m_icon
    00106         >> i_inputType >> i_outputType
    00107         >> i_isSourceProtocol >> i_isHelperProtocol
    00108         >> i_supportsListing >> i_supportsReading
    00109         >> i_supportsWriting >> i_supportsMakeDir
    00110         >> i_supportsDeleting >> i_supportsLinking
    00111         >> i_supportsMoving
    00112         >> i_canCopyFromFile >> i_canCopyToFile
    00113         >> m_config >> m_maxSlaves;
    00114    m_inputType = (Type) i_inputType;
    00115    m_outputType = (Type) i_outputType;
    00116    m_isSourceProtocol = (i_isSourceProtocol != 0);
    00117    m_isHelperProtocol = (i_isHelperProtocol != 0);
    00118    m_supportsListing = (i_supportsListing != 0);
    00119    m_supportsReading = (i_supportsReading != 0);
    00120    m_supportsWriting = (i_supportsWriting != 0);
    00121    m_supportsMakeDir = (i_supportsMakeDir != 0);
    00122    m_supportsDeleting = (i_supportsDeleting != 0);
    00123    m_supportsLinking = (i_supportsLinking != 0);
    00124    m_supportsMoving = (i_supportsMoving != 0);
    00125    m_canCopyFromFile = (i_canCopyFromFile != 0);
    00126    m_canCopyToFile = (i_canCopyToFile != 0);
    00127    m_determineMimetypeFromExtension = (i_determineMimetypeFromExtension != 0);
    00128 }
    00129
    00130 void
    00131 KProtocolInfo::save( QDataStream& _str)
    00132 {
    00133    KSycocaEntry::save( _str );
    00134
    00135    Q_INT32 i_inputType, i_outputType;
    00136    Q_INT8 i_isSourceProtocol, i_isHelperProtocol,
    00137           i_supportsListing, i_supportsReading,
    00138           i_supportsWriting, i_supportsMakeDir,
    00139           i_supportsDeleting, i_supportsLinking,
    00140           i_supportsMoving, i_determineMimetypeFromExtension,
    00141           i_canCopyFromFile, i_canCopyToFile;
    00142
    00143    i_inputType = (Q_INT32) m_inputType;
    00144    i_outputType = (Q_INT32) m_outputType;
    00145    i_isSourceProtocol = m_isSourceProtocol ? 1 : 0;
    00146    i_isHelperProtocol = m_isHelperProtocol ? 1 : 0;
    00147    i_supportsListing = m_supportsListing ? 1 : 0;
    00148    i_supportsReading = m_supportsReading ? 1 : 0;
    00149    i_supportsWriting = m_supportsWriting ? 1 : 0;
    00150    i_supportsMakeDir = m_supportsMakeDir ? 1 : 0;
    00151    i_supportsDeleting = m_supportsDeleting ? 1 : 0;
    00152    i_supportsLinking = m_supportsLinking ? 1 : 0;
    00153    i_supportsMoving = m_supportsMoving ? 1 : 0;
    00154    i_canCopyFromFile = m_canCopyFromFile ? 1 : 0;
    00155    i_canCopyToFile = m_canCopyToFile ? 1 : 0;
    00156    i_determineMimetypeFromExtension = m_determineMimetypeFromExtension ? 1 : 0;
    00157
    00158
    00159    _str << m_name << m_exec << m_listing << m_defaultMimetype
    00160         << i_determineMimetypeFromExtension
    00161         << m_icon
    00162         << i_inputType << i_outputType
    00163         << i_isSourceProtocol << i_isHelperProtocol
    00164         << i_supportsListing << i_supportsReading
    00165         << i_supportsWriting << i_supportsMakeDir
    00166         << i_supportsDeleting << i_supportsLinking
    00167         << i_supportsMoving
    00168         << i_canCopyFromFile << i_canCopyToFile
    00169         << m_config << m_maxSlaves;
    00170 }
    00171
    00172
    00173 //
    00174 // Static functions:
    00175 //
    00176
    00177 QStringList KProtocolInfo::protocols()
    00178 {
    00179   return KProtocolInfoFactory::self()->protocols();
    00180 }
    00181
    00182 bool KProtocolInfo::isSourceProtocol( const QString& _protocol )
    00183 {
    00184   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00185   if ( !prot )
    00186     return false;
    00187
    00188   return prot->m_isSourceProtocol;
    00189 }
    00190
    00191 bool KProtocolInfo::isFilterProtocol( const QString& _protocol )
    00192 {
    00193   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00194   if ( !prot )
    00195     return false;
    00196
    00197   return !prot->m_isSourceProtocol;
    00198 }
    00199
    00200 bool KProtocolInfo::isHelperProtocol( const QString& _protocol )
    00201 {
    00202   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00203   if ( !prot )
    00204     return false;
    00205
    00206   return prot->m_isHelperProtocol;
    00207 }
    00208
    00209 bool KProtocolInfo::isKnownProtocol( const QString& _protocol )
    00210 {
    00211   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00212   return ( prot != 0);
    00213 }
    00214
    00215 bool KProtocolInfo::supportsListing( const QString& _protocol )
    00216 {
    00217   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00218   if ( !prot )
    00219     return false;
    00220
    00221   return prot->m_supportsListing;
    00222 }
    00223
    00224 QStringList KProtocolInfo::listing( const QString& _protocol )
    00225 {
    00226   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00227   if ( !prot )
    00228     return QStringList();
    00229
    00230   return prot->m_listing;
    00231 }
    00232
    00233 bool KProtocolInfo::supportsReading( const QString& _protocol )
    00234 {
    00235   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00236   if ( !prot )
    00237     return false;
    00238
    00239   return prot->m_supportsReading;
    00240 }
    00241
    00242 bool KProtocolInfo::supportsWriting( const QString& _protocol )
    00243 {
    00244   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00245   if ( !prot )
    00246     return false;
    00247
    00248   return prot->m_supportsWriting;
    00249 }
    00250
    00251 bool KProtocolInfo::supportsMakeDir( const QString& _protocol )
    00252 {
    00253   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00254   if ( !prot )
    00255     return false;
    00256
    00257   return prot->m_supportsMakeDir;
    00258 }
    00259
    00260 bool KProtocolInfo::supportsDeleting( const QString& _protocol )
    00261 {
    00262   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00263   if ( !prot )
    00264     return false;
    00265
    00266   return prot->m_supportsDeleting;
    00267 }
    00268
    00269 bool KProtocolInfo::supportsLinking( const QString& _protocol )
    00270 {
    00271   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00272   if ( !prot )
    00273     return false;
    00274
    00275   return prot->m_supportsLinking;
    00276 }
    00277
    00278 bool KProtocolInfo::supportsMoving( const QString& _protocol )
    00279 {
    00280   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00281   if ( !prot )
    00282     return false;
    00283
    00284   return prot->m_supportsMoving;
    00285 }
    00286
    00287 bool KProtocolInfo::canCopyFromFile( const QString& _protocol )
    00288 {
    00289   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00290   if ( !prot )
    00291     return false;
    00292
    00293   return prot->m_canCopyFromFile;
    00294 }
    00295
    00296
    00297 bool KProtocolInfo::canCopyToFile( const QString& _protocol )
    00298 {
    00299   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00300   if ( !prot )
    00301     return false;
    00302
    00303   return prot->m_canCopyToFile;
    00304 }
    00305
    00306 QString KProtocolInfo::icon( const QString& _protocol )
    00307 {
    00308   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00309   if ( !prot )
    00310     return QString::fromLatin1("mime_empty");
    00311
    00312   return prot->m_icon;
    00313 }
    00314
    00315 QString KProtocolInfo::config( const QString& _protocol )
    00316 {
    00317   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00318   if ( !prot )
    00319     return QString::null;
    00320
    00321   return QString("kio_%1rc").arg(prot->m_config);
    00322 }
    00323
    00324 int KProtocolInfo::maxSlaves( const QString& _protocol )
    00325 {
    00326   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00327   if ( !prot )
    00328     return 1;
    00329
    00330   return prot->m_maxSlaves;
    00331 }
    00332
    00333 QString KProtocolInfo::defaultMimetype( const QString& _protocol )
    00334 {
    00335   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00336   if ( !prot )
    00337     return QString::null;
    00338
    00339   return prot->m_defaultMimetype;
    00340 }
    00341
    00342 bool KProtocolInfo::determineMimetypeFromExtension( const QString &_protocol )
    00343 {
    00344   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol( _protocol );
    00345   if ( !prot )
    00346     return true;
    00347
    00348   return prot->m_determineMimetypeFromExtension;
    00349 }
    00350
    00351 QString KProtocolInfo::exec( const QString& _protocol )
    00352 {
    00353   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00354   if ( !prot )
    00355     return QString::null;
    00356
    00357   return prot->m_exec;
    00358 }
    00359
    00360 KProtocolInfo::Type KProtocolInfo::inputType( const QString& _protocol )
    00361 {
    00362   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00363   if ( !prot )
    00364     return T_NONE;
    00365
    00366   return prot->m_inputType;
    00367 }
    00368
    00369 KProtocolInfo::Type KProtocolInfo::outputType( const QString& _protocol )
    00370 {
    00371   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
    00372   if ( !prot )
    00373     return T_NONE;
    00374
    00375   return prot->m_outputType;
    00376 }
    00377
    00378
    00379 KProtocolInfo::Type KProtocolInfo::inputType( const KURL &url )
    00380 {
    00381   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url);
    00382   if ( !prot )
    00383     return T_NONE;
    00384
    00385   return prot->m_inputType;
    00386 }
    00387
    00388 KProtocolInfo::Type KProtocolInfo::outputType( const KURL &url )
    00389 {
    00390   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url);
    00391   if ( !prot )
    00392     return T_NONE;
    00393
    00394   return prot->m_outputType;
    00395 }
    00396
    00397
    00398 bool KProtocolInfo::isSourceProtocol( const KURL &url )
    00399 {
    00400   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url);
    00401   if ( !prot )
    00402     return false;
    00403
    00404   return prot->m_isSourceProtocol;
    00405 }
    00406
    00407 bool KProtocolInfo::isFilterProtocol( const KURL &url )
    00408 {
    00409   // We use url.protocol() to bypass any proxy settings.
    00410   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url.protocol());
    00411   if ( !prot )
    00412     return false;
    00413
    00414   return !prot->m_isSourceProtocol;
    00415 }
    00416
    00417 bool KProtocolInfo::isHelperProtocol( const KURL &url )
    00418 {
    00419   // We use url.protocol() to bypass any proxy settings.
    00420   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url.protocol());
    00421   if ( !prot )
    00422     return false;
    00423
    00424   return prot->m_isHelperProtocol;
    00425 }
    00426
    00427 bool KProtocolInfo::isKnownProtocol( const KURL &url )
    00428 {
    00429   // We use url.protocol() to bypass any proxy settings.
    00430   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url.protocol());
    00431   return ( prot != 0);
    00432 }
    00433
    00434 bool KProtocolInfo::supportsListing( const KURL &url )
    00435 {
    00436   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url);
    00437   if ( !prot )
    00438     return false;
    00439
    00440   return prot->m_supportsListing;
    00441 }
    00442
    00443 QStringList KProtocolInfo::listing( const KURL &url )
    00444 {
    00445   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url);
    00446   if ( !prot )
    00447     return QStringList();
    00448
    00449   return prot->m_listing;
    00450 }
    00451
    00452 bool KProtocolInfo::supportsReading( const KURL &url )
    00453 {
    00454   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url);
    00455   if ( !prot )
    00456     return false;
    00457
    00458   return prot->m_supportsReading;
    00459 }
    00460
    00461 bool KProtocolInfo::supportsWriting( const KURL &url )
    00462 {
    00463   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url);
    00464   if ( !prot )
    00465     return false;
    00466
    00467   return prot->m_supportsWriting;
    00468 }
    00469
    00470 bool KProtocolInfo::supportsMakeDir( const KURL &url )
    00471 {
    00472   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url);
    00473   if ( !prot )
    00474     return false;
    00475
    00476   return prot->m_supportsMakeDir;
    00477 }
    00478
    00479 bool KProtocolInfo::supportsDeleting( const KURL &url )
    00480 {
    00481   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url);
    00482   if ( !prot )
    00483     return false;
    00484
    00485   return prot->m_supportsDeleting;
    00486 }
    00487
    00488 bool KProtocolInfo::supportsLinking( const KURL &url )
    00489 {
    00490   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url);
    00491   if ( !prot )
    00492     return false;
    00493
    00494   return prot->m_supportsLinking;
    00495 }
    00496
    00497 bool KProtocolInfo::supportsMoving( const KURL &url )
    00498 {
    00499   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url);
    00500   if ( !prot )
    00501     return false;
    00502
    00503   return prot->m_supportsMoving;
    00504 }
    00505
    00506 bool KProtocolInfo::canCopyFromFile( const KURL &url )
    00507 {
    00508   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url);
    00509   if ( !prot )
    00510     return false;
    00511
    00512   return prot->m_canCopyFromFile;
    00513 }
    00514
    00515
    00516 bool KProtocolInfo::canCopyToFile( const KURL &url )
    00517 {
    00518   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url);
    00519   if ( !prot )
    00520     return false;
    00521
    00522   return prot->m_canCopyToFile;
    00523 }
    00524
    00525 QString KProtocolInfo::defaultMimetype( const KURL &url )
    00526 {
    00527   KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url);
    00528   if ( !prot )
    00529     return QString::null;
    00530
    00531   return prot->m_defaultMimetype;
    00532 }
    00533
    00534 void KProtocolInfo::virtual_hook( int id, void* data )
    00535 { KSycocaEntry::virtual_hook( id, data ); }
    00536

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:14:08 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001