1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/*
ktnefproperty.cpp
Copyright (C) 2002 Michael Goffioul <[email protected]>
This file is part of KTNEF, the KDE TNEF support library/program.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "ktnef/ktnefproperty.h"
#include "mapi.h"
#include <qdatetime.h>
#include <ctype.h>
KTNEFProperty::KTNEFProperty()
{
}
KTNEFProperty::KTNEFProperty( int key_, int type_, const QVariant& value_, const QVariant& name_ )
: _key( key_ ), _type( type_ ), _value( value_ ), _name( name_ )
{
}
KTNEFProperty::KTNEFProperty( const KTNEFProperty& p )
: _key( p._key ), _type( p._type ), _value( p._value ), _name( p._name )
{
}
QString KTNEFProperty::keyString()
{
if ( _name.isValid() )
{
if ( _name.type() == QVariant::String )
return _name.asString();
else
return mapiNamedTagString( _name.asUInt(), _key );
}
else
return mapiTagString( _key );
}
QString KTNEFProperty::formatValue( const QVariant& value, bool beautify )
{
if ( value.type() == QVariant::ByteArray )
{
// check the first bytes (up to 8) if they are
// printable characters
QByteArray arr = value.toByteArray();
bool printable = true;
for ( int i=QMIN( arr.size(), 8 )-1; i>=0 && printable; i-- )
printable = ( isprint( arr[ i ] ) != 0 );
if ( !printable )
{
QString s;
uint i;
uint txtCount = beautify ? QMIN( arr.size(), 32 ) : arr.size();
for ( i=0; i < txtCount; ++i )
{
s.append( QString().sprintf( "%02X", ( uchar )arr[ i ] ) );
if( beautify )
s.append( " " );
}
if ( i < arr.size() )
s.append( "... (size=" + QString::number( arr.size() ) + ")" );
return s;
}
}
//else if ( value.type() == QVariant::DateTime )
// return value.toDateTime().toString();
return value.toString();
}
QString KTNEFProperty::valueString()
{
return formatValue( _value );
}
int KTNEFProperty::key() const
{ return _key; }
int KTNEFProperty::type() const
{ return _type; }
QVariant KTNEFProperty::value() const
{ return _value; }
QVariant KTNEFProperty::name() const
{ return _name; }
bool KTNEFProperty::isVector() const
{ return ( _value.type() == QVariant::List ); }
|