libkcal

attachment.cpp
1/*
2 This file is part of libkcal.
3
4 Copyright (c) 2002 Michael Brade <brade@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#include "attachment.h"
23#include <kmdcodec.h>
24
25using namespace KCal;
26
28{
29 mSize = attachment.mSize;
30 mMimeType = attachment.mMimeType;
31 mUri = attachment.mUri;
32 mData = tqstrdup( attachment.mData );
33 mLabel = attachment.mLabel;
34 mBinary = attachment.mBinary;
35 mLocal = attachment.mLocal;
36 mShowInline = attachment.mShowInline;
37}
38
39Attachment::Attachment( const TQString &uri, const TQString &mime )
40{
41 mSize = 0;
42 mMimeType = mime;
43 mUri = uri;
44 mData = 0;
45 mBinary = false;
46 mLocal = false;
47 mShowInline = false;
48}
49
50Attachment::Attachment( const char *base64, const TQString &mime )
51{
52 mSize = 0;
53 mMimeType = mime;
54 mData = tqstrdup( base64 );
55 mBinary = true;
56 mLocal = false;
57 mShowInline = false;
58}
59
60Attachment::~Attachment()
61{
62 delete[] mData;
63}
64
65bool Attachment::isUri() const
66{
67 return !mBinary;
68}
69
70TQString Attachment::uri() const
71{
72 if ( !mBinary ) {
73 return mUri;
74 } else {
75 return TQString();
76 }
77}
78
79void Attachment::setUri( const TQString &uri )
80{
81 mUri = uri;
82 mBinary = false;
83}
84
85bool Attachment::isBinary() const
86{
87 return mBinary;
88}
89
90char *Attachment::data() const
91{
92 if ( mBinary ) {
93 return mData;
94 } else {
95 return 0;
96 }
97}
98
99TQByteArray &Attachment::decodedData()
100{
101 if ( mDataCache.isNull() && mData ) {
102 // base64Decode() sometimes appends a null byte when called
103 // with a TQCString so work on TQByteArray's instead
104 TQByteArray encoded;
105 encoded.duplicate( mData, strlen( mData ) );
106 TQByteArray decoded;
107 KCodecs::base64Decode( encoded, decoded );
108 mDataCache = decoded;
109 }
110
111 return mDataCache;
112}
113
114void Attachment::setDecodedData( const TQByteArray &data )
115{
116 TQByteArray encoded;
117 KCodecs::base64Encode( data, encoded );
118
119 encoded.resize( encoded.count() + 1 );
120 encoded[encoded.count()-1] = '\0';
121
122 setData( encoded.data() );
123 mDataCache = data;
124 mSize = mDataCache.size();
125}
126
127void Attachment::setData( const char *base64 )
128{
129 delete[] mData;
130 mData = tqstrdup( base64 );
131 mBinary = true;
132 mDataCache = TQByteArray();
133 mSize = 0;
134}
135
136uint Attachment::size()
137{
138 if ( isUri() ) {
139 return 0;
140 }
141 if ( !mSize ) {
142 mSize = decodedData().size();
143 }
144
145 return mSize;
146}
147
148TQString Attachment::mimeType() const
149{
150 return mMimeType;
151}
152
153void Attachment::setMimeType(const TQString& mime)
154{
155 mMimeType = mime;
156}
157
158bool Attachment::showInline() const
159{
160 return mShowInline;
161}
162
163void Attachment::setShowInline( bool showinline )
164{
165 mShowInline = showinline;
166}
167
168TQString Attachment::label() const
169{
170 return mLabel;
171}
172
173void Attachment::setLabel( const TQString& label )
174{
175 mLabel = label;
176}
177
179{
180 return mLocal;
181}
182
183void Attachment::setLocal( bool local )
184{
185 mLocal = local;
186}
This class represents information related to an attachment.
Definition attachment.h:35
Attachment(const Attachment &attachment)
Create a Reference to some URI by copying an existing Attachment.
bool isLocal() const
Returns the attachment "local" flag.
void setLocal(bool local)
Sets the attachment "local" option, which is derived from the Calendar Incidence X-KONTACT-TYPE param...
Namespace KCal is for global classes, objects and/or functions in libkcal.
Definition alarm.h:38