summaryrefslogtreecommitdiffstats
path: root/kopete/libkopete/managedconnectionaccount.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitbcb704366cb5e333a626c18c308c7e0448a8e69f (patch)
treef0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /kopete/libkopete/managedconnectionaccount.cpp
downloadtdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz
tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip
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
Diffstat (limited to 'kopete/libkopete/managedconnectionaccount.cpp')
-rw-r--r--kopete/libkopete/managedconnectionaccount.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/kopete/libkopete/managedconnectionaccount.cpp b/kopete/libkopete/managedconnectionaccount.cpp
new file mode 100644
index 00000000..0f1625b2
--- /dev/null
+++ b/kopete/libkopete/managedconnectionaccount.cpp
@@ -0,0 +1,73 @@
+/*
+ managedconnectionaccount.h - Kopete Account that uses a manager to
+ control its connection and respond to connection events
+
+ Copyright (c) 2005 by Will Stephenson <lists@stevello.free-online.co.uk>
+ Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
+
+ *************************************************************************
+ * *
+ * This library is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU Lesser General Public *
+ * License as published by the Free Software Foundation; either *
+ * version 2 of the License, or (at your option) any later version. *
+ * *
+ *************************************************************************
+*/
+
+#include "connectionmanager.h"
+#include "kopeteuiglobal.h"
+
+#include "managedconnectionaccount.h"
+
+
+namespace Kopete
+{
+
+ManagedConnectionAccount::ManagedConnectionAccount( Protocol *parent, const QString &acctId, uint maxPasswordLength, const char *name )
+ : PasswordedAccount( parent, acctId, maxPasswordLength, name ), m_waitingForConnection( false )
+{
+ QObject::connect( ConnectionManager::self(), SIGNAL(statusChanged(const QString&, NetworkStatus::EnumStatus ) ),
+ SLOT(slotConnectionStatusChanged(const QString&, NetworkStatus::EnumStatus ) ) );
+}
+
+void ManagedConnectionAccount::connectWithPassword( const QString &password )
+{
+ m_password = password;
+ NetworkStatus::EnumStatus status = ConnectionManager::self()->status( QString::null );
+ if ( status == NetworkStatus::NoNetworks )
+ performConnectWithPassword( password );
+ else
+ {
+ m_waitingForConnection = true;
+ // need to adapt libkopete so we know the hostname in this class and whether the connection was user initiated
+ // for now, these are the default parameters to always bring up a connection to "the internet".
+ NetworkStatus::EnumRequestResult response = ConnectionManager::self()->requestConnection( Kopete::UI::Global::mainWidget(), QString::null, true );
+ if ( response == NetworkStatus::Connected )
+ {
+ m_waitingForConnection = false;
+ performConnectWithPassword( password );
+ }
+ else if ( response == NetworkStatus::UserRefused || response == NetworkStatus::Unavailable )
+ disconnect();
+ }
+}
+
+void ManagedConnectionAccount::slotConnectionStatusChanged( const QString & host, NetworkStatus::EnumStatus status )
+{
+ Q_UNUSED(host); // as above, we didn't register a hostname, so treat any connection as our own.
+
+ if ( m_waitingForConnection && ( status == NetworkStatus::Online || status == NetworkStatus::NoNetworks ) )
+ {
+ m_waitingForConnection = false;
+ performConnectWithPassword( m_password );
+ }
+ else if ( isConnected() && ( status == NetworkStatus::Offline
+ || status == NetworkStatus::ShuttingDown
+ || status == NetworkStatus::OfflineDisconnected
+ || status == NetworkStatus::OfflineFailed ) )
+ disconnect();
+}
+
+} // end namespace Kopete
+#include "managedconnectionaccount.moc"