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

kabc

picture.cpp

00001 /*
00002     This file is part of libkabc.
00003     Copyright (c) 2002 Tobias Koenig <tokoe@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 as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "picture.h"
00022 
00023 #include <QtCore/QBuffer>
00024 #include <QtCore/QSharedData>
00025 
00026 using namespace KABC;
00027 
00028 class Picture::Private : public QSharedData
00029 {
00030   public:
00031     Private()
00032       : mIntern( false )
00033     {
00034     }
00035 
00036     Private( const Private &other )
00037       : QSharedData( other )
00038     {
00039       mUrl = other.mUrl;
00040       mType = other.mType;
00041       mData = other.mData;
00042       mIntern = other.mIntern;
00043     }
00044 
00045     QString mUrl;
00046     QString mType;
00047     QImage mData;
00048 
00049     bool mIntern;
00050 };
00051 
00052 Picture::Picture()
00053   : d( new Private )
00054 {
00055 }
00056 
00057 Picture::Picture( const QString &url )
00058   : d( new Private )
00059 {
00060   d->mUrl = url;
00061 }
00062 
00063 Picture::Picture( const QImage &data )
00064   : d( new Private )
00065 {
00066   d->mIntern = true;
00067   d->mData = data;
00068 }
00069 
00070 Picture::Picture( const Picture &other )
00071   : d( other.d )
00072 {
00073 }
00074 
00075 Picture::~Picture()
00076 {
00077 }
00078 
00079 Picture &Picture::operator=( const Picture &other )
00080 {
00081   if ( this != &other ) {
00082     d = other.d;
00083   }
00084 
00085   return *this;
00086 }
00087 
00088 bool Picture::operator==( const Picture &p ) const
00089 {
00090   if ( d->mIntern != p.d->mIntern ) {
00091     return false;
00092   }
00093 
00094   if ( d->mIntern ) {
00095     if ( d->mData != p.d->mData ) {
00096       return false;
00097     }
00098   } else {
00099     if ( d->mUrl != p.d->mUrl ) {
00100       return false;
00101     }
00102   }
00103 
00104   return true;
00105 }
00106 
00107 bool Picture::operator!=( const Picture &p ) const
00108 {
00109   return !( p == *this );
00110 }
00111 
00112 bool Picture::isEmpty() const
00113 {
00114   return
00115     d->mIntern == false && d->mUrl.isEmpty() ||
00116     d->mIntern == true && d->mData.isNull();
00117 }
00118 
00119 void Picture::setUrl( const QString &url )
00120 {
00121   d->mUrl = url;
00122   d->mIntern = false;
00123 }
00124 
00125 void Picture::setData( const QImage &data )
00126 {
00127   d->mData = data;
00128   d->mIntern = true;
00129 }
00130 
00131 void Picture::setType( const QString &type )
00132 {
00133   d->mType = type;
00134 }
00135 
00136 bool Picture::isIntern() const
00137 {
00138   return d->mIntern;
00139 }
00140 
00141 QString Picture::url() const
00142 {
00143   return d->mUrl;
00144 }
00145 
00146 QImage Picture::data() const
00147 {
00148   return d->mData;
00149 }
00150 
00151 QString Picture::type() const
00152 {
00153   return d->mType;
00154 }
00155 
00156 QString Picture::toString() const
00157 {
00158   QString str;
00159 
00160   str += QString( "Picture {\n" );
00161   str += QString( "  Type: %1\n" ).arg( d->mType );
00162   str += QString( "  IsIntern: %1\n" ).arg( d->mIntern ? "true" : "false" );
00163   if ( d->mIntern ) {
00164     QByteArray data;
00165     QBuffer buffer( &data );
00166     buffer.open( QIODevice::WriteOnly );
00167     d->mData.save( &buffer, "PNG" );
00168     str += QString( "  Data: %1\n" ).arg( QString( data.toBase64() ) );
00169   } else {
00170     str += QString( "  Url: %1\n" ).arg( d->mUrl );
00171   }
00172   str += QString( "}\n" );
00173 
00174   return str;
00175 }
00176 
00177 QDataStream &KABC::operator<<( QDataStream &s, const Picture &picture )
00178 {
00179   return s << picture.d->mIntern << picture.d->mUrl << picture.d->mType << picture.d->mData;
00180 }
00181 
00182 QDataStream &KABC::operator>>( QDataStream &s, Picture &picture )
00183 {
00184   s >> picture.d->mIntern >> picture.d->mUrl >> picture.d->mType >> picture.d->mData;
00185 
00186   return s;
00187 }

kabc

Skip menu "kabc"
  • 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"
  • akonadi
  • 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.6
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