1 | // vim: set noet ts=4 sts=4 sw=4 : |
2 | // -*- Mode: c++-mode; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 2; -*- |
3 | // |
4 | // Copyright (C) 2003-2004 Grzegorz Jaskiewicz <gj at pointblue.com.pl> |
5 | // Copyright (C) 2002 Zack Rusin <zack@kde.org> |
6 | // |
7 | // gadusession.h |
8 | // |
9 | // This program is free software; you can redistribute it and/or |
10 | // modify it under the terms of the GNU General Public License |
11 | // as published by the Free Software Foundation; either version 2 |
12 | // of the License, or (at your option) any later version. |
13 | // |
14 | // This program is distributed in the hope that it will be useful, |
15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | // GNU General Public License for more details. |
18 | // |
19 | // You should have received a copy of the GNU General Public License |
20 | // along with this program; if not, write to the Free Software |
21 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
22 | // 02110-1301, USA. |
23 | |
24 | #ifndef GADUSESSION_H |
25 | #define GADUSESSION_H |
26 | |
27 | #include "kopeteaccount.h" |
28 | |
29 | #include <qobject.h> |
30 | #include <qstring.h> |
31 | #include <qstringlist.h> |
32 | #include <qdatetime.h> |
33 | #include <q3cstring.h> |
34 | #include <qhostaddress.h> |
35 | #include <QList> |
36 | |
37 | #include "gaducontactlist.h" |
38 | |
39 | #include <libgadu.h> |
40 | |
41 | struct KGaduMessage { |
42 | QString message; // Unicode |
43 | unsigned int sender_id; // sender's UIN |
44 | QDateTime sendTime; |
45 | QByteArray rtf; |
46 | }; |
47 | |
48 | struct KGaduLoginParams { |
49 | uin_t uin; |
50 | QByteArray password; |
51 | bool useTls; |
52 | int status; |
53 | QString statusDescr; |
54 | unsigned int server; |
55 | bool forFriends; |
56 | unsigned int client_addr; |
57 | unsigned int client_port; |
58 | }; |
59 | |
60 | struct KGaduNotify { |
61 | int status; |
62 | QHostAddress remote_ip; |
63 | unsigned short remote_port; |
64 | bool fileCap; |
65 | int version; |
66 | int image_size; |
67 | int time; |
68 | QString description; |
69 | unsigned int contact_id; |
70 | }; |
71 | |
72 | struct ResLine{ |
73 | unsigned int uin; |
74 | QString firstname; |
75 | QString surname; |
76 | QString nickname; |
77 | QString age; |
78 | QString city; |
79 | QString orgin; |
80 | QString meiden; |
81 | QString gender; |
82 | int status; |
83 | }; |
84 | |
85 | typedef QList<ResLine> SearchResult; |
86 | |
87 | class QSocketNotifier; |
88 | namespace Kopete { class Message; } |
89 | class GaduRichTextFormat; |
90 | |
91 | class GaduSession : public QObject |
92 | { |
93 | Q_OBJECT |
94 | |
95 | public: |
96 | GaduSession( QObject* parent = 0 ); |
97 | virtual ~GaduSession(); |
98 | bool isConnected() const; |
99 | int status() const; |
100 | QString contactsToString( GaduContactsList* contactsList ); |
101 | bool stringToContacts( GaduContactsList& , const QString& ); |
102 | static QString failureDescription( gg_failure_t ); |
103 | static QString errorDescription( int err ); |
104 | static QString stateDescription( int state ); |
105 | void dccRequest( const unsigned int ); |
106 | unsigned int getPersonalInformation(); |
107 | /* |
108 | * Initiates search in public directory, we need to be logged on to perform search ! |
109 | * This returns 0, if you are unable to search (fe you are not logged on, you don't have memory) |
110 | * This does not checks parametrs ! |
111 | * Calling this function more times with the same params, will continue this search as long as |
112 | * @ref pubDirSearchClose() will not be called |
113 | * You must set @ref pubDirSearchResult() signal before calling this function, otherwise no result |
114 | * will be returned |
115 | */ |
116 | unsigned int pubDirSearch( ResLine&, int, int, bool ); |
117 | |
118 | public slots: |
119 | void login( KGaduLoginParams* login ); |
120 | void logoff( Kopete::Account::DisconnectReason reason = Kopete::Account::Manual ); |
121 | int notify( uin_t*, int ); |
122 | int addNotify( uin_t ); |
123 | int removeNotify( uin_t ); |
124 | int sendMessage( uin_t recipient, const Kopete::Message& msg, int msgClass ); |
125 | int changeStatus( int, bool forFriends = false ); |
126 | int changeStatusDescription( int, const QString&, bool forFriends = false ); |
127 | int ping(); |
128 | |
129 | void requestContacts(); |
130 | |
131 | /* |
132 | * Releases all allocated memory needed to perform search. |
133 | * This will be done on each @ref pubDirNewSearch(), if previuos is not released |
134 | */ |
135 | void pubDirSearchClose(); |
136 | void exportContactsOnServer( GaduContactsList* ); |
137 | void deleteContactsOnServer( ); |
138 | bool publishPersonalInformation( ResLine& ); |
139 | |
140 | signals: |
141 | void error( const QString&, const QString& ); |
142 | void messageReceived( KGaduMessage* ); |
143 | void ackReceived( unsigned int ); |
144 | void contactStatusChanged( KGaduNotify* ); |
145 | void pong(); |
146 | void connectionFailed( gg_failure_t failure ); |
147 | void connectionSucceed( ); |
148 | void disconnect( Kopete::Account::DisconnectReason ); |
149 | void pubDirSearchResult( const SearchResult&, unsigned int ); |
150 | void userListRecieved( const QString& ); |
151 | void userListExported(); |
152 | void userListDeleted(); |
153 | void incomingCtcp( unsigned int ); |
154 | |
155 | protected slots: |
156 | void enableNotifiers( int ); |
157 | void disableNotifiers(); |
158 | void checkDescriptor(); |
159 | void login( struct gg_login_params* ); |
160 | |
161 | private: |
162 | |
163 | void sendResult( gg_pubdir50_t ); |
164 | void handleUserlist( gg_event* ); |
165 | void notify60( gg_event* ); |
166 | void destroySession(); |
167 | void destroyNotifiers(); |
168 | void createNotifiers( bool connect ); |
169 | |
170 | gg_session* session_; |
171 | QSocketNotifier* read_; |
172 | QSocketNotifier* write_; |
173 | gg_login_params params_; |
174 | QTextCodec* textcodec; |
175 | int searchSeqNr_; |
176 | bool deletingUserList; |
177 | GaduRichTextFormat* rtf; |
178 | }; |
179 | |
180 | #endif |
181 | |