key.cpp
00001 /* 00002 This file is part of libkabc. 00003 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include <kapplication.h> 00022 #include <klocale.h> 00023 00024 #include "key.h" 00025 00026 using namespace KABC; 00027 00028 Key::Key( const QString &text, int type ) 00029 : mTextData( text ), mIsBinary( false ), mType( type ) 00030 { 00031 mId = KApplication::randomString(8); 00032 } 00033 00034 Key::~Key() 00035 { 00036 } 00037 00038 bool Key::operator==( const Key &k ) const 00039 { 00040 if ( mIsBinary != k.mIsBinary ) return false; 00041 if ( mIsBinary ) 00042 if ( mBinaryData != k.mBinaryData ) return false; 00043 else 00044 if ( mTextData != k.mTextData ) return false; 00045 if ( mType != k.mType ) return false; 00046 if ( mCustomTypeString != k.mCustomTypeString ) return false; 00047 00048 return true; 00049 } 00050 00051 bool Key::operator!=( const Key &k ) const 00052 { 00053 return !( k == *this ); 00054 } 00055 00056 void Key::setId( const QString &id ) 00057 { 00058 mId = id; 00059 } 00060 00061 QString Key::id() const 00062 { 00063 return mId; 00064 } 00065 00066 void Key::setBinaryData( const QByteArray &binary ) 00067 { 00068 mBinaryData = binary; 00069 mIsBinary = true; 00070 } 00071 00072 QByteArray Key::binaryData() const 00073 { 00074 return mBinaryData; 00075 } 00076 00077 void Key::setTextData( const QString &text ) 00078 { 00079 mTextData = text; 00080 mIsBinary = false; 00081 } 00082 00083 QString Key::textData() const 00084 { 00085 return mTextData; 00086 } 00087 00088 bool Key::isBinary() const 00089 { 00090 return mIsBinary; 00091 } 00092 00093 void Key::setType( int type ) 00094 { 00095 mType = type; 00096 } 00097 00098 void Key::setCustomTypeString( const QString &custom ) 00099 { 00100 mCustomTypeString = custom; 00101 } 00102 00103 int Key::type() const 00104 { 00105 return mType; 00106 } 00107 00108 QString Key::customTypeString() const 00109 { 00110 return mCustomTypeString; 00111 } 00112 00113 Key::TypeList Key::typeList() 00114 { 00115 TypeList list; 00116 list << X509; 00117 list << PGP; 00118 list << Custom; 00119 00120 return list; 00121 } 00122 00123 QString Key::typeLabel( int type ) 00124 { 00125 switch ( type ) { 00126 case X509: 00127 return i18n( "X509" ); 00128 break; 00129 case PGP: 00130 return i18n( "PGP" ); 00131 break; 00132 case Custom: 00133 return i18n( "Custom" ); 00134 break; 00135 default: 00136 return i18n( "Unknown type" ); 00137 break; 00138 } 00139 } 00140 00141 QDataStream &KABC::operator<<( QDataStream &s, const Key &key ) 00142 { 00143 return s << key.mId << key.mIsBinary << key.mTextData << key.mBinaryData << 00144 key.mCustomTypeString << key.mType; 00145 } 00146 00147 QDataStream &KABC::operator>>( QDataStream &s, Key &key ) 00148 { 00149 s >> key.mId >> key.mIsBinary >> key.mTextData >> key.mBinaryData >> 00150 key.mCustomTypeString >> key.mType; 00151 00152 return s; 00153 }