diff --git a/CMakeLists.txt b/CMakeLists.txt index 80b6719b623347c0969d5a7979dd308252455049..2739729ae0485e4a86cdefb39ba414dbcfb3464d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -217,6 +217,7 @@ SET( libringclient_LIB_SRCS #Data objects src/call.cpp src/uri.cpp + src/ringdevice.cpp src/account.cpp src/credential.cpp src/person.cpp @@ -243,6 +244,7 @@ SET( libringclient_LIB_SRCS #Models src/bootstrapmodel.cpp + src/ringdevicemodel.cpp src/accountmodel.cpp src/availableaccountmodel.cpp src/callmodel.cpp @@ -350,6 +352,7 @@ ENDIF(${ENABLE_LIBWRAP} MATCHES true) # Public API SET( libringclient_LIB_HDRS src/account.h + src/ringdevice.h src/credential.h src/accountmodel.h src/availableaccountmodel.h @@ -359,6 +362,7 @@ SET( libringclient_LIB_HDRS src/categorizedhistorymodel.h src/person.h src/bootstrapmodel.h + src/ringdevicemodel.h src/collectioninterface.h src/collectioninterface.hpp src/categorizedbookmarkmodel.h @@ -580,6 +584,7 @@ ENDIF() # Manually wrap private files and interfaces SET(libringclient_PRIVATE_HDRS src/private/call_p.h + src/private/ringdevicemodel_p.h src/private/account_p.h src/private/sortproxies.h src/private/accountmodel_p.h diff --git a/src/account.cpp b/src/account.cpp index 9bf165f2e5a770649083759a206b5027f67c013a..2d195ab638026ede30c6ff7c0a006b5fa0db80b3 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -46,6 +46,7 @@ #include "ciphermodel.h" #include "protocolmodel.h" #include "bootstrapmodel.h" +#include "ringdevicemodel.h" #include "trustrequest.h" #include "person.h" #include "profile.h" @@ -101,7 +102,8 @@ m_pStatusModel(nullptr),m_LastTransportCode(0),m_RegistrationState(Account::Regi m_UseDefaultPort(false),m_pProtocolModel(nullptr),m_pBootstrapModel(nullptr),m_RemoteEnabledState(false), m_HaveCalled(false),m_TotalCount(0),m_LastWeekCount(0),m_LastTrimCount(0),m_LastUsed(0),m_pKnownCertificates(nullptr), m_pBannedCertificates(nullptr), m_pAllowedCertificates(nullptr),m_InternalId(++p_sAutoIncrementId), -m_pNetworkInterfaceModel(nullptr),m_pAllowedCerts(nullptr),m_pBannedCerts(nullptr),m_pPendingTrustRequestModel(nullptr) +m_pNetworkInterfaceModel(nullptr),m_pAllowedCerts(nullptr),m_pBannedCerts(nullptr),m_pPendingTrustRequestModel(nullptr), +m_pRingDeviceModel(nullptr) { } @@ -278,6 +280,12 @@ const QByteArray Account::id() const return d_ptr->m_AccountId; } +///Get the device ID +QString Account::deviceId() const +{ + return d_ptr->accountDetail(DRing::Account::ConfProperties::RING_DEVICE_ID); +} + ///Get current state const QString Account::toHumanStateName() const { @@ -290,6 +298,8 @@ const QString Account::toHumanStateName() const //: Account state static const QString notRegistered = tr("Not Registered" ); //: Account state + static const QString initializing = tr("Initializing" ); + //: Account state static const QString trying = tr("Trying..." ); //: Account state static const QString error = tr("Error" ); @@ -316,6 +326,8 @@ const QString Account::toHumanStateName() const return ready ; if(s == DRing::Account::States::REGISTERED ) return registered ; + if(s == DRing::Account::States::INITIALIZING ) + return initializing ; if(s == DRing::Account::States::UNREGISTERED ) return notRegistered ; if(s == DRing::Account::States::TRYING ) @@ -397,6 +409,7 @@ QString Account::stateColorName() const case RegistrationState::UNREGISTERED: return "black"; case RegistrationState::TRYING: + case RegistrationState::INITIALIZING: return "orange"; case RegistrationState::ERROR: return "red"; @@ -500,6 +513,14 @@ BootstrapModel* Account::bootstrapModel() const return d_ptr->m_pBootstrapModel; } +RingDeviceModel* Account::ringDeviceModel() const +{ + if (!d_ptr->m_pRingDeviceModel) + d_ptr->m_pRingDeviceModel = new RingDeviceModel(const_cast<Account*>(this)); + + return d_ptr->m_pRingDeviceModel; +} + QAbstractItemModel* Account::knownCertificateModel() const { if (!d_ptr->m_pKnownCertificates) { @@ -626,6 +647,14 @@ bool Account::isAutoAnswer() const return d_ptr->accountDetail(DRing::Account::ConfProperties::AUTOANSWER) IS_TRUE; } +//Return if the accounts needs to migrate +bool Account::needsMigration() const +{ + const MapStringString details = ConfigurationManager::instance().getVolatileAccountDetails(id()); + const QString status = details[DRing::Account::VolatileProperties::Registration::STATUS]; + return status == DRing::Account::States::ERROR_NEED_MIGRATION; +} + ///Return the account user name QString Account::username() const { @@ -984,6 +1013,16 @@ QString Account::displayName() const return d_ptr->accountDetail(DRing::Account::ConfProperties::DISPLAYNAME); } +QString Account::archivePassword() const +{ + return d_ptr->accountDetail(DRing::Account::ConfProperties::ARCHIVE_PASSWORD); +} + +QString Account::archivePin() const +{ + return d_ptr->accountDetail(DRing::Account::ConfProperties::ARCHIVE_PIN); +} + bool Account::allowIncomingFromUnknown() const { return d_ptr->accountDetail(DRing::Account::ConfProperties::DHT::PUBLIC_IN_CALLS) IS_TRUE; @@ -1015,6 +1054,11 @@ bool Account::hasActiveCallLimit() const return activeCallLimit() > -1; } +bool Account::exportOnRing(const QString& password) const +{ + return ConfigurationManager::instance().exportOnRing(id(), password); +} + #define CAST(item) static_cast<int>(item) QVariant Account::roleData(int role) const @@ -1768,6 +1812,16 @@ void Account::setDisplayName(const QString& value) d_ptr->setAccountProperty(DRing::Account::ConfProperties::DISPLAYNAME, value); } +void Account::setArchivePassword(const QString& value) +{ + d_ptr->setAccountProperty(DRing::Account::ConfProperties::ARCHIVE_PASSWORD, value); +} + +void Account::setArchivePin(const QString& value) +{ + d_ptr->setAccountProperty(DRing::Account::ConfProperties::ARCHIVE_PIN, value); +} + void Account::setAllowIncomingFromUnknown(bool value) { d_ptr->setAccountProperty(DRing::Account::ConfProperties::DHT::PUBLIC_IN_CALLS, (value)TO_BOOL); @@ -2246,6 +2300,9 @@ void AccountPrivate::save() details[iter.key()] = iter.value(); } + //Clear the password + q_ptr->setArchivePassword(""); + const QString currentId = configurationManager.addAccount(details); q_ptr->codecModel() << CodecModel::EditAction::RELOAD; diff --git a/src/account.h b/src/account.h index df54ca8440bc06d0ba340dd3bb9c81e2429b0fd3..3f46759f7458140a4dc789160da447078ec4e8f7 100644 --- a/src/account.h +++ b/src/account.h @@ -40,6 +40,7 @@ class AccountStatusModel ; class ProtocolModel ; class CodecModel ; class BootstrapModel ; +class RingDeviceModel ; class NetworkInterfaceModel ; class KeyExchangeModelPrivate ; class PendingTrustRequestModel; @@ -85,6 +86,7 @@ class LIB_EXPORT Account : public ItemBase { friend class TlsMethodModelPrivate; friend class TlsMethodModel; friend class BootstrapModelPrivate; + friend class RingDeviceModelPrivate; friend class KeyExchangeModel; friend class KeyExchangeModelPrivate; friend class ContactMethod; @@ -94,6 +96,7 @@ class LIB_EXPORT Account : public ItemBase { //Properties Q_PROPERTY(QByteArray id READ id ) + Q_PROPERTY(QString deviceId READ deviceId ) Q_PROPERTY(QString alias READ alias WRITE setAlias ) Q_PROPERTY(Account::Protocol protocol READ protocol WRITE setProtocol ) Q_PROPERTY(QString hostname READ hostname WRITE setHostname ) @@ -145,6 +148,8 @@ class LIB_EXPORT Account : public ItemBase { Q_PROPERTY(QString userAgent READ userAgent WRITE setUserAgent ) Q_PROPERTY(bool useDefaultPort READ useDefaultPort WRITE setUseDefaultPort ) Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName ) + Q_PROPERTY(QString archivePassword READ archivePassword WRITE setArchivePassword ) + Q_PROPERTY(QString archivePin READ archivePin WRITE setArchivePin ) Q_PROPERTY(RegistrationState registrationState READ registrationState ) Q_PROPERTY(bool usedForOutgogingCall READ isUsedForOutgogingCall ) Q_PROPERTY(uint totalCallCount READ totalCallCount ) @@ -165,6 +170,7 @@ class LIB_EXPORT Account : public ItemBase { Q_PROPERTY(TlsMethodModel* tlsMethodModel READ tlsMethodModel ) Q_PROPERTY(ProtocolModel* protocolModel READ protocolModel ) Q_PROPERTY(BootstrapModel* bootstrapModel READ bootstrapModel ) + Q_PROPERTY(RingDeviceModel* ringDeviceModel READ ringDeviceModel ) Q_PROPERTY(NetworkInterfaceModel* networkInterfaceModel READ networkInterfaceModel ) Q_PROPERTY(QAbstractItemModel* knownCertificateModel READ knownCertificateModel ) Q_PROPERTY(QAbstractItemModel* bannedCertificatesModel READ bannedCertificatesModel ) @@ -206,8 +212,9 @@ class LIB_EXPORT Account : public ItemBase { enum class RegistrationState { READY = 0, /*!< The account can be used to pass a call */ UNREGISTERED = 1, /*!< The account isn't functional voluntarily */ - TRYING = 2, /*!< The account is trying to become ready */ - ERROR = 3, /*!< The account failed to become ready */ + INITIALIZING = 2, /*!< The account being created */ + TRYING = 3, /*!< The account is trying to become ready */ + ERROR = 4, /*!< The account failed to become ready */ COUNT__ }; Q_ENUMS(RegistrationState) @@ -288,6 +295,7 @@ class LIB_EXPORT Account : public ItemBase { TlsMethodModel , ProtocolModel , BootstrapModel , + RingDeviceModel , NetworkInterfaceModel , KnownCertificateModel , BannedCertificatesModel , @@ -325,6 +333,14 @@ class LIB_EXPORT Account : public ItemBase { }; Q_ENUMS(Protocol) + ///Possible account export status + enum class ExportOnRingStatus { + SUCCESS = 0, + WRONG_PASSWORD = 1 , + NETWORK_ERROR = 2 + }; + Q_ENUMS(ExportOnRingStatus) + /** *Perform an action * @return If the state changed @@ -352,6 +368,7 @@ class LIB_EXPORT Account : public ItemBase { TlsMethodModel* tlsMethodModel () const; ProtocolModel* protocolModel () const; BootstrapModel* bootstrapModel () const; + RingDeviceModel* ringDeviceModel () const; NetworkInterfaceModel* networkInterfaceModel () const; QAbstractItemModel* knownCertificateModel () const; QAbstractItemModel* bannedCertificatesModel () const; @@ -363,6 +380,7 @@ class LIB_EXPORT Account : public ItemBase { //Getters QString hostname () const; + QString deviceId () const; bool isEnabled () const; bool isAutoAnswer () const; QString username () const; @@ -418,6 +436,8 @@ class LIB_EXPORT Account : public ItemBase { QString turnServerRealm () const; bool hasProxy () const; QString displayName () const; + QString archivePassword () const; + QString archivePin () const; RegistrationState registrationState () const; Protocol protocol () const; ContactMethod* contactMethod () const; @@ -427,6 +447,9 @@ class LIB_EXPORT Account : public ItemBase { bool allowIncomingFromContact () const; int activeCallLimit () const; bool hasActiveCallLimit () const; + bool needsMigration () const; + + bool exportOnRing (const QString& password) const; bool isUsedForOutgogingCall () const; uint totalCallCount () const; @@ -465,6 +488,8 @@ class LIB_EXPORT Account : public ItemBase { void setTurnServerPassword (const QString& value ); void setTurnServerRealm (const QString& value ); void setDisplayName (const QString& value ); + void setArchivePassword (const QString& value ); + void setArchivePin (const QString& value ); void setVoiceMailCount (int count ); void setRegistrationExpire (int detail); void setTlsNegotiationTimeoutSec (int detail); @@ -532,6 +557,8 @@ class LIB_EXPORT Account : public ItemBase { void enabled(bool); ///The account edit state changed void editStateChanged(const EditState state, const EditState previous); + ///Export on Ring has ended + void exportOnRingEnded(Account::ExportOnRingStatus status, const QString& pin); }; // Q_DISABLE_COPY(Account) Q_DECLARE_METATYPE(Account*) diff --git a/src/accountmodel.cpp b/src/accountmodel.cpp index eb98ab41cc45462d7742783a10cae9c1a627a8c0..a1a3e010aab9ff433ea15e2ee63b1f6adfc125ad 100644 --- a/src/accountmodel.cpp +++ b/src/accountmodel.cpp @@ -39,8 +39,10 @@ #include "protocolmodel.h" #include "trustrequest.h" #include "pendingtrustrequestmodel.h" +#include "ringdevicemodel.h" #include "private/account_p.h" #include "private/accountmodel_p.h" +#include "private/ringdevicemodel_p.h" #include "accountstatusmodel.h" #include "dbus/configurationmanager.h" #include "dbus/callmanager.h" @@ -84,6 +86,10 @@ void AccountModelPrivate::init() SLOT(slotMediaParametersChanged(QString))); connect(&configurationManager, &ConfigurationManagerInterface::incomingTrustRequest, this, &AccountModelPrivate::slotIncomingTrustRequest); + connect(&configurationManager, &ConfigurationManagerInterface::knownDevicesChanged, this, + &AccountModelPrivate::slotKownDevicesChanged); + connect(&configurationManager, &ConfigurationManagerInterface::exportOnRingEnded, this, + &AccountModelPrivate::slotExportOnRingEnded); } ///Destructor @@ -254,6 +260,9 @@ Account::RegistrationState AccountModelPrivate::fromDaemonName(const QString& st else if( st == DRing::Account::States::TRYING ) return Account::RegistrationState::TRYING; + else if (st == DRing::Account::States::INITIALIZING ) + return Account::RegistrationState::INITIALIZING; + else if( st == DRing::Account::States::ERROR || st == DRing::Account::States::ERROR_GENERIC || st == DRing::Account::States::ERROR_AUTH @@ -263,6 +272,7 @@ Account::RegistrationState AccountModelPrivate::fromDaemonName(const QString& st || st == DRing::Account::States::ERROR_EXIST_STUN || st == DRing::Account::States::ERROR_SERVICE_UNAVAILABLE || st == DRing::Account::States::ERROR_NOT_ACCEPTABLE + || st == DRing::Account::States::ERROR_NEED_MIGRATION || st == DRing::Account::States::REQUEST_TIMEOUT ) return Account::RegistrationState::ERROR; @@ -273,6 +283,16 @@ Account::RegistrationState AccountModelPrivate::fromDaemonName(const QString& st } +QList<Account*> AccountModel::accountsToMigrate() const +{ + QList<Account*> accounts; + foreach(Account* account, d_ptr->m_lAccounts) { + if (account->needsMigration()) + accounts << account; + } + return accounts; +} + ///Account status changed void AccountModelPrivate::slotDaemonAccountChanged(const QString& account, const QString& registration_state, unsigned code, const QString& status) { @@ -417,6 +437,36 @@ void AccountModelPrivate::slotIncomingTrustRequest(const QString& accountId, con a->pendingTrustRequestModel()->d_ptr->addRequest(r); } +///Known Ring devices have changed +void AccountModelPrivate::slotKownDevicesChanged(const QString& accountId, const MapStringString& accountDevices) +{ + qDebug() << "Known devices changed" << accountId; + + Account* a = q_ptr->getById(accountId.toLatin1()); + + if (!a) { + qWarning() << "Known devices changed for unknown account" << accountId; + return; + } + + a->ringDeviceModel()->d_ptr->reload(accountDevices); +} + +///Export on Ring ended +void AccountModelPrivate::slotExportOnRingEnded(const QString& accountId, int status, const QString& pin) +{ + qDebug() << "Export on ring ended" << accountId; + + Account* a = q_ptr->getById(accountId.toLatin1()); + + if (!a) { + qWarning() << "export on Ring ended for unknown account" << accountId; + return; + } + + emit a->exportOnRingEnded(static_cast<Account::ExportOnRingStatus>(status), pin); +} + ///Update accounts void AccountModel::update() { diff --git a/src/accountmodel.h b/src/accountmodel.h index 7420849d49cb946e10cefbc81ff67f7bf2bdb19e..76e3598e80bffba9f82025064ced6aa5520a46a1 100644 --- a/src/accountmodel.h +++ b/src/accountmodel.h @@ -79,6 +79,7 @@ public: bool isRingSupported ( ) const; EditState editState ( ) const; Account* selectedAccount ( ) const; + QList<Account*> accountsToMigrate ( ) const; QItemSelectionModel* selectionModel ( ) const; diff --git a/src/private/account_p.h b/src/private/account_p.h index 95a3a169e91557b49258f9868817330d0924a73a..05649f665e753507669621c6e9635eceb94186af 100644 --- a/src/private/account_p.h +++ b/src/private/account_p.h @@ -131,6 +131,7 @@ public: TlsMethodModel* m_pTlsMethodModel ; ProtocolModel* m_pProtocolModel ; BootstrapModel* m_pBootstrapModel ; + RingDeviceModel* m_pRingDeviceModel ; QAbstractItemModel* m_pKnownCertificates ; QAbstractItemModel* m_pBannedCertificates ; QAbstractItemModel* m_pAllowedCertificates ; @@ -161,4 +162,3 @@ public Q_SLOTS: void slotPresenceMessageChanged(const QString& ); void slotUpdateCertificate ( ); }; - diff --git a/src/private/accountmodel_p.h b/src/private/accountmodel_p.h index 6f4b7905f5b93b2a4f16ec4c540ac392ab56802d..7853e6b5fde928b055cb8564bde1efa06065a8ea 100644 --- a/src/private/accountmodel_p.h +++ b/src/private/accountmodel_p.h @@ -72,4 +72,6 @@ public Q_SLOTS: void slotVolatileAccountDetailsChange(const QString& accountId, const MapStringString& details); void slotMediaParametersChanged(const QString& accountId); void slotIncomingTrustRequest(const QString& accountId, const QString& hash, const QByteArray& payload, time_t time); + void slotKownDevicesChanged(const QString& accountId, const MapStringString& devices); + void slotExportOnRingEnded(const QString& accountId, int status, const QString& pin); }; diff --git a/src/private/ringdevicemodel_p.h b/src/private/ringdevicemodel_p.h new file mode 100644 index 0000000000000000000000000000000000000000..1f20d84b80fc1fb15b61b12b077900688c2b0345 --- /dev/null +++ b/src/private/ringdevicemodel_p.h @@ -0,0 +1,40 @@ +/**************************************************************************** + * Copyright (C) 2016 by Savoir-faire Linux * + * Author : Alexandre Viau <alexandre.viau@savoirfairelinux.com> * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#pragma once + +#include "ringdevice.h" +#include "ringdevicemodel.h" + +typedef void (RingDeviceModelPrivate::*RingDeviceModelPrivateFct)(); + +class RingDeviceModelPrivate +{ +public: + RingDeviceModelPrivate(RingDeviceModel* q,Account* a); + + //Attributes + Account* m_pAccount ; + QVector<RingDevice*> m_lRingDevices ; + RingDeviceModel* q_ptr ; + + void reload(); + void reload(MapStringString accountDevices); + void clearLines(); + +}; diff --git a/src/qtwrapper/configurationmanager_wrap.h b/src/qtwrapper/configurationmanager_wrap.h index 3fd8cac8c052f323b4c880d37843f1d97567e698..4ee220d0d85b39bd0b6b9333441fe666c8896fc9 100644 --- a/src/qtwrapper/configurationmanager_wrap.h +++ b/src/qtwrapper/configurationmanager_wrap.h @@ -124,6 +124,18 @@ public: Q_EMIT this->incomingTrustRequest(QString(accountId.c_str()), QString(certId.c_str()), QByteArray(reinterpret_cast<const char*>(payload.data()), payload.size()), timestamp); }); }), + exportable_callback<ConfigurationSignal::KnownDevicesChanged>( + [this] (const std::string &accountId, const std::map<std::string, std::string>& devices) { + QTimer::singleShot(0, [this, accountId, devices] { + Q_EMIT this->knownDevicesChanged(QString(accountId.c_str()), convertMap(devices)); + }); + }), + exportable_callback<ConfigurationSignal::ExportOnRingEnded>( + [this] (const std::string &accountId, int status, const std::string &pin) { + QTimer::singleShot(0, [this, accountId, status, pin] { + Q_EMIT this->exportOnRingEnded(QString(accountId.c_str()), status, QString(pin.c_str())); + }); + }), exportable_callback<ConfigurationSignal::IncomingAccountMessage>( [this] (const std::string& account_id, const std::string& from, const std::map<std::string, std::string>& payloads) { QTimer::singleShot(0, [this, account_id,from,payloads] { @@ -155,6 +167,18 @@ public Q_SLOTS: // METHODS return temp; } + bool exportOnRing(const QString& accountID, const QString& password) + { + return DRing::exportOnRing(accountID.toStdString(), password.toStdString()); + } + + MapStringString getKnownRingDevices(const QString& accountID) + { + MapStringString temp = + convertMap(DRing::getKnownRingDevices(accountID.toStdString())); + return temp; + } + MapStringString getAccountDetails(const QString& accountID) { MapStringString temp = @@ -636,6 +660,8 @@ Q_SIGNALS: // SIGNALS void certificatePathPinned(const QString& path, const QStringList& certIds); void certificateExpired(const QString& certId); void incomingTrustRequest(const QString& accountId, const QString& from, const QByteArray& payload, qulonglong timeStamp); + void knownDevicesChanged(const QString& accountId, const MapStringString& devices); + void exportOnRingEnded(const QString& accountId, int status, const QString& pin); void incomingAccountMessage(const QString& accountId, const QString& from, const MapStringString& payloads); void mediaParametersChanged(const QString& accountId); void audioDeviceEvent(); diff --git a/src/ringdevice.cpp b/src/ringdevice.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ecde31b3ad3ce855d279974c1e88ea47cdad673a --- /dev/null +++ b/src/ringdevice.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** + * Copyright (C) 2016 by Savoir-faire Linux * + * Author : Alexandre Viau <alexandre.viau@savoirfairelinux.com> * + * * + * This library is free software you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +// Qt +#include <QtCore/QObject> + +#include "ringdevice.h" + + +class RingDevicePrivate final : public QObject +{ +public: + Q_OBJECT + Q_DECLARE_PUBLIC(RingDevice) + + RingDevice* q_ptr ; + QString m_ID ; + QString m_Name ; + + // Constructor + explicit RingDevicePrivate(RingDevice* device); +}; + +RingDevicePrivate::RingDevicePrivate(RingDevice* device) : QObject(device), q_ptr(device) +{ +} + + ///Constructors +RingDevice::RingDevice(const QString& id, const QString& name) +{ + d_ptr = new RingDevicePrivate(this); + d_ptr->m_ID = id; + d_ptr->m_Name = name; +} + +const QString RingDevice::id() const +{ + return d_ptr->m_ID; +} + +const QString RingDevice::name() const +{ + return d_ptr->m_Name; +} + +#define CAST(item) static_cast<int>(item) +QVariant RingDevice::columnData(int column) const +{ + switch(column) { + case CAST(RingDevice::Column::Id): + return id(); + case CAST(RingDevice::Column::Name): + return name(); + default: + return QVariant(); + } +} +#undef CAST + + +#include <ringdevice.moc> diff --git a/src/ringdevice.h b/src/ringdevice.h new file mode 100644 index 0000000000000000000000000000000000000000..0ac395d0df0f34d665094f81f2011b3f0611fac8 --- /dev/null +++ b/src/ringdevice.h @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (C) 2016 by Savoir-faire Linux * + * Author : Alexandre Viau <alexandre.viau@savoirfairelinux.com> * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ +#pragma once + +#include <typedefs.h> +#include <itembase.h> + +class RingDevicePrivate; + + +class LIB_EXPORT RingDevice : public ItemBase +{ + Q_OBJECT + + friend class RingDeviceModel; + friend class RingDeviceModelPrivate; + +public: + + enum class Column { + Id = 0, + Name + }; + + Q_PROPERTY(QString id READ id ) + Q_PROPERTY(QString name READ name) + + //Getters + const QString id ( ) const; + const QString name ( ) const; + Q_INVOKABLE QVariant columnData (int column) const; + + +private: + RingDevice(const QString& id, const QString& name); + RingDevicePrivate* d_ptr; + Q_DECLARE_PRIVATE(RingDevice) +}; + +Q_DECLARE_METATYPE(RingDevice*) diff --git a/src/ringdevicemodel.cpp b/src/ringdevicemodel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..31a953faed43477573f79bdbc3e82f3eb54ad1d2 --- /dev/null +++ b/src/ringdevicemodel.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** + * Copyright (C) 2016 by Savoir-faire Linux * + * Author : Alexandre Viau <alexandre.viau@savoirfairelinux.com> * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ +#include "ringdevice.h" +#include "ringdevicemodel.h" +#include "private/ringdevicemodel_p.h" + +#include "dbus/configurationmanager.h" + +//Qt +#include <QtCore/QDir> +#include <QtCore/QFile> +#include <QtCore/QDirIterator> +#include <QtCore/QJsonDocument> +#include <QtCore/QJsonArray> +#include <QtCore/QJsonObject> +#include <QtCore/QStandardPaths> + +//Ring daemon +#include <account_const.h> + +//Ring +#include <account.h> +#include <private/account_p.h> + +RingDeviceModelPrivate::RingDeviceModelPrivate(RingDeviceModel* q,Account* a) : q_ptr(q),m_pAccount(a) +{ +} + +void RingDeviceModelPrivate::clearLines() +{ + q_ptr->beginRemoveRows(QModelIndex(),0,m_lRingDevices.size()); + qDeleteAll(m_lRingDevices); + m_lRingDevices.clear(); + q_ptr->endRemoveRows(); +} + +void RingDeviceModelPrivate::reload() +{ + const MapStringString accountDevices = ConfigurationManager::instance().getKnownRingDevices(this->m_pAccount->id()); + reload(accountDevices); +} + +void RingDeviceModelPrivate::reload(MapStringString accountDevices) +{ + clearLines(); + + QMapIterator<QString, QString> i(accountDevices); + while (i.hasNext()) { + i.next(); + + RingDevice* device = new RingDevice(i.key(), i.value()); + + q_ptr->beginInsertRows(QModelIndex(),m_lRingDevices.size(), m_lRingDevices.size()); + m_lRingDevices << device; + q_ptr->endInsertRows(); + } +} + +RingDeviceModel::RingDeviceModel(Account* a) : QAbstractTableModel(a), d_ptr(new RingDeviceModelPrivate(this,a)) +{ + d_ptr->reload(); +} + +RingDeviceModel::~RingDeviceModel() +{ + d_ptr->clearLines(); + delete d_ptr; +} + +QVariant RingDeviceModel::data( const QModelIndex& index, int role) const +{ + Q_UNUSED(role); + + if (role == Qt::DisplayRole && index.isValid()) { + + RingDevice* device = nullptr; + if (index.row() < d_ptr->m_lRingDevices.size()) + device = d_ptr->m_lRingDevices[index.row()]; + + if (!device) + return QVariant(); + + return device->columnData(index.column()); + } else + return QVariant(); +} + +QVariant RingDeviceModel::headerData( int section, Qt::Orientation ori, int role) const +{ + if (role == Qt::DisplayRole) { + if (ori == Qt::Vertical) + return section; + + switch (section) { + case static_cast<int>(RingDevice::Column::Id): + return tr("Id"); + case static_cast<int>(RingDevice::Column::Name): + return tr("Name"); + default: + return QVariant(); + } + } + return QVariant(); +} + + +int RingDeviceModel::rowCount( const QModelIndex& parent) const +{ + return parent.isValid()?0:d_ptr->m_lRingDevices.size(); +} + +int RingDeviceModel::columnCount( const QModelIndex& parent) const +{ + return parent.isValid()?0:2; +} + +int RingDeviceModel::size() const +{ + return d_ptr->m_lRingDevices.size(); +} + +Qt::ItemFlags RingDeviceModel::flags(const QModelIndex &index) const +{ + return index.isValid() ? (Qt::ItemIsEnabled | Qt::ItemIsSelectable) : Qt::NoItemFlags; +} diff --git a/src/ringdevicemodel.h b/src/ringdevicemodel.h new file mode 100644 index 0000000000000000000000000000000000000000..1864b84bc4f06f444728690a07a420a39a863b14 --- /dev/null +++ b/src/ringdevicemodel.h @@ -0,0 +1,51 @@ +/**************************************************************************** + * Copyright (C) 2016 by Savoir-faire Linux * + * Author : Alexandre Viau <alexandre.viau@savoirfairelinux.com> * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ +#pragma once + +#include <QtCore/QAbstractTableModel> + +#include <typedefs.h> + +class Account; + +class RingDeviceModelPrivate; + +class LIB_EXPORT RingDeviceModel : public QAbstractTableModel +{ + Q_OBJECT +public: + friend class Account; + friend class AccountModelPrivate; + + //Abstract model accessors + virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const override; + virtual QVariant headerData ( int section, Qt::Orientation orientation, int role ) const override; + virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const override; + virtual int columnCount ( const QModelIndex& parent = QModelIndex() ) const override; + virtual Qt::ItemFlags flags (const QModelIndex &index ) const override; + + virtual int size ( ) const; + +private: + explicit RingDeviceModel(Account* a); + virtual ~RingDeviceModel(); + + RingDeviceModelPrivate* d_ptr; + Q_DECLARE_PRIVATE(RingDeviceModel) + +}; diff --git a/src/useractionmodel.cpp b/src/useractionmodel.cpp index affb22b6cf951c6c2aa5a64df522a542bd9f7020..35489fbc819cf1cbc9172c3d046a1a6a61aab1fc 100644 --- a/src/useractionmodel.cpp +++ b/src/useractionmodel.cpp @@ -170,30 +170,30 @@ const Matrix2D< UAM::Action, Call::State, bool > UserActionModelPrivate::availab * this will impact the available actions */ const Matrix2D< UAMA, Account::RegistrationState, bool > UserActionModelPrivate::availableAccountActionMap = { - /* READY UNREGISTERED TRYING ERROR */ - { UAMA::ACCEPT , {{ true , false, false, false }}}, - { UAMA::HOLD , {{ true , false, false, false }}}, - { UAMA::MUTE_AUDIO , {{ true , true , true , true }}}, - { UAMA::MUTE_VIDEO , {{ true , true , true , true }}}, - { UAMA::SERVER_TRANSFER , {{ true , false, false, false }}}, - { UAMA::RECORD , {{ true , true , true , true }}}, - { UAMA::HANGUP , {{ true , true , true , true }}}, - - { UAMA::JOIN , {{ true , true , true , true }}}, - - { UAMA::ADD_NEW , {{ true , false, true , true }}}, - { UAMA::TOGGLE_VIDEO , {{ true , true , true , true }}}, - { UAMA::ADD_CONTACT , {{ true , true , true , true }}}, - { UAMA::ADD_TO_CONTACT , {{ true , true , true , true }}}, - { UAMA::DELETE_CONTACT , {{ true , true , true , true }}}, - { UAMA::EMAIL_CONTACT , {{ true , true , true , true }}}, - { UAMA::COPY_CONTACT , {{ true , true , true , true }}}, - { UAMA::BOOKMARK , {{ true , true , true , true }}}, - { UAMA::VIEW_CHAT_HISTORY , {{ true , true , true , true }}}, - { UAMA::ADD_CONTACT_METHOD, {{ true , true , true , true }}}, - { UAMA::CALL_CONTACT , {{ true , true , true , true }}}, - { UAMA::EDIT_CONTACT , {{ true , true , true , true }}}, - { UAMA::REMOVE_HISTORY , {{ true , true , true , true }}}, + /* READY UNREGISTERED INITIALIZING TRYING ERROR */ + { UAMA::ACCEPT , {{ true , false, false, false, false }}}, + { UAMA::HOLD , {{ true , false, false, false, false }}}, + { UAMA::MUTE_AUDIO , {{ true , true , false, true , true }}}, + { UAMA::MUTE_VIDEO , {{ true , true , false, true , true }}}, + { UAMA::SERVER_TRANSFER , {{ true , false, false, false, false }}}, + { UAMA::RECORD , {{ true , true , false, true, true }}}, + { UAMA::HANGUP , {{ true , true , false, true, true }}}, + + { UAMA::JOIN , {{ true , true , false, true , true }}}, + + { UAMA::ADD_NEW , {{ true , false, false, true , true }}}, + { UAMA::TOGGLE_VIDEO , {{ true , true , false, true , true }}}, + { UAMA::ADD_CONTACT , {{ true , true , false, true , true }}}, + { UAMA::ADD_TO_CONTACT , {{ true , true , false, true , true }}}, + { UAMA::DELETE_CONTACT , {{ true , true , false, true , true }}}, + { UAMA::EMAIL_CONTACT , {{ true , true , false, true , true }}}, + { UAMA::COPY_CONTACT , {{ true , true , false, true , true }}}, + { UAMA::BOOKMARK , {{ true , true , false, true , true }}}, + { UAMA::VIEW_CHAT_HISTORY , {{ true , true , false, true , true }}}, + { UAMA::ADD_CONTACT_METHOD, {{ true , true , false, true , true }}}, + { UAMA::CALL_CONTACT , {{ true , true , false, true , true }}}, + { UAMA::EDIT_CONTACT , {{ true , true , false, true , true }}}, + { UAMA::REMOVE_HISTORY , {{ true , true , false, true , true }}}, }; /**