summaryrefslogtreecommitdiffstats
path: root/src/mobility
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2010-05-03 14:05:09 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2010-05-03 14:05:09 +0200
commitb471ca62a783d80ebe4b1253d1768e251cc1b3d4 (patch)
tree7d96f96fdd963fbc1308463428e2465a291f241d /src/mobility
Initial import.
Diffstat (limited to 'src/mobility')
-rw-r--r--src/mobility/contacts.cpp108
-rw-r--r--src/mobility/contacts.h75
-rw-r--r--src/mobility/messaging.cpp149
-rw-r--r--src/mobility/messaging.h56
-rw-r--r--src/mobility/mobility.pri12
-rw-r--r--src/mobility/mobilitydata.cpp262
-rw-r--r--src/mobility/mobilitydata.h82
-rw-r--r--src/mobility/mobilitymanager.cpp503
-rw-r--r--src/mobility/mobilitymanager.h130
9 files changed, 1377 insertions, 0 deletions
diff --git a/src/mobility/contacts.cpp b/src/mobility/contacts.cpp
new file mode 100644
index 0000000..fd5933c
--- /dev/null
+++ b/src/mobility/contacts.cpp
@@ -0,0 +1,108 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#include "contacts.h"
+
+#include <contacts/qcontact.h>
+#include <contacts/qcontactmanager.h>
+#include <contacts/details/qcontactname.h>
+#include <contacts/details/qcontactdisplaylabel.h>
+#include <contacts/details/qcontactphonenumber.h>
+#include <contacts/engines/qcontactmemorybackend_p.h>
+#include <versit/qversitreader.h>
+#include <versit/qversitcontactimporter.h>
+
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QFile>
+#include <QtCore/QTextStream>
+
+using namespace QtMobility;
+
+Contacts::Contacts(QObject *parent)
+ : QObject(parent)
+{
+ QMap<QString, QString> engineParams;
+ engineParams.insert("id", "simulator");
+ mManager = new QContactManager("memory", engineParams, this);
+
+ connect(mManager, SIGNAL(contactsAdded(const QList<QContactLocalId> &)), SIGNAL(contactsAdded(const QList<QContactLocalId> &)));
+ connect(mManager, SIGNAL(contactsChanged(const QList<QContactLocalId> &)), SIGNAL(contactsChanged(const QList<QContactLocalId> &)));
+ connect(mManager, SIGNAL(contactsRemoved(const QList<QContactLocalId> &)), SIGNAL(contactsRemoved(const QList<QContactLocalId> &)));
+ connect(mManager, SIGNAL(relationshipsAdded(QList<QContactLocalId>)), SIGNAL(relationshipsAdded(QList<QContactLocalId>)));
+ connect(mManager, SIGNAL(relationshipsRemoved(QList<QContactLocalId>)), SIGNAL(relationshipsRemoved(QList<QContactLocalId>)));
+}
+
+QContactManager *Contacts::manager()
+{
+ return mManager;
+}
+
+void Contacts::setInitialData()
+{
+ importFromVCardFile("stubdata/standardselfcontact.vcf");
+ if (mManager->contactIds().count() == 1) {
+ mManager->setSelfContactId(mManager->contactIds().at(0));
+ } else {
+ qWarning("The file stubdata/standardselfcontact.vcf contains more than one contact. Not setting a self contact.");
+ }
+
+ importFromVCardFile("stubdata/standardcontacts.vcf");
+}
+
+void Contacts::publish() const
+{
+ emit contactsDataChanged(*mManager);
+}
+
+bool Contacts::importFromVCardFile(const QString &fileName)
+{
+ QFile contactsFile(fileName);
+ contactsFile.open(QIODevice::ReadOnly);
+ if (!contactsFile.isReadable())
+ return false;
+
+ QVersitReader reader;
+ reader.setDevice(&contactsFile);
+ if (!reader.startReading())
+ return false;
+ reader.waitForFinished();
+
+ QVersitContactImporter importer;
+ if (!importer.importDocuments(reader.results())) {
+ qWarning() << "Could not import contacts from " << fileName;
+ return false;
+ }
+
+ QList<QContact> contacts = importer.contacts();
+ QMap<int, QContactManager::Error> errors;
+ mManager->saveContacts(&contacts, &errors);
+
+ return true;
+}
diff --git a/src/mobility/contacts.h b/src/mobility/contacts.h
new file mode 100644
index 0000000..7f18b51
--- /dev/null
+++ b/src/mobility/contacts.h
@@ -0,0 +1,75 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#ifndef CONTACTS_H
+#define CONTACTS_H
+
+#include <QtCore/QObject>
+#include <QtCore/QList>
+#include <contacts/qtcontactsglobal.h>
+
+namespace QtMobility {
+ class QContactManager;
+}
+
+// These are required - otherwise the signals defined below have to contain
+// QtMobility:: in their signature and and that makes connect() refuse to
+// connect them.
+using QtMobility::QContactLocalId;
+using QtMobility::QContactManager;
+
+class Contacts : public QObject
+{
+ Q_OBJECT
+public:
+ explicit Contacts(QObject *parent = 0);
+
+ QtMobility::QContactManager *manager();
+
+public slots:
+ void setInitialData();
+ void publish() const;
+ bool importFromVCardFile(const QString &fileName);
+
+signals:
+ // for incremental changes triggered remotely
+ void contactsAdded(const QList<QContactLocalId> &contactIds) const;
+ void contactsChanged(const QList<QContactLocalId> &contactIds) const;
+ void contactsRemoved(const QList<QContactLocalId> &contactIds) const;
+ void relationshipsAdded(const QList<QContactLocalId> &affectedContactIds) const;
+ void relationshipsRemoved(const QList<QContactLocalId> &affectedContactIds) const;
+
+ // for a complete update triggered by publish
+ void contactsDataChanged(const QContactManager &) const;
+
+private:
+ QtMobility::QContactManager *mManager;
+};
+
+#endif // CONTACTS_H
diff --git a/src/mobility/messaging.cpp b/src/mobility/messaging.cpp
new file mode 100644
index 0000000..00eadc9
--- /dev/null
+++ b/src/mobility/messaging.cpp
@@ -0,0 +1,149 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#include "messaging.h"
+
+#include <qmailstore.h>
+#include <qsimulatordata_p.h>
+
+#include <QtCore/QDir>
+#include <QtCore/QThread>
+
+class MaildirImporter : public QThread
+{
+public:
+ MaildirImporter(const QString &path, QObject *parent = 0)
+ : QThread(parent), mPath(path)
+ {
+ }
+
+protected:
+ virtual void run()
+ {
+ QDir dir(mPath);
+ if (!dir.exists())
+ return;
+
+ QMailStore *store = QMailStore::instance();
+ QMailAccountIdList accountIdList = store->queryAccounts();
+ if (accountIdList.isEmpty())
+ return;
+ QMailFolderIdList folderIdList = store->queryFolders();
+ if (folderIdList.isEmpty())
+ return;
+
+ foreach (const QFileInfo &fileInfo, dir.entryInfoList(QDir::Files)) {
+ QFile file(fileInfo.absoluteFilePath());
+ file.open(QIODevice::ReadOnly);
+ QByteArray data = file.readAll();
+ file.close();
+
+ // RFC 2822 requires CRLF line endings
+ for (int i = 0; i < data.size(); ++i) {
+ if (data.at(i) == '\n' && i > 0 && data.at(i-1) != '\r') {
+ data.insert(i, '\r');
+ ++i;
+ }
+ }
+
+ QMailMessage message(QMailMessage::fromRfc2822(data));
+ if (message.headerFields().isEmpty())
+ continue;
+
+ QMailMessage *storeMessage = new QMailMessage(message);
+ storeMessage->setMessageType(QMailMessage::Email);
+ storeMessage->setParentAccountId(accountIdList.first());
+ storeMessage->setParentFolderId(folderIdList.first());
+ QMailStore::instance()->addMessage(storeMessage);
+ }
+ }
+
+private:
+ QString mPath;
+};
+
+Messaging::Messaging(QObject *parent) :
+ QObject(parent)
+{
+}
+
+void Messaging::setInitialData()
+{
+ // have to use the same on the client
+ QtSimulatorPrivate::qt_setQmfPaths();
+
+ QMailStore *mailstore = QMailStore::instance();
+
+ // remove existing data
+ mailstore->removeAccounts(QMailAccountKey());
+
+ // add stub account
+ QMailAccount *account = new QMailAccount();
+ account->setName("TestAccount");
+ mailstore->addAccount(account, 0);
+
+ // add stub folder
+ QMailFolder *folder = new QMailFolder("TestFolder");
+ mailstore->addFolder(folder);
+
+ importMaildir("stubdata/standardmessages");
+}
+
+void Messaging::addMessage(QMailMessage *message)
+{
+ QMailStore *store = QMailStore::instance();
+ QMailAccountIdList accountIdList = store->queryAccounts();
+ if (accountIdList.isEmpty())
+ return;
+ QMailFolderIdList folderIdList = store->queryFolders();
+ if (folderIdList.isEmpty())
+ return;
+
+ message->setParentAccountId(accountIdList.first());
+ message->setParentFolderId(folderIdList.first());
+ store->addMessage(message);
+}
+
+void Messaging::importMaildir(const QString &path)
+{
+ // remove done threads
+ QMutableListIterator<MaildirImporter *> it(mImporterThreads);
+ while (it.hasNext()) {
+ MaildirImporter *importer = it.next();
+ if (importer->isFinished()) {
+ delete importer;
+ it.remove();
+ }
+ }
+
+ // start new importer thread
+ MaildirImporter *maildirImporter = new MaildirImporter(path, this);
+ maildirImporter->start();
+ mImporterThreads += maildirImporter;
+}
diff --git a/src/mobility/messaging.h b/src/mobility/messaging.h
new file mode 100644
index 0000000..1cbf54d
--- /dev/null
+++ b/src/mobility/messaging.h
@@ -0,0 +1,56 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#ifndef MESSAGING_H
+#define MESSAGING_H
+
+#include <QtCore/QObject>
+
+class MaildirImporter;
+class QMailAccount;
+class QMailFolder;
+class QMailMessage;
+
+class Messaging : public QObject
+{
+Q_OBJECT
+public:
+ explicit Messaging(QObject *parent = 0);
+
+ void importMaildir(const QString &path);
+ void addMessage(QMailMessage *message);
+
+public slots:
+ void setInitialData();
+
+private:
+ QList<MaildirImporter *> mImporterThreads;
+};
+
+#endif // MESSAGING_H
diff --git a/src/mobility/mobility.pri b/src/mobility/mobility.pri
new file mode 100644
index 0000000..86c81a7
--- /dev/null
+++ b/src/mobility/mobility.pri
@@ -0,0 +1,12 @@
+INCLUDEPATH += src/mobility
+DEPENDPATH += src/mobility
+SOURCES += \
+ mobilitymanager.cpp \
+ contacts.cpp \
+ mobilitydata.cpp \
+ messaging.cpp
+HEADERS += \
+ mobilitymanager.h \
+ contacts.h \
+ mobilitydata.h \
+ messaging.h
diff --git a/src/mobility/mobilitydata.cpp b/src/mobility/mobilitydata.cpp
new file mode 100644
index 0000000..469a409
--- /dev/null
+++ b/src/mobility/mobilitydata.cpp
@@ -0,0 +1,262 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#include "mobilitydata.h"
+
+#include <contacts/qcontactmanager.h>
+#include <contacts/qcontact.h>
+#include <contacts/details/qcontactemailaddress.h>
+#include <contacts/details/qcontactphonenumber.h>
+#include <qmailmessage.h>
+
+#include <qmath.h>
+
+using namespace QtMobility;
+
+MobilityData::MobilityData(QObject *parent)
+ : QObject(parent)
+ , mContacts(new Contacts(this))
+ , mLocationUi(0)
+ , mSystemInfoGenericUi(0)
+ , mSystemInfoNetworkUi(0)
+ , mSystemInfoStorageUi(0)
+ , mMessaging(new Messaging(this))
+ , mSensorsUi(0)
+ , mInitialized(false)
+ , mInitializeWithLandscape(false)
+{
+}
+
+void MobilityData::setInitialData()
+{
+ setInitialLocationData();
+ mContacts->setInitialData();
+ setInitialSystemInfoGenericData();
+ setInitialSystemInfoNetworkData();
+ setInitialSystemInfoStorageData();
+ mMessaging->setInitialData();
+ setInitialSensorsData();
+}
+
+void MobilityData::setInitialSensorsData()
+{
+ SensorsUi::SensorsData sensors;
+ sensors.ambientLightLevel = SensorsScriptInterface::Light;
+
+ if (mInitializeWithLandscape) {
+ sensors.accelerometerX = -9.8;
+ sensors.accelerometerY = 0;
+ } else {
+ sensors.accelerometerX = 0;
+ sensors.accelerometerY = 9.8;
+ }
+ sensors.accelerometerZ = 0;
+
+ sensors.magnetometerX = 0.5;
+ sensors.magnetometerY = 0.5;
+ sensors.magnetometerY = 0.5;
+ sensors.magnetometerCalibrationLevel = 0.85;
+
+ sensors.compassCalibrationLevel = 0.85;
+ sensors.compassAzimuth = 132.65;
+
+ sensors.proximitySensorClose = true;
+
+ mSensorsUi->setSensorsData(sensors);
+ mInitialized = true;
+}
+
+void MobilityData::setInitialLocationData()
+{
+ LocationUi::LocationData data;
+ data.latitude = 52.5056819;
+ data.longitude = 13.3232027;
+ data.altitude = 4.897392;
+ data.useCurrentTime = true;
+ mLocationUi->setLocation(data);
+}
+
+void MobilityData::setInitialSystemInfoGenericData()
+{
+ GenericSystemInfoUi::GenericData data;
+ data.currentLanguage = "en";
+ data.currentCountryCode = "EN";
+ data.availableLanguages.append("en");
+ data.availableLanguages.append("de");
+ data.features[GenericSystemInfoScriptInterface::LocationFeature] = true;
+ data.features[GenericSystemInfoScriptInterface::UsbFeature] = true;
+ data.versions[GenericSystemInfoScriptInterface::QtCore] = "4.6 probably";
+ data.versions[GenericSystemInfoScriptInterface::Firmware] = "1.9-alpha-rc7";
+ data.displayBrightness = 100;
+ data.colorDepth = 32;
+ data.profile = GenericSystemInfoScriptInterface::NormalProfile;
+ data.currentPowerState = GenericSystemInfoScriptInterface::WallPower;
+ data.simStatus = GenericSystemInfoScriptInterface::SimNotAvailable;
+ data.inputFlags = static_cast<GenericSystemInfoScriptInterface::InputMethod>
+ (GenericSystemInfoScriptInterface::Keyboard | GenericSystemInfoScriptInterface::Mouse);
+ data.imei = "12-345678-901234-5";
+ data.imsi = "12345679012345";
+ data.manufacturer = "simulator manufacturer";
+ data.model = "simulator model";
+ data.productName = "simulator product name";
+ data.batteryLevel = 84;
+ data.deviceLocked = false;
+ mSystemInfoGenericUi->setGenericData(data);
+}
+
+void MobilityData::setInitialSystemInfoNetworkData()
+{
+ NetworkSystemInfoUi::NetworkData data;
+ data.cellId = 12345;
+ data.locationAreaCode = 54321;
+ data.currentMobileCountryCode = QLatin1String("242");
+ data.currentMobileNetworkCode = QLatin1String("123456789");
+ data.homeMobileCountryCode = QLatin1String("+47");
+ data.homeMobileNetworkCode = QLatin1String("987654321");
+ data.currentMode = NetworkSystemInfoScriptInterface::EthernetMode;
+
+ for (int i = 0; i < data.networkInfo.size(); ++i) {
+ NetworkSystemInfoUi::NetworkData::ModeInfo &mode = data.networkInfo[i];
+
+ mode.name = QLatin1String("name");
+ mode.macAddress = QLatin1String("ff:ff:ff:ff:ff:ff");
+ mode.signalStrength = 75;
+ mode.status = NetworkSystemInfoScriptInterface::UndefinedStatus;
+ }
+ mSystemInfoNetworkUi->setNetworkData(data);
+}
+
+void MobilityData::setInitialSystemInfoStorageData()
+{
+ StorageSystemInfoScriptInterface *si = mSystemInfoStorageUi->scriptInterface();
+ si->addDrive("Internal Drive", StorageSystemInfoScriptInterface::InternalDrive,
+ 256*1024*qint64(1024), 32*1024*qint64(1024));
+ si->addDrive("Removable Drive", StorageSystemInfoScriptInterface::RemovableDrive,
+ 4*1024*1024*qint64(1024), 3*1024*1024*qint64(1024));
+}
+
+static int randomInt(int begin, int end)
+{
+ return begin + floor((qreal)qrand() / RAND_MAX * (end - begin));
+}
+
+void MobilityData::addNewEmail()
+{
+ // ### A script should do this...
+ QContactManager *manager = mContacts->manager();
+
+ // find sender
+ QList<QContact> contacts = manager->contacts();
+ QContact sender = contacts.at(randomInt(0, contacts.size()));
+
+ // find target
+ QContact receiver = manager->contact(manager->selfContactId());
+
+ // make message
+ QMailMessage *message = new QMailMessage();
+ message->setMessageType(QMailMessage::Email);
+ message->setSubject(tr("Generated message"));
+ message->setBody(
+ QMailMessageBody::fromData(tr("This is a simulator-generated email message."),
+ QMailMessageContentType("text/plain"),
+ QMailMessageBodyFwd::NoEncoding));
+ message->setFrom(QMailAddress(sender.displayLabel(),
+ sender.detail<QContactEmailAddress>().emailAddress()));
+ message->setTo(QMailAddress(receiver.displayLabel(),
+ receiver.detail<QContactEmailAddress>().emailAddress()));
+ mMessaging->addMessage(message);
+}
+
+void MobilityData::addNewSms()
+{
+ // ### A script should do this...
+ QContactManager *manager = mContacts->manager();
+
+ // find sender
+ QList<QContact> contacts = manager->contacts();
+ QContact sender = contacts.at(randomInt(0, contacts.size()));
+
+ // find target
+ QContact receiver = manager->contact(manager->selfContactId());
+
+ // make message
+ QMailMessage *message = new QMailMessage();
+ message->setMessageType(QMailMessage::Sms);
+ message->setSubject(tr("Generated message"));
+ message->setBody(
+ QMailMessageBody::fromData(tr("This is a simulator-generated SMS message."),
+ QMailMessageContentType("text/plain"),
+ QMailMessageBodyFwd::NoEncoding));
+ message->setFrom(QMailAddress(sender.displayLabel(),
+ sender.detail<QContactPhoneNumber>().number()));
+ message->setTo(QMailAddress(receiver.displayLabel(),
+ receiver.detail<QContactPhoneNumber>().number()));
+ mMessaging->addMessage(message);
+}
+
+void MobilityData::rotateDevice(Orientation current, Orientation native)
+{
+ SensorsUi::SensorsData sensors = mSensorsUi->sensorsData();
+
+ if (native == landscapeOrientation) {
+ if (current == portraitOrientation) {
+ sensors.accelerometerX -= 9.8;
+ sensors.accelerometerY -= 9.8;
+ } else {
+ sensors.accelerometerX += 9.8;
+ sensors.accelerometerY += 9.8;
+ }
+ } else {
+ if (current == portraitOrientation) {
+ sensors.accelerometerX -= 9.8;
+ sensors.accelerometerY += 9.8;
+ } else {
+ sensors.accelerometerX += 9.8;
+ sensors.accelerometerY -= 9.8;
+ }
+ }
+
+ mSensorsUi->setSensorsData(sensors);
+}
+
+void MobilityData::changeDevice(Orientation current, Orientation currentNative, Orientation targetNative)
+{
+ if (currentNative == targetNative)
+ return;
+
+ if (!mInitialized) {
+ if (targetNative == landscapeOrientation)
+ mInitializeWithLandscape = true;
+ else
+ mInitializeWithLandscape = false;
+ return;
+ }
+
+ rotateDevice(currentNative, current == landscapeOrientation ? portraitOrientation : landscapeOrientation);
+}
diff --git a/src/mobility/mobilitydata.h b/src/mobility/mobilitydata.h
new file mode 100644
index 0000000..4be7c98
--- /dev/null
+++ b/src/mobility/mobilitydata.h
@@ -0,0 +1,82 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#ifndef MOBILITYDATA_H
+#define MOBILITYDATA_H
+
+#include <QObject>
+
+// while a forward declaration would suffice, we include these here
+// as everything using MobilityData will usually want to include them too
+#include "contacts.h"
+#include "systeminfogenericui.h"
+#include "systeminfonetworkui.h"
+#include "systeminfostorageui.h"
+#include "messaging.h"
+#include "sensorsui.h"
+#include "deviceitem.h"
+
+#include <remotecontrolwidget/locationui.h>
+
+class MobilityData : public QObject
+{
+Q_OBJECT
+public:
+ explicit MobilityData(QObject *parent = 0);
+
+ Contacts *mContacts;
+ LocationUi *mLocationUi;
+ GenericSystemInfoUi *mSystemInfoGenericUi;
+ NetworkSystemInfoUi *mSystemInfoNetworkUi;
+ StorageSystemInfoUi *mSystemInfoStorageUi;
+ Messaging *mMessaging;
+ SensorsUi *mSensorsUi;
+
+ void setInitialData();
+
+public slots:
+ void addNewEmail();
+ void addNewSms();
+
+ // for adjusting data based on orientation of device
+ void rotateDevice(Orientation current, Orientation native);
+ void changeDevice(Orientation current, Orientation currentNative, Orientation targetNative);
+
+private:
+ void setInitialSensorsData();
+ void setInitialLocationData();
+ void setInitialSystemInfoNetworkData();
+ void setInitialSystemInfoStorageData();
+ void setInitialSystemInfoGenericData();
+
+ bool mInitialized;
+ bool mInitializeWithLandscape;
+};
+
+#endif // MOBILITYDATA_H
diff --git a/src/mobility/mobilitymanager.cpp b/src/mobility/mobilitymanager.cpp
new file mode 100644
index 0000000..2bb340d
--- /dev/null
+++ b/src/mobility/mobilitymanager.cpp
@@ -0,0 +1,503 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#include "mobilitymanager.h"
+#include "mobilitydata.h"
+
+#include <qsimulatordata_p.h>
+#include <contacts/engines/qcontactmemorybackend_p.h>
+#include <contacts/engines/qcontactmemorybackenddata_simulator_p.h>
+#include <contacts/qcontactmanager.h>
+#include <contacts/qcontactmanager_p.h>
+#include <contacts/qcontactrelationship.h>
+
+#include <QtCore/QList>
+#include <QtCore/QDebug>
+
+#include <QtNetwork/QLocalSocket>
+#include <QtNetwork/QLocalServer>
+
+#include <limits>
+
+using namespace QtMobility;
+
+int MobilityClient::contactsClientsCount = 0;
+
+MobilityServer::MobilityServer(MobilityData *mobility, QObject *parent)
+ : QObject(parent)
+ , mMobility(mobility)
+{
+ mServer = new QLocalServer();
+ QLocalServer::removeServer(SIMULATOR_MOBILITY_SERVERNAME);
+ if (!mServer->listen(SIMULATOR_MOBILITY_SERVERNAME)) {
+ qFatal("Could not open mobility server");
+ }
+ connect(mServer, SIGNAL(newConnection()), this, SLOT(newConnection()));
+
+ qt_registerSystemInfoTypes();
+ qt_registerContactsTypes();
+ qt_registerLocationTypes();
+ qt_registerSensorTypes();
+}
+
+MobilityServer::~MobilityServer()
+{
+ if (mServer) {
+ mServer->close();
+ QLocalServer::removeServer(SIMULATOR_DISPLAY_SERVERNAME);
+ delete mServer;
+ mServer = 0;
+ }
+}
+
+void MobilityServer::newConnection()
+{
+ // get the incoming connection
+ QLocalSocket* socket = mServer->nextPendingConnection();
+ if (!socket->isValid()) {
+ qWarning() << "Invalid socket!";
+ return;
+ }
+
+ // expect an initial application connect packet to to verify that this is
+ // indeed a simulator client application and to get its pid
+ using namespace ::QtSimulatorPrivate;
+
+ // read the command id
+ qint32 requestCommand = 0;
+ qint64 bytesToRead = sizeof(requestCommand);
+ qint64 bytesRead = qt_blockingRead(
+ socket, reinterpret_cast<char *>(&requestCommand), bytesToRead, 500);
+ if (bytesRead < bytesToRead)
+ {
+ qWarning("Dropped incoming connection, couldn't read command id.");
+ return;
+ }
+ if (requestCommand != QtSimulatorPrivate::Command::ApplicationConnect)
+ {
+ qWarning("Dropped incoming connection, it sent an invalid command.");
+ return;
+ }
+
+ // read the command
+ QtSimulatorPrivate::ApplicationConnectCommand cmd;
+ bytesToRead = sizeof(cmd.request);
+ bytesRead = qt_blockingRead(
+ socket, reinterpret_cast<char *>(&cmd.request), bytesToRead, 500);
+ if (bytesRead < bytesToRead)
+ {
+ qWarning("Dropped incoming connection, couldn't read command data.");
+ return;
+ }
+
+ // send a reply
+ qint64 bytesToWrite = sizeof(cmd.reply);
+ qint64 bytesWritten = qt_blockingWrite(
+ socket, reinterpret_cast<const char *>(&cmd.reply), bytesToWrite, 500);
+ if (bytesWritten < bytesToWrite)
+ {
+ qWarning("Dropped incoming connection, couldn't send connect reply.");
+ return;
+ }
+
+ // success: register client
+ mClients.append(new MobilityClient(cmd.request.applicationPid, socket, this));
+}
+
+void MobilityServer::removeClient(MobilityClient *c)
+{
+ mClients.removeAll(c);
+}
+
+MobilityClient::MobilityClient(qint64 pid, QLocalSocket *receiveSocket, MobilityServer *server)
+ : QObject(server)
+ , mPid(pid)
+ , mReceiveSocket(receiveSocket)
+ , mSendSocket(0)
+ , mMobilityServer(server)
+ , mNotifyClientOnContactsChange(true)
+{
+ // initiate sendSocket as a backchannel to the client
+ mSendSocket = new QLocalSocket(this);
+ mSendSocket->connectToServer(qt_mobilityServerName(pid));
+ if (!mSendSocket->waitForConnected(1000))
+ qFatal("Couldn't set up back channel to mobility interface of client");
+
+ // there might be data available already
+ readyRead();
+ connect(mReceiveSocket, SIGNAL(readyRead()), this, SLOT(readyRead()));
+ connect(mReceiveSocket, SIGNAL(disconnected()), this, SLOT(disconnect()));
+}
+
+MobilityClient::~MobilityClient()
+{
+ mSendSocket->disconnectFromServer();
+ mSendSocket->deleteLater();
+}
+
+void MobilityClient::disconnect()
+{
+ mMobilityServer->removeClient(this);
+ delete this;
+}
+
+void MobilityClient::readyRead()
+{
+ mReadBuffer += mReceiveSocket->readAll();
+ forever {
+ QtSimulatorPrivate::IncomingRemoteMetacall rpc;
+ if (rpc.read(&mReadBuffer)) {
+ if (rpc.call(mReceiveSocket, this)) {
+ continue;
+ }
+ qWarning("Ignoring a call to %s, No such slot in MobilityClient.", rpc.signature().data());
+ }
+ break;
+ }
+}
+
+void MobilityClient::sendSystemGenericInfo(const GenericSystemInfoUi::GenericData &data)
+{
+ QSystemInfoData sysInfoData;
+ sysInfoData.availableLanguages = data.availableLanguages;
+ sysInfoData.currentCountryCode = data.currentCountryCode;
+ sysInfoData.currentLanguage = data.currentLanguage;
+ sysInfoData.features = data.features;
+ sysInfoData.versions = data.versions;
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "setSystemInfoData", sysInfoData);
+ QSystemDeviceInfoData deviceInfoData;
+ deviceInfoData.batteryLevel = data.batteryLevel;
+ deviceInfoData.currentPowerState = static_cast<QtMobility::QSystemDeviceInfo::PowerState>(data.currentPowerState);
+ deviceInfoData.currentProfile = static_cast<QtMobility::QSystemDeviceInfo::Profile>(data.profile);
+ deviceInfoData.deviceLocked = data.deviceLocked;
+ deviceInfoData.imei = data.imei;
+ deviceInfoData.imsi = data.imsi;
+ QtMobility::QSystemDeviceInfo::InputMethodFlags flags;
+ if (data.inputFlags & GenericSystemInfoScriptInterface::Keys)
+ flags |= QSystemDeviceInfo::Keys;
+ if (data.inputFlags & GenericSystemInfoScriptInterface::Keypad)
+ flags |= QSystemDeviceInfo::Keypad;
+ if (data.inputFlags & GenericSystemInfoScriptInterface::Keyboard)
+ flags |= QSystemDeviceInfo::Keyboard;
+ if (data.inputFlags & GenericSystemInfoScriptInterface::MultiTouch)
+ flags |= QSystemDeviceInfo::MultiTouch;
+ if (data.inputFlags & GenericSystemInfoScriptInterface::SingleTouch)
+ flags |= QSystemDeviceInfo::SingleTouch;
+ if (data.inputFlags & GenericSystemInfoScriptInterface::Mouse)
+ flags |= QSystemDeviceInfo::Mouse;
+ deviceInfoData.inputMethodType = flags;
+ deviceInfoData.manufacturer = data.manufacturer;
+ deviceInfoData.model = data.model;
+ deviceInfoData.productName = data.productName;
+ deviceInfoData.simStatus = static_cast<QtMobility::QSystemDeviceInfo::SimStatus>(data.simStatus);
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "setSystemDeviceInfoData", deviceInfoData);
+
+ QSystemDisplayInfoData displayInfoData;
+ displayInfoData.colorDepth = data.colorDepth;
+ displayInfoData.displayBrightness = data.displayBrightness;
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "setSystemDisplayInfoData", displayInfoData);
+
+}
+
+void MobilityClient::sendSystemStorageInfo(const StorageSystemInfoUi::StorageData &data)
+{
+ QSystemStorageInfoData storage;
+ QHashIterator<QString, StorageSystemInfoUi::StorageData::DriveInfo> iter(data.drives);
+ while (iter.hasNext()) {
+ iter.next();
+ QSystemStorageInfoData::DriveInfo info;
+ info.type = static_cast<QSystemStorageInfo::DriveType>(iter.value().type);
+ info.availableSpace = iter.value().availableSpace;
+ info.totalSpace = iter.value().totalSpace;
+ storage.drives.insert(iter.key(), info);
+ }
+
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "setSystemStorageInfoData", storage);
+}
+
+void MobilityClient::sendSystemNetworkInfo(const NetworkSystemInfoUi::NetworkData &data)
+{
+ QSystemNetworkInfoData network;
+ network.cellId = data.cellId;
+ network.locationAreaCode = data.locationAreaCode;
+ network.currentMobileCountryCode = data.currentMobileCountryCode;
+ network.currentMobileNetworkCode = data.currentMobileNetworkCode;
+ network.homeMobileCountryCode = data.homeMobileCountryCode;
+ network.homeMobileNetworkCode = data.homeMobileNetworkCode;
+ network.currentMode = static_cast<QSystemNetworkInfo::NetworkMode>(data.currentMode);
+ foreach (const NetworkSystemInfoUi::NetworkData::ModeInfo &modeInfo, data.networkInfo) {
+ QSystemNetworkInfoData::NetworkInfo info;
+ info.name = modeInfo.name;
+ info.macAddress = modeInfo.macAddress;
+ info.signalStrength = modeInfo.signalStrength;
+ info.status = static_cast<QSystemNetworkInfo::NetworkStatus>(modeInfo.status);
+ network.networkInfo.append(info);
+ }
+
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "setSystemNetworkInfoData", network);
+}
+
+void MobilityClient::sendLocationData(const LocationUi::LocationData &data)
+{
+ QGeoPositionInfoData location;
+ location.latitude = data.latitude;
+ location.longitude = data.longitude;
+ location.altitude = data.altitude;
+ if (data.useCurrentTime)
+ location.dateTime = QDateTime();
+ else
+ location.dateTime = data.timestamp;
+ location.minimumInterval = 1000;
+ location.enabled = true;
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "setLocationData", location);
+}
+
+void MobilityClient::sendSensorsData(const SensorsUi::SensorsData &data)
+{
+ QDateTime timestampToSend;
+ if (!data.useCurrentTime)
+ timestampToSend = data.timestamp;
+ QAmbientLightReadingData ambientData;
+ ambientData.lightLevel = static_cast<QtMobility::QAmbientLightReading::LightLevel>(data.ambientLightLevel);
+ ambientData.timestamp = timestampToSend;
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "setAmbientLightData", ambientData);
+
+ QAccelerometerReadingData accelermometerData;
+ accelermometerData.x = data.accelerometerX;
+ accelermometerData.y = data.accelerometerY;
+ accelermometerData.z = data.accelerometerZ;
+ accelermometerData.timestamp = timestampToSend;
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "setAccelerometerData", accelermometerData);
+
+ QMagnetometerReadingData magnetometerData;
+ magnetometerData.x = data.magnetometerX;
+ magnetometerData.y = data.magnetometerY;
+ magnetometerData.z = data.magnetometerZ;
+ magnetometerData.calibrationLevel = data.magnetometerCalibrationLevel;
+ magnetometerData.timestamp = timestampToSend;
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "setMagnetometerData", magnetometerData);
+
+ QCompassReadingData compassData;
+ compassData.azimuth = data.compassAzimuth;
+ compassData.calibrationLevel = data.compassCalibrationLevel;
+ compassData.timestamp = timestampToSend;
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "setCompassData", compassData);
+
+ QProximityReadingData proximityData;
+ proximityData.close = data.proximitySensorClose;
+ proximityData.timestamp = timestampToSend;
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "setProximityData", proximityData);
+}
+
+// Sends simulator contact data to client, overwriting its local data.
+// Can invalidate ids the client stored locally.
+// Ideally it's used only for the initial data transmission.
+void MobilityClient::sendContactData(const QContactManager &manager)
+{
+ QContactSimulatorData data;
+ QContactMemoryEngineData *engineData = static_cast<QContactMemoryEngine *>(manager.d->m_engine)->d;
+ data.m_selfContactId = engineData->m_selfContactId;
+ data.m_contacts = engineData->m_contacts;
+ data.m_contactIds = engineData->m_contactIds;
+ data.m_relationships = engineData->m_relationships;
+ data.m_orderedRelationships = engineData->m_orderedRelationships;
+ data.m_definitionIds = engineData->m_definitionIds;
+ data.m_definitions = engineData->m_definitions;
+ data.m_nextContactId = engineData->m_nextContactId;
+
+ // to avoid collisions, give each client a large area for unique detail ids
+ // ### TODO: Ugly hack.
+ contactsClientsCount++;
+ data.m_lastDetailId = std::numeric_limits<int>::max() / 1000 * contactsClientsCount;
+
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "setContactData", data);
+}
+
+void MobilityClient::setRequestsSystemInfo()
+{
+ connect(mMobilityServer->mMobility->mSystemInfoStorageUi, SIGNAL(storageDataChanged(StorageSystemInfoUi::StorageData)),
+ SLOT(sendSystemStorageInfo(StorageSystemInfoUi::StorageData)));
+ connect(mMobilityServer->mMobility->mSystemInfoGenericUi, SIGNAL(genericDataChanged(GenericSystemInfoUi::GenericData)),
+ SLOT(sendSystemGenericInfo(GenericSystemInfoUi::GenericData)));
+ connect(mMobilityServer->mMobility->mSystemInfoNetworkUi, SIGNAL(networkDataChanged(NetworkSystemInfoUi::NetworkData)),
+ SLOT(sendSystemNetworkInfo(NetworkSystemInfoUi::NetworkData)));
+ sendSystemGenericInfo(mMobilityServer->mMobility->mSystemInfoGenericUi->genericData());
+ sendSystemNetworkInfo(mMobilityServer->mMobility->mSystemInfoNetworkUi->networkData());
+ sendSystemStorageInfo(mMobilityServer->mMobility->mSystemInfoStorageUi->storageData());
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "initialSystemInfoDataSent");
+}
+
+void MobilityClient::setRequestsLocationInfo()
+{
+ connect(mMobilityServer->mMobility->mLocationUi, SIGNAL(locationChanged(LocationUi::LocationData)),
+ SLOT(sendLocationData(LocationUi::LocationData)));
+ sendLocationData(mMobilityServer->mMobility->mLocationUi->locationData());
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "initialLocationDataSent");
+}
+
+void MobilityClient::setRequestsContactInfo()
+{
+ connect(mMobilityServer->mMobility->mContacts, SIGNAL(contactsDataChanged(QContactManager)), this, SLOT(sendContactData(QContactManager)));
+ connect(mMobilityServer->mMobility->mContacts, SIGNAL(contactsAdded(QList<QContactLocalId>)), this, SLOT(sendAddedContacts(QList<QContactLocalId>)));
+ connect(mMobilityServer->mMobility->mContacts, SIGNAL(contactsChanged(QList<QContactLocalId>)), this, SLOT(sendChangedContacts(QList<QContactLocalId>)));
+ connect(mMobilityServer->mMobility->mContacts, SIGNAL(contactsRemoved(QList<QContactLocalId>)), this, SLOT(sendRemovedContacts(QList<QContactLocalId>)));
+ connect(mMobilityServer->mMobility->mContacts, SIGNAL(relationshipsAdded(QList<QContactLocalId>)), this, SLOT(sendRelationshipsFor(QList<QContactLocalId>)));
+ connect(mMobilityServer->mMobility->mContacts, SIGNAL(relationshipsRemoved(QList<QContactLocalId>)), this, SLOT(sendRelationshipsFor(QList<QContactLocalId>)));
+}
+
+void MobilityClient::setRequestsSensors()
+{
+ connect(mMobilityServer->mMobility->mSensorsUi, SIGNAL(sensorsDataChanged(SensorsUi::SensorsData)),
+ SLOT(sendSensorsData(SensorsUi::SensorsData)));
+ sendSensorsData(mMobilityServer->mMobility->mSensorsUi->sensorsData());
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "initialSensorsDataSent");
+}
+
+void MobilityClient::triggerContactDataResend()
+{
+ mMobilityServer->mMobility->mContacts->publish();
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "initialContactDataSent");
+}
+
+Simulator::SaveContactReply MobilityClient::requestSaveContact(const QContact &contact)
+{
+ Simulator::SaveContactReply reply;
+ reply.savedContact = contact;
+
+ // execute change and notify other clients in the process
+ mNotifyClientOnContactsChange = false;
+ mMobilityServer->mMobility->mContacts->manager()->saveContact(&reply.savedContact);
+ mNotifyClientOnContactsChange = true;
+
+ reply.error = mMobilityServer->mMobility->mContacts->manager()->error();
+ return reply;
+}
+
+int MobilityClient::requestRemoveContact(uint id)
+{
+ // execute change and notify other clients in the process
+ mNotifyClientOnContactsChange = false;
+ mMobilityServer->mMobility->mContacts->manager()->removeContact(id);
+ mNotifyClientOnContactsChange = true;
+
+ return static_cast<int>(mMobilityServer->mMobility->mContacts->manager()->error());
+}
+
+Simulator::SaveRelationshipReply MobilityClient::requestSaveRelationship(const QContactRelationship &relationship)
+{
+ Simulator::SaveRelationshipReply reply;
+ reply.savedRelationship = relationship;
+
+ // execute change and notify other clients in the process
+ mNotifyClientOnContactsChange = false;
+ mMobilityServer->mMobility->mContacts->manager()->saveRelationship(&reply.savedRelationship);
+ mNotifyClientOnContactsChange = true;
+
+ reply.error = mMobilityServer->mMobility->mContacts->manager()->error();
+ return reply;
+}
+
+int MobilityClient::requestRemoveRelationship(const QContactRelationship &relationship)
+{
+ // execute change and notify other clients in the process
+ mNotifyClientOnContactsChange = false;
+ mMobilityServer->mMobility->mContacts->manager()->removeRelationship(relationship);
+ mNotifyClientOnContactsChange = true;
+
+ return static_cast<int>(mMobilityServer->mMobility->mContacts->manager()->error());
+}
+
+void MobilityClient::sendAddedContacts(const QList<QContactLocalId> &contactIds)
+{
+ if (!mNotifyClientOnContactsChange)
+ return;
+
+ foreach (QContactLocalId id, contactIds) {
+ const QContact &contact = mMobilityServer->mMobility->mContacts->manager()->contact(id);
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "addContact", contact);
+ }
+}
+
+void MobilityClient::sendChangedContacts(const QList<QContactLocalId> &contactIds)
+{
+ if (!mNotifyClientOnContactsChange)
+ return;
+
+ foreach (QContactLocalId id, contactIds) {
+ const QContact &contact = mMobilityServer->mMobility->mContacts->manager()->contact(id);
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "changeContact", contact);
+ }
+}
+
+void MobilityClient::sendRemovedContacts(const QList<QContactLocalId> &contactIds)
+{
+ if (!mNotifyClientOnContactsChange)
+ return;
+
+ foreach (QContactLocalId id, contactIds) {
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "removeContact", id);
+ }
+}
+
+void MobilityClient::sendRelationshipsFor(const QList<QContactLocalId> &contactIds)
+{
+ if (!mNotifyClientOnContactsChange)
+ return;
+
+ QContactManager *manager = mMobilityServer->mMobility->mContacts->manager();
+
+ foreach (QContactLocalId localId, contactIds) {
+ QContactId id(manager->contact(localId).id());
+ QList<QContactRelationship> relationships(manager->relationships(id));
+ QVariantList list;
+ foreach (const QContactRelationship &r, relationships)
+ list.append(QVariant::fromValue(r));
+ QtSimulatorPrivate::RemoteMetacall<void>::call(mSendSocket, QtSimulatorPrivate::NoSync,
+ "setRelationships", localId, list);
+ }
+}
diff --git a/src/mobility/mobilitymanager.h b/src/mobility/mobilitymanager.h
new file mode 100644
index 0000000..0888f3d
--- /dev/null
+++ b/src/mobility/mobilitymanager.h
@@ -0,0 +1,130 @@
+/**************************************************************************
+**
+** This file is part of Qt Simulator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#ifndef MOBILITY_H
+#define MOBILITY_H
+
+#include "sensorsui.h"
+#include "systeminfonetworkui.h"
+#include "systeminfostorageui.h"
+#include "systeminfogenericui.h"
+
+#include <remotecontrolwidget/locationui.h>
+
+#include <systeminfo/qsysteminfodata_simulator_p.h>
+#include <location/qgeopositioninfodata_simulator_p.h>
+#include <mobilitysimulator/mobilityconnection_p.h>
+#include <contacts/engines/qcontactmemorybackenddata_simulator_p.h>
+#include <contacts/engines/qcontactmemorybackenddata_simulator_p.h>
+#include <../plugins/sensors/simulator/qsensordata_simulator_p.h>
+
+class QLocalSocket;
+class QLocalServer;
+class MobilityData;
+class MobilityClient;
+namespace QtMobility {
+ class QContactManager;
+ class QContact;
+}
+// Required to give some slots below a connectable signature.
+using namespace QtMobility;
+
+class MobilityServer : public QObject
+{
+ Q_OBJECT
+public:
+ explicit MobilityServer(MobilityData *mobility, QObject *parent = 0);
+ ~MobilityServer();
+
+private slots:
+ void newConnection();
+
+private:
+ void removeClient(MobilityClient *c);
+
+ QLocalServer *mServer;
+ QList<MobilityClient *> mClients;
+
+ MobilityData *mMobility;
+
+ friend class MobilityClient;
+};
+
+class MobilityClient : public QObject
+{
+ Q_OBJECT
+public:
+ MobilityClient(qint64 pid, QLocalSocket *receiveSocket, MobilityServer *server);
+ ~MobilityClient();
+
+public slots:
+ void sendSystemStorageInfo(const StorageSystemInfoUi::StorageData &data);
+ void sendSystemGenericInfo(const GenericSystemInfoUi::GenericData &data);
+ void sendSystemNetworkInfo(const NetworkSystemInfoUi::NetworkData &data);
+
+ void sendLocationData(const LocationUi::LocationData &data);
+
+ void sendContactData(const QContactManager &manager);
+
+ void sendSensorsData(const SensorsUi::SensorsData &data);
+
+private slots:
+ void disconnect();
+ void readyRead();
+
+ void sendAddedContacts(const QList<QContactLocalId> &);
+ void sendChangedContacts(const QList<QContactLocalId> &);
+ void sendRemovedContacts(const QList<QContactLocalId> &);
+ void sendRelationshipsFor(const QList<QContactLocalId> &);
+
+ // called remotely
+ void setRequestsSystemInfo();
+ void setRequestsLocationInfo();
+ void setRequestsContactInfo();
+ void setRequestsSensors();
+ void triggerContactDataResend();
+
+ QtMobility::Simulator::SaveContactReply requestSaveContact(const QtMobility::QContact &contact);
+ int requestRemoveContact(uint id);
+ QtMobility::Simulator::SaveRelationshipReply requestSaveRelationship(const QtMobility::QContactRelationship &relationship);
+ int requestRemoveRelationship(const QtMobility::QContactRelationship &relationship);
+
+private:
+ qint64 mPid;
+ QLocalSocket *mReceiveSocket;
+ QLocalSocket *mSendSocket;
+ QByteArray mReadBuffer;
+ MobilityServer *mMobilityServer;
+
+ bool mNotifyClientOnContactsChange;
+
+ static int contactsClientsCount;
+};
+
+#endif // MOBILITY_H