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

KTNEF Library

  • sources
  • kde-4.12
  • kdepimlibs
  • ktnef
ktnefpropertyset.cpp
Go to the documentation of this file.
1 /*
2  ktnefpropertyset.cpp
3 
4  Copyright (C) 2002 Michael Goffioul <kdeprint@swing.be>
5 
6  This file is part of KTNEF, the KDE TNEF support library/program.
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22  */
31 #include "ktnefpropertyset.h"
32 #include "ktnefproperty.h"
33 
34 #include <kdebug.h>
35 
36 #include <QtCore/QList>
37 
38 using namespace KTnef;
39 
40 class KTNEFPropertySet::Private
41 {
42  public:
43  QMap<int,KTNEFProperty*> properties_; // used to store MAPI properties
44  QMap<int,KTNEFProperty*> attributes_; // used to store TNEF attributes
45 };
46 
47 KTNEFPropertySet::KTNEFPropertySet()
48  : d( new Private )
49 {
50 }
51 
52 KTNEFPropertySet::~KTNEFPropertySet()
53 {
54  clear( true );
55 
56  delete d;
57 }
58 
59 void KTNEFPropertySet::addProperty( int key, int type, const QVariant &value,
60  const QVariant &name, bool overwrite )
61 {
62  QMap<int,KTNEFProperty*>::ConstIterator it = d->properties_.constFind( key );
63  if ( it != d->properties_.constEnd() ) {
64  if ( overwrite ) {
65  delete ( *it );
66  } else {
67  return;
68  }
69  }
70  KTNEFProperty *p = new KTNEFProperty( key, type, value, name );
71  d->properties_[ p->key() ] = p;
72 }
73 
74 QString KTNEFPropertySet::findProp( int key, const QString &fallback,
75  bool upper ) const
76 {
77  QMap<int,KTNEFProperty*>::Iterator it = d->properties_.find( key );
78  if ( d->properties_.end() != it ) {
79  return upper ?
80  KTNEFProperty::formatValue( (*it)->value(), false ).toUpper() :
81  KTNEFProperty::formatValue( (*it)->value(), false );
82  } else {
83  return fallback;
84  }
85 }
86 
87 QString KTNEFPropertySet::findNamedProp( const QString &name,
88  const QString &fallback,
89  bool upper ) const
90 {
91  for ( QMap<int,KTNEFProperty*>::Iterator it = d->properties_.begin();
92  it != d->properties_.end();
93  ++it ) {
94  if ( (*it)->name().isValid() ) {
95  QString s;
96  if ( (*it)->name().type() == QVariant::String ) {
97  s = (*it)->name().toString();
98  } else {
99  s = QString().sprintf( "0X%04X", (*it)->name().toUInt() );
100  }
101 
102  if ( s.toUpper() == name.toUpper() ) {
103  QVariant value = ( *it )->value();
104  if ( value.type() == QVariant::List ) {
105  QList<QVariant> l = value.toList();
106  s = "";
107  for ( QList<QVariant>::ConstIterator lit = l.constBegin();
108  lit != l.constEnd();
109  ++lit ) {
110  if ( !s.isEmpty() ) {
111  s += ',';
112  }
113  s += KTNEFProperty::formatValue( *lit, false );
114  }
115  } else {
116  s = KTNEFProperty::formatValue( value, false );
117  }
118  return upper ? s.toUpper() : s;
119  }
120  }
121  }
122  return fallback;
123 }
124 
125 QMap<int,KTNEFProperty*>& KTNEFPropertySet::properties()
126 {
127  return d->properties_;
128 }
129 
130 const QMap<int,KTNEFProperty*>& KTNEFPropertySet::properties() const
131 {
132  return d->properties_;
133 }
134 
135 QVariant KTNEFPropertySet::property( int key ) const
136 {
137  QMap<int,KTNEFProperty*>::ConstIterator it = d->properties_.constFind( key );
138  if ( it == d->properties_.constEnd() ) {
139  return QVariant();
140  } else {
141  return ( *it )->value();
142  }
143 }
144 
145 void KTNEFPropertySet::clear( bool deleteAll )
146 {
147  if ( deleteAll ) {
148  for ( QMap<int,KTNEFProperty*>::ConstIterator it=d->properties_.constBegin();
149  it != d->properties_.constEnd();
150  ++it )
151  delete ( *it );
152  for ( QMap<int,KTNEFProperty*>::ConstIterator it=d->attributes_.constBegin();
153  it != d->attributes_.constEnd();
154  ++it )
155  delete ( *it );
156  }
157  d->properties_.clear();
158  d->attributes_.clear();
159 }
160 
161 void KTNEFPropertySet::addAttribute( int key, int type, const QVariant &value,
162  bool overwrite )
163 {
164  QMap<int,KTNEFProperty*>::ConstIterator it = d->attributes_.constFind( key );
165  if ( it != d->attributes_.constEnd() ) {
166  if ( overwrite ) {
167  delete ( *it );
168  } else {
169  return;
170  }
171  }
172  KTNEFProperty *p = new KTNEFProperty( key, type, value, QVariant() );
173  d->attributes_[ p->key() ] = p;
174 }
175 
176 QMap<int,KTNEFProperty*>& KTNEFPropertySet::attributes()
177 {
178  return d->attributes_;
179 }
180 
181 const QMap<int,KTNEFProperty*>& KTNEFPropertySet::attributes() const
182 {
183  return d->attributes_;
184 }
185 
186 QVariant KTNEFPropertySet::attribute( int key ) const
187 {
188  QMap<int,KTNEFProperty*>::ConstIterator it = d->attributes_.constFind( key );
189  if ( it == d->attributes_.constEnd() ) {
190  return QVariant();
191  } else {
192  return ( *it )->value();
193  }
194 }
KTnef::KTNEFPropertySet::attribute
QVariant attribute(int key) const
Returns the attribute associcated with the specified key.
Definition: ktnefpropertyset.cpp:186
KTnef::KTNEFPropertySet::property
QVariant property(int key) const
Returns the property associcated with the specified key.
Definition: ktnefpropertyset.cpp:135
KTnef::KTNEFPropertySet::addProperty
void addProperty(int key, int type, const QVariant &value, const QVariant &name=QVariant(), bool overwrite=false)
Adds a MAPI property.
Definition: ktnefpropertyset.cpp:59
KTnef::KTNEFPropertySet::findProp
QString findProp(int key, const QString &fallback=QString(), bool convertToUpper=false) const
Finds a property by key, returning a formatted value.
Definition: ktnefpropertyset.cpp:74
KTnef::KTNEFProperty::key
int key() const
Returns the integer key of the property.
Definition: ktnefproperty.cpp:133
KTnef::KTNEFPropertySet::properties
QMap< int, KTNEFProperty * > & properties()
Returns a #QMap of all (key,MAPI) properties.
Definition: ktnefpropertyset.cpp:125
KTnef::KTNEFPropertySet::addAttribute
void addAttribute(int key, int type, const QVariant &value, bool overwrite=false)
Adds a TNEF attribute.
Definition: ktnefpropertyset.cpp:161
KTnef::KTNEFPropertySet::clear
void clear(bool deleteAll=false)
Clears the MAPI and TNEF maps.
Definition: ktnefpropertyset.cpp:145
KTnef::KTNEFPropertySet::findNamedProp
QString findNamedProp(const QString &name, const QString &fallback=QString(), bool convertToUpper=false) const
Finds a property by name, returning a formatted value.
Definition: ktnefpropertyset.cpp:87
ktnefpropertyset.h
This file is part of the API for handling TNEF data and defines the KTNEFPropertySet class...
ktnefproperty.h
This file is part of the API for handling TNEF data and defines the KTNEFProperty class...
KTnef::KTNEFProperty::formatValue
static QString formatValue(const QVariant &v, bool beautify=true)
Creates a formatted string from the value of the property.
Definition: ktnefproperty.cpp:97
KTnef::KTNEFPropertySet::~KTNEFPropertySet
~KTNEFPropertySet()
Destructor.
Definition: ktnefpropertyset.cpp:52
KTnef::KTNEFPropertySet::KTNEFPropertySet
KTNEFPropertySet()
Constructor.
Definition: ktnefpropertyset.cpp:47
KTnef::KTNEFPropertySet::attributes
QMap< int, KTNEFProperty * > & attributes()
Returns a #QMap of all (key,TNEF) attributes.
Definition: ktnefpropertyset.cpp:176
KTnef::KTNEFProperty
Interface for setting MAPI properties.
Definition: ktnefproperty.h:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:01:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KTNEF Library

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

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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