• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • 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     m_strName = desktopGroup.readEntry( "X-KDE-ServiceType" );
00060     m_strComment = desktopGroup.readEntry("Comment");
00061     deleted = desktopGroup.readEntry("Hidden", false);
00062 
00063     // We store this as property to preserve BC, we can't change that
00064     // because KSycoca needs to remain BC between KDE 2.x and KDE 3.x
00065     QString sDerived = desktopGroup.readEntry( "X-KDE-Derived" );
00066     m_bDerived = !sDerived.isEmpty();
00067     if ( m_bDerived )
00068         m_mapProps.insert( QString::fromLatin1("X-KDE-Derived"), sDerived );
00069 
00070     const QStringList tmpList = config->groupList();
00071     QStringList::const_iterator gIt = tmpList.begin();
00072 
00073     for( ; gIt != tmpList.end(); ++gIt ) {
00074         if ( (*gIt).startsWith( QLatin1String("Property::") ) ) {
00075             KConfigGroup cg(config, *gIt );
00076             QVariant v = QVariant::nameToType( cg.readEntry( "Type" ).toLatin1().constData() );
00077             v = cg.readEntry( "Value", v );
00078 
00079             if ( v.isValid() )
00080                 m_mapProps.insert( (*gIt).mid( 10 ), v );
00081         }
00082     }
00083 
00084     gIt = tmpList.begin();
00085     for( ; gIt != tmpList.end(); ++gIt ) {
00086         if( (*gIt).startsWith( QLatin1String("PropertyDef::") ) ) {
00087             KConfigGroup cg(config, *gIt);
00088             m_mapPropDefs.insert( (*gIt).mid( 13 ),
00089                                   QVariant::nameToType( cg.readEntry( "Type" ).toLatin1().constData() ) );
00090         }
00091     }
00092 }
00093 
00094 KServiceType::KServiceType( QDataStream& _str, int offset )
00095     : KSycocaEntry(*new KServiceTypePrivate(_str, offset))
00096 {
00097     Q_D(KServiceType);
00098     d->load(_str);
00099 }
00100 
00101 KServiceType::KServiceType( KServiceTypePrivate &dd)
00102     : KSycocaEntry(dd)
00103 {
00104 }
00105 
00106 void
00107 KServiceTypePrivate::load( QDataStream& _str )
00108 {
00109     qint8 b;
00110     QString dummy;
00111     _str >> m_strName >> dummy >> m_strComment >> m_mapProps >> m_mapPropDefs
00112          >> b >> m_serviceOffersOffset;
00113     m_bDerived = m_mapProps.contains(QString::fromLatin1("X-KDE-Derived"));
00114 }
00115 
00116 void
00117 KServiceTypePrivate::save( QDataStream& _str )
00118 {
00119   KSycocaEntryPrivate::save( _str );
00120   // !! This data structure should remain binary compatible at all times !!
00121   // You may add new fields at the end. Make sure to update the version
00122   // number in ksycoca.h
00123   _str << m_strName << QString() /*was icon*/ << m_strComment << m_mapProps << m_mapPropDefs
00124        << (qint8) 1 << m_serviceOffersOffset;
00125 }
00126 
00127 KServiceType::~KServiceType()
00128 {
00129 }
00130 
00131 QString KServiceType::parentServiceType() const
00132 {
00133     const QVariant v = property(QString::fromLatin1("X-KDE-Derived"));
00134     return v.toString();
00135 }
00136 
00137 bool KServiceType::inherits( const QString& servTypeName ) const
00138 {
00139     if ( name() == servTypeName )
00140         return true;
00141     QString st = parentServiceType();
00142     while ( !st.isEmpty() )
00143     {
00144         KServiceType::Ptr ptr = KServiceType::serviceType( st );
00145         if (!ptr) return false; //error
00146         if ( ptr->name() == servTypeName )
00147             return true;
00148         st = ptr->parentServiceType();
00149     }
00150     return false;
00151 }
00152 
00153 QVariant
00154 KServiceTypePrivate::property( const QString& _name ) const
00155 {
00156     QVariant v;
00157 
00158     if ( _name == QLatin1String("Name") )
00159         v = QVariant( m_strName );
00160     else if ( _name == QLatin1String("Comment") )
00161         v = QVariant( m_strComment );
00162     else
00163         v = m_mapProps.value( _name );
00164 
00165     return v;
00166 }
00167 
00168 QStringList
00169 KServiceTypePrivate::propertyNames() const
00170 {
00171     QStringList res = m_mapProps.keys();
00172     res.append( QString::fromLatin1("Name") );
00173     res.append( QString::fromLatin1("Comment") );
00174     return res;
00175 }
00176 
00177 QVariant::Type
00178 KServiceType::propertyDef( const QString& _name ) const
00179 {
00180     Q_D(const KServiceType);
00181     return static_cast<QVariant::Type>( d->m_mapPropDefs.value( _name, QVariant::Invalid ) );
00182 }
00183 
00184 QStringList
00185 KServiceType::propertyDefNames() const
00186 {
00187     Q_D(const KServiceType);
00188     return d->m_mapPropDefs.keys();
00189 }
00190 
00191 KServiceType::Ptr KServiceType::serviceType( const QString& _name )
00192 {
00193     return KServiceTypeFactory::self()->findServiceTypeByName( _name );
00194 }
00195 
00196 KServiceType::List KServiceType::allServiceTypes()
00197 {
00198     return KServiceTypeFactory::self()->allServiceTypes();
00199 }
00200 
00201 KServiceType::Ptr KServiceType::parentType()
00202 {
00203     Q_D(KServiceType);
00204     if (d->m_parentTypeLoaded)
00205         return d->parentType;
00206 
00207     d->m_parentTypeLoaded = true;
00208 
00209     const QString parentSt = parentServiceType();
00210     if (parentSt.isEmpty())
00211         return KServiceType::Ptr();
00212 
00213     d->parentType = KServiceTypeFactory::self()->findServiceTypeByName( parentSt );
00214     if (!d->parentType)
00215         kWarning(servicesDebugArea()) << entryPath() << "specifies undefined mimetype/servicetype"<< parentSt;
00216     return d->parentType;
00217 }
00218 
00219 void KServiceType::setServiceOffersOffset( int offset )
00220 {
00221     Q_D(KServiceType);
00222     Q_ASSERT( offset != -1 );
00223     d->m_serviceOffersOffset = offset;
00224 }
00225 
00226 int KServiceType::serviceOffersOffset() const
00227 {
00228     Q_D(const KServiceType);
00229     return d->serviceOffersOffset();
00230 }
00231 
00232 QString KServiceType::comment() const
00233 {
00234     Q_D(const KServiceType);
00235     return d->comment();
00236 }
00237 
00238 // ## KDE4: remove?
00239 #ifndef KDE_NO_DEPRECATED
00240 QString KServiceType::desktopEntryPath() const
00241 {
00242     return entryPath();
00243 }
00244 #endif
00245 
00246 bool KServiceType::isDerived() const
00247 {
00248     Q_D(const KServiceType);
00249     return d->m_bDerived;
00250 }
00251 
00252 QMap<QString,QVariant::Type> KServiceType::propertyDefs() const
00253 {
00254     Q_D(const KServiceType);
00255     return d->m_mapPropDefs;
00256 }

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
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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