• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

KCal Library

attachment.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of the kcal library.
00003 
00004     Copyright (c) 2002 Michael Brade <brade@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 */
00032 #include "attachment.h"
00033 
00034 #include <QtCore/QByteArray>
00035 
00036 using namespace KCal;
00037 
00042 //@cond PRIVATE
00043 class KCal::Attachment::Private
00044 {
00045   public:
00046     Private( const QString &data, const QString &mime, bool binary )
00047       : mMimeType( mime ),
00048         mData( data ),
00049         mBinary( binary ),
00050         mShowInline( false )
00051     {}
00052     Private( const Private &other )
00053       : mMimeType( other.mMimeType ),
00054         mData( other.mData ),
00055         mLabel( other.mLabel ),
00056         mBinary( other.mBinary ),
00057         mLocal( other.mLocal ),
00058         mShowInline( other.mShowInline )
00059     {}
00060     QByteArray mDataCache;
00061     uint mSize;
00062     QString mMimeType;
00063     QString mData;
00064     QString mLabel;
00065     bool mBinary;
00066     bool mLocal;
00067     bool mShowInline;
00068 };
00069 //@endcond
00070 
00071 Attachment::Attachment( const Attachment &attachment )
00072   : d( new Attachment::Private( *attachment.d ) )
00073 {
00074 }
00075 
00076 Attachment::Attachment( const QString &uri, const QString &mime )
00077   : d( new Attachment::Private( uri, mime, false ) )
00078 {
00079   d->mLocal = false;
00080 }
00081 
00082 Attachment::Attachment( const char *base64, const QString &mime )
00083   : d( new Attachment::Private( QString::fromUtf8( base64 ), mime, true ) )
00084 {
00085 }
00086 
00087 Attachment::~Attachment()
00088 {
00089   delete d;
00090 }
00091 
00092 bool Attachment::isUri() const
00093 {
00094   return !d->mBinary;
00095 }
00096 
00097 QString Attachment::uri() const
00098 {
00099   if ( !d->mBinary ) {
00100     return d->mData;
00101   } else {
00102     return QString();
00103   }
00104 }
00105 
00106 void Attachment::setUri( const QString &uri )
00107 {
00108   d->mData = uri;
00109   d->mBinary = false;
00110 }
00111 
00112 bool Attachment::isBinary() const
00113 {
00114   return d->mBinary;
00115 }
00116 
00117 char *Attachment::data() const
00118 {
00119   if ( d->mBinary ) {
00120     return d->mData.toUtf8().data();
00121   } else {
00122     return 0;
00123   }
00124 }
00125 
00126 QByteArray &Attachment::decodedData() const
00127 {
00128   if ( d->mDataCache.isNull() ) {
00129     d->mDataCache = QByteArray::fromBase64( d->mData.toUtf8() );
00130   }
00131 
00132   return d->mDataCache;
00133 }
00134 
00135 void Attachment::setDecodedData( const QByteArray &data )
00136 {
00137   setData( data.toBase64() );
00138   d->mDataCache = data;
00139 }
00140 
00141 void Attachment::setData( const char *base64 )
00142 {
00143   d->mData = QString::fromUtf8( base64 );
00144   d->mBinary = true;
00145   d->mDataCache = QByteArray();
00146   d->mSize = 0;
00147 }
00148 
00149 uint Attachment::size() const
00150 {
00151   if ( isUri() ) {
00152     return 0;
00153   }
00154   if ( !d->mSize ) {
00155     d->mSize = decodedData().size();
00156   }
00157 
00158   return d->mSize;
00159 }
00160 
00161 QString Attachment::mimeType() const
00162 {
00163   return d->mMimeType;
00164 }
00165 
00166 void Attachment::setMimeType( const QString &mime )
00167 {
00168   d->mMimeType = mime;
00169 }
00170 
00171 bool Attachment::showInline() const
00172 {
00173   return d->mShowInline;
00174 }
00175 
00176 void Attachment::setShowInline( bool showinline )
00177 {
00178   d->mShowInline = showinline;
00179 }
00180 
00181 QString Attachment::label() const
00182 {
00183   return d->mLabel;
00184 }
00185 
00186 void Attachment::setLabel( const QString &label )
00187 {
00188   d->mLabel = label;
00189 }
00190 
00191 bool Attachment::isLocal() const
00192 {
00193   return d->mLocal;
00194 }
00195 
00196 void Attachment::setLocal( bool local )
00197 {
00198   d->mLocal = local;
00199 }

KCal Library

Skip menu "KCal Library"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.5
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