From bcb704366cb5e333a626c18c308c7e0448a8e69f Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kopete/protocols/yahoo/yahoochatsession.cpp | 166 ++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 kopete/protocols/yahoo/yahoochatsession.cpp (limited to 'kopete/protocols/yahoo/yahoochatsession.cpp') diff --git a/kopete/protocols/yahoo/yahoochatsession.cpp b/kopete/protocols/yahoo/yahoochatsession.cpp new file mode 100644 index 00000000..0402c400 --- /dev/null +++ b/kopete/protocols/yahoo/yahoochatsession.cpp @@ -0,0 +1,166 @@ +/* + yahoochatsession.cpp - Yahoo! Message Manager + + Copyright (c) 2005 by André Duffeck + + ************************************************************************* + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "yahoochatsession.h" + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kopetecontactaction.h" +#include "kopetemetacontact.h" +#include "kopetecontactlist.h" +#include "kopetechatsessionmanager.h" +#include "kopeteuiglobal.h" +#include "kopeteglobal.h" +#include "kopeteview.h" + +#include "yahoocontact.h" +#include "yahooaccount.h" + +YahooChatSession::YahooChatSession( Kopete::Protocol *protocol, const Kopete::Contact *user, + Kopete::ContactPtrList others, const char *name ) +: Kopete::ChatSession( user, others, protocol, name ) +{ + kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl; + Kopete::ChatSessionManager::self()->registerChatSession( this ); + setInstance(protocol->instance()); + + // Add Actions + new KAction( i18n( "Buzz Contact" ), QIconSet(BarIcon("bell")), "Ctrl+G", this, SLOT( slotBuzzContact() ), actionCollection(), "yahooBuzz" ) ; + new KAction( i18n( "Show User Info" ), QIconSet(BarIcon("idea")), 0, this, SLOT( slotUserInfo() ), actionCollection(), "yahooShowInfo" ) ; + new KAction( i18n( "Request Webcam" ), QIconSet(BarIcon("webcamreceive")), 0, this, SLOT( slotRequestWebcam() ), actionCollection(), "yahooRequestWebcam" ) ; + new KAction( i18n( "Invite to view your Webcam" ), QIconSet(BarIcon("webcamsend")), 0, this, SLOT( slotInviteWebcam() ), actionCollection(), "yahooSendWebcam" ) ; + new KAction( i18n( "Send File" ), QIconSet(BarIcon("attach")), 0, this, SLOT( slotSendFile() ), actionCollection(), "yahooSendFile" ); + + YahooContact *c = static_cast( others.first() ); + connect( c, SIGNAL( displayPictureChanged() ), this, SLOT( slotDisplayPictureChanged() ) ); + m_image = new QLabel( 0L, "kde toolbar widget" ); + new KWidgetAction( m_image, i18n( "Yahoo Display Picture" ), 0, this, SLOT( slotDisplayPictureChanged() ), actionCollection(), "yahooDisplayPicture" ); + if(c->hasProperty(Kopete::Global::Properties::self()->photo().key()) ) + { + connect( Kopete::ChatSessionManager::self() , SIGNAL(viewActivated(KopeteView* )) , this, SLOT(slotDisplayPictureChanged()) ); + } + else + { + m_image = 0L; + } + + setXMLFile("yahoochatui.rc"); +} + +YahooChatSession::~YahooChatSession() +{ + delete m_image; +} + +void YahooChatSession::slotBuzzContact() +{ + kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl; + QPtrListcontacts = members(); + static_cast(contacts.first())->buzzContact(); +} + +void YahooChatSession::slotUserInfo() +{ + kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl; + QPtrListcontacts = members(); + static_cast(contacts.first())->slotUserInfo(); +} + +void YahooChatSession::slotRequestWebcam() +{ + kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl; + QPtrListcontacts = members(); + static_cast(contacts.first())->requestWebcam(); +} + +void YahooChatSession::slotInviteWebcam() +{ + kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl; + QPtrListcontacts = members(); + static_cast(contacts.first())->inviteWebcam(); +} + +void YahooChatSession::slotSendFile() +{ + kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl; + QPtrListcontacts = members(); + static_cast(contacts.first())->sendFile(); +} + +void YahooChatSession::slotDisplayPictureChanged() +{ + kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl; + QPtrList mb=members(); + YahooContact *c = static_cast( mb.first() ); + if ( c && m_image ) + { + if(c->hasProperty(Kopete::Global::Properties::self()->photo().key())) + { + int sz=22; + // get the size of the toolbar were the aciton is plugged. + // if you know a better way to get the toolbar, let me know + KMainWindow *w= view(false) ? dynamic_cast( view(false)->mainWidget()->topLevelWidget() ) : 0L; + if(w) + { + //We connected that in the constructor. we don't need to keep this slot active. + disconnect( Kopete::ChatSessionManager::self() , SIGNAL(viewActivated(KopeteView* )) , this, SLOT(slotDisplayPictureChanged()) ); + + QPtrListIterator it=w->toolBarIterator() ; + KAction *imgAction=actionCollection()->action("yahooDisplayPicture"); + if(imgAction) while(it) + { + KToolBar *tb=*it; + if(imgAction->isPlugged(tb)) + { + sz=tb->iconSize(); + //ipdate if the size of the toolbar change. + disconnect(tb, SIGNAL(modechange()), this, SLOT(slotDisplayPictureChanged())); + connect(tb, SIGNAL(modechange()), this, SLOT(slotDisplayPictureChanged())); + break; + } + ++it; + } + } + QString imgURL=c->property(Kopete::Global::Properties::self()->photo()).value().toString(); + QImage scaledImg = QPixmap( imgURL ).convertToImage().smoothScale( sz, sz ); + if(!scaledImg.isNull()) + m_image->setPixmap( scaledImg ); + else + { //the image has maybe not been transfered correctly.. force to download again + c->removeProperty(Kopete::Global::Properties::self()->photo()); + //slotDisplayPictureChanged(); //don't do that or we might end in a infinite loop + } + QToolTip::add( m_image, "" ); + } + } +} + +#include "yahoochatsession.moc" -- cgit v1.2.1