TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kprotocolinfo_tdecore.cpp 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. /* This file is part of the KDE libraries
  2. Copyright (C) 1999 Torben Weis <weis@kde.org>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License version 2 as published by the Free Software Foundation.
  6. This library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Library General Public License for more details.
  10. You should have received a copy of the GNU Library General Public License
  11. along with this library; see the file COPYING.LIB. If not, write to
  12. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  13. Boston, MA 02110-1301, USA.
  14. */
  15. #ifdef MAKE_TDECORE_LIB //needed for proper linkage (win32)
  16. #undef TDEIO_EXPORT
  17. #define TDEIO_EXPORT KDE_EXPORT
  18. #endif
  19. #define KPROTOCOLINFO_TDECORE
  20. #include "kprotocolinfo.h"
  21. #include "kprotocolinfofactory.h"
  22. #include <kstandarddirs.h>
  23. #include <kglobal.h>
  24. #include <kapplication.h>
  25. #include <kdebug.h>
  26. #include <ksimpleconfig.h>
  27. #include <tdeconfig.h>
  28. #include <kstringhandler.h>
  29. class KProtocolInfo::KProtocolInfoPrivate
  30. {
  31. public:
  32. TQString docPath;
  33. TQString protClass;
  34. KProtocolInfo::ExtraFieldList extraFields;
  35. bool showPreviews;
  36. bool canRenameFromFile;
  37. bool canRenameToFile;
  38. bool canDeleteRecursive;
  39. bool fileNameUsedForCopying; // true if using UDS_NAME, false if using KURL::fileName() [default]
  40. KURL::URIMode uriMode;
  41. TQStringList capabilities;
  42. TQString proxyProtocol;
  43. };
  44. //
  45. // Internal functions:
  46. //
  47. KProtocolInfo::KProtocolInfo(const TQString &path)
  48. : KSycocaEntry(path)
  49. {
  50. d = new KProtocolInfoPrivate;
  51. TQString fullPath = locate("services", path);
  52. KSimpleConfig config( fullPath, true );
  53. config.setGroup( "Protocol" );
  54. m_name = config.readEntry( "protocol" );
  55. m_exec = config.readPathEntry( "exec" );
  56. m_isSourceProtocol = config.readBoolEntry( "source", true );
  57. m_isHelperProtocol = config.readBoolEntry( "helper", false );
  58. m_supportsReading = config.readBoolEntry( "reading", false );
  59. m_supportsWriting = config.readBoolEntry( "writing", false );
  60. m_supportsMakeDir = config.readBoolEntry( "makedir", false );
  61. m_supportsDeleting = config.readBoolEntry( "deleting", false );
  62. m_supportsLinking = config.readBoolEntry( "linking", false );
  63. m_supportsMoving = config.readBoolEntry( "moving", false );
  64. m_canCopyFromFile = config.readBoolEntry( "copyFromFile", false );
  65. m_canCopyToFile = config.readBoolEntry( "copyToFile", false );
  66. d->canRenameFromFile = config.readBoolEntry( "renameFromFile", false );
  67. d->canRenameToFile = config.readBoolEntry( "renameToFile", false );
  68. d->canDeleteRecursive = config.readBoolEntry( "deleteRecursive", false );
  69. d->fileNameUsedForCopying = config.readEntry( "fileNameUsedForCopying", "FromURL" ) == "Name";
  70. m_listing = config.readListEntry( "listing" );
  71. // Many .protocol files say "Listing=false" when they really mean "Listing=" (i.e. unsupported)
  72. if ( m_listing.count() == 1 && m_listing.first() == "false" )
  73. m_listing.clear();
  74. m_supportsListing = ( m_listing.count() > 0 );
  75. m_defaultMimetype = config.readEntry( "defaultMimetype" );
  76. m_determineMimetypeFromExtension = config.readBoolEntry( "determineMimetypeFromExtension", true );
  77. m_icon = config.readEntry( "Icon", "unknown" );
  78. m_config = config.readEntry( "config", m_name );
  79. m_maxSlaves = config.readNumEntry( "maxInstances", 1);
  80. TQString tmp = config.readEntry( "input" );
  81. if ( tmp == "filesystem" )
  82. m_inputType = KProtocolInfo::T_FILESYSTEM;
  83. else if ( tmp == "stream" )
  84. m_inputType = KProtocolInfo::T_STREAM;
  85. else
  86. m_inputType = KProtocolInfo::T_NONE;
  87. tmp = config.readEntry( "output" );
  88. if ( tmp == "filesystem" )
  89. m_outputType = KProtocolInfo::T_FILESYSTEM;
  90. else if ( tmp == "stream" )
  91. m_outputType = KProtocolInfo::T_STREAM;
  92. else
  93. m_outputType = KProtocolInfo::T_NONE;
  94. d->docPath = config.readPathEntry( "DocPath" );
  95. d->protClass = config.readEntry( "Class" ).lower();
  96. if (d->protClass[0] != ':')
  97. d->protClass.prepend(':');
  98. TQStringList extraNames = config.readListEntry( "ExtraNames" );
  99. TQStringList extraTypes = config.readListEntry( "ExtraTypes" );
  100. TQStringList::Iterator it = extraNames.begin();
  101. TQStringList::Iterator typeit = extraTypes.begin();
  102. for( ; it != extraNames.end() && typeit != extraTypes.end(); ++it, ++typeit ) {
  103. d->extraFields.append( ExtraField( *it, *typeit ) );
  104. }
  105. d->showPreviews = config.readBoolEntry( "ShowPreviews", d->protClass == ":local" );
  106. tmp = config.readEntry( "URIMode", TQString::null ).lower();
  107. if (tmp == "rawuri")
  108. d->uriMode = KURL::RawURI;
  109. else if (tmp == "mailto")
  110. d->uriMode = KURL::Mailto;
  111. else if (tmp == "url")
  112. d->uriMode = KURL::URL;
  113. else
  114. d->uriMode = KURL::Auto;
  115. d->capabilities = config.readListEntry( "Capabilities" );
  116. d->proxyProtocol = config.readEntry( "ProxiedBy" );
  117. }
  118. KProtocolInfo::KProtocolInfo( TQDataStream& _str, int offset) :
  119. KSycocaEntry( _str, offset)
  120. {
  121. d = new KProtocolInfoPrivate;
  122. load( _str );
  123. }
  124. KProtocolInfo::~KProtocolInfo()
  125. {
  126. delete d;
  127. }
  128. void
  129. KProtocolInfo::load( TQDataStream& _str)
  130. {
  131. // You may add new fields at the end. Make sure to update the version
  132. // number in tdesycoca.h
  133. TQ_INT32 i_inputType, i_outputType;
  134. TQ_INT8 i_isSourceProtocol, i_isHelperProtocol,
  135. i_supportsListing, i_supportsReading,
  136. i_supportsWriting, i_supportsMakeDir,
  137. i_supportsDeleting, i_supportsLinking,
  138. i_supportsMoving, i_determineMimetypeFromExtension,
  139. i_canCopyFromFile, i_canCopyToFile, i_showPreviews,
  140. i_uriMode, i_canRenameFromFile, i_canRenameToFile,
  141. i_canDeleteRecursive, i_fileNameUsedForCopying;
  142. _str >> m_name >> m_exec >> m_listing >> m_defaultMimetype
  143. >> i_determineMimetypeFromExtension
  144. >> m_icon
  145. >> i_inputType >> i_outputType
  146. >> i_isSourceProtocol >> i_isHelperProtocol
  147. >> i_supportsListing >> i_supportsReading
  148. >> i_supportsWriting >> i_supportsMakeDir
  149. >> i_supportsDeleting >> i_supportsLinking
  150. >> i_supportsMoving
  151. >> i_canCopyFromFile >> i_canCopyToFile
  152. >> m_config >> m_maxSlaves >> d->docPath >> d->protClass
  153. >> d->extraFields >> i_showPreviews >> i_uriMode
  154. >> d->capabilities >> d->proxyProtocol
  155. >> i_canRenameFromFile >> i_canRenameToFile
  156. >> i_canDeleteRecursive >> i_fileNameUsedForCopying;
  157. m_inputType = (Type) i_inputType;
  158. m_outputType = (Type) i_outputType;
  159. m_isSourceProtocol = (i_isSourceProtocol != 0);
  160. m_isHelperProtocol = (i_isHelperProtocol != 0);
  161. m_supportsListing = (i_supportsListing != 0);
  162. m_supportsReading = (i_supportsReading != 0);
  163. m_supportsWriting = (i_supportsWriting != 0);
  164. m_supportsMakeDir = (i_supportsMakeDir != 0);
  165. m_supportsDeleting = (i_supportsDeleting != 0);
  166. m_supportsLinking = (i_supportsLinking != 0);
  167. m_supportsMoving = (i_supportsMoving != 0);
  168. m_canCopyFromFile = (i_canCopyFromFile != 0);
  169. m_canCopyToFile = (i_canCopyToFile != 0);
  170. d->canRenameFromFile = (i_canRenameFromFile != 0);
  171. d->canRenameToFile = (i_canRenameToFile != 0);
  172. d->canDeleteRecursive = (i_canDeleteRecursive != 0);
  173. d->fileNameUsedForCopying = (i_fileNameUsedForCopying != 0);
  174. m_determineMimetypeFromExtension = (i_determineMimetypeFromExtension != 0);
  175. d->showPreviews = (i_showPreviews != 0);
  176. d->uriMode = (KURL::URIMode) i_uriMode;
  177. }
  178. void
  179. KProtocolInfo::save( TQDataStream& _str)
  180. {
  181. KSycocaEntry::save( _str );
  182. // You may add new fields at the end. Make sure to update the version
  183. // number in tdesycoca.h
  184. TQ_INT32 i_inputType, i_outputType;
  185. TQ_INT8 i_isSourceProtocol, i_isHelperProtocol,
  186. i_supportsListing, i_supportsReading,
  187. i_supportsWriting, i_supportsMakeDir,
  188. i_supportsDeleting, i_supportsLinking,
  189. i_supportsMoving, i_determineMimetypeFromExtension,
  190. i_canCopyFromFile, i_canCopyToFile, i_showPreviews,
  191. i_uriMode, i_canRenameFromFile, i_canRenameToFile,
  192. i_canDeleteRecursive, i_fileNameUsedForCopying;
  193. i_inputType = (TQ_INT32) m_inputType;
  194. i_outputType = (TQ_INT32) m_outputType;
  195. i_isSourceProtocol = m_isSourceProtocol ? 1 : 0;
  196. i_isHelperProtocol = m_isHelperProtocol ? 1 : 0;
  197. i_supportsListing = m_supportsListing ? 1 : 0;
  198. i_supportsReading = m_supportsReading ? 1 : 0;
  199. i_supportsWriting = m_supportsWriting ? 1 : 0;
  200. i_supportsMakeDir = m_supportsMakeDir ? 1 : 0;
  201. i_supportsDeleting = m_supportsDeleting ? 1 : 0;
  202. i_supportsLinking = m_supportsLinking ? 1 : 0;
  203. i_supportsMoving = m_supportsMoving ? 1 : 0;
  204. i_canCopyFromFile = m_canCopyFromFile ? 1 : 0;
  205. i_canCopyToFile = m_canCopyToFile ? 1 : 0;
  206. i_canRenameFromFile = d->canRenameFromFile ? 1 : 0;
  207. i_canRenameToFile = d->canRenameToFile ? 1 : 0;
  208. i_canDeleteRecursive = d->canDeleteRecursive ? 1 : 0;
  209. i_fileNameUsedForCopying = d->fileNameUsedForCopying ? 1 : 0;
  210. i_determineMimetypeFromExtension = m_determineMimetypeFromExtension ? 1 : 0;
  211. i_showPreviews = d->showPreviews ? 1 : 0;
  212. i_uriMode = d->uriMode;
  213. _str << m_name << m_exec << m_listing << m_defaultMimetype
  214. << i_determineMimetypeFromExtension
  215. << m_icon
  216. << i_inputType << i_outputType
  217. << i_isSourceProtocol << i_isHelperProtocol
  218. << i_supportsListing << i_supportsReading
  219. << i_supportsWriting << i_supportsMakeDir
  220. << i_supportsDeleting << i_supportsLinking
  221. << i_supportsMoving
  222. << i_canCopyFromFile << i_canCopyToFile
  223. << m_config << m_maxSlaves << d->docPath << d->protClass
  224. << d->extraFields << i_showPreviews << i_uriMode
  225. << d->capabilities << d->proxyProtocol
  226. << i_canRenameFromFile << i_canRenameToFile
  227. << i_canDeleteRecursive << i_fileNameUsedForCopying;
  228. }
  229. //
  230. // Static functions:
  231. //
  232. TQStringList KProtocolInfo::protocols()
  233. {
  234. return KProtocolInfoFactory::self()->protocols();
  235. }
  236. bool KProtocolInfo::isSourceProtocol( const TQString& _protocol )
  237. {
  238. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  239. if ( !prot )
  240. return false;
  241. return prot->m_isSourceProtocol;
  242. }
  243. bool KProtocolInfo::isFilterProtocol( const TQString& _protocol )
  244. {
  245. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  246. if ( !prot )
  247. return false;
  248. return !prot->m_isSourceProtocol;
  249. }
  250. bool KProtocolInfo::isHelperProtocol( const TQString& _protocol )
  251. {
  252. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  253. if ( !prot )
  254. return false;
  255. return prot->m_isHelperProtocol;
  256. }
  257. bool KProtocolInfo::isKnownProtocol( const TQString& _protocol )
  258. {
  259. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  260. return ( prot != 0);
  261. }
  262. bool KProtocolInfo::supportsListing( const TQString& _protocol )
  263. {
  264. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  265. if ( !prot )
  266. return false;
  267. return prot->m_supportsListing;
  268. }
  269. TQStringList KProtocolInfo::listing( const TQString& _protocol )
  270. {
  271. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  272. if ( !prot )
  273. return TQStringList();
  274. return prot->m_listing;
  275. }
  276. bool KProtocolInfo::supportsReading( const TQString& _protocol )
  277. {
  278. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  279. if ( !prot )
  280. return false;
  281. return prot->m_supportsReading;
  282. }
  283. bool KProtocolInfo::supportsWriting( const TQString& _protocol )
  284. {
  285. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  286. if ( !prot )
  287. return false;
  288. return prot->m_supportsWriting;
  289. }
  290. bool KProtocolInfo::supportsMakeDir( const TQString& _protocol )
  291. {
  292. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  293. if ( !prot )
  294. return false;
  295. return prot->m_supportsMakeDir;
  296. }
  297. bool KProtocolInfo::supportsDeleting( const TQString& _protocol )
  298. {
  299. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  300. if ( !prot )
  301. return false;
  302. return prot->m_supportsDeleting;
  303. }
  304. bool KProtocolInfo::supportsLinking( const TQString& _protocol )
  305. {
  306. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  307. if ( !prot )
  308. return false;
  309. return prot->m_supportsLinking;
  310. }
  311. bool KProtocolInfo::supportsMoving( const TQString& _protocol )
  312. {
  313. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  314. if ( !prot )
  315. return false;
  316. return prot->m_supportsMoving;
  317. }
  318. bool KProtocolInfo::canCopyFromFile( const TQString& _protocol )
  319. {
  320. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  321. if ( !prot )
  322. return false;
  323. return prot->m_canCopyFromFile;
  324. }
  325. bool KProtocolInfo::canCopyToFile( const TQString& _protocol )
  326. {
  327. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  328. if ( !prot )
  329. return false;
  330. return prot->m_canCopyToFile;
  331. }
  332. TQString KProtocolInfo::icon( const TQString& _protocol )
  333. {
  334. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  335. if ( !prot )
  336. return TQString::fromLatin1("unknown");
  337. return prot->m_icon;
  338. }
  339. TQString KProtocolInfo::config( const TQString& _protocol )
  340. {
  341. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  342. if ( !prot )
  343. return TQString::null;
  344. return TQString("tdeio_%1rc").arg(prot->m_config);
  345. }
  346. int KProtocolInfo::maxSlaves( const TQString& _protocol )
  347. {
  348. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  349. if ( !prot )
  350. return 1;
  351. return prot->m_maxSlaves;
  352. }
  353. TQString KProtocolInfo::defaultMimetype( const TQString& _protocol )
  354. {
  355. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  356. if ( !prot )
  357. return TQString::null;
  358. return prot->m_defaultMimetype;
  359. }
  360. bool KProtocolInfo::determineMimetypeFromExtension( const TQString &_protocol )
  361. {
  362. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol( _protocol );
  363. if ( !prot )
  364. return true;
  365. return prot->m_determineMimetypeFromExtension;
  366. }
  367. TQString KProtocolInfo::exec( const TQString& _protocol )
  368. {
  369. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  370. if ( !prot )
  371. return TQString::null;
  372. return prot->m_exec;
  373. }
  374. KProtocolInfo::Type KProtocolInfo::inputType( const TQString& _protocol )
  375. {
  376. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  377. if ( !prot )
  378. return T_NONE;
  379. return prot->m_inputType;
  380. }
  381. KProtocolInfo::Type KProtocolInfo::outputType( const TQString& _protocol )
  382. {
  383. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  384. if ( !prot )
  385. return T_NONE;
  386. return prot->m_outputType;
  387. }
  388. KProtocolInfo::ExtraFieldList KProtocolInfo::extraFields( const KURL &url )
  389. {
  390. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(url.protocol());
  391. if ( !prot )
  392. return ExtraFieldList();
  393. return prot->d->extraFields;
  394. }
  395. TQString KProtocolInfo::docPath( const TQString& _protocol )
  396. {
  397. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  398. if ( !prot )
  399. return TQString::null;
  400. return prot->d->docPath;
  401. }
  402. TQString KProtocolInfo::protocolClass( const TQString& _protocol )
  403. {
  404. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  405. if ( !prot )
  406. return TQString::null;
  407. return prot->d->protClass;
  408. }
  409. bool KProtocolInfo::showFilePreview( const TQString& _protocol )
  410. {
  411. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  412. if ( !prot )
  413. return false;
  414. return prot->d->showPreviews;
  415. }
  416. KURL::URIMode KProtocolInfo::uriParseMode( const TQString& _protocol )
  417. {
  418. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  419. if ( !prot )
  420. return KURL::Auto;
  421. return prot->d->uriMode;
  422. }
  423. TQStringList KProtocolInfo::capabilities( const TQString& _protocol )
  424. {
  425. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  426. if ( !prot )
  427. return TQStringList();
  428. return prot->d->capabilities;
  429. }
  430. TQString KProtocolInfo::proxiedBy( const TQString& _protocol )
  431. {
  432. KProtocolInfo::Ptr prot = KProtocolInfoFactory::self()->findProtocol(_protocol);
  433. if ( !prot )
  434. return TQString::null;
  435. return prot->d->proxyProtocol;
  436. }
  437. bool KProtocolInfo::canRenameFromFile() const
  438. {
  439. return d->canRenameFromFile;
  440. }
  441. bool KProtocolInfo::canRenameToFile() const
  442. {
  443. return d->canRenameToFile;
  444. }
  445. bool KProtocolInfo::canDeleteRecursive() const
  446. {
  447. return d->canDeleteRecursive;
  448. }
  449. KProtocolInfo::FileNameUsedForCopying KProtocolInfo::fileNameUsedForCopying() const
  450. {
  451. return d->fileNameUsedForCopying ? Name : FromURL;
  452. }
  453. TQDataStream& operator>>( TQDataStream& s, KProtocolInfo::ExtraField& field ) {
  454. s >> field.name;
  455. s >> field.type;
  456. return s;
  457. }
  458. TQDataStream& operator<<( TQDataStream& s, const KProtocolInfo::ExtraField& field ) {
  459. s << field.name;
  460. s << field.type;
  461. return s;
  462. }
  463. // KURL based static functions are implemented in ../tdeio/tdeio/kprotocolinfo.cpp
  464. void KProtocolInfo::virtual_hook( int id, void* data )
  465. { KSycocaEntry::virtual_hook( id, data ); }