KTnef

ktnefproperty.cpp
Go to the documentation of this file.
1/*
2 ktnefproperty.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 KTNEFProperty class.
14 *
15 * @author Michael Goffioul
16 */
17
18#include "ktnefproperty.h"
19#include "mapi.h"
20
21#include <cctype>
22
23using namespace KTnef;
24
25class KTNEFPropertyPrivate
26{
27public:
28 int _key = 0;
29 int _type = 0;
30 QVariant _value;
31 QVariant _name;
32};
33
35 : d(new KTNEFPropertyPrivate)
36{
37}
38
39KTNEFProperty::KTNEFProperty(int key_, int type_, const QVariant &value_, const QVariant &name_)
40 : d(new KTNEFPropertyPrivate)
41{
42 d->_key = key_;
43 d->_type = type_;
44 d->_value = value_;
45 d->_name = name_;
46}
47
49 : d(new KTNEFPropertyPrivate)
50{
51 *d = *p.d;
52}
53
55
56KTNEFProperty &KTNEFProperty::operator=(const KTNEFProperty &other)
57{
58 if (this != &other) {
59 *d = *other.d;
60 }
61
62 return *this;
63}
64
66{
67 if (d->_name.isValid()) {
68 if (d->_name.metaType().id() == QMetaType::QString) {
69 return d->_name.toString();
70 } else {
71 return mapiNamedTagString(d->_name.toUInt(), d->_key);
72 }
73 } else {
74 return mapiTagString(d->_key);
75 }
76}
77
78QString KTNEFProperty::formatValue(const QVariant &value, bool beautify)
79{
81 // check the first bytes (up to 8) if they are
82 // printable characters
84 bool printable = true;
85 for (int i = qMin(arr.size(), 8) - 1; i >= 0 && printable; i--) {
86 printable = (isprint(arr[i]) != 0);
87 }
88 if (!printable) {
89 QString s;
90 int i;
91 int txtCount = beautify ? qMin(arr.size(), 32) : arr.size();
92 for (i = 0; i < txtCount; ++i) {
93 s.append(QString::asprintf("%02X", (uchar)arr[i]));
94 if (beautify) {
95 s.append(QLatin1Char(' '));
96 }
97 }
98 if (i < arr.size()) {
99 s.append(QLatin1StringView("... (size=") + QString::number(arr.size()) + QLatin1Char(')'));
100 }
101 return s;
102 }
103 }
104 // else if ( value.type() == QVariant::DateTime )
105 // return value.toDateTime().toString();
106 return value.toString();
107}
108
110{
111 return formatValue(d->_value);
112}
113
115{
116 return d->_key;
117}
118
120{
121 return d->_type;
122}
123
125{
126 return d->_value;
127}
128
130{
131 return d->_name;
132}
133
135{
136 return d->_value.metaType().id() == QMetaType::QVariantList;
137}
Interface for setting MAPI properties.
int type() const
Returns the integer type of the property.
QString valueString() const
Returns the value string of the property.
int key() const
Returns the integer key of the property.
bool isVector() const
Determines if the property is a vector type.
QVariant name() const
Returns the name of the property.
QVariant value() const
Returns the value of the property.
KTNEFProperty()
Constructs a TNEF property.
~KTNEFProperty()
Destroys the property.
static QString formatValue(const QVariant &v, bool beautify=true)
Creates a formatted string from the value of the property.
QString keyString() const
Returns the key string 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 provides functions that convert MAPI keycodes...
QString mapiTagString(int key)
Convert a keycode to a MAPI tag string.
Definition mapi.cpp:190
QString mapiNamedTagString(int key, int tag=-1)
Convert a keycode to a MAPI named tag string.
Definition mapi.cpp:205
int id() const const
QString asprintf(const char *cformat,...)
QString number(double n, char format, int precision)
QMetaType metaType() const const
QByteArray toByteArray() const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:42 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.