KTnef

ktnefpropertyset.cpp
Go to the documentation of this file.
1/*
2 ktnefpropertyset.cpp
3
4 SPDX-FileCopyrightText: 2002 Michael Goffioul <kdeprint@swing.be>
5
6 This file is part of KTNEF, the KDE TNEF support library/program.
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9 */
10/**
11 * @file
12 * This file is part of the API for handling TNEF data and
13 * defines the KTNEFPropertySet class.
14 *
15 * @author Michael Goffioul
16 */
17
18#include "ktnefpropertyset.h"
19#include "ktnefproperty.h"
20
21#include <QList>
22
23using namespace KTnef;
24
25class KTNEFPropertySetPrivate
26{
27public:
28 QMap<int, KTNEFProperty *> properties_; // used to store MAPI properties
29 QMap<int, KTNEFProperty *> attributes_; // used to store TNEF attributes
30};
31
33 : d(new KTNEFPropertySetPrivate)
34{
35}
36
41
42void KTNEFPropertySet::addProperty(int key, int type, const QVariant &value, const QVariant &name, bool overwrite)
43{
44 QMap<int, KTNEFProperty *>::ConstIterator it = d->properties_.constFind(key);
45 if (it != d->properties_.constEnd()) {
46 if (overwrite) {
47 delete (*it);
48 } else {
49 return;
50 }
51 }
52 auto p = new KTNEFProperty(key, type, value, name);
53 d->properties_[p->key()] = p;
54}
55
56QString KTNEFPropertySet::findProp(int key, const QString &fallback, bool upper) const
57{
58 QMap<int, KTNEFProperty *>::Iterator it = d->properties_.find(key);
59 if (d->properties_.end() != it) {
60 return upper ? KTNEFProperty::formatValue((*it)->value(), false).toUpper() : KTNEFProperty::formatValue((*it)->value(), false);
61 } else {
62 return fallback;
63 }
64}
65
66QString KTNEFPropertySet::findNamedProp(const QString &name, const QString &fallback, bool upper) const
67{
68 for (QMap<int, KTNEFProperty *>::Iterator it = d->properties_.begin(), protEnd = d->properties_.end(); it != protEnd; ++it) {
69 if ((*it)->name().isValid()) {
70 QString s;
71 if ((*it)->name().metaType().id() == QMetaType::QString) {
72 s = (*it)->name().toString();
73 } else {
74 s = QString::asprintf("0X%04X", (*it)->name().toUInt());
75 }
76
77 if (s.toUpper() == name.toUpper()) {
78 QVariant value = (*it)->value();
79 if (value.metaType().id() == QMetaType::QVariantList) {
80 QList<QVariant> l = value.toList();
81 s.clear();
82 for (QList<QVariant>::ConstIterator lit = l.constBegin(), litEnd = l.constEnd(); lit != litEnd; ++lit) {
83 if (!s.isEmpty()) {
84 s += QLatin1Char(',');
85 }
86 s += KTNEFProperty::formatValue(*lit, false);
87 }
88 } else {
89 s = KTNEFProperty::formatValue(value, false);
90 }
91 return upper ? s.toUpper() : s;
92 }
93 }
94 }
95 return fallback;
96}
97
99{
100 return d->properties_;
101}
102
104{
105 return d->properties_;
106}
107
109{
110 QMap<int, KTNEFProperty *>::ConstIterator it = d->properties_.constFind(key);
111 if (it == d->properties_.constEnd()) {
112 return {};
113 } else {
114 return (*it)->value();
115 }
116}
117
118void KTNEFPropertySet::clear(bool deleteAll)
119{
120 if (deleteAll) {
121 for (QMap<int, KTNEFProperty *>::ConstIterator it = d->properties_.constBegin(); it != d->properties_.constEnd(); ++it) {
122 delete (*it);
123 }
124 for (QMap<int, KTNEFProperty *>::ConstIterator it = d->attributes_.constBegin(); it != d->attributes_.constEnd(); ++it) {
125 delete (*it);
126 }
127 }
128 d->properties_.clear();
129 d->attributes_.clear();
130}
131
132void KTNEFPropertySet::addAttribute(int key, int type, const QVariant &value, bool overwrite)
133{
134 QMap<int, KTNEFProperty *>::ConstIterator it = d->attributes_.constFind(key);
135 if (it != d->attributes_.constEnd()) {
136 if (overwrite) {
137 delete (*it);
138 } else {
139 return;
140 }
141 }
142 auto p = new KTNEFProperty(key, type, value, QVariant());
143 d->attributes_[p->key()] = p;
144}
145
147{
148 return d->attributes_;
149}
150
152{
153 return d->attributes_;
154}
155
157{
158 QMap<int, KTNEFProperty *>::ConstIterator it = d->attributes_.constFind(key);
159 if (it == d->attributes_.constEnd()) {
160 return {};
161 } else {
162 return (*it)->value();
163 }
164}
QMap< int, KTNEFProperty * > & properties()
Returns a QMap of all (key,MAPI) properties.
QString findProp(int key, const QString &fallback=QString(), bool convertToUpper=false) const
Finds a property by key, returning a formatted value.
QMap< int, KTNEFProperty * > & attributes()
Returns a QMap of all (key,TNEF) attributes.
QString findNamedProp(const QString &name, const QString &fallback=QString(), bool convertToUpper=false) const
Finds a property by name, returning a formatted value.
void clear(bool deleteAll=false)
Clears the MAPI and TNEF maps.
QVariant property(int key) const
Returns the property associated with the specified key.
void addProperty(int key, int type, const QVariant &value, const QVariant &name=QVariant(), bool overwrite=false)
Adds a MAPI property.
void addAttribute(int key, int type, const QVariant &value, bool overwrite=false)
Adds a TNEF attribute.
QVariant attribute(int key) const
Returns the attribute associated with the specified key.
Interface for setting MAPI properties.
static QString formatValue(const QVariant &v, bool beautify=true)
Creates a formatted string from the value of the property.
This file is part of the API for handling TNEF data and defines the KTNEFProperty class.
This file is part of the API for handling TNEF data and defines the KTNEFPropertySet class.
const_iterator constBegin() const const
const_iterator constEnd() const const
ConstIterator
const_iterator constEnd() const const
int id() const const
QString asprintf(const char *cformat,...)
void clear()
bool isEmpty() const const
QString toUpper() const const
void clear()
QMetaType metaType() const const
QList< QVariant > toList() const const
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 11:57:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.