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 00081 return *this; 00082 } 00083 00084 QString KTNEFProperty::keyString() const 00085 { 00086 if ( d->_name.isValid() ) { 00087 if ( d->_name.type() == QVariant::String ) { 00088 return d->_name.toString(); 00089 } else { 00090 return mapiNamedTagString( d->_name.toUInt(), d->_key ); 00091 } 00092 } else { 00093 return mapiTagString( d->_key ); 00094 } 00095 } 00096 00097 QString KTNEFProperty::formatValue( const QVariant &value, bool beautify ) 00098 { 00099 if ( value.type() == QVariant::ByteArray ) { 00100 // check the first bytes (up to 8) if they are 00101 // printable characters 00102 QByteArray arr = value.toByteArray(); 00103 bool printable = true; 00104 for ( int i=qMin( arr.size(), 8 )-1; i>=0 && printable; i-- ) { 00105 printable = ( isprint( arr[ i ] ) != 0 ); 00106 } 00107 if ( !printable ) { 00108 QString s; 00109 int i; 00110 int txtCount = beautify ? qMin( arr.size(), 32 ) : arr.size(); 00111 for ( i=0; i < txtCount; ++i ) { 00112 s.append( QString().sprintf( "%02X", ( uchar )arr[ i ] ) ); 00113 if ( beautify ) { 00114 s.append( " " ); 00115 } 00116 } 00117 if ( i < arr.size() ) { 00118 s.append( "... (size=" + QString::number( arr.size() ) + ')' ); 00119 } 00120 return s; 00121 } 00122 } 00123 //else if ( value.type() == QVariant::DateTime ) 00124 // return value.toDateTime().toString(); 00125 return value.toString(); 00126 } 00127 00128 QString KTNEFProperty::valueString() const 00129 { 00130 return formatValue( d->_value ); 00131 } 00132 00133 int KTNEFProperty::key() const 00134 { 00135 return d->_key; 00136 } 00137 00138 int KTNEFProperty::type() const 00139 { 00140 return d->_type; 00141 } 00142 00143 QVariant KTNEFProperty::value() const 00144 { 00145 return d->_value; 00146 } 00147 00148 QVariant KTNEFProperty::name() const 00149 { 00150 return d->_name; 00151 } 00152 00153 bool KTNEFProperty::isVector() const 00154 { 00155 return d->_value.type() == QVariant::List; 00156 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:50:02 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:50:02 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.