Show invite menu in wlm chat window immediately
[kdenetwork.git] / kopete / protocols / groupwise / libgroupwise / gwfield.cpp
blobde0d930ef72875ca96c8686c4d6b5a83f7f2f61f
1 /*
2 gwfield.cpp - Fields used for Request/Response data in GroupWise
3 Copyright (c) 2004 SUSE Linux AG http://www.suse.com
5 Based on Testbed
6 Copyright (c) 2003 by Will Stephenson <will@stevello.free-online.co.uk>
8 Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
10 *************************************************************************
11 * *
12 * This library is free software; you can redistribute it and/or *
13 * modify it under the terms of the GNU Lesser General Public *
14 * License as published by the Free Software Foundation; either *
15 * version 2 of the License, or (at your option) any later version. *
16 * *
17 *************************************************************************
20 #include <q3cstring.h>
22 #include "gwerror.h"
24 #ifdef LIBGW_USE_KDEBUG
25 #include <kdebug.h>
26 #endif
28 #include "gwfield.h"
29 #include <iostream>
31 using namespace Field;
32 using namespace std;
34 QByteArray Field::NM_A_IP_ADDRESS ("nnmIPAddress");
35 QByteArray Field::NM_A_PORT ("nnmPort");
36 QByteArray Field::NM_A_FA_FOLDER ("NM_A_FA_FOLDER");
37 QByteArray Field::NM_A_FA_CONTACT ("NM_A_FA_CONTACT");
38 QByteArray Field::NM_A_FA_CONVERSATION ("NM_A_FA_CONVERSATION");
39 QByteArray Field::NM_A_FA_MESSAGE ("NM_A_FA_MESSAGE");
40 QByteArray Field::NM_A_FA_CONTACT_LIST ("NM_A_FA_CONTACT_LIST");
41 QByteArray Field::NM_A_FA_RESULTS ("NM_A_FA_RESULTS");
42 QByteArray Field::NM_A_FA_INFO_DISPLAY_ARRAY ("NM_A_FA_INFO_DISPLAY_ARRAY");
43 QByteArray Field::NM_A_FA_USER_DETAILS ("NM_A_FA_USER_DETAILS");
44 QByteArray Field::NM_A_SZ_OBJECT_ID ("NM_A_SZ_OBJECT_ID");
45 QByteArray Field::NM_A_SZ_PARENT_ID ("NM_A_SZ_PARENT_ID");
46 QByteArray Field::NM_A_SZ_SEQUENCE_NUMBER ("NM_A_SZ_SEQUENCE_NUMBER");
47 QByteArray Field::NM_A_SZ_TYPE ("NM_A_SZ_TYPE");
48 QByteArray Field::NM_A_SZ_STATUS ("NM_A_SZ_STATUS");
49 QByteArray Field::NM_A_SZ_STATUS_TEXT ("NM_A_SZ_STATUS_TEXT");
50 QByteArray Field::NM_A_SZ_DN ("NM_A_SZ_DN");
51 QByteArray Field::NM_A_SZ_DISPLAY_NAME ("NM_A_SZ_DISPLAY_NAME");
52 QByteArray Field::NM_A_SZ_USERID ("NM_A_SZ_USERID");
53 QByteArray Field::NM_A_SZ_CREDENTIALS ("NM_A_SZ_CREDENTIALS");
54 QByteArray Field::NM_A_SZ_MESSAGE_BODY ("NM_A_SZ_MESSAGE_BODY");
55 QByteArray Field::NM_A_SZ_MESSAGE_TEXT ("NM_A_SZ_MESSAGE_TEXT");
56 QByteArray Field::NM_A_UD_MESSAGE_TYPE ("NM_A_UD_MESSAGE_TYPE");
57 QByteArray Field::NM_A_FA_PARTICIPANTS ("NM_A_FA_PARTICIPANTS");
58 QByteArray Field::NM_A_FA_INVITES ("NM_A_FA_INVITES");
59 QByteArray Field::NM_A_FA_EVENT ("NM_A_FA_EVENT");
60 QByteArray Field::NM_A_UD_COUNT ("NM_A_UD_COUNT");
61 QByteArray Field::NM_A_UD_DATE ("NM_A_UD_DATE");
62 QByteArray Field::NM_A_UD_EVENT ("NM_A_UD_EVENT");
63 QByteArray Field::NM_A_B_NO_CONTACTS ("NM_A_B_NO_CONTACTS");
64 QByteArray Field::NM_A_B_NO_CUSTOMS ("NM_A_B_NO_CUSTOMS");
65 QByteArray Field::NM_A_B_NO_PRIVACY ("NM_A_B_NO_PRIVACY");
66 QByteArray Field::NM_A_B_ONLY_MODIFIED ("NM_A_B_ONLY_MODIFIED");
67 QByteArray Field::NM_A_UW_STATUS ("NM_A_UW_STATUS");
68 QByteArray Field::NM_A_UD_OBJECT_ID ("NM_A_UD_OBJECT_ID");
69 QByteArray Field::NM_A_SZ_TRANSACTION_ID ("NM_A_SZ_TRANSACTION_ID");
70 QByteArray Field::NM_A_SZ_RESULT_CODE ("NM_A_SZ_RESULT_CODE");
71 QByteArray Field::NM_A_UD_BUILD ("NM_A_UD_BUILD");
72 QByteArray Field::NM_A_SZ_AUTH_ATTRIBUTE ("NM_A_SZ_AUTH_ATTRIBUTE");
73 QByteArray Field::NM_A_UD_KEEPALIVE ("NM_A_UD_KEEPALIVE");
74 QByteArray Field::NM_A_SZ_USER_AGENT ("NM_A_SZ_USER_AGENT");
75 QByteArray Field::NM_A_BLOCKING ("nnmBlocking");
76 QByteArray Field::NM_A_BLOCKING_DENY_LIST ("nnmBlockingDenyList");
77 QByteArray Field::NM_A_BLOCKING_ALLOW_LIST ("nnmBlockingAllowList");
78 QByteArray Field::NM_A_SZ_BLOCKING_ALLOW_ITEM ("NM_A_SZ_BLOCKING_ALLOW_ITEM");
79 QByteArray Field::NM_A_SZ_BLOCKING_DENY_ITEM ("NM_A_SZ_BLOCKING_DENY_ITEM");
80 QByteArray Field::NM_A_LOCKED_ATTR_LIST ("nnmLockedAttrList");
81 QByteArray Field::NM_A_SZ_DEPARTMENT ("OU");
82 QByteArray Field::NM_A_SZ_TITLE ("Title");
83 // GW7
84 QByteArray Field::NM_A_FA_CUSTOM_STATUSES ("NM_A_FA_CUSTOM_STATUSES");
85 QByteArray Field::NM_A_FA_STATUS ("NM_A_FA_STATUS");
86 QByteArray Field::NM_A_UD_QUERY_COUNT ("NM_A_UD_QUERY_COUNT");
87 QByteArray Field::NM_A_FA_CHAT ("NM_A_FA_CHAT");
88 QByteArray Field::NM_A_DISPLAY_NAME ("nnmDisplayName");
89 QByteArray Field::NM_A_CHAT_OWNER_DN ("nnmChatOwnerDN");
90 QByteArray Field::NM_A_UD_PARTICIPANTS ("NM_A_UD_PARTICIPANTS");
91 QByteArray Field::NM_A_DESCRIPTION ("nnmDescription");
92 QByteArray Field::NM_A_DISCLAIMER ("nnmDisclaimer");
93 QByteArray Field::NM_A_QUERY ("nnmQuery");
94 QByteArray Field::NM_A_ARCHIVE ("nnmArchive");
95 QByteArray Field::NM_A_MAX_USERS ("nnmMaxUsers");
96 QByteArray Field::NM_A_SZ_TOPIC ("NM_A_SZ_TOPIC");
97 QByteArray Field::NM_A_FA_CHAT_ACL ("NM_A_FA_CHAT_ACL");
98 QByteArray Field::NM_A_FA_CHAT_ACL_ENTRY ("NM_A_FA_CHAT_ACL_ENTRY");
99 QByteArray Field::NM_A_SZ_ACCESS_FLAGS ("NM_A_SZ_ACCESS_FLAGS");
100 QByteArray Field::NM_A_CHAT_CREATOR_DN ("nnmCreatorDN");
101 QByteArray Field::NM_A_CREATION_TIME ("nnmCreationTime");
102 QByteArray Field::NM_A_UD_CHAT_RIGHTS ("NM_A_UD_CHAT_RIGHTS");
104 QByteArray Field::KOPETE_NM_USER_DETAILS_CN("CN");
105 QByteArray Field::KOPETE_NM_USER_DETAILS_GIVEN_NAME("Given Name");
106 QByteArray Field::KOPETE_NM_USER_DETAILS_SURNAME("Surname");
107 QByteArray Field::KOPETE_NM_USER_DETAILS_ARCHIVE_FLAG("nnmArchive");
108 QByteArray Field::KOPETE_NM_USER_DETAILS_FULL_NAME("Full Name");
111 QByteArray Field::NM_FIELD_TRUE ("1");
112 QByteArray Field::NM_FIELD_FALSE ("0");
114 /* === FieldList ==================================================== */
115 FieldList::~FieldList()
119 FieldListIterator FieldList::find( const QByteArray & tag )
121 FieldListIterator it = begin();
122 return find( it, tag );
125 FieldListIterator FieldList::find( FieldListIterator &it, const QByteArray & tag )
127 FieldListIterator theEnd = end();
128 //qDebug() << "FieldList::find() looking for " << tag << endl;
129 for ( ; it != theEnd; ++it )
131 //qDebug() << " - on '" << (*it)->tag() << "'" << endl;
132 if ( (*it)->tag() == tag )
133 break;
135 return it;
138 int FieldList::findIndex( const QByteArray & tag )
140 FieldListIterator it = begin();
141 FieldListIterator theEnd = end();
142 int index = 0;
143 for ( ; it != theEnd; ++it, ++index )
144 if ( (*it)->tag() == tag )
145 return index;
147 return -1;
150 void FieldList::dump( bool recursive, int offset )
152 const FieldListIterator myEnd = end();
153 //if ( !offset )
154 //kDebug() << ( recursive ? ", recursively" : ", non-recursive" );
155 for( FieldListIterator it = begin(); it != myEnd; ++it )
157 QString s;
158 s.fill(' ', offset*2 );
159 s.append( (*it)->tag() );
160 SingleField * sf;
161 if ( ( sf = dynamic_cast<SingleField*>( *it ) ) )
163 s.append( " :" );
164 s.append( sf->value().toString() );
166 //kDebug() << s;
167 if ( recursive )
169 MultiField * mf;
170 if ( ( mf = dynamic_cast<MultiField*>( *it ) ) )
171 mf->fields().dump( recursive, offset+1 );
176 void FieldList::purge()
178 Field::FieldListIterator it = begin();
179 Field::FieldListIterator theEnd = end();
180 int index = 0;
181 for ( ; it != theEnd; ++it, ++index )
182 delete *it;
185 // THIS IS AN ATTEMPT TO HIDE THE POLYMORPHISM INSIDE THE LIST
186 // HOWEVER IT FAILS BECAUSE WE NEED BOTH THE ITERATOR AND THE CASTED Single|MultiField it points to
188 SingleField * FieldList::findSingleField( const QByteArray & tag )
190 FieldListIterator it = begin();
191 return findSingleField( it, tag );
194 SingleField * FieldList::findSingleField( FieldListIterator &it, const QByteArray & tag )
196 FieldListIterator found = find( it, tag );
197 if ( found == end() )
198 return 0;
199 else
200 return dynamic_cast<SingleField *>( *found );
203 MultiField * FieldList::findMultiField( const QByteArray & tag )
205 FieldListIterator it = begin();
206 return findMultiField( it, tag );
209 MultiField * FieldList::findMultiField( FieldListIterator &it, const QByteArray & tag )
211 FieldListIterator found = find( it, tag );
212 if ( found == end() )
213 return 0;
214 else
215 return dynamic_cast<MultiField *>( *found );
219 /* === FieldBase ========================================================= */
221 FieldBase::FieldBase( const QByteArray & tag, quint8 method, quint8 flags, quint8 type )
222 : m_tag( tag ), m_method( method ), m_flags( flags ), m_type( type )
226 QByteArray FieldBase::tag() const
228 return m_tag;
231 quint8 FieldBase::method() const
233 return m_method;
236 quint8 FieldBase::flags() const
238 return m_flags;
241 quint8 FieldBase::type() const
243 return m_type;
246 void FieldBase::setFlags( const quint8 flags )
248 m_flags = flags;
251 /* === SingleField ========================================================= */
253 SingleField::SingleField( const QByteArray & tag, quint8 method, quint8 flags, quint8 type, QVariant value )
254 : FieldBase( tag, method, flags, type ), m_value( value )
258 SingleField::SingleField( const QByteArray & tag, quint8 flags, quint8 type, QVariant value )
259 : FieldBase( tag, NMFIELD_METHOD_VALID, flags, type ), m_value( value )
263 SingleField::~SingleField()
267 void SingleField::setValue( const QVariant v )
269 m_value = v;
272 QVariant SingleField::value() const
274 return m_value;
277 /* === MultiField ========================================================= */
279 MultiField::MultiField( const QByteArray & tag, quint8 method, quint8 flags, quint8 type, FieldList fields )
280 : FieldBase( tag, method, flags, type ), m_fields( fields )
284 MultiField::MultiField( const QByteArray & tag, quint8 method, quint8 flags, quint8 type )
285 : FieldBase( tag, method, flags, type )
289 MultiField::~MultiField()
291 m_fields.purge();
294 FieldList MultiField::fields() const
296 return m_fields;
299 void MultiField::setFields( FieldList fields )
301 m_fields = fields;