summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/groupwise/libgroupwise/tasks/createcontactinstancetask.cpp
blob: ae1a698407a25635506207dd43524f76bea8e9b8 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
    Kopete Groupwise Protocol
    createcontactinstancetask.h - Request Task that creates an instance of a contact on the server side contact list

    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 "client.h"

#include "createcontactinstancetask.h"

CreateContactInstanceTask::CreateContactInstanceTask(Task* tqparent) : NeedFolderTask(tqparent)
{
	// make the client tell the client app (Kopete) when we receive a contact
	connect( this, TQT_SIGNAL( gotContactAdded( const ContactItem & ) ), client(), TQT_SIGNAL( contactReceived( const ContactItem & ) ) );
}

CreateContactInstanceTask::~CreateContactInstanceTask()
{
}

void CreateContactInstanceTask::contactFromUserId( const TQString & userId, const TQString & displayName, const int tqparentFolder )
{
	contact( new Field::SingleField( NM_A_SZ_USERID, 0, NMFIELD_TYPE_UTF8, userId ), displayName, tqparentFolder );
}

void CreateContactInstanceTask::contactFromUserIdAndFolder( const TQString & userId, const TQString & displayName, const int folderSequence, const TQString & folderDisplayName )
{
	// record the user details
	m_userId = userId;
	m_displayName = displayName;
	// record the folder details
	m_folderSequence = folderSequence;
	m_folderDisplayName = folderDisplayName;
}

void CreateContactInstanceTask::contactFromDN( const TQString & dn, const TQString & displayName, const int tqparentFolder )
{
	contact( new Field::SingleField( NM_A_SZ_DN, 0, NMFIELD_TYPE_UTF8, dn ), displayName, tqparentFolder );
}

void CreateContactInstanceTask::contactFromDNAndFolder( const TQString & dn, const TQString & displayName, const int folderSequence, const TQString & folderDisplayName )
{
	// record the user details
	m_dn = dn;
	m_displayName = displayName;
	// record the folder details
	m_folderSequence = folderSequence;
	m_folderDisplayName = folderDisplayName;
}

void CreateContactInstanceTask::contact( Field::SingleField * id, const TQString & displayName, const int tqparentFolder )
{
	Field::FieldList lst;
	lst.append( new Field::SingleField( NM_A_SZ_PARENT_ID, 0, NMFIELD_TYPE_UTF8, TQString::number( tqparentFolder ) ) );
	// this is either a user Id or a DN
	lst.append( id );
	if ( displayName.isEmpty() ) // fallback so that the contact is created
		lst.append( new Field::SingleField( NM_A_SZ_DISPLAY_NAME, 0, NMFIELD_TYPE_UTF8, m_dn ) );
	else
		lst.append( new Field::SingleField( NM_A_SZ_DISPLAY_NAME, 0, NMFIELD_TYPE_UTF8, displayName ) );
	createTransfer( "createcontact", lst );
}

void CreateContactInstanceTask::onGo()
{
	// are we creating a folder first or can we just proceed as normal?
	if ( m_folderDisplayName.isEmpty() )
		RequestTask::onGo();
	else // create the folder, when the folder has been created, onFolderCreated gets called and creates the contact
		createFolder();
}

void CreateContactInstanceTask::onFolderCreated()
{
	// now the folder exists, perform the requested type of contact instance creation
	if ( m_userId.isEmpty() )
		contact( new Field::SingleField( NM_A_SZ_DN, 0, NMFIELD_TYPE_UTF8, m_dn ), m_displayName, m_folderId );
	else
		contact( new Field::SingleField( NM_A_SZ_USERID, 0, NMFIELD_TYPE_UTF8, m_userId ), m_displayName, m_folderId );
	// send the transfer immediately
	RequestTask::onGo();
}

#include "createcontactinstancetask.moc"