1 /*
2   oscarcontact.h  -  Oscar Protocol Plugin
3 
4   Copyright (c) 2002 by Tom Linsky <twl6@po.cwru.edu>
5   Copyright (c) 2004 by Matt Rogers <matt.rogers@kdemail.net>
6   Kopete    (c) 2002-2004 by the Kopete developers  <kopete-devel@kde.org>
7 
8   *************************************************************************
9   *                                                                       *
10   * This program is free software; you can redistribute it and/or modify  *
11   * it under the terms of the GNU General Public License as published by  *
12   * the Free Software Foundation; either version 2 of the License, or     *
13   * (at your option) any later version.                                   *
14   *                                                                       *
15   *************************************************************************
16   */
17 
18 #ifndef OSCARCONTACT_H
19 #define OSCARCONTACT_H
20 
21 #include <qwidget.h>
22 #include <qdatetime.h>
23 #include <kurl.h>
24 #include "kopetecontact.h"
25 #include "kopetemessage.h"
26 #include "userdetails.h"
27 #include "client.h"
28 #include "oscartypeclasses.h"
29 #include "contact.h"
30 #include "oscar_export.h"
31 
32 namespace Kopete
33 {
34 class ChatSession;
35 class OnlineStatus;
36 }
37 
38 namespace Oscar
39 {
40 class Presence;
41 }
42 
43 class OscarAccount;
44 class QTextCodec;
45 class OscarEncodingSelectionDialog;
46 
47 /**
48  * Contact for oscar protocol
49  * @author Matt Rogers
50  * @TODO Reimplement functions to do the following
51  * \li get the idle time
52  * \li get the real IP for the contact ( DC )
53  * \li get the local IP for the contact
54  * \li get the port for the DC
55  * \li get the sign on time for the contact
56  * \li get the status of authorization for the contact
57  * \li get the status of authoziation for the contact
58  * \li get the user info for the contact
59  * \li check if the contact has a certain capability
60  * \li request authorization from the contact
61  * \li get and set the custom encoding for the contact
62  * \li get and set the SSI group id for the contact
63  * \li get and set whether the contact is server side or not
64  * \li get/set the ignore setting for the contact
65  * \li get/set the visibility setting for the contact ( i.e. are we visible to the contact )
66  */
67 class OSCAR_EXPORT OscarContact : public Kopete::Contact
68 {
69 Q_OBJECT
70 
71 public:
72 	OscarContact( Kopete::Account* account, const QString& name,
73 	              Kopete::MetaContact* parent, const QString& icon = QString() );
74 
75 	virtual ~OscarContact();
76 
77 	void serialize(QMap<QString, QString>&, QMap<QString, QString>&) Q_DECL_OVERRIDE;
78 
79 	Kopete::ChatSession *manager( Kopete::Contact::CanCreateFlags canCreate = Kopete::Contact::CanCreate ) Q_DECL_OVERRIDE;
80 
contactName()81 	const QString &contactName() const { return mName; }
account()82 	OscarAccount *account() const { return mAccount; }
83 
84 	bool isOnServer() const;
85 
86 	virtual void setSSIItem( const OContact& item );
87 	OContact ssiItem() const;
88 
89 	/** we received a typing notification from this contact, tell any message manager */
90 	void startedTyping();
91 	void stoppedTyping();
92 
93 	/**
94 	 * Returns codec for contact's encoding or default one
95 	 * if contact has no encoding
96 	 */
97 	QTextCodec *contactCodec() const;
98 
99 	/**
100 	 * Returns true if contact has this capability
101 	 */
102 	bool hasCap( int capNumber ) const;
103 
104 	/**
105 	 * Set presence target
106 	 * Helper function that converts Oscar::Presence to Kopete::OnlineStatus and sets OnlineStatus.
107 	 */
108 	void setPresenceTarget( const Oscar::Presence &presence );
109 
110 	/**
111 	 * Set encoding for this contact
112 	 * @param mib the MIBenum
113 	 * @note If @p mib is 0 then default encoding will be used
114 	 */
115 	virtual void setEncoding( int mib );
116 
117 public Q_SLOTS:
118 	/** Remove this contact from the server. Reimplemented from Kopete::Contact */
119 	void deleteContact() Q_DECL_OVERRIDE;
120 
121 	/** the metacontact owning this contact changed */
122 	void sync(unsigned int flags) Q_DECL_OVERRIDE;
123 
124 	/** our user info has been updated */
125 	virtual void userInfoUpdated( const QString& contact, const UserDetails& details );
126 
127 	/** a user is online */
128 	virtual void userOnline( const QString& ) = 0;
129 
130 	/** a user is offline */
131 	virtual void userOffline( const QString& ) = 0;
132 
133 	/** send a file to this contact */
134     void sendFile( const QUrl &sourceURL = KUrl(), const QString &fileName = QString(), uint fileSize = 0L ) Q_DECL_OVERRIDE;
135 
136 	/** set a away message */
137 	virtual void setAwayMessage( const QString &message );
138 
139 	/** change contact encoding */
140 	void changeContactEncoding();
141 
142 	void requestAuthorization();
143 
144 protected Q_SLOTS:
145 	void slotTyping( bool typing );
146 	void messageAck( const QString& contact, uint messageId );
147 	void messageError( const QString& contact, uint messageId );
148 
149 protected:
150 	OscarAccount *mAccount;
151 	QString mName;
152 	Kopete::ChatSession *mMsgManager;
153 	UserDetails m_details;
154 	OContact m_ssiItem;
155 	int m_warningLevel;
156 	QString m_clientFeatures;
157 
158 protected Q_SLOTS:
159 	virtual void slotSendMsg( Kopete::Message& msg, Kopete::ChatSession* session);
160 
161 private Q_SLOTS:
162 	void changeEncodingDialogClosed( int );
163 	void chatSessionDestroyed();
164 	void requestBuddyIcon();
165 	void haveIcon( const QString&, QByteArray );
166 	void receivedStatusMessage( const QString& userId, const QString& message );
167 
168 private:
169 	QString filterAwayMessage( const QString &message ) const;
170 	int oscarFontSize( int size ) const;
171 	QString brMargin( int margin, int fontPointSize, bool forceBr = false ) const;
172 
173 	bool m_buddyIconDirty;
174 
175 	OscarEncodingSelectionDialog* m_oesd;
176 };
177 
178 #endif
179