KTnef

ktnefproperty.cpp
Go to the documentation of this file.
1 /*
2  ktnefproperty.cpp
3 
4  Copyright (C) 2002 Michael Goffioul <[email protected]>
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 "ktnefproperty.h"
32 #include "mapi.h"
33 
34 
35 #include <ctype.h>
36 
37 using namespace KTnef;
38 
39 class KTNEFPropertyPrivate
40 {
41 public:
42  int _key = 0;
43  int _type = 0;
44  QVariant _value;
45  QVariant _name;
46 };
47 
49  : d(new KTNEFPropertyPrivate)
50 {
51 }
52 
53 KTNEFProperty::KTNEFProperty(int key_, int type_, const QVariant &value_,
54  const QVariant &name_)
55  : d(new KTNEFPropertyPrivate)
56 {
57  d->_key = key_;
58  d->_type = type_;
59  d->_value = value_;
60  d->_name = name_;
61 }
62 
64  : d(new KTNEFPropertyPrivate)
65 {
66  *d = *p.d;
67 }
68 
70 {
71  delete d;
72 }
73 
74 KTNEFProperty &KTNEFProperty::operator=(const KTNEFProperty &other)
75 {
76  if (this != &other) {
77  *d = *other.d;
78  }
79 
80  return *this;
81 }
82 
84 {
85  if (d->_name.isValid()) {
86  if (d->_name.type() == QVariant::String) {
87  return d->_name.toString();
88  } else {
89  return mapiNamedTagString(d->_name.toUInt(), d->_key);
90  }
91  } else {
92  return mapiTagString(d->_key);
93  }
94 }
95 
97 {
98  if (value.type() == QVariant::ByteArray) {
99  // check the first bytes (up to 8) if they are
100  // printable characters
101  QByteArray arr = value.toByteArray();
102  bool printable = true;
103  for (int i = qMin(arr.size(), 8) - 1; i >= 0 && printable; i--) {
104  printable = (isprint(arr[ i ]) != 0);
105  }
106  if (!printable) {
107  QString s;
108  int i;
109  int txtCount = beautify ? qMin(arr.size(), 32) : arr.size();
110  for (i = 0; i < txtCount; ++i) {
111  s.append(QString::asprintf("%02X", (uchar)arr[ i ]));
112  if (beautify) {
113  s.append(QLatin1Char(' '));
114  }
115  }
116  if (i < arr.size()) {
117  s.append(QLatin1String("... (size=") + QString::number(arr.size()) + QLatin1Char(')'));
118  }
119  return s;
120  }
121  }
122  //else if ( value.type() == QVariant::DateTime )
123  // return value.toDateTime().toString();
124  return value.toString();
125 }
126 
128 {
129  return formatValue(d->_value);
130 }
131 
133 {
134  return d->_key;
135 }
136 
138 {
139  return d->_type;
140 }
141 
143 {
144  return d->_value;
145 }
146 
148 {
149  return d->_name;
150 }
151 
153 {
154  return d->_value.type() == QVariant::List;
155 }
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:223
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:46
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:207
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 30 2020 22:45:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.