-rw-r--r-- | kabc/key.cpp | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/kabc/key.cpp b/kabc/key.cpp new file mode 100644 index 0000000..802424b --- a/dev/null +++ b/kabc/key.cpp | |||
@@ -0,0 +1,160 @@ | |||
1 | /* | ||
2 | This file is part of libkabc. | ||
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Library General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Library General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Library General Public License | ||
16 | along with this library; see the file COPYING.LIB. If not, write to | ||
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #include <kapplication.h> | ||
29 | #include <klocale.h> | ||
30 | |||
31 | #include "key.h" | ||
32 | |||
33 | using namespace KABC; | ||
34 | |||
35 | Key::Key( const QString &text, int type ) | ||
36 | : mTextData( text ), mIsBinary( false ), mType( type ) | ||
37 | { | ||
38 | mId = KApplication::randomString(8); | ||
39 | } | ||
40 | |||
41 | Key::~Key() | ||
42 | { | ||
43 | } | ||
44 | |||
45 | bool Key::operator==( const Key &k ) const | ||
46 | { | ||
47 | if ( mIsBinary != k.mIsBinary ) return false; | ||
48 | if ( mIsBinary ) | ||
49 | if ( mBinaryData != k.mBinaryData ) return false; | ||
50 | else | ||
51 | if ( mTextData != k.mTextData ) return false; | ||
52 | if ( mType != k.mType ) return false; | ||
53 | if ( mCustomTypeString != k.mCustomTypeString ) return false; | ||
54 | |||
55 | return true; | ||
56 | } | ||
57 | |||
58 | bool Key::operator!=( const Key &k ) const | ||
59 | { | ||
60 | return !( k == *this ); | ||
61 | } | ||
62 | |||
63 | void Key::setId( const QString &id ) | ||
64 | { | ||
65 | mId = id; | ||
66 | } | ||
67 | |||
68 | QString Key::id() const | ||
69 | { | ||
70 | return mId; | ||
71 | } | ||
72 | |||
73 | void Key::setBinaryData( const QByteArray &binary ) | ||
74 | { | ||
75 | mBinaryData = binary; | ||
76 | mIsBinary = true; | ||
77 | } | ||
78 | |||
79 | QByteArray Key::binaryData() const | ||
80 | { | ||
81 | return mBinaryData; | ||
82 | } | ||
83 | |||
84 | void Key::setTextData( const QString &text ) | ||
85 | { | ||
86 | mTextData = text; | ||
87 | mIsBinary = false; | ||
88 | } | ||
89 | |||
90 | QString Key::textData() const | ||
91 | { | ||
92 | return mTextData; | ||
93 | } | ||
94 | |||
95 | bool Key::isBinary() const | ||
96 | { | ||
97 | return mIsBinary; | ||
98 | } | ||
99 | |||
100 | void Key::setType( int type ) | ||
101 | { | ||
102 | mType = type; | ||
103 | } | ||
104 | |||
105 | void Key::setCustomTypeString( const QString &custom ) | ||
106 | { | ||
107 | mCustomTypeString = custom; | ||
108 | } | ||
109 | |||
110 | int Key::type() const | ||
111 | { | ||
112 | return mType; | ||
113 | } | ||
114 | |||
115 | QString Key::customTypeString() const | ||
116 | { | ||
117 | return mCustomTypeString; | ||
118 | } | ||
119 | |||
120 | Key::TypeList Key::typeList() | ||
121 | { | ||
122 | TypeList list; | ||
123 | list << X509; | ||
124 | list << PGP; | ||
125 | list << Custom; | ||
126 | |||
127 | return list; | ||
128 | } | ||
129 | |||
130 | QString Key::typeLabel( int type ) | ||
131 | { | ||
132 | switch ( type ) { | ||
133 | case X509: | ||
134 | return i18n( "X509" ); | ||
135 | break; | ||
136 | case PGP: | ||
137 | return i18n( "PGP" ); | ||
138 | break; | ||
139 | case Custom: | ||
140 | return i18n( "Custom" ); | ||
141 | break; | ||
142 | default: | ||
143 | return i18n( "Unknown type" ); | ||
144 | break; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | QDataStream &KABC::operator<<( QDataStream &s, const Key &key ) | ||
149 | { | ||
150 | return s << key.mId << key.mIsBinary << key.mTextData << key.mBinaryData << | ||
151 | key.mCustomTypeString << key.mType; | ||
152 | } | ||
153 | |||
154 | QDataStream &KABC::operator>>( QDataStream &s, Key &key ) | ||
155 | { | ||
156 | s >> key.mId >> key.mIsBinary >> key.mTextData >> key.mBinaryData >> | ||
157 | key.mCustomTypeString >> key.mType; | ||
158 | |||
159 | return s; | ||
160 | } | ||