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

List:       kopete-devel
Subject:    [kopete-devel] [PATCH] Lid auto away
From:       "Roman Jarosz" <kedgedev () centrum ! cz>
Date:       2008-04-19 18:29:03
Message-ID: op.t9veypqeyuholc () localhost
[Download RAW message or body]

Hi,

I've created a patch which allows to use notebook lid for auto away.
It's simple if user closes the lid then the status will change to away status,
which is defined in away settings. When user opens it then it will stay as it is
or will change back to online (depends on configuration).

There's not much to see so here's at least the config window with lid checkbox :)
http://kedge.wz.cz/kopete/autoaway.png

Any comments before I commit it?

Regards,
Roman

P.S. Solid is great :)

["lidaway.diff" (lidaway.diff)]

Index: kopete/config/behavior/behaviorconfig_away.ui
===================================================================
--- kopete/config/behavior/behaviorconfig_away.ui	(revision 798835)
+++ kopete/config/behavior/behaviorconfig_away.ui	(working copy)
@@ -98,6 +98,13 @@
        </layout>
       </item>
       <item>
+       <widget class="QCheckBox" name="kcfg_useLidAutoAway" >
+        <property name="text" >
+         <string>Use notebook lid for auto away</string>
+        </property>
+       </widget>
+      </item>
+      <item>
        <widget class="QCheckBox" name="kcfg_autoAwayGoAvailable" >
         <property name="enabled" >
          <bool>false</bool>
@@ -111,7 +118,10 @@
     </widget>
    </item>
    <item>
-    <widget class="QGroupBox" name="groupBox_3" >
+    <widget class="QGroupBox" name="awayMessageBox" >
+     <property name="enabled" >
+      <bool>false</bool>
+     </property>
      <property name="title" >
       <string>Auto Away Message</string>
      </property>
@@ -132,23 +142,37 @@
       </item>
       <item row="2" column="0" >
        <widget class="QLabel" name="label" >
+        <property name="enabled" >
+         <bool>false</bool>
+        </property>
         <property name="text" >
          <string>Title:</string>
         </property>
        </widget>
       </item>
       <item row="2" column="1" >
-       <widget class="KLineEdit" name="kcfg_autoAwayCustomTitle" />
+       <widget class="KLineEdit" name="kcfg_autoAwayCustomTitle" >
+        <property name="enabled" >
+         <bool>false</bool>
+        </property>
+       </widget>
       </item>
       <item row="3" column="0" >
        <widget class="QLabel" name="label_4" >
+        <property name="enabled" >
+         <bool>false</bool>
+        </property>
         <property name="text" >
          <string>Message:</string>
         </property>
        </widget>
       </item>
       <item row="3" column="1" >
-       <widget class="QTextEdit" name="kcfg_autoAwayCustomMessage" />
+       <widget class="QTextEdit" name="mAutoAwayCustomMessage" >
+        <property name="enabled" >
+         <bool>false</bool>
+        </property>
+       </widget>
       </item>
      </layout>
     </widget>
@@ -178,10 +202,12 @@
  <tabstops>
   <tabstop>kcfg_useAutoAway</tabstop>
   <tabstop>mAutoAwayTimeout</tabstop>
+  <tabstop>kcfg_useLidAutoAway</tabstop>
   <tabstop>kcfg_autoAwayGoAvailable</tabstop>
   <tabstop>kcfg_useLastAwayMessage</tabstop>
   <tabstop>kcfg_useCustomAwayMessage</tabstop>
   <tabstop>kcfg_autoAwayCustomTitle</tabstop>
+  <tabstop>mAutoAwayCustomMessage</tabstop>
  </tabstops>
  <resources/>
  <connections>
@@ -192,12 +218,12 @@
    <slot>setEnabled(bool)</slot>
    <hints>
     <hint type="sourcelabel" >
-     <x>88</x>
-     <y>119</y>
+     <x>108</x>
+     <y>60</y>
     </hint>
     <hint type="destinationlabel" >
-     <x>105</x>
-     <y>143</y>
+     <x>126</x>
+     <y>91</y>
     </hint>
    </hints>
   </connection>
@@ -208,12 +234,12 @@
    <slot>setEnabled(bool)</slot>
    <hints>
     <hint type="sourcelabel" >
-     <x>142</x>
-     <y>115</y>
+     <x>162</x>
+     <y>60</y>
     </hint>
     <hint type="destinationlabel" >
-     <x>174</x>
-     <y>148</y>
+     <x>201</x>
+     <y>91</y>
     </hint>
    </hints>
   </connection>
@@ -224,62 +250,78 @@
    <slot>setEnabled(bool)</slot>
    <hints>
     <hint type="sourcelabel" >
-     <x>212</x>
-     <y>117</y>
+     <x>232</x>
+     <y>60</y>
     </hint>
     <hint type="destinationlabel" >
-     <x>246</x>
-     <y>154</y>
+     <x>329</x>
+     <y>91</y>
     </hint>
    </hints>
   </connection>
   <connection>
-   <sender>kcfg_useAutoAway</sender>
+   <sender>kcfg_useCustomAwayMessage</sender>
    <signal>toggled(bool)</signal>
-   <receiver>kcfg_autoAwayGoAvailable</receiver>
+   <receiver>kcfg_autoAwayCustomTitle</receiver>
    <slot>setEnabled(bool)</slot>
    <hints>
     <hint type="sourcelabel" >
-     <x>72</x>
-     <y>120</y>
+     <x>123</x>
+     <y>248</y>
     </hint>
     <hint type="destinationlabel" >
-     <x>65</x>
-     <y>177</y>
+     <x>193</x>
+     <y>278</y>
     </hint>
    </hints>
   </connection>
   <connection>
-   <sender>kcfg_useAutoAway</sender>
+   <sender>kcfg_useCustomAwayMessage</sender>
    <signal>toggled(bool)</signal>
-   <receiver>groupBox_3</receiver>
+   <receiver>label</receiver>
    <slot>setEnabled(bool)</slot>
    <hints>
     <hint type="sourcelabel" >
-     <x>42</x>
-     <y>116</y>
+     <x>41</x>
+     <y>242</y>
     </hint>
     <hint type="destinationlabel" >
-     <x>44</x>
-     <y>208</y>
+     <x>43</x>
+     <y>272</y>
     </hint>
    </hints>
   </connection>
   <connection>
    <sender>kcfg_useCustomAwayMessage</sender>
    <signal>toggled(bool)</signal>
-   <receiver>kcfg_autoAwayCustomTitle</receiver>
+   <receiver>mAutoAwayCustomMessage</receiver>
    <slot>setEnabled(bool)</slot>
    <hints>
     <hint type="sourcelabel" >
-     <x>103</x>
-     <y>271</y>
+     <x>127</x>
+     <y>237</y>
     </hint>
     <hint type="destinationlabel" >
-     <x>106</x>
-     <y>352</y>
+     <x>129</x>
+     <y>335</y>
     </hint>
    </hints>
   </connection>
+  <connection>
+   <sender>kcfg_useCustomAwayMessage</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>label_4</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel" >
+     <x>70</x>
+     <y>241</y>
+    </hint>
+    <hint type="destinationlabel" >
+     <x>64</x>
+     <y>328</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
 </ui>
Index: kopete/config/behavior/behaviorconfig_away.cpp
===================================================================
--- kopete/config/behavior/behaviorconfig_away.cpp	(revision 798835)
+++ kopete/config/behavior/behaviorconfig_away.cpp	(working copy)
@@ -17,10 +17,23 @@
 
 #include "behaviorconfig_away.h"
 
+#include <kopetestatusmanager.h>
+
 BehaviorConfig_Away::BehaviorConfig_Away(QWidget *parent)
 	: QWidget(parent)
 {
 	setupUi(this);
+
+	connect(kcfg_useAutoAway, SIGNAL(toggled(bool)), this, SLOT(updateComponents()));
+	connect(kcfg_useLidAutoAway, SIGNAL(toggled(bool)), this, \
SLOT(updateComponents())); +	kcfg_useLidAutoAway->setEnabled( \
Kopete::StatusManager::self()->hasLid() );  }
 
+void BehaviorConfig_Away::updateComponents()
+{
+	bool enable = (kcfg_useAutoAway->isChecked() || kcfg_useLidAutoAway->isChecked());
+	awayMessageBox->setEnabled( enable );
+	kcfg_autoAwayGoAvailable->setEnabled( enable );
+}
+
 #include "behaviorconfig_away.moc"
Index: kopete/config/behavior/behaviorconfig_away.h
===================================================================
--- kopete/config/behavior/behaviorconfig_away.h	(revision 798835)
+++ kopete/config/behavior/behaviorconfig_away.h	(working copy)
@@ -26,6 +26,8 @@
 
 public:
 	BehaviorConfig_Away(QWidget *parent = 0);
+private slots:
+	void updateComponents();
 };
 
 #endif // BEHAVIORCONFIG_AWAY_H
Index: kopete/config/behavior/behaviorconfig.cpp
===================================================================
--- kopete/config/behavior/behaviorconfig.cpp	(revision 798835)
+++ kopete/config/behavior/behaviorconfig.cpp	(working copy)
@@ -86,7 +86,10 @@
 
 	// "Away" TAB ===============================================================
 	connect( mPrfsAway->mAutoAwayTimeout, SIGNAL(valueChanged(int)),
-		this, SLOT(slotValueChanged(int)));;
+	         this, SLOT(slotValueChanged(int)) );
+	connect( mPrfsAway->mAutoAwayCustomMessage, SIGNAL(textChanged()),
+	         this, SLOT(slotTextChanged()) );
+	
 }
 
 void BehaviorConfig::save()
@@ -97,6 +100,7 @@
 
 	// "Away" TAB ===============================================================
 	Kopete::BehaviorSettings::self()->setAutoAwayTimeout( \
mPrfsAway->mAutoAwayTimeout->value() * 60 ); \
+	Kopete::BehaviorSettings::self()->setAutoAwayCustomMessage( \
mPrfsAway->mAutoAwayCustomMessage->toPlainText() );  
 	// "Chat" TAB ===============================================================
 	Kopete::BehaviorSettings::self()->setViewPlugin(viewPlugins[mPrfsChat->viewPlugin->currentIndex()].pluginName() \
); @@ -116,6 +120,7 @@
 
 	// "Away" TAB ===============================================================
 	mPrfsAway->mAutoAwayTimeout->setValue( \
Kopete::BehaviorSettings::self()->autoAwayTimeout() / 60 ); \
+	mPrfsAway->mAutoAwayCustomMessage->setPlainText( \
Kopete::BehaviorSettings::self()->autoAwayCustomMessage() );  
 	// "Chat" TAB ===============================================================
 	mPrfsChat->viewPlugin->clear();
@@ -140,7 +145,7 @@
 	emit changed( true );
 }
 
-void BehaviorConfig::slotTextChanged(const QString&)
+void BehaviorConfig::slotTextChanged()
 {
 	emit changed( true );
 }
Index: kopete/config/behavior/behaviorconfig.h
===================================================================
--- kopete/config/behavior/behaviorconfig.h	(revision 798835)
+++ kopete/config/behavior/behaviorconfig.h	(working copy)
@@ -41,7 +41,7 @@
 	private slots:
 		void slotSettingsChanged(bool);
 		void slotValueChanged(int);
-		void slotTextChanged(const QString&);
+		void slotTextChanged();
 
 	private:
 		QTabWidget* mBehaviorTabCtl;
Index: libkopete/kopetestatusmanager.cpp
===================================================================
--- libkopete/kopetestatusmanager.cpp	(revision 798835)
+++ libkopete/kopetestatusmanager.cpp	(working copy)
@@ -20,6 +20,8 @@
 
 #include <ksavefile.h>
 #include <kstandarddirs.h>
+#include <solid/device.h>
+#include <solid/button.h>
 
 #include "kopeteaccountmanager.h"
 #include "kopeteaccount.h"
@@ -48,9 +50,10 @@
 	Kopete::StatusMessage customStatusMessage;
 	
 	bool away;
-	QList<Kopete::Account*> autoAwayAccounts;
+	QSet<Kopete::Account*> autoAccounts;
 
 	Kopete::IdleTimer* idleTimer;
+	Solid::Button *lidButton;
 };
 
 StatusManager::StatusManager()
@@ -59,8 +62,10 @@
 	d->away = false;
 	d->root = 0;
 	d->idleTimer = 0;
+	d->lidButton = 0;
 	loadXML();
 
+	scanDevices();
 	loadSettings();
 	loadBehaviorSettings();
 	connect( Kopete::BehaviorSettings::self(), SIGNAL(configChanged()),
@@ -297,6 +302,7 @@
 {
 	d->globalStatusCategory = category;
 	d->globalStatusMessage = statusMessage;
+	d->autoAccounts.clear();
 
 	KConfigGroup config( KGlobal::config(), "Status Manager" );
 	config.writeEntry( "GlobalStatusCategory", d->globalStatusCategory );
@@ -310,6 +316,7 @@
 void StatusManager::setGlobalStatusMessage( const Kopete::StatusMessage \
&statusMessage )  {
 	d->globalStatusMessage = statusMessage;
+	d->autoAccounts.clear();
 	
 	KConfigGroup config( KGlobal::config(), "Status Manager" );
 	config.writeEntry( "GlobalStatusTitle", d->globalStatusMessage.title() );
@@ -331,18 +338,7 @@
 	{
 		d->away = false;
 		if ( d->goAvailable )
-		{
-			QList<Kopete::Account*>::iterator it, itEnd = d->autoAwayAccounts.end();
-			for( it = d->autoAwayAccounts.begin(); it != itEnd; ++it )
-			{
-				if( (*it)->isConnected() && (*it)->isAway() )
-				{
-					(*it)->setOnlineStatus( Kopete::OnlineStatusManager::self()->onlineStatus( \
                (*it)->protocol(),
-						Kopete::OnlineStatusManager::Online ) );
-				}
-			}
-			d->autoAwayAccounts.clear();
-		}
+			clearAutoStatus();
 	}
 }
 
@@ -352,51 +348,40 @@
 	if ( !d->away )
 	{
 		d->away = true;
-		
-		// Set all accounts that are not away already to away.
-		// We remember them so later we only set the accounts to
-		// available that we set to away (and not the user).
-		QList<Kopete::Account *> accountList = Kopete::AccountManager::self()->accounts();
 
-		QList<Kopete::Account*>::iterator it, itEnd = accountList.end();
-		for( it = accountList.begin(); it != itEnd; ++it )
+		if( d->useCustomStatus )
 		{
-			if( (*it)->myself()->onlineStatus().status() == Kopete::OnlineStatus::Online )
-			{
-				d->autoAwayAccounts.append( (*it) );
-				
-				if( d->useCustomStatus )
-				{
-					// Display a specific away message
-					(*it)->setOnlineStatus( Kopete::OnlineStatusManager::self()->onlineStatus( \
                (*it)->protocol(),
-						Kopete::OnlineStatusManager::Idle ), d->customStatusMessage );
-				}
-				else
-				{
-					// Display the last global away message used
-					(*it)->setOnlineStatus( Kopete::OnlineStatusManager::self()->onlineStatus( \
                (*it)->protocol(),
-						Kopete::OnlineStatusManager::Idle ), d->globalStatusMessage );
-				}
-			}
+			// Display a specific away message
+			setAutoStatus( Kopete::OnlineStatusManager::Idle, d->customStatusMessage );
 		}
+		else
+		{
+			// Display the last global away message used
+			setAutoStatus( Kopete::OnlineStatusManager::Idle, d->globalStatusMessage );
+		}
 	}
 }
 
-bool StatusManager::autoAway()
+bool StatusManager::autoAway() const
 {
 	return d->away;
 }
 
-bool StatusManager::globalAway()
+bool StatusManager::globalAway() const
 {
 	return ( d->globalStatusCategory == OnlineStatusManager::Away ||
 	         d->globalStatusCategory == OnlineStatusManager::ExtendedAway ||
 	         d->globalStatusCategory == OnlineStatusManager::Busy );
 }
 
+bool StatusManager::hasLid() const
+{
+	return d->lidButton;
+}
+
 void StatusManager::accountUnregistered( const Kopete::Account *account )
 {
-	d->autoAwayAccounts.removeAll( const_cast<Kopete::Account *>(account) );
+	d->autoAccounts.remove( const_cast<Kopete::Account *>(account) );
 }
 
 void StatusManager::loadSettings()
@@ -426,8 +411,87 @@
 	
 	if ( Kopete::BehaviorSettings::self()->useAutoAway() )
 		idleTimer->registerTimeout( d->awayTimeout, this, SLOT(setActive()), \
SLOT(setAutoAway()) ); +
+	if ( d->lidButton )
+	{
+		disconnect( d->lidButton, 0, this, 0 );
+		if ( Kopete::BehaviorSettings::self()->useLidAutoAway() )
+		{
+			connect( d->lidButton, SIGNAL(pressed(Solid::Button::ButtonType, const \
QString&)), +			         this, SLOT(lidButtonPressed()) );
+		}
+	}
 }
 
+void StatusManager::lidButtonPressed()
+{
+	Solid::Button *button = static_cast<Solid::Button*>(sender());
+	kDebug(14010) << " value: " << button->stateValue();
+
+	if ( button->stateValue() )
+	{
+		if( d->useCustomStatus ) // Display a specific away message
+			setAutoStatus( Kopete::OnlineStatusManager::Idle, d->customStatusMessage );
+		else // Display the last global away message used
+			setAutoStatus( Kopete::OnlineStatusManager::Idle, d->globalStatusMessage );
+	}
+	else if ( !d->away && d->goAvailable )
+		clearAutoStatus();
 }
 
+void StatusManager::clearAutoStatus()
+{
+	kDebug(14010);
+	QSet<Kopete::Account*>::iterator it, itEnd = d->autoAccounts.end();
+	for( it = d->autoAccounts.begin(); it != itEnd; ++it )
+	{
+		if( (*it)->isConnected() && (*it)->isAway() )
+		{
+			(*it)->setOnlineStatus( Kopete::OnlineStatusManager::self()->onlineStatus( \
(*it)->protocol(), +				Kopete::OnlineStatusManager::Online ) );
+		}
+	}
+	d->autoAccounts.clear();
+}
+
+void StatusManager::setAutoStatus( uint category, const Kopete::StatusMessage \
&reason ) +{
+	kDebug(14010);
+	// Set all accounts that are online to status given by the category.
+	// We remember them so later we only set the accounts to
+	// available that we set with this method (and not the user).
+	QList<Kopete::Account *> accountList = Kopete::AccountManager::self()->accounts();
+	OnlineStatusManager::Category osmCategory = \
(OnlineStatusManager::Category)category; +	
+	QList<Kopete::Account*>::iterator it, itEnd = accountList.end();
+	for ( it = accountList.begin(); it != itEnd; ++it )
+	{
+		if ( (*it)->myself()->onlineStatus().status() == Kopete::OnlineStatus::Online )
+		{
+			d->autoAccounts.insert( (*it) );
+			
+			(*it)->setOnlineStatus( Kopete::OnlineStatusManager::self()->onlineStatus( \
(*it)->protocol(), osmCategory ), reason ); +		}
+	}
+}
+
+void StatusManager::scanDevices()
+{
+	QList<Solid::Device> deviceList = Solid::Device::listFromType( \
Solid::DeviceInterface::Button, QString() ); +	foreach ( Solid::Device device, \
deviceList ) +	{
+		if ( device.is<Solid::Button>() )
+		{
+			Solid::Button *button = device.as<Solid::Button>();
+			if ( button && button->type() == Solid::Button::LidButton )
+			{
+				d->lidButton = button;
+				break;
+			}
+		}
+	}
+}
+
+}
+
 #include "kopetestatusmanager.moc"
Index: libkopete/kopetestatusmanager.h
===================================================================
--- libkopete/kopetestatusmanager.h	(revision 798835)
+++ libkopete/kopetestatusmanager.h	(working copy)
@@ -114,13 +114,18 @@
 	/**
 	 * Returns true if auto away status was set
 	 */
-	bool autoAway();
+	bool autoAway() const;
 
 	/**
 	 * Returns true if global away status was set
 	 */
-	bool globalAway();
+	bool globalAway() const;
 
+	/**
+	 * Returns true if computer has lid
+	 */
+	bool hasLid() const;
+
 public Q_SLOTS:
 	/**
 	 * Undo auto away
@@ -147,11 +152,17 @@
 	void accountUnregistered( const Kopete::Account *account );
 	void loadSettings();
 	void loadBehaviorSettings();
-	
+	void lidButtonPressed();
+
 private:
 	StatusManager();
 	void updateUidHash( Status::StatusItem *item );
 
+	void setAutoStatus( uint category, const Kopete::StatusMessage &reason );
+	void clearAutoStatus();
+
+	void scanDevices();
+
 	Status::StatusGroup *defaultStatuses() const;
 
 	static StatusManager *instance;
Index: libkopete/kopetebehaviorsettings.kcfg
===================================================================
--- libkopete/kopetebehaviorsettings.kcfg	(revision 798835)
+++ libkopete/kopetebehaviorsettings.kcfg	(working copy)
@@ -169,6 +169,10 @@
 			<label>The custom auto away message.</label>
 			<default code="true">i18n("I am gone right now, but I will be back \
later")</default>  </entry>
+		<entry key="useLidAutoAway" type="Bool">
+			<label>Use notebook lid for auto away</label>
+			<default>true</default>
+		</entry>
 	</group>
 
 	<group name="ContactList">



_______________________________________________
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