Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #66 from monich/qofonomodeminterface
Add base classes for modem interfaces
  • Loading branch information
monich committed Dec 12, 2014
2 parents bf74f19 + 0eaa927 commit dea86a4
Show file tree
Hide file tree
Showing 75 changed files with 2,783 additions and 3,116 deletions.
8 changes: 5 additions & 3 deletions plugin/plugin.pro
Expand Up @@ -13,15 +13,17 @@ equals(QT_MAJOR_VERSION, 4):{

equals(QT_MAJOR_VERSION, 5): {
QT += qml
QT-=gui
QT -= gui
LIBS += -L../src -lqofono-qt5
}

SOURCES = \
qofonodeclarativeplugin.cpp
qofonodeclarativeplugin.cpp \
qofononetworkoperatorlistmodel.cpp

HEADERS = \
qofonodeclarativeplugin.h
qofonodeclarativeplugin.h \
qofononetworkoperatorlistmodel.h

INCLUDEPATH += ../src

Expand Down
71 changes: 39 additions & 32 deletions plugin/qofonodeclarativeplugin.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Copyright (C) 2013-2014 Jolla Ltd.
** Contact: lorn.potter@jollamobile.com
**
** GNU Lesser General Public License Usage
Expand Down Expand Up @@ -60,55 +60,62 @@
#include "qofonopositioningrequestagent.h"
#include "qofonolocationreporting.h"

#include "qofononetworkoperatorlistmodel.h"

void QOfonoDeclarativePlugin::registerTypes(const char *uri)
void QOfonoDeclarativePlugin::registerTypes(const char *uri, int major, int minor)
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("MeeGo.QOfono"));

qmlRegisterType<QOfonoManager>(uri,0,2,"OfonoManager");
qmlRegisterType<QOfonoModem>(uri,0,2,"OfonoModem");
qmlRegisterType<QOfonoManager>(uri,major,minor,"OfonoManager");
qmlRegisterType<QOfonoModem>(uri,major,minor,"OfonoModem");

qmlRegisterType<QOfonoConnectionManager>(uri,major,minor,"OfonoConnMan");
qmlRegisterType<QOfonoConnectionContext>(uri,major,minor,"OfonoContextConnection");

qmlRegisterType<QOfonoConnectionManager>(uri,0,2,"OfonoConnMan");
qmlRegisterType<QOfonoConnectionContext>(uri,0,2,"OfonoContextConnection");
qmlRegisterType<QOfonoNetworkRegistration>(uri,major,minor,"OfonoNetworkRegistration");
qmlRegisterType<QOfonoNetworkOperator>(uri,major,minor,"OfonoNetworkOperator");

qmlRegisterType<QOfonoNetworkRegistration>(uri,0,2,"OfonoNetworkRegistration");
qmlRegisterType<QOfonoNetworkOperator>(uri,0,2,"OfonoNetworkOperator");
qmlRegisterType<QOfonoCellBroadcast>(uri,major,minor,"OfonoCellBroadcast");

qmlRegisterType<QOfonoCellBroadcast>(uri,0,2,"OfonoCellBroadcast");
qmlRegisterType<QOfonoCallBarring>(uri,major,minor,"OfonoCallBarring");
qmlRegisterType<QOfonoCallForwarding>(uri,major,minor,"OfonoCallForwarding");

qmlRegisterType<QOfonoCallBarring>(uri,0,2,"OfonoCallBarring");
qmlRegisterType<QOfonoCallForwarding>(uri,0,2,"OfonoCallForwarding");
qmlRegisterType<QOfonoCallSettings>(uri,major,minor,"OfonoCallSettings");
qmlRegisterType<QOfonoCallMeter>(uri,major,minor,"OfonoCallMeter");

qmlRegisterType<QOfonoCallSettings>(uri,0,2,"OfonoCallSettings");
qmlRegisterType<QOfonoCallMeter>(uri,0,2,"OfonoCallMeter");
qmlRegisterType<QOfonoMessage>(uri,major,minor,"OfonoMessage");
qmlRegisterType<QOfonoMessageManager>(uri,major,minor,"OfonoMessageManager");
qmlRegisterType<QOfonoMessageWaiting>(uri,major,minor,"OfonoMessageWaiting");

qmlRegisterType<QOfonoMessage>(uri,0,2,"OfonoMessage");
qmlRegisterType<QOfonoMessageManager>(uri,0,2,"OfonoMessageManager");
qmlRegisterType<QOfonoMessageWaiting>(uri,0,2,"OfonoMessageWaiting");
qmlRegisterType<QOfonoSimManager>(uri,major,minor,"OfonoSimManager");

qmlRegisterType<QOfonoSimManager>(uri,0,2,"OfonoSimManager");
qmlRegisterType<QOfonoSmartMessaging>(uri,major,minor,"OfonoSmartMessaging");
qmlRegisterType<QOfonoSmartMessagingAgent>(uri,major,minor,"OfonoSmartMessagingAgent");

qmlRegisterType<QOfonoSmartMessaging>(uri,0,2,"OfonoSmartMessaging");
qmlRegisterType<QOfonoSmartMessagingAgent>(uri,0,2,"OfonoSmartMessagingAgent");
qmlRegisterType<QOfonoVoiceCall>(uri,major,minor,"OfonoVoiceCall");
qmlRegisterType<QOfonoVoiceCallManager>(uri,major,minor,"OfonoVoiceCallManager");

qmlRegisterType<QOfonoVoiceCall>(uri,0,2,"OfonoVoiceCall");
qmlRegisterType<QOfonoVoiceCallManager>(uri,0,2,"OfonoVoiceCallManager");
qmlRegisterType<QOfonoRadioSettings>(uri,major,minor,"OfonoRadioSettings");
qmlRegisterType<QOfonoSupplementaryServices>(uri,major,minor,"OfonoSupplementaryServices");

qmlRegisterType<QOfonoRadioSettings>(uri,0,2,"OfonoRadioSettings");
qmlRegisterType<QOfonoSupplementaryServices>(uri,0,2,"OfonoSupplementaryServices");
qmlRegisterType<QOfonoPhonebook>(uri,major,minor,"OfonoPhonebook");
qmlRegisterType<QOfonoTextTelephony>(uri,major,minor,"OfonoTextTelephony");

qmlRegisterType<QOfonoPhonebook>(uri,0,2,"OfonoPhonebook");
qmlRegisterType<QOfonoTextTelephony>(uri,0,2,"OfonoTextTelephony");
qmlRegisterType<QOfonoHandsfree>(uri,major,minor,"OfonoHandsfree");
qmlRegisterType<QOfonoHandsfreeAudioAgent>(uri,major,minor,"OfonoHandsfreeAudioAgent");
qmlRegisterType<QOfonoHandsfreeAudioCard>(uri,major,minor,"OfonoHandsfreeAudioCard");
qmlRegisterType<QOfonoHandsfreeAudioManager>(uri,major,minor,"OfonoHandsfreeAudioManager");

qmlRegisterType<QOfonoHandsfree>(uri,0,2,"OfonoHandsfree");
qmlRegisterType<QOfonoHandsfreeAudioAgent>(uri,0,2,"OfonoHandsfreeAudioAgent");
qmlRegisterType<QOfonoHandsfreeAudioCard>(uri,0,2,"OfonoHandsfreeAudioCard");
qmlRegisterType<QOfonoHandsfreeAudioManager>(uri,0,2,"OfonoHandsfreeAudioManager");
qmlRegisterType<QOfonoAssistedSatelliteNavigation>(uri,major,minor,"OfonoAssistedSatelliteNavigation");
qmlRegisterType<QOfonoPositioningRequestAgent>(uri,major,minor,"OfonoPositioningRequestAgent");
qmlRegisterType<QOfonoLocationReporting>(uri,major,minor,"OfonoLocationReporting");

qmlRegisterType<QOfonoAssistedSatelliteNavigation>(uri,0,2,"OfonoAssistedSatelliteNavigation");
qmlRegisterType<QOfonoPositioningRequestAgent>(uri,0,2,"OfonoPositioningRequestAgent");
qmlRegisterType<QOfonoLocationReporting>(uri,0,2,"OfonoLocationReporting");
qmlRegisterType<QOfonoNetworkOperatorListModel>(uri,major,minor,"OfonoNetworkOperatorListModel");
}

void QOfonoDeclarativePlugin::registerTypes(const char *uri)
{
registerTypes(uri, 0, 2);
}

#if QT_VERSION < 0x050000
Expand Down
3 changes: 2 additions & 1 deletion plugin/qofonodeclarativeplugin.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Copyright (C) 2013-2014 Jolla Ltd.
** Contact: lorn.potter@jollamobile.com
**
** GNU Lesser General Public License Usage
Expand Down Expand Up @@ -34,6 +34,7 @@ class QOFONOSHARED_EXPORT QOfonoDeclarativePlugin : public QQmlExtensionPlugin
#endif
public:
void registerTypes(const char *uri);
static void registerTypes(const char *uri, int major, int minor);
#if QT_VERSION < 0x050000
void initializeEngine(QDeclarativeEngine *engine, const char *uri);
#endif
Expand Down
165 changes: 165 additions & 0 deletions plugin/qofononetworkoperatorlistmodel.cpp
@@ -0,0 +1,165 @@
/****************************************************************************
**
** Copyright (C) 2014 Jolla Ltd.
** Contact: slava.monich@jolla.com
**
** 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.
**
****************************************************************************/

#include "qofononetworkoperatorlistmodel.h"

QOfonoNetworkOperatorListModel::QOfonoNetworkOperatorListModel(QObject *parent) :
QAbstractListModel(parent)
{
netreg = new QOfonoNetworkRegistration(this);
onNetworkOperatorsChanged(netreg->networkOperators());
connect(netreg,
SIGNAL(validChanged(bool)),
SIGNAL(validChanged(bool)));
connect(netreg,
SIGNAL(modemPathChanged(QString)),
SIGNAL(modemPathChanged(QString)));
connect(netreg,
SIGNAL(networkOperatorsChanged(QStringList)),
SLOT(onNetworkOperatorsChanged(QStringList)));
}

QString QOfonoNetworkOperatorListModel::modemPath() const
{
return netreg->modemPath();
}

void QOfonoNetworkOperatorListModel::setModemPath(const QString &path)
{
netreg->setModemPath(path);
}

bool QOfonoNetworkOperatorListModel::isValid() const
{
return netreg->isValid();
}

int QOfonoNetworkOperatorListModel::rowCount(const QModelIndex &) const
{
return operators.count();
}

int QOfonoNetworkOperatorListModel::count() const
{
return operators.count();
}

QVariant QOfonoNetworkOperatorListModel::data(const QModelIndex &index, int role) const
{
int row = index.row();
if (row >= 0 && row < operators.count()) {
QOfonoNetworkOperator* op = netreg->networkOperator(operators[row]);
if (op) {
switch (role) {
case PathRole: return op->operatorPath();
case NameRole: return op->name();
case StatusRole: return op->status();
case MccRole: return op->mcc();
case MncRole: return op->mnc();
case TechRole: return op->technologies();
case InfoRole: return op->additionalInfo();
}
}
}
qWarning() << index << role;
return QVariant();
}

QHash<int,QByteArray> QOfonoNetworkOperatorListModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[PathRole] = "operatorPath";
roles[NameRole] = "name";
roles[StatusRole] = "status";
roles[MccRole] = "mcc";
roles[MncRole] = "mnc";
roles[TechRole] = "technologies";
roles[InfoRole] = "additionalInfo";
return roles;
}

void QOfonoNetworkOperatorListModel::operatorPropertyChanged(OperatorRole role)
{
QOfonoNetworkOperator* op = (QOfonoNetworkOperator*)sender();
if (op) {
int row = operators.indexOf(op->operatorPath());
if (row >= 0) {
QModelIndex modelIndex = index(row);
QVector<int> roles;
roles.append(role);
Q_EMIT dataChanged(modelIndex, modelIndex, roles);
}
}
}

void QOfonoNetworkOperatorListModel::onNetworkOperatorsChanged(const QStringList &list)
{
beginResetModel();
const int oldCount = operators.count();
const int n = list.count();
operators = list;
for (int i=0; i<n; i++) {
QOfonoNetworkOperator* op = netreg->networkOperator(list[i]);
if (op) {
op->disconnect(this);
connect(op, SIGNAL(operatorPathChanged(QString)), SLOT(onOperatorPathChanged(QString)));
connect(op, SIGNAL(nameChanged(QString)), SLOT(onOperatorNameChanged(QString)));
connect(op, SIGNAL(statusChanged(QString)), SLOT(onOperatorStatusChanged(QString)));
connect(op, SIGNAL(mccChanged(QString)), SLOT(onOperatorMccChanged(QString)));
connect(op, SIGNAL(mncChanged(QString)), SLOT(onOperatorMncChanged(QString)));
connect(op, SIGNAL(technologiesChanged(QStringList)), SLOT(onOperatorTechChanged(QStringList)));
connect(op, SIGNAL(additionalInfoChanged(QString)), SLOT(onOperatorInfoChanged(QString)));
}
}
if (oldCount != n) {
Q_EMIT countChanged(n);
}
endResetModel();
}

void QOfonoNetworkOperatorListModel::onOperatorPathChanged(const QString &)
{
operatorPropertyChanged(PathRole);
}

void QOfonoNetworkOperatorListModel::onOperatorNameChanged(const QString &)
{
operatorPropertyChanged(NameRole);
}

void QOfonoNetworkOperatorListModel::onOperatorStatusChanged(const QString &)
{
operatorPropertyChanged(StatusRole);
}

void QOfonoNetworkOperatorListModel::onOperatorMccChanged(const QString &)
{
operatorPropertyChanged(MccRole);
}

void QOfonoNetworkOperatorListModel::onOperatorMncChanged(const QString &)
{
operatorPropertyChanged(MncRole);
}

void QOfonoNetworkOperatorListModel::onOperatorTechChanged(const QStringList &)
{
operatorPropertyChanged(TechRole);
}

void QOfonoNetworkOperatorListModel::onOperatorInfoChanged(const QString &)
{
operatorPropertyChanged(InfoRole);
}
74 changes: 74 additions & 0 deletions plugin/qofononetworkoperatorlistmodel.h
@@ -0,0 +1,74 @@
/****************************************************************************
**
** Copyright (C) 2014 Jolla Ltd.
** Contact: slava.monich@jolla.com
**
** 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.
**
****************************************************************************/

#ifndef QOFONONETWORKOPERATORLISTMODEL_H
#define QOFONONETWORKOPERATORLISTMODEL_H

#include "qofononetworkregistration.h"

class QOfonoNetworkOperatorListModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(QString modemPath READ modemPath WRITE setModemPath NOTIFY modemPathChanged)
Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
Q_PROPERTY(int count READ count NOTIFY countChanged)

public:
enum OperatorRole {
PathRole = Qt::UserRole + 1,
NameRole,
StatusRole,
MccRole,
MncRole,
TechRole,
InfoRole
};

explicit QOfonoNetworkOperatorListModel(QObject* parent = NULL);

QString modemPath() const;
void setModemPath(const QString &path);
bool isValid() const;
int count() const;

int rowCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;

protected:
QHash<int,QByteArray> roleNames() const;

Q_SIGNALS:
void modemPathChanged(const QString &value);
void validChanged(bool value);
void countChanged(int value);

private Q_SLOTS:
void onNetworkOperatorsChanged(const QStringList &list);
void onOperatorNameChanged(const QString &value);
void onOperatorStatusChanged(const QString &value);
void onOperatorMccChanged(const QString &value);
void onOperatorMncChanged(const QString &value);
void onOperatorTechChanged(const QStringList &value);
void onOperatorInfoChanged(const QString &value);
void onOperatorPathChanged(const QString &value);

private:
void operatorPropertyChanged(OperatorRole role);

private:
QOfonoNetworkRegistration *netreg;
QStringList operators;
};

#endif // QOFONONETWORKOPERATORLISTMODEL_H

0 comments on commit dea86a4

Please sign in to comment.