1 /** \file TocBaseEngine.h
2 * \brief Declaration of TocBaseEngine class
4 * Tieto Open Communicator - Client for the Telepathy communications framework.
5 * Copyright (c) 2010, Tieto Corporation
8 * Redistribution and use in source and binary forms, with or without modification,
9 * are permitted provided that the following conditions are met:
11 * Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * Neither the name of the Tieto Corporation nor the names of its contributors
17 * may be used to endorse or promote products derived from this software without
18 * specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "TocBaseEngine"
36 #include <QtTapioca/Connection>
37 #include <QtTapioca/TextChannel>
43 using namespace QtTapioca;
47 /** \brief TocEngine class
49 * Wrapper around the QtTapioca/QtTelepathy communication framework,
50 * responsible for managing opened channels and connection(s),
51 * and for synchronizaion beetween our contact list and the one we get from the telepathy.
53 class TocEngine : public TocBaseEngine
62 TocEngine( QObject * parent = 0 );
73 /** \brief Reimplemented from TocBaseEngine
76 void onPresenceChange(Presence presence, QString description);
78 /** \brief Reimplemented from TocBaseEngine
81 void onAddContactRequest(TocContact* pContact);
83 /** \brief Reimplemented from TocBaseEngine
86 void onEditContactRequest(TocContact* pContact, QString oldUid);
88 /** \brief Reimplemented from TocBaseEngine
91 void onRemoveContactRequest(QString uid);
93 /** \brief Reimplemented from TocBaseEngine
96 void onSubscriptionAccepted(QString /*uid*/, bool /*bAuthorized*/) {}
98 /** \brief Reimplemented from TocBaseEngine
101 void initializeFromSettings();
103 /** \brief Called when User wants to send a message to the contact
105 * @param uid Contact's ID
106 * @param message Message to be sent
108 virtual void onNewMessageReady(QString uid, Message message);
110 /** \brief Closes the channel(s) created for the given contact
112 * When user wants to quit the conversation this slot should be called.
114 * @param uid User ID of the contact
116 virtual void onSessionClosed(QString uid);
120 /** \brief Used when connection status was changed
122 * @param pConnection Handler to QtTapioca connection
123 * @param status Status of connection
124 * @param reason Reason of status change
126 void onStatusChange(QtTapioca::Connection *pConnection, QtTapioca::Connection::Status status, QtTapioca::Connection::Reason reason);
128 /** \brief Used when contact presence was changed
130 * @param pContact Contact item which changed its presence
131 * @param presence Actual contact's presence
132 * @param presenceMessage Actual contact's presence message
134 void onPresenceUpdated(QtTapioca::ContactBase *pContact, QtTapioca::ContactBase::Presence presence, const QString &presenceMessage);
136 /** \brief Used when user presence was changed
138 * @param pContact Contact item which changed its presence
139 * @param presence Actual users's presence
140 * @param presenceMessage Actual users's presence message
142 void onSelfPresenceUpdated(QtTapioca::ContactBase *pContact, QtTapioca::ContactBase::Presence presence, const QString &presenceMessage);
144 /** \brief Used when user receives message
146 * @param pTextChannel Channel from whom we recieved message
147 * @param message received message
149 void onMessageReceived(const QtTapioca::TextChannel* pTextChannel, const QtTapioca::TextChannel::Message &message);
151 /** \brief Used when message has not been sent
153 * When an error occured this slot prepares a Message with a proper 'error' field value
155 * @param message Message for which an error occured
156 * @param error Error type
158 void onMessageDeliveryError(const QtTapioca::TextChannel::Message &message, QtTapioca::TextChannel::Message::DeliveryError error);
160 /** \brief Called when someone wants to initiate chat with user
162 * To receive message that initiated this channel one should call pendingMessages method
164 * @param pConnection Connection on which new channel is created
165 * @param pChannel Newly created channel
166 * @param bSuppresHandler Used to notify other channel handlers that they should not use this channel object
168 void onChannelCreated(QtTapioca::Connection* pConnection, QtTapioca::Channel* pChannel, bool bSuppresHandler);
171 /** \brief Authorizes a contact and add it to users list
173 * TODO: this should be implemented in a way that authorization
174 * depends on user settings
176 * @param pContact Contact to be authorized
178 void onAuthorizationRequested(QtTapioca::Contact *pContact);
182 /** \brief Synchronizes server and local contact lists
184 * Lists should be synchronized according to
185 * the synchronization priority set by user. (NO LONGER TRUE AS THE SYNC PRORITY WILL BE REMOVED)
187 void synchronizeContactLists();
189 /** \brief Adds pending contacts to the list on the server
192 void addPendingContacts();
194 /** \brief Removes pending contacts from the list on the server
197 void removePendingContacts();
199 /** \brief Syncronizes contacts from server to the local list
201 * When contacts from server are edited in a different client
203 * Note that this function SHOULD NOT be run alone,
204 * but ONLY AFTER addition and removal of pending contacts from server
206 void syncContactsFromServer();
208 /** \brief Returns true if a user with the given Uid is already on the list
210 * @param uid Uid of the searched contact
211 * @return index of the contact or -1 if not found
213 int indexForUid( QString uid );
215 /** \brief Removes contact from local contact list
217 * @param uid Uid of the contact to be removed
219 void removeContact( QString uid );
221 /** \brief Adds contact to the local list
223 * @param contact Pointer to the QtTapioca::Contact instance
225 void addContact( const Contact* contact );
229 bool _bNewUserContact; /// Indicates that this is the first status change after initializeFromSettings
230 bool _bContactListSynchronized; /// Indicates if contact list has been already sent to the UI
231 QtTapioca::Connection* _pConnection; /// Active connection
232 TocContactList* _pTocContactList; /// Current contact list
233 QStringList* _pAddedContacts; /// Contacts to be added
234 QStringList* _pRemovedContacts; /// Contacts to be removed
239 #endif // TOCENGINE_H