From ed61394b001bfdee35bc204deab201741396b826 Mon Sep 17 00:00:00 2001 From: Bernd Wachter Date: Sat, 20 Apr 2013 15:38:27 +0300 Subject: [PATCH] [sysinfo] Include the interesting bits of QSystemInfo to avoid depending on the whole graphics stack --- board-mappings.ini | 3 + libssu/libssu.pro | 16 +- libssu/mobility-booty/README | 2 + libssu/mobility-booty/qofonoservice_linux.cpp | 408 ++++++++++++++++++ libssu/mobility-booty/qofonoservice_linux_p.h | 202 +++++++++ libssu/mobility-booty/qsysteminfo_dbus_p.h | 55 +++ .../qsysteminfo_linux_common.cpp | 130 ++++++ .../qsysteminfo_linux_common_p.h | 81 ++++ libssu/ssudeviceinfo.cpp | 20 +- rpm/ssu.spec | 5 +- ssu_common.pri | 1 + 11 files changed, 913 insertions(+), 10 deletions(-) create mode 100644 libssu/mobility-booty/README create mode 100644 libssu/mobility-booty/qofonoservice_linux.cpp create mode 100644 libssu/mobility-booty/qofonoservice_linux_p.h create mode 100644 libssu/mobility-booty/qsysteminfo_dbus_p.h create mode 100644 libssu/mobility-booty/qsysteminfo_linux_common.cpp create mode 100644 libssu/mobility-booty/qsysteminfo_linux_common_p.h diff --git a/board-mappings.ini b/board-mappings.ini index 43040f5..4bf91df 100644 --- a/board-mappings.ini +++ b/board-mappings.ini @@ -15,6 +15,9 @@ # - file.exists -- checks for existince of a file in the filesystem # - systeminfo.equals -- compares the model returned by QSystemInfo # with the value provided +# NOTE: systeminfo matching is currently disabled, as this would +# pull in the whole X11 stack, and on Mer/Nemo does cpuinfo +# matching only anyway, which ssu can do better already. # - cpuinfo.contains -- searches /proc/cpuinfo for a string # - arch.equals -- compares with zyppers arch (like i586) # diff --git a/libssu/libssu.pro b/libssu/libssu.pro index b0c84e9..5cd33e6 100644 --- a/libssu/libssu.pro +++ b/libssu/libssu.pro @@ -13,7 +13,10 @@ public_headers = \ HEADERS = \ $${public_headers} \ sandbox_p.h \ - ssucoreconfig.h + ssucoreconfig.h \ + mobility-booty/qofonoservice_linux_p.h \ + mobility-booty/qsysteminfo_linux_common_p.h \ + mobility-booty/qsysteminfo_dbus_p.h SOURCES = \ sandbox.cpp \ @@ -23,11 +26,14 @@ SOURCES = \ ssulog.cpp \ ssuvariables.cpp \ ssurepomanager.cpp \ - ssusettings.cpp + ssusettings.cpp \ + mobility-booty/qofonoservice_linux.cpp \ + mobility-booty/qsysteminfo_linux_common.cpp \ -CONFIG += mobility link_pkgconfig -QT += network xml -MOBILITY += systeminfo +#CONFIG += mobility link_pkgconfig +CONFIG += link_pkgconfig +QT += network xml dbus +#MOBILITY += systeminfo PKGCONFIG += libsystemd-journal install_headers.files = $${public_headers} diff --git a/libssu/mobility-booty/README b/libssu/mobility-booty/README new file mode 100644 index 0000000..d103891 --- /dev/null +++ b/libssu/mobility-booty/README @@ -0,0 +1,2 @@ +This directory contains the handful of bits used from QtSystemInfo, to avoid +pulling in the whole X11 stack. diff --git a/libssu/mobility-booty/qofonoservice_linux.cpp b/libssu/mobility-booty/qofonoservice_linux.cpp new file mode 100644 index 0000000..d42df07 --- /dev/null +++ b/libssu/mobility-booty/qofonoservice_linux.cpp @@ -0,0 +1,408 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qofonoservice_linux_p.h" +#include +#include +#include + +#ifndef QT_NO_DBUS + +QDBusArgument &operator<<(QDBusArgument &argument, const QOfonoProperties &property) +{ + argument.beginStructure(); + argument << property.path << property.properties; + argument.endStructure(); + return argument; +} + +const QDBusArgument &operator>>(const QDBusArgument &argument, QOfonoProperties &property) +{ + argument.beginStructure(); + argument >> property.path >> property.properties; + argument.endStructure(); + return argument; +} + +//QTM_BEGIN_NAMESPACE + +#define OFONO_SERVICE "org.ofono" +#define OFONO_MANAGER_INTERFACE "org.ofono.Manager" +#define OFONO_MANAGER_PATH "/" +#define OFONO_MODEM_INTERFACE "org.ofono.Modem" +#define OFONO_NETWORK_REGISTRATION_INTERFACE "org.ofono.NetworkRegistration" +#define OFONO_NETWORK_OPERATOR_INTERFACE "org.ofono.NetworkOperator" +#define OFONO_SIM_MANAGER_INTERFACE "org.ofono.SimManager" +#define OFONO_CONNECTION_MANAGER_INTERFACE "org.ofono.ConnectionManager" + +QOfonoManagerInterface::QOfonoManagerInterface(QObject *parent) + : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), QLatin1String(OFONO_MANAGER_PATH), + OFONO_MANAGER_INTERFACE, QDBusConnection::systemBus(), parent) +{ + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); +} + +QOfonoManagerInterface::~QOfonoManagerInterface() +{ +} + +QList QOfonoManagerInterface::getModems() +{ + QDBusReply reply = call(QLatin1String("GetModems")); + QList modems; + if (reply.isValid()) { + foreach (const QOfonoProperties &property, reply.value()) + modems << property.path; + } + return modems; +} + +QDBusObjectPath QOfonoManagerInterface::currentModem() +{ + QList modems = getModems(); + foreach (const QDBusObjectPath &modem, modems) { + QOfonoModemInterface device(modem.path()); + if (device.isPowered()) + return modem; + } + return QDBusObjectPath(); +} + +void QOfonoManagerInterface::connectNotify(const char *signal) +{ + if (QLatin1String(signal) == SIGNAL(propertyChangedContext(QString,QString,QDBusVariant))) { + QOfonoDBusHelper *helper = new QOfonoDBusHelper(this); + QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE), + QLatin1String(OFONO_MANAGER_PATH), + QLatin1String(OFONO_MANAGER_INTERFACE), + QLatin1String("PropertyChanged"), + helper, SLOT(propertyChanged(QString,QDBusVariant))); + connect(helper, SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant))); + } +} + +void QOfonoManagerInterface::disconnectNotify(const char */*signal*/) +{ + // TODO: disconnect the DBus signal +} + +QVariant QOfonoManagerInterface::getProperty(const QString &property) +{ + QVariant value; + + if (isValid()) { + QDBusReply reply = call(QLatin1String("GetProperties")); + value = reply.value().value(property); + } + + return value; +} + +QOfonoDBusHelper::QOfonoDBusHelper(QObject *parent) + : QObject(parent) +{ +} + +QOfonoDBusHelper::~QOfonoDBusHelper() +{ +} + +void QOfonoDBusHelper::propertyChanged(const QString &item, const QDBusVariant &value) +{ + QDBusMessage msg = message(); + Q_EMIT propertyChangedContext(msg.path(), item, value); +} + +QOfonoModemInterface::QOfonoModemInterface(const QString &dbusPathName, QObject *parent) + : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), dbusPathName, + OFONO_MODEM_INTERFACE, QDBusConnection::systemBus(), parent) +{ +} + +QOfonoModemInterface::~QOfonoModemInterface() +{ +} + +bool QOfonoModemInterface::isPowered() +{ + QVariant var = getProperty("Powered"); + return qdbus_cast(var); +} + +QString QOfonoModemInterface::getSerial() +{ + QVariant var = getProperty("Serial"); + return qdbus_cast(var); +} + +QVariant QOfonoModemInterface::getProperty(const QString &property) +{ + QVariant value; + + if (isValid()) { + QDBusReply reply = call(QLatin1String("GetProperties")); + value = reply.value().value(property); + } + + return value; +} + +QOfonoNetworkRegistrationInterface::QOfonoNetworkRegistrationInterface(const QString &dbusPathName, QObject *parent) + : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), dbusPathName, + OFONO_NETWORK_REGISTRATION_INTERFACE, QDBusConnection::systemBus(), parent) +{ +} + +QOfonoNetworkRegistrationInterface::~QOfonoNetworkRegistrationInterface() +{ +} + +QString QOfonoNetworkRegistrationInterface::getStatus() +{ + QVariant var = getProperty("Status"); + return qdbus_cast(var); +} + +quint16 QOfonoNetworkRegistrationInterface::getLac() +{ + QVariant var = getProperty("LocationAreaCode"); + return qdbus_cast(var); +} + +quint32 QOfonoNetworkRegistrationInterface::getCellId() +{ + QVariant var = getProperty("CellId"); + return qdbus_cast(var); +} + +QString QOfonoNetworkRegistrationInterface::getTechnology() +{ + QVariant var = getProperty("Technology"); + return qdbus_cast(var); +} + +QString QOfonoNetworkRegistrationInterface::getOperatorName() +{ + QVariant var = getProperty("Name"); + return qdbus_cast(var); +} + +int QOfonoNetworkRegistrationInterface::getSignalStrength() +{ + QVariant var = getProperty("Strength"); + return qdbus_cast(var); +} + +QList QOfonoNetworkRegistrationInterface::getOperators() +{ + QDBusReply reply = call(QLatin1String("GetOperators")); + QList operators; + if (reply.isValid()) { + foreach (const QOfonoProperties &property, reply.value()) + operators << property.path; + } + return operators; +} + +void QOfonoNetworkRegistrationInterface::connectNotify(const char *signal) +{ + if (QLatin1String(signal) == SIGNAL(propertyChangedContext(QString,QString,QDBusVariant))) { + QOfonoDBusHelper *helper = new QOfonoDBusHelper(this); + QDBusConnection::systemBus().connect(QLatin1String(OFONO_SERVICE), + path(), + QLatin1String(OFONO_NETWORK_REGISTRATION_INTERFACE), + QLatin1String("PropertyChanged"), + helper, SLOT(propertyChanged(QString,QDBusVariant))); + connect(helper, SIGNAL(propertyChangedContext(QString,QString,QDBusVariant)), + this,SIGNAL(propertyChangedContext(QString,QString,QDBusVariant))); + } +} + +void QOfonoNetworkRegistrationInterface::disconnectNotify(const char */*signal*/) +{ + // TODO: disconnect the signal +} + +QVariant QOfonoNetworkRegistrationInterface::getProperty(const QString &property) +{ + QVariant value; + + if (isValid()) { + QDBusReply reply = call(QLatin1String("GetProperties")); + value = reply.value().value(property); + } + + return value; +} + +QOfonoNetworkOperatorInterface::QOfonoNetworkOperatorInterface(const QString &dbusPathName, QObject *parent) + : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), dbusPathName, + OFONO_NETWORK_OPERATOR_INTERFACE, QDBusConnection::systemBus(), parent) +{ +} + +QOfonoNetworkOperatorInterface::~QOfonoNetworkOperatorInterface() +{ +} + +QString QOfonoNetworkOperatorInterface::getStatus() +{ + QVariant var = getProperty("Status"); + return qdbus_cast(var); +} + +QString QOfonoNetworkOperatorInterface::getMcc() +{ + QVariant var = getProperty("MobileCountryCode"); + return qdbus_cast(var); +} + +QString QOfonoNetworkOperatorInterface::getMnc() +{ + QVariant var = getProperty("MobileNetworkCode"); + return qdbus_cast(var); +} + +QStringList QOfonoNetworkOperatorInterface::getTechnologies() +{ + QVariant var = getProperty("Technologies"); + return qdbus_cast(var); +} + +QVariant QOfonoNetworkOperatorInterface::getProperty(const QString &property) +{ + QVariant value; + + if (isValid()) { + QDBusReply reply = call(QLatin1String("GetProperties")); + value = reply.value().value(property); + } + + return value; +} + +QOfonoSimInterface::QOfonoSimInterface(const QString &dbusPathName, QObject *parent) + : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), dbusPathName, + OFONO_SIM_MANAGER_INTERFACE, QDBusConnection::systemBus(), parent) +{ +} + +QOfonoSimInterface::~QOfonoSimInterface() +{ +} + +bool QOfonoSimInterface::isPresent() +{ + QVariant var = getProperty("Present"); + return qdbus_cast(var); +} + +QString QOfonoSimInterface::getHomeMcc() +{ + QVariant var = getProperty("MobileCountryCode"); + return qdbus_cast(var); +} + +QString QOfonoSimInterface::getHomeMnc() +{ + QVariant var = getProperty("MobileNetworkCode"); + return qdbus_cast(var); +} + +QString QOfonoSimInterface::pinRequired() +{ + QVariant var = getProperty("PinRequired"); + return qdbus_cast(var); +} + +QString QOfonoSimInterface::getImsi() +{ + QVariant var = getProperty("SubscriberIdentity"); + return qdbus_cast(var); +} + +QVariant QOfonoSimInterface::getProperty(const QString &property) +{ + QVariant value; + + if (isValid()) { + QDBusReply reply = call(QLatin1String("GetProperties")); + value = reply.value().value(property); + } + + return value; +} + +QOfonoConnectionManagerInterface::QOfonoConnectionManagerInterface(const QString &dbusPathName, QObject *parent) + : QDBusAbstractInterface(QLatin1String(OFONO_SERVICE), dbusPathName, + OFONO_CONNECTION_MANAGER_INTERFACE, QDBusConnection::systemBus(), parent) +{ +} + +QOfonoConnectionManagerInterface::~QOfonoConnectionManagerInterface() +{ +} + +QString QOfonoConnectionManagerInterface::bearer() +{ + QVariant var = getProperty("Bearer"); + return qdbus_cast(var); +} + +QVariant QOfonoConnectionManagerInterface::getProperty(const QString &property) +{ + QVariant value; + + if (isValid()) { + QDBusReply reply = call(QLatin1String("GetProperties")); + value = reply.value().value(property); + } + + return value; +} + +#include "moc_qofonoservice_linux_p.cpp" + +//QTM_END_NAMESPACE + +#endif // QT_NO_DBUS diff --git a/libssu/mobility-booty/qofonoservice_linux_p.h b/libssu/mobility-booty/qofonoservice_linux_p.h new file mode 100644 index 0000000..34ce477 --- /dev/null +++ b/libssu/mobility-booty/qofonoservice_linux_p.h @@ -0,0 +1,202 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOFONOSERVICE_H +#define QOFONOSERVICE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +//#include "qmobilityglobal.h" +#include +#include + +struct QOfonoProperties +{ + QDBusObjectPath path; + QVariantMap properties; +}; +Q_DECLARE_METATYPE(QOfonoProperties) + +typedef QList QOfonoPropertyMap; +Q_DECLARE_METATYPE(QOfonoPropertyMap) + +//QTM_BEGIN_NAMESPACE + +class QOfonoManagerInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + QOfonoManagerInterface( QObject *parent = 0); + ~QOfonoManagerInterface(); + + QDBusObjectPath currentModem(); + QList getModems(); + +Q_SIGNALS: + void propertyChangedContext(const QString &path, const QString &item, const QDBusVariant &value); + +protected: + void connectNotify(const char *signal); + void disconnectNotify(const char *signal); + +private: + QVariant getProperty(const QString &property); +}; + +class QOfonoDBusHelper: public QObject, protected QDBusContext +{ + Q_OBJECT + +public: + QOfonoDBusHelper(QObject *parent = 0); + ~QOfonoDBusHelper(); + +public Q_SLOTS: + void propertyChanged(const QString &item, const QDBusVariant &value); + +Q_SIGNALS: + void propertyChangedContext(const QString &path, const QString &item, const QDBusVariant &value); +}; + +class QOfonoModemInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + QOfonoModemInterface(const QString &dbusModemPathName, QObject *parent = 0); + ~QOfonoModemInterface(); + + bool isPowered(); + QString getSerial(); + +private: + QVariant getProperty(const QString &property); +}; + +class QOfonoNetworkRegistrationInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + QOfonoNetworkRegistrationInterface(const QString &dbusModemPathName, QObject *parent = 0); + ~QOfonoNetworkRegistrationInterface(); + + int getSignalStrength(); + QList getOperators(); + QString getOperatorName(); + QString getStatus(); + QString getTechnology(); + quint16 getLac(); + quint32 getCellId(); + +protected: + void connectNotify(const char *signal); + void disconnectNotify(const char *signal); + +private: + QVariant getProperty(const QString &property); + +Q_SIGNALS: + void propertyChangedContext(const QString &path, const QString &item, const QDBusVariant &value); +}; + +class QOfonoNetworkOperatorInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + QOfonoNetworkOperatorInterface(const QString &dbusPathName, QObject *parent = 0); + ~QOfonoNetworkOperatorInterface(); + + QString getMcc(); + QString getMnc(); + QString getStatus(); + QStringList getTechnologies(); + +private: + QVariant getProperty(const QString &property); +}; + +class QOfonoSimInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + QOfonoSimInterface(const QString &dbusModemPathName, QObject *parent = 0); + ~QOfonoSimInterface(); + + bool isPresent(); + QString getHomeMcc(); + QString getHomeMnc(); + QString getImsi(); + QString pinRequired(); + +private: + QVariant getProperty(const QString &property); +}; + +class QOfonoConnectionManagerInterface : public QDBusAbstractInterface +{ + Q_OBJECT + +public: + QOfonoConnectionManagerInterface(const QString &dbusPathName, QObject *parent = 0); + ~QOfonoConnectionManagerInterface(); + + QString bearer(); + +private: + QVariant getProperty(const QString &); +}; + +//QTM_END_NAMESPACE + +#endif //QOFONOSERVICE_H diff --git a/libssu/mobility-booty/qsysteminfo_dbus_p.h b/libssu/mobility-booty/qsysteminfo_dbus_p.h new file mode 100644 index 0000000..8923728 --- /dev/null +++ b/libssu/mobility-booty/qsysteminfo_dbus_p.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSYSTEMINFO_DBUS_P_H +#define QSYSTEMINFO_DBUS_P_H + +static bool ofonoAvailable() +{ + if (QDBusConnection::systemBus().isConnected()) { + QDBusReply reply = QDBusConnection::systemBus().interface()->isServiceRegistered("org.ofono"); + if (reply.isValid() && reply.value()) + return reply.value(); + } + return false; +} + +#endif // QSYSTEMINFO_DBUS_P_H diff --git a/libssu/mobility-booty/qsysteminfo_linux_common.cpp b/libssu/mobility-booty/qsysteminfo_linux_common.cpp new file mode 100644 index 0000000..e47d77c --- /dev/null +++ b/libssu/mobility-booty/qsysteminfo_linux_common.cpp @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qsysteminfo_linux_common_p.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "qofonoservice_linux_p.h" +#include "qsysteminfo_dbus_p.h" + +//QTM_BEGIN_NAMESPACE + +QSystemDeviceInfoLinuxCommonPrivate::QSystemDeviceInfoLinuxCommonPrivate(QObject *parent) + : QObject(parent) +{ + +} + +QSystemDeviceInfoLinuxCommonPrivate::~QSystemDeviceInfoLinuxCommonPrivate() +{ +} + +QString QSystemDeviceInfoLinuxCommonPrivate::imei() +{ +#if !defined(QT_NO_CONNMAN) + if (ofonoAvailable()) { + QOfonoManagerInterface ofonoManager; + QString modem = ofonoManager.currentModem().path(); + if (!modem.isEmpty()) { + QOfonoModemInterface modemIface(modem,this); + QString imei = modemIface.getSerial(); + if (!imei.isEmpty()) + return imei; + } + } +#endif // QT_NO_CONNMAN + + return QString(); +} + +QString QSystemDeviceInfoLinuxCommonPrivate::manufacturer() +{ + QFile vendorId("/sys/devices/virtual/dmi/id/board_vendor"); + if (vendorId.open(QIODevice::ReadOnly)) { + QTextStream cpuinfo(&vendorId); + return cpuinfo.readLine().trimmed(); + } else { + QFile file("/proc/cpuinfo"); + if (!file.open(QIODevice::ReadOnly)) { + qDebug() << "Could not open /proc/cpuinfo"; + } else { + QTextStream cpuinfo(&file); + QString line = cpuinfo.readLine(); + while (!line.isNull()) { + line = cpuinfo.readLine(); + if (line.contains("vendor_id")) + return line.split(": ").at(1).trimmed(); + } + } + } + + return QString(); +} + +QByteArray QSystemDeviceInfoLinuxCommonPrivate::uniqueDeviceID() +{ + QCryptographicHash hash(QCryptographicHash::Sha1); + + // Return the DBUS machine ID + QByteArray dbusId = QDBusConnection::localMachineId(); + hash.addData(dbusId); + + return hash.result().toHex(); +} + + +//#include "moc_qsysteminfo_linux_common_p.cpp" + +//QTM_END_NAMESPACE diff --git a/libssu/mobility-booty/qsysteminfo_linux_common_p.h b/libssu/mobility-booty/qsysteminfo_linux_common_p.h new file mode 100644 index 0000000..11d3368 --- /dev/null +++ b/libssu/mobility-booty/qsysteminfo_linux_common_p.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSYSTEMINFO_LINUX_COMMON_P_H +#define QSYSTEMINFO_LINUX_COMMON_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +/* +#include "qsysteminfo.h" +#include "qsystemdeviceinfo.h" +*/ + +#include "qofonoservice_linux_p.h" + +//QTM_BEGIN_NAMESPACE + +class QSystemDeviceInfoLinuxCommonPrivate : public QObject +{ + Q_OBJECT + +public: + QSystemDeviceInfoLinuxCommonPrivate(QObject *parent = 0); + virtual ~QSystemDeviceInfoLinuxCommonPrivate(); + + QByteArray uniqueDeviceID(); //1.2 + QString imei(); + QString manufacturer(); +}; + + +//QTM_END_NAMESPACE + +#endif // QSYSTEMINFO_LINUX_COMMON_P_H diff --git a/libssu/ssudeviceinfo.cpp b/libssu/ssudeviceinfo.cpp index 9575fae..a481d3f 100644 --- a/libssu/ssudeviceinfo.cpp +++ b/libssu/ssudeviceinfo.cpp @@ -5,7 +5,7 @@ * @date 2013 */ -#include + #include #include @@ -15,7 +15,10 @@ #include "../constants.h" -QTM_USE_NAMESPACE +#include "mobility-booty/qsysteminfo_linux_common_p.h" + +//#include +//QTM_USE_NAMESPACE SsuDeviceInfo::SsuDeviceInfo(QString model): QObject(){ @@ -139,7 +142,14 @@ QString SsuDeviceInfo::deviceModel(){ if (!cachedModel.isEmpty()) return cachedModel; // check if the QSystemInfo model is useful - QSystemDeviceInfo devInfo; + //QSystemDeviceInfo devInfo; + // TODO Current Mer SystemDeviceInfo only returns cpuinfo stuff, + // which is what we can do with cpuinfo matching in a more + // flexible way, so there's not really any need to pull in the + // whole X11 stack just for this. Can be enabled once systeminfo + // is less insane + /* + QSystemDeviceInfoLinuxCommonPrivate devInfo; QString model = devInfo.model(); boardMappings->beginGroup("systeminfo.equals"); keys = boardMappings->allKeys(); @@ -152,6 +162,7 @@ QString SsuDeviceInfo::deviceModel(){ } boardMappings->endGroup(); if (!cachedModel.isEmpty()) return cachedModel; + */ // check if the device can be identified by a string in /proc/cpuinfo procCpuinfo.setFileName("/proc/cpuinfo"); @@ -195,7 +206,8 @@ QString SsuDeviceInfo::deviceModel(){ QString SsuDeviceInfo::deviceUid(){ QString IMEI; - QSystemDeviceInfo devInfo; + //QSystemDeviceInfo devInfo; + QSystemDeviceInfoLinuxCommonPrivate devInfo; IMEI = devInfo.imei(); diff --git a/rpm/ssu.spec b/rpm/ssu.spec index 8166369..35a659b 100644 --- a/rpm/ssu.spec +++ b/rpm/ssu.spec @@ -7,8 +7,11 @@ License: GPLv2 Source0: %{name}-%{version}.tar.gz URL: https://github.com/nemomobile/ssu BuildRequires: pkgconfig(QtCore) +BuildRequires: pkgconfig(QtDBus) +BuildRequires: pkgconfig(QtDeclarative) +BuildRequires: pkgconfig(QtNetwork) +BuildRequires: pkgconfig(QtXml) BuildRequires: pkgconfig(libzypp) -BuildRequires: pkgconfig(QtSystemInfo) BuildRequires: pkgconfig(qt-boostable) BuildRequires: pkgconfig(libsystemd-journal) BuildRequires: oneshot diff --git a/ssu_common.pri b/ssu_common.pri index 9527080..3bd4b18 100644 --- a/ssu_common.pri +++ b/ssu_common.pri @@ -1,4 +1,5 @@ CONFIG -= gui +QT -= gui INCLUDEPATH *= $$PWD DEPENDPATH *= $$PWD