KTnef

ktnefproperty.cpp
Go to the documentation of this file.
1 /*
2  ktnefproperty.cpp
3 
4  SPDX-FileCopyrightText: 2002 Michael Goffioul <[email protected]>
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  */
18 #include "ktnefproperty.h"
19 #include "mapi.h"
20 
21 
22 #include <ctype.h>
23 
24 using namespace KTnef;
25 
26 class KTNEFPropertyPrivate
27 {
28 public:
29  int _key = 0;
30  int _type = 0;
31  QVariant _value;
32  QVariant _name;
33 };
34 
36  : d(new KTNEFPropertyPrivate)
37 {
38 }
39 
40 KTNEFProperty::KTNEFProperty(int key_, int type_, const QVariant &value_,
41  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 {
58  delete d;
59 }
60 
61 KTNEFProperty &KTNEFProperty::operator=(const KTNEFProperty &other)
62 {
63  if (this != &other) {
64  *d = *other.d;
65  }
66 
67  return *this;
68 }
69 
71 {
72  if (d->_name.isValid()) {
73  if (d->_name.type() == QVariant::String) {
74  return d->_name.toString();
75  } else {
76  return mapiNamedTagString(d->_name.toUInt(), d->_key);
77  }
78  } else {
79  return mapiTagString(d->_key);
80  }
81 }
82 
84 {
85  if (value.type() == QVariant::ByteArray) {
86  // check the first bytes (up to 8) if they are
87  // printable characters
88  QByteArray arr = value.toByteArray();
89  bool printable = true;
90  for (int i = qMin(arr.size(), 8) - 1; i >= 0 && printable; i--) {
91  printable = (isprint(arr[ i ]) != 0);
92  }
93  if (!printable) {
94  QString s;
95  int i;
96  int txtCount = beautify ? qMin(arr.size(), 32) : arr.size();
97  for (i = 0; i < txtCount; ++i) {
98  s.append(QString::asprintf("%02X", (uchar)arr[ i ]));
99  if (beautify) {
100  s.append(QLatin1Char(' '));
101  }
102  }
103  if (i < arr.size()) {
104  s.append(QLatin1String("... (size=") + QString::number(arr.size()) + QLatin1Char(')'));
105  }
106  return s;
107  }
108  }
109  //else if ( value.type() == QVariant::DateTime )
110  // return value.toDateTime().toString();
111  return value.toString();
112 }
113 
115 {
116  return formatValue(d->_value);
117 }
118 
120 {
121  return d->_key;
122 }
123 
125 {
126  return d->_type;
127 }
128 
130 {
131  return d->_value;
132 }
133 
135 {
136  return d->_name;
137 }
138 
140 {
141  return d->_value.type() == QVariant::List;
142 }
QByteArray toByteArray() const const
QString & append(QChar ch)
QString asprintf(const char *cformat,...)
KTNEFProperty()
Constructs a TNEF property.
int key() const
Returns the integer key of the property.
QString mapiNamedTagString(int key, int tag=-1)
Convert a keycode to a MAPI named tag string.
Definition: mapi.cpp:210
int type() const
Returns the integer type of the property.
~KTNEFProperty()
Destroys the property.
QString number(int n, int base)
QString valueString() const
Returns the value string of the property.
QVariant value() const
Returns the value of the property.
bool isVector() const
Determines if the property is a vector type.
This file is part of the API for handling TNEF data and provides functions that convert MAPI keycodes...
This file is part of the API for handling TNEF data and defines the KTNEFProperty class...
static QString formatValue(const QVariant &v, bool beautify=true)
Creates a formatted string from the value of the property.
QVariant name() const
Returns the name of the property.
QVariant::Type type() const const
int size() const const
QString toString() const const
Interface for setting MAPI properties.
Definition: ktnefproperty.h:33
QString keyString() const
Returns the key string of the property.
QString mapiTagString(int key)
Convert a keycode to a MAPI tag string.
Definition: mapi.cpp:194
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Nov 27 2020 23:19:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.