KDECore
ksycocaentry.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 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Library General Public 00006 * License version 2 as published by the Free Software Foundation; 00007 * 00008 * This library is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Library General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Library General Public License 00014 * along with this library; see the file COPYING.LIB. If not, write to 00015 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 * Boston, MA 02110-1301, USA. 00017 **/ 00018 00019 #include "ksycocaentry.h" 00020 #include "ksycocaentry_p.h" 00021 #include <kdebug.h> 00022 00023 #include <ksycoca.h> 00024 00025 KSycocaEntryPrivate::KSycocaEntryPrivate(QDataStream &_str, int iOffset) 00026 : offset(iOffset), deleted(false) 00027 { 00028 KSycocaEntry::read( _str, path ); 00029 } 00030 00031 KSycocaEntry::KSycocaEntry() 00032 : d_ptr(0) 00033 { 00034 } 00035 00036 KSycocaEntry::KSycocaEntry(KSycocaEntryPrivate &d) 00037 : d_ptr(&d) 00038 { 00039 } 00040 00041 KSycocaEntry::~KSycocaEntry() 00042 { 00043 delete d_ptr; 00044 } 00045 00046 void KSycocaEntry::read( QDataStream &s, QString &str ) 00047 { 00048 quint32 bytes; 00049 s >> bytes; // read size of string 00050 if ( bytes > 8192 ) { // null string or too big 00051 if (bytes != 0xffffffff) 00052 KSycoca::flagError(); 00053 str.clear(); 00054 } 00055 else if ( bytes > 0 ) { // not empty 00056 int bt = bytes/2; 00057 str.resize( bt ); 00058 QChar* ch = (QChar *) str.unicode(); 00059 char t[8192]; 00060 char *b = t; 00061 s.readRawData( b, bytes ); 00062 while ( bt-- ) { 00063 *ch++ = (ushort) (((ushort)b[0])<<8) | (uchar)b[1]; 00064 b += 2; 00065 } 00066 } else { 00067 str = QString(); 00068 } 00069 } 00070 00071 void KSycocaEntry::read( QDataStream &s, QStringList &list ) 00072 { 00073 list.clear(); 00074 quint32 count; 00075 s >> count; // read size of list 00076 if (count >= 1024) 00077 { 00078 KSycoca::flagError(); 00079 return; 00080 } 00081 for(quint32 i = 0; i < count; i++) 00082 { 00083 QString str; 00084 read(s, str); 00085 list.append( str ); 00086 if (s.atEnd()) 00087 { 00088 KSycoca::flagError(); 00089 return; 00090 } 00091 } 00092 } 00093 00094 bool KSycocaEntry::isType(KSycocaType t) const 00095 { 00096 return d_ptr->isType(t); 00097 } 00098 00099 KSycocaType KSycocaEntry::sycocaType() const 00100 { 00101 return d_ptr->sycocaType(); 00102 } 00103 00104 QString KSycocaEntry::entryPath() const 00105 { 00106 Q_D(const KSycocaEntry); 00107 return d->path; 00108 } 00109 00110 QString KSycocaEntry::storageId() const 00111 { 00112 Q_D(const KSycocaEntry); 00113 return d->storageId(); 00114 } 00115 00116 bool KSycocaEntry::isDeleted() const 00117 { 00118 Q_D(const KSycocaEntry); 00119 return d->deleted; 00120 } 00121 00122 void KSycocaEntry::setDeleted( bool deleted ) 00123 { 00124 Q_D(KSycocaEntry); 00125 d->deleted = deleted; 00126 } 00127 00128 bool KSycocaEntry::isSeparator() const 00129 { 00130 return d_ptr == 0 || isType(KST_KServiceSeparator); 00131 } 00132 00133 int KSycocaEntry::offset() const 00134 { 00135 Q_D(const KSycocaEntry); 00136 return d->offset; 00137 } 00138 00139 void KSycocaEntryPrivate::save(QDataStream &s) 00140 { 00141 offset = s.device()->pos(); // store position in member variable 00142 s << qint32(sycocaType()) << path; 00143 } 00144 00145 void KSycocaEntry::save(QDataStream &s) 00146 { 00147 Q_D(KSycocaEntry); 00148 d->save(s); 00149 } 00150 00151 bool KSycocaEntry::isValid() const 00152 { 00153 Q_D(const KSycocaEntry); 00154 return d && d->isValid(); 00155 } 00156 00157 QString KSycocaEntry::name() const 00158 { 00159 Q_D(const KSycocaEntry); 00160 return d->name(); 00161 } 00162 00163 QStringList KSycocaEntry::propertyNames() const 00164 { 00165 Q_D(const KSycocaEntry); 00166 return d->propertyNames(); 00167 } 00168 00169 QVariant KSycocaEntry::property(const QString &name) const 00170 { 00171 Q_D(const KSycocaEntry); 00172 return d->property(name); 00173 }
KDE 4.6 API Reference