19 #ifdef MAKE_TDECORE_LIB
21 #define TDEIO_EXPORT TDE_EXPORT
24 #define KPROTOCOLINFO_TDECORE
25 #include "kprotocolinfo.h"
26 #include "kprotocolinfofactory.h"
28 #include <kstandarddirs.h>
29 #include <tdeglobal.h>
30 #include <tdeapplication.h>
32 #include <ksimpleconfig.h>
33 #include <tdeconfig.h>
34 #include <kstringhandler.h>
36 class KProtocolInfo::KProtocolInfoPrivate
41 KProtocolInfo::ExtraFieldList extraFields;
43 bool canRenameFromFile;
45 bool canDeleteRecursive;
46 bool fileNameUsedForCopying;
48 TQStringList capabilities;
49 TQString proxyProtocol;
55 KProtocolInfo::KProtocolInfo(
const TQString &path)
58 d =
new KProtocolInfoPrivate;
59 TQString fullPath =
locate(
"services", path);
62 config.setGroup(
"Protocol" );
64 m_name = config.readEntry(
"protocol" );
65 m_exec = config.readPathEntry(
"exec" );
66 m_isSourceProtocol = config.readBoolEntry(
"source",
true );
67 m_isHelperProtocol = config.readBoolEntry(
"helper",
false );
68 m_supportsReading = config.readBoolEntry(
"reading",
false );
69 m_supportsWriting = config.readBoolEntry(
"writing",
false );
70 m_supportsMakeDir = config.readBoolEntry(
"makedir",
false );
71 m_supportsDeleting = config.readBoolEntry(
"deleting",
false );
72 m_supportsLinking = config.readBoolEntry(
"linking",
false );
73 m_supportsMoving = config.readBoolEntry(
"moving",
false );
74 m_canCopyFromFile = config.readBoolEntry(
"copyFromFile",
false );
75 m_canCopyToFile = config.readBoolEntry(
"copyToFile",
false );
76 d->canRenameFromFile = config.readBoolEntry(
"renameFromFile",
false );
77 d->canRenameToFile = config.readBoolEntry(
"renameToFile",
false );
78 d->canDeleteRecursive = config.readBoolEntry(
"deleteRecursive",
false );
79 d->fileNameUsedForCopying = config.readEntry(
"fileNameUsedForCopying",
"FromURL" ) ==
"Name";
81 m_listing = config.readListEntry(
"listing" );
83 if ( m_listing.count() == 1 && m_listing.first() ==
"false" )
85 m_supportsListing = ( m_listing.count() > 0 );
86 m_defaultMimetype = config.readEntry(
"defaultMimetype" );
87 m_determineMimetypeFromExtension = config.readBoolEntry(
"determineMimetypeFromExtension",
true );
88 m_icon = config.readEntry(
"Icon",
"unknown" );
89 m_config = config.readEntry(
"config", m_name );
90 m_maxSlaves = config.readNumEntry(
"maxInstances", 1);
92 TQString tmp = config.readEntry(
"input" );
93 if ( tmp ==
"filesystem" )
94 m_inputType = KProtocolInfo::T_FILESYSTEM;
95 else if ( tmp ==
"stream" )
96 m_inputType = KProtocolInfo::T_STREAM;
98 m_inputType = KProtocolInfo::T_NONE;
100 tmp = config.readEntry(
"output" );
101 if ( tmp ==
"filesystem" )
102 m_outputType = KProtocolInfo::T_FILESYSTEM;
103 else if ( tmp ==
"stream" )
104 m_outputType = KProtocolInfo::T_STREAM;
106 m_outputType = KProtocolInfo::T_NONE;
108 d->docPath = config.readPathEntry(
"X-DocPath" );
109 d->protClass = config.readEntry(
"Class" ).lower();
110 if (d->protClass[0] !=
':')
111 d->protClass.prepend(
':');
113 TQStringList extraNames = config.readListEntry(
"ExtraNames" );
114 TQStringList extraTypes = config.readListEntry(
"ExtraTypes" );
115 TQStringList::Iterator it = extraNames.begin();
116 TQStringList::Iterator typeit = extraTypes.begin();
117 for( ; it != extraNames.end() && typeit != extraTypes.end(); ++it, ++typeit ) {
118 d->extraFields.append( ExtraField( *it, *typeit ) );
121 d->showPreviews = config.readBoolEntry(
"ShowPreviews", d->protClass ==
":local" );
123 tmp = config.readEntry(
"URIMode", TQString::null ).lower();
126 else if (tmp ==
"mailto")
128 else if (tmp ==
"url")
133 d->capabilities = config.readListEntry(
"Capabilities" );
134 d->proxyProtocol = config.readEntry(
"ProxiedBy" );
137 KProtocolInfo::KProtocolInfo( TQDataStream& _str,
int offset) :
140 d =
new KProtocolInfoPrivate;
144 KProtocolInfo::~KProtocolInfo()
150 KProtocolInfo::load( TQDataStream& _str)
154 TQ_INT32 i_inputType, i_outputType;
155 TQ_INT8 i_isSourceProtocol, i_isHelperProtocol,
156 i_supportsListing, i_supportsReading,
157 i_supportsWriting, i_supportsMakeDir,
158 i_supportsDeleting, i_supportsLinking,
159 i_supportsMoving, i_determineMimetypeFromExtension,
160 i_canCopyFromFile, i_canCopyToFile, i_showPreviews,
161 i_uriMode, i_canRenameFromFile, i_canRenameToFile,
162 i_canDeleteRecursive, i_fileNameUsedForCopying;
164 _str >> m_name >> m_exec >> m_listing >> m_defaultMimetype
165 >> i_determineMimetypeFromExtension
167 >> i_inputType >> i_outputType
168 >> i_isSourceProtocol >> i_isHelperProtocol
169 >> i_supportsListing >> i_supportsReading
170 >> i_supportsWriting >> i_supportsMakeDir
171 >> i_supportsDeleting >> i_supportsLinking
173 >> i_canCopyFromFile >> i_canCopyToFile
174 >> m_config >> m_maxSlaves >> d->docPath >> d->protClass
175 >> d->extraFields >> i_showPreviews >> i_uriMode
176 >> d->capabilities >> d->proxyProtocol
177 >> i_canRenameFromFile >> i_canRenameToFile
178 >> i_canDeleteRecursive >> i_fileNameUsedForCopying;
180 m_inputType = (Type) i_inputType;
181 m_outputType = (Type) i_outputType;
182 m_isSourceProtocol = (i_isSourceProtocol != 0);
183 m_isHelperProtocol = (i_isHelperProtocol != 0);
184 m_supportsListing = (i_supportsListing != 0);
185 m_supportsReading = (i_supportsReading != 0);
186 m_supportsWriting = (i_supportsWriting != 0);
187 m_supportsMakeDir = (i_supportsMakeDir != 0);
188 m_supportsDeleting = (i_supportsDeleting != 0);
189 m_supportsLinking = (i_supportsLinking != 0);
190 m_supportsMoving = (i_supportsMoving != 0);
191 m_canCopyFromFile = (i_canCopyFromFile != 0);
192 m_canCopyToFile = (i_canCopyToFile != 0);
193 d->canRenameFromFile = (i_canRenameFromFile != 0);
194 d->canRenameToFile = (i_canRenameToFile != 0);
195 d->canDeleteRecursive = (i_canDeleteRecursive != 0);
196 d->fileNameUsedForCopying = (i_fileNameUsedForCopying != 0);
197 m_determineMimetypeFromExtension = (i_determineMimetypeFromExtension != 0);
198 d->showPreviews = (i_showPreviews != 0);
203 KProtocolInfo::save( TQDataStream& _str)
205 KSycocaEntry::save( _str );
209 TQ_INT32 i_inputType, i_outputType;
210 TQ_INT8 i_isSourceProtocol, i_isHelperProtocol,
211 i_supportsListing, i_supportsReading,
212 i_supportsWriting, i_supportsMakeDir,
213 i_supportsDeleting, i_supportsLinking,
214 i_supportsMoving, i_determineMimetypeFromExtension,
215 i_canCopyFromFile, i_canCopyToFile, i_showPreviews,
216 i_uriMode, i_canRenameFromFile, i_canRenameToFile,
217 i_canDeleteRecursive, i_fileNameUsedForCopying;
219 i_inputType = (TQ_INT32) m_inputType;
220 i_outputType = (TQ_INT32) m_outputType;
221 i_isSourceProtocol = m_isSourceProtocol ? 1 : 0;
222 i_isHelperProtocol = m_isHelperProtocol ? 1 : 0;
223 i_supportsListing = m_supportsListing ? 1 : 0;
224 i_supportsReading = m_supportsReading ? 1 : 0;
225 i_supportsWriting = m_supportsWriting ? 1 : 0;
226 i_supportsMakeDir = m_supportsMakeDir ? 1 : 0;
227 i_supportsDeleting = m_supportsDeleting ? 1 : 0;
228 i_supportsLinking = m_supportsLinking ? 1 : 0;
229 i_supportsMoving = m_supportsMoving ? 1 : 0;
230 i_canCopyFromFile = m_canCopyFromFile ? 1 : 0;
231 i_canCopyToFile = m_canCopyToFile ? 1 : 0;
232 i_canRenameFromFile = d->canRenameFromFile ? 1 : 0;
233 i_canRenameToFile = d->canRenameToFile ? 1 : 0;
234 i_canDeleteRecursive = d->canDeleteRecursive ? 1 : 0;
235 i_fileNameUsedForCopying = d->fileNameUsedForCopying ? 1 : 0;
236 i_determineMimetypeFromExtension = m_determineMimetypeFromExtension ? 1 : 0;
237 i_showPreviews = d->showPreviews ? 1 : 0;
238 i_uriMode = d->uriMode;
240 _str << m_name << m_exec << m_listing << m_defaultMimetype
241 << i_determineMimetypeFromExtension
243 << i_inputType << i_outputType
244 << i_isSourceProtocol << i_isHelperProtocol
245 << i_supportsListing << i_supportsReading
246 << i_supportsWriting << i_supportsMakeDir
247 << i_supportsDeleting << i_supportsLinking
249 << i_canCopyFromFile << i_canCopyToFile
250 << m_config << m_maxSlaves << d->docPath << d->protClass
251 << d->extraFields << i_showPreviews << i_uriMode
252 << d->capabilities << d->proxyProtocol
253 << i_canRenameFromFile << i_canRenameToFile
254 << i_canDeleteRecursive << i_fileNameUsedForCopying;
262 TQStringList KProtocolInfo::protocols()
267 bool KProtocolInfo::isSourceProtocol(
const TQString& _protocol )
273 return prot->m_isSourceProtocol;
276 bool KProtocolInfo::isFilterProtocol(
const TQString& _protocol )
282 return !prot->m_isSourceProtocol;
285 bool KProtocolInfo::isHelperProtocol(
const TQString& _protocol )
291 return prot->m_isHelperProtocol;
294 bool KProtocolInfo::isKnownProtocol(
const TQString& _protocol )
300 bool KProtocolInfo::supportsListing(
const TQString& _protocol )
306 return prot->m_supportsListing;
309 TQStringList KProtocolInfo::listing(
const TQString& _protocol )
313 return TQStringList();
315 return prot->m_listing;
318 bool KProtocolInfo::supportsReading(
const TQString& _protocol )
324 return prot->m_supportsReading;
327 bool KProtocolInfo::supportsWriting(
const TQString& _protocol )
333 return prot->m_supportsWriting;
336 bool KProtocolInfo::supportsMakeDir(
const TQString& _protocol )
342 return prot->m_supportsMakeDir;
345 bool KProtocolInfo::supportsDeleting(
const TQString& _protocol )
351 return prot->m_supportsDeleting;
354 bool KProtocolInfo::supportsLinking(
const TQString& _protocol )
360 return prot->m_supportsLinking;
363 bool KProtocolInfo::supportsMoving(
const TQString& _protocol )
369 return prot->m_supportsMoving;
372 bool KProtocolInfo::canCopyFromFile(
const TQString& _protocol )
378 return prot->m_canCopyFromFile;
382 bool KProtocolInfo::canCopyToFile(
const TQString& _protocol )
388 return prot->m_canCopyToFile;
391 TQString KProtocolInfo::icon(
const TQString& _protocol )
395 return TQString::fromLatin1(
"unknown");
400 TQString KProtocolInfo::config(
const TQString& _protocol )
404 return TQString::null;
406 return TQString(
"tdeio_%1rc").arg(prot->m_config);
409 int KProtocolInfo::maxSlaves(
const TQString& _protocol )
415 return prot->m_maxSlaves;
418 TQString KProtocolInfo::defaultMimetype(
const TQString& _protocol )
422 return TQString::null;
424 return prot->m_defaultMimetype;
427 bool KProtocolInfo::determineMimetypeFromExtension(
const TQString &_protocol )
433 return prot->m_determineMimetypeFromExtension;
436 TQString KProtocolInfo::exec(
const TQString& _protocol )
440 return TQString::null;
445 KProtocolInfo::Type KProtocolInfo::inputType(
const TQString& _protocol )
451 return prot->m_inputType;
454 KProtocolInfo::Type KProtocolInfo::outputType(
const TQString& _protocol )
460 return prot->m_outputType;
463 KProtocolInfo::ExtraFieldList KProtocolInfo::extraFields(
const KURL &url )
467 return ExtraFieldList();
469 return prot->d->extraFields;
472 TQString KProtocolInfo::docPath(
const TQString& _protocol )
476 return TQString::null;
478 return prot->d->docPath;
481 TQString KProtocolInfo::protocolClass(
const TQString& _protocol )
485 return TQString::null;
487 return prot->d->protClass;
490 bool KProtocolInfo::showFilePreview(
const TQString& _protocol )
496 return prot->d->showPreviews;
499 KURL::URIMode KProtocolInfo::uriParseMode(
const TQString& _protocol )
505 return prot->d->uriMode;
508 TQStringList KProtocolInfo::capabilities(
const TQString& _protocol )
512 return TQStringList();
514 return prot->d->capabilities;
517 TQString KProtocolInfo::proxiedBy(
const TQString& _protocol )
521 return TQString::null;
523 return prot->d->proxyProtocol;
526 bool KProtocolInfo::canRenameFromFile()
const
528 return d->canRenameFromFile;
531 bool KProtocolInfo::canRenameToFile()
const
533 return d->canRenameToFile;
536 bool KProtocolInfo::canDeleteRecursive()
const
538 return d->canDeleteRecursive;
541 KProtocolInfo::FileNameUsedForCopying KProtocolInfo::fileNameUsedForCopying()
const
543 return d->fileNameUsedForCopying ? Name : FromURL;
546 TQDataStream& operator>>( TQDataStream& s, KProtocolInfo::ExtraField& field ) {
552 TQDataStream& operator<<( TQDataStream& s,
const KProtocolInfo::ExtraField& field ) {
560 void KProtocolInfo::virtual_hook(
int id,
void* data )
561 { KSycocaEntry::virtual_hook(
id, data ); }
TQStringList protocols()
Returns list of all known protocols.
static KProtocolInfoFactory * self()
The instance of the KProtocolInfoFactory.
KDE Configuration entries.
Base class for all Sycoca entries.
Represents and parses a URL.
TQString protocol() const
Returns the protocol for the URL.
URIMode
Defines the type of URI we are processing.
@ URL
Standards compliant URL.
@ Auto
Automatically detected.
TQString locate(const char *type, const TQString &filename, const TDEInstance *instance=TDEGlobal::instance())