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=C5=99=C3=AD Popelka 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/71cff79a2128b6e62e61555cc38383196b= beb540 diff --git a/backends/NetworkManager/connectiondbus.cpp b/backends/NetworkM= anager/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_PERMISSIO= NS), permissionsDbus); } = + connectionMap.insert(QLatin1String(NM_SETTING_CONNECTION_ZONE), m_conn= ection->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_CONNECTIO= N_UUID)).toString()); QString dbusConnectionType =3D connectionSettings.value(QLatin1String(= NM_SETTING_CONNECTION_TYPE)).toString(); bool autoconnect =3D true; //default value must be true according to N= M settings spec + QString zone =3D connectionSettings.value(QLatin1String(NM_SETTING_CON= NECTION_ZONE)).toString(); = if (connectionSettings.contains(QLatin1String(NM_SETTING_CONNECTION_AU= TOCONNECT))) autoconnect =3D 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_autoConne= ct(false) + : m_name(name), m_uuid(QUuid::createUuid()), m_type(type), m_autoConne= ct(false), m_zone("") { addToPermissions(KUser().loginName(),QString()); init(bt_cap); } = Connection::Connection(const QUuid & uuid, const Connection::Type type, NM= BluetoothCapabilities 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 =3D static_cast(setting(Setting::Ipv= 4)); @@ -390,6 +396,11 @@ void Connection::setAutoConnect(bool autoConnect) m_autoConnect =3D autoConnect; } = +void Connection::setZone(const QString & zone) +{ + m_zone =3D zone; +} + void Connection::updateTimestamp() { m_timestamp =3D 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 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 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 @@ 0 0 - 445 + 459 356 + + + - - + + + + + 250 + 0 + + + + + + + + true + - &Connection name: + &Firewall zone: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - id + cmbZone - - + + + + + 48 + 48 + + - 250 - 0 + 48 + 48 + + + @@ -50,15 +75,15 @@ - - &System connection - Save secrets in system storage If checked, secrets (passwords and encryption keys) will= be saved in system storage, which allows the connection to work without a = KDE session. + + &System connection + @@ -82,50 +107,59 @@ - - - - - 48 - 48 - + + + + &Connection name: - - - 48 - 48 - + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + id + + + + + + + true + + + The zone defines trust level of the connection. Default is= not a regular zone, selecting it results in the use of the default zone se= t in the firewall. Only usable if firewalld is active. - - - - KPushButton - QPushButton -
kpushbutton.h
-
- KLineEdit QLineEdit
klineedit.h
+ KPushButton + QPushButton +
kpushbutton.h
+
+ KTabWidget QTabWidget
ktabwidget.h
1
+ + id + autoconnect + system + pushButtonPermissions + cmbZone + tabwidget + 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 . #include "connectionwidget.h" #include "settingwidget_p.h" = +#include +#include +#include +#include +#include + #include = #include @@ -51,6 +57,19 @@ ConnectionWidget::ConnectionWidget(QWidget * parent) d->ui.pushButtonPermissions->setIcon(KIcon("preferences-desktop-user")= ); connect(d->ui.pushButtonPermissions, SIGNAL(clicked()), this, SLOT(but= tonPermissionsClicked())); 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/fedorap= roject/FirewallD1", + "org.fedoraproject.FirewallD1.zone", QDBusCon= nection::systemBus()); + if (firewalld.isValid()) { + QDBusPendingCall pcall =3D firewalld.asyncCall(QLatin1String("getZ= ones")); + QDBusPendingCallWatcher *watcher =3D new QDBusPendingCallWatcher(p= call, this); + QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*= )), + this, SLOT(getZonesCallFinished(QDBusPendingCallW= atcher*))); + } else { + kDebug() << "error during creation of interface org.fedoraproject.= FirewallD1.zone"; + } } = ConnectionWidget::~ConnectionWidget() @@ -102,6 +121,12 @@ void ConnectionWidget::writeConfig() } } else connection()->setPermissions(QHash()); + + if (d->ui.cmbZone->currentText() =3D=3D 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 reply =3D *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 =3D d->ui.cmbZone->findText(i18n("Default")); + } else { + index =3D 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=3D4 sts=3D4 et tw=3D100 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 . #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