19 #include "kuserprofile.h"
21 #include "kservicetype.h"
22 #include "kservicetypefactory.h"
24 #include <tdeconfig.h>
25 #include <tdeapplication.h>
26 #include <tdeglobal.h>
28 #include <kstaticdeleter.h>
32 template class TQPtrList<KServiceTypeProfile>;
33 typedef TQPtrList<KServiceTypeProfile> KServiceTypeProfileList;
41 KServiceTypeProfileList* KServiceTypeProfile::s_lstProfiles = 0L;
42 static KStaticDeleter< KServiceTypeProfileList > profileDeleter;
43 bool KServiceTypeProfile::s_configurationMode =
false;
45 void KServiceTypeProfile::initStatic()
51 (void) KServiceTypeFactory::self();
53 profileDeleter.setObject(s_lstProfiles,
new KServiceTypeProfileList);
54 s_lstProfiles->setAutoDelete(
true );
56 TDEConfig config(
"profilerc",
true,
false);
58 static const TQString & defaultGroup = TDEGlobal::staticQString(
"<default>");
60 TQStringList tmpList = config.groupList();
61 for (TQStringList::Iterator aIt = tmpList.begin();
62 aIt != tmpList.end(); ++aIt) {
63 if ( *aIt == defaultGroup )
66 config.setGroup( *aIt );
68 TQString appId = config.readEntry(
"Application" );
73 TQString application = pService->storageId();
74 TQString type = config.readEntry(
"ServiceType" );
75 TQString type2 = config.readEntry(
"GenericServiceType" );
77 type2 = (pService->type() ==
"Application") ?
"Application" :
"KParts/ReadOnlyPart";
78 int pref = config.readNumEntry(
"Preference" );
80 if ( !type.isEmpty() )
87 s_lstProfiles->append( p );
90 bool allow = config.readBoolEntry(
"AllowAsDefault" );
104 if( s_lstProfiles == NULL || s_lstProfiles->count() == 0 )
106 profileDeleter.destructObject();
113 TQStringList serviceList;
118 if ( _genericServiceType.isEmpty() )
123 TQPtrListIterator<KServiceTypeProfile> it( *s_lstProfiles );
124 for( ; it.current(); ++it )
125 if ( it.current()->m_strServiceType == _servicetype )
127 offers += it.current()->offers();
137 offers += profile->
offers();
146 offers += profile->
offers();
152 OfferList::Iterator itOffers = offers.begin();
153 for( ; itOffers != offers.end(); ++itOffers )
154 serviceList += (*itOffers).service()->desktopEntryPath();
162 TQValueListIterator<KService::Ptr> it = list.begin();
163 for( ; it != list.end(); ++it )
165 if (_genericServiceType.isEmpty() || (*it)->hasServiceType( _genericServiceType ))
168 if ( serviceList.find( (*it)->desktopEntryPath() ) == serviceList.end() )
170 bool allow = (*it)->allowAsDefault();
171 KServiceOffer o( (*it), (*it)->initialPreferenceForMimeType(_servicetype), allow );
180 qBubbleSort( offers );
184 kdDebug(7014) <<
"Sorted list:" << endl;
185 OfferList::Iterator itOff = offers.begin();
186 for( ; itOff != offers.end(); ++itOff )
187 kdDebug(7014) << (*itOff).service()->name() <<
" allow-as-default=" << (*itOff).allowAsDefault() << endl;
198 m_strServiceType = _servicetype;
199 m_strGenericServiceType = _genericServiceType;
202 KServiceTypeProfile::~KServiceTypeProfile()
207 int _preference,
bool _allow_as_default )
209 m_mapServices[ _service ].m_iPreference = _preference;
210 m_mapServices[ _service ].m_bAllowAsDefault = _allow_as_default;
218 TQMap<TQString,Service>::ConstIterator it = m_mapServices.find( service->storageId() );
219 if ( it == m_mapServices.end() )
222 return it.data().m_iPreference;
232 if ( !service->allowAsDefault() )
236 TQMap<TQString,Service>::ConstIterator it = m_mapServices.find( service->storageId() );
237 if ( it == m_mapServices.end() )
240 return it.data().m_bAllowAsDefault;
246 static const TQString& app_str = TDEGlobal::staticQString(
"Application");
248 const TQString &_genservicetype = ((!_genericServiceType.isEmpty()) ? _genericServiceType : app_str);
250 TQPtrListIterator<KServiceTypeProfile> it( *s_lstProfiles );
251 for( ; it.current(); ++it )
252 if (( it.current()->m_strServiceType == _servicetype ) &&
253 ( it.current()->m_strGenericServiceType == _genservicetype))
264 kdDebug(7014) <<
"KServiceTypeProfile::offers serviceType=" << m_strServiceType <<
" genericServiceType=" << m_strGenericServiceType << endl;
266 TQValueListIterator<KService::Ptr> it = list.begin();
267 for( ; it != list.end(); ++it )
270 if ( m_strGenericServiceType.isEmpty() || (*it)->hasServiceType( m_strGenericServiceType ) )
273 TQMap<TQString,Service>::ConstIterator it2 = m_mapServices.find( (*it)->storageId() );
275 if( it2 != m_mapServices.end() )
278 if ( it2.data().m_iPreference > 0 ) {
279 bool allow = (*it)->allowAsDefault();
281 allow = it2.data().m_bAllowAsDefault;
297 qBubbleSort( offers );
305 OfferList lst =
offers( _serviceType, _genericServiceType );
307 OfferList::Iterator itOff = lst.begin();
311 if( itOff != lst.end() && (*itOff).allowAsDefault() )
312 return (*itOff).service();
331 m_pService = _o.m_pService;
332 m_iPreference = _o.m_iPreference;
333 m_bAllowAsDefault = _o.m_bAllowAsDefault;
338 m_pService = _service;
339 m_iPreference = _pref;
340 m_bAllowAsDefault = _default;
347 if ( _o.m_bAllowAsDefault && !m_bAllowAsDefault )
349 if ( !_o.m_bAllowAsDefault && m_bAllowAsDefault )
354 return _o.m_iPreference < m_iPreference;