Source Code (Use browser search to find items of interest.)
Class Index
kdelibs'KServiceTypeProfile (./kdelibs/kio/kuserprofile.h:65)
class KServiceTypeProfile
{
public:
typedef QValueList<KServiceOffer> OfferList;
~KServiceTypeProfile();
/**
* @return the users preference of this special service or 0 if
* the service is unknown.
*/
int preference( const QString& _service ) const;
bool allowAsDefault( const QString& _service ) const;
OfferList offers() const;
/**
* @return the service type for which this profile is responsible.
*/
QString serviceType() const { return m_strServiceType; }
/**
* @return the preferred service (convenience method)
*/
static KService::Ptr preferredService( const QString & _serviceType);
/**
* @return the profile for the requested service type.
*/
static KServiceTypeProfile* serviceTypeProfile( const QString& _servicetype );
/**
* @return the offers associated with a given servicetype
*/
static OfferList offers( const QString& _servicetype );
static const QList<KServiceTypeProfile>& serviceTypeProfiles() { return *s_lstProfiles; }
/**
* Clear all cached information
*/
static void clear() { delete s_lstProfiles; s_lstProfiles = 0L; }
protected:
/**
* Constructor is called when the user profile is read for the
* first time.
*/
KServiceTypeProfile( const QString& _servicetype );
/**
* Add a service to this profile.
*/
void addService( const QString& _service, int _preference = 1, bool _allow_as_default = TRUE );
private:
/**
* Represents the users assessment of a special service
*/
struct Service
{
/**
* The bigger this number is, the better is this service.
*/
int m_iPreference;
/**
* Is it allowed to use this service for default actions.
*/
bool m_bAllowAsDefault;
};
/**
* Map of all services for which we have assessments.
*/
QMap<QString,Service> m_mapServices;
/**
* ServiceType of this profile.
*/
QString m_strServiceType;
static void initStatic();
static QList<KServiceTypeProfile>* s_lstProfiles;
};
kdelibs'KServiceTypeProfile::initStatic() (./kdelibs/kio/kuserprofile.cpp:39)
void KServiceTypeProfile::initStatic()
{
if ( s_lstProfiles )
return;
s_lstProfiles = new QList<KServiceTypeProfile>;
KSimpleConfig config( "profilerc");
QStringList tmpList = config.groupList();
for (QStringList::Iterator aIt = tmpList.begin();
aIt != tmpList.end(); ++aIt) {
if ( *aIt == "<default>" )
continue;
config.setGroup( *aIt );
QString type = config.readEntry( "ServiceType" );
int pref = config.readNumEntry( "Preference" );
bool allow = config.readBoolEntry( "AllowAsDefault" );
if ( !type.isEmpty() && pref >= 0 )
{
KServiceTypeProfile* p = KServiceTypeProfile::serviceTypeProfile( type );
if ( !p )
p = new KServiceTypeProfile( type );
p->addService( config.group(), pref, allow );
}
}
}
//static
KServiceTypeProfile::OfferList KServiceTypeProfile::offers( const QString& _servicetype )
{
OfferList offers;
KServiceTypeProfile* profile = serviceTypeProfile( _servicetype );
if ( profile )
return profile->offers();
KService::List list = KServiceType::offers( _servicetype );
QValueListIterator<KService::Ptr> it = list.begin();
for( ; it != list.end(); ++it )
{
bool allow = (*it)->allowAsDefault();
KServiceOffer o( (*it), 1, allow );
offers.append( o );
}
qBubbleSort( offers );
return offers;
}
kdelibs'KServiceTypeProfile::KServiceTypeProfile() (./kdelibs/kio/kuserprofile.cpp:94)
KServiceTypeProfile::KServiceTypeProfile( const QString& _servicetype )
{
initStatic();
m_strServiceType = _servicetype;
s_lstProfiles->append( this );
}
kdelibs'KServiceTypeProfile::~KServiceTypeProfile() (./kdelibs/kio/kuserprofile.cpp:103)
KServiceTypeProfile::~KServiceTypeProfile()
{
ASSERT( s_lstProfiles );
s_lstProfiles->removeRef( this );
}
kdelibs'KServiceTypeProfile::addService() (./kdelibs/kio/kuserprofile.cpp:110)
void KServiceTypeProfile::addService( const QString& _service,
int _preference, bool _allow_as_default )
{
m_mapServices[ _service ].m_iPreference = _preference;
m_mapServices[ _service ].m_bAllowAsDefault = _allow_as_default;
}
kdelibs'KServiceTypeProfile::preference() (./kdelibs/kio/kuserprofile.cpp:117)
int KServiceTypeProfile::preference( const QString& _service ) const
{
QMap<QString,Service>::ConstIterator it = m_mapServices.find( _service );
if ( it == m_mapServices.end() )
return 0;
return it.data().m_iPreference;
}
kdelibs'KServiceTypeProfile::allowAsDefault() (./kdelibs/kio/kuserprofile.cpp:126)
bool KServiceTypeProfile::allowAsDefault( const QString& _service ) const
{
// Does the service itself not allow that ?
KService::Ptr s = KService::serviceByName( _service );
if ( s && !s->allowAsDefault() )
return false;
// Look what the user says ...
QMap<QString,Service>::ConstIterator it = m_mapServices.find( _service );
if ( it == m_mapServices.end() )
return 0;
return it.data().m_bAllowAsDefault;
}
kdelibs'KServiceTypeProfile::serviceTypeProfile() (./kdelibs/kio/kuserprofile.cpp:141)
KServiceTypeProfile* KServiceTypeProfile::serviceTypeProfile( const QString& _servicetype )
{
initStatic();
QListIterator<KServiceTypeProfile> it( *s_lstProfiles );
for( ; it.current(); ++it )
if ( it.current()->serviceType() == _servicetype )
return it.current();
return 0;
}
KServiceTypeProfile::OfferList KServiceTypeProfile::offers() const
{
OfferList offers;
KService::List list = KServiceType::offers( m_strServiceType );
QValueListIterator<KService::Ptr> it = list.begin();
for( ; it != list.end(); ++it )
{
if ( (*it)->hasServiceType( m_strServiceType ) )
{
QMap<QString,Service>::ConstIterator it2 = m_mapServices.find( (*it)->name() );
if( it2 != m_mapServices.end() )
{
bool allow = (*it)->allowAsDefault();
if ( allow )
allow = it2.data().m_bAllowAsDefault;
KServiceOffer o( (*it), it2.data().m_iPreference, allow );
offers.append( o );
}
else
{
KServiceOffer o( (*it), 1, (*it)->allowAsDefault() );
offers.append( o );
}
}
}
qBubbleSort( offers );
return offers;
}
KService::Ptr KServiceTypeProfile::preferredService( const QString & _serviceType )
{
OfferList lst = offers( _serviceType );
if ( lst.count() == 0 || !(*lst.begin()).allowAsDefault() )
{
kdDebug(7010) << "No Offers" << endl;
return 0L;
}
return ( *lst.begin() ).service();
}
/*********************************************
*
* KServiceOffer
*
*********************************************/