[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdenetwork/kopete
From:       Pali Rohár <pali.rohar () gmail ! com>
Date:       2013-05-17 13:55:08
Message-ID: 20130517135508.33066AC87A () svn ! kde ! org
[Download RAW message or body]

SVN commit 1355161 by pali:

Automatically logout and login with suspend/resume

This patch logs off each account when PC is suspended and restores the online state \
of each account on resume. This patch also addresses another problem of kopete: When \
the user was setting kopete to "Offline" and the network connection was lost and \
recovered kopete would reset all accounts to "Online".

Thanks Benni Hill for patch!

BUG: 212037
BUG: 149544
FEATURE: 149544
FIXED-IN: 4.11
REVIEW: 6511


 M  +10 -0     kopete/kopetedbusinterface.cpp  
 M  +10 -0     kopete/kopetedbusinterface.h  
 M  +4 -0      kopete/org.kde.Kopete.xml  
 M  +28 -0     libkopete/kopeteaccount.cpp  
 M  +12 -0     libkopete/kopeteaccount.h  
 M  +59 -25    libkopete/kopeteaccountmanager.cpp  
 M  +11 -0     libkopete/kopeteaccountmanager.h  


--- trunk/KDE/kdenetwork/kopete/kopete/kopetedbusinterface.cpp #1355160:1355161
@@ -256,6 +256,16 @@
 			Kopete::OnlineStatusManager::Offline);
 }
 
+void KopeteDBusInterface::suspend()
+{
+	Kopete::AccountManager::self()->suspend();
+}
+
+void KopeteDBusInterface::resume()
+{
+	Kopete::AccountManager::self()->resume();
+}
+
 void KopeteDBusInterface::setOnlineStatus(const QString &status,
 		const QString &message)
 {
--- trunk/KDE/kdenetwork/kopete/kopete/kopetedbusinterface.h #1355160:1355161
@@ -55,6 +55,16 @@
 	void disconnectAll();
 
 	/**
+	 * @brief Saves the online status of all accounts and disconnects them
+	 */
+	void suspend();
+
+	/**
+	 * @brief Sets the online status of all accounts to the status they had when \
suspend was called +	 */
+	void resume();
+
+	/**
 	 * @brief Get information if we are connected to a given account in the given \
                protocol
 	 * @param protocolName The protocol name (ex: Jabber, Yahoo, Messenger)
 	 * @param accountId Account ID
--- trunk/KDE/kdenetwork/kopete/kopete/org.kde.Kopete.xml #1355160:1355161
@@ -5,6 +5,10 @@
     </method>
     <method name="disconnectAll">
     </method>
+    <method name="suspend">
+    </method>
+    <method name="resume">
+    </method>
     <method name="isConnected">
       <arg type="b" direction="out"/>
       <arg name="protocolName" type="s" direction="in"/>
--- trunk/KDE/kdenetwork/kopete/libkopete/kopeteaccount.cpp #1355160:1355161
@@ -93,6 +93,8 @@
 	Kopete::OnlineStatus restoreStatus;
 	Kopete::StatusMessage restoreMessage;
 	QDateTime lastLoginTime;
+	bool suspended;
+	Kopete::OnlineStatus suspendStatus;
 };
 
 Account::Account( Protocol *parent, const QString &accountId )
@@ -117,6 +119,9 @@
 
 	QObject::connect( &d->suppressStatusTimer, SIGNAL(timeout()),
 		this, SLOT(slotStopSuppression()) );
+
+	d->suspended = false;
+	d->suspendStatus = Kopete::OnlineStatus::Offline;
 }
 
 Account::~Account()
@@ -551,6 +556,7 @@
 {
 	const bool wasOffline = !oldStatus.isDefinitelyOnline();
 	const bool isOffline  = !newStatus.isDefinitelyOnline();
+	d->suspended = false;
 
 	if ( wasOffline && !isOffline )
 		d->lastLoginTime = QDateTime::currentDateTime();
@@ -589,6 +595,28 @@
 		emit isConnectedChanged();
 }
 
+bool Account::suspend( const Kopete::StatusMessage &reason )
+{
+	if ( d->suspended )
+		return false;
+
+	d->suspendStatus = myself()->onlineStatus();
+	if( myself()->onlineStatus().status() == OnlineStatus::Connecting )
+		d->suspendStatus = d->restoreStatus;
+	setOnlineStatus( OnlineStatus::Offline, reason );
+	d->suspended = true;
+	return true;
+}
+
+bool Account::resume()
+{
+	if ( !d->suspended )
+		return false;
+
+	setOnlineStatus( d->suspendStatus, d->restoreMessage, Kopete::Account::None );
+	return true;
+}
+
 void Account::setAllContactsStatus( const Kopete::OnlineStatus &status )
 {
 	d->suppressStatusNotification = true;
--- trunk/KDE/kdenetwork/kopete/libkopete/kopeteaccount.h #1355160:1355161
@@ -570,6 +570,18 @@
 	virtual void setStatusMessage( const Kopete::StatusMessage &statusMessage ) = 0;
 
 	/**
+	 * Disconnects account, required before resume()
+	 * Returns false if account is already suspended.
+	 */
+	bool suspend( const Kopete::StatusMessage &reason = Kopete::StatusMessage() );
+
+	/**
+	 * Sets account to the online status that was active when suspend() was called.
+	 * Returns false if account has not been suspended or status has changed to \
something other than Offline in the meantime. +	 */
+	bool resume();
+
+	/**
 	 * Display the edit account widget for the account
 	 */
 	void editAccount( QWidget* parent = 0L );
--- trunk/KDE/kdenetwork/kopete/libkopete/kopeteaccountmanager.cpp #1355160:1355161
@@ -22,6 +22,7 @@
 #include <QtCore/QRegExp>
 #include <QtCore/QTimer>
 #include <QtCore/QHash>
+#include <QtDBus/QDBusInterface>
 
 #include <ksharedconfig.h>
 #include <kdebug.h>
@@ -65,6 +66,9 @@
 public:
 	QList<Account *> accounts;
 	QList<Account *> accountsToBeRemoved;
+	bool suspended;
+	Kopete::StatusMessage suspendedStatusMessage;
+	uint suspendedStatusCategory;
 };
 
 AccountManager * AccountManager::s_self = 0L;
@@ -84,6 +88,10 @@
 	setObjectName( "KopeteAccountManager" );
 	connect( Solid::Networking::notifier(), SIGNAL(shouldConnect()), this, \
SLOT(networkConnected()) );  connect( Solid::Networking::notifier(), \
SIGNAL(shouldDisconnect()), this, SLOT(networkDisconnected()) ); +#warning TODO: \
Switch to a org.kde.Solid.PowerManagement Sleeping/Suspending signal when available. \
+	QDBusConnection::systemBus().connect( "org.freedesktop.UPower", \
"/org/freedesktop/UPower", "", "Sleeping", this, SLOT( suspend() ) ); \
+	QDBusConnection::sessionBus().connect( "org.kde.Solid.PowerManagement", \
"/org/kde/Solid/PowerManagement", "org.kde.Solid.PowerManagement", \
"resumingFromSuspend", this, SLOT( resume() ) ); +	d->suspended = false;
 }
 
 
@@ -111,6 +119,7 @@
 	OnlineStatusManager::Categories categories
 		= (OnlineStatusManager::Categories)category;
 	const bool onlyChangeConnectedAccounts = ( !forced && isAnyAccountConnected() );
+	d->suspended = false;
 
 	foreach( Account *account, d->accounts )
 	{
@@ -147,6 +156,53 @@
 	}
 }
 
+void AccountManager::suspend()
+{
+	if ( d->suspended )
+		return;
+
+	d->suspended = true;
+	d->suspendedStatusMessage = Kopete::StatusManager::self()->globalStatusMessage();
+	d->suspendedStatusCategory = Kopete::StatusManager::self()->globalStatusCategory();
+
+	Kopete::StatusMessage statusMessage( i18n( "Offline" ), "" );
+	QList <Kopete::Status::StatusItem *> statusList = \
Kopete::StatusManager::self()->getRootGroup()->childList(); +	//find first Status for \
OffineStatus +	for ( QList <Kopete::Status::StatusItem *>::ConstIterator it = \
statusList.constBegin(); it != statusList.constEnd(); ++it ) +	{
+		if ( ! (*it)->isGroup() && (*it)->category() == \
Kopete::OnlineStatusManager::Offline ) +		{
+			QString message, title;
+			title = (*it)->title();
+			message = (static_cast <Kopete::Status::Status*> (*it))->message(); //if it is \
not group, it's status +			statusMessage.setTitle( title );
+			statusMessage.setMessage( message );
+			break;
+		}
+	}
+
+	foreach( Account *account, d->accounts )
+	{
+		account->suspend( statusMessage );
+	}
+	Kopete::StatusManager::self()->setGlobalStatus( \
Kopete::OnlineStatusManager::Offline, statusMessage ); +}
+
+bool AccountManager::resume()
+{
+	bool networkAvailable = ( Solid::Networking::status() == Solid::Networking::Unknown \
|| Solid::Networking::status() == Solid::Networking::Connected ); +	if ( \
!d->suspended || !networkAvailable ) +		return false;
+
+	foreach( Account *account, d->accounts )
+	{
+		account->resume();
+	}
+	Kopete::StatusManager::self()->setGlobalStatus( d->suspendedStatusCategory, \
d->suspendedStatusMessage ); +	d->suspended = false;
+	return true;
+}
+
 QColor AccountManager::guessColor( Protocol *protocol ) const
 {
 	// In a perfect wold, we should check if the color is actually not used by the \
account. @@ -394,36 +450,14 @@
 
 void AccountManager::networkConnected()
 {
-	Kopete::OnlineStatusManager::Category initStatus = \
                Kopete::OnlineStatusManager::self()->initialStatus();
-	//we check for network availability here too
-	if ( Solid::Networking::status() == Solid::Networking::Unknown ||
-			  Solid::Networking::status() == Solid::Networking::Connected ){
-
-		QList <Kopete::Status::StatusItem *> statusList = \
                Kopete::StatusManager::self()->getRootGroup()->childList();
-		QString message, title;
-		bool found = false;
-
-		//find first Status for OnlineStatus
-		for ( QList <Kopete::Status::StatusItem *>::ConstIterator it = \
                statusList.constBegin(); it != statusList.constEnd(); ++it ) {
-			if ( ! (*it)->isGroup() && (*it)->category() == initStatus ) {
-				title = (*it)->title();
-				message = (static_cast <Kopete::Status::Status*> (*it))->message(); //if it is \
                not group, it status
-				found = true;
-				break;
+	if( !resume() )
+		setOnlineStatus( Kopete::StatusManager::self()->globalStatusCategory(), \
Kopete::StatusManager::self()->globalStatusMessage(), 0, true);  }
-		}
 
-		Kopete::AccountManager::self()->setOnlineStatus(initStatus, \
Kopete::StatusMessage(title, message), Kopete::AccountManager::ConnectIfOffline);  
-		if ( found )
-			Kopete::StatusManager::self()->setGlobalStatus(initStatus, \
                Kopete::StatusMessage(title, message));
-	}
-}
-
-
 void AccountManager::networkDisconnected()
 {
-	setOnlineStatus( Kopete::OnlineStatusManager::Offline );
+	suspend();
 }
 
 void AccountManager::removeAccountConnectedChanged()
--- trunk/KDE/kdenetwork/kopete/libkopete/kopeteaccountmanager.h #1355160:1355161
@@ -153,6 +153,17 @@
 	void setStatusMessage(const QString &message);
 
 	/**
+	 * Suspends all accounts.
+	 */
+	void suspend();
+
+	/**
+	 * Resumes all accounts.
+	 * Returns false if network is not available.
+	 */
+	bool resume();
+
+	/**
 	 * \internal
 	 * Save the account data to KConfig
 	 */


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic