summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/groupwise/libgroupwise/tasks/updatecontacttask.cpp
blob: a1e539d9d56ed628b5f4860725c7d2e5bc3dc6d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
    Kopete Groupwise Protocol
    updatecontacttask.cpp - rename a contact on the server

    Copyright (c) 2004      SUSE Linux AG	 	 http://www.suse.com
    
    Based on Iris, Copyright (C) 2003  Justin Karneges

    Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
 
    *************************************************************************
    *                                                                       *
    * This library is free software; you can redistribute it and/or         *
    * modify it under the terms of the GNU Lesser General Public            *
    * License as published by the Free Software Foundation; either          *
    * version 2 of the License, or (at your option) any later version.      *
    *                                                                       *
    *************************************************************************
*/

#include "gwfield.h" 

#include "updatecontacttask.h"

using namespace GroupWise; 

UpdateContactTask::UpdateContactTask(Task* tqparent): UpdateItemTask(tqparent)
{
}


UpdateContactTask::~UpdateContactTask()
{
}

TQString UpdateContactTask::displayName()
{
	return m_name;
}

void UpdateContactTask::renameContact( const TQString & newName, const TQValueList<ContactItem> & contactInstances )
{
	m_name = newName;
	// build a list of delete, add fields that removes each instance on the server and then readds it with the new name
	Field::FieldList lst;
	const TQValueList<ContactItem>::ConstIterator end = contactInstances.end();
	for( TQValueList<ContactItem>::ConstIterator it = contactInstances.begin(); it != end; ++it )
	{
		Field::FieldList contactFields;
		contactFields.append( new Field::SingleField( NM_A_SZ_OBJECT_ID, 0, NMFIELD_TYPE_UTF8, (*it).id ) );
		contactFields.append( new Field::SingleField( NM_A_SZ_PARENT_ID, 0, NMFIELD_TYPE_UTF8, (*it).parentId ) );
		contactFields.append( new Field::SingleField( NM_A_SZ_SEQUENCE_NUMBER, 0, NMFIELD_TYPE_UTF8, (*it).sequence ) );
		if ( !(*it).dn.isNull() )
			contactFields.append( new Field::SingleField( NM_A_SZ_DN, 0, NMFIELD_TYPE_UTF8, (*it).dn ) );
		if ( !(*it).displayName.isNull() )
			contactFields.append( new Field::SingleField( NM_A_SZ_DISPLAY_NAME, 0, NMFIELD_TYPE_UTF8, (*it).displayName ) );
		lst.append( 
			new Field::MultiField( NM_A_FA_CONTACT, NMFIELD_METHOD_DELETE, 0, NMFIELD_TYPE_ARRAY, contactFields ) );
	}
	for( TQValueList<ContactItem>::ConstIterator it = contactInstances.begin(); it != end; ++it )
	{
		Field::FieldList contactFields;
		contactFields.append( new Field::SingleField( NM_A_SZ_OBJECT_ID, 0, NMFIELD_TYPE_UTF8, (*it).id ) );
		contactFields.append( new Field::SingleField( NM_A_SZ_PARENT_ID, 0, NMFIELD_TYPE_UTF8, (*it).parentId ) );
		contactFields.append( new Field::SingleField( NM_A_SZ_SEQUENCE_NUMBER, 0, NMFIELD_TYPE_UTF8, (*it).sequence ) );
		if ( !(*it).dn.isNull() )
			contactFields.append( new Field::SingleField( NM_A_SZ_DN, 0, NMFIELD_TYPE_UTF8, (*it).dn ) );
		contactFields.append( new Field::SingleField( NM_A_SZ_DISPLAY_NAME, 0, NMFIELD_TYPE_UTF8, newName ) );
		lst.append( 
			new Field::MultiField( NM_A_FA_CONTACT, NMFIELD_METHOD_ADD, 0, NMFIELD_TYPE_ARRAY, contactFields ) );
	}
	//lst.dump( true );
	UpdateItemTask::item( lst );
}

#include "updatecontacttask.moc"