2 testbedaccount.cpp - Kopete Testbed Protocol
4 Copyright (c) 2003 by Will Stephenson <will@stevello.free-online.co.uk>
5 Kopete (c) 2002-2003 by the Kopete developers <kopete-devel@kde.org>
7 *************************************************************************
9 * This library is free software; you can redistribute it and/or *
10 * modify it under the terms of the GNU General Public *
11 * License as published by the Free Software Foundation; either *
12 * version 2 of the License, or (at your option) any later version. *
14 *************************************************************************
18 #include "testbedaccount.h"
23 #include <kactionmenu.h>
27 #include "kopetemetacontact.h"
28 #include "kopetecontactlist.h"
30 #include "testbedcontact.h"
31 #include "testbedfakeserver.h"
32 #include "testbedprotocol.h"
35 TestbedAccount::TestbedAccount( TestbedProtocol
*parent
, const QString
& accountID
)
36 : Kopete::Account ( parent
, accountID
)
38 // Init the myself contact
39 setMyself( new TestbedContact( this, accountId(), accountId(), Kopete::ContactList::self()->myself() ) );
40 myself()->setOnlineStatus( TestbedProtocol::protocol()->testbedOffline
);
41 m_server
= new TestbedFakeServer();;
44 TestbedAccount::~TestbedAccount()
49 void TestbedAccount::fillActionMenu( KActionMenu
*actionMenu
)
51 Kopete::Account::fillActionMenu( actionMenu
);
53 actionMenu
->addSeparator();
57 action
= new KAction (KIcon("testbed_showvideo"), i18n ("Show my own video..."), actionMenu
);
58 //, "actionShowVideo");
59 QObject::connect( action
, SIGNAL(triggered(bool)), this, SLOT(slotShowVideo()) );
60 actionMenu
->addAction(action
);
61 action
->setEnabled( isConnected() );
64 bool TestbedAccount::createContact(const QString
& contactId
, Kopete::MetaContact
* parentContact
)
66 TestbedContact
* newContact
= new TestbedContact( this, contactId
, parentContact
->displayName(), parentContact
);
67 return newContact
!= 0L;
70 void TestbedAccount::setAway( bool away
, const QString
& /* reason */ )
78 void TestbedAccount::setOnlineStatus(const Kopete::OnlineStatus
& status
, const Kopete::StatusMessage
&reason
)
80 if ( status
.status() == Kopete::OnlineStatus::Online
&&
81 myself()->onlineStatus().status() == Kopete::OnlineStatus::Offline
)
83 else if (status
.status() == Kopete::OnlineStatus::Online
&&
84 myself()->onlineStatus().status() == Kopete::OnlineStatus::Away
)
85 setAway( false, reason
.message() );
86 else if ( status
.status() == Kopete::OnlineStatus::Offline
)
88 else if ( status
.status() == Kopete::OnlineStatus::Away
)
89 slotGoAway( /* reason */ );
92 void TestbedAccount::setStatusMessage(const Kopete::StatusMessage
& statusMessage
)
94 Q_UNUSED(statusMessage
);
95 /* Not used in testbed */
98 void TestbedAccount::connect( const Kopete::OnlineStatus
& /* initialStatus */ )
101 myself()->setOnlineStatus( TestbedProtocol::protocol()->testbedOnline
);
102 QObject::connect ( m_server
, SIGNAL ( messageReceived( const QString
& ) ),
103 this, SLOT ( receivedMessage( const QString
& ) ) );
106 void TestbedAccount::disconnect()
109 myself()->setOnlineStatus( TestbedProtocol::protocol()->testbedOffline
);
110 QObject::disconnect ( m_server
, 0, 0, 0 );
113 TestbedFakeServer
* TestbedAccount::server()
118 void TestbedAccount::slotGoOnline ()
125 myself()->setOnlineStatus( TestbedProtocol::protocol()->testbedOnline
);
126 updateContactStatus();
129 void TestbedAccount::slotGoAway ()
136 myself()->setOnlineStatus( TestbedProtocol::protocol()->testbedAway
);
137 updateContactStatus();
141 void TestbedAccount::slotGoOffline ()
147 updateContactStatus();
150 void TestbedAccount::slotShowVideo ()
156 TestbedWebcamDialog
*testbedWebcamDialog
= new TestbedWebcamDialog(0, 0);
157 Q_UNUSED(testbedWebcamDialog
);
159 updateContactStatus();
162 void TestbedAccount::receivedMessage( const QString
&message
)
164 // Look up the contact the message is from
166 TestbedContact
* messageSender
;
168 from
= message
.section( ':', 0, 0 );
169 Kopete::Contact
* contact
= contacts()[from
];
170 messageSender
= dynamic_cast<TestbedContact
*>( contact
);
172 kDebug( 14210 ) << " got a message from " << from
<< ", " << messageSender
<< ", is: " << message
;
173 // Pass it on to the contact to process and display via a KMM
175 messageSender
->receivedMessage( message
);
177 kWarning(14210) << "unable to look up contact for delivery";
180 void TestbedAccount::updateContactStatus()
182 QHashIterator
<QString
, Kopete::Contact
*>itr( contacts() );
183 for ( ; itr
.hasNext(); ) {
185 itr
.value()->setOnlineStatus( myself()->onlineStatus() );
190 #include "testbedaccount.moc"