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 class KServiceType::KServiceTypePrivate
33 KServiceTypePrivate() : parentTypeLoaded(false) { }
35 KServiceType::Ptr parentType;
36 KService::List services;
37 bool parentTypeLoaded;
41 : KSycocaEntry(_fullpath), d(0)
43 KDesktopFile config( _fullpath );
49 : KSycocaEntry(config->fileName()), d(0)
55 KServiceType::init( KDesktopFile *config)
58 m_strName = config->readEntry(
"MimeType" );
61 if ( m_strName.isEmpty() )
63 m_strName = config->readEntry(
"X-TDE-ServiceType" );
66 m_strComment = config->readComment();
67 m_bDeleted = config->readBoolEntry(
"Hidden",
false );
68 m_strIcon = config->readIcon();
72 TQString sDerived = config->readEntry(
"X-TDE-Derived" );
73 m_bDerived = !sDerived.isEmpty();
75 m_mapProps.insert(
"X-TDE-Derived", sDerived );
77 TQStringList tmpList = config->groupList();
78 TQStringList::Iterator gIt = tmpList.begin();
80 for( ; gIt != tmpList.end(); ++gIt )
82 if ( (*gIt).find(
"Property::" ) == 0 )
84 config->setGroup( *gIt );
85 TQVariant v = config->readPropertyEntry(
"Value",
86 TQVariant::nameToType( config->readEntry(
"Type" ).ascii() ) );
88 m_mapProps.insert( (*gIt).mid( 10 ), v );
92 gIt = tmpList.begin();
93 for( ; gIt != tmpList.end(); ++gIt )
95 if( (*gIt).find(
"PropertyDef::" ) == 0 )
97 config->setGroup( *gIt );
98 m_mapPropDefs.insert( (*gIt).mid( 13 ),
99 TQVariant::nameToType( config->readEntry(
"Type" ).ascii() ) );
103 m_bValid = !m_strName.isEmpty();
107 const TQString& _icon,
const TQString& _comment )
108 : KSycocaEntry(_fullpath), d(0)
112 m_strComment = _comment;
113 m_bValid = !m_strName.isEmpty();
117 : KSycocaEntry( _str, offset ), d(0)
123 KServiceType::load( TQDataStream& _str )
126 _str >> m_strName >> m_strIcon >> m_strComment >> m_mapProps >> m_mapPropDefs
129 m_bDerived = m_mapProps.contains(
"X-TDE-Derived");
133 KServiceType::save( TQDataStream& _str )
135 KSycocaEntry::save( _str );
139 _str << m_strName << m_strIcon << m_strComment << m_mapProps << m_mapPropDefs
140 << (TQ_INT8)m_bValid;
143 KServiceType::~KServiceType()
150 TQVariant v =
property(
"X-TDE-Derived");
156 if (
name() == servTypeName )
159 while ( !st.isEmpty() )
162 if (!ptr)
return false;
163 if ( ptr->name() == servTypeName )
165 st = ptr->parentServiceType();
175 if ( _name ==
"Name" )
176 v = TQVariant( m_strName );
177 else if ( _name ==
"Icon" )
178 v = TQVariant( m_strIcon );
179 else if ( _name ==
"Comment" )
180 v = TQVariant( m_strComment );
182 TQStringVariantMap::ConstIterator it = m_mapProps.find( _name );
183 if ( it != m_mapProps.end() )
195 TQStringVariantMap::ConstIterator it = m_mapProps.begin();
196 for( ; it != m_mapProps.end(); ++it )
197 res.append( it.key() );
199 res.append(
"Name" );
200 res.append(
"Comment" );
201 res.append(
"Icon" );
209 TQMap<TQString,TQVariant::Type>::ConstIterator it = m_mapPropDefs.find( _name );
210 if ( it == m_mapPropDefs.end() )
211 return TQVariant::Invalid;
216 KServiceType::propertyDefNames()
const
220 TQMap<TQString,TQVariant::Type>::ConstIterator it = m_mapPropDefs.begin();
221 for( ; it != m_mapPropDefs.end(); ++it )
222 l.append( it.key() );
229 KServiceType * p = KServiceTypeFactory::self()->findServiceTypeByName( _name );
230 return KServiceType::Ptr( p );
233 static void addUnique(KService::List &lst, TQDict<KService> &dict,
const KService::List &newLst,
bool lowPrio)
235 TQValueListConstIterator<KService::Ptr> it = newLst.begin();
236 for( ; it != newLst.end(); ++it )
244 service->setInitialPreference( 0 );
250 TQDict<KService> dict(53);
254 KServiceType::Ptr serv = KServiceTypeFactory::self()->findServiceTypeByName( _servicetype );
256 addUnique(lst, dict, KServiceFactory::self()->
offers( serv->offset() ),
false);
258 kdWarning(7009) <<
"KServiceType::offers : servicetype " << _servicetype <<
" not found" << endl;
262 bool isAMimeType = (mime != 0);
268 if (parent.isEmpty())
270 mime =
dynamic_cast<KMimeType *
>(KServiceTypeFactory::self()->findServiceTypeByName( parent ));
274 addUnique(lst, dict, KServiceFactory::self()->
offers( mime->offset() ),
false);
286 if ( !KServiceTypeProfile::configurationMode()
288 && _servicetype.left(4) !=
"all/" )
291 KServiceType * servAll = KServiceTypeFactory::self()->findServiceTypeByName(
"all/all" );
294 addUnique(lst, dict, KServiceFactory::self()->
offers( servAll->offset() ),
true);
297 kdWarning(7009) <<
"KServiceType::offers : servicetype all/all not found" << endl;
301 if ( _servicetype !=
"inode/directory" && _servicetype !=
"inode/directory-locked" )
303 KServiceType * servAllFiles = KServiceTypeFactory::self()->findServiceTypeByName(
"all/allfiles" );
306 addUnique(lst, dict, KServiceFactory::self()->
offers( servAllFiles->offset() ),
true);
309 kdWarning(7009) <<
"KServiceType::offers : servicetype all/allfiles not found" << endl;
319 return KServiceTypeFactory::self()->allServiceTypes();
322 KServiceType::Ptr KServiceType::parentType()
324 if (d && d->parentTypeLoaded)
325 return d->parentType;
328 d =
new KServiceTypePrivate;
331 if (!parentSt.isEmpty())
333 d->parentType = KServiceTypeFactory::self()->findServiceTypeByName( parentSt );
335 kdWarning(7009) <<
"'" <<
desktopEntryPath() <<
"' specifies undefined mimetype/servicetype '"<< parentSt <<
"'" << endl;
338 d->parentTypeLoaded =
true;
340 return d->parentType;
343 void KServiceType::addService(KService::Ptr service)
346 d =
new KServiceTypePrivate;
348 if (d->services.count() && d->services.last() == service)
351 d->services.append(service);
354 KService::List KServiceType::services()
359 return KService::List();
362 void KServiceType::virtual_hook(
int id,
void* data )
363 { KSycocaEntry::virtual_hook(
id, data ); }
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.
A service type is the generic notion for a mimetype, a type of service instead of a type of file.
virtual TQVariant::Type propertyDef(const TQString &_name) const
Returns the type of the property with the given _name.
static List allServiceTypes()
Returns a list of all the supported servicetypes.
virtual TQStringList propertyNames() const
Returns the list of all properties of this service type.
static KService::List offers(const TQString &_servicetype)
Returns all services supporting the given servicetype name.
TQString desktopEntryPath() const
Returns the relative path to the desktop entry file responsible for this servicetype.
static Ptr serviceType(const TQString &_name)
Returns a pointer to the servicetype '_name' or 0L if the service type is unknown.
virtual TQVariant property(const TQString &_name) const
Returns the requested property.
TQString parentServiceType() const
If this service type inherits from another service type, return the name of the parent.
bool inherits(const TQString &servTypeName) const
Checks whether this service type is or inherits from servTypeName.
KServiceType(const TQString &_fullpath, const TQString &_name, const TQString &_icon, const TQString &_comment)
Constructor.
TQString name() const
Returns the name of this service type.
Represent a service, i.e.
TQString desktopEntryPath() const
Returns the path to the location where the service desktop entry is stored.