21 #include "tdesycoca.h"
22 #include "kservicetype.h"
23 #include "kservicetypefactory.h"
24 #include "kservicefactory.h"
25 #include "kuserprofile.h"
28 #include <kdesktopfile.h>
30 template TQDataStream&
operator>> <TQString, TQVariant>(TQDataStream&, TQMap<TQString, TQVariant>&);
31 template TQDataStream& operator<< <TQString, TQVariant>(TQDataStream&,
const TQMap<TQString, TQVariant>&);
33 class KServiceType::KServiceTypePrivate
36 KServiceTypePrivate() : parentTypeLoaded(false) { }
38 KServiceType::Ptr parentType;
39 KService::List services;
40 bool parentTypeLoaded;
44 : KSycocaEntry(_fullpath), d(0)
46 KDesktopFile config( _fullpath );
52 : KSycocaEntry(config->fileName()), d(0)
58 KServiceType::init( KDesktopFile *config)
61 m_strName = config->readEntry(
"MimeType" );
64 if ( m_strName.isEmpty() )
66 m_strName = config->readEntry(
"X-TDE-ServiceType" );
69 m_strComment = config->readComment();
70 m_bDeleted = config->readBoolEntry(
"Hidden",
false );
71 m_strIcon = config->readIcon();
75 TQString sDerived = config->readEntry(
"X-TDE-Derived" );
76 m_bDerived = !sDerived.isEmpty();
78 m_mapProps.insert(
"X-TDE-Derived", sDerived );
80 TQStringList tmpList = config->groupList();
81 TQStringList::Iterator gIt = tmpList.begin();
83 for( ; gIt != tmpList.end(); ++gIt )
85 if ( (*gIt).find(
"Property::" ) == 0 )
87 config->setGroup( *gIt );
88 TQVariant v = config->readPropertyEntry(
"Value",
89 TQVariant::nameToType( config->readEntry(
"Type" ).ascii() ) );
91 m_mapProps.insert( (*gIt).mid( 10 ), v );
95 gIt = tmpList.begin();
96 for( ; gIt != tmpList.end(); ++gIt )
98 if( (*gIt).find(
"PropertyDef::" ) == 0 )
100 config->setGroup( *gIt );
101 m_mapPropDefs.insert( (*gIt).mid( 13 ),
102 TQVariant::nameToType( config->readEntry(
"Type" ).ascii() ) );
106 m_bValid = !m_strName.isEmpty();
110 const TQString& _icon,
const TQString& _comment )
111 : KSycocaEntry(_fullpath), d(0)
115 m_strComment = _comment;
116 m_bValid = !m_strName.isEmpty();
120 : KSycocaEntry( _str, offset ), d(0)
126 KServiceType::load( TQDataStream& _str )
129 _str >> m_strName >> m_strIcon >> m_strComment >> m_mapProps >> m_mapPropDefs
132 m_bDerived = m_mapProps.contains(
"X-TDE-Derived");
136 KServiceType::save( TQDataStream& _str )
138 KSycocaEntry::save( _str );
142 _str << m_strName << m_strIcon << m_strComment << m_mapProps << m_mapPropDefs
143 << (TQ_INT8)m_bValid;
146 KServiceType::~KServiceType()
153 TQVariant v =
property(
"X-TDE-Derived");
159 if (
name() == servTypeName )
162 while ( !st.isEmpty() )
165 if (!ptr)
return false;
166 if ( ptr->name() == servTypeName )
168 st = ptr->parentServiceType();
178 if ( _name ==
"Name" )
179 v = TQVariant( m_strName );
180 else if ( _name ==
"Icon" )
181 v = TQVariant( m_strIcon );
182 else if ( _name ==
"Comment" )
183 v = TQVariant( m_strComment );
185 TQMap<TQString,TQVariant>::ConstIterator it = m_mapProps.find( _name );
186 if ( it != m_mapProps.end() )
198 TQMap<TQString,TQVariant>::ConstIterator it = m_mapProps.begin();
199 for( ; it != m_mapProps.end(); ++it )
200 res.append( it.key() );
202 res.append(
"Name" );
203 res.append(
"Comment" );
204 res.append(
"Icon" );
212 TQMap<TQString,TQVariant::Type>::ConstIterator it = m_mapPropDefs.find( _name );
213 if ( it == m_mapPropDefs.end() )
214 return TQVariant::Invalid;
219 KServiceType::propertyDefNames()
const
223 TQMap<TQString,TQVariant::Type>::ConstIterator it = m_mapPropDefs.begin();
224 for( ; it != m_mapPropDefs.end(); ++it )
225 l.append( it.key() );
232 KServiceType * p = KServiceTypeFactory::self()->findServiceTypeByName( _name );
233 return KServiceType::Ptr( p );
236 static void addUnique(KService::List &lst, TQDict<KService> &dict,
const KService::List &newLst,
bool lowPrio)
238 TQValueListConstIterator<KService::Ptr> it = newLst.begin();
239 for( ; it != newLst.end(); ++it )
247 service->setInitialPreference( 0 );
253 TQDict<KService> dict(53);
257 KServiceType::Ptr serv = KServiceTypeFactory::self()->findServiceTypeByName( _servicetype );
259 addUnique(lst, dict, KServiceFactory::self()->
offers( serv->offset() ),
false);
261 kdWarning(7009) <<
"KServiceType::offers : servicetype " << _servicetype <<
" not found" << endl;
265 bool isAMimeType = (mime != 0);
271 if (parent.isEmpty())
273 mime =
dynamic_cast<KMimeType *
>(KServiceTypeFactory::self()->findServiceTypeByName( parent ));
277 addUnique(lst, dict, KServiceFactory::self()->
offers( mime->offset() ),
false);
289 if ( !KServiceTypeProfile::configurationMode()
291 && _servicetype.left(4) !=
"all/" )
294 KServiceType * servAll = KServiceTypeFactory::self()->findServiceTypeByName(
"all/all" );
297 addUnique(lst, dict, KServiceFactory::self()->
offers( servAll->offset() ),
true);
300 kdWarning(7009) <<
"KServiceType::offers : servicetype all/all not found" << endl;
304 if ( _servicetype !=
"inode/directory" && _servicetype !=
"inode/directory-locked" )
306 KServiceType * servAllFiles = KServiceTypeFactory::self()->findServiceTypeByName(
"all/allfiles" );
309 addUnique(lst, dict, KServiceFactory::self()->
offers( servAllFiles->offset() ),
true);
312 kdWarning(7009) <<
"KServiceType::offers : servicetype all/allfiles not found" << endl;
322 return KServiceTypeFactory::self()->allServiceTypes();
325 KServiceType::Ptr KServiceType::parentType()
327 if (d && d->parentTypeLoaded)
328 return d->parentType;
331 d =
new KServiceTypePrivate;
334 if (!parentSt.isEmpty())
336 d->parentType = KServiceTypeFactory::self()->findServiceTypeByName( parentSt );
338 kdWarning(7009) <<
"'" <<
desktopEntryPath() <<
"' specifies undefined mimetype/servicetype '"<< parentSt <<
"'" << endl;
341 d->parentTypeLoaded =
true;
343 return d->parentType;
346 void KServiceType::addService(KService::Ptr service)
349 d =
new KServiceTypePrivate;
351 if (d->services.count() && d->services.last() == service)
354 d->services.append(service);
357 KService::List KServiceType::services()
362 return KService::List();
365 void KServiceType::virtual_hook(
int id,
void* data )
366 { KSycocaEntry::virtual_hook(
id, data ); }
static List allServiceTypes()
Returns a list of all the supported servicetypes.
Represent a service, i.e.
Represent a mime type, like "text/plain", and the data that is associated with it.
TQString parentMimeType() const
If this mimetype inherits from ("is also") another mimetype, return the name of the parent...
TQString name() const
Returns the name of this service type.
A service type is the generic notion for a mimetype, a type of service instead of a type of file...
TQString parentServiceType() const
If this service type inherits from another service type, return the name of the parent.
static KService::List offers(const TQString &_servicetype)
Returns all services supporting the given servicetype name.
virtual TQStringList propertyNames() const
Returns the list of all properties of this service type.
TQString desktopEntryPath() const
Returns the path to the location where the service desktop entry is stored.
static Ptr serviceType(const TQString &_name)
Returns a pointer to the servicetype '_name' or 0L if the service type is unknown.
virtual TQVariant::Type propertyDef(const TQString &_name) const
Returns the type of the property with the given _name.
bool inherits(const TQString &servTypeName) const
Checks whether this service type is or inherits from servTypeName.
TQString desktopEntryPath() const
Returns the relative path to the desktop entry file responsible for this servicetype.
KServiceType(const TQString &_fullpath, const TQString &_name, const TQString &_icon, const TQString &_comment)
Constructor.
virtual TQVariant property(const TQString &_name) const
Returns the requested property.