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"
19using namespace Qt::Literals::StringLiterals;
20
21#include "mapi.h"
22
23#include <cctype>
24
25using namespace KTnef;
26
27class KTNEFPropertyPrivate
28{
29public:
30 int _key = 0;
31 int _type = 0;
32 QVariant _value;
33 QVariant _name;
34};
35
37 : d(new KTNEFPropertyPrivate)
38{
39}
40
41KTNEFProperty::KTNEFProperty(int key_, int type_, const QVariant &value_, const QVariant &name_)
42 : d(new KTNEFPropertyPrivate)
43{
44 d->_key = key_;
45 d->_type = type_;
46 d->_value = value_;
47 d->_name = name_;
48}
49
51 : d(new KTNEFPropertyPrivate)
52{
53 *d = *p.d;
54}
55
57
58KTNEFProperty &KTNEFProperty::operator=(const KTNEFProperty &other)
59{
60 if (this != &other) {
61 *d = *other.d;
62 }
63
64 return *this;
65}
66
68{
69 if (d->_name.isValid()) {
70 if (d->_name.metaType().id() == QMetaType::QString) {
71 return d->_name.toString();
72 } else {
73 return mapiNamedTagString(d->_name.toUInt(), d->_key);
74 }
75 } else {
76 return mapiTagString(d->_key);
77 }
78}
79
80QString KTNEFProperty::formatValue(const QVariant &value, bool beautify)
81{
83 // check the first bytes (up to 8) if they are
84 // printable characters
86 bool printable = true;
87 for (int i = qMin(arr.size(), 8) - 1; i >= 0 && printable; i--) {
88 printable = (isprint(arr[i]) != 0);
89 }
90 if (!printable) {
91 QString s;
92 int i;
93 int txtCount = beautify ? qMin(arr.size(), 32) : arr.size();
94 for (i = 0; i < txtCount; ++i) {
95 s.append(QString::asprintf("%02X", (uchar)arr[i]));
96 if (beautify) {
97 s.append(QLatin1Char(' '));
98 }
99 }
100 if (i < arr.size()) {
101 s.append("... (size="_L1 + QString::number(arr.size()) + QLatin1Char(')'));
102 }
103 return s;
104 }
105 }
106 // else if ( value.type() == QVariant::DateTime )
107 // return value.toDateTime().toString();
108 return value.toString();
109}
110
112{
113 return formatValue(d->_value);
114}
115
117{
118 return d->_key;
119}
120
122{
123 return d->_type;
124}
125
127{
128 return d->_value;
129}
130
132{
133 return d->_name;
134}
135
137{
138 return d->_value.metaType().id() == QMetaType::QVariantList;
139}
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
qsizetype size() const const
int id() const const
QString & append(QChar ch)
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 Mon Nov 18 2024 12:13:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.