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

List:       kde-commits
Subject:    [networkmanagement/nm09] /: add support for network zones
From:       Lukas Tinkl <lukas () kde ! org>
Date:       2012-06-26 11:06:48
Message-ID: 20120626110648.15D68A60BB () git ! kde ! org
[Download RAW message or body]

Git commit 71cff79a2128b6e62e61555cc38383196bbeb540 by Lukas Tinkl.
Committed on 26/06/2012 at 13:05.
Pushed by lukas into branch 'nm09'.

add support for network zones

contributed by Jiří Popelka <jpopelka@redhat.com>

REVIEW: 105324

M  +4    -0    backends/NetworkManager/connectiondbus.cpp
M  +13   -2    libs/internals/connection.cpp
M  +3    -0    libs/internals/connection.h
M  +68   -34   libs/ui/connection.ui
M  +52   -0    libs/ui/connectionwidget.cpp
M  +2    -0    libs/ui/connectionwidget.h

http://commits.kde.org/networkmanagement/71cff79a2128b6e62e61555cc38383196bbeb540

diff --git a/backends/NetworkManager/connectiondbus.cpp \
b/backends/NetworkManager/connectiondbus.cpp index 4649a19..031d768 100644
--- a/backends/NetworkManager/connectiondbus.cpp
+++ b/backends/NetworkManager/connectiondbus.cpp
@@ -192,6 +192,8 @@ QVariantMapMap ConnectionDbus::toDbusMap()
         connectionMap.insert(QLatin1String(NM_SETTING_CONNECTION_PERMISSIONS), \
permissionsDbus);  }
 
+    connectionMap.insert(QLatin1String(NM_SETTING_CONNECTION_ZONE), \
m_connection->zone()); +
     //kDebug() << "Printing connection map: ";
     //foreach(QString key, connectionMap.keys())
         //kDebug() << key << " : " << connectionMap.value(key);
@@ -265,6 +267,7 @@ void ConnectionDbus::fromDbusMap(const QVariantMapMap &settings)
     QUuid uuid(connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_UUID)).toString());
                
     QString dbusConnectionType = \
                connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_TYPE)).toString();
                
     bool autoconnect = true; //default value must be true according to NM settings \
spec +    QString zone = \
connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_ZONE)).toString();  
     if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT)))
                
         autoconnect = \
connectionSettings.value(QLatin1String(NM_SETTING_CONNECTION_AUTOCONNECT)).toBool(); \
@@ -312,6 +315,7 @@ void ConnectionDbus::fromDbusMap(const QVariantMapMap &settings)  \
m_connection->setUuid(uuid);  m_connection->setType(type, bt_cap);
     m_connection->setAutoConnect(autoconnect);
+    m_connection->setZone(zone);
 
     // all other settings
     foreach (Setting * setting, m_connection->settings()) {
diff --git a/libs/internals/connection.cpp b/libs/internals/connection.cpp
index 67f31bc..42d12a6 100644
--- a/libs/internals/connection.cpp
+++ b/libs/internals/connection.cpp
@@ -126,14 +126,14 @@ Connection::Type Connection::typeFromSolidType(const \
Solid::Control::NetworkInte  }
 
 Connection::Connection(const QString & name, const Connection::Type type, \
                NMBluetoothCapabilities bt_cap)
-    : m_name(name), m_uuid(QUuid::createUuid()), m_type(type), m_autoConnect(false)
+    : m_name(name), m_uuid(QUuid::createUuid()), m_type(type), m_autoConnect(false), \
m_zone("")  {
     addToPermissions(KUser().loginName(),QString());
     init(bt_cap);
 }
 
 Connection::Connection(const QUuid & uuid, const Connection::Type type, \
                NMBluetoothCapabilities bt_cap)
-    : m_uuid(uuid), m_type(type), m_autoConnect(false)
+    : m_uuid(uuid), m_type(type), m_autoConnect(false), m_zone("")
 {
     addToPermissions(KUser().loginName(),QString());
     init(bt_cap);
@@ -144,6 +144,7 @@ Connection::Connection(Connection *con)
     setUuid(con->uuid());
     setType(con->type());
     setAutoConnect(con->autoConnect());
+    setZone(con->zone());
     setPermissions(con->permissions());
     setTimestamp(con->timestamp());
     setName(con->name());
@@ -333,6 +334,11 @@ bool Connection::autoConnect() const
     return m_autoConnect;
 }
 
+QString Connection::zone() const
+{
+    return m_zone;
+}
+
 bool Connection::isShared() const
 {
     Ipv4Setting * ipv4 = static_cast<Ipv4Setting *>(setting(Setting::Ipv4));
@@ -390,6 +396,11 @@ void Connection::setAutoConnect(bool autoConnect)
     m_autoConnect = autoConnect;
 }
 
+void Connection::setZone(const QString & zone)
+{
+    m_zone = zone;
+}
+
 void Connection::updateTimestamp()
 {
     m_timestamp = QDateTime::currentDateTime();
diff --git a/libs/internals/connection.h b/libs/internals/connection.h
index 485b810..16b5236 100644
--- a/libs/internals/connection.h
+++ b/libs/internals/connection.h
@@ -62,6 +62,7 @@ public:
     QUuid uuid() const;
     Connection::Type type() const;
     bool autoConnect() const;
+    QString zone() const;
     bool isShared() const;
     QDateTime timestamp() const;
     QHash<QString,QString> permissions() const;
@@ -85,6 +86,7 @@ public:
     void setIconName(const QString &);
     void setUuid(const QUuid &);
     void setAutoConnect(bool);
+    void setZone(const QString &);
     void setTimestamp(const QDateTime&);
 
     /**
@@ -138,6 +140,7 @@ private:
     QUuid m_uuid;
     Connection::Type m_type;
     bool m_autoConnect;
+    QString m_zone;
     QDateTime m_timestamp;
     QString m_origin;
     QList<Setting*> m_settings;
diff --git a/libs/ui/connection.ui b/libs/ui/connection.ui
index 7b9f873..e73ddc8 100644
--- a/libs/ui/connection.ui
+++ b/libs/ui/connection.ui
@@ -6,34 +6,59 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>445</width>
+    <width>459</width>
     <height>356</height>
    </rect>
   </property>
   <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0" rowspan="2">
+   <item row="2" column="0" colspan="2">
+    <widget class="KTabWidget" name="tabwidget"/>
+   </item>
     <layout class="QGridLayout" name="gridLayout_2">
-     <item row="0" column="0">
-      <widget class="QLabel" name="label">
+     <item row="0" column="1">
+      <widget class="KLineEdit" name="id">
+       <property name="minimumSize">
+        <size>
+         <width>250</width>
+         <height>0</height>
+        </size>
+       </property>
+      </widget>
+     </item>
+     <item row="3" column="0">
+      <widget class="QLabel" name="label_2">
+       <property name="enabled">
+        <bool>true</bool>
+       </property>
        <property name="text">
-        <string>&amp;Connection name:</string>
+        <string>&amp;Firewall zone:</string>
        </property>
        <property name="alignment">
         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
        </property>
        <property name="buddy">
-        <cstring>id</cstring>
+        <cstring>cmbZone</cstring>
        </property>
       </widget>
      </item>
-     <item row="0" column="1">
-      <widget class="KLineEdit" name="id">
+     <item row="0" column="2" rowspan="2">
+      <widget class="QLabel" name="connectionIcon">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+         <horstretch>48</horstretch>
+         <verstretch>48</verstretch>
+        </sizepolicy>
+       </property>
        <property name="minimumSize">
         <size>
-         <width>250</width>
-         <height>0</height>
+         <width>48</width>
+         <height>48</height>
         </size>
        </property>
+       <property name="text">
+        <string notr="true"/>
+       </property>
       </widget>
      </item>
      <item row="1" column="1">
@@ -50,15 +75,15 @@
       <layout class="QHBoxLayout" name="horizontalLayout_4">
        <item>
         <widget class="QCheckBox" name="system">
-         <property name="text">
-          <string>&amp;System connection</string>
-         </property>
          <property name="toolTip">
           <string>Save secrets in system storage</string>
          </property>
          <property name="whatsThis">
           <string>If checked, secrets (passwords and encryption keys) will be saved \
in system storage, which allows the connection to work without a KDE \
session.</string>  </property>
+         <property name="text">
+          <string>&amp;System connection</string>
+         </property>
         </widget>
        </item>
        <item>
@@ -82,50 +107,59 @@
        </item>
       </layout>
      </item>
-     <item row="0" column="2" rowspan="2">
-      <widget class="QLabel" name="connectionIcon">
-       <property name="sizePolicy">
-        <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
-         <horstretch>48</horstretch>
-         <verstretch>48</verstretch>
-        </sizepolicy>
+     <item row="0" column="0">
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>&amp;Connection name:</string>
        </property>
-       <property name="minimumSize">
-        <size>
-         <width>48</width>
-         <height>48</height>
-        </size>
+       <property name="alignment">
+        <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
        </property>
-       <property name="text">
-        <string notr="true"/>
+       <property name="buddy">
+        <cstring>id</cstring>
+       </property>
+      </widget>
+     </item>
+     <item row="3" column="1">
+      <widget class="KComboBox" name="cmbZone">
+       <property name="enabled">
+        <bool>true</bool>
+       </property>
+       <property name="toolTip">
+        <string>The zone defines trust level of the connection. Default is not a \
regular zone, selecting it results in the use of the default zone set in the \
firewall. Only usable if firewalld is active.</string>  </property>
       </widget>
      </item>
     </layout>
    </item>
-   <item row="2" column="0" colspan="2">
-    <widget class="KTabWidget" name="tabwidget"/>
-   </item>
   </layout>
  </widget>
  <customwidgets>
   <customwidget>
-   <class>KPushButton</class>
-   <extends>QPushButton</extends>
-   <header>kpushbutton.h</header>
-  </customwidget>
-  <customwidget>
    <class>KLineEdit</class>
    <extends>QLineEdit</extends>
    <header>klineedit.h</header>
   </customwidget>
   <customwidget>
+   <class>KPushButton</class>
+   <extends>QPushButton</extends>
+   <header>kpushbutton.h</header>
+  </customwidget>
+  <customwidget>
    <class>KTabWidget</class>
    <extends>QTabWidget</extends>
    <header>ktabwidget.h</header>
    <container>1</container>
   </customwidget>
  </customwidgets>
+ <tabstops>
+  <tabstop>id</tabstop>
+  <tabstop>autoconnect</tabstop>
+  <tabstop>system</tabstop>
+  <tabstop>pushButtonPermissions</tabstop>
+  <tabstop>cmbZone</tabstop>
+  <tabstop>tabwidget</tabstop>
+ </tabstops>
  <resources/>
  <connections>
   <connection>
diff --git a/libs/ui/connectionwidget.cpp b/libs/ui/connectionwidget.cpp
index f67f157..53560b2 100644
--- a/libs/ui/connectionwidget.cpp
+++ b/libs/ui/connectionwidget.cpp
@@ -21,6 +21,12 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #include "connectionwidget.h"
 #include "settingwidget_p.h"
 
+#include <QtDBus/QDBusConnection>
+#include <QtDBus/QDBusInterface>
+#include <QtDBus/QDBusPendingCall>
+#include <QtDBus/QDBusPendingCallWatcher>
+#include <QtDBus/QDBusPendingReply>
+
 #include <KDebug>
 
 #include <kicondialog.h>
@@ -51,6 +57,19 @@ ConnectionWidget::ConnectionWidget(QWidget * parent)
     d->ui.pushButtonPermissions->setIcon(KIcon("preferences-desktop-user"));
     connect(d->ui.pushButtonPermissions, SIGNAL(clicked()), this, \
                SLOT(buttonPermissionsClicked()));
     connect(d->ui.id, SIGNAL(textChanged(QString)), this, SLOT(validate()));
+
+    d->ui.cmbZone->setVisible(false);
+    d->ui.label_2->setVisible(false);
+    QDBusInterface firewalld("org.fedoraproject.FirewallD1", \
"/org/fedoraproject/FirewallD1", +                             \
"org.fedoraproject.FirewallD1.zone", QDBusConnection::systemBus()); +    if \
(firewalld.isValid()) { +        QDBusPendingCall pcall = \
firewalld.asyncCall(QLatin1String("getZones")); +        QDBusPendingCallWatcher \
*watcher = new QDBusPendingCallWatcher(pcall, this); +        \
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), +               \
this, SLOT(getZonesCallFinished(QDBusPendingCallWatcher*))); +    } else {
+        kDebug() << "error during creation of interface \
org.fedoraproject.FirewallD1.zone"; +    }
 }
 
 ConnectionWidget::~ConnectionWidget()
@@ -102,6 +121,12 @@ void ConnectionWidget::writeConfig()
         }
     } else
         connection()->setPermissions(QHash<QString,QString>());
+
+    if (d->ui.cmbZone->currentText() == i18n("Default")) {
+        connection()->setZone("");
+    } else {
+        connection()->setZone(d->ui.cmbZone->currentText());
+    }
 }
 
 void ConnectionWidget::validate()
@@ -126,4 +151,31 @@ void ConnectionWidget::buttonPermissionsClicked()
     }
 }
 
+void ConnectionWidget::getZonesCallFinished(QDBusPendingCallWatcher* call)
+{
+    Q_D(ConnectionWidget);
+
+    QDBusPendingReply<QStringList> reply = *call;
+    if (!reply.isError()) {
+        d->ui.cmbZone->addItem(i18n("Default"));
+        foreach (const QString &zone, reply.value())
+            d->ui.cmbZone->addItem(zone);
+
+        int index;
+        if (connection()->zone().isEmpty()) {
+            index = d->ui.cmbZone->findText(i18n("Default"));
+        } else {
+            index = d->ui.cmbZone->findText(connection()->zone());
+        }
+        d->ui.cmbZone->setCurrentIndex(index);
+
+        d->ui.cmbZone->setVisible(true);
+        d->ui.label_2->setVisible(true);
+    } else {
+        kDebug() << "remote function getZones() call failed.";
+    }
+
+    call->deleteLater();
+}
+
 // vim: sw=4 sts=4 et tw=100
diff --git a/libs/ui/connectionwidget.h b/libs/ui/connectionwidget.h
index aac7050..c735fff 100644
--- a/libs/ui/connectionwidget.h
+++ b/libs/ui/connectionwidget.h
@@ -28,6 +28,7 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #include "knm_export.h"
 
 class QTabWidget;
+class QDBusPendingCallWatcher;
 namespace Knm
 {
     class Connection;
@@ -66,6 +67,7 @@ public Q_SLOTS:
 
 private Q_SLOTS:
     void buttonPermissionsClicked();
+    void getZonesCallFinished(QDBusPendingCallWatcher* watcher);
 };
 
 #endif // CONNECTIONWIDGET_H


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

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