KIMAP Library
message_p.h
00001 /* 00002 Copyright (c) 2009 Kevin Ottens <ervin@kde.org> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 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 the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 00018 */ 00019 00020 #ifndef KIMAP_MESSAGE_P_H 00021 #define KIMAP_MESSAGE_P_H 00022 00023 #include <QtCore/QByteArray> 00024 #include <QtCore/QList> 00025 #include <QtCore/QMetaType> 00026 00027 namespace KIMAP { 00028 00029 struct Message 00030 { 00031 class Part 00032 { 00033 public: 00034 enum Type { String = 0, List }; 00035 00036 explicit Part(const QByteArray &string) 00037 : m_type(String), m_string(string) { } 00038 explicit Part(const QList<QByteArray> &list) 00039 : m_type(List), m_list(list) { } 00040 00041 inline Type type() const { return m_type; } 00042 inline QByteArray toString() const { return m_string; } 00043 inline QList<QByteArray> toList() const { return m_list; } 00044 00045 private: 00046 Type m_type; 00047 QByteArray m_string; 00048 QList<QByteArray> m_list; 00049 }; 00050 00051 inline QByteArray toString() const 00052 { 00053 QByteArray result; 00054 00055 foreach ( const Part &part, content ) { 00056 if ( part.type()==Part::List ) { 00057 result+='('; 00058 foreach ( const QByteArray &item, part.toList() ) { 00059 result+= ' '; 00060 result+= item; 00061 } 00062 result+=" ) "; 00063 } else { 00064 result+= part.toString()+' '; 00065 } 00066 } 00067 00068 if ( !responseCode.isEmpty() ) { 00069 result+="[ "; 00070 foreach ( const Part &part, responseCode ) { 00071 if ( part.type()==Part::List ) { 00072 result+='('; 00073 foreach ( const QByteArray &item, part.toList() ) { 00074 result+= ' '; 00075 result+= item; 00076 } 00077 result+=" ) "; 00078 } else { 00079 result+= part.toString()+' '; 00080 } 00081 } 00082 result+=" ]"; 00083 } 00084 00085 return result; 00086 } 00087 00088 QList<Part> content; 00089 QList<Part> responseCode; 00090 }; 00091 00092 } 00093 00094 Q_DECLARE_METATYPE(KIMAP::Message) 00095 static const int _kimap_messageTypeId = qRegisterMetaType<KIMAP::Message>(); 00096 00097 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 7 2012 23:55:08 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 7 2012 23:55:08 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.