• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

kservicetype.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE libraries
00002  *  Copyright (C) 1999 Waldo Bastian <bastian@kde.org>
00003  *                     David Faure   <faure@kde.org>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation;
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #include "kservicetype.h"
00021 #include "kservicetype_p.h"
00022 #include "ksycoca.h"
00023 #include "kservice.h"
00024 #include "kservicetypefactory.h"
00025 #include "kservicefactory.h"
00026 #include "kservicetypeprofile.h"
00027 #include <assert.h>
00028 #include <kdebug.h>
00029 #include <kdesktopfile.h>
00030 #include <kconfiggroup.h>
00031 
00032 extern int servicesDebugArea();
00033 
00034 template QDataStream& operator>> <QString, QVariant>(QDataStream&, QMap<QString, QVariant>&);
00035 template QDataStream& operator<< <QString, QVariant>(QDataStream&, const QMap<QString, QVariant>&);
00036 
00037 KServiceType::KServiceType( KServiceTypePrivate &dd, const QString& _name,
00038                             const QString& _comment )
00039     : KSycocaEntry(dd)
00040 {
00041     Q_D(KServiceType);
00042     d->m_strName = _name;
00043     d->m_strComment = _comment;
00044 }
00045 
00046 KServiceType::KServiceType( KDesktopFile *config )
00047     : KSycocaEntry(*new KServiceTypePrivate(config->fileName()))
00048 {
00049     Q_D(KServiceType);
00050     d->init(config);
00051 }
00052 
00053 void
00054 KServiceTypePrivate::init( KDesktopFile *config )
00055 {
00056 //    Q_Q(KServiceType);
00057 
00058     KConfigGroup desktopGroup = config->desktopGroup();
00059     // Is it a mimetype ? ### KDE4: remove
00060     m_strName = desktopGroup.readEntry( "MimeType" );
00061 
00062     // Or is it a servicetype ?
00063     if ( m_strName.isEmpty() ) {
00064         m_strName = desktopGroup.readEntry( "X-KDE-ServiceType" );
00065     }
00066 
00067     m_strComment = desktopGroup.readEntry("Comment");
00068     deleted = desktopGroup.readEntry("Hidden", false);
00069 
00070     // We store this as property to preserve BC, we can't change that
00071     // because KSycoca needs to remain BC between KDE 2.x and KDE 3.x
00072     QString sDerived = desktopGroup.readEntry( "X-KDE-Derived" );
00073     m_bDerived = !sDerived.isEmpty();
00074     if ( m_bDerived )
00075         m_mapProps.insert( "X-KDE-Derived", sDerived );
00076 
00077     const QStringList tmpList = config->groupList();
00078     QStringList::const_iterator gIt = tmpList.begin();
00079 
00080     for( ; gIt != tmpList.end(); ++gIt ) {
00081         if ( (*gIt).startsWith( QLatin1String("Property::") ) ) {
00082             KConfigGroup cg(config, *gIt );
00083             QVariant v = QVariant::nameToType( cg.readEntry( "Type" ).toLatin1().constData() );
00084             v = cg.readEntry( "Value", v );
00085 
00086             if ( v.isValid() )
00087                 m_mapProps.insert( (*gIt).mid( 10 ), v );
00088         }
00089     }
00090 
00091     gIt = tmpList.begin();
00092     for( ; gIt != tmpList.end(); ++gIt ) {
00093         if( (*gIt).startsWith( QLatin1String("PropertyDef::") ) ) {
00094             KConfigGroup cg(config, *gIt);
00095             m_mapPropDefs.insert( (*gIt).mid( 13 ),
00096                                   QVariant::nameToType( cg.readEntry( "Type" ).toLatin1().constData() ) );
00097         }
00098     }
00099 }
00100 
00101 KServiceType::KServiceType( QDataStream& _str, int offset )
00102     : KSycocaEntry(*new KServiceTypePrivate(_str, offset))
00103 {
00104 }
00105 
00106 KServiceType::KServiceType( KServiceTypePrivate &dd)
00107     : KSycocaEntry(dd)
00108 {
00109 }
00110 
00111 void
00112 KServiceTypePrivate::load( QDataStream& _str )
00113 {
00114     qint8 b;
00115     QString dummy;
00116     _str >> m_strName >> dummy >> m_strComment >> m_mapProps >> m_mapPropDefs
00117          >> b >> m_serviceOffersOffset;
00118     m_bDerived = m_mapProps.contains("X-KDE-Derived");
00119 }
00120 
00121 void
00122 KServiceTypePrivate::save( QDataStream& _str )
00123 {
00124   KSycocaEntryPrivate::save( _str );
00125   // !! This data structure should remain binary compatible at all times !!
00126   // You may add new fields at the end. Make sure to update the version
00127   // number in ksycoca.h
00128   _str << m_strName << QString() /*was icon*/ << m_strComment << m_mapProps << m_mapPropDefs
00129        << (qint8) 1 << m_serviceOffersOffset;
00130 }
00131 
00132 KServiceType::~KServiceType()
00133 {
00134 }
00135 
00136 QString KServiceType::parentServiceType() const
00137 {
00138     const QVariant v = property("X-KDE-Derived");
00139     return v.toString();
00140 }
00141 
00142 bool KServiceType::inherits( const QString& servTypeName ) const
00143 {
00144     if ( name() == servTypeName )
00145         return true;
00146     QString st = parentServiceType();
00147     while ( !st.isEmpty() )
00148     {
00149         KServiceType::Ptr ptr = KServiceType::serviceType( st );
00150         if (!ptr) return false; //error
00151         if ( ptr->name() == servTypeName )
00152             return true;
00153         st = ptr->parentServiceType();
00154     }
00155     return false;
00156 }
00157 
00158 QVariant
00159 KServiceTypePrivate::property( const QString& _name ) const
00160 {
00161     QVariant v;
00162 
00163     if ( _name == "Name" )
00164         v = QVariant( m_strName );
00165     else if ( _name == "Comment" )
00166         v = QVariant( m_strComment );
00167     else
00168         v = m_mapProps.value( _name );
00169 
00170     return v;
00171 }
00172 
00173 QStringList
00174 KServiceTypePrivate::propertyNames() const
00175 {
00176     QStringList res = m_mapProps.keys();
00177     res.append( "Name" );
00178     res.append( "Comment" );
00179     return res;
00180 }
00181 
00182 QVariant::Type
00183 KServiceType::propertyDef( const QString& _name ) const
00184 {
00185     Q_D(const KServiceType);
00186     return static_cast<QVariant::Type>( d->m_mapPropDefs.value( _name, QVariant::Invalid ) );
00187 }
00188 
00189 QStringList
00190 KServiceType::propertyDefNames() const
00191 {
00192     Q_D(const KServiceType);
00193     return d->m_mapPropDefs.keys();
00194 }
00195 
00196 KServiceType::Ptr KServiceType::serviceType( const QString& _name )
00197 {
00198     return KServiceTypeFactory::self()->findServiceTypeByName( _name );
00199 }
00200 
00201 KServiceType::List KServiceType::allServiceTypes()
00202 {
00203     return KServiceTypeFactory::self()->allServiceTypes();
00204 }
00205 
00206 KServiceType::Ptr KServiceType::parentType()
00207 {
00208     Q_D(KServiceType);
00209     if (d->m_parentTypeLoaded)
00210         return d->parentType;
00211 
00212     d->m_parentTypeLoaded = true;
00213 
00214     const QString parentSt = parentServiceType();
00215     if (parentSt.isEmpty())
00216         return KServiceType::Ptr();
00217 
00218     d->parentType = KServiceTypeFactory::self()->findServiceTypeByName( parentSt );
00219     if (!d->parentType)
00220         kWarning(servicesDebugArea()) << entryPath() << "specifies undefined mimetype/servicetype"<< parentSt;
00221     return d->parentType;
00222 }
00223 
00224 void KServiceType::setServiceOffersOffset( int offset )
00225 {
00226     Q_D(KServiceType);
00227     Q_ASSERT( offset != -1 );
00228     d->m_serviceOffersOffset = offset;
00229 }
00230 
00231 int KServiceType::serviceOffersOffset() const
00232 {
00233     Q_D(const KServiceType);
00234     return d->m_serviceOffersOffset;
00235 }
00236 
00237 QString KServiceType::comment() const
00238 {
00239     Q_D(const KServiceType);
00240     return d->comment();
00241 }
00242 
00243 // ## KDE4: remove?
00244 QString KServiceType::desktopEntryPath() const
00245 {
00246     return entryPath();
00247 }
00248 
00249 bool KServiceType::isDerived() const
00250 {
00251     Q_D(const KServiceType);
00252     return d->m_bDerived;
00253 }
00254 
00255 QMap<QString,QVariant::Type> KServiceType::propertyDefs() const
00256 {
00257     Q_D(const KServiceType);
00258     return d->m_mapPropDefs;
00259 }

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  •     Sodep
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal