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

List:       kde-commits
Subject:    branches/work/knetworkmanager/knetworkmanager-0.7/src
From:       Helmut Schaa <hschaa () suse ! de>
Date:       2008-04-21 13:06:34
Message-ID: 1208783194.769324.30288.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 799397 by hschaa:

Allow removal of connections (not persistet yet!)


 M  +9 -0      connection_editor.ui  
 M  +8 -0      connection_settings.ui  
 M  +24 -18    knetworkmanager-connection.cpp  
 M  +3 -0      knetworkmanager-connection.h  
 M  +6 -1      knetworkmanager-connection_dbus.cpp  
 M  +3 -0      knetworkmanager-connection_dbus.h  
 M  +85 -0     knetworkmanager-connection_editor.cpp  
 M  +6 -0      knetworkmanager-connection_editor.h  
 M  +18 -0     knetworkmanager-connection_store.cpp  
 M  +2 -0      knetworkmanager-connection_store.h  


--- branches/work/knetworkmanager/knetworkmanager-0.7/src/connection_editor.ui \
#799396:799397 @@ -45,6 +45,15 @@
             <property name="name">
                 <cstring>lvConnections</cstring>
             </property>
+            <property name="allColumnsShowFocus">
+                <bool>true</bool>
+            </property>
+            <property name="showSortIndicator">
+                <bool>true</bool>
+            </property>
+            <property name="resizeMode">
+                <enum>AllColumns</enum>
+            </property>
         </widget>
         <widget class="KComboBox" row="0" column="0">
             <property name="name">
--- branches/work/knetworkmanager/knetworkmanager-0.7/src/connection_settings.ui \
#799396:799397 @@ -48,6 +48,14 @@
             <property name="name">
                 <cstring>wstackSettings</cstring>
             </property>
+            <property name="sizePolicy">
+                <sizepolicy>
+                    <hsizetype>5</hsizetype>
+                    <vsizetype>7</vsizetype>
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                </sizepolicy>
+            </property>
             <property name="frameShape">
                 <enum>TabWidgetPanel</enum>
             </property>
--- branches/work/knetworkmanager/knetworkmanager-0.7/src/knetworkmanager-connection.cpp \
#799396:799397 @@ -65,18 +65,19 @@
 {
 	public:
 		ConnectionPrivate(Connection* parent)
-			: conn_dbus(parent)
-      , conn_secrets_dbus(parent)
-      , id("")
-    {}
+      : id("")
+    {
+			conn_dbus = new ConnectionDBus(parent);
+			conn_secrets_dbus = new ConnectionSecretsDBus(parent);
+		}
 		~ConnectionPrivate() {}
 
-		QDBusObjectPath       obj_path;
-		ConnectionDBus        conn_dbus;
-		ConnectionSecretsDBus conn_secrets_dbus;
-		QString               id;
+		QDBusObjectPath        obj_path;
+		ConnectionDBus*        conn_dbus;
+		ConnectionSecretsDBus* conn_secrets_dbus;
+		QString                id;
 		QValueList<ConnectionSetting*> settings;
-		QString               specific_object;
+		QString                specific_object;
 };
 
 }
@@ -93,12 +94,11 @@
 
 	QDBusConnection conn = QDBusConnection::systemBus();
 
-	// dynamic_cast is required here due to multiple inheritance
 	if (!registerObject(conn, objectPath()))
 		kdError() << "registerobjectpath failed" << endl;
 
 	// get notified whenever NM needs a secret
-	connect(&(d->conn_secrets_dbus), SIGNAL(SecretsNeeded(const QString&, const \
QStringList&, bool)), this, SLOT(slotSecretsNeeded(const QString&, const \
QStringList&, bool))); +	connect(d->conn_secrets_dbus, SIGNAL(SecretsNeeded(const \
QString&, const QStringList&, bool)), this, SLOT(slotSecretsNeeded(const QString&, \
const QStringList&, bool)));  }
 
 Connection::~Connection()
@@ -195,14 +195,14 @@
 	if (!setting)
 	{
 		// send an error to NM
-		d->conn_secrets_dbus.SendGetSecretsReply(NULL);
+		d->conn_secrets_dbus->SendGetSecretsReply(NULL);
 	}
 	else
 	{
 		if (!request_new && setting->hasSecrets())
 		{
 			// if the setting has secrets just send them
-			d->conn_secrets_dbus.SendGetSecretsReply(setting);
+			d->conn_secrets_dbus->SendGetSecretsReply(setting);
 		}
 		else
 		{
@@ -218,12 +218,12 @@
 	if (!setting)
 	{
 		// send an error to NM
-		d->conn_secrets_dbus.SendGetSecretsError();
+		d->conn_secrets_dbus->SendGetSecretsError();
 	}
 	else
 	{
 		// if we have the secrets already send them to NM
-		d->conn_secrets_dbus.SendGetSecretsReply(setting);
+		d->conn_secrets_dbus->SendGetSecretsReply(setting);
 	}
 
 }
@@ -231,7 +231,7 @@
 void
 Connection::slotSecretsError()
 {
-	d->conn_secrets_dbus.SendGetSecretsError();
+	d->conn_secrets_dbus->SendGetSecretsError();
 }
 
 QDBusObjectBase*
@@ -239,10 +239,10 @@
 {
 	// the interfaces are already created, just return the right one
 	if (interfaceName == NM_DBUS_IFACE_SETTINGS_CONNECTION)
-		return &(d->conn_dbus);
+		return d->conn_dbus;
 
 	if (interfaceName == NM_DBUS_IFACE_SETTINGS_CONNECTION_SECRETS)
-		return &(d->conn_secrets_dbus);
+		return d->conn_secrets_dbus;
 
 	return NULL;
 }
@@ -259,4 +259,10 @@
 	emit validityChanged();
 }
 
+void
+Connection::slotAboutToBeRemoved()
+{
+	d->conn_dbus->slotAboutToBeRemoved();
+}
+
 #include "knetworkmanager-connection.moc"
--- branches/work/knetworkmanager/knetworkmanager-0.7/src/knetworkmanager-connection.h \
#799396:799397 @@ -97,6 +97,9 @@
 			// gets called when a settings validity changes
 			void slotSettingValidityChanged();
 
+			// gets called when the connection is about to be removed
+			void slotAboutToBeRemoved();
+
 		protected:
 			// implementations for ConnectionNode
 			QDBusObjectBase* createInterface(const QString& interfaceName);
--- branches/work/knetworkmanager/knetworkmanager-0.7/src/knetworkmanager-connection_dbus.cpp \
#799396:799397 @@ -173,6 +173,11 @@
 	return QString(d->parent->getObjectPath());
 }
 
+void
+ConnectionDBus::slotAboutToBeRemoved()
+{
+	// tell NM about us being removed
+	emitRemoved();
+}
 
-
 #include "knetworkmanager-connection_dbus.moc"
--- branches/work/knetworkmanager/knetworkmanager-0.7/src/knetworkmanager-connection_dbus.h \
#799396:799397 @@ -53,6 +53,9 @@
 			ConnectionDBus(ConnectionSettings::Connection* parent);
 			~ConnectionDBus();
 
+		public slots:
+			void slotAboutToBeRemoved();
+
 		protected:
 			// implementations of the Setting DBus-interface
 			bool GetID(QString& id, QDBusError& error);
--- branches/work/knetworkmanager/knetworkmanager-0.7/src/knetworkmanager-connection_editor.cpp \
#799396:799397 @@ -35,6 +35,7 @@
 #include <kiconloader.h>
 #include <kdebug.h>
 #include <kpushbutton.h>
+#include <klistview.h>
 
 // Qt DBus headers
 #include <dbus/qdbuserror.h>
@@ -65,6 +66,41 @@
 #include "knetworkmanager-nm_proxy.h"
 #include "knetworkmanager-storage.h"
 
+
+using namespace ConnectionSettings;
+
+/*
+ * ConnectionListViewItem
+ */
+class ConnectionListViewItem : public KListViewItem
+{
+	public:
+
+	ConnectionListViewItem(QListView* parent, GenericConnection* connection)
+		: KListViewItem(parent)
+		, _conn(connection)
+	{
+		Info* info = _conn->getInfoSetting();
+		if (info)
+		{
+			setText(0, info->getName());
+			setText(1, info->getDevType());
+			// TODO: Move to a Factory
+			if (info->getDevType() == "802-3-ethernet")
+				setPixmap(0, KGlobal::iconLoader()->loadIcon("wired", KIcon::Small));
+			else if (info->getDevType() == "802-11-wireless")
+				setPixmap(0, KGlobal::iconLoader()->loadIcon("wireless", KIcon::Small));
+			else
+				setPixmap(0, KGlobal::iconLoader()->loadIcon("help", KIcon::Small));
+		}
+	}
+
+	GenericConnection* _conn;
+};
+
+/*
+ * Constructor
+ */
 ConnectionEditorImpl::ConnectionEditorImpl(QWidget* parent, const char* name, bool \
modal, WFlags fl)  : ConnectionEditor(parent, name, modal, fl)
 {
@@ -73,11 +109,60 @@
 	pbEdit->setIconSet(KGlobal::iconLoader()->loadIcon("edit", KIcon::Small));
 
 	connect(pbClose, SIGNAL(clicked()), this, SLOT(close()));
+	connect(pbDelete, SIGNAL(clicked()), this, SLOT(slotRemoveCurrentConnection()));
+	fillConnectionList();
+
 }
 
+/*
+ * Destructor
+ */
 ConnectionEditorImpl::~ConnectionEditorImpl()
 {
 
 }
 
+void ConnectionEditorImpl::slotRemoveCurrentConnection()
+{
+	ConnectionListViewItem* item = \
dynamic_cast<ConnectionListViewItem*>(lvConnections->currentItem()); +	if (!item)
+		return;
+
+	ConnectionStore* cstore = ConnectionStore::getInstance();
+	Connection* conn = item->_conn;
+
+	lvConnections->takeItem(item);
+	delete item;
+	
+	cstore->removeConnection(conn);
+}
+
+/*
+ * Fill the connection list
+ */
+void ConnectionEditorImpl::fillConnectionList()
+{
+	ConnectionStore* cstore = ConnectionStore::getInstance();
+	QValueList<Connection*> conns = cstore->getConnections();
+	QValueList<Connection*>::Iterator it = conns.begin();
+
+	for (; it != conns.end(); ++it)
+	{
+		GenericConnection* conn = dynamic_cast<GenericConnection*>(*it);
+		if (conn)
+		{
+			Info* info = conn->getInfoSetting();
+			if (info)
+			{
+				new ConnectionListViewItem(lvConnections, conn);
+			}
+			else
+				kdWarning() << k_funcinfo << "Connection without Info setting, drop it." << \
endl; +		}
+		else
+			kdWarning() << k_funcinfo << "non-generic connection, dropping it." << endl;
+		
+	}
+}
+
 #include "knetworkmanager-connection_editor.moc"
--- branches/work/knetworkmanager/knetworkmanager-0.7/src/knetworkmanager-connection_editor.h \
#799396:799397 @@ -49,6 +49,12 @@
 	public:
 		ConnectionEditorImpl(QWidget* parent = 0, const char* name = 0, bool modal = \
FALSE, WFlags fl = 0);  ~ConnectionEditorImpl();
+
+	protected slots:
+		void slotRemoveCurrentConnection();
+
+	private:
+		void fillConnectionList();
 };
 
 #endif /* KNETWORKMANAGER_CONNECTION_EDITOR_H*/
--- branches/work/knetworkmanager/knetworkmanager-0.7/src/knetworkmanager-connection_store.cpp \
#799396:799397 @@ -108,6 +108,24 @@
 	emit newConnection(con);
 }
 
+void
+ConnectionStore::removeConnection(Connection* con)
+{
+	// check if the connection is != NULL
+	if (!con)
+		return;
+
+	// remove the object from our list
+	if (_connectionList.remove(con) == 0)
+		return;
+
+	// TODO: perhaps we should notify everybody?
+
+	// delete the connection, it will deregister itself from NM
+	con->slotAboutToBeRemoved();
+	delete con;
+}
+
 Connection*
 ConnectionStore::getConnection(const QString& obj_path)
 {
--- branches/work/knetworkmanager/knetworkmanager-0.7/src/knetworkmanager-connection_store.h \
#799396:799397 @@ -47,6 +47,8 @@
 		void addConnection(ConnectionSettings::Connection*);
 		QValueList<ConnectionSettings::Connection*> getConnections(const QString& type = \
QString::null);  ConnectionSettings::Connection* getConnection(const QString&);
+		void removeConnection(ConnectionSettings::Connection*);
+
 	public slots:
 		void slotInit();
 		void slotSecretsNeeded(Connection* connection, ConnectionSetting* setting, const \
QStringList& hints, bool request_new);


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

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