summaryrefslogtreecommitdiffstats
path: root/ktnef/lib/ktnefproperty.cpp
blob: df04a388d2a40989ca7c54d659631a482da4f71d (plain)
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 <kdeprint@swing.be>

    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 <tqdatetime.h>
#include <ctype.h>

KTNEFProperty::KTNEFProperty()
{
}

KTNEFProperty::KTNEFProperty( int key_, int type_, const TQVariant& value_, const TQVariant& 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 )
{
}

TQString KTNEFProperty::keyString()
{
	if ( _name.isValid() )
	{
		if ( _name.type() == TQVariant::String )
			return _name.asString();
		else
			return mapiNamedTagString( _name.asUInt(), _key );
	}
	else
		return mapiTagString( _key );
}

TQString KTNEFProperty::formatValue( const TQVariant& value, bool beautify )
{
	if ( value.type() == TQVariant::ByteArray )
	{
		// check the first bytes (up to 8) if they are
		// printable characters
		TQByteArray 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 )
		{
			TQString s;
			uint i;
      uint txtCount = beautify ? QMIN( arr.size(), 32 ) : arr.size();
			for ( i=0; i < txtCount; ++i )
			{
				s.append( TQString().sprintf( "%02X", ( uchar )arr[ i ] ) );
				if( beautify )
					s.append( " " );
			}
			if ( i < arr.size() )
				s.append( "... (size=" + TQString::number( arr.size() ) + ")" );
			return s;
		}
	}
	//else if ( value.type() == TQVariant::DateTime )
	//	return value.toDateTime().toString();
	return value.toString();
}

TQString KTNEFProperty::valueString()
{
	return formatValue( _value );
}

int KTNEFProperty::key() const
{ return _key; }

int KTNEFProperty::type() const
{ return _type; }

TQVariant KTNEFProperty::value() const
{ return _value; }

TQVariant KTNEFProperty::name() const
{ return _name; }

bool KTNEFProperty::isVector() const
{ return ( _value.type() == TQVariant::List ); }