• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.4 API Reference
  • KDE Home
  • Contact Us
 

kabc

  • kabc
picture.cpp
1 /*
2  This file is part of libkabc.
3  Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "picture.h"
22 
23 #include <QtCore/QBuffer>
24 #include <QtCore/QSharedData>
25 
26 using namespace KABC;
27 
28 class Picture::Private : public QSharedData
29 {
30  public:
31  Private()
32  : mIntern( false )
33  {
34  }
35 
36  Private( const Private &other )
37  : QSharedData( other )
38  {
39  mUrl = other.mUrl;
40  mType = other.mType;
41  mData = other.mData;
42  mIntern = other.mIntern;
43  }
44 
45  QString mUrl;
46  QString mType;
47  QImage mData;
48 
49  bool mIntern;
50 };
51 
52 Picture::Picture()
53  : d( new Private )
54 {
55 }
56 
57 Picture::Picture( const QString &url )
58  : d( new Private )
59 {
60  d->mUrl = url;
61 }
62 
63 Picture::Picture( const QImage &data )
64  : d( new Private )
65 {
66  d->mIntern = true;
67  d->mData = data;
68 }
69 
70 Picture::Picture( const Picture &other )
71  : d( other.d )
72 {
73 }
74 
75 Picture::~Picture()
76 {
77 }
78 
79 Picture &Picture::operator=( const Picture &other )
80 {
81  if ( this != &other ) {
82  d = other.d;
83  }
84 
85  return *this;
86 }
87 
88 bool Picture::operator==( const Picture &p ) const
89 {
90  if ( d->mIntern != p.d->mIntern ) {
91  return false;
92  }
93 
94  if ( d->mIntern ) {
95  if ( d->mData != p.d->mData ) {
96  return false;
97  }
98  } else {
99  if ( d->mUrl != p.d->mUrl ) {
100  return false;
101  }
102  }
103 
104  return true;
105 }
106 
107 bool Picture::operator!=( const Picture &p ) const
108 {
109  return !( p == *this );
110 }
111 
112 bool Picture::isEmpty() const
113 {
114  return
115  ( ( d->mIntern == false && d->mUrl.isEmpty() ) || ( d->mIntern == true && d->mData.isNull() ) );
116 }
117 
118 void Picture::setUrl( const QString &url )
119 {
120  d->mUrl = url;
121  d->mIntern = false;
122 }
123 
124 void Picture::setData( const QImage &data )
125 {
126  d->mData = data;
127  d->mIntern = true;
128 }
129 
130 void Picture::setType( const QString &type )
131 {
132  d->mType = type;
133 }
134 
135 bool Picture::isIntern() const
136 {
137  return d->mIntern;
138 }
139 
140 QString Picture::url() const
141 {
142  return d->mUrl;
143 }
144 
145 QImage Picture::data() const
146 {
147  return d->mData;
148 }
149 
150 QString Picture::type() const
151 {
152  return d->mType;
153 }
154 
155 QString Picture::toString() const
156 {
157  QString str;
158 
159  str += QLatin1String( "Picture {\n" );
160  str += QString::fromLatin1( " Type: %1\n" ).arg( d->mType );
161  str += QString::fromLatin1( " IsIntern: %1\n" ).
162  arg( d->mIntern ? QLatin1String( "true" ) : QLatin1String( "false" ) );
163  if ( d->mIntern ) {
164  QByteArray data;
165  QBuffer buffer( &data );
166  buffer.open( QIODevice::WriteOnly );
167  d->mData.save( &buffer, "PNG" );
168  str += QString::fromLatin1( " Data: %1\n" ).arg( QString::fromLatin1( data.toBase64() ) );
169  } else {
170  str += QString::fromLatin1( " Url: %1\n" ).arg( d->mUrl );
171  }
172  str += QLatin1String( "}\n" );
173 
174  return str;
175 }
176 
177 QDataStream &KABC::operator<<( QDataStream &s, const Picture &picture )
178 {
179  return s << picture.d->mIntern << picture.d->mUrl << picture.d->mType << picture.d->mData;
180 }
181 
182 QDataStream &KABC::operator>>( QDataStream &s, Picture &picture )
183 {
184  s >> picture.d->mIntern >> picture.d->mUrl >> picture.d->mType >> picture.d->mData;
185 
186  return s;
187 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Dec 10 2012 13:49:02 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kabc

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

kdepimlibs-4.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal