1 /*
2 	Kopete Oscar Protocol
3 	ssimodifytask.h - Handles all the ssi modification stuff
4 
5 	Copyright (c) 2004 by Kopete Developers <kopete-devel@kde.org>
6 
7 	Based on code Copyright (c) 2004 SuSE Linux AG <http://www.suse.com>
8 	Based on Iris, Copyright (C) 2003  Justin Karneges <justin@affinix.com>
9 
10 	Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
11 
12 	*************************************************************************
13 	*                                                                       *
14 	* This library is free software; you can redistribute it and/or         *
15 	* modify it under the terms of the GNU Lesser General Public            *
16 	* License as published by the Free Software Foundation; either          *
17 	* version 2 of the License, or (at your option) any later version.      *
18 	*                                                                       *
19 	*************************************************************************
20 */
21 #ifndef SSIMODIFYTASK_H
22 #define SSIMODIFYTASK_H
23 
24 #include "task.h"
25 #include "oscartypes.h"
26 #include "contactmanager.h"
27 #include "contact.h"
28 
29 class Buffer;
30 
31 /**
32 This class takes care of any SSI list modifications that need to be made. This includes:
33 @li adds
34 @li edits
35 @li removes
36 @li group changes
37 @li alias changes
38 @li authorization changes
39 etc.
40 
41 This task implements the following SNACs from the SSI family (0x0013):
42 @li 0x0008
43 @li 0x0009
44 @li 0x000A
45 @li 0x000E
46 @li 0x0011
47 @li 0x0012
48 
49 @author Matt Rogers
50 */
51 class SSIModifyTask : public Task
52 {
53 public:
54     explicit SSIModifyTask( Task* parent, bool staticTask = false );
55     ~SSIModifyTask();
56 
57 	void onGo() Q_DECL_OVERRIDE;
58 	bool take( Transfer* transfer ) Q_DECL_OVERRIDE;
59 
60 	/* Contact properties */
61 	enum OperationType { NoType = 0x00, Add = 0x10, Remove = 0x20, Rename = 0x40, Change = 0x80 };
62 	enum OperationSubject { NoSubject = 0x000, Contact = 0x100, Group = 0x200, Visibility = 0x400, Invisibility = 0x800 };
63 
64 	//! Set up the stuff needed to add a contact.
65 	//! @return true if we can send the packet
66 	bool addContact( const QString& contact, const QString& group, bool requiresAuth = false );
67 
68 	//! Set up the stuff needed to remove a contact.
69 	//! @return true if we can send the packet
70 	bool removeContact( const QString& contact );
71 
72 	//! Set up the stuff needed to change groups
73 	//! @return true if we can send the packet
74 	bool changeGroup( const QString& contact, const QString& newGroup );
75 
76 	/* Group properties */
77 
78 	//! Add a new group to the SSI list
79 	//! @return true if we can send the packet
80 	bool addGroup( const QString& groupName );
81 
82 	//! Remove a group from the SSI list
83 	//! @return true if we can send the packet
84 	bool removeGroup( const QString& groupName );
85 
86 	//! Rename a group on the SSI list
87 	//! @return true if we can send the packet
88 	bool renameGroup( const QString& oldName, const QString& newName );
89 
90 	//! Add an item to the SSI list
91 	//! Should be used for other items we don't have explicit functions for
92 	//! like icon hashs, privacy settings, non-icq contacts, etc.
93 	bool addItem( const OContact& item );
94 
95 	//! Remove an item from the SSI list
96 	//! Should be used for other items we don't have explicit functions for
97 	//! like icon hashs, privacy settings, non-icq contacts, etc.
98 	bool removeItem( const OContact& item );
99 
100 	//! Modify an item on the SSI list
101 	//! Should be used for other items we don't have explicit functions for
102 	//! like icon hashs, privacy settings, non-icq contacts, etc.
103 	bool modifyItem( const OContact& oldItem, const OContact& newItem );
104 
105 	//! Modify an contact item on the SSI list
106 	bool modifyContact( const OContact& oldItem, const OContact& newItem );
107 
108 protected:
109 	bool forMe( const Transfer* transfer ) const Q_DECL_OVERRIDE;
110 
111 private:
112 	//! Handle the acknowledgement from the server
113 	void handleContactAck();
114 
115 	//! Construct and send the packet to send to the server
116 	void sendContactUpdate();
117 
118 	//! Helper function to change the group on the server
119 	void changeGroupOnServer();
120 
121 	//! Update the Contact Manager with the new data
122 	void updateContactManager();
123 
124 	//! Helper function to free id on error
125 	void freeIdOnError();
126 
127 	//! Send the SSI edit start packet
128 	void sendEditStart();
129 
130 	//! Send the SSI edit end packet
131 	void sendEditEnd();
132 
133 	void addItemToBuffer( OContact item, Buffer* buffer );
134 	OContact getItemFromBuffer( Buffer* buffer ) const;
135 
136 	//! Handle server request to add data
137 	void handleContactAdd();
138 
139 	//! Handle server request to update data
140 	void handleContactUpdate();
141 
142 	//! Handle server request to remove data
143 	void handleContactRemove();
144 
145 private:
146 	OContact m_oldItem;
147 	OContact m_newItem;
148 	OContact m_groupItem;
149 	OperationType m_opType;
150 	OperationSubject m_opSubject;
151 	Oscar::DWORD m_id;
152 	ContactManager* m_ssiManager;
153 	bool m_static;
154 
155 };
156 
157 #endif
158 
159