implement update interval of list; can be disabled / changed by user
[kdenetwork.git] / kopete / protocols / testbed / testbedaccount.cpp
blobb56e78f53365bc2402fa8c3b731b76e6fb1e9256
1 /*
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 *************************************************************************
8 * *
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. *
13 * *
14 *************************************************************************
18 #include "testbedaccount.h"
20 #include <kaction.h>
21 #include <kdebug.h>
22 #include <klocale.h>
23 #include <kactionmenu.h>
24 #include <kmenu.h>
25 #include <kicon.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()
46 delete m_server;
49 void TestbedAccount::fillActionMenu( KActionMenu *actionMenu )
51 Kopete::Account::fillActionMenu( actionMenu );
53 actionMenu->addSeparator();
55 KAction *action;
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 */ )
72 if ( away )
73 slotGoAway();
74 else
75 slotGoOnline();
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 )
82 slotGoOnline();
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 )
87 slotGoOffline();
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 */ )
100 kDebug ( 14210 ) ;
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()
108 kDebug ( 14210 ) ;
109 myself()->setOnlineStatus( TestbedProtocol::protocol()->testbedOffline );
110 QObject::disconnect ( m_server, 0, 0, 0 );
113 TestbedFakeServer * TestbedAccount::server()
115 return m_server;
118 void TestbedAccount::slotGoOnline ()
120 kDebug ( 14210 ) ;
122 if (!isConnected ())
123 connect ();
124 else
125 myself()->setOnlineStatus( TestbedProtocol::protocol()->testbedOnline );
126 updateContactStatus();
129 void TestbedAccount::slotGoAway ()
131 kDebug ( 14210 ) ;
133 if (!isConnected ())
134 connect();
136 myself()->setOnlineStatus( TestbedProtocol::protocol()->testbedAway );
137 updateContactStatus();
141 void TestbedAccount::slotGoOffline ()
143 kDebug ( 14210 ) ;
145 if (isConnected ())
146 disconnect ();
147 updateContactStatus();
150 void TestbedAccount::slotShowVideo ()
152 kDebug ( 14210 ) ;
154 if (isConnected ())
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
165 QString 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
174 if ( messageSender )
175 messageSender->receivedMessage( message );
176 else
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(); ) {
184 itr.next();
185 itr.value()->setOnlineStatus( myself()->onlineStatus() );
190 #include "testbedaccount.moc"