[prev in list] [next in list] [prev in thread] [next in thread]
List: kopete-devel
Subject: Re: Review Request: Kopete: Automatically logout and login with suspend/resume
From: Pali =?ISO-8859-1?Q?Roh=E1r?= <pali.rohar () gmail ! com>
Date: 2012-02-25 19:40:29
Message-ID: 1690535.LEWshR8Et8 () pali
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
[Attachment #4 (multipart/mixed)]
Hi,
I'm attaching updated patch. Old patch on reviewboard cannot apply on kopete
from trunk. I tried to update patch also on reviewboard, but I do not have
permission to update it (I'm not author of that review/patch).
On Saturday 20 August 2011 09:31:55 Pali Rohár wrote:
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> http://svn.reviewboard.kde.org/r/6511/#review10359
> -----------------------------------------------------------
>
>
> I cannot apply this patch on kopete from trunk. Can you update it?
>
> - Pali
>
> On March 1, 2011, 9:39 p.m., alter_schwede wrote:
> > -----------------------------------------------------------
> > This is an automatically generated e-mail. To reply, visit:
> > http://svn.reviewboard.kde.org/r/6511/
> > -----------------------------------------------------------
> >
> > (Updated March 1, 2011, 9:39 p.m.)
> >
> >
> > Review request for Kopete.
> >
> >
> > Summary
> > -------
> >
> > I already posted this patch here:
> > https://bugs.kde.org/show_bug.cgi?id=149544
> >
> > 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".
> >
> >
> > This addresses bugs 149544 and 212037.
> >
> > https://bugs.kde.org/show_bug.cgi?id=149544
> > https://bugs.kde.org/show_bug.cgi?id=212037
> >
> > Diffs
> > -----
> >
> > /branches/KDE/4.6/kdenetwork/kopete/kopete/kopetedbusinterface.h 1222426
> > /branches/KDE/4.6/kdenetwork/kopete/kopete/kopetedbusinterface.cpp
> > 1222426
> > /branches/KDE/4.6/kdenetwork/kopete/kopete/org.kde.Kopete.xml 1222426
> > /branches/KDE/4.6/kdenetwork/kopete/libkopete/kopeteaccount.h 1222426
> > /branches/KDE/4.6/kdenetwork/kopete/libkopete/kopeteaccount.cpp 1222426
> > /branches/KDE/4.6/kdenetwork/kopete/libkopete/kopeteaccountmanager.h
> > 1222426
> > /branches/KDE/4.6/kdenetwork/kopete/libkopete/kopeteaccountmanager.cpp
> > 1222426>
> > Diff: http://svn.reviewboard.kde.org/r/6511/diff
> >
> >
> > Testing
> > -------
> >
> >
> > Thanks,
> >
> > alter_schwede
--
Pali Rohár
pali.rohar@gmail.com
["kopete-suspend-patch6.diff.new" (kopete-suspend-patch6.diff.new)]
Index: kopete/kopete/kopetedbusinterface.cpp
===================================================================
--- kopete/kopete/kopetedbusinterface.cpp (revision 1282223)
+++ kopete/kopete/kopetedbusinterface.cpp (working copy)
@@ -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)
{
Index: kopete/kopete/kopetedbusinterface.h
===================================================================
--- kopete/kopete/kopetedbusinterface.h (revision 1282223)
+++ kopete/kopete/kopetedbusinterface.h (working copy)
@@ -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
Index: kopete/kopete/org.kde.Kopete.xml
===================================================================
--- kopete/kopete/org.kde.Kopete.xml (revision 1282223)
+++ kopete/kopete/org.kde.Kopete.xml (working copy)
@@ -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"/>
Index: kopete/libkopete/kopeteaccountmanager.h
===================================================================
--- kopete/libkopete/kopeteaccountmanager.h (revision 1282223)
+++ kopete/libkopete/kopeteaccountmanager.h (working copy)
@@ -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
*/
Index: kopete/libkopete/kopeteaccountmanager.cpp
===================================================================
--- kopete/libkopete/kopeteaccountmanager.cpp (revision 1282223)
+++ kopete/libkopete/kopeteaccountmanager.cpp (working copy)
@@ -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;
- }
- }
-
- Kopete::AccountManager::self()->setOnlineStatus(initStatus, \
Kopete::StatusMessage(title, message), \
Kopete::AccountManager::ConnectIfOffline);
-
- if ( found )
- Kopete::StatusManager::self()->setGlobalStatus(initStatus, \
Kopete::StatusMessage(title, message));
- }
+ if( !resume() )
+ setOnlineStatus( Kopete::StatusManager::self()->globalStatusCategory(), \
Kopete::StatusManager::self()->globalStatusMessage(), 0, true); }
void AccountManager::networkDisconnected()
{
- setOnlineStatus( Kopete::OnlineStatusManager::Offline );
+ suspend();
}
void AccountManager::removeAccountConnectedChanged()
Index: kopete/libkopete/kopeteaccount.cpp
===================================================================
--- kopete/libkopete/kopeteaccount.cpp (revision 1282223)
+++ kopete/libkopete/kopeteaccount.cpp (working copy)
@@ -92,6 +92,8 @@
Kopete::OnlineStatus restoreStatus;
Kopete::StatusMessage restoreMessage;
QDateTime lastLoginTime;
+ bool suspended;
+ Kopete::OnlineStatus suspendStatus;
};
Account::Account( Protocol *parent, const QString &accountId )
@@ -113,6 +115,9 @@
QObject::connect( &d->suppressStatusTimer, SIGNAL(timeout()),
this, SLOT(slotStopSuppression()) );
+
+ d->suspended = false;
+ d->suspendStatus = Kopete::OnlineStatus::Offline;
}
Account::~Account()
@@ -513,6 +518,7 @@
{
const bool wasOffline = !oldStatus.isDefinitelyOnline();
const bool isOffline = !newStatus.isDefinitelyOnline();
+ d->suspended = false;
if ( wasOffline && !isOffline )
d->lastLoginTime = QDateTime::currentDateTime();
@@ -551,6 +557,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;
Index: kopete/libkopete/kopeteaccount.h
===================================================================
--- kopete/libkopete/kopeteaccount.h (revision 1282223)
+++ kopete/libkopete/kopeteaccount.h (working copy)
@@ -548,6 +548,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 );
["signature.asc" (application/pgp-signature)]
_______________________________________________
kopete-devel mailing list
kopete-devel@kde.org
https://mail.kde.org/mailman/listinfo/kopete-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic