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

KIO

udsentry.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2000-2005 David Faure <faure@kde.org>
00003    Copyright (C) 2007 Norbert Frese <nf2@scheinwelt.at>
00004    Copyright (C) 2007 Thiago Macieira <thiago@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "udsentry.h"
00023 
00024 #include <kdebug.h>
00025 #include <kio/global.h>
00026 #include <kio/kio_export.h>
00027 
00028 #include <QtCore/QString>
00029 #include <QtCore/QHash>
00030 #include <QtCore/QList>
00031 
00032 using namespace KIO;
00033 
00034 /* ---------- UDSEntry ------------ */
00035 
00036 class KIO::UDSEntryPrivate : public QSharedData
00037 {
00038 public:
00039     struct Field
00040     {
00041         inline Field() : m_long(0) { }
00042         QString m_str;
00043         long long m_long;
00044     };
00045     typedef QHash<uint, Field> FieldHash;
00046     FieldHash fields;
00047 
00048     static void save(QDataStream &, const UDSEntry &);
00049     static void load(QDataStream &, UDSEntry &);
00050 };
00051 Q_DECLARE_TYPEINFO(KIO::UDSEntryPrivate::Field, Q_MOVABLE_TYPE);
00052 
00053 UDSEntry::UDSEntry()
00054     : d(new UDSEntryPrivate())
00055 {
00056 }
00057 
00058 UDSEntry::UDSEntry(const UDSEntry &other)
00059     : d(other.d)
00060 {
00061 }
00062 
00063 UDSEntry::~UDSEntry()
00064 {
00065 }
00066 
00067 UDSEntry &UDSEntry::operator=(const UDSEntry &other)
00068 {
00069     d = other.d;
00070     return *this;
00071 }
00072 
00073 QString UDSEntry::stringValue(uint field) const
00074 {
00075     return d->fields.value(field).m_str;
00076 }
00077 
00078 long long UDSEntry::numberValue(uint field, long long defaultValue) const
00079 {
00080     UDSEntryPrivate::FieldHash::ConstIterator it = d->fields.find(field);
00081     return it != d->fields.constEnd() ? it->m_long : defaultValue;
00082 }
00083 
00084 bool UDSEntry::isDir() const
00085 {
00086     return S_ISDIR(numberValue(UDS_FILE_TYPE));
00087 }
00088 
00089 bool UDSEntry::isLink() const
00090 {
00091     return !stringValue(UDS_LINK_DEST).isEmpty();
00092 }
00093 
00094 void UDSEntry::insert(uint field, const QString& value)
00095 {
00096     UDSEntryPrivate::Field f;
00097     f.m_str = value;
00098     d->fields.insert(field, f);
00099 }
00100 
00101 void UDSEntry::insert(uint field, long long value)
00102 {
00103     UDSEntryPrivate::Field f;
00104     f.m_long = value;
00105     d->fields.insert(field, f);
00106 }
00107 
00108 QList<uint> UDSEntry::listFields() const
00109 {
00110     return d->fields.keys();
00111 }
00112 
00113 int UDSEntry::count() const
00114 {
00115     return d->fields.count();
00116 }
00117 
00118 bool UDSEntry::contains(uint field) const
00119 {
00120     return d->fields.contains(field);
00121 }
00122 
00123 bool UDSEntry::remove(uint field)
00124 {
00125     return d->fields.remove(field) > 0;
00126 }
00127 
00128 void UDSEntry::clear()
00129 {
00130     d->fields.clear();
00131 }
00132 
00133 QDataStream & operator<<(QDataStream &s, const UDSEntry &a)
00134 {
00135     UDSEntryPrivate::save(s, a);
00136     return s;
00137 }
00138 
00139 QDataStream & operator>>(QDataStream &s, UDSEntry &a)
00140 {
00141     UDSEntryPrivate::load(s, a);
00142     return s;
00143 }
00144 
00145 void UDSEntryPrivate::save(QDataStream &s, const UDSEntry &a)
00146 {
00147     const FieldHash &e = a.d->fields;
00148 
00149     s << e.size();
00150     FieldHash::ConstIterator it = e.begin();
00151     const FieldHash::ConstIterator end = e.end();
00152     for( ; it != end; ++it)
00153     {
00154         const quint32 uds = it.key();
00155         s << uds;
00156         if (uds & KIO::UDSEntry::UDS_STRING)
00157             s << it->m_str;
00158         else if (uds & KIO::UDSEntry::UDS_NUMBER)
00159             s << it->m_long;
00160         else
00161             Q_ASSERT_X(false, "KIO::UDSEntry", "Found a field with an invalid type");
00162      }
00163  }
00164 
00165 void UDSEntryPrivate::load(QDataStream &s, UDSEntry &a)
00166 {
00167     FieldHash &e = a.d->fields;
00168 
00169     e.clear();
00170     quint32 size;
00171     s >> size;
00172     for(quint32 i = 0; i < size; ++i)
00173     {
00174         quint32 uds;
00175         s >> uds;
00176         if (uds & KIO::UDSEntry::UDS_STRING) {
00177             Field f;
00178             s >> f.m_str;
00179             e.insert(uds, f);
00180         } else if (uds & KIO::UDSEntry::UDS_NUMBER) {
00181             Field f;
00182             s >> f.m_long;
00183             e.insert(uds, f);
00184         } else {
00185             Q_ASSERT_X(false, "KIO::UDSEntry", "Found a field with an invalid type");
00186         }
00187     }
00188 }
00189 
00190 

KIO

Skip menu "KIO"
  • Main Page
  • 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
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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