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

List:       kopete-devel
Subject:    [Kopete-devel] [PATCH] Autoaway plugin - status restoration
From:       Ladislav Strojil <Ladislav.Strojil () seznam ! cz>
Date:       2002-05-04 11:45:05
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I have finished testing the changes and include patch that does following 
things:

introduces 
	void storeStatusAll(void);
	void restoreStatusAll(void);
in kopete.h.

	virtual void storeStatus(void) { };
	virtual void restoreStatus(void) { setAvailable(); };
in kopeteprotocol.h

and modifies AutoAway plugin to use these functions.

Furthermore ICQ plugin is modified to take advantage of these new functions, 
defining storeStatus and restoreStatus.
Plugins that do not define these functions will behave exactly as before, that 
is go "away" and then be restored to "available".

In ICQ plugin I had to make few changed moving code for setting proper icon 
into separate method now called setIcon (code moved from slotConnected()).

Also, I changed isAway method to consider STATUS_DND and STATUS_OCCUPIED as 
NOT away status. This IMO makes much more sense, I personally use OCCUPIED 
when I work, but still I wan't my status to change to away if I leave my 
computer.

Please review and comment.

Cheers,
Lada

- -- 
    ~       Ladislav Strojil, MFF UK
  ' v '               
 //   \\              
/(     )\    Powered by Penguin.
  ^ ' ^
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE808nBTnMZPFqq4nwRAnFaAKCucG8rzpVJafCa+GFsJSeJ227B9gCg5aYD
AqpLxzWFS2ipwBN9UDSMPPI=
=3Rk0
-----END PGP SIGNATURE-----

["kopete.diff" (text/x-diff)]

Index: libkopete/kopete.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/libkopete/kopete.cpp,v
retrieving revision 1.56
diff -u -3 -p -r1.56 kopete.cpp
--- libkopete/kopete.cpp	27 Apr 2002 21:31:06 -0000	1.56
+++ libkopete/kopete.cpp	4 May 2002 11:32:01 -0000
@@ -219,6 +219,50 @@ void Kopete::slotSetAvailableAll(void)
 	}
 }
 
+// Store old status for all protocol plugins
+// Some protocols may not support storing old status
+// these will later be restored to available
+void Kopete::storeStatusAll(void)
+{
+	QValueList<KopeteLibraryInfo> l = kopeteapp->libraryLoader()->loaded();
+	for (QValueList<KopeteLibraryInfo>::Iterator i = l.begin(); i != l.end(); ++i)
+	{
+		kdDebug() << "[Kopete] storeStatusAll() for plugin: " << (*i).name << endl;
+		Plugin *tmpprot = (kopeteapp->libraryLoader())->mLibHash[(*i).specfile]->plugin;
+		KopeteProtocol *prot =  dynamic_cast<KopeteProtocol*>(tmpprot);
+
+		if (!prot)
+			continue;
+
+		if ( prot->isConnected() )
+		{
+			kdDebug() << "[Kopete] storing status for: " << (*i).name << endl;
+			prot->storeStatus(); // sets store status
+		}
+	}
+}
+
+// Restore former state in all plugins
+void Kopete::restoreStatusAll(void)
+{
+	QValueList<KopeteLibraryInfo> l = kopeteapp->libraryLoader()->loaded();
+	for (QValueList<KopeteLibraryInfo>::Iterator i = l.begin(); i != l.end(); ++i)
+	{
+		kdDebug() << "[Kopete] restoreStatusAll() for plugin: " << (*i).name << endl;
+		Plugin *tmpprot = (kopeteapp->libraryLoader())->mLibHash[(*i).specfile]->plugin;
+		KopeteProtocol *prot =  dynamic_cast<KopeteProtocol*>(tmpprot);
+
+		if (!prot)
+			continue;
+
+		if ( prot->isConnected() )
+		{
+			kdDebug() << "[Kopete] setting former-mode for: " << (*i).name << endl;
+			prot->restoreStatus(); 
+		}
+	}
+}
+
 /** Add a contact through Wizard */
 void Kopete::slotAddContact()
 {
Index: libkopete/kopete.h
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/libkopete/kopete.h,v
retrieving revision 1.41
diff -u -3 -p -r1.41 kopete.h
--- libkopete/kopete.h	28 Apr 2002 01:17:46 -0000	1.41
+++ libkopete/kopete.h	4 May 2002 11:32:01 -0000
@@ -143,6 +143,10 @@ public:
 	**/
 	QString parseHTML( QString message, bool parseURLs = true );
 
+
+	void storeStatusAll(void);
+	void restoreStatusAll(void);
+
 	void initEmoticons();
 
 private:
Index: libkopete/kopeteprotocol.h
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/libkopete/kopeteprotocol.h,v
retrieving revision 1.2
diff -u -3 -p -r1.2 kopeteprotocol.h
--- libkopete/kopeteprotocol.h	13 Apr 2002 03:45:41 -0000	1.2
+++ libkopete/kopeteprotocol.h	4 May 2002 11:32:01 -0000
@@ -48,6 +48,14 @@ public:
 	// this will be called if main-kopete wants
 	// the plugin to set the user's mode to online or something similar
 	virtual void setAvailable(void)=0;
+	
+	// this should be redefined in protocol plugins to store their current status
+	// to keep compatibility, default version does nothing
+	virtual void storeStatus(void) { };
+	// this restores saved status
+	// for compatibility reasons this only set to available
+	virtual void restoreStatus(void) { setAvailable(); };
+
 	// plugin has to return wether it is away or not
 	// plugins should also return TRUE for modes like occupied not-vailable etc.
 	virtual bool isAway(void) const = 0;
Index: plugins/autoaway/autoawayplugin.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/plugins/autoaway/autoawayplugin.cpp,v
retrieving revision 1.3
diff -u -3 -p -r1.3 autoawayplugin.cpp
--- plugins/autoaway/autoawayplugin.cpp	14 Apr 2002 18:37:06 -0000	1.3
+++ plugins/autoaway/autoawayplugin.cpp	4 May 2002 11:32:01 -0000
@@ -52,6 +52,7 @@ bool AutoAwayPlugin::unload()
 void AutoAwayPlugin::slotTimeout()
 {
 	kdDebug() << "[AutoAway Plugin] : Timeout and no user activity, going away" << \
endl; +	kopeteapp->storeStatusAll();
 	kopeteapp->slotSetAwayAll();
 }
 
@@ -59,8 +60,8 @@ void AutoAwayPlugin::slotActivity()
 {
 	if ( mPrefs->goAvailable() )
 	{
-		kdDebug() << "[AutoAway Plugin] : User activity!, going available" << endl;
-		kopeteapp->slotSetAvailableAll();
+		kdDebug() << "[AutoAway Plugin] : User activity!, restoring" << endl;
+		kopeteapp->restoreStatusAll();
 	}
 }
 
Index: protocols/icq/icqprotocol.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/protocols/icq/icqprotocol.cpp,v
retrieving revision 1.80
diff -u -3 -p -r1.80 icqprotocol.cpp
--- protocols/icq/icqprotocol.cpp	14 Apr 2002 17:53:30 -0000	1.80
+++ protocols/icq/icqprotocol.cpp	4 May 2002 11:32:01 -0000
@@ -124,6 +124,8 @@ ICQProtocol::ICQProtocol(): QObject(0, "
 	
 	// get new/unread messages
 	kxMessages->readMessages();
+
+	formerStatus = STATUS_OFFLINE; //probably the most reasonable default?
 }
 
 void ICQProtocol::initActions()
@@ -294,6 +296,18 @@ void ICQProtocol::setAway(void)
 	statusBarIcon->setPixmap ( awayIcon );
 }
 
+void ICQProtocol::storeStatus(void)
+{
+	formerStatus = engine->getStatus();
+}
+
+void ICQProtocol::restoreStatus(void)
+{
+	engine->changeStatus ( formerStatus );
+	setIcon( formerStatus );
+	formerStatus=STATUS_OFFLINE;
+}
+
 void ICQProtocol::setAvailable(void)
 {
 	engine->changeStatus ( STATUS_ONLINE );
@@ -306,12 +320,16 @@ bool ICQProtocol::isAway(void) const
 
 	// TODO: is invisible like away or a special mode?
 	
-	if ( curStatus == STATUS_OFFLINE || curStatus == STATUS_ONLINE || curStatus == \
                STATUS_INVISIBLE )
-	{
-		return false;
+	switch (curStatus) {
+		case STATUS_OFFLINE:
+		case STATUS_ONLINE:
+		case STATUS_DND:
+		case STATUS_OCCUPIED:
+		case STATUS_INVISIBLE:
+			return false;
+		default:
+			return true;
 	}
-
-	return true;
 }
 
 
@@ -575,11 +593,8 @@ void ICQProtocol::initIcons()
 	connectingIcon		= QMovie( locate("data","kopete/pics/icq_connecting.mng") );
 }
 
-void ICQProtocol::slotConnected()
-{
-	kdDebug() << "ICQProtocol::slotConnected()" << endl;
-
-	switch ( engine->getStatus() )
+void ICQProtocol::setIcon(int status) {
+	switch ( status )
 	{
 		case STATUS_ONLINE:
 			statusBarIcon->setPixmap(onlineIcon);
@@ -603,6 +618,14 @@ void ICQProtocol::slotConnected()
 			statusBarIcon->setPixmap(invIcon);
 			break;
 	}
+}
+
+void ICQProtocol::slotConnected()
+{
+	kdDebug() << "ICQProtocol::slotConnected()" << endl;
+
+	setIcon( engine->getStatus() );
+
 	mIsConnected = true; // was this a bug ( said true! ) ? Duncan
 }
 
Index: protocols/icq/icqprotocol.h
===================================================================
RCS file: /home/kde/kdenonbeta/kopete/protocols/icq/icqprotocol.h,v
retrieving revision 1.40
diff -u -3 -p -r1.40 icqprotocol.h
--- protocols/icq/icqprotocol.h	13 Apr 2002 03:46:43 -0000	1.40
+++ protocols/icq/icqprotocol.h	4 May 2002 11:32:01 -0000
@@ -88,10 +88,15 @@ public:
 	virtual bool isConnected() const;
 	virtual void setAway(void);
 	virtual void setAvailable(void);
+	virtual void storeStatus(void);
+	virtual void restoreStatus(void);
 	virtual bool isAway(void) const;
 
 	void addContact(UIN uin, bool, bool, const QString &, const QString &, const \
QString &, const QString &, const QString &, bool, bool, const QString &);  void \
addUnknownContact(UIN uin, bool auth, bool notify, const QString &nickname, const \
QString &notsure, const QString &firstname, const QString &lastname, const QString \
&email, bool unused, bool requestinfo); +
+	// set icon correconding to status
+	void setIcon(int status);
 	
 	ICQPreferences *prefs() const { return mPrefs; };
 	QString nickName() const { return mName; };
@@ -134,6 +139,8 @@ private:
 	// our own nickname
 	QString mName;
 	bool selfinfoLocked; // What is this actually?, mETz
+
+	int formerStatus;
 
 signals:
 	void userStatusChanged(UIN, Q_UINT16, Q_UINT16);


_______________________________________________
Kopete-devel mailing list
Kopete-devel@mail.kde.org
http://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