kimproxy.h
00001 /* 00002 kimproxy.h 00003 00004 IM service library for KDE 00005 00006 Copyright (c) 2004 Will Stephenson <lists@stevello.free-online.co.uk> 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Library General Public 00010 License as published by the Free Software Foundation; either 00011 version 2 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Library General Public License for more details. 00017 00018 You should have received a copy of the GNU Library General Public License 00019 along with this library; see the file COPYING.LIB. If not, write to 00020 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00021 Boston, MA 02110-1301, USA. 00022 */ 00023 00024 #ifndef KIMPROXY_H 00025 #define KIMPROXY_H 00026 00027 #include <tqdict.h> 00028 #include <tqmap.h> 00029 #include <tqptrdict.h> 00030 #include <tqstringlist.h> 00031 00032 00033 #define IM_SERVICE_TYPE "DCOP/InstantMessenger" 00034 #define IM_CLIENT_PREFERENCES_FILE "default_components" 00035 #define IM_CLIENT_PREFERENCES_SECTION "InstantMessenger" 00036 #define IM_CLIENT_PREFERENCES_ENTRY "imClient" 00037 00038 #include "kimproxyiface.h" 00039 00040 class DCOPClient; 00041 class KIMIface_stub; 00042 class KURL; 00043 class ContactPresenceListCurrent; 00044 00046 typedef TQMap<TQCString, int> AppPresence; // appId->presence; contains all applications' ideas of a user's presence 00047 typedef TQDict<AppPresence> PresenceMap; // uid->AppPresence; contains a AppPresences for all users 00049 typedef TQMap<TQString, ContactPresenceListCurrent> PresenceStringMap; 00050 00107 class KIMPROXY_EXPORT KIMProxy : public TQObject, virtual public KIMProxyIface 00108 { 00109 Q_OBJECT 00110 struct Private; 00111 00112 template<class> friend class KStaticDeleter; 00113 ~KIMProxy(); 00114 00115 public: 00131 static KIMProxy * instance( DCOPClient * client ); 00132 00147 bool initialize(); 00148 00166 TQStringList allContacts(); 00167 00182 TQStringList reachableContacts(); 00183 00202 TQStringList onlineContacts(); 00203 00224 TQStringList fileTransferContacts(); 00225 00244 bool isPresent( const TQString& uid ); 00245 00266 TQString displayName( const TQString& uid ); 00267 00307 int presenceNumeric( const TQString& uid ); 00308 00343 TQString presenceString( const TQString& uid ); 00344 00372 TQPixmap presenceIcon( const TQString& uid ); 00373 00389 bool canReceiveFiles( const TQString & uid ); 00390 00414 bool canRespond( const TQString & uid ); 00415 00432 TQString locate( const TQString & contactId, const TQString & protocol ); 00433 00454 TQString context( const TQString & uid ); 00455 00467 void chatWithContact( const TQString& uid ); 00468 00484 void messageContact( const TQString& uid, const TQString& message ); 00485 00503 void sendFile(const TQString &uid, const KURL &sourceURL, 00504 const TQString &altFileName = TQString::null, uint fileSize = 0); 00505 00519 bool addContact( const TQString &contactId, const TQString &protocol ); 00520 00533 bool imAppsAvailable(); 00534 00540 bool startPreferredApp(); 00541 00545 void contactPresenceChanged( TQString uid, TQCString appId, int presence ); 00546 00547 public slots: 00560 void registeredToDCOP( const TQCString& appId ); 00561 00579 void unregisteredFromDCOP( const TQCString& appId ); 00580 signals: 00591 void sigContactPresenceChanged( const TQString &uid ); 00592 00600 void sigPresenceInfoExpired(); 00601 protected: 00605 void pollApp( const TQCString & appId ); 00609 void pollAll( const TQString &uid ); 00610 00614 bool updatePresence( const TQString &uid, const TQCString &appId, int presence ); 00615 00619 TQString preferredApp(); 00620 00624 KIMIface_stub * stubForUid( const TQString &uid ); 00625 00630 KIMIface_stub * stubForProtocol( const TQString &protocol ); 00631 00632 private: 00633 // client stubs used to get presence 00634 // appId (from DCOP) -> KIMIface_stub 00635 TQDict<KIMIface_stub> m_im_client_stubs; 00636 // map containing numeric presence and the originating application ID for each KABC uid we know of 00637 // KABC Uid -> (appId, numeric presence )(AppPresence) 00638 PresenceMap m_presence_map; 00639 // cache of the client strings in use by each application 00640 // dictionary of KIMIface_stub -> map of numeric presence -> string presence 00641 // FIXME: remove for KDE4 - UNUSED but maintained for binary compatibility in KDE 3.4 00642 TQPtrDict<int> m_client_presence_strings; 00643 Private * d; 00644 bool m_apps_available; 00645 bool m_initialized; 00649 KIMProxy( DCOPClient * client); 00650 static KIMProxy * s_instance; 00651 }; 00652 00653 #endif 00654