~unity-team/libqtdbusmock/trunk

« back to all changes in this revision

Viewing changes to src/libqtdbusmock/DBusMock.cpp

  • Committer: Bileto Bot
  • Date: 2017-03-16 10:32:00 UTC
  • mfrom: (47.1.5 trunk)
  • Revision ID: ci-train-bot@canonical.com-20170316103200-rpwd8q43apgcknh0
* Add hostname1 and login1 templates to new binary package
  libqtdbusmock1-common.
* Search /usr/share/libqtdbusmock/templates for templates.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <libqtdbustest/QProcessDBusService.h>
21
21
 
22
22
#include <NetworkManager.h>
 
23
#include <QFile>
23
24
#include <QJsonDocument>
 
25
#include <QStandardPaths>
24
26
 
25
27
using namespace QtDBusTest;
26
28
 
84
86
                              QDBusConnection::BusType busType) {
85
87
        QStringList arguments;
86
88
        arguments << "-m" << "dbusmock";
87
 
        arguments << "--template" << templateName;
 
89
 
 
90
        bool found = false;
 
91
        if (!templateName.contains(QDir::separator())) {
 
92
                auto dirs = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
 
93
                for (const auto & dir : dirs) {
 
94
                        auto path = QDir(QDir(QDir(dir).filePath("libqtdbusmock")).filePath("templates")).filePath(templateName + ".py");
 
95
                        if (QFileInfo::exists(path)) {
 
96
                                arguments << "--template" << path;
 
97
                                found = true;
 
98
                                break;
 
99
                        }
 
100
                }
 
101
        }
 
102
        if (!found) {
 
103
                arguments << "--template" << templateName;
 
104
        }
88
105
 
89
106
        if (!parameters.isEmpty())
90
107
        {
155
172
                        QDBusConnection::SystemBus);
156
173
}
157
174
 
 
175
void DBusMock::registerHostname1(const QVariantMap& parameters) {
 
176
        registerTemplate("org.freedesktop.hostname1", "org.freedesktop.hostname1", parameters,
 
177
                        QDBusConnection::SystemBus);
 
178
}
 
179
 
 
180
void DBusMock::registerLogin1(const QVariantMap& parameters) {
 
181
        registerTemplate("org.freedesktop.login1", "org.freedesktop.login1", parameters,
 
182
                        QDBusConnection::SystemBus);
 
183
}
 
184
 
158
185
void DBusMock::registerURfkill() {
159
186
        registerURfkill(QVariantMap());
160
187
}