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

List:       kde-commits
Subject:    branches/work/knetworkmanager/knetworkmanager-0.7/src
From:       Will Stephenson <wstephenson () kde ! org>
Date:       2008-06-02 17:38:53
Message-ID: 1212428333.734245.4416.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 815859 by wstephens:

Show activating device or that which holds the connection with the default route in \
the tray

 M  +49 -1     devicetraycomponent.cpp  
 M  +4 -0      devicetraycomponent.h  
 M  +108 -3    knetworkmanager-tray.cpp  
 M  +6 -1      knetworkmanager-tray.h  


--- branches/work/knetworkmanager/knetworkmanager-0.7/src/devicetraycomponent.cpp \
#815858:815859 @@ -20,15 +20,39 @@
 
 #include "devicetraycomponent.h"
 
+#include <kiconloader.h>
 #include <klocale.h>
 #include <ksystemtray.h>
 
 #include "knetworkmanager-device.h"
+#include "knetworkmanager-nm_proxy.h"
 
 DeviceTrayComponent::DeviceTrayComponent(Device * device, KSystemTray * parent, \
const char * name )  : TrayComponent(parent, name), m_device(device)
 {
+	connect( m_device, SIGNAL(StateChanged(NMDeviceState)), \
SLOT(deviceStateChanged(NMDeviceState)));  
+	m_pixmaps[NM_DEVICE_STATE_UNKNOWN] = SmallIcon("nm_no_connection");
+	m_pixmaps[NM_DEVICE_STATE_UNMANAGED] = SmallIcon("nm_no_connection");
+	m_pixmaps[NM_DEVICE_STATE_UNAVAILABLE] = SmallIcon("nm_no_connection");
+	m_pixmaps[NM_DEVICE_STATE_DISCONNECTED] = SmallIcon("nm_no_connection");
+
+	m_movies[NM_DEVICE_STATE_PREPARE] = QMovie( \
KGlobal::iconLoader()->moviePath("nm_stage01_connecting", KIcon::Panel)); \
+	m_movies[NM_DEVICE_STATE_PREPARE].pause(); +
+	m_movies[NM_DEVICE_STATE_CONFIG] = QMovie( \
KGlobal::iconLoader()->moviePath("nm_stage02_connecting", KIcon::Panel)); \
+	m_movies[NM_DEVICE_STATE_CONFIG].pause(); +
+	m_movies[NM_DEVICE_STATE_IP_CONFIG] = QMovie( \
KGlobal::iconLoader()->moviePath("nm_stage03_connecting", KIcon::Panel)); \
+	m_movies[NM_DEVICE_STATE_IP_CONFIG].pause(); +
+	m_movies[NM_DEVICE_STATE_NEED_AUTH] = m_movies[NM_DEVICE_STATE_CONFIG];
+	m_movies[NM_DEVICE_STATE_NEED_AUTH].pause();
+
+	m_pixmaps[NM_DEVICE_STATE_ACTIVATED] = SmallIcon("ok");
+
+	m_pixmaps[NM_DEVICE_STATE_FAILED] = SmallIcon("nm_no_connection");
+
 }
 
 DeviceTrayComponent::~DeviceTrayComponent()
@@ -80,5 +104,29 @@
     m_pixmaps[state] = pixmap;
 }
 
-
+void DeviceTrayComponent::deviceStateChanged(NMDeviceState state)
+{
+    //check if our device now holds the default active connection
+    // if it is the default active connection
+    // or if it is activating.  what if 2 devices are activating simultaneously?
+    NMProxy * nm = 0;
+    switch (state) {
+        case NM_DEVICE_STATE_PREPARE:
+            emit needsCenterStage(this, true);
+            break;
+        case NM_DEVICE_STATE_ACTIVATED:
+            nm = NMProxy::getInstance();
+            if ( m_device == nm->getDefaultDevice() ) {
+                emit needsCenterStage(this, true);
+            }
+            break;
+        case NM_DEVICE_STATE_UNAVAILABLE:
+        case NM_DEVICE_STATE_DISCONNECTED:
+        case NM_DEVICE_STATE_FAILED:
+            emit needsCenterStage(this, false);
+            break;
+        default:
+            break;
+    }
+}
 #include "devicetraycomponent.moc"
--- branches/work/knetworkmanager/knetworkmanager-0.7/src/devicetraycomponent.h \
#815858:815859 @@ -44,8 +44,12 @@
     QMovie movieForState(NMDeviceState state);
     virtual QString getToolTipText();
     Device* device() const;
+signals:
+    void needsCenterStage(TrayComponent *, bool);
 public slots:
     virtual void newConnection() = 0;
+protected slots:
+    void deviceStateChanged(NMDeviceState);
 protected:
     void setMovieForState(NMDeviceState, QMovie);
     void setPixmapForState(NMDeviceState, QPixmap);
--- branches/work/knetworkmanager/knetworkmanager-0.7/src/knetworkmanager-tray.cpp \
#815858:815859 @@ -38,6 +38,7 @@
 #include <qstyle.h>
 #include <qvaluelist.h>
 #include <dcopclient.h>
+#include <dbus/qdbusobjectpath.h>
 #include <kdebug.h>
 #include <kdialogbase.h>
 #include <knotifyclient.h>
@@ -83,6 +84,7 @@
 	public:
 		TrayPrivate(QObject* parent)
 			: tooltip("")
+		  , foregroundTrayComponent(0)
 		  , signalMapper(parent, "signal_mapper")
 		  , current_idx(0)
 		{}
@@ -92,6 +94,7 @@
 
 		static Tray* tray;
 		QValueList<TrayComponent*> trayComponents;
+		DeviceTrayComponent * foregroundTrayComponent;
 		QSignalMapper signalMapper;
 		QMap<int, QPair<ConnectionSettings::Connection*, Device*> > act_conn_map;
 		int current_idx;
@@ -296,6 +299,11 @@
 void 
 Tray::slotVPNSecretsNeeded(ConnectionSettings::Connection* connection, \
ConnectionSettings::ConnectionSetting* setting, const QStringList& hints, bool \
request_new)  {
+#warning Implement Tray::slotVPNSecretsNeeded to handle parms properly
+	Q_UNUSED(setting);
+	Q_UNUSED(hints);
+	Q_UNUSED(request_new);
+
 	printf("Tray::slotVPNSecretsNeeded\n");
 	ConnectionSettings::VPNConnection* conn = \
dynamic_cast<ConnectionSettings::VPNConnection*>(connection);  \
VPNAuthenticationDialog* auth = new VPNAuthenticationDialog(conn, this, "vpnauth"); \
@@ -404,6 +412,8 @@  }
 		if(devTray)
 		{
+			connect( devTray, SIGNAL(needsCenterStage(TrayComponent*,bool)),
+					SLOT(trayComponentNeedsCenterStage(TrayComponent*,bool)));
 			d->trayComponents.append(devTray);
             //WILLTODO: sort
 		}
@@ -437,7 +447,7 @@
 	}
 }
 
-void Tray::slotUpdateDeviceTrays()
+void Tray::updateDeviceTrays()
 {
 	// create one tray-icon for each device
 	DeviceStore* store = DeviceStore::getInstance();	
@@ -483,6 +493,101 @@
 		nm->deactivateConnection(conn, dev);
 }
 
+void Tray::trayComponentNeedsCenterStage(TrayComponent *component, bool needsIt)
+{
+	DeviceTrayComponent * dtc = dynamic_cast<DeviceTrayComponent*>(component);
+	if (dtc) {
+		kdDebug() << k_funcinfo << dtc->device()->getInterface() << " : " << needsIt << \
endl; +		Device * device = dtc->device();
+		if (needsIt) {
+			if (d->foregroundTrayComponent) {
+				disconnect(d->foregroundTrayComponent->device(), \
SIGNAL(StateChanged(NMDeviceState)), this, 0 ); +			}
+			d->foregroundTrayComponent = dtc;
+			connect(device, SIGNAL(StateChanged(NMDeviceState)),
+					SLOT(slotUpdateDeviceState(NMDeviceState)));
+		} else {
+			disconnect(device, SIGNAL(StateChanged(NMDeviceState)), this, 0 );
+			//use active default
+			NMProxy* nm = NMProxy::getInstance();
+			device = nm->getDefaultDevice();
+			if ( device ) {
+				// identify the new foreground
+				for (QValueList<TrayComponent*>::Iterator it = d->trayComponents.begin(); it != \
d->trayComponents.end(); ++it) +				{	
+					DeviceTrayComponent* newDtc = dynamic_cast<DeviceTrayComponent*> (*it);
+					if ( newDtc->device() == device ) {
+						d->foregroundTrayComponent = newDtc;
+						break;
+					}
+				}
+				kdDebug() << "  Device " << dtc->device()->getInterface() << " background, new \
foreground device: " << device->getInterface() << endl; +				connect(device, \
SIGNAL(StateChanged(NMDeviceState)), \
+						SLOT(slotUpdateDeviceState(NMDeviceState))); \
+				slotUpdateDeviceState(device->getState()); +			}
+		}
+	}
+}
+
+void Tray::slotUpdateDeviceState(NMDeviceState state)
+{
+	updateTrayIcon(state);
+	updateActiveConnection(state);
+}
+
+void Tray::updateTrayIcon(NMDeviceState state)
+{
+	// stop the old movie to avoid unnecessary wakups
+	DeviceTrayComponent * dtc = d->foregroundTrayComponent;
+	if (dtc) {
+		if (movie())
+			movie()->pause();
+
+		if (!dtc->movieForState(state).isNull())
+		{
+			// animation desired
+			int frame = -1;
+			if (movie())
+				frame = movie()->frameNumber();
+
+			// set the movie
+			setMovie(dtc->movieForState(state));
+
+			// start at the same frame as the movie before
+			if (frame > 0)
+				movie()->step(frame);
+
+			// start the animation
+			movie()->unpause();
+		}
+		else if (!dtc->pixmapForState(state).isNull())
+			setPixmap(dtc->pixmapForState(state));
+		else
+			setPixmap(loadIcon("knetworkmanager"));
+	}
+	else
+		setPixmap(loadIcon("knetworkmanager"));
+}
+
+void Tray::updateActiveConnection(NMDeviceState state)
+{
+	if (state != NM_DEVICE_STATE_ACTIVATED)
+		return;
+
+	NMProxy* nm = NMProxy::getInstance();
+	if (d->foregroundTrayComponent) {
+		Connection* active_conn = \
nm->getActiveConnection(d->foregroundTrayComponent->device()); +		if (active_conn)
+		{
+			Info* info = dynamic_cast<Info*>(active_conn->getSetting(NM_SETTING_CONNECTION_SETTING_NAME));
 +			if (info)
+				info->setTimestamp(QDateTime::currentDateTime());
+		}
+	}
+}
+
+
 Tray::Tray () : KSystemTray ()
 {
 	d = new TrayPrivate(this);
@@ -536,12 +641,12 @@
 
 	// get notified about new/removed devices
 	DeviceStore* store = DeviceStore::getInstance();
-	connect(store, SIGNAL(DeviceStoreChanged()), this, SLOT(slotUpdateDeviceTrays()));	
+	connect(store, SIGNAL(DeviceStoreChanged()), this, SLOT(updateDeviceTrays()));	
 	connect(store, SIGNAL(DeviceAdded(Device*)), this, \
SLOT(slotAddDeviceTrayComponent(Device*)));	  connect(store, \
SIGNAL(DeviceRemoved(Device*)), this, SLOT(slotRemoveDeviceTrayComponent(Device*)));	 \
  // initial setup of the device-trays
-    QTimer::singleShot(0, this, SLOT(slotUpdateDeviceTrays()));
+	updateDeviceTrays();
 
 	QDBusError err;
 	slotStateChanged(nm->getState(err));
--- branches/work/knetworkmanager/knetworkmanager-0.7/src/knetworkmanager-tray.h \
#815858:815859 @@ -53,6 +53,7 @@
 }
 
 class QMouseEvent;
+class TrayComponent;
 class TrayPrivate;
 
 class Tray : public KSystemTray
@@ -79,12 +80,16 @@
 		void slotSecretsNeeded(ConnectionSettings::Connection* connection, \
ConnectionSettings::ConnectionSetting* setting, const QStringList& hints, bool \
request_new);  
   protected slots:
-		void slotUpdateDeviceTrays();
+		void updateDeviceTrays();
 		void slotAddDeviceTrayComponent(Device*);
 		void slotRemoveDeviceTrayComponent(Device*);
 		void slotDeactivateConnection(int);
+		void trayComponentNeedsCenterStage(TrayComponent*, bool);
+		void slotUpdateDeviceState(NMDeviceState);
 
 	private:
+		void updateTrayIcon(NMDeviceState);
+		void updateActiveConnection(NMDeviceState);
 		void mousePressEvent( QMouseEvent *e );
 		void createVPNTrayComponent();
 		void createDeviceTrayComponent(Device*);


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

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