KTNEF Library
ktnefproperty.cpp
Go to the documentation of this file.00001 /* 00002 ktnefproperty.cpp 00003 00004 Copyright (C) 2002 Michael Goffioul <kdeprint@swing.be> 00005 00006 This file is part of KTNEF, the KDE TNEF support library/program. 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Library General Public 00010 License as published by the Free Software Foundation; either 00011 version 2 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Library General Public License for more details. 00017 00018 You should have received a copy of the GNU Library General Public License 00019 along with this library; see the file COPYING.LIB. If not, write to 00020 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00021 Boston, MA 02110-1301, USA. 00022 */ 00031 #include "ktnefproperty.h" 00032 #include "mapi.h" 00033 00034 #include <QtCore/QDateTime> 00035 00036 #include <ctype.h> 00037 00038 using namespace KTnef; 00039 00040 class KTNEFProperty::Private 00041 { 00042 public: 00043 int _key; 00044 int _type; 00045 QVariant _value; 00046 QVariant _name; 00047 }; 00048 00049 KTNEFProperty::KTNEFProperty() 00050 : d( new Private ) 00051 { 00052 } 00053 00054 KTNEFProperty::KTNEFProperty( int key_, int type_, const QVariant &value_, 00055 const QVariant &name_ ) 00056 : d( new Private ) 00057 { 00058 d->_key = key_; 00059 d->_type = type_; 00060 d->_value = value_; 00061 d->_name = name_; 00062 } 00063 00064 KTNEFProperty::KTNEFProperty( const KTNEFProperty &p ) 00065 : d( new Private ) 00066 { 00067 *d = *p.d; 00068 } 00069 00070 KTNEFProperty::~KTNEFProperty() 00071 { 00072 delete d; 00073 } 00074 00075 KTNEFProperty& KTNEFProperty::operator=( const KTNEFProperty &other ) 00076 { 00077 if ( this != &other ) 00078 *d = *other.d; 00079 00080 return *this; 00081 } 00082 00083 QString KTNEFProperty::keyString() const 00084 { 00085 if ( d->_name.isValid() ) { 00086 if ( d->_name.type() == QVariant::String ) { 00087 return d->_name.toString(); 00088 } else { 00089 return mapiNamedTagString( d->_name.toUInt(), d->_key ); 00090 } 00091 } else { 00092 return mapiTagString( d->_key ); 00093 } 00094 } 00095 00096 QString KTNEFProperty::formatValue( const QVariant &value, bool beautify ) 00097 { 00098 if ( value.type() == QVariant::ByteArray ) { 00099 // check the first bytes (up to 8) if they are 00100 // printable characters 00101 QByteArray arr = value.toByteArray(); 00102 bool printable = true; 00103 for ( int i=qMin( arr.size(), 8 )-1; i>=0 && printable; i-- ) { 00104 printable = ( isprint( arr[ i ] ) != 0 ); 00105 } 00106 if ( !printable ) { 00107 QString s; 00108 int i; 00109 int txtCount = beautify ? qMin( arr.size(), 32 ) : arr.size(); 00110 for ( i=0; i < txtCount; ++i ) { 00111 s.append( QString().sprintf( "%02X", ( uchar )arr[ i ] ) ); 00112 if ( beautify ) { 00113 s.append( " " ); 00114 } 00115 } 00116 if ( i < arr.size() ) { 00117 s.append( "... (size=" + QString::number( arr.size() ) + ')' ); 00118 } 00119 return s; 00120 } 00121 } 00122 //else if ( value.type() == QVariant::DateTime ) 00123 // return value.toDateTime().toString(); 00124 return value.toString(); 00125 } 00126 00127 QString KTNEFProperty::valueString() const 00128 { 00129 return formatValue( d->_value ); 00130 } 00131 00132 int KTNEFProperty::key() const 00133 { 00134 return d->_key; 00135 } 00136 00137 int KTNEFProperty::type() const 00138 { 00139 return d->_type; 00140 } 00141 00142 QVariant KTNEFProperty::value() const 00143 { 00144 return d->_value; 00145 } 00146 00147 QVariant KTNEFProperty::name() const 00148 { 00149 return d->_name; 00150 } 00151 00152 bool KTNEFProperty::isVector() const 00153 { 00154 return ( d->_value.type() == QVariant::List ); 00155 }
KDE 4.0 API Reference