~ubuntu-branches/ubuntu/precise/networkmanagement/precise

« back to all changes in this revision

Viewing changes to backends/NetworkManager/nmdbussettingsconnectionprovider.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-10-23 14:00:13 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20111023140013-e38hdzybcg6zndrk
Tags: 0.9~svngit.nm09.20111023.ff842e-0ubuntu1
* New upstream snapshot.
* Drop all patches, merged upstream.
* Add kubuntu_add_subdirectory_po.diff to build the translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
// knmservice includes
42
42
#include "activatablelist.h"
43
 
#include "connectionlist.h"
44
43
 
45
44
#include "settings/ipv4.h"
46
45
 
168
167
        d->uuidToPath.remove(uuid.toString());
169
168
        delete removed;
170
169
        Knm::Connection *con = d->connectionList->findConnection(uuid.toString());
171
 
        con->removeCertificates();
172
170
        d->connectionList->removeConnection(con);
173
171
 
174
172
        emit connectionsChanged();
180
178
    Q_D(NMDBusSettingsConnectionProvider);
181
179
    RemoteConnection * connection = static_cast<RemoteConnection*>(sender());
182
180
    kDebug() << connection->path();
 
181
 
183
182
    QUuid uuid = d->uuidToPath.key(connection->path(), QUuid());
184
183
    if (!uuid.isNull() && d->connections.contains(uuid.toString())) {
 
184
        ConnectionDbus temp(new Knm::Connection(QUuid(), Knm::Connection::Wired));
185
185
        Knm::Connection *con = d->connectionList->findConnection(uuid.toString());
186
186
        ConnectionDbus dbusConverter(con);
187
187
        dbusConverter.fromDbusMap(connection->GetSettings());
 
188
 
188
189
        d->connectionList->updateConnection(con);
189
190
 
190
191
        emit connectionsChanged();
214
215
void NMDBusSettingsConnectionProvider::clearConnections()
215
216
{
216
217
    Q_D(NMDBusSettingsConnectionProvider);
217
 
    foreach (const QString &key, d->connections.keys()) {
218
 
        // Remove it from d->connections first to prevent a crash because
219
 
        // of the "delete toDelete.second" emmiting a Delete signal captured by
220
 
        // NMDBusSettingsConnectionProvider::onRemoteConnectionRemoved(), which deletes
221
 
        // toDelete.second again.
222
 
        RemoteConnection *toDelete = d->connections.take(key);
223
 
        d->connectionList->removeConnection(key);
224
 
        delete toDelete;
 
218
    foreach (RemoteConnection * conn, d->connections.values()) {
 
219
        // Qt::DirectConnection makes this call synchronous.
 
220
        // The connection will actually be deleted by NMDBusSettingsConnectionProvider::onRemoteConnectionRemoved().
 
221
        QMetaObject::invokeMethod(conn, "Removed", Qt::DirectConnection);
225
222
    }
226
 
    // Just to make sure d->connections is really clear.
 
223
    // Just to make sure they are really clear.
227
224
    d->connections.clear();
228
225
    d->uuidToPath.clear();
229
226
    emit connectionsChanged();
288
285
                // Try to pin-unlock the modem.
289
286
                QMetaObject::invokeMethod(modem, "unlockRequiredChanged", Qt::DirectConnection,
290
287
                                          Q_ARG(QString, modem->unlockRequired()));
291
 
                kDebug() << "Trying to enable modem";
292
 
                modem->enable(true);
293
288
            }
294
289
        }
295
290
 
336
331
        RemoteConnection *remote = d->connections.value(uuid);
337
332
        kDebug() << "Updating connection "<< remote->id() << objPath;
338
333
 
339
 
        newConnection->saveCertificates();
340
 
        newConnection->setSecrets();
 
334
        newConnection->setUuid(uuid);
341
335
        ConnectionDbus converter(newConnection);
342
336
        QVariantMapMap map = converter.toDbusMap();
343
337
 
344
 
        remote->Update(map);
345
 
 
346
 
        // FIXME: if connection's name (id in NM termonology) changed in the Update call above,
347
 
        // NM will leave the old connection file intact and create/update a new connection file
348
 
        // in /etc/NetworkManager/system-connections/ with the same uuid, which is wrong in my oppinion.
349
 
        // Furthermore the old connection is not shown in kcm's because we use the uuid as connection identifier.
 
338
        if (newConnection->name() == remote->id()) {
 
339
            remote->Update(map);
 
340
        } else {
 
341
            /* If connection's name (id in NM's termonology) changes during an Update
 
342
             * NM will leave the old connection file intact and create a new connection file
 
343
             * in /etc/NetworkManager/system-connections/ with the same uuid, which is wrong in my oppinion.
 
344
             * Furthermore the old connection will not be shown in Plasma NM's connection list
 
345
             * because we use connection's uuid as connection identifier.
 
346
             * Deleting the old connection and creating a new one seems to work.
 
347
             */
 
348
            kDebug() << "Renaming connection:" << remote->id() << " -> " << newConnection->name();
 
349
            QDBusPendingCall reply = remote->Delete();
 
350
            reply.waitForFinished();
 
351
            sleep(1);
 
352
            addConnection(newConnection);
 
353
        }
350
354
 
351
355
        // don't do any processing on d->connections and d->connectionList here
352
356
        // because onRemoteConnectionUpdated() method will take care of them
356
360
    }
357
361
 
358
362
    kWarning() << "Connection could not found!"<< uuid;
359
 
 
360
363
}
361
364
 
362
365
void NMDBusSettingsConnectionProvider::addConnection(Knm::Connection *newConnection)
363
366
{
364
367
    Q_D(NMDBusSettingsConnectionProvider);
365
 
    newConnection->saveCertificates();
366
 
    newConnection->setSecrets();
 
368
 
367
369
    ConnectionDbus converter(newConnection);
368
370
    QVariantMapMap map = converter.toDbusMap();
369
371
    kDebug() << "Adding connection " << newConnection->name() << newConnection->uuid().toString();
373
375
    if(newConnection && newConnection->name().isEmpty())
374
376
        kWarning() << "Trying to add connection without a name!";
375
377
 
376
 
 
377
 
 
378
378
    d->secretsToSave.insert(newConnection->uuid(), map);
379
379
    QDBusPendingCall reply = d->iface->AddConnection(map);
380
380
    //do not check if reply is valid or not because it's an async call and invalid till reply is really arrived
397
397
    {
398
398
        Q_D(NMDBusSettingsConnectionProvider);
399
399
        QDBusObjectPath objPath = reply.argumentAt<0>();
400
 
        emit addConnectionCompleted(true, QString());
401
400
 
402
401
        // Hack to force NetworkManager to call the secrets agent to save this connections's secrets.
403
402
        // This does not work for VPN connections.
405
404
        QString uuid = d->uuidToPath.key(objPath.path(), QUuid()).toString();
406
405
        RemoteConnection *remote = d->connections.value(uuid);
407
406
        QVariantMapMap map = d->secretsToSave.take(uuid);
 
407
        sleep(1);
408
408
        remote->Update(map);
 
409
        emit addConnectionCompleted(true, QString());
409
410
 
410
411
        kDebug() << "Connection added successfully: " << objPath.path() << uuid;
411
412
    }
418
419
{
419
420
    Q_D(NMDBusSettingsConnectionProvider);
420
421
 
421
 
    if (!con->hasSecrets())
422
 
    {
423
 
        kDebug() << "Connection seems not to have any secret information. Ignoring...";
424
 
        return false;
425
 
    }
426
 
 
427
422
    QUuid uuid = con->uuid();
428
423
    if ( !d->uuidToPath.contains(uuid)){
429
424
        kWarning() << "Secrets requested but connection not found!";
436
431
 
437
432
    kDebug() << "Getting connection secrets for " << uuid.toString();
438
433
 
439
 
    QStringList secretSettings = con->secretSettings();
 
434
    QStringList secretSettings = con->hasPersistentSecretsSettings();
440
435
 
441
436
    kDebug() << "Settings containing secret values are " << secretSettings;
442
437
 
520
515
    kWarning() << "Connection could not found!"<< uuid;
521
516
}
522
517
 
 
518
ConnectionList * NMDBusSettingsConnectionProvider::connectionList()
 
519
{
 
520
    Q_D(NMDBusSettingsConnectionProvider);
 
521
    return d->connectionList;
 
522
}
523
523
// vim: sw=4 sts=4 et tw=100