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

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
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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