From 5bdfd654ee4e670e8cdca3939f7da8f8ea715211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Fri, 29 Jun 2018 12:01:27 -0400 Subject: [PATCH] lrc: continue to remove old models Change-Id: I76b411c9e613b1ccdcb6c189b82badd8fe1cc38d --- CMakeLists.txt | 60 -- src/account.cpp | 183 +--- src/account.h | 31 - src/accountmodel.cpp | 52 +- src/accountmodel.h | 7 - src/actionextenderdefault.cpp | 70 -- src/actionextenderdefault.h | 48 -- src/availableaccountmodel.h | 67 -- src/bannedcontactmodel.cpp | 182 ---- src/bannedcontactmodel.h | 56 -- src/call.cpp | 134 +-- src/call.h | 4 - src/categorizedbookmarkmodel.cpp | 493 ----------- src/categorizedbookmarkmodel.h | 91 -- src/categorizedcontactmodel.cpp | 673 --------------- src/categorizedcontactmodel.h | 100 --- src/categorizedhistorymodel.cpp | 634 -------------- src/categorizedhistorymodel.h | 127 --- src/certificatemodel.cpp | 19 - src/certificatemodel.h | 2 - src/ciphermodel.cpp | 142 --- src/ciphermodel.h | 74 -- src/contactmethod.cpp | 45 +- src/contactmethod.h | 10 - src/contactmodel.cpp | 2 - src/contactrequest.cpp | 152 ---- src/contactrequest.h | 70 -- src/conversationmodel.cpp | 13 +- src/daemoncertificatecollection.cpp | 236 ----- src/daemoncertificatecollection.h | 67 -- .../presencecollectionextension.cpp | 42 - src/extensions/presencecollectionextension.h | 39 - .../securityevaluationextension.cpp | 1 - src/fallbackpersoncollection.cpp | 276 ------ src/fallbackpersoncollection.h | 59 -- src/foldercertificatecollection.h | 78 -- src/globalinstances.cpp | 46 - src/globalinstances.h | 11 - src/historytimecategorymodel.h | 85 -- src/interfaces/actionextenderi.h | 63 -- src/interfaces/pixmapmanipulatori.h | 4 - src/interfaces/presenceserializeri.h | 35 - src/itemdataroles.h | 1 - src/localprofilecollection.h | 47 - src/localringtonecollection.h | 48 -- src/media/avrecording.cpp | 2 +- src/media/media.h | 2 - src/media/recordingmodel.cpp | 28 - src/media/recordingmodel.h | 5 - src/media/text.cpp | 82 +- src/media/text.h | 4 - src/networkinterfacemodel.cpp | 154 ---- src/networkinterfacemodel.h | 62 -- src/newaccountmodel.cpp | 19 +- src/peerprofilecollection.h | 46 - src/person.cpp | 19 +- src/phonedirectorymodel.cpp | 21 +- src/phonedirectorymodel.h | 1 - src/pixmapmanipulatordefault.cpp | 12 - src/pixmapmanipulatordefault.h | 2 - src/presenceserializerdefault.cpp | 34 - src/presenceserializerdefault.h | 37 - src/presencestatusmodel.cpp | 394 --------- src/presencestatusmodel.h | 138 --- src/private/account_p.h | 12 - src/private/accountmodel_p.h | 3 - src/private/call_p.h | 3 - src/private/certificatemodel_p.h | 1 - src/private/contactmethod_p.h | 2 - src/private/imconversationmanagerprivate.h | 1 - src/private/sortproxies.cpp | 114 +-- src/private/videorenderermanager.cpp | 39 +- src/profile.cpp | 100 --- src/profile.h | 55 -- src/profilemodel.cpp | 806 ------------------ src/profilemodel.h | 90 -- src/protocolmodel.cpp | 150 ---- src/protocolmodel.h | 66 -- src/ringtone.cpp | 65 -- src/ringtone.h | 43 - src/ringtonemodel.cpp | 300 ------- src/ringtonemodel.h | 75 -- src/smartinfohub.cpp | 1 - src/tlsmethodmodel.cpp | 205 ----- src/tlsmethodmodel.h | 72 -- src/typedefs.h | 1 + 86 files changed, 34 insertions(+), 7911 deletions(-) delete mode 100644 src/actionextenderdefault.cpp delete mode 100644 src/actionextenderdefault.h delete mode 100644 src/availableaccountmodel.h delete mode 100644 src/bannedcontactmodel.cpp delete mode 100644 src/bannedcontactmodel.h delete mode 100644 src/categorizedbookmarkmodel.cpp delete mode 100644 src/categorizedbookmarkmodel.h delete mode 100644 src/categorizedcontactmodel.cpp delete mode 100644 src/categorizedcontactmodel.h delete mode 100644 src/categorizedhistorymodel.cpp delete mode 100644 src/categorizedhistorymodel.h delete mode 100644 src/ciphermodel.cpp delete mode 100644 src/ciphermodel.h delete mode 100644 src/contactrequest.cpp delete mode 100644 src/contactrequest.h delete mode 100644 src/daemoncertificatecollection.cpp delete mode 100644 src/daemoncertificatecollection.h delete mode 100644 src/extensions/presencecollectionextension.cpp delete mode 100644 src/extensions/presencecollectionextension.h delete mode 100644 src/fallbackpersoncollection.cpp delete mode 100644 src/fallbackpersoncollection.h delete mode 100644 src/foldercertificatecollection.h delete mode 100644 src/historytimecategorymodel.h delete mode 100644 src/interfaces/actionextenderi.h delete mode 100644 src/interfaces/presenceserializeri.h delete mode 100644 src/localprofilecollection.h delete mode 100644 src/localringtonecollection.h delete mode 100644 src/networkinterfacemodel.cpp delete mode 100644 src/networkinterfacemodel.h delete mode 100644 src/peerprofilecollection.h delete mode 100644 src/presenceserializerdefault.cpp delete mode 100644 src/presenceserializerdefault.h delete mode 100644 src/presencestatusmodel.cpp delete mode 100644 src/presencestatusmodel.h delete mode 100644 src/profile.cpp delete mode 100644 src/profile.h delete mode 100644 src/profilemodel.cpp delete mode 100644 src/profilemodel.h delete mode 100644 src/protocolmodel.cpp delete mode 100644 src/protocolmodel.h delete mode 100644 src/ringtone.cpp delete mode 100644 src/ringtone.h delete mode 100644 src/ringtonemodel.cpp delete mode 100644 src/ringtonemodel.h delete mode 100644 src/tlsmethodmodel.cpp delete mode 100644 src/tlsmethodmodel.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 40437fd5..f41fe345 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -282,9 +282,6 @@ SET( libringclient_LIB_SRCS src/video/renderer.cpp src/certificate.cpp src/securityflaw.cpp - src/ringtone.cpp - src/profile.cpp - src/contactrequest.cpp src/media/media.cpp src/media/audio.cpp src/media/video.cpp @@ -292,33 +289,19 @@ SET( libringclient_LIB_SRCS src/media/file.cpp src/media/recording.cpp src/media/avrecording.cpp - src/media/textrecording.cpp #Models src/accountmodel.cpp - src/availableaccountmodel.cpp - src/callmodel.cpp - src/categorizedhistorymodel.cpp - src/categorizedbookmarkmodel.cpp - src/categorizedcontactmodel.cpp - src/presencestatusmodel.cpp src/phonedirectorymodel.cpp - src/historytimecategorymodel.cpp src/numbercategorymodel.cpp src/macromodel.cpp src/keyexchangemodel.cpp - src/tlsmethodmodel.cpp - src/protocolmodel.cpp - src/profilemodel.cpp - src/ringtonemodel.cpp src/securityevaluationmodel.cpp src/personmodel.cpp src/collectionmodel.cpp src/collectionextensionmodel.cpp src/collectionmanagerinterface.cpp - src/networkinterfacemodel.cpp src/certificatemodel.cpp - src/ciphermodel.cpp src/chainoftrustmodel.cpp src/video/devicemodel.cpp src/video/sourcemodel.cpp @@ -332,7 +315,6 @@ SET( libringclient_LIB_SRCS src/audio/ringtonedevicemodel.cpp src/audio/settings.cpp src/media/recordingmodel.cpp - src/bannedcontactmodel.cpp src/contactmodel.cpp src/newcallmodel.cpp src/newdevicemodel.cpp @@ -354,14 +336,6 @@ SET( libringclient_LIB_SRCS #Data collections src/collectioninterface.cpp src/collectioneditor.cpp - src/fallbackpersoncollection.cpp - src/daemoncertificatecollection.cpp - src/foldercertificatecollection.cpp - src/localrecordingcollection.cpp - src/localtextrecordingcollection.cpp - src/localprofilecollection.cpp - src/localringtonecollection.cpp - src/peerprofilecollection.cpp #Communication src/dbus/configurationmanager.cpp @@ -372,10 +346,8 @@ SET( libringclient_LIB_SRCS #Default interface implementations src/globalinstances.cpp - src/presenceserializerdefault.cpp src/pixmapmanipulatordefault.cpp src/shortcutcreatordefault.cpp - src/actionextenderdefault.cpp src/dbuserrorhandlerdefault.cpp #Other @@ -393,7 +365,6 @@ SET( libringclient_LIB_SRCS src/usage_statistics.cpp #Extension - src/extensions/presencecollectionextension.cpp src/extensions/securityevaluationextension.cpp ) @@ -401,32 +372,16 @@ SET( libringclient_LIB_SRCS SET( libringclient_LIB_HDRS src/account.h src/accountmodel.h - src/availableaccountmodel.h src/call.h src/call.hpp - src/callmodel.h - src/categorizedhistorymodel.h src/person.h src/collectioninterface.h src/collectioninterface.hpp - src/categorizedbookmarkmodel.h - src/categorizedcontactmodel.h - src/presencestatusmodel.h src/contactmethod.h src/phonedirectorymodel.h - src/historytimecategorymodel.h src/numbercategorymodel.h src/keyexchangemodel.h - src/tlsmethodmodel.h - src/protocolmodel.h - src/profilemodel.h src/numbercategory.h - src/ringtonemodel.h - src/localrecordingcollection.h - src/localringtonecollection.h - src/localprofilecollection.h - src/localtextrecordingcollection.h - src/peerprofilecollection.h src/securityevaluationmodel.h src/certificate.h src/personmodel.h @@ -438,38 +393,28 @@ SET( libringclient_LIB_HDRS src/namedirectory.h src/uri.h src/macro.h - src/ringtone.h - src/profile.h src/itembase.h src/itembase.hpp src/mime.h src/collectionextensioninterface.h src/collectionmanagerinterface.h src/collectionmanagerinterface.hpp - src/networkinterfacemodel.h src/certificatemodel.h - src/ciphermodel.h src/collectionmediator.h src/collectionmediator.hpp src/collectioneditor.h src/collectioneditor.hpp - src/fallbackpersoncollection.h - src/daemoncertificatecollection.h - src/foldercertificatecollection.h src/securityflaw.h src/collectioncreationinterface.h src/collectionconfigurationinterface.h src/chainoftrustmodel.h - src/contactrequest.h src/globalinstances.h - src/presenceserializerdefault.h src/pixmapmanipulatordefault.h src/shortcutcreatordefault.h src/dbuserrorhandlerdefault.h src/itemdataroles.h src/smartinfohub.h src/usage_statistics.h - src/bannedcontactmodel.h src/vcard.h src/shmrenderer.h src/directrenderer.h @@ -521,7 +466,6 @@ SET(libringclient_audio_LIB_HDRS ) SET(libringclient_extensions_LIB_HDRS - src/extensions/presencecollectionextension.h src/extensions/securityevaluationextension.h ) @@ -533,17 +477,14 @@ SET(libringclient_media_LIB_HDRS src/media/file.h src/media/recording.h src/media/avrecording.h - src/media/textrecording.h src/media/recordingmodel.h ) SET(libringclient_interface_LIB_HDRS src/interfaces/contactmethodselectori.h - src/interfaces/presenceserializeri.h src/interfaces/itemmodelstateserializeri.h src/interfaces/pixmapmanipulatori.h src/interfaces/shortcutcreatori.h - src/interfaces/actionextenderi.h src/interfaces/dbuserrorhandleri.h ) @@ -648,7 +589,6 @@ SET(libringclient_PRIVATE_HDRS src/private/accountmodel_p.h src/private/phonedirectorymodel_p.h src/private/videorenderer_p.h - src/private/textrecording_p.h src/private/videodevice_p.h src/private/collectionmodel_p.h src/private/securityflaw_p.h diff --git a/src/account.cpp b/src/account.cpp index c5307798..d0b557f1 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -27,7 +27,6 @@ #include <QtCore/QString> #include <QtCore/QMimeData> #include <QtCore/QItemSelectionModel> - //Ring daemon #include <account_const.h> #include <presence_const.h> @@ -44,25 +43,16 @@ #include "private/certificatemodel_p.h" #include "private/account_p.h" #include "private/accountmodel_p.h" -#include "ciphermodel.h" -#include "protocolmodel.h" -#include "contactrequest.h" #include "person.h" -#include "profile.h" -#include "profilemodel.h" -#include "networkinterfacemodel.h" #include "contactmethod.h" #include "phonedirectorymodel.h" -#include "presencestatusmodel.h" #include "uri.h" #include "private/vcardutils.h" #include "mime.h" #include "namedirectory.h" #include "securityevaluationmodel.h" -#include "daemoncertificatecollection.h" #include "private/securityevaluationmodel_p.h" #include "extensions/securityevaluationextension.h" -#include "bannedcontactmodel.h" // define #define TO_BOOL ?"true":"false" @@ -95,12 +85,11 @@ static uint p_sAutoIncrementId = 0; AccountPrivate::AccountPrivate(Account* acc) : QObject(acc),q_ptr(acc), m_LastErrorCode(-1),m_VoiceMailCount(0),m_CurrentState(Account::EditState::READY), -m_pAccountNumber(nullptr),m_pKeyExchangeModel(nullptr),m_pSecurityEvaluationModel(nullptr),m_pTlsMethodModel(nullptr), -m_pCaCert(nullptr),m_pTlsCert(nullptr),m_isLoaded(true),m_pCipherModel(nullptr),m_LastTransportCode(0),m_RegistrationState(Account::RegistrationState::UNREGISTERED), -m_UseDefaultPort(false),m_pProtocolModel(nullptr),m_RemoteEnabledState(false), +m_pAccountNumber(nullptr),m_pKeyExchangeModel(nullptr),m_pSecurityEvaluationModel(nullptr), +m_pCaCert(nullptr),m_pTlsCert(nullptr),m_isLoaded(true),m_LastTransportCode(0),m_RegistrationState(Account::RegistrationState::UNREGISTERED), +m_UseDefaultPort(false),m_RemoteEnabledState(false), m_pKnownCertificates(nullptr), -m_pBannedCertificates(nullptr), m_pAllowedCertificates(nullptr),m_InternalId(++p_sAutoIncrementId), -m_pNetworkInterfaceModel(nullptr),m_pAllowedCerts(nullptr),m_pBannedCerts(nullptr) +m_pBannedCertificates(nullptr), m_pAllowedCertificates(nullptr),m_InternalId(++p_sAutoIncrementId) { } @@ -144,8 +133,6 @@ Account* Account::buildExistingAccountFromId(const QByteArray& _accountId) auto contactMethod = PhoneDirectoryModel::instance().getNumber(ringID, a); auto person = VCardUtils::mapToPersonFromReceivedProfile(contactMethod, payload); - - auto contactRequest = new ContactRequest(a, person, ringID, timeReceived); } } @@ -157,7 +144,6 @@ Account* Account::buildExistingAccountFromId(const QByteArray& _accountId) for (auto contact_info : account_contacts) { auto cm = PhoneDirectoryModel::instance().getNumber(contact_info["id"], a); if (contact_info["banned"] IS_TRUE) { - a->bannedContactModel()->add(cm); } else { cm->setConfirmed(contact_info["confirmed"] IS_TRUE); a->d_ptr->m_NumbersFromDaemon << cm; @@ -432,14 +418,6 @@ KeyExchangeModel* Account::keyExchangeModel() const return d_ptr->m_pKeyExchangeModel; } -CipherModel* Account::cipherModel() const -{ - if (!d_ptr->m_pCipherModel) { - d_ptr->m_pCipherModel = new CipherModel(const_cast<Account*>(this)); - } - return d_ptr->m_pCipherModel; -} - SecurityEvaluationModel* Account::securityEvaluationModel() const { if (!d_ptr->m_pSecurityEvaluationModel) { @@ -448,22 +426,6 @@ SecurityEvaluationModel* Account::securityEvaluationModel() const return d_ptr->m_pSecurityEvaluationModel; } -TlsMethodModel* Account::tlsMethodModel() const -{ - if (!d_ptr->m_pTlsMethodModel ) { - d_ptr->m_pTlsMethodModel = new TlsMethodModel(const_cast<Account*>(this)); - } - return d_ptr->m_pTlsMethodModel; -} - -ProtocolModel* Account::protocolModel() const -{ - if (!d_ptr->m_pProtocolModel ) { - d_ptr->m_pProtocolModel = new ProtocolModel(const_cast<Account*>(this)); - } - return d_ptr->m_pProtocolModel; -} - QAbstractItemModel* Account::knownCertificateModel() const { if (!d_ptr->m_pKnownCertificates) { @@ -478,14 +440,6 @@ QAbstractItemModel* Account::bannedCertificatesModel() const if (protocol() != Account::Protocol::RING || isNew()) return nullptr; - if (!d_ptr->m_pBannedCerts) { - d_ptr->m_pBannedCerts = CertificateModel::instance().addCollection<DaemonCertificateCollection,Account*,DaemonCertificateCollection::Mode>( - const_cast<Account*>(this), - DaemonCertificateCollection::Mode::BANNED - ); - d_ptr->m_pBannedCerts->load(); - } - if (!d_ptr->m_pBannedCertificates) { d_ptr->m_pBannedCertificates = CertificateModel::instance().d_ptr->createBannedList(this); } @@ -498,14 +452,6 @@ QAbstractItemModel* Account::allowedCertificatesModel() const if (protocol() != Account::Protocol::RING || isNew()) return nullptr; - if (!d_ptr->m_pAllowedCerts) { - d_ptr->m_pAllowedCerts = CertificateModel::instance().addCollection<DaemonCertificateCollection,Account*,DaemonCertificateCollection::Mode>( - const_cast<Account*>(this), - DaemonCertificateCollection::Mode::ALLOWED - ); - d_ptr->m_pAllowedCerts->load(); - } - if (!d_ptr->m_pAllowedCertificates) { d_ptr->m_pAllowedCertificates = CertificateModel::instance().d_ptr->createAllowedList(this); } @@ -513,24 +459,6 @@ QAbstractItemModel* Account::allowedCertificatesModel() const return d_ptr->m_pAllowedCertificates; } -BannedContactModel* -Account::bannedContactModel() const -{ - if (!d_ptr->m_pBannedContactModel) - d_ptr->m_pBannedContactModel = new BannedContactModel(const_cast<Account*>(this)); - - return d_ptr->m_pBannedContactModel; -} - -NetworkInterfaceModel* Account::networkInterfaceModel() const -{ - if (!d_ptr->m_pNetworkInterfaceModel) { - d_ptr->m_pNetworkInterfaceModel = new NetworkInterfaceModel(const_cast<Account*>(this)); - } - - return d_ptr->m_pNetworkInterfaceModel; -} - bool Account::isUsedForOutgogingCall() const { return usageStats.haveCalled(); @@ -859,11 +787,6 @@ DtmfType Account::DTMFType() const return (type == "overrtp" || type.isEmpty())? DtmfType::OverRtp:DtmfType::OverSip; } -bool Account::presenceStatus() const -{ - return d_ptr->m_pAccountNumber->isPresent(); -} - QString Account::presenceMessage() const { return d_ptr->m_pAccountNumber->presenceMessage(); @@ -1135,10 +1058,6 @@ QVariant Account::roleData(int role) const } case CAST(Account::Role::TypeName): return CAST(protocol()); - case CAST(Account::Role::PresenceStatus): - return PresenceStatusModel::instance().currentStatus(); - case CAST(Account::Role::PresenceMessage): - return PresenceStatusModel::instance().currentMessage(); case CAST(Account::Role::RegistrationState): return QVariant::fromValue(registrationState()); case CAST(Account::Role::UsedForOutgogingCall): @@ -1202,16 +1121,8 @@ QVariant Account::roleData(int role) const return isSrtpEnabled(); case CAST(Account::Role::KeyExchangeModel ): return QVariant::fromValue(keyExchangeModel()); - case CAST(Account::Role::CipherModel ): - return QVariant::fromValue(cipherModel()); case CAST(Account::Role::SecurityEvaluationModel ): return QVariant::fromValue(securityEvaluationModel()); - case CAST(Account::Role::TlsMethodModel ): - return QVariant::fromValue(tlsMethodModel()); - case CAST(Account::Role::ProtocolModel ): - return QVariant::fromValue(protocolModel()); - case CAST(Account::Role::NetworkInterfaceModel ): - return QVariant::fromValue(networkInterfaceModel()); case CAST(Account::Role::KnownCertificateModel ): return QVariant::fromValue(knownCertificateModel()); case CAST(Account::Role::BannedCertificatesModel ): @@ -1295,45 +1206,6 @@ bool Account::banCertificate(Certificate* c) return CertificateModel::instance().d_ptr->banCertificate(c, this); } -///Ask the certificate owner (peer) to trust you -bool Account::sendContactRequest( const URI& uri ) -{ - if (uri.isEmpty()) - return false; - - QByteArray payload; - - // Send our VCard as payload - payload = profile()->person()->toVCard(); - - ConfigurationManager::instance().sendTrustRequest(id(), uri, payload); - - return true; -} - -bool Account::sendContactRequest(const ContactMethod* c) -{ - if (!c) - return false; - - return sendContactRequest(c->uri()); -} - -bool Account::sendContactRequest( Certificate* c ) -{ - if ((!c) || (c->remoteId().isEmpty())) - return false; - - QByteArray payload; - - // Send our VCard as payload - payload = profile()->person()->toVCard(); - - ConfigurationManager::instance().sendTrustRequest(id(),c->remoteId(), payload); - - return true; -} - bool Account::removeContact( const URI& uri ) { if (uri.isEmpty()) @@ -1956,48 +1828,6 @@ void Account::setDTMFType(DtmfType type) d_ptr->setAccountProperty(DRing::Account::ConfProperties::DTMF_TYPE,(type==OverRtp)?"overrtp":"oversip"); } -void Account::setProfile(Profile* p) -{ - if (!p) { - qWarning() << "Cannot set profile to null as all accounts must belong to a profile"; - return; - } - - if (p == d_ptr->m_pProfile) - return; // nothing to do - - if (d_ptr->m_pProfile) - d_ptr->m_pProfile->removeAccount(this); - - if (p->addAccount(this)) - p->save(); - - d_ptr->m_pProfile = p; - - emit changed(this); -} - -Profile* Account::profile() const -{ - // Make sure all accounts belong to a profile - if (!d_ptr->m_pProfile) { - Profile* p = ProfileModel::instance().selectedProfile(); - - if (!p) // for now default to the first profile - p = ProfileModel::instance().getProfile(ProfileModel::instance().index(0,0)); - - if (!p) - return nullptr; - - // Use a const cast rather than a mutable to make sure the logic is the - // same between "automatic" default profile" and the setProfile - // implementation. - const_cast<Account*>(this)->setProfile(p); - } - - return d_ptr->m_pProfile; -} - void Account::setLastSipRegistrationStatus(const QString& value ) { d_ptr->m_LastSipRegistrationStatus = value; @@ -2167,12 +1997,8 @@ void Account::setRoleData(int role, const QVariant& value) setSrtpEnabled(value.toBool()); break; case CAST(Account::Role::KeyExchangeModel ): - case CAST(Account::Role::CipherModel ): case CAST(Account::Role::StatusModel ): case CAST(Account::Role::SecurityEvaluationModel ): - case CAST(Account::Role::TlsMethodModel ): - case CAST(Account::Role::ProtocolModel ): - case CAST(Account::Role::NetworkInterfaceModel ): case CAST(Account::Role::KnownCertificateModel ): case CAST(Account::Role::BannedCertificatesModel ): case CAST(Account::Role::AllowedCertificatesModel ): @@ -2284,7 +2110,6 @@ Account::RoleState Account::roleState(Account::Role role) const case Account::Role::HasCustomUserAgent: case Account::Role::HasProxy : case Account::Role::Proxy : - case Account::Role::CipherModel : case Account::Role::DisplayName : return Account::RoleState::UNAVAILABLE; case Account::Role::Username : diff --git a/src/account.h b/src/account.h index a5f0812a..901c2a90 100644 --- a/src/account.h +++ b/src/account.h @@ -28,7 +28,6 @@ class QString; //Ring #include "itembase.h" #include "keyexchangemodel.h" -#include "tlsmethodmodel.h" #include "uri.h" #include "typedefs.h" #include "itemdataroles.h" @@ -38,13 +37,7 @@ class QString; class ContactMethod ; class SecurityEvaluationModel ; class Certificate ; -class CipherModel ; -class ProtocolModel ; -class NetworkInterfaceModel ; class KeyExchangeModelPrivate ; -class Profile; -class ContactRequest; -class BannedContactModel; //Private class AccountPrivate; @@ -116,7 +109,6 @@ class LIB_EXPORT Account : public ItemBase { Q_PROPERTY(DtmfType dTMFType READ DTMFType WRITE setDTMFType ) Q_PROPERTY(int voiceMailCount READ voiceMailCount WRITE setVoiceMailCount ) // Q_PROPERTY(QString typeName READ type WRITE setType ) - Q_PROPERTY(bool presenceStatus READ presenceStatus ) Q_PROPERTY(QString presenceMessage READ presenceMessage ) Q_PROPERTY(bool supportPresencePublish READ supportPresencePublish ) Q_PROPERTY(bool supportPresenceSubscribe READ supportPresenceSubscribe ) @@ -128,7 +120,6 @@ class LIB_EXPORT Account : public ItemBase { Q_PROPERTY(int audioPortMin READ audioPortMin WRITE setAudioPortMin ) Q_PROPERTY(bool upnpEnabled READ isUpnpEnabled WRITE setUpnpEnabled ) Q_PROPERTY(bool hasCustomUserAgent READ hasCustomUserAgent WRITE setHasCustomUserAgent ) - Q_PROPERTY(Profile* profile READ profile WRITE setProfile ) Q_PROPERTY(QString userAgent READ userAgent WRITE setUserAgent ) Q_PROPERTY(bool useDefaultPort READ useDefaultPort WRITE setUseDefaultPort ) @@ -148,11 +139,7 @@ class LIB_EXPORT Account : public ItemBase { Q_PROPERTY(bool allowIncomingFromUnknown READ allowIncomingFromUnknown WRITE setAllowIncomingFromUnknown ) Q_PROPERTY(KeyExchangeModel* keyExchangeModel READ keyExchangeModel ) - Q_PROPERTY(CipherModel* cipherModel READ cipherModel ) Q_PROPERTY(SecurityEvaluationModel* securityEvaluationModel READ securityEvaluationModel ) - Q_PROPERTY(TlsMethodModel* tlsMethodModel READ tlsMethodModel ) - Q_PROPERTY(ProtocolModel* protocolModel READ protocolModel ) - Q_PROPERTY(NetworkInterfaceModel* networkInterfaceModel READ networkInterfaceModel ) Q_PROPERTY(QAbstractItemModel* knownCertificateModel READ knownCertificateModel ) Q_PROPERTY(QAbstractItemModel* bannedCertificatesModel READ bannedCertificatesModel ) Q_PROPERTY(QAbstractItemModel* allowedCertificatesModel READ allowedCertificatesModel ) @@ -239,7 +226,6 @@ class LIB_EXPORT Account : public ItemBase { Id , Object , TypeName , - PresenceStatus , PresenceMessage , RegistrationState , UseDefaultPort , @@ -274,12 +260,8 @@ class LIB_EXPORT Account : public ItemBase { DisplayName , SrtpEnabled , KeyExchangeModel , - CipherModel , StatusModel , SecurityEvaluationModel , - TlsMethodModel , - ProtocolModel , - NetworkInterfaceModel , KnownCertificateModel , BannedCertificatesModel , AllowedCertificatesModel , @@ -354,15 +336,10 @@ class LIB_EXPORT Account : public ItemBase { bool isIp2ip () const; KeyExchangeModel* keyExchangeModel () const; - CipherModel* cipherModel () const; SecurityEvaluationModel* securityEvaluationModel () const; - TlsMethodModel* tlsMethodModel () const; - ProtocolModel* protocolModel () const; - NetworkInterfaceModel* networkInterfaceModel () const; QAbstractItemModel* knownCertificateModel () const; QAbstractItemModel* bannedCertificatesModel () const; QAbstractItemModel* allowedCertificatesModel () const; - BannedContactModel* bannedContactModel() const; Q_INVOKABLE RoleState roleState (Account::Role role) const; Q_INVOKABLE RoleStatus roleStatus(Account::Role role) const; @@ -402,7 +379,6 @@ class LIB_EXPORT Account : public ItemBase { int localPort () const; int voiceMailCount () const; DtmfType DTMFType () const; - bool presenceStatus () const; QString presenceMessage () const; bool supportPresencePublish () const; bool supportPresenceSubscribe () const; @@ -435,7 +411,6 @@ class LIB_EXPORT Account : public ItemBase { RegistrationState registrationState () const; Protocol protocol () const; ContactMethod* contactMethod () const; - Profile* profile () const; bool allowIncomingFromUnknown () const; bool allowIncomingFromHistory () const; bool allowIncomingFromContact () const; @@ -463,9 +438,6 @@ class LIB_EXPORT Account : public ItemBase { Q_INVOKABLE bool supportScheme ( URI::SchemeType type ) const; Q_INVOKABLE bool allowCertificate( Certificate* c ) ; Q_INVOKABLE bool banCertificate ( Certificate* c ) ; - Q_INVOKABLE bool sendContactRequest(Certificate* c); - Q_INVOKABLE bool sendContactRequest(const ContactMethod* c); - Q_INVOKABLE bool sendContactRequest(const URI& uri); Q_INVOKABLE bool removeContact(Certificate* c); Q_INVOKABLE bool removeContact(const ContactMethod* c); Q_INVOKABLE bool removeContact(const URI& uri); @@ -539,7 +511,6 @@ class LIB_EXPORT Account : public ItemBase { void setAllowIncomingFromContact (bool value ); void setAllowIncomingFromUnknown (bool value ); void setHasActiveCallLimit (bool value ); - void setProfile (Profile* p ); void setLastSipRegistrationStatus (const QString& value ); void setLastTransportCode (int value ); void setLastTransportMessage (const QString& value ); @@ -598,8 +569,6 @@ class LIB_EXPORT Account : public ItemBase { void registeredNameFound(NameDirectory::LookupStatus status, const QString& address, const QString& name); /// Migration ended void migrationEnded(const Account::MigrationEndedStatus); - /// contact request accepted - void contactRequestAccepted(const ContactRequest*); }; Q_DECLARE_METATYPE(Account*) Q_DECLARE_METATYPE(const Account*) diff --git a/src/accountmodel.cpp b/src/accountmodel.cpp index f1165db6..e559b2e2 100644 --- a/src/accountmodel.cpp +++ b/src/accountmodel.cpp @@ -37,9 +37,6 @@ //Ring library #include "account.h" #include "mime.h" -#include "profilemodel.h" -#include "protocolmodel.h" -#include "contactrequest.h" #include "private/accountmodel_p.h" #include "dbus/configurationmanager.h" #include "dbus/callmanager.h" @@ -48,13 +45,12 @@ #include "person.h" #include "private/vcardutils.h" #include "phonedirectorymodel.h" -#include "bannedcontactmodel.h" #include "contactmethod.h" QHash<QByteArray,AccountPlaceHolder*> AccountModelPrivate::m_hsPlaceHolder; AccountModelPrivate::AccountModelPrivate(AccountModel* parent) : QObject(parent),q_ptr(parent), -m_pIP2IP(nullptr),m_pProtocolModel(nullptr),m_pSelectionModel(nullptr),m_lMimes({RingMimes::ACCOUNT}), +m_pIP2IP(nullptr),m_pSelectionModel(nullptr),m_lMimes({RingMimes::ACCOUNT}), m_lSupportedProtocols {{ /* SIP */ false, /* RING */ false, @@ -83,8 +79,6 @@ void AccountModelPrivate::init() SLOT(slotVoiceMailNotify(QString,int)) ); connect(&configurationManager, SIGNAL(volatileAccountDetailsChanged(QString,MapStringString)),this, SLOT(slotVolatileAccountDetailsChange(QString,MapStringString)), Qt::QueuedConnection); - connect(&configurationManager, &ConfigurationManagerInterface::incomingTrustRequest, this, - &AccountModelPrivate::slotIncomingContactRequest, Qt::QueuedConnection); connect(&configurationManager, &ConfigurationManagerInterface::exportOnRingEnded, this, &AccountModelPrivate::slotExportOnRingEnded, Qt::QueuedConnection); connect(&configurationManager, &ConfigurationManagerInterface::migrationEnded, this, @@ -149,7 +143,6 @@ QHash<int,QByteArray> AccountModel::roleNames() const roles.insert(CAST(Account::Role::Id ) ,QByteArray("id" )); roles.insert(CAST(Account::Role::Object ) ,QByteArray("object" )); roles.insert(CAST(Account::Role::TypeName ) ,QByteArray("typeName" )); - roles.insert(CAST(Account::Role::PresenceStatus ) ,QByteArray("presenceStatus" )); roles.insert(CAST(Account::Role::PresenceMessage ) ,QByteArray("presenceMessage" )); roles.insert(CAST(Account::Role::UsedForOutgogingCall ) ,QByteArray("usedForOutgogingCall" )); roles.insert(CAST(Account::Role::TotalCallCount ) ,QByteArray("totalCallCount" )); @@ -177,11 +170,7 @@ QHash<int,QByteArray> AccountModel::roleNames() const roles.insert(CAST(Account::Role::DisplayName ) ,QByteArray("displayName" )); roles.insert(CAST(Account::Role::SrtpEnabled ) ,QByteArray("srtpEnabled" )); roles.insert(CAST(Account::Role::KeyExchangeModel ) ,QByteArray("keyExchangeModel" )); - roles.insert(CAST(Account::Role::CipherModel ) ,QByteArray("cipherModel" )); roles.insert(CAST(Account::Role::SecurityEvaluationModel ) ,QByteArray("securityEvaluationModel" )); - roles.insert(CAST(Account::Role::TlsMethodModel ) ,QByteArray("tlsMethodModel" )); - roles.insert(CAST(Account::Role::ProtocolModel ) ,QByteArray("protocolModel" )); - roles.insert(CAST(Account::Role::NetworkInterfaceModel ) ,QByteArray("networkInterfaceModel" )); roles.insert(CAST(Account::Role::KnownCertificateModel ) ,QByteArray("knownCertificateModel" )); roles.insert(CAST(Account::Role::BannedCertificatesModel ) ,QByteArray("bannedCertificatesModel" )); roles.insert(CAST(Account::Role::AllowedCertificatesModel ) ,QByteArray("allowedCertificatesModel" )); @@ -444,25 +433,6 @@ void AccountModelPrivate::slotVolatileAccountDetailsChange(const QString& accoun } } -///When a Ring-DHT trust request arrive -void AccountModelPrivate::slotIncomingContactRequest(const QString& accountId, const QString& ringID, const QByteArray& payload, time_t time) -{ - Q_UNUSED(payload); - - Account* a = q_ptr->getById(accountId.toLatin1()); - - if (!a) { - qWarning() << "Incoming trust request for unknown account" << accountId; - return; - } - - /* do not pass a person before the contact request was added to his model */ - ContactRequest* r = new ContactRequest(a, nullptr, ringID, time); - - auto contactMethod = PhoneDirectoryModel::instance().getNumber(ringID, a); - r->setPeer(VCardUtils::mapToPersonFromReceivedProfile(contactMethod, payload)); -} - ///Export on Ring ended void AccountModelPrivate::slotExportOnRingEnded(const QString& accountId, int status, const QString& pin) { @@ -527,8 +497,6 @@ AccountModelPrivate::slotContactRemoved(const QString &accountID, const QString auto index = daemon_contacts.indexOf(cm); if (index >= 0) daemon_contacts.remove(index); - if (banned) - account->bannedContactModel()->add(cm); } } } @@ -975,14 +943,6 @@ bool AccountModel::isRingSupported() const } -ProtocolModel* AccountModel::protocolModel() const -{ - if (!d_ptr->m_pProtocolModel) - d_ptr->m_pProtocolModel = new ProtocolModel(); - return d_ptr->m_pProtocolModel; -} - - /***************************************************************************** * * * Setters * @@ -1000,11 +960,6 @@ void AccountModelPrivate::insertAccount(Account* a, int idx) emit q_ptr->accountEditStateChanged(a, state, previous); }); - // Connect the signal when a contact was added by an account - connect(a, &Account::contactRequestAccepted, [a, this](const ContactRequest* r){ - emit q_ptr->accountContactAdded(a, r); - }); - switch(a->protocol()) { case Account::Protocol::SIP: m_lSipAccounts << a; @@ -1072,11 +1027,6 @@ Account* AccountModel::add(const QString& alias, const Account::Protocol proto) return a; } -Account* AccountModel::add(const QString& alias, const QModelIndex& idx) -{ - return add(alias, qvariant_cast<Account::Protocol>(idx.data((int)ProtocolModel::Role::Protocol))); -} - ///Remove an account void AccountModel::remove(Account* account) { diff --git a/src/accountmodel.h b/src/accountmodel.h index ebd2683c..094f7bfa 100644 --- a/src/accountmodel.h +++ b/src/accountmodel.h @@ -27,8 +27,6 @@ #include "account.h" #include "typedefs.h" -class ContactRequest; - //Private class AccountModelPrivate; @@ -44,7 +42,6 @@ public: Q_PROPERTY(bool presenceEnabled READ isPresenceEnabled ) Q_PROPERTY(bool presencePublishSupported READ isPresencePublishSupported ) Q_PROPERTY(bool presenceSubscribeSupported READ isPresenceSubscribeSupported ) - Q_PROPERTY(ProtocolModel* protocolModel READ protocolModel ) Q_PROPERTY(bool isSipSupported READ isSipSupported NOTIFY supportedProtocolsChanged) Q_PROPERTY(bool isIP2IPSupported READ isIP2IPSupported NOTIFY supportedProtocolsChanged) Q_PROPERTY(bool isRingSupported READ isRingSupported NOTIFY supportedProtocolsChanged) @@ -74,7 +71,6 @@ public: bool isPresenceEnabled ( ) const; bool isPresencePublishSupported ( ) const; bool isPresenceSubscribeSupported( ) const; - ProtocolModel* protocolModel ( ) const; bool isSipSupported ( ) const; bool isIP2IPSupported ( ) const; bool isRingSupported ( ) const; @@ -102,7 +98,6 @@ public: //Mutators Q_INVOKABLE Account* add ( const QString& alias, const Account::Protocol protocol = Account::Protocol::SIP); - Q_INVOKABLE Account* add ( const QString& alias, const QModelIndex& protocol ); Q_INVOKABLE void remove ( Account* account ); void remove ( const QModelIndex& index ); void save ( ); @@ -169,7 +164,5 @@ Q_SIGNALS: void editStateChanged(const EditState state, const EditState previous) const; /// A list of contacts has been obtained. void contactsList(Account *account); - /// A new contact has been added. - void accountContactAdded(Account* a, const ContactRequest* r); }; Q_DECLARE_METATYPE(AccountModel*) diff --git a/src/actionextenderdefault.cpp b/src/actionextenderdefault.cpp deleted file mode 100644 index 967649c9..00000000 --- a/src/actionextenderdefault.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage <emmanuel.lepage@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 "actionextenderdefault.h" - -#include "macro.h" - -namespace Interfaces { - -void ActionExtenderDefault::editPerson(Person* p) -{ - Q_UNUSED(p) -} - -void ActionExtenderDefault::viewChatHistory(ContactMethod* cm) -{ - Q_UNUSED(cm) -} - -void ActionExtenderDefault::viewChatHistory(Person* p) -{ - Q_UNUSED(p) -} - -void ActionExtenderDefault::copyInformation(QMimeData* data) -{ - Q_UNUSED(data) -} - -bool ActionExtenderDefault::warnDeletePerson(Person* p) -{ - Q_UNUSED(p) - return true; -} - -bool ActionExtenderDefault::warnDeleteCall(Call* c) -{ - Q_UNUSED(c) - return true; -} - -Person* ActionExtenderDefault::selectPerson(FlagPack<SelectPersonHint> hints, const QVariant& hintVar) const -{ - Q_UNUSED(hintVar) - Q_UNUSED(hints) - return nullptr; -} - -ContactMethod* ActionExtenderDefault::selectContactMethod(FlagPack<SelectContactMethodHint> hints, const QVariant& hintVar) const -{ - Q_UNUSED(hintVar) - Q_UNUSED(hints) - return nullptr; -} - -} // namespace Interfaces diff --git a/src/actionextenderdefault.h b/src/actionextenderdefault.h deleted file mode 100644 index 97f290b9..00000000 --- a/src/actionextenderdefault.h +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage <emmanuel.lepage@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> - -//Qt -class QMimeData; - -//Ring -#include "interfaces/actionextenderi.h" -class Person; -class ContactMethod; -class Call; - -namespace Interfaces { - -///Default implementation of the ActionExtender interfaces; does nothing -class LIB_EXPORT ActionExtenderDefault final : public ActionExtenderI -{ -public: - - virtual void editPerson(Person* p) override; - virtual void viewChatHistory(ContactMethod* cm) override; - virtual void viewChatHistory(Person* p) override; - virtual void copyInformation(QMimeData* data) override; - virtual bool warnDeletePerson(Person* p) override; - virtual bool warnDeleteCall(Call* c) override; - virtual Person* selectPerson(FlagPack<SelectPersonHint> hints, const QVariant& hintVar) const override; - virtual ContactMethod* selectContactMethod(FlagPack<SelectContactMethodHint> hints, const QVariant& hintVar) const override; -}; - -} // namespace Interfaces diff --git a/src/availableaccountmodel.h b/src/availableaccountmodel.h deleted file mode 100644 index c4e4c496..00000000 --- a/src/availableaccountmodel.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2012-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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/QSortFilterProxyModel> - -#include <accountmodel.h> - -class AvailableAccountModelPrivate; - -//TODO Qt5 use QAbstractItemProxyModel -/** - * This model filter the account list to disable all unavailable accounts. It - * also remove the enabled checkbox as it is no longer relevant. - * - * This model also handle all the logic behind the "current account" used by - * default when passing a call. It use the first "READY" account in the - * AccountModel list unless manually specified. To change the default - * permanently, use the setDefaultAccount method. - * - * @todo Once the history is not saved by the daemon, implement setDefaultAccount - */ -class LIB_EXPORT AvailableAccountModel : public QSortFilterProxyModel -{ - Q_OBJECT -public: - - virtual QVariant data (const QModelIndex& index,int role = Qt::DisplayRole ) const override; - virtual Qt::ItemFlags flags (const QModelIndex& index ) const override; - virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent ) const override; - - QItemSelectionModel* selectionModel() const; - - //Getter - static Account* currentDefaultAccount(ContactMethod* method = nullptr); - static Account* currentDefaultAccount(URI::SchemeType schemeType); - static bool validAccountForScheme(Account* account, URI::SchemeType scheme); - - //Singleton - static AvailableAccountModel& instance(); - -Q_SIGNALS: - void currentDefaultAccountChanged(Account*); - -private: - virtual ~AvailableAccountModel(); - explicit AvailableAccountModel(QObject* parent = nullptr); - - AvailableAccountModelPrivate* d_ptr; - Q_DECLARE_PRIVATE(AvailableAccountModel) -}; -Q_DECLARE_METATYPE(AvailableAccountModel*) diff --git a/src/bannedcontactmodel.cpp b/src/bannedcontactmodel.cpp deleted file mode 100644 index a2ce9ebc..00000000 --- a/src/bannedcontactmodel.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2017-2019 Savoir-faire Linux Inc. * - * Author : Nicolas Jäger <nicolas.jager@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 "bannedcontactmodel.h" - -//Qt -#include <QtCore/QDateTime> - -// LRC -#include "dbus/configurationmanager.h" -#include "contactmethod.h" -#include "phonedirectorymodel.h" - -#include <contactrequest.h> -#include <certificate.h> -#include <account.h> -#include "person.h" -#include "contactmethod.h" - -class BannedContactModelPrivate -{ -public: - //Constructor - BannedContactModelPrivate(BannedContactModel* parent); - - //Attributes - QList<ContactMethod*> m_lBanned; - Account* m_pAccount ; - -private: - BannedContactModel* q_ptr; -}; - -/** - * constructor of BannedContactModelPrivate. - */ -BannedContactModelPrivate::BannedContactModelPrivate(BannedContactModel* p) : q_ptr(p) -{ -} - -/** - * constructor of BannedContactModel. - */ -BannedContactModel::BannedContactModel(Account* a) : QAbstractTableModel(a), -d_ptr(new BannedContactModelPrivate(this)) -{ - d_ptr->m_pAccount = a; - - // Load the contacts associated from the daemon and create the cms. - const auto account_contacts - = static_cast<QVector<QMap<QString, QString>>>(ConfigurationManager::instance().getContacts(a->id().data())); - - if (a->protocol() == Account::Protocol::RING) { - for (auto contact_info : account_contacts) { - if (contact_info["banned"] == "true") { - auto cm = PhoneDirectoryModel::instance().getNumber(contact_info["id"], a); - add(cm); - } - } - } -} - -/** - * destructor of BannedContactModel. - */ -BannedContactModel::~BannedContactModel() -{ - delete d_ptr; -} - -/** - * QAbstractTableModel function used to return the data. - */ -QVariant -BannedContactModel::data( const QModelIndex& index, int role ) const -{ - if (!index.isValid()) - return QVariant(); - - switch(index.column()) { - case Columns::PEER_ID: - switch(role) { - case Qt::DisplayRole: - return d_ptr->m_lBanned[index.row()]->bestId(); - case static_cast<int>(ContactMethod::Role::Object): - return QVariant::fromValue(d_ptr->m_lBanned[index.row()]); - } - break; - case Columns::COUNT__: - switch(role) { - case Qt::DisplayRole: - return static_cast<int>(BannedContactModel::Columns::COUNT__); - } - break; - } - - return QVariant(); -} - -/** - * return the number of rows from the model. - */ -int -BannedContactModel::rowCount( const QModelIndex& parent ) const -{ - return parent.isValid()? 0 : d_ptr->m_lBanned.size(); -} - -/** - * return the number of columns from the model. - */ -int -BannedContactModel::columnCount( const QModelIndex& parent ) const -{ - return parent.isValid()? 0 : static_cast<int>(BannedContactModel::Columns::COUNT__); -} - -/** - * this function add a ContactMethod to the banned list. - * @param cm, the ContactMethod to add to the list. - */ -void -BannedContactModel::add(ContactMethod* cm) -{ - if (isBanned(cm)) - return; - - beginInsertRows(QModelIndex(),d_ptr->m_lBanned.size(),d_ptr->m_lBanned.size()); - d_ptr->m_lBanned << cm; - endInsertRows(); -} - -/** - * this function removes a ContactMethod from the banned list. - * @param cm, the ContactMethod to remove from the list. - */ -void -BannedContactModel::remove(ContactMethod* cm, bool updatedaemon) -{ - // Do not remove contact if contact isn't banned - auto rowIndex = d_ptr->m_lBanned.indexOf(cm); - if (rowIndex < 0) - return; - - beginRemoveRows(QModelIndex(), rowIndex, rowIndex); - d_ptr->m_lBanned.removeAt(rowIndex); - endRemoveRows(); - - if (!cm->account()) { - qWarning() << "BannedContactModel, cannot remove. cm->account is nullptr"; - return; - } - - if (updatedaemon) { - qWarning() << "deprecated method: updating daemon using BannedContactModel::remove is deprecated, please use ContactModel::addContact"; - ConfigurationManager::instance().addContact(cm->account()->id(), cm->uri()); - } -} - -/** - * this function returns whether passed ContactMethod is in the banned list or not. - * @param cm, the ContactMethod whose presence in the banned list should be checked. - */ -bool -BannedContactModel::isBanned(ContactMethod* cm) -{ - return d_ptr->m_lBanned.contains(cm); -} diff --git a/src/bannedcontactmodel.h b/src/bannedcontactmodel.h deleted file mode 100644 index 7707b00a..00000000 --- a/src/bannedcontactmodel.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2017-2019 Savoir-faire Linux Inc. * - * Author : Nicolas Jäger <nicolas.jager@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 BannedContactModelPrivate; -class ContactMethod; -class ContactRequest; - -class LIB_EXPORT BannedContactModel : public QAbstractTableModel -{ - Q_OBJECT - -public: - BannedContactModel(Account* a); - - enum Columns { - PEER_ID, - COUNT__ - }; - - // Model functions - virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const override; - virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const override; - virtual int columnCount ( const QModelIndex& parent = QModelIndex() ) const override; - - // Helper - void add(ContactMethod* cm); - void remove(ContactMethod* cm, bool updatedaemon = true); - bool isBanned(ContactMethod* cm); - -private: - virtual ~BannedContactModel(); - - BannedContactModelPrivate* d_ptr; - Q_DECLARE_PRIVATE(BannedContactModel) - -}; diff --git a/src/call.cpp b/src/call.cpp index 44f39386..522d3ec2 100644 --- a/src/call.cpp +++ b/src/call.cpp @@ -47,11 +47,7 @@ #include <mime.h> #include "account.h" #include "accountmodel.h" -#include "availableaccountmodel.h" #include "private/videorenderermanager.h" -#include "localrecordingcollection.h" -#include "categorizedhistorymodel.h" -#include "callmodel.h" #include "certificate.h" #include "numbercategory.h" #include "certificatemodel.h" @@ -59,7 +55,6 @@ #include "contactmethod.h" #include "video/renderer.h" #include "video/sourcemodel.h" -#include "tlsmethodmodel.h" #include "audio/settings.h" #include "personmodel.h" #include "private/contactmethod_p.h" @@ -70,16 +65,12 @@ #include "media/audio.h" #include "media/video.h" #include "media/text.h" -#include "media/textrecording.h" #include "media/file.h" #include "securityevaluationmodel.h" #include "globalinstances.h" #include "interfaces/pixmapmanipulatori.h" -#include "profilemodel.h" -#include "profile.h" - //Track where state changes are performed on finished (over, error, failed) calls //while not really problematic, it is technically wrong #define Q_ASSERT_IS_IN_PROGRESS Q_ASSERT(m_CurrentState != Call::State::OVER); @@ -90,7 +81,6 @@ changeCurrentState(Call::State::ERROR);} #include "private/call_p.h" -#include "private/textrecording_p.h" const TypedStateMachine< TypedStateMachine< Call::State , Call::Action> , Call::State> CallPrivate::actionPerformedStateMap = {{ @@ -137,7 +127,6 @@ const TypedStateMachine< TypedStateMachine< function , Call::Action > , Call::St /*CONNECTED */ {{CP::nothing , CP::cancel , CP::nothing , CP::nothing , CP::nothing , CP::nothing , CP::nothing }},/**/ }};// */ - const TypedStateMachine< TypedStateMachine< Call::State , CallPrivate::DaemonState> , Call::State> CallPrivate::stateChangedStateMap = {{ // RINGING CONNECTING CURRENT BUSY HOLD HUNGUP FAILURE OVER INACTIVE /**/ @@ -237,7 +226,6 @@ const TypedStateMachine< TypedStateMachine< bool , Call::LifeCycleState > , Call /*^^ A call _can_ be created on hold (conference) and as over (peer hang up before pickup) the progress->failure one is an implementation bug*/ - QDebug LIB_EXPORT operator<<(QDebug dbg, const CallPrivate::DaemonState& c ); QDebug LIB_EXPORT operator<<(QDebug dbg, const Call::State& c) @@ -287,7 +275,7 @@ QDebug LIB_EXPORT operator<<(QDebug dbg, const Call::Action& c) CallPrivate::CallPrivate(Call* parent) : QObject(parent),q_ptr(parent), m_pStopTimeStamp(0),m_pTimer(nullptr),m_Account(nullptr), -m_PeerName(),m_pPeerContactMethod(nullptr),m_HistoryConst(HistoryTimeCategoryModel::HistoryConst::Never), +m_PeerName(),m_pPeerContactMethod(nullptr), m_pStartTimeStamp(0), m_pDialNumber(new TemporaryContactMethod()), m_History(false),m_Missed(false),m_Direction(Call::Direction::OUTGOING),m_Type(Call::Type::CALL), @@ -315,7 +303,7 @@ m_CurrentState(Call::State::ERROR),m_pCertificate(nullptr),m_mMedias({{ ///Constructor Call::Call(Call::State startState, const QString& peerName, ContactMethod* number, Account* account) - : ItemBase(&CallModel::instance()) + : ItemBase() , d_ptr(new CallPrivate(this)) { d_ptr->m_CurrentState = startState; @@ -329,7 +317,7 @@ Call::Call(Call::State startState, const QString& peerName, ContactMethod* numbe ///Constructor Call::Call(const QString& confId, const QString& account) - : ItemBase(&CallModel::instance()) + : ItemBase() , d_ptr(new CallPrivate(this)) { d_ptr->m_CurrentState = Call::State::CONFERENCE; @@ -660,7 +648,6 @@ Call::State CallPrivate::startStateFromDaemonCallState(const QString& daemonCall return Call::State::FAILURE ; } //startStateFromDaemonCallState - /***************************************************************************** * * * Getters * @@ -871,7 +858,6 @@ Certificate* Call::certificate() const return d_ptr->m_pCertificate; } - FlagPack<Call::HoldFlags> Call::holdFlags() const { return d_ptr->m_fHoldFlags; @@ -923,7 +909,6 @@ Call::Type Call::type() const return d_ptr->m_Type; } - bool Call::hasRemote() const { return !d_ptr->m_DringId.isEmpty(); @@ -974,13 +959,6 @@ Account* Call::account() const bool Call::isSecure() const { - /*if (!d_ptr->m_Account) { - qDebug() << "Account not set, can't check security"; - return false; - } - //BUG this doesn't work - return d_ptr->m_Account && ((d_ptr->m_Account->isTlsEnabled()) || (d_ptr->m_Account->tlsMethod() != TlsMethodModel::Type::DEFAULT));*/ - return false; //No, it is not and cannot be } //isSecure @@ -1070,7 +1048,6 @@ QList<media::Media*> Call::allMedia() const return ret; } - /***************************************************************************** * * * Media type inference utils * @@ -1149,7 +1126,6 @@ media::Media* MediaTypeInference::safeMediaCreator(Call* c, media::Media::Type t return nullptr; } - /***************************************************************************** * * * Setters * @@ -1208,17 +1184,6 @@ void Call::setPeerContactMethod(ContactMethod* cm) ///Set the recording path void CallPrivate::setRecordingPath(const QString& path) { - - if (!path.isEmpty() && QFile::exists(path)) { - - media::Recording* rec = LocalRecordingCollection::instance().addFromPath(path); - (*m_mRecordings[media::Media::Type::AUDIO][media::Media::Direction::IN ]) << rec; - (*m_mRecordings[media::Media::Type::AUDIO][media::Media::Direction::OUT]) << rec; - } - - //TODO add a media type attribute to this method - /*(*m_mRecordings[media::Media::Type::VIDEO][media::Media::Direction::IN ] - (*m_mRecordings[media::Media::Type::VIDEO][media::Media::Direction::OUT]*/ } ///Set peer name @@ -1499,9 +1464,6 @@ void CallPrivate::terminateMedia() void CallPrivate::setStartTimeStamp(time_t stamp) { m_pStartTimeStamp = stamp; - //While the HistoryConst is not directly related to the call concept, - //It is called to often to ignore - m_HistoryConst = HistoryTimeCategoryModel::timeToHistoryConst(m_pStartTimeStamp); } void CallPrivate::setStartTimeStamp() @@ -1518,12 +1480,7 @@ bool Call::hasParentCall() const bool Call::joinToParent() { - if (not d_ptr->m_pParentCall) - return false; - auto success = CallModel::instance().createJoinOrMergeConferenceFromCall(this, d_ptr->m_pParentCall); - if (success) - setParentCall(nullptr); - return success; + return false; } QMimeData* Call::mimePayload() const @@ -1531,7 +1488,6 @@ QMimeData* Call::mimePayload() const return RingMimes::payload(this, nullptr, nullptr); } - /***************************************************************************** * * * Automate function * @@ -1677,68 +1633,6 @@ void CallPrivate::abort() */ void CallPrivate::sendProfile() { - auto profile = ProfileModel::instance().selectedProfile(); - if (not profile) - return; - - /* - * SIP messages need to be very small ( < 2kB ) not to hit some hardcoded - * buffer size in the PJ_SIP. As profile photo tend to hover around 10kB, - * the profile need to be sent in parts and re-assembled. To do this, the - * most simple way is to add MIME type metadata intended for the peer. Of - * course, this is an ugly hack is while vCard is a standard, using it - * like this is not. Therefore we use the proprietary PROFILE_VCF MIME. - */ - auto t = mediaFactory<media::Text>(media::Media::Direction::OUT); - - MapStringString details = ConfigurationManager::instance().getAccountDetails(m_Account->id()); - using namespace DRing::Account; - std::string uri = ""; - if (m_Account->protocol() == Account::Protocol::RING - && details[ConfProperties::USERNAME].contains("ring:")) { - uri = details[ConfProperties::USERNAME].toStdString().substr(std::string("ring:").size()); - } else { - uri = details[ConfProperties::USERNAME].toStdString(); - } - - // NOTE: Some clients still use the old LRC. So, we should be able to use the database or old VCard files for now. - // TODO: migrate sendProfile to newcallmodel.cpp as soon as possible. -#ifdef ENABLE_TEST - std::ifstream dbfile(QDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation)).filePath(lrc::NAME).toStdString()); -#else - std::ifstream dbfile(QDir(lrc::Database::getPath()).filePath(lrc::NAME).toStdString()); -#endif - std::string photo = ""; - std::string alias = ""; - if (dbfile.good()) { - lrc::Database db; - auto accountProfileId = lrc::authority::database::getOrInsertProfile(db, uri, - m_Account->id().toStdString(), true, - m_Account->protocol() == Account::Protocol::RING ? "RING" : "SIP"); - // Retrieve avatar from database - photo = lrc::authority::database::getAvatarForProfileId(db, accountProfileId); - alias = lrc::authority::database::getAliasForProfileId(db, accountProfileId); - } - auto vCard = profile->person()->toVCard({}, photo, alias); - - qsrand(time(nullptr)); - const auto& key = QString::number(qrand()); - - int i = 0; - int total = vCard.size()/1000 + (vCard.size()%1000?1:0); - while (vCard.size()) { - QMap<QString, QString> chunk; - chunk[QString("%1; id=%2,part=%3,of=%4") - .arg( RingMimes::PROFILE_VCF ) - .arg( key ) - .arg( QString::number( i+1 ) ) - .arg( QString::number( total ) ) - ] = vCard.left(1000); - vCard = vCard.remove(0, 1000); - ++i; - t->send(chunk); - } - } ///Cancel this call @@ -1805,18 +1699,6 @@ void CallPrivate::call() m_Account = tryingAcc; } - // Otherwise set default account - if (!m_Account) { - qDebug() << "Account is not set, taking the first registered."; - m_Account = AvailableAccountModel::currentDefaultAccount(peerCM); - if (!m_Account) { - qDebug() << "Trying to call " - << (m_pTransferNumber ? static_cast<QString>(m_pTransferNumber->uri()) : "ERROR") - << " with no account registered . callId : " << q_ptr << "ConfId:" << q_ptr; - throw tr("No account registered!"); - } - } - // Normal case qDebug() << "Calling " << peerCM->uri() << " with account " << m_Account << ", CallId: " << q_ptr @@ -1866,8 +1748,6 @@ void CallPrivate::call() } setObjectName("Call:"+m_DringId); - CallModel::instance().registerCall(q_ptr); - connect(peerCM, SIGNAL(presentChanged(bool)), this, SLOT(updated())); emit q_ptr->dialNumberChanged(QString()); @@ -2078,7 +1958,6 @@ void Call::appendText(const QString& str) else qDebug() << "TemporaryContactMethod not defined"; - emit changed(); } @@ -2269,7 +2148,7 @@ QVariant Call::roleData(int role) const return normStripppedC; } case static_cast<int>(Call::Role::FuzzyDate): - return QVariant::fromValue(d_ptr->m_HistoryConst); + return QVariant(); case static_cast<int>(Call::Role::IsBookmark): return false; case static_cast<int>(Call::Role::Security): @@ -2335,9 +2214,6 @@ QVariant Call::roleData(int role) const case static_cast<int>(Call::Role::SecurityLevelIcon): //TODO remove return GlobalInstances::pixmapManipulator().securityLevelIcon(account()->securityEvaluationModel()->securityLevel()); case static_cast<int>(Ring::Role::UnreadTextMessageCount): - if (peerContactMethod() && peerContactMethod()->textRecording()) - return peerContactMethod()->textRecording()->unreadInstantTextMessagingModel()->rowCount(); - else return 0; break; default: diff --git a/src/call.h b/src/call.h index e84f0bea..fd3b35d1 100644 --- a/src/call.h +++ b/src/call.h @@ -28,7 +28,6 @@ class QTimer; //Ring #include "typedefs.h" -#include "historytimecategorymodel.h" #include "media/media.h" #include "itemdataroles.h" class Account ; @@ -82,9 +81,6 @@ class LIB_EXPORT Call : public ItemBase Q_OBJECT #pragma GCC diagnostic pop public: - friend class CallModel ; - friend class CategorizedHistoryModel; - friend class CallModelPrivate ; friend class IMConversationManager; friend class VideoRendererManager; friend class VideoRendererManagerPrivate; diff --git a/src/categorizedbookmarkmodel.cpp b/src/categorizedbookmarkmodel.cpp deleted file mode 100644 index bddae33b..00000000 --- a/src/categorizedbookmarkmodel.cpp +++ /dev/null @@ -1,493 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "categorizedbookmarkmodel.h" - -//Qt -#include <QtCore/QMimeData> -#include <QtCore/QCoreApplication> -#include <QtCore/QAbstractItemModel> - -//Ring -#include "categorizedhistorymodel.h" -#include "dbus/presencemanager.h" -#include "phonedirectorymodel.h" -#include "contactmethod.h" -#include "callmodel.h" -#include "call.h" -#include "person.h" -#include "uri.h" -#include "mime.h" -#include "collectioneditor.h" -#include "collectioninterface.h" -#include "private/phonedirectorymodel_p.h" - -class NumberTreeBackend; - -class CategorizedBookmarkModelPrivate final : public QObject -{ - Q_OBJECT -public: - CategorizedBookmarkModelPrivate(CategorizedBookmarkModel* parent); - - //Attributes - QList<NumberTreeBackend*> m_lCategoryCounter ; - QHash<QString,NumberTreeBackend*> m_hCategories ; - QStringList m_lMimes ; - QHash<ContactMethod*,QMetaObject::Connection> m_Tracked ; - - //Helpers - QString category ( NumberTreeBackend* number ) const; - bool displayFrequentlyUsed( ) const; - QVector<ContactMethod*> bookmarkList ( ) const; - -public Q_SLOTS: - void slotIndexChanged( const QModelIndex& idx ); - -private: - CategorizedBookmarkModel* q_ptr; -}; - -//Model item/index -class NumberTreeBackend final -{ - friend class CategorizedBookmarkModel; -public: - enum class Type { - BOOKMARK, - CATEGORY, - }; - - //Constructor - explicit NumberTreeBackend(const QString& name); - NumberTreeBackend(ContactMethod* number); - virtual ~NumberTreeBackend(); - - //Attributes - ContactMethod* m_pNumber ; - NumberTreeBackend* m_pParent ; - int m_Index ; - Type m_Type ; - QString m_Name ; - bool m_MostPopular; - QList<NumberTreeBackend*> m_lChildren ; - QMetaObject::Connection m_Conn ; -}; - -CategorizedBookmarkModelPrivate::CategorizedBookmarkModelPrivate(CategorizedBookmarkModel* parent) : -QObject(parent), q_ptr(parent) -{} - -NumberTreeBackend::NumberTreeBackend(ContactMethod* number): -m_pNumber(number),m_pParent(nullptr),m_Index(-1), m_Type(NumberTreeBackend::Type::BOOKMARK), -m_MostPopular(false) -{ - Q_ASSERT(number != nullptr); -} - -NumberTreeBackend::NumberTreeBackend(const QString& name) - : m_Type(NumberTreeBackend::Type::CATEGORY),m_Name(name), - m_MostPopular(false),m_Index(-1), m_pNumber(nullptr),m_pParent(nullptr) -{} - -NumberTreeBackend::~NumberTreeBackend() -{ - QObject::disconnect(m_Conn); -} - -CategorizedBookmarkModel::CategorizedBookmarkModel(QObject* parent) : QAbstractItemModel(parent), CollectionManagerInterface<ContactMethod>(this), -d_ptr(new CategorizedBookmarkModelPrivate(this)) -{ - setObjectName("CategorizedBookmarkModel"); - reloadCategories(); - d_ptr->m_lMimes << RingMimes::PLAIN_TEXT << RingMimes::PHONENUMBER; - - if (d_ptr->displayFrequentlyUsed()) { - connect(PhoneDirectoryModel::instance().mostPopularNumberModel(),&QAbstractItemModel::rowsInserted,this,&CategorizedBookmarkModel::reloadCategories); - } -} - -CategorizedBookmarkModel::~CategorizedBookmarkModel() -{ - foreach(NumberTreeBackend* item, d_ptr->m_lCategoryCounter) { - foreach (NumberTreeBackend* child, item->m_lChildren) { - auto l = d_ptr->m_Tracked[child->m_pNumber]; - if (l) { - disconnect(l); - } - delete child; - } - delete item; - } - delete d_ptr; -} - -CategorizedBookmarkModel& CategorizedBookmarkModel::instance() -{ - static auto instance = new CategorizedBookmarkModel(QCoreApplication::instance()); - return *instance; -} - -QHash<int,QByteArray> CategorizedBookmarkModel::roleNames() const -{ - static QHash<int, QByteArray> roles = QAbstractItemModel::roleNames(); - static bool initRoles = false; - if (!initRoles) { - initRoles = true; - roles[static_cast<int>(Call::Role::Name)] = CallModel::instance().roleNames()[static_cast<int>(Call::Role::Name)]; - } - return roles; -} - -///Reload bookmark cateogries -void CategorizedBookmarkModel::reloadCategories() -{ - d_ptr->m_hCategories.clear(); - - beginRemoveRows(QModelIndex(), 0, d_ptr->m_lCategoryCounter.size()-1); - - //TODO this is not efficient, nor necessary - foreach(NumberTreeBackend* item, d_ptr->m_lCategoryCounter) { - foreach (NumberTreeBackend* child, item->m_lChildren) { - auto l = d_ptr->m_Tracked[child->m_pNumber]; - if (l) { - disconnect(l); - } - delete child; - } - delete item; - } - d_ptr->m_Tracked.clear(); - d_ptr->m_lCategoryCounter.clear(); - endRemoveRows(); - - //Load most used contacts - if (d_ptr->displayFrequentlyUsed()) { - //: Most popular contacts - NumberTreeBackend* item = new NumberTreeBackend(tr("Most popular")); - d_ptr->m_hCategories["mp"] = item; - item->m_Index = d_ptr->m_lCategoryCounter.size(); - item->m_MostPopular = true; - beginInsertRows(QModelIndex(), d_ptr->m_lCategoryCounter.size(),d_ptr->m_lCategoryCounter.size()); - d_ptr->m_lCategoryCounter << item; - endInsertRows(); - - //This a proxy, so the items already exist elsewhere - beginInsertRows(index(item->m_Index,0), item->m_lChildren.size(), item->m_lChildren.size()); - endInsertRows(); - - const QVector<ContactMethod*> cl = PhoneDirectoryModel::instance().getNumbersByPopularity(); - } - - foreach(ContactMethod* bookmark, d_ptr->bookmarkList()) { - NumberTreeBackend* bm = new NumberTreeBackend(bookmark); - const QString val = d_ptr->category(bm); - if (!d_ptr->m_hCategories[val]) { - NumberTreeBackend* item = new NumberTreeBackend(val); - d_ptr->m_hCategories[val] = item; - item->m_Index = d_ptr->m_lCategoryCounter.size(); - beginInsertRows(QModelIndex(), d_ptr->m_lCategoryCounter.size(),d_ptr->m_lCategoryCounter.size()); - d_ptr->m_lCategoryCounter << item; - endInsertRows(); - } - NumberTreeBackend* item = d_ptr->m_hCategories[val]; - if (item) { - bookmark->setBookmarked(true); - bm->m_pParent = item; - bm->m_Index = item->m_lChildren.size(); - bm->m_Conn = connect(bookmark, &ContactMethod::changed, [this,bm]() { - d_ptr->slotIndexChanged(index(bm->m_Index,0,index(bm->m_pParent->m_Index,0))); - }); - - beginInsertRows(index(item->m_Index,0), item->m_lChildren.size(), item->m_lChildren.size()); - item->m_lChildren << bm; - endInsertRows(); - - if (!d_ptr->m_Tracked[bookmark]) { - const QString displayName = bm->m_pNumber->roleData(Qt::DisplayRole).toString(); - - QMetaObject::Connection conn = connect(bookmark, &ContactMethod::primaryNameChanged, [this,displayName,bm]() { - //If a contact arrive later, reload - if (displayName != bm->m_pNumber->roleData(Qt::DisplayRole)) { - reloadCategories(); - } - }); - - d_ptr->m_Tracked[bookmark] = conn; - } - } - else - qDebug() << "ERROR count"; - } - - - emit layoutAboutToBeChanged(); - emit layoutChanged(); -} //reloadCategories - -//Do nothing -bool CategorizedBookmarkModel::setData( const QModelIndex& index, const QVariant &value, int role) -{ - Q_UNUSED(index) - Q_UNUSED(value) - Q_UNUSED(role ) - return false; -} - -QVariant CategorizedBookmarkModel::data( const QModelIndex& index, int role) const -{ - if ((!index.isValid())) - return QVariant(); - - if (index.parent().isValid()) { - NumberTreeBackend* parentItem = static_cast<NumberTreeBackend*>(index.parent().internalPointer()); - if (parentItem->m_MostPopular) { - return PhoneDirectoryModel::instance().mostPopularNumberModel()->data( - PhoneDirectoryModel::instance().mostPopularNumberModel()->index(index.row(),0), - role - ); - } - } - - NumberTreeBackend* modelItem = static_cast<NumberTreeBackend*>(index.internalPointer()); - - if (!modelItem) - return QVariant(); - - switch (modelItem->m_Type) { - case NumberTreeBackend::Type::CATEGORY: - switch (role) { - case Qt::DisplayRole: - return modelItem->m_Name; - case static_cast<int>(Call::Role::Name): - //Make sure it is at the top of the bookmarks when sorted - if (modelItem->m_MostPopular) { - return "000000"; - } - else { - return modelItem->m_Name; - } - } - break; - case NumberTreeBackend::Type::BOOKMARK: - return modelItem->m_pNumber->roleData(role == Qt::DisplayRole ? (int)Call::Role::Name : role); - break; - }; - - return QVariant(); -} //Data - -///Get header data -QVariant CategorizedBookmarkModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - Q_UNUSED(section) - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) - return QVariant(tr("Contacts")); - return QVariant(); -} - -///Get the number of child of "parent" -int CategorizedBookmarkModel::rowCount( const QModelIndex& parent ) const -{ - if (!parent.isValid()) - return d_ptr->m_lCategoryCounter.size(); - - NumberTreeBackend* modelItem = static_cast<NumberTreeBackend*>(parent.internalPointer()); - - //Is from MostPopularModel - if (!modelItem) - return 0; - - switch (modelItem->m_Type) { - case NumberTreeBackend::Type::CATEGORY: - if (modelItem->m_MostPopular) { - static auto& index = PhoneDirectoryModel::instance().d_ptr->m_lPopularityIndex; - return index.size(); - } - else - return modelItem->m_lChildren.size(); - case NumberTreeBackend::Type::BOOKMARK: - return 0; - } - return 0; -} - -Qt::ItemFlags CategorizedBookmarkModel::flags( const QModelIndex& index ) const -{ - if (!index.isValid()) - return 0; - return index.isValid() ? ( - Qt::ItemIsEnabled | - Qt::ItemIsSelectable | - (index.parent().isValid()?Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled:Qt::ItemIsEnabled) - ) : Qt::NoItemFlags; -} - -///There is only 1 column -int CategorizedBookmarkModel::columnCount ( const QModelIndex& parent) const -{ - Q_UNUSED(parent) - return 1; -} - -///Get the bookmark parent -QModelIndex CategorizedBookmarkModel::parent( const QModelIndex& idx) const -{ - if (!idx.isValid()) { - return QModelIndex(); - } - const NumberTreeBackend* modelItem = static_cast<NumberTreeBackend*>(idx.internalPointer()); - - if (!modelItem) - return index(d_ptr->m_hCategories["mp"]->m_Index,0); - - switch(modelItem->m_Type) { - case NumberTreeBackend::Type::BOOKMARK: - return index(modelItem->m_pParent->m_Index,0); - case NumberTreeBackend::Type::CATEGORY: - return QModelIndex(); - } - return QModelIndex(); -} //parent - -///Get the index -QModelIndex CategorizedBookmarkModel::index(int row, int column, const QModelIndex& parent) const -{ - if (column != 0) - return QModelIndex(); - - if (parent.isValid() && d_ptr->m_lCategoryCounter.size() > parent.row()) { - const NumberTreeBackend* modelItem = static_cast<NumberTreeBackend*>(parent.internalPointer()); - - if (modelItem->m_MostPopular) - return createIndex(row, column, nullptr); - - if (modelItem->m_lChildren.size() > row) - return createIndex(row,column,(void*) static_cast<NumberTreeBackend*>(modelItem->m_lChildren[row])); - } - else if (row >= 0 && row < d_ptr->m_lCategoryCounter.size()) { - return createIndex(row,column,(void*) static_cast<NumberTreeBackend*>(d_ptr->m_lCategoryCounter[row])); - } - return QModelIndex(); -} - -///Get bookmarks mime types -QStringList CategorizedBookmarkModel::mimeTypes() const -{ - return d_ptr->m_lMimes; -} - -///Generate mime data -QMimeData* CategorizedBookmarkModel::mimeData(const QModelIndexList &indexes) const -{ - QMimeData *mimeData = new QMimeData(); - foreach (const QModelIndex &index, indexes) { - if (index.isValid()) { - QString text = data(index, static_cast<int>(Call::Role::Number)).toString(); - mimeData->setData(RingMimes::PLAIN_TEXT , text.toUtf8()); - mimeData->setData(RingMimes::PHONENUMBER, text.toUtf8()); - return mimeData; - } - } - return mimeData; -} //mimeData - -///Return valid payload types -int CategorizedBookmarkModel::acceptedPayloadTypes() -{ - return CallModel::DropPayloadType::CALL; -} - -///Get category -QString CategorizedBookmarkModelPrivate::category(NumberTreeBackend* number) const -{ - if (number->m_Name.size()) - return number->m_Name; - - QString cat = number->m_pNumber->roleData(Qt::DisplayRole).toString(); - - if (cat.size()) - cat = cat[0].toUpper(); - return cat; -} - -bool CategorizedBookmarkModelPrivate::displayFrequentlyUsed() const -{ - return true; -} - -QVector<ContactMethod*> CategorizedBookmarkModelPrivate::bookmarkList() const -{ - return (q_ptr->collections().size() > 0) ? q_ptr->collections()[0]->items<ContactMethod>() : QVector<ContactMethod*>(); -} - -void CategorizedBookmarkModel::addBookmark(ContactMethod* number) -{ - Q_UNUSED(number) - if (collections().size()) - collections()[0]->editor<ContactMethod>()->addNew(number); - else - qWarning() << "No bookmark backend is set"; -} - -void CategorizedBookmarkModel::removeBookmark(ContactMethod* number) -{ - collections()[0]->editor<ContactMethod>()->remove(number); -} - -void CategorizedBookmarkModel::remove(const QModelIndex& idx) -{ - collections()[0]->editor<ContactMethod>()->remove(getNumber(idx)); -} - -ContactMethod* CategorizedBookmarkModel::getNumber(const QModelIndex& idx) -{ - if (idx.isValid()) { - if (idx.parent().isValid() && idx.parent().row() < d_ptr->m_lCategoryCounter.size()) { - NumberTreeBackend* bm = d_ptr->m_lCategoryCounter[idx.parent().row()]->m_lChildren[idx.row()]; - return bm->m_pNumber; - } - } - return nullptr; -} - -///Callback when an item change -void CategorizedBookmarkModelPrivate::slotIndexChanged(const QModelIndex& idx) -{ - emit q_ptr->dataChanged(idx,idx); -} - -bool CategorizedBookmarkModel::addItemCallback(const ContactMethod* item) -{ - Q_UNUSED(item) - reloadCategories(); //TODO this is far from optimal - return true; -} - -bool CategorizedBookmarkModel::removeItemCallback(const ContactMethod* item) -{ - Q_UNUSED(item) - return false; -} - -void CategorizedBookmarkModel::collectionAddedCallback(CollectionInterface* backend) -{ - Q_UNUSED(backend) - reloadCategories(); -} - -#include <categorizedbookmarkmodel.moc> diff --git a/src/categorizedbookmarkmodel.h b/src/categorizedbookmarkmodel.h deleted file mode 100644 index 7e682581..00000000 --- a/src/categorizedbookmarkmodel.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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/QAbstractItemModel> -#include <QtCore/QHash> -#include <QtCore/QStringList> -#include <QtCore/QDateTime> - -//Ring -#include "collectionmanagerinterface.h" -#include "collectioninterface.h" -#include "typedefs.h" -#include "contactmethod.h" -// #include "person.h" -// #include "call.h" -class PersonBackend; -class NumberTreeBackend; - -class CategorizedBookmarkModelPrivate; -class CollectionInterface2; - -class LIB_EXPORT CategorizedBookmarkModel : public QAbstractItemModel, public CollectionManagerInterface<ContactMethod> -{ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" - Q_OBJECT - #pragma GCC diagnostic pop -public: - friend class NumberTreeBackend; - //Constructor - virtual ~CategorizedBookmarkModel(); - explicit CategorizedBookmarkModel(QObject* parent); - - //Setters - void setRole(int role); - void setShowAll(bool showAll); - - //Model implementation - virtual bool setData ( const QModelIndex& index, const QVariant &value, int role ) override; - virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const override; - virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const override; - virtual Qt::ItemFlags flags ( const QModelIndex& index ) const override; - virtual int columnCount ( const QModelIndex& parent = QModelIndex() ) const override; - virtual QModelIndex parent ( const QModelIndex& index ) const override; - virtual QModelIndex index ( int row, int column, const QModelIndex& parent=QModelIndex()) const override; - virtual QStringList mimeTypes ( ) const override; - virtual QMimeData* mimeData ( const QModelIndexList &indexes ) const override; - virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override; - virtual QHash<int,QByteArray> roleNames() const override; - - //Management - void remove (const QModelIndex& idx ); - void addBookmark (ContactMethod* number ); - void removeBookmark(ContactMethod* number ); - - //Getters - int acceptedPayloadTypes(); - ContactMethod* getNumber(const QModelIndex& idx); - - //Singleton - static CategorizedBookmarkModel& instance(); - -private: - CategorizedBookmarkModelPrivate* d_ptr; - Q_DECLARE_PRIVATE(CategorizedBookmarkModel) - - //Backend interface - virtual void collectionAddedCallback(CollectionInterface* backend) override; - virtual bool addItemCallback(const ContactMethod* item) override; - virtual bool removeItemCallback(const ContactMethod* item) override; - -public Q_SLOTS: - void reloadCategories(); -}; - diff --git a/src/categorizedcontactmodel.cpp b/src/categorizedcontactmodel.cpp deleted file mode 100644 index a44d9b9e..00000000 --- a/src/categorizedcontactmodel.cpp +++ /dev/null @@ -1,673 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "categorizedcontactmodel.h" - -//Qt -#include <QtCore/QDebug> -#include <QtCore/QDate> -#include <QtCore/QMimeData> -#include <QtCore/QCoreApplication> - -//Ring -#include "callmodel.h" -#include "categorizedhistorymodel.h" -#include "contactmethod.h" -#include "phonedirectorymodel.h" -#include "historytimecategorymodel.h" -#include "person.h" -#include "uri.h" -#include "mime.h" -#include "personmodel.h" -#include "private/sortproxies.h" - -class ContactTreeNode; - -class ContactTreeNode final -{ -public: - friend class CategorizedContactModel; - friend class CategorizedContactModelPrivate; - friend class ContactTreeBinder; - - enum class NodeType { - PERSON , - CONTACTMETHOD, - CATEGORY , - }; - - //Constructor - ContactTreeNode( const Person* ct , CategorizedContactModel* parent); - ContactTreeNode( ContactMethod* cm , CategorizedContactModel* parent); - ContactTreeNode( const QString& name , CategorizedContactModel* parent); - virtual ~ContactTreeNode(); - - //Attributes - const Person* m_pContact ; - ContactMethod* m_pContactMethod; - uint m_Index ; - QString m_Name ; - NodeType m_Type ; - QVector<ContactTreeNode*> m_lChildren ; - CategorizedContactModel* m_pModel ; - - //Setter - inline void setParent (ContactTreeNode* n); - inline void setVisible( bool visible ); - - //Helpers - void slotChanged (); - void slotContactMethodsChanged (); - void slotContactMethodsAboutToChange(); - -private: - ContactTreeNode* m_pParent ; - bool m_Visible ; - uint m_VisibleCounter; - QVector<QMetaObject::Connection> m_lConections ; -}; - -class CategorizedContactModelPrivate final : public QObject -{ - Q_OBJECT -public: - CategorizedContactModelPrivate(CategorizedContactModel* parent); - - //Helpers - QString category(const Person* ct) const; - - //Attributes - QHash<Person*, time_t> m_hContactByDate ; - QVector<ContactTreeNode*> m_lCategoryCounter ; - QHash<QString,ContactTreeNode*> m_hCategories ; - int m_Role ; - QStringList m_lMimes ; - bool m_SortAlphabetical ; - QString m_DefaultCategory ; - bool m_UnreachableHidden; - SortingCategory::ModelTuple* m_pSortedProxy {nullptr}; - CategorizedContactModel::SortedProxy m_pProxies ; - - //Helper - ContactTreeNode* getContactTopLevelItem(const QString& category); - QModelIndex getIndex(int row, int column, ContactTreeNode* parent); - void reloadTreeVisibility (ContactTreeNode*); - -private: - CategorizedContactModel* q_ptr; - -public Q_SLOTS: - void reloadCategories(); - void slotContactAdded(const Person* c); - void slotContactRemoved(const Person* c); -}; - -ContactTreeNode::ContactTreeNode(const Person* ct, CategorizedContactModel* parent) : - m_pContact(ct),m_Index(-1),m_pContactMethod(nullptr),m_Type(ContactTreeNode::NodeType::PERSON),m_pParent(nullptr),m_pModel(parent),m_Visible(true), - m_VisibleCounter(0) -{ - m_Visible = m_pContact->isActive() && ((!parent->d_ptr->m_UnreachableHidden) || m_pContact->isReachable()); - m_lConections << QObject::connect(m_pContact,&Person::changed ,[this](){ slotChanged (); }); - m_lConections << QObject::connect(m_pContact,&Person::phoneNumbersChanged ,[this](){ slotContactMethodsChanged (); }); - m_lConections << QObject::connect(m_pContact,&Person::phoneNumbersAboutToChange,[this](){ slotContactMethodsAboutToChange(); }); -} - -ContactTreeNode::ContactTreeNode(ContactMethod* cm, CategorizedContactModel* parent) : - m_pContactMethod(cm),m_Index(-1),m_pContact(nullptr),m_Type(ContactTreeNode::NodeType::CONTACTMETHOD),m_pParent(nullptr),m_pModel(parent), - m_Visible(true),m_VisibleCounter(0) -{ - m_lConections << QObject::connect(m_pContactMethod,&ContactMethod::changed,[this](){ slotChanged(); }); -} - -ContactTreeNode::ContactTreeNode(const QString& name, CategorizedContactModel* parent) : - m_pContactMethod(nullptr),m_Index(-1),m_pContact(nullptr),m_Type(ContactTreeNode::NodeType::CATEGORY),m_Name(name),m_pParent(nullptr), - m_pModel(parent),m_Visible(false),m_VisibleCounter(0) -{ -} - -ContactTreeNode::~ContactTreeNode() -{ - for (auto c : m_lConections) { - QObject::disconnect(c); - } - for (ContactTreeNode* c : m_lChildren) { - delete c; - } -} - -QModelIndex CategorizedContactModelPrivate::getIndex(int row, int column, ContactTreeNode* parent) -{ - return q_ptr->createIndex(row,column,parent); -} - -void ContactTreeNode::slotChanged() -{ - const QModelIndex& self = m_pModel->d_ptr->getIndex(m_Index,0,this); - - if (!self.isValid()) return; - - ContactTreeNode *n = static_cast<ContactTreeNode*>(self.internalPointer()); - if (n->m_Type == ContactTreeNode::NodeType::PERSON) - n->m_Visible = n->m_pContact && n->m_pContact->isActive(); - emit m_pModel->dataChanged(self,self); - - const QModelIndex& tl = m_pModel->index(0,0,self); - const QModelIndex& br = m_pModel->index(0,m_pModel->rowCount(self),self); - emit m_pModel->dataChanged(tl, br); -} - -void ContactTreeNode::slotContactMethodsChanged() -{ - const QModelIndex idx = m_pModel->d_ptr->getIndex(m_Index,0,this); - - //After discussion, it was decided that contacts with only 1 phone number should - //be handled differently and the additional complexity isn't worth it - if (m_pContact->phoneNumbers().size() > 1) { - m_pModel->beginInsertRows(idx,0,m_pContact->phoneNumbers().size()-1); - for (int i = 0; i < m_pContact->phoneNumbers().size(); ++i) { - ContactTreeNode* n2 = new ContactTreeNode(m_pContact->phoneNumbers()[i],m_pModel); - n2->m_Index = m_lChildren.size(); - n2->setParent(this); - m_lChildren << n2; - } - m_pModel->endInsertRows(); - } - emit m_pModel->dataChanged(idx,idx); -} - -void ContactTreeNode::slotContactMethodsAboutToChange() -{ - const QModelIndex idx = m_pModel->d_ptr->getIndex(m_Index,0,this); - - if (m_lChildren.size() > 0) { - m_pModel->beginRemoveRows(idx,0,m_lChildren.size()-1); - while (m_lChildren.size()) { - auto node = m_lChildren.at(0); - m_lChildren.removeAt(0); - delete node; - } - m_pModel->endRemoveRows(); - } -} - -void ContactTreeNode::setParent(ContactTreeNode* p) -{ - if (p && p != m_pParent && p->m_Type == NodeType::CATEGORY) { - p->m_VisibleCounter += m_Visible ? 1 : 0; - const bool hasChanged = p->m_Visible != (p->m_VisibleCounter > 0); - p->m_Visible = p->m_VisibleCounter > 0; - if (hasChanged) { - const QModelIndex idx = m_pModel->index(p->m_Index,0); - emit m_pModel->dataChanged(idx,idx); - } - } - m_pParent = p; -} - -void ContactTreeNode::setVisible(bool v) -{ - if (v != m_Visible) { - if (m_pParent) { - m_pParent->m_VisibleCounter += v ? 1 : -1; - m_pParent->m_Visible = m_pParent->m_VisibleCounter > 0; - } - m_Visible = v; - const QModelIndex idx = m_pModel->index(m_Index,0,m_pParent ? - m_pModel->index(m_pParent->m_Index,0) : QModelIndex() - ); - emit m_pModel->dataChanged(idx,idx); - } -} - -CategorizedContactModelPrivate::CategorizedContactModelPrivate(CategorizedContactModel* parent) : QObject(parent), q_ptr(parent), -m_lCategoryCounter(),m_Role(Qt::DisplayRole),m_SortAlphabetical(true),m_UnreachableHidden(false),m_pSortedProxy(nullptr) -{ - -} - -// -CategorizedContactModel::CategorizedContactModel(int role) : QAbstractItemModel(QCoreApplication::instance()),d_ptr(new CategorizedContactModelPrivate(this)) -{ - setObjectName("CategorizedContactModel"); - d_ptr->m_Role = role; - d_ptr->m_lCategoryCounter.reserve(32); - d_ptr->m_lMimes << RingMimes::PLAIN_TEXT << RingMimes::PHONENUMBER; - - connect(&PersonModel::instance(),&PersonModel::newPersonAdded,d_ptr.data(),&CategorizedContactModelPrivate::slotContactAdded); - connect(&PersonModel::instance(),&PersonModel::personRemoved,d_ptr.data(),&CategorizedContactModelPrivate::slotContactRemoved); - - for(int i=0; i < PersonModel::instance().rowCount();i++) { - Person* p = qvariant_cast<Person*>(PersonModel::instance().index(i,0).data((int)Person::Role::Object)); - d_ptr->slotContactAdded(p); - } - -} - -CategorizedContactModel::~CategorizedContactModel() -{ - foreach(ContactTreeNode* item,d_ptr->m_lCategoryCounter) { - delete item; - } - - if (d_ptr->m_pSortedProxy) - delete d_ptr->m_pSortedProxy; -} - -CategorizedContactModel& CategorizedContactModel::instance() -{ - static auto instance = new CategorizedContactModel; - return *instance; -} - -QHash<int,QByteArray> CategorizedContactModel::roleNames() const -{ - static QHash<int, QByteArray> roles = QAbstractItemModel::roleNames(); - static bool initRoles = false; - if (!initRoles) { - initRoles = true; - roles.insert((int)Person::Role::Organization ,QByteArray("organization") ); - roles.insert((int)Person::Role::Group ,QByteArray("group") ); - roles.insert((int)Person::Role::Department ,QByteArray("department") ); - roles.insert((int)Person::Role::PreferredEmail ,QByteArray("preferredEmail") ); - roles.insert((int)Person::Role::FormattedLastUsed ,QByteArray("formattedLastUsed")); - roles.insert((int)Person::Role::IndexedLastUsed ,QByteArray("indexedLastUsed") ); - roles.insert((int)Person::Role::DatedLastUsed ,QByteArray("datedLastUsed") ); - roles.insert((int)Person::Role::Filter ,QByteArray("filter") ); - roles.insert((int)Person::Role::DropState ,QByteArray("dropState") ); - } - return roles; -} - -ContactTreeNode* CategorizedContactModelPrivate::getContactTopLevelItem(const QString& category) -{ - if (!m_hCategories[category]) { - ContactTreeNode* item = new ContactTreeNode(category,q_ptr); - m_hCategories[category] = item; - item->m_Index = m_lCategoryCounter.size(); -// emit layoutAboutToBeChanged(); - q_ptr->beginInsertRows(QModelIndex(),m_lCategoryCounter.size(),m_lCategoryCounter.size()); { - m_lCategoryCounter << item; - } q_ptr->endInsertRows(); -// emit layoutChanged(); - } - ContactTreeNode* item = m_hCategories[category]; - return item; -} - -void CategorizedContactModelPrivate::reloadCategories() -{ - emit q_ptr->layoutAboutToBeChanged(); //FIXME far from optimal - m_hCategories.clear(); - q_ptr->beginRemoveRows(QModelIndex(),0,m_lCategoryCounter.size()-1); - foreach(ContactTreeNode* item,m_lCategoryCounter) { - delete item; - } - q_ptr->endRemoveRows(); - m_lCategoryCounter.clear(); - for(int i=0; i < PersonModel::instance().rowCount();i++) { - Person* cont = qvariant_cast<Person*>(PersonModel::instance().index(i,0).data((int)Person::Role::Object)); - slotContactAdded(cont); - } - emit q_ptr->layoutChanged(); -} - -void CategorizedContactModelPrivate::slotContactRemoved(const Person* c) { - Q_UNUSED(c) - - reloadCategories(); -} - -void CategorizedContactModelPrivate::slotContactAdded(const Person* c) -{ - if (!c) return; - - const QString val = category(c); - ContactTreeNode* item = getContactTopLevelItem(val); - ContactTreeNode* contactNode = new ContactTreeNode(c,q_ptr); - contactNode->setParent(item); - contactNode->m_Index = item->m_lChildren.size(); - //emit layoutAboutToBeChanged(); - q_ptr->beginInsertRows(q_ptr->index(item->m_Index,0,QModelIndex()),item->m_lChildren.size(),item->m_lChildren.size()); { - item->m_lChildren << contactNode; - } q_ptr->endInsertRows(); - reloadTreeVisibility(item); - - if (c->phoneNumbers().size() > 1) { - q_ptr->beginInsertRows(q_ptr->createIndex(contactNode->m_Index,0,contactNode),0,c->phoneNumbers().size() - 1); - foreach (ContactMethod* m, c->phoneNumbers() ) { //TODO check if this can be merged with slotContactMethodCountChanged - ContactTreeNode* n2 = new ContactTreeNode(m,q_ptr); - n2->m_Index = contactNode->m_lChildren.size(); - n2->setParent(contactNode); - contactNode->m_lChildren << n2; - } - q_ptr->endInsertRows(); - } - - //emit layoutChanged(); -} - -bool CategorizedContactModel::setData( const QModelIndex& index, const QVariant &value, int role) -{ - Q_UNUSED(index) - Q_UNUSED(value) - Q_UNUSED(role ) - - return false; -} - -QVariant CategorizedContactModel::data( const QModelIndex& index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - ContactTreeNode* modelItem = (ContactTreeNode*)index.internalPointer(); - switch (modelItem->m_Type) { - case ContactTreeNode::NodeType::CATEGORY: - switch (role) { - case Qt::DisplayRole: - return static_cast<const ContactTreeNode*>(modelItem)->m_Name; - case (int)Person::Role::IndexedLastUsed: - return index.child(0,0).data((int)Person::Role::IndexedLastUsed); - default: - break; - } - break; - case ContactTreeNode::NodeType::PERSON: - return modelItem->m_pContact->roleData(role); - case ContactTreeNode::NodeType::CONTACTMETHOD: /* && (role == Qt::DisplayRole)) {*/ - return modelItem->m_pContactMethod->roleData(role); - } - return QVariant(); -} - -QVariant CategorizedContactModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - Q_UNUSED(section) - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) - return QVariant(tr("Contacts")); - return QVariant(); -} - -bool CategorizedContactModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) -{ - Q_UNUSED( action ) - setData(parent,-1,static_cast<int>(Call::Role::DropState)); - if (data->hasFormat(RingMimes::CALLID)) { - const QByteArray encodedCallId = data->data( RingMimes::CALLID ); - const QModelIndex targetIdx = index ( row,column,parent ); - Call* call = CallModel::instance().fromMime ( encodedCallId ); - if (call && targetIdx.isValid()) { - ContactTreeNode* modelItem = (ContactTreeNode*)targetIdx.internalPointer(); - switch (modelItem->m_Type) { - case ContactTreeNode::NodeType::PERSON: { - const Person* ct = modelItem->m_pContact; - if (ct) { - switch(ct->phoneNumbers().size()) { - case 0: //Do nothing when there is no phone numbers - return false; - case 1: //Call when there is one - CallModel::instance().transfer(call,ct->phoneNumbers()[0]); - break; - default: - //TODO - break; - }; - } - } break; - case ContactTreeNode::NodeType::CONTACTMETHOD: { - const ContactMethod* nb = modelItem->m_pContactMethod; - if (nb) { - call->setTransferNumber(nb->uri()); - CallModel::instance().transfer(call,nb); - } - } break; - case ContactTreeNode::NodeType::CATEGORY: - break; - } - } - } - return false; -} - - -int CategorizedContactModel::rowCount( const QModelIndex& parent ) const -{ - if (!parent.isValid() || !parent.internalPointer()) - return d_ptr->m_lCategoryCounter.size(); - const ContactTreeNode* parentNode = static_cast<ContactTreeNode*>(parent.internalPointer()); - - if (parentNode) - return parentNode->m_lChildren.size(); - - return 0; -} - -Qt::ItemFlags CategorizedContactModel::flags( const QModelIndex& index ) const -{ - if (!index.isValid()) - return Qt::NoItemFlags; - - const ContactTreeNode* modelNode = static_cast<ContactTreeNode*>(index.internalPointer()); - - return (modelNode->m_Visible) ? Qt::ItemIsEnabled | Qt::ItemIsSelectable | ( - modelNode->m_pParent? (Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled) : Qt::NoItemFlags - ) : Qt::NoItemFlags; -} - -int CategorizedContactModel::columnCount ( const QModelIndex& parent) const -{ - Q_UNUSED(parent) - return 1; -} - -QModelIndex CategorizedContactModel::parent( const QModelIndex& index) const -{ - if (!index.isValid() || !index.internalPointer()) - return QModelIndex(); - - const ContactTreeNode* modelItem = static_cast<ContactTreeNode*>(index.internalPointer()); - - if (modelItem && modelItem->m_pParent) - return createIndex(modelItem->m_pParent->m_Index,0,modelItem->m_pParent); - - return QModelIndex(); -} - -QModelIndex CategorizedContactModel::index( int row, int column, const QModelIndex& parent) const -{ - if (!parent.isValid() && row < d_ptr->m_lCategoryCounter.size()) { - return createIndex(row,column,d_ptr->m_lCategoryCounter[row]); - } - - ContactTreeNode* parentNode = static_cast<ContactTreeNode*>(parent.internalPointer()); - - if (parentNode && row < parentNode->m_lChildren.size()) - return createIndex(row,column,parentNode->m_lChildren[row]); - - return QModelIndex(); -} - -QStringList CategorizedContactModel::mimeTypes() const -{ - return d_ptr->m_lMimes; -} - -QMimeData* CategorizedContactModel::mimeData(const QModelIndexList &indexes) const -{ - QMimeData *mimeData = new QMimeData(); - foreach (const QModelIndex &index, indexes) { - if (index.isValid()) { - const ContactTreeNode* modelItem = static_cast<ContactTreeNode*>(index.internalPointer()); - switch(modelItem->m_Type) { - case ContactTreeNode::NodeType::PERSON: { - //Contact - const Person* ct = modelItem->m_pContact; - if (ct) { - if (ct->phoneNumbers().size() == 1) { - mimeData->setData(RingMimes::PHONENUMBER , ct->phoneNumbers()[0]->toHash().toUtf8()); - } - mimeData->setData(RingMimes::CONTACT , ct->uid()); - } - return mimeData; - } - case ContactTreeNode::NodeType::CONTACTMETHOD: { - //Phone number - const QString text = data(index, Qt::DisplayRole).toString(); - const ContactTreeNode* n = static_cast<ContactTreeNode*>(index.internalPointer()); - if (n->m_pContactMethod) { - mimeData->setData(RingMimes::PLAIN_TEXT , text.toUtf8()); - mimeData->setData(RingMimes::PHONENUMBER, n->m_pContactMethod->toHash().toUtf8()); - return mimeData; - } - - } break; - case ContactTreeNode::NodeType::CATEGORY: - return nullptr; - }; - } - } - return mimeData; -} - -///Return valid payload types -int CategorizedContactModel::acceptedPayloadTypes() -{ - return CallModel::DropPayloadType::CALL; -} - - - -/***************************************************************************** - * * - * Helpers * - * * - ****************************************************************************/ - - -QString CategorizedContactModelPrivate::category(const Person* ct) const { - if (!ct) - return QString(); - - QString cat = ct->roleData(m_Role).toString(); - - if (cat.size() && m_SortAlphabetical) - cat = cat[0].toUpper(); - else if (!cat.size()) - cat = m_DefaultCategory; - - return cat; -} - -void CategorizedContactModel::setRole(int role) -{ - if (role != d_ptr->m_Role) { - d_ptr->m_Role = role; - d_ptr->reloadCategories(); - } -} - -void CategorizedContactModel::setSortAlphabetical(bool alpha) -{ - d_ptr->m_SortAlphabetical = alpha; -} - -bool CategorizedContactModel::isSortAlphabetical() const -{ - return d_ptr->m_SortAlphabetical; -} - -void CategorizedContactModel::setDefaultCategory(const QString& cat) -{ - d_ptr->m_DefaultCategory = cat; -} - -QString CategorizedContactModel::defaultCategory() const -{ - return d_ptr->m_DefaultCategory; -} - -bool CategorizedContactModel::areUnreachableHidden() const -{ - return d_ptr->m_UnreachableHidden; -} - -/** - * Show/hide contacts that are currently unreachable - * - * @warning This method will reloaded person reachability status, - * this require large amount of CPU when many contacts are present - */ -void CategorizedContactModel::setUnreachableHidden(bool val) -{ - if (d_ptr->m_UnreachableHidden != val) { - d_ptr->m_UnreachableHidden = val; - d_ptr->reloadTreeVisibility(nullptr); - } -} - -void CategorizedContactModelPrivate::reloadTreeVisibility( ContactTreeNode* node ) -{ - if (!node) { - for(ContactTreeNode* n : m_hCategories) - reloadTreeVisibility(n); - return; - } - - switch(node->m_Type) { - case ContactTreeNode::NodeType::PERSON : - node->setVisible(node->m_pContact->isActive() && ((!m_UnreachableHidden) || node->m_pContact->isReachable())); - break; - case ContactTreeNode::NodeType::CONTACTMETHOD: - //Nothing to do - break; - case ContactTreeNode::NodeType::CATEGORY : - for (ContactTreeNode* n : node->m_lChildren) - reloadTreeVisibility(n); - break; - }; -} - -QSortFilterProxyModel* CategorizedContactModel::SortedProxy::model() const -{ - if (!CategorizedContactModel::instance().d_ptr->m_pSortedProxy) - CategorizedContactModel::instance().d_ptr->m_pSortedProxy = SortingCategory::getContactProxy(); - - return CategorizedContactModel::instance().d_ptr->m_pSortedProxy->model; -} - -QAbstractItemModel* CategorizedContactModel::SortedProxy::categoryModel() const -{ - if (!CategorizedContactModel::instance().d_ptr->m_pSortedProxy) - CategorizedContactModel::instance().d_ptr->m_pSortedProxy = SortingCategory::getContactProxy(); - - return CategorizedContactModel::instance().d_ptr->m_pSortedProxy->categories; -} - -QItemSelectionModel* CategorizedContactModel::SortedProxy::categorySelectionModel() const -{ - if (!CategorizedContactModel::instance().d_ptr->m_pSortedProxy) - CategorizedContactModel::instance().d_ptr->m_pSortedProxy = SortingCategory::getContactProxy(); - - return CategorizedContactModel::instance().d_ptr->m_pSortedProxy->selectionModel; -} - -CategorizedContactModel::SortedProxy& CategorizedContactModel::SortedProxy::instance() -{ - return CategorizedContactModel::instance().d_ptr->m_pProxies; -} - -#include <categorizedcontactmodel.moc> diff --git a/src/categorizedcontactmodel.h b/src/categorizedcontactmodel.h deleted file mode 100644 index b03ff611..00000000 --- a/src/categorizedcontactmodel.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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/QHash> -#include <QtCore/QStringList> -#include <QtCore/QAbstractItemModel> - -//Ring -#include "typedefs.h" -#include "person.h" -class PersonModel; -class ContactTreeNode; -class TopLevelItem; -class ContactTreeBinder; -class CategorizedContactModelPrivate; -class QSortFilterProxyModel; -class QItemSelectionModel; - -class LIB_EXPORT CategorizedContactModel : public QAbstractItemModel -{ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" - Q_OBJECT - #pragma GCC diagnostic pop -public: - friend class PersonModel ; - friend class ContactTreeNode ; - friend class ContactTreeBinder; - friend class SortedProxy ; - - virtual ~CategorizedContactModel(); - - //Setters - void setRole ( int role ); - void setSortAlphabetical ( bool alpha = true ); - void setDefaultCategory ( const QString& cat ); - void setUnreachableHidden( bool value ); - - //Model implementation - virtual bool setData ( const QModelIndex& index, const QVariant &value, int role ) override; - virtual bool dropMimeData( const QMimeData*, Qt::DropAction, int, int, const QModelIndex& ) override; - virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const override; - virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const override; - virtual Qt::ItemFlags flags ( const QModelIndex& index ) const override; - virtual int columnCount ( const QModelIndex& parent = QModelIndex() ) const override; - virtual QModelIndex parent ( const QModelIndex& index ) const override; - virtual QModelIndex index ( int row, int column, const QModelIndex& parent=QModelIndex() ) const override; - virtual QStringList mimeTypes ( ) const override; - virtual QMimeData* mimeData ( const QModelIndexList &indexes ) const override; - virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override; - virtual QHash<int,QByteArray> roleNames() const override; - - //Getter - static int acceptedPayloadTypes() ; - bool isSortAlphabetical () const; - QString defaultCategory () const; - bool areUnreachableHidden() const; - - struct SortedProxy { - enum class Categories { - NAME , - ORGANIZATION, - RECENTLYUSED, - GROUP , - DEPARTMENT , - COUNT__ - }; - - QSortFilterProxyModel* model () const; - QAbstractItemModel * categoryModel () const; - QItemSelectionModel * categorySelectionModel() const; - static CategorizedContactModel::SortedProxy& instance(); - }; - - //Singleton - static CategorizedContactModel& instance(); - -private: - explicit CategorizedContactModel(int role = Qt::DisplayRole); - - QScopedPointer<CategorizedContactModelPrivate> d_ptr; - Q_DECLARE_PRIVATE(CategorizedContactModel) -}; - diff --git a/src/categorizedhistorymodel.cpp b/src/categorizedhistorymodel.cpp deleted file mode 100644 index 2d4ba8ea..00000000 --- a/src/categorizedhistorymodel.cpp +++ /dev/null @@ -1,634 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2012-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "categorizedhistorymodel.h" - -//C include -#include <time.h> - -//Qt include -#include <QMimeData> -#include <QCoreApplication> - -//Ring lib -#include "private/sortproxies.h" -#include "mime.h" -#include "dbus/callmanager.h" -#include "dbus/configurationmanager.h" -#include "call.h" -#include "person.h" -#include "contactmethod.h" -#include "callmodel.h" -#include "collectioneditor.h" -#include "historytimecategorymodel.h" -#include "collectioninterface.h" - -/***************************************************************************** - * * - * Private classes * - * * - ****************************************************************************/ - -struct HistoryNode; - -class CategorizedHistoryModelPrivate final : public QObject -{ - Q_OBJECT -public: - CategorizedHistoryModelPrivate(CategorizedHistoryModel* parent); - - //Helpers - HistoryNode* getCategory(const Call* call); - - //Attributes - static CallMap m_sHistoryCalls; - - //Model categories - QVector<HistoryNode*> m_lCategoryCounter ; - QHash<int,HistoryNode*> m_hCategories ; - QHash<QString,HistoryNode*> m_hCategoryByName ; - SortingCategory::ModelTuple* m_pSortedProxy {nullptr}; - int m_Role ; - QStringList m_lMimes ; - CategorizedHistoryModel::SortedProxy m_pProxies; - -private: - CategorizedHistoryModel* q_ptr; - -public Q_SLOTS: - void add(Call* call); - void reloadCategories(); - void slotChanged(const QModelIndex& idx); -}; - -struct HistoryNode final -{ - enum class Type { - CAT , - CALL, - }; - - ~HistoryNode() { - foreach (HistoryNode* n, m_lChildren) - delete n; - } - - //Attributes - HistoryNode* m_pParent { nullptr }; - int m_Index { -1 }; - Call* m_pCall { nullptr }; - Type m_Type { Type::CAT }; - QString m_Name ; - int m_AbsIdx { 0 }; - QVector<HistoryNode*> m_lChildren ; -}; - -CallMap CategorizedHistoryModelPrivate::m_sHistoryCalls; - -/***************************************************************************** - * * - * Constructor * - * * - ****************************************************************************/ - -CategorizedHistoryModelPrivate::CategorizedHistoryModelPrivate(CategorizedHistoryModel* parent) : QObject(parent), q_ptr(parent), -m_Role(static_cast<int>(Call::Role::FuzzyDate)),m_pSortedProxy(nullptr) -{ -} - -///Constructor -CategorizedHistoryModel::CategorizedHistoryModel():QAbstractItemModel(QCoreApplication::instance()),CollectionManagerInterface<Call>(this), -d_ptr(new CategorizedHistoryModelPrivate(this)) -{ - d_ptr->m_lMimes << RingMimes::PLAIN_TEXT << RingMimes::PHONENUMBER << RingMimes::HISTORYID; -} //initHistory - -///Destructor -CategorizedHistoryModel::~CategorizedHistoryModel() -{ - - while(d_ptr->m_lCategoryCounter.size()) { - HistoryNode* item = d_ptr->m_lCategoryCounter[0]; - d_ptr->m_lCategoryCounter.remove(0); - - delete item; - } - - if (d_ptr->m_pSortedProxy) - delete d_ptr->m_pSortedProxy; -} - -QHash<int,QByteArray> CategorizedHistoryModel::roleNames() const -{ - static QHash<int, QByteArray> roles = QAbstractItemModel::roleNames(); - static bool initRoles = false; - if (!initRoles) { - initRoles = true; - roles.insert(static_cast<int>(Call::Role::Name ) ,QByteArray("name" )); - roles.insert(static_cast<int>(Call::Role::Number ) ,QByteArray("number" )); - roles.insert(static_cast<int>(Call::Role::Direction ) ,QByteArray("direction" )); - roles.insert(static_cast<int>(Call::Role::Date ) ,QByteArray("date" )); - roles.insert(static_cast<int>(Call::Role::Length ) ,QByteArray("length" )); - roles.insert(static_cast<int>(Call::Role::FormattedDate ) ,QByteArray("formattedDate" )); - roles.insert(static_cast<int>(Call::Role::HasAVRecording ) ,QByteArray("hasAVRecording")); - roles.insert(static_cast<int>(Call::Role::Historystate ) ,QByteArray("historyState" )); - roles.insert(static_cast<int>(Call::Role::Filter ) ,QByteArray("filter" )); - roles.insert(static_cast<int>(Call::Role::FuzzyDate ) ,QByteArray("fuzzyDate" )); - roles.insert(static_cast<int>(Call::Role::IsBookmark ) ,QByteArray("isBookmark" )); - roles.insert(static_cast<int>(Call::Role::Security ) ,QByteArray("security" )); - roles.insert(static_cast<int>(Call::Role::Department ) ,QByteArray("department" )); - roles.insert(static_cast<int>(Call::Role::Email ) ,QByteArray("email" )); - roles.insert(static_cast<int>(Call::Role::Organisation ) ,QByteArray("organisation" )); - roles.insert(static_cast<int>(Call::Role::Object ) ,QByteArray("object" )); - roles.insert(static_cast<int>(Call::Role::Photo ) ,QByteArray("photo" )); - roles.insert(static_cast<int>(Call::Role::State ) ,QByteArray("state" )); - roles.insert(static_cast<int>(Call::Role::StartTime ) ,QByteArray("startTime" )); - roles.insert(static_cast<int>(Call::Role::StopTime ) ,QByteArray("stopTime" )); - roles.insert(static_cast<int>(Call::Role::DropState ) ,QByteArray("dropState" )); - roles.insert(static_cast<int>(Call::Role::DTMFAnimState ) ,QByteArray("dTMFAnimState" )); - roles.insert(static_cast<int>(Call::Role::LastDTMFidx ) ,QByteArray("lastDTMFidx" )); - roles.insert(static_cast<int>(Call::Role::IsAVRecording ) ,QByteArray("isAVRecording" )); - roles.insert(static_cast<int>(Call::Role::DateOnly ) ,QByteArray("dateOnly" )); - roles.insert(static_cast<int>(Call::Role::DateTime ) ,QByteArray("dateTime" )); - } - return roles; -} - -///Singleton -CategorizedHistoryModel& CategorizedHistoryModel::instance() -{ - static auto instance = new CategorizedHistoryModel; - return *instance; -} - - -/***************************************************************************** - * * - * History related code * - * * - ****************************************************************************/ -///Get the top level item based on a call -HistoryNode* CategorizedHistoryModelPrivate::getCategory(const Call* call) -{ - HistoryNode* category = nullptr; - static QString name; - int index = -1; - const QVariant var = call->roleData(m_Role); - - if (m_Role == static_cast<int>(Call::Role::FuzzyDate)) { - index = var.toInt(); - name = HistoryTimeCategoryModel::indexToName(index); - category = m_hCategories[index]; - } - else if (var.type() == QVariant::Int || var.type() == QVariant::UInt) { - index = var.toInt(); - name = var.toString(); - category = m_hCategories[index]; - } - else { - name = var.toString(); - category = m_hCategoryByName[name]; - } - - if (!category) { - category = new HistoryNode(); - category->m_Name = name; - category->m_AbsIdx = index; - category->m_Index = m_lCategoryCounter.size(); - - CategorizedHistoryModel::instance().beginInsertRows(QModelIndex(),m_lCategoryCounter.size(),m_lCategoryCounter.size()); - - m_lCategoryCounter << category; - - if (index != -1) - m_hCategories [index] = category; - - m_hCategoryByName [name ] = category; - CategorizedHistoryModel::instance().endInsertRows(); - - } - return category; -} - - -const CallMap CategorizedHistoryModel::getHistoryCalls() const -{ - return d_ptr->m_sHistoryCalls; -} - -///Add to history -void CategorizedHistoryModelPrivate::add(Call* call) -{ - if (!call || call->lifeCycleState() != Call::LifeCycleState::FINISHED || !call->startTimeStamp()) { - return; - } - - emit q_ptr->newHistoryCall(call); - - HistoryNode* tl = getCategory(call); - - const QModelIndex& parentIdx = q_ptr->index(tl->m_Index, 0); - - q_ptr->beginInsertRows(parentIdx,tl->m_lChildren.size(),tl->m_lChildren.size()); - - HistoryNode* item = new HistoryNode(); - - item->m_Type = HistoryNode::Type::CALL; - item->m_pCall = call; - item->m_pParent = tl; - - connect(call, &Call::changed, [this, item]() { - const QModelIndex idx = q_ptr->createIndex(item->m_Index, 0, item); - emit q_ptr->dataChanged(idx, idx); - }); - - const int size = tl->m_lChildren.size(); - item->m_Index = size; - tl->m_lChildren << item; - - //Try to prevent startTimeStamp() collisions, it technically doesn't work as time_t are signed - //we don't care - m_sHistoryCalls[(call->startTimeStamp() << 10)+qrand()%1024] = call; - q_ptr->endInsertRows(); - - emit q_ptr->historyChanged(); - - //When the categories goes from 0 items to many, its conceptual state change - //therefore the clients may want to act on this, notify them - if (!size) { - const QModelIndex idx = q_ptr->index(item->m_Index,0); - emit q_ptr->dataChanged(idx,idx); - } -} - -///Set if the history has a limit -void CategorizedHistoryModel::setHistoryLimited(bool isLimited) -{ - if (!isLimited) - ConfigurationManager::instance().setHistoryLimit(0); -} - -///Set if the history is enabled -void CategorizedHistoryModel::setHistoryEnabled(bool isEnabled) -{ - if (!isEnabled) - ConfigurationManager::instance().setHistoryLimit(-1); -} - -///Set the number of days before history items are discarded -void CategorizedHistoryModel::setHistoryLimit(int numberOfDays) -{ - ConfigurationManager::instance().setHistoryLimit(numberOfDays); -} - -///Is history items are being deleted after "historyLimit()" days -bool CategorizedHistoryModel::isHistoryLimited() const -{ - return ConfigurationManager::instance().getHistoryLimit() > 0; -} - -///Number of days before items are discarded (0 = never) -int CategorizedHistoryModel::historyLimit() const -{ - return ConfigurationManager::instance().getHistoryLimit(); -} - -///Get if the history is enabled -bool CategorizedHistoryModel::isHistoryEnabled() const -{ - return ConfigurationManager::instance().getHistoryLimit() >= 0; -} - - -/***************************************************************************** - * * - * Model related * - * * - ****************************************************************************/ - -void CategorizedHistoryModelPrivate::reloadCategories() -{ - emit q_ptr->layoutAboutToBeChanged(); - m_hCategories.clear(); - m_hCategoryByName.clear(); - q_ptr->beginRemoveRows(QModelIndex(),0,m_lCategoryCounter.size()-1); - foreach(HistoryNode* item, m_lCategoryCounter) { - delete item; - } - q_ptr->endRemoveRows(); - m_lCategoryCounter.clear(); - - foreach(Call* call, m_sHistoryCalls) { - HistoryNode* category = getCategory(call); - if (category) { - HistoryNode* item = new HistoryNode(); - item->m_Type = HistoryNode::Type::CALL; - item->m_pCall = call; - item->m_Index = category->m_lChildren.size(); - - connect(call, &Call::changed, [this, item]() { - const QModelIndex idx = q_ptr->createIndex(item->m_Index, 0, item); - emit q_ptr->dataChanged(idx, idx); - }); - - item->m_pParent = category; - q_ptr->beginInsertRows(q_ptr->index(category->m_Index,0), item->m_Index, item->m_Index); { - category->m_lChildren << item; - } q_ptr->endInsertRows(); - } - else - qDebug() << "ERROR count"; - } - - emit q_ptr->layoutChanged(); - emit q_ptr->dataChanged(q_ptr->index(0,0),q_ptr->index(q_ptr->rowCount()-1,0)); -} - -void CategorizedHistoryModelPrivate::slotChanged(const QModelIndex& idx) -{ - emit q_ptr->dataChanged(idx,idx); -} - -bool CategorizedHistoryModel::setData( const QModelIndex& idx, const QVariant &value, int role) -{ - Q_UNUSED(idx) - Q_UNUSED(value) - Q_UNUSED(role) - - return false; -} - -QVariant CategorizedHistoryModel::data( const QModelIndex& idx, int role) const -{ - if (!idx.isValid()) - return QVariant(); - - HistoryNode* modelItem = static_cast<HistoryNode*>(idx.internalPointer()); - - switch (modelItem->m_Type) { - case HistoryNode::Type::CAT: - switch (role) { - case Qt::DisplayRole: - return modelItem->m_Name; - case static_cast<int>(Call::Role::FuzzyDate): - case static_cast<int>(Call::Role::Date): - case static_cast<int>(Call::Role::CallCount): - return modelItem->m_AbsIdx; - default: - break; - } - break; - case HistoryNode::Type::CALL: - switch (role) { - // Dates need to be sorted from newest to oldest - case static_cast<int>(Call::Role::FuzzyDate): - case static_cast<int>(Call::Role::Date): - return -modelItem->m_pCall->roleData(static_cast<int>(Call::Role::Date)).toInt(); - default: - return modelItem->m_pCall->roleData(role); - } - }; - return QVariant(); -} - -QVariant CategorizedHistoryModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - Q_UNUSED(section) - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) - return QVariant(tr("History")); - if (role == Qt::InitialSortOrderRole) - return QVariant(Qt::DescendingOrder); - return QVariant(); -} - -int CategorizedHistoryModel::rowCount( const QModelIndex& parentIdx ) const -{ - if ((!parentIdx.isValid()) || (!parentIdx.internalPointer())) { - return d_ptr->m_lCategoryCounter.size(); - } - else { - HistoryNode* node = static_cast<HistoryNode*>(parentIdx.internalPointer()); - switch(node->m_Type) { - case HistoryNode::Type::CAT: - return node->m_lChildren.size(); - case HistoryNode::Type::CALL: - return 0; - }; - } - return 0; -} - -Qt::ItemFlags CategorizedHistoryModel::flags( const QModelIndex& idx ) const -{ - if (!idx.isValid()) - return Qt::NoItemFlags; - - HistoryNode* node = static_cast<HistoryNode*>(idx.internalPointer()); - const bool hasParent = node->m_Type != HistoryNode::Type::CAT; - const bool isEnabled = node->m_Type == HistoryNode::Type::CALL && node->m_pCall->isActive(); - - return (isEnabled?Qt::ItemIsEnabled:Qt::NoItemFlags) | Qt::ItemIsSelectable | (hasParent?Qt::ItemIsDragEnabled|Qt::ItemIsDropEnabled:Qt::ItemIsEnabled); -} - -int CategorizedHistoryModel::columnCount ( const QModelIndex& parentIdx) const -{ - Q_UNUSED(parentIdx) - return 1; -} - -QModelIndex CategorizedHistoryModel::parent( const QModelIndex& idx) const -{ - if (!idx.isValid() || !idx.internalPointer()) { - return QModelIndex(); - } - - HistoryNode* modelItem = static_cast<HistoryNode*>(idx.internalPointer()); - - if (modelItem->m_Type == HistoryNode::Type::CALL) { - HistoryNode* tli = modelItem->m_pParent; - - return createIndex(tli->m_Index, idx.column(), tli); - } - - return QModelIndex(); -} - -QModelIndex CategorizedHistoryModel::index( int row, int column, const QModelIndex& parentIdx) const -{ - if (!parentIdx.isValid() && row >= 0 && row < d_ptr->m_lCategoryCounter.size()) - return createIndex(row,column,(void*)d_ptr->m_lCategoryCounter[row]); - - HistoryNode* node = static_cast<HistoryNode*>(parentIdx.internalPointer()); - - switch(node->m_Type) { - case HistoryNode::Type::CAT: - if (row < node->m_lChildren.size()) - return createIndex(row,column, node->m_lChildren[row]); - break; - case HistoryNode::Type::CALL: - break; - }; - - return QModelIndex(); -} - -///Called when dynamically adding calls, otherwise the proxy filter will segfault -bool CategorizedHistoryModel::insertRows( int row, int count, const QModelIndex & parent) -{ - if (parent.isValid()) { - beginInsertRows(parent,row,row+count-1); - endInsertRows(); - return true; - } - return false; -} - -QStringList CategorizedHistoryModel::mimeTypes() const -{ - return d_ptr->m_lMimes; -} - -QMimeData* CategorizedHistoryModel::mimeData(const QModelIndexList &indexes) const -{ - QMimeData *mimeData2 = new QMimeData(); - foreach (const QModelIndex &idx, indexes) { - if (idx.isValid()) { - const HistoryNode* node = static_cast<HistoryNode*>(idx.internalPointer()); - const QString text = data(idx, static_cast<int>(Call::Role::Number)).toString(); - const Call* call = node->m_pCall; - - //TODO use RingMimes::payload once the multi selection is investigated - mimeData2->setData(RingMimes::PLAIN_TEXT , text.toUtf8()); - - mimeData2->setData(RingMimes::PHONENUMBER, call->peerContactMethod()->toHash().toUtf8()); - - if (node->m_Type == HistoryNode::Type::CALL) - mimeData2->setData(RingMimes::HISTORYID , call->dringId().toUtf8()); - - return mimeData2; - } - } - return mimeData2; -} - -bool CategorizedHistoryModel::dropMimeData(const QMimeData *mime, Qt::DropAction action, int row, int column, const QModelIndex &parentIdx) -{ - Q_UNUSED(row) - Q_UNUSED(column) - Q_UNUSED(action) - setData(parentIdx,-1,static_cast<int>(Call::Role::DropState)); - QByteArray encodedContactMethod = mime->data( RingMimes::PHONENUMBER ); - QByteArray encodedPerson = mime->data( RingMimes::CONTACT ); - - if (parentIdx.isValid() && mime->hasFormat( RingMimes::CALLID)) { - QByteArray encodedCallId = mime->data( RingMimes::CALLID ); - Call* call = CallModel::instance().fromMime(encodedCallId); - - if (call) { - const QModelIndex& idx = index(row,column,parentIdx); - - if (idx.isValid()) { - const Call* target = static_cast<HistoryNode*>(idx.internalPointer())->m_pCall; - - if (target) { - CallModel::instance().transfer(call,target->peerContactMethod()); - return true; - } - } - } - } - return false; -} - -void CategorizedHistoryModel::collectionAddedCallback(CollectionInterface* backend) -{ - Q_UNUSED(backend) -} - -///Call all collections that support clearing -bool CategorizedHistoryModel::clearAllCollections() const -{ - foreach (CollectionInterface* backend, collections(CollectionInterface::SupportedFeatures::CLEAR)) { - backend->clear(); - } - return true; -} - -///Delete all history and clear model -void CategorizedHistoryModel::clear() -{ - beginResetModel(); - clearAllCollections(); - endResetModel(); -} - -bool CategorizedHistoryModel::addItemCallback(const Call* item) -{ - d_ptr->add(const_cast<Call*>(item)); - return true; -} - -bool CategorizedHistoryModel::removeItemCallback(const Call* item) -{ - emit const_cast<Call*>(item)->changed(); - return false; -} - -///Return valid payload types -int CategorizedHistoryModel::acceptedPayloadTypes() const -{ - return CallModel::DropPayloadType::CALL; -} - -void CategorizedHistoryModel::setCategoryRole(int role) -{ - if (d_ptr->m_Role != role) { - d_ptr->m_Role = role; - d_ptr->reloadCategories(); - } -} - -QSortFilterProxyModel* CategorizedHistoryModel::SortedProxy::model() const -{ - if (!CategorizedHistoryModel::instance().d_ptr->m_pSortedProxy) - CategorizedHistoryModel::instance().d_ptr->m_pSortedProxy = SortingCategory::getHistoryProxy(); - - return CategorizedHistoryModel::instance().d_ptr->m_pSortedProxy->model; -} - -QAbstractItemModel* CategorizedHistoryModel::SortedProxy::categoryModel() const -{ - if (!CategorizedHistoryModel::instance().d_ptr->m_pSortedProxy) - CategorizedHistoryModel::instance().d_ptr->m_pSortedProxy = SortingCategory::getHistoryProxy(); - - return CategorizedHistoryModel::instance().d_ptr->m_pSortedProxy->categories; -} - -QItemSelectionModel* CategorizedHistoryModel::SortedProxy::categorySelectionModel() const -{ - if (!CategorizedHistoryModel::instance().d_ptr->m_pSortedProxy) - CategorizedHistoryModel::instance().d_ptr->m_pSortedProxy = SortingCategory::getHistoryProxy(); - - return CategorizedHistoryModel::instance().d_ptr->m_pSortedProxy->selectionModel; -} - -CategorizedHistoryModel::SortedProxy& CategorizedHistoryModel::SortedProxy::instance() -{ - return CategorizedHistoryModel::instance().d_ptr->m_pProxies; -} - -#include <categorizedhistorymodel.moc> diff --git a/src/categorizedhistorymodel.h b/src/categorizedhistorymodel.h deleted file mode 100644 index cf0e6d8f..00000000 --- a/src/categorizedhistorymodel.h +++ /dev/null @@ -1,127 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2012-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 - -//Base -#include "typedefs.h" -#include <QtCore/QObject> -#include <QtCore/QAbstractItemModel> -#include <QtCore/QStringList> - -//Qt - -//Ring -#include "call.h" -#include "collectionmanagerinterface.h" - -//Typedef -typedef QMap<uint, Call*> CallMap; -typedef QList<Call*> CallList; - -class HistoryItemNode; -class AbstractHistoryBackend; -class CategorizedHistoryModelPrivate; -class QSortFilterProxyModel; -class QItemSelectionModel; - -//TODO split ASAP -///CategorizedHistoryModel: History call manager -class LIB_EXPORT CategorizedHistoryModel : public QAbstractItemModel, public CollectionManagerInterface<Call> -{ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" - Q_OBJECT - #pragma GCC diagnostic pop -public: - friend class HistoryItemNode; - friend class HistoryTopLevelItem; - - //Properties - Q_PROPERTY(bool hasCollections READ hasCollections ) - Q_PROPERTY(bool historyEnabled READ isHistoryEnabled WRITE setHistoryEnabled) - Q_PROPERTY(bool historyLimited READ isHistoryLimited WRITE setHistoryLimited) - - //Singleton - static CategorizedHistoryModel& instance(); - - //Getters - int acceptedPayloadTypes () const; - bool isHistoryLimited () const; - bool isHistoryEnabled () const; - int historyLimit () const; - const CallMap getHistoryCalls () const; - - //Backend model implementation - virtual bool clearAllCollections() const override; - - //Setters - void setCategoryRole(int role); - void setHistoryLimited(bool isLimited); - void setHistoryLimit(int numberOfDays); - void setHistoryEnabled(bool isEnabled); - void clear(); - - //Model implementation - virtual bool setData ( const QModelIndex& index, const QVariant &value, int role ) override; - virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const override; - virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const override; - virtual Qt::ItemFlags flags ( const QModelIndex& index ) const override; - virtual int columnCount ( const QModelIndex& parent = QModelIndex() ) const override; - virtual QModelIndex parent ( const QModelIndex& index ) const override; - virtual QModelIndex index ( int row, int column, const QModelIndex& parent=QModelIndex()) const override; - virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override; - virtual QStringList mimeTypes ( ) const override; - virtual QMimeData* mimeData ( const QModelIndexList &indexes ) const override; - virtual bool dropMimeData( const QMimeData*, Qt::DropAction, int, int, const QModelIndex& ) override; - virtual bool insertRows ( int row, int count, const QModelIndex & parent = QModelIndex() ) override; - virtual QHash<int,QByteArray> roleNames() const override; - - struct LIB_EXPORT SortedProxy { - enum class Categories { - DATE , - NAME , - POPULARITY, - LENGTH , - SPENT_TIME, - COUNT__ - }; - - QSortFilterProxyModel* model () const; - QAbstractItemModel * categoryModel () const; - QItemSelectionModel * categorySelectionModel() const; - static CategorizedHistoryModel::SortedProxy& instance(); - }; - -private: - //Constructor - explicit CategorizedHistoryModel(); - ~CategorizedHistoryModel(); - QScopedPointer<CategorizedHistoryModelPrivate> d_ptr; - Q_DECLARE_PRIVATE(CategorizedHistoryModel) - - //Backend interface - virtual void collectionAddedCallback(CollectionInterface* collection) override; - virtual bool addItemCallback(const Call* item) override; - virtual bool removeItemCallback(const Call* item) override; - -Q_SIGNALS: - ///Emitted when the history change (new items, cleared) - void historyChanged ( ); - ///Emitted when a new item is added to prevent full reload - void newHistoryCall ( Call* call ); -}; diff --git a/src/certificatemodel.cpp b/src/certificatemodel.cpp index 78f76d26..1ea213b3 100644 --- a/src/certificatemodel.cpp +++ b/src/certificatemodel.cpp @@ -37,8 +37,6 @@ #include "certificate.h" #include "contactmethod.h" #include "account.h" -#include "foldercertificatecollection.h" -#include "daemoncertificatecollection.h" #include "private/matrixutils.h" #include "private/certificatemodel_p.h" #include "accountmodel.h" @@ -123,10 +121,6 @@ private: CertificateNode* m_pRoot; }; -//TODO remove -static FolderCertificateCollection* m_pFallbackCollection = nullptr; -static DaemonCertificateCollection* m_pFallbackDaemonCollection = nullptr; - const Matrix1D<Certificate::Status, const char*> CertificateModelPrivate::m_StatusMap = {{ /* Certificate::Status::UNDEFINED */ DRing::Certificate::Status::UNDEFINED, /* Certificate::Status::ALLOWED */ DRing::Certificate::Status::ALLOWED , @@ -177,17 +171,6 @@ CertificateModel::CertificateModel(QObject* parent) : QAbstractItemModel(parent) d_ptr(new CertificateModelPrivate(this)) { setObjectName("CertificateModel"); - //TODO replace with something else - m_pFallbackCollection = addCollection<FolderCertificateCollection,QString,FlagPack<FolderCertificateCollection::Options>, QString>(QString(), - FolderCertificateCollection::Options::FALLBACK | FolderCertificateCollection::Options::READ_WRITE, - QObject::tr("Local certificate store") - ); - m_pFallbackDaemonCollection = addCollection<DaemonCertificateCollection,Account*,DaemonCertificateCollection::Mode>( - nullptr, - DaemonCertificateCollection::Mode::ALLOWED - ); - - m_pFallbackCollection->load(); } CertificateModel::~CertificateModel() @@ -628,7 +611,6 @@ Certificate* CertificateModel::getCertificateFromPath(const QString& path, Accou if (!cert) { cert = new Certificate(path, Certificate::Type::NONE); - cert->setCollection(m_pFallbackDaemonCollection); { // mutex QMutexLocker(&d_ptr->m_CertInsertion); @@ -659,7 +641,6 @@ Certificate* CertificateModel::getCertificateFromPath(const QString& path, Certi //The certificate is not loaded yet if (!cert) { cert = new Certificate(path, type); - cert->setCollection(m_pFallbackDaemonCollection); { // mutex QMutexLocker(&d_ptr->m_CertInsertion); diff --git a/src/certificatemodel.h b/src/certificatemodel.h index d4bd1b34..dca26b2b 100644 --- a/src/certificatemodel.h +++ b/src/certificatemodel.h @@ -36,8 +36,6 @@ public: friend class Certificate; friend class CertificatePrivate; friend class Account; - friend class DaemonCertificateCollectionPrivate; - friend class DaemonCertificateCollection; enum class Role { NodeType = static_cast<int>(Ring::Role::UserRole) + 100, diff --git a/src/ciphermodel.cpp b/src/ciphermodel.cpp deleted file mode 100644 index 4d4a3422..00000000 --- a/src/ciphermodel.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "ciphermodel.h" - -//Qt -#include <QtCore/QCoreApplication> - -//Ring daemon -#include <account_const.h> - -//Ring -#include "dbus/configurationmanager.h" -#include "account.h" - -class CipherModelPrivate { -public: - CipherModelPrivate(Account* parent); - ~CipherModelPrivate(); - - //Attributes - bool* m_lChecked ; - Account* m_pAccount ; - static QVector<QByteArray> m_slSupportedCiphers; - static QHash<const QString,int> m_shMapping ; - static bool m_sIsLoaded ; - bool m_UseDefault ; - -}; - -bool CipherModelPrivate::m_sIsLoaded = false; -QVector<QByteArray> CipherModelPrivate::m_slSupportedCiphers; -QHash<const QString,int> CipherModelPrivate::m_shMapping; - -CipherModelPrivate::CipherModelPrivate(Account* parent) : m_pAccount(parent),m_UseDefault(true) -{ - m_lChecked = new bool[m_slSupportedCiphers.size()]{}; - - foreach(const QString& cipher, parent->accountDetail(DRing::Account::ConfProperties::TLS::CIPHERS).split(' ')) { - if (!cipher.trimmed().isEmpty()) { - m_lChecked[m_shMapping[cipher]] = true; - m_UseDefault = false; - } - } -} - -CipherModelPrivate::~CipherModelPrivate() -{ - delete[] m_lChecked; -} - -CipherModel::CipherModel(Account* parent) : QAbstractListModel(parent), -d_ptr(new CipherModelPrivate(parent)) -{} - -CipherModel::~CipherModel() -{ - delete d_ptr; -} - -QHash<int,QByteArray> CipherModel::roleNames() const -{ - static QHash<int, QByteArray> roles = QAbstractItemModel::roleNames(); - /*static bool initRoles = false; - if (!initRoles) { - initRoles = true; - - }*/ - return roles; -} - -//Model functions -QVariant CipherModel::data( const QModelIndex& index, int role) const -{ - if (!index.isValid()) return QVariant(); - switch (role) { - case Qt::DisplayRole: - return CipherModelPrivate::m_slSupportedCiphers[index.row()]; - case Qt::CheckStateRole: - return d_ptr->m_lChecked[index.row()]?Qt::Checked:Qt::Unchecked; - }; - return QVariant(); -} - -int CipherModel::rowCount( const QModelIndex& parent ) const -{ - return !parent.isValid() ? d_ptr->m_slSupportedCiphers.size() : 0; -} - -Qt::ItemFlags CipherModel::flags( const QModelIndex& index ) const -{ - return (index.isValid()) ? (Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsUserCheckable) : Qt::NoItemFlags; -} - -bool CipherModel::setData( const QModelIndex& index, const QVariant &value, int role) -{ - if (index.isValid() && role == Qt::CheckStateRole) { - d_ptr->m_lChecked[index.row()] = value == Qt::Checked; - emit dataChanged(index,index); - QStringList ciphers; - for(int i =0; i< d_ptr->m_slSupportedCiphers.size();i++) { - if (d_ptr->m_lChecked[i]) - ciphers << d_ptr->m_slSupportedCiphers[i]; - } - d_ptr->m_pAccount->setAccountProperty(DRing::Account::ConfProperties::TLS::CIPHERS,ciphers.join(QString(' '))); - - emit modified(); - - return true; - } - return false; -} - -bool CipherModel::useDefault() const -{ - return d_ptr->m_UseDefault; -} - -void CipherModel::setUseDefault(bool value) -{ - d_ptr->m_UseDefault = value; - if (value) { - for (int i =0; i < d_ptr->m_slSupportedCiphers.size();i++) { - d_ptr->m_lChecked[i] = false; - } - emit dataChanged(index(0,0),index(d_ptr->m_slSupportedCiphers.size()-1,0)); - } -} diff --git a/src/ciphermodel.h b/src/ciphermodel.h deleted file mode 100644 index cc14755e..00000000 --- a/src/ciphermodel.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 <QtCore/QAbstractListModel> - -class CipherModelPrivate; -class Account; - -/**This model is exposed for each account. It allow to ensure that the selected - * ciphers are supported by the system. This was previously done using a simple - * line edit in each UI, but it allowed to enter random (and invalid) values, - * making the process of configuring a secure account harder. - * - * @todo This model need to automatically sort the ciphers in the optimal order - * when sabing them. - */ -class LIB_EXPORT CipherModel : public QAbstractListModel { - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" - Q_OBJECT - #pragma GCC diagnostic pop - - friend class Account; - -public: - - //Property - Q_PROPERTY(bool useDefault READ useDefault WRITE setUseDefault) - - //Model functions - virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const override; - virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const override; - virtual Qt::ItemFlags flags ( const QModelIndex& index ) const override; - virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) override; - virtual QHash<int,QByteArray> roleNames() const override; - - //Getter - bool useDefault() const; - - //Setter - void setUseDefault(bool value); - -private: - - //Private constructor, can only be called by 'Account' - explicit CipherModel(Account* parent); - virtual ~CipherModel(); - - CipherModelPrivate* d_ptr; - Q_DECLARE_PRIVATE(CipherModel) - -Q_SIGNALS: - void modified(); - -}; -Q_DECLARE_METATYPE(CipherModel*) - diff --git a/src/contactmethod.cpp b/src/contactmethod.cpp index 5bb637b7..fde283dd 100644 --- a/src/contactmethod.cpp +++ b/src/contactmethod.cpp @@ -32,7 +32,6 @@ #include "private/person_p.h" #include "private/contactmethod_p.h" #include "call.h" -#include "availableaccountmodel.h" #include "dbus/presencemanager.h" #include "numbercategorymodel.h" #include "private/numbercategorymodel_p.h" @@ -40,14 +39,12 @@ #include "certificate.h" #include "accountmodel.h" #include "certificatemodel.h" -#include "media/textrecording.h" #include "mime.h" #include "globalinstances.h" #include "interfaces/pixmapmanipulatori.h" //Private #include "private/phonedirectorymodel_p.h" -#include "private/textrecording_p.h" void ContactMethodPrivate::callAdded(Call* call) { @@ -101,7 +98,7 @@ ContactMethodPrivate::ContactMethodPrivate(const URI& uri, NumberCategory* cat, m_Uri(uri),m_pCategory(cat),m_Tracked(false),m_Present(false), m_Type(st),m_PopularityIndex(-1),m_pPerson(nullptr),m_pAccount(nullptr), m_IsBookmark(false), - m_Index(-1),m_hasType(false),m_pTextRecording(nullptr), m_pCertificate(nullptr), + m_Index(-1),m_hasType(false), m_pCertificate(nullptr), m_Confirmed(false), q_ptr(q) {} @@ -599,10 +596,10 @@ QVariant ContactMethod::roleData(int role) const case static_cast<int>(Ring::Role::FormattedLastUsed): case static_cast<int>(Call::Role::FormattedDate): case static_cast<int>(Call::Role::FuzzyDate): - cat = HistoryTimeCategoryModel::timeToHistoryCategory(d_ptr->m_UsageStats.lastUsed()); + cat = QVariant(); break; case static_cast<int>(Ring::Role::IndexedLastUsed): - return QVariant(static_cast<int>(HistoryTimeCategoryModel::timeToHistoryConst(d_ptr->m_UsageStats.lastUsed()))); + return QVariant(); case static_cast<int>(Call::Role::HasAVRecording): cat = cat = !lastCall ? QVariant() : lastCall->isAVRecording(); break; @@ -634,12 +631,6 @@ QVariant ContactMethod::roleData(int role) const break; case static_cast<int>(Call::Role::LifeCycleState): return QVariant::fromValue(Call::LifeCycleState::FINISHED); - case static_cast<int>(Ring::Role::UnreadTextMessageCount): - if (auto rec = textRecording()) - cat = rec->unreadInstantTextMessagingModel()->rowCount(); - else - cat = 0; - break; } return cat; } @@ -834,15 +825,6 @@ bool ContactMethod::operator==(const ContactMethod& other) const return this->d_ptr== other.d_ptr; } -media::TextRecording* ContactMethod::textRecording() const -{ - if (!d_ptr->m_pTextRecording) { - d_ptr->m_pTextRecording = media::RecordingModel::instance().createTextRecording(this); - } - - return d_ptr->m_pTextRecording; -} - bool ContactMethod::isReachable() const { auto& m = AccountModel::instance(); @@ -894,27 +876,6 @@ void ContactMethodPrivate::setCertificate(Certificate* certificate) certificate->setContactMethod(q_ptr); } -void ContactMethodPrivate::setTextRecording(media::TextRecording* r) -{ - m_pTextRecording = r; -} - -bool ContactMethod::sendOfflineTextMessage(const QMap<QString,QString>& payloads) -{ - auto selectedAccount = account() ? account() : AvailableAccountModel::currentDefaultAccount(this); - - if (!selectedAccount) { - qDebug() << "No account available for this contactmethod!"; - return false; - } - auto txtRecording = textRecording(); - auto id = ConfigurationManager::instance().sendTextMessage(selectedAccount->id() - ,uri().format(URI::Section::SCHEME|URI::Section::USER_INFO|URI::Section::HOSTNAME) - ,payloads); - txtRecording->d_ptr->insertNewMessage(payloads, this, media::Media::Direction::OUT, id); - return true; -} - /************************************************************************************ * * diff --git a/src/contactmethod.h b/src/contactmethod.h index f6d54f45..d20bc073 100644 --- a/src/contactmethod.h +++ b/src/contactmethod.h @@ -41,11 +41,6 @@ class TemporaryContactMethodPrivate; class InstantMessagingModel; class Certificate; -namespace media { - class TextRecording; -} - - ///ContactMethod: represent a phone number class LIB_EXPORT ContactMethod : public ItemBase { @@ -53,7 +48,6 @@ class LIB_EXPORT ContactMethod : public ItemBase public: friend class PhoneDirectoryModel; friend class PhoneDirectoryModelPrivate; - friend class LocalTextRecordingCollection; friend class CallPrivate; friend class AccountPrivate; @@ -133,7 +127,6 @@ public: QString uid () const; URI::ProtocolHint protocolHint () const; QByteArray sha1 () const; - media::TextRecording* textRecording () const; bool isReachable () const; Certificate* certificate () const; QString registeredName () const; @@ -205,9 +198,6 @@ private Q_SLOTS: void accountDestroyed(QObject* o); void contactRebased(Person* other); -public Q_SLOTS: - bool sendOfflineTextMessage(const QMap<QString, QString>& payloads); - Q_SIGNALS: ///A new call have used this ContactMethod void callAdded ( Call* call ); diff --git a/src/contactmodel.cpp b/src/contactmodel.cpp index b29703a0..e2c9d226 100644 --- a/src/contactmodel.cpp +++ b/src/contactmodel.cpp @@ -38,7 +38,6 @@ #include "api/newaccountmodel.h" #include "callbackshandler.h" #include "uri.h" - #include "private/vcardutils.h" #include "authority/daemon.h" @@ -658,7 +657,6 @@ ContactModelPimpl::slotContactRemoved(const std::string& accountId, const std::s if (banned) { contact->second.isBanned = true; - // Update bannedContacts index bannedContacts.emplace_back(contact->second.profileInfo.uri); } else { diff --git a/src/contactrequest.cpp b/src/contactrequest.cpp deleted file mode 100644 index 3f938916..00000000 --- a/src/contactrequest.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "contactrequest.h" - -//Qt -#include <QtCore/QDateTime> - -//Ring -#include <account.h> -#include <certificate.h> -#include <certificatemodel.h> -#include "itembase.h" -#include "personmodel.h" - -//DRing -#include "dbus/configurationmanager.h" - -class ContactRequestPrivate -{ -public: - //Attributes - QDateTime m_Time ; - Certificate* m_pCertificate; - Account* m_pAccount ; - Person* m_pPeer ; -}; - -ContactRequest::ContactRequest(Account* a, Person* p, const QString& id, time_t time) : QObject(a), d_ptr(new ContactRequestPrivate) -{ - d_ptr->m_pAccount = a; - d_ptr->m_pPeer = p; - d_ptr->m_Time = QDateTime::fromTime_t(time); - d_ptr->m_pCertificate = CertificateModel::instance().getCertificateFromId(id, a); -} - -ContactRequest::~ContactRequest() -{ - delete d_ptr; -} - -Certificate* ContactRequest::certificate() const -{ - return d_ptr->m_pCertificate; -} - -QDateTime ContactRequest::date() const -{ - return d_ptr->m_Time; -} - -Account* ContactRequest::account() const -{ - return d_ptr->m_pAccount; -} - -/** - * get the person associated to the contact request. - */ -Person* -ContactRequest::peer() const -{ - return d_ptr->m_pPeer; -} - -/** - * set the person associated to the contact request. - */ -void -ContactRequest::setPeer(Person* person) -{ - d_ptr->m_pPeer = person; -} - -bool ContactRequest::accept() -{ - if (ConfigurationManager::instance().acceptTrustRequest(d_ptr->m_pAccount->id(), d_ptr->m_pCertificate->remoteId())) { - PersonModel::instance().addPeerProfile(peer()); - emit requestAccepted(); - return true; - } - return false; -} - -bool ContactRequest::discard() -{ - if (ConfigurationManager::instance().discardTrustRequest(d_ptr->m_pAccount->id(), d_ptr->m_pCertificate->remoteId())) { - emit requestDiscarded(); - return true; - } - return false; -} - -/** - * block the contact request. - */ -void -ContactRequest::block() -{ - ConfigurationManager::instance().removeContact(d_ptr->m_pAccount->id(), d_ptr->m_pCertificate->remoteId(), true); - emit requestBlocked(); -} - -/** - * get the data by role selection - * @param role define the role to select - * @return a QVariant object, which contains the selection - */ -QVariant -ContactRequest::roleData(int role) const -{ - switch (role) { - case Qt::DisplayRole: - case Qt::EditRole: - return certificate()->remoteId(); - case static_cast<int>(Ring::Role::Object): - return QVariant::fromValue(const_cast<ContactRequest*>(this)); - case static_cast<int>(Ring::Role::ObjectType): - return QVariant::fromValue(Ring::ObjectType::ContactRequest); - } - - /* unknown role */ - return QVariant(); -} - -/** - * defines the comparaison operator - */ -bool -ContactRequest::operator==(const ContactRequest& another) const -{ - bool certificate = d_ptr->m_pCertificate == another.d_ptr->m_pCertificate; - bool account = d_ptr->m_pAccount == another.d_ptr->m_pAccount; - bool time = d_ptr->m_Time == another.d_ptr->m_Time; - - return account && certificate && time; -} - diff --git a/src/contactrequest.h b/src/contactrequest.h deleted file mode 100644 index 261cfc6f..00000000 --- a/src/contactrequest.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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/QObject> -#include <typedefs.h> - -class ContactRequestPrivate; -class AccountModel; -class AccountModelPrivate; -class Certificate; -class Account; -class AccountPrivate; -class Person; - -class LIB_EXPORT ContactRequest : public QObject -{ - Q_OBJECT - -friend class Account; -friend class AccountModelPrivate; -friend class AccountPrivate; - -public: - - //Getter - Certificate* certificate() const; - QDateTime date () const; - Account* account () const; - Q_INVOKABLE QVariant roleData (int role) const; - Person* peer() const; - - // Setter - void setPeer(Person* person); - - //Mutator - Q_INVOKABLE bool accept (); - Q_INVOKABLE bool discard(); - Q_INVOKABLE void block(); - - // Operator - bool operator==(const ContactRequest& another) const; - -private: - explicit ContactRequest(Account* a, Person* p, const QString& id = QString(), time_t time = -1); - virtual ~ContactRequest(); - - ContactRequestPrivate* d_ptr; - Q_DECLARE_PRIVATE(ContactRequest) - -Q_SIGNALS: - void requestAccepted (); - void requestDiscarded(); - void requestBlocked(); -}; diff --git a/src/conversationmodel.cpp b/src/conversationmodel.cpp index 7609d1af..65e1648f 100644 --- a/src/conversationmodel.cpp +++ b/src/conversationmodel.cpp @@ -47,10 +47,7 @@ #include "callbackshandler.h" #include "authority/databasehelper.h" -#include "availableaccountmodel.h" -#include "namedirectory.h" -#include "phonedirectorymodel.h" -#include "contactmethod.h" +#include "uri.h" // Dbus #include "dbus/configurationmanager.h" @@ -1136,8 +1133,8 @@ ConversationModelPimpl::~ConversationModelPimpl() void ConversationModelPimpl::initConversations() { - auto* account = AccountModel::instance().getById(linked.owner.id.c_str()); - if (!account) + const MapStringString accountDetails = ConfigurationManager::instance().getAccountDetails(linked.owner.id.c_str()); + if (accountDetails.empty()) return; // Fill conversations @@ -1894,8 +1891,8 @@ ConversationModelPimpl::slotTransferStatusCreated(long long dringId, datatransfe // check if transfer is for the current account if (info.accountId != linked.owner.id) return; - const auto* account = AccountModel::instance().getById(info.accountId.c_str()); - if (not account) + const MapStringString accountDetails = ConfigurationManager::instance().getAccountDetails(linked.owner.id.c_str()); + if (accountDetails.empty()) return; auto type = linked.owner.profileInfo.type; try { diff --git a/src/daemoncertificatecollection.cpp b/src/daemoncertificatecollection.cpp deleted file mode 100644 index b91a730e..00000000 --- a/src/daemoncertificatecollection.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "daemoncertificatecollection.h" - -//Ring -#include "certificate.h" -#include "account.h" -#include "certificatemodel.h" -#include "globalinstances.h" -#include "interfaces/pixmapmanipulatori.h" - -//Dring -#include "dbus/configurationmanager.h" -#include "security_const.h" - -class DaemonCertificateEditor final : public CollectionEditor<Certificate> -{ -public: - DaemonCertificateEditor(CollectionMediator<Certificate>* m, const QString& path); - virtual bool save ( const Certificate* item ) override; - virtual bool remove ( const Certificate* item ) override; - virtual bool edit ( Certificate* item ) override; - virtual bool addNew ( Certificate* item ) override; - virtual bool addExisting( const Certificate* item ) override; - - QVector<Certificate*> m_lItems; - QString m_Path ; - QHash<const Certificate*,QString> m_hPaths; - -private: - virtual QVector<Certificate*> items() const override; -}; - -class DaemonCertificateCollectionPrivate : public QObject -{ - Q_OBJECT -public: - DaemonCertificateCollectionPrivate(DaemonCertificateCollection* parent, Account* a, DaemonCertificateCollection::Mode mode); - - //Attributes - DaemonCertificateCollection* q_ptr; - Account* m_pAccount; - DaemonCertificateCollection::Mode m_Mode; - -public Q_SLOTS: - void slotCertificatePinned(const QString& id); - void slotCertificateExpired(const QString& id); - void slotCertificatePathPinned(const QString& path, const QStringList& certIds); -}; - -DaemonCertificateCollectionPrivate::DaemonCertificateCollectionPrivate(DaemonCertificateCollection* parent, Account* a, DaemonCertificateCollection::Mode mode) : QObject(), q_ptr(parent), -m_pAccount(a), m_Mode(mode) -{ - ConfigurationManagerInterface& configurationManager = ConfigurationManager::instance(); - - connect(&configurationManager, &ConfigurationManagerInterface::certificatePinned , this, &DaemonCertificateCollectionPrivate::slotCertificatePinned ); - - connect(&configurationManager, &ConfigurationManagerInterface::certificateExpired , this, &DaemonCertificateCollectionPrivate::slotCertificateExpired ); - - connect(&configurationManager, &ConfigurationManagerInterface::certificatePathPinned , this, &DaemonCertificateCollectionPrivate::slotCertificatePathPinned); - - // connect(&configurationManager, &ConfigurationManagerInterface::incomingContactRequest , this, &DaemonCertificateCollectionPrivate::); -} - -DaemonCertificateCollection::DaemonCertificateCollection(CollectionMediator<Certificate>* mediator, Account* a, DaemonCertificateCollection::Mode mode) : -CollectionInterface(new DaemonCertificateEditor(mediator,QString()),nullptr),d_ptr(new DaemonCertificateCollectionPrivate(this,a,mode)) -{ - -} - -DaemonCertificateCollection::~DaemonCertificateCollection() -{ - delete d_ptr; -} - -void DaemonCertificateCollectionPrivate::slotCertificatePinned(const QString& id) -{ - //qDebug() << "\n\nCERTIFICATE ADDED" << id; - Certificate* cert = CertificateModel::instance().getCertificateFromId(id); - - if (!cert->collection()) - cert->setCollection(q_ptr); - - q_ptr->editor<Certificate>()->addExisting(cert); -} - -void DaemonCertificateCollectionPrivate::slotCertificateExpired(const QString& id) -{ - Q_UNUSED(id); - //qDebug() << "\n\nCERTIFICATE EXPIRED" << id; -} - -void DaemonCertificateCollectionPrivate::slotCertificatePathPinned(const QString& path, const QStringList& certIds) -{ - Q_UNUSED(path); - Q_UNUSED(certIds); - //Create a new collection if it is a directory or size > 1 - //qDebug() << "\n\nSIGNAL CERTIFICATE PATH PINNING" << path << certIds; -} - -bool DaemonCertificateCollection::load() -{ - if (!d_ptr->m_pAccount || d_ptr->m_pAccount->isNew()) - return false; - - const QString mode = d_ptr->m_Mode == DaemonCertificateCollection::Mode::ALLOWED ? - DRing::Certificate::Status::ALLOWED : DRing::Certificate::Status::BANNED; - - ConfigurationManagerInterface& configurationManager = ConfigurationManager::instance(); - - const QStringList certs = configurationManager.getCertificatesByStatus( - d_ptr->m_pAccount->id(), mode - ); - - for (const QString& id : certs) - CertificateModel::instance().getCertificateFromId(id,d_ptr->m_pAccount,d_ptr->m_pAccount->id()+"_"+mode); - - return true; -} - -bool DaemonCertificateCollection::reload() -{ - return false; -} - -bool DaemonCertificateCollection::clear() -{ - return false; -} - -QString DaemonCertificateCollection::name() const -{ - auto name = d_ptr->m_pAccount ? d_ptr->m_pAccount->alias() : QObject::tr("Daemon certificate store"); - - if (d_ptr->m_Mode == Mode::BANNED) { - //: The list of banned certificates for this account - return QObject::tr("%1 banned list").arg(name); - } - //: The list of allowed certificates for this account - return QObject::tr("%1 allowed list").arg(name); -} - -QString DaemonCertificateCollection::category() const -{ - return QObject::tr("Certificate"); -} - -QVariant DaemonCertificateCollection::icon() const -{ - return GlobalInstances::pixmapManipulator().collectionIcon(this,Interfaces::PixmapManipulatorI::CollectionIconHint::CERTIFICATE); -} - -bool DaemonCertificateCollection::isEnabled() const -{ - return true; -} - -QByteArray DaemonCertificateCollection::id() const -{ - return "DaemonCertificateCollection"; -} - -FlagPack<CollectionInterface::SupportedFeatures> DaemonCertificateCollection::supportedFeatures() const -{ - return - CollectionInterface::SupportedFeatures::NONE | - CollectionInterface::SupportedFeatures::LOAD | - CollectionInterface::SupportedFeatures::REMOVE | - CollectionInterface::SupportedFeatures::LISTABLE ; -} - - -/******************************************************************************* - * * - * Editor * - * * - ******************************************************************************/ - -DaemonCertificateEditor::DaemonCertificateEditor(CollectionMediator<Certificate>* m, const QString& path) : CollectionEditor<Certificate>(m),m_Path(path) -{ - -} - -bool DaemonCertificateEditor::save( const Certificate* item) -{ - Q_UNUSED(item) - return false; -} - -bool DaemonCertificateEditor::remove( const Certificate* item) -{ - //TODO - Q_UNUSED(item); - return false; -} - -bool DaemonCertificateEditor::edit( Certificate* item) -{ - Q_UNUSED(item) - return false; -} - -bool DaemonCertificateEditor::addNew( Certificate* item) -{ - Q_UNUSED(item) - return false; -} - -bool DaemonCertificateEditor::addExisting( const Certificate* item) -{ - Q_UNUSED(item) - m_lItems << const_cast<Certificate*>(item); - return false; -} - -QVector<Certificate*> DaemonCertificateEditor::items() const -{ - return m_lItems; -} - -#include <daemoncertificatecollection.moc> diff --git a/src/daemoncertificatecollection.h b/src/daemoncertificatecollection.h deleted file mode 100644 index 9b85b6c2..00000000 --- a/src/daemoncertificatecollection.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 <collectioninterface.h> -#include <typedefs.h> - -class Call; -class Person; -class DaemonCertificateCollectionPrivate; -class Certificate; -class Account; - -template<typename T> class CollectionMediator; - -/** - * This class is used when no other Person collections are available. It will - * provide a basic collection to add and use Persons/Contacts. It is also - * necessary as some metadata required for elements such as auto completion are - * provided by the Person collections. - */ -class LIB_EXPORT DaemonCertificateCollection : public CollectionInterface -{ - -public: - - enum class Mode { - ALLOWED, - BANNED - }; - - explicit DaemonCertificateCollection(CollectionMediator<Certificate>* mediator, Account* a, Mode mode); - virtual ~DaemonCertificateCollection(); - - virtual bool load () override; - virtual bool reload() override; - virtual bool clear () override; - - virtual QString name () const override; - virtual QString category () const override; - virtual QVariant icon () const override; - virtual bool isEnabled() const override; - virtual QByteArray id () const override; - - virtual FlagPack<SupportedFeatures> supportedFeatures() const override; - -private: - DaemonCertificateCollectionPrivate* d_ptr; - Q_DECLARE_PRIVATE(DaemonCertificateCollection) -}; -Q_DECLARE_METATYPE(DaemonCertificateCollection*) - diff --git a/src/extensions/presencecollectionextension.cpp b/src/extensions/presencecollectionextension.cpp deleted file mode 100644 index a1e54e7f..00000000 --- a/src/extensions/presencecollectionextension.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2014-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "presencecollectionextension.h" -#include "collectioninterface.h" -#include "contactmethod.h" -#include "person.h" -#include "presencestatusmodel.h" -#include "collectionextensionmodel.h" - -DECLARE_COLLECTION_EXTENSION(PresenceCollectionExtension) - -PresenceCollectionExtension::PresenceCollectionExtension(QObject* parent) : - CollectionExtensionInterface(parent) -{ - -} - -QVariant PresenceCollectionExtension::data(int role) const -{ - Q_UNUSED(role) - - if (role == Qt::DisplayRole) { - return QObject::tr("Presence tracking"); - } - - return QVariant(); -} diff --git a/src/extensions/presencecollectionextension.h b/src/extensions/presencecollectionextension.h deleted file mode 100644 index 4ee925b4..00000000 --- a/src/extensions/presencecollectionextension.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2014-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 <collectionextensioninterface.h> -#include <collectionextensionmodel.h> - -#include <typedefs.h> - -#include <QtCore/QVariant> -#include <QtCore/QModelIndex> - -class CollectionInterface; - -class LIB_EXPORT PresenceCollectionExtension final : public CollectionExtensionInterface -{ - Q_OBJECT - -public: - explicit PresenceCollectionExtension(QObject* parent); - - virtual QVariant data(int role) const override; -}; - diff --git a/src/extensions/securityevaluationextension.cpp b/src/extensions/securityevaluationextension.cpp index 7b6e19b2..8c78e59a 100644 --- a/src/extensions/securityevaluationextension.cpp +++ b/src/extensions/securityevaluationextension.cpp @@ -22,7 +22,6 @@ #include "person.h" #include "account.h" #include "call.h" -#include "presencestatusmodel.h" #include "collectionextensionmodel.h" #include "globalinstances.h" #include "interfaces/pixmapmanipulatori.h" diff --git a/src/fallbackpersoncollection.cpp b/src/fallbackpersoncollection.cpp deleted file mode 100644 index a73983a1..00000000 --- a/src/fallbackpersoncollection.cpp +++ /dev/null @@ -1,276 +0,0 @@ -/************************************************************************************ - * Copyright (C) 2014-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 Lesser General Public * - * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***********************************************************************************/ -#include "fallbackpersoncollection.h" - -//Qt -#include <QtCore/QFile> -#include <QtCore/QDir> -#include <QtCore/QHash> -#include <QtCore/QTimer> -#include <QtCore/QUrl> -#include <QtCore/QCryptographicHash> -#include <QtCore/QStandardPaths> - -//Ring -#include "database.h" -#include "person.h" -#include "personmodel.h" -#include "private/vcardutils.h" -#include "contactmethod.h" -#include "collectioneditor.h" -#include "globalinstances.h" -#include "interfaces/pixmapmanipulatori.h" -#include "interfaces/actionextenderi.h" -#include "interfaces/itemmodelstateserializeri.h" -#include "private/threadworker.h" - -class FallbackPersonBackendEditor final : public CollectionEditor<Person> -{ -public: - FallbackPersonBackendEditor(CollectionMediator<Person>* m, const QString& path) : CollectionEditor<Person>(m),m_Path(path) {} - virtual bool save ( const Person* item ) override; - virtual bool remove ( const Person* item ) override; - virtual bool edit ( Person* item ) override; - virtual bool addNew ( Person* item ) override; - virtual bool addExisting( const Person* item ) override; - - QVector<Person*> m_lItems; - QString m_Path ; - QHash<const Person*,QString> m_hPaths; - -private: - virtual QVector<Person*> items() const override; -}; - -class FallbackPersonCollectionPrivate final : public QObject -{ - Q_OBJECT -public: - FallbackPersonCollectionPrivate(FallbackPersonCollection* parent, CollectionMediator<Person>* mediator, const QString& path); - CollectionMediator<Person>* m_pMediator; - QString m_Path ; - QString m_Name ; - - FallbackPersonCollection* q_ptr; - -public Q_SLOTS: - void loadAsync(); -}; - -FallbackPersonCollectionPrivate::FallbackPersonCollectionPrivate(FallbackPersonCollection* parent, CollectionMediator<Person>* mediator, const QString& path) : q_ptr(parent), m_pMediator(mediator), m_Path(path) -{ - //Default to somewhere ~/.local/share - if (m_Path.isEmpty()) { - m_Path = (lrc::Database::getPath()) + "/vCard/"; - static_cast<FallbackPersonBackendEditor *>(q_ptr->editor<Person>()) - ->m_Path = m_Path; - } - //Make sure the directory exists so that saving new contacts there doesn't fail - if (!QDir().mkpath(m_Path)) - qWarning() << "cannot create path for fallbackcollection: " << m_Path; - - m_Name = path.split('/').last(); - if (m_Name.size()) - m_Name[0] = m_Name[0].toUpper(); - else - m_Name = "vCard"; -} - -FallbackPersonCollection::FallbackPersonCollection(CollectionMediator<Person>* mediator, const QString& path, FallbackPersonCollection* parent) : -CollectionInterface(new FallbackPersonBackendEditor(mediator,path),parent),d_ptr(new FallbackPersonCollectionPrivate(this,mediator,path)) -{ -} - -FallbackPersonCollection::~FallbackPersonCollection() -{ - delete d_ptr; -} - -bool FallbackPersonBackendEditor::save(const Person* item) -{ - if (!item) - return false; - - //An UID is required - if (item->uid().isEmpty()) { - QCryptographicHash hash(QCryptographicHash::Sha1); - for (ContactMethod* n : item->phoneNumbers()) - hash.addData(n->uri().toLatin1()); - hash.addData(item->formattedName().toLatin1()); - QByteArray random; - - for (int i=0;i<5;i++) - random.append(QChar((char)(rand()%255))); - - hash.addData(random); - - const_cast<Person*>(item)->setUid(hash.result().toHex()); - } - - const QString path = m_Path+'/'+item->uid()+".vcf"; - - QFile file(path); - - if (Q_UNLIKELY(!file.open(QIODevice::WriteOnly))) { - qWarning() << "Can't write to" << path; - return false; - } - - file.write(item->toVCard({})); - file.close(); - return true; -} - -bool FallbackPersonBackendEditor::remove(const Person* item) -{ - if (!item) - return false; - - QString path = m_hPaths[item]; - - if (path.isEmpty()) - path = m_Path+'/'+item->uid()+".vcf"; - - bool ret = QFile::remove(path); - - if (ret) { - ret &= mediator()->removeItem(item); - } - - return ret; -} - -bool FallbackPersonBackendEditor::edit( Person* item) -{ - GlobalInstances::actionExtender().editPerson(item); - return true; -} - -bool FallbackPersonBackendEditor::addNew( Person* item) -{ - item->ensureUid(); - bool ret = save(item); - - if (ret) { - addExisting(item); - } - - return ret; -} - -bool FallbackPersonBackendEditor::addExisting(const Person* item) -{ - m_lItems << const_cast<Person*>(item); - mediator()->addItem(item); - return true; -} - -QVector<Person*> FallbackPersonBackendEditor::items() const -{ - return m_lItems; -} - -QString FallbackPersonCollection::name () const -{ - return d_ptr->m_Name; -} - -QString FallbackPersonCollection::category () const -{ - return QObject::tr("Contact"); -} - -QVariant FallbackPersonCollection::icon() const -{ - return GlobalInstances::pixmapManipulator().collectionIcon(this,Interfaces::PixmapManipulatorI::CollectionIconHint::CONTACT); -} - -bool FallbackPersonCollection::isEnabled() const -{ - /* if ItemModelStateSerializer exists, check if collectin is enabled, else assume it is */ - try { - return GlobalInstances::itemModelStateSerializer().isChecked(this); - } catch (...) { - return true; - } -} - -bool FallbackPersonCollection::load() -{ - new ThreadWorker([this]() { - bool ok; - Q_UNUSED(ok) - QList< Person* > ret = VCardUtils::loadDir(QUrl(d_ptr->m_Path),ok,static_cast<FallbackPersonBackendEditor*>(editor<Person>())->m_hPaths); - for(Person* p : ret) { - p->setCollection(this); - editor<Person>()->addExisting(p); - } - }); - - //Add all sub directories as new backends - QTimer::singleShot(0,d_ptr,SLOT(loadAsync())); - - return true; -} - -bool FallbackPersonCollection::reload() -{ - return false; -} - -FlagPack<CollectionInterface::SupportedFeatures> FallbackPersonCollection::supportedFeatures() const -{ - return - CollectionInterface::SupportedFeatures::NONE | - CollectionInterface::SupportedFeatures::LOAD | - CollectionInterface::SupportedFeatures::CLEAR | - CollectionInterface::SupportedFeatures::MANAGEABLE | - CollectionInterface::SupportedFeatures::REMOVE | - CollectionInterface::SupportedFeatures::EDIT | - CollectionInterface::SupportedFeatures::ADD ; -} - -bool FallbackPersonCollection::clear() -{ - QDir dir(d_ptr->m_Path); - for (const QString& file : dir.entryList({"*.vcf"},QDir::Files)) - dir.remove(file); - return true; -} - -QByteArray FallbackPersonCollection::id() const -{ - return "fpc2"+d_ptr->m_Path.toLatin1(); -} - - -void FallbackPersonCollectionPrivate::loadAsync() -{ - QDir d(m_Path); - for (const QString& dir : d.entryList(QDir::AllDirs)) { - if (dir != QString('.') && dir != "..") { - CollectionInterface* col = PersonModel::instance().addCollection<FallbackPersonCollection,QString,FallbackPersonCollection*>(m_Path+'/'+dir,q_ptr); - if (col->isEnabled()) { - col->load(); - } - } - } -} - -#include "fallbackpersoncollection.moc" diff --git a/src/fallbackpersoncollection.h b/src/fallbackpersoncollection.h deleted file mode 100644 index 48b47d5b..00000000 --- a/src/fallbackpersoncollection.h +++ /dev/null @@ -1,59 +0,0 @@ -/************************************************************************************ - * Copyright (C) 2014-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 Lesser General Public * - * License along with this library; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***********************************************************************************/ -#pragma once - -#include <collectioninterface.h> -#include <typedefs.h> - -class Call; -class Person; -class FallbackPersonCollectionPrivate; - -template<typename T> class CollectionMediator; - -/** - * This class is used when no other Person collections are available. It will - * provide a basic collection to add and use Persons/Contacts. It is also - * necessary as some metadata required for elements such as auto completion are - * provided by the Person collections. - */ -class LIB_EXPORT FallbackPersonCollection : public CollectionInterface -{ -public: - explicit FallbackPersonCollection(CollectionMediator<Person>* mediator, const QString& path = QString(), FallbackPersonCollection* parent = nullptr); - virtual ~FallbackPersonCollection(); - - virtual bool load () override; - virtual bool reload() override; - virtual bool clear () override; - - virtual QString name () const override; - virtual QString category () const override; - virtual QVariant icon () const override; - virtual bool isEnabled() const override; - virtual QByteArray id () const override; - - virtual FlagPack<SupportedFeatures> supportedFeatures() const override; - -private: - FallbackPersonCollectionPrivate* d_ptr; - Q_DECLARE_PRIVATE(FallbackPersonCollection) -}; -Q_DECLARE_METATYPE(FallbackPersonCollection*) - diff --git a/src/foldercertificatecollection.h b/src/foldercertificatecollection.h deleted file mode 100644 index b6d51f7a..00000000 --- a/src/foldercertificatecollection.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 <collectioninterface.h> -#include <typedefs.h> - -class FolderCertificateCollectionPrivate; -class Certificate; - -template<typename T> class CollectionMediator; - -/** - * This class provide a fallback storage container for certificates used - * locally by LibRingClient. If the platform have a certificate hosting facility, - * it is strongly encourages to use it rather than this. - */ -class LIB_EXPORT FolderCertificateCollection : public CollectionInterface -{ - friend class BackgroundLoader; - -public: - ///@enum Options load and behavior parameters for a FolderCertificateCollection - enum class Options { - READ_WRITE = 0 << 0, /*!< Try to add certificates to that store (default) */ - READ_ONLY = 1 << 0, /*!< Do not try to add certificate to that store */ - RECURSIVE = 1 << 1, /*!< Read all sub-folders recursively */ - ROOT = 1 << 2, /*!< Consider those certificates as top-level entities */ - FALLBACK = 1 << 3, /*!< Consider this folder the default destination for volatile certificates */ - }; - - explicit FolderCertificateCollection(CollectionMediator<Certificate>* mediator, - const QString& path = QString(), - const FlagPack<Options>& options = Options::READ_WRITE, - const QString& name = QString(), - FolderCertificateCollection* parent = nullptr - ); - - virtual ~FolderCertificateCollection(); - - //Re-implementation - virtual bool load () override; - virtual bool reload() override; - virtual bool clear () override; - - virtual QString name () const override; - virtual QString category () const override; - virtual QVariant icon () const override; - virtual bool isEnabled() const override; - virtual QByteArray id () const override; - virtual QList<Element> listId () const override; - virtual bool listId (std::function<void(const QList<Element>)> callback) const override; - virtual FlagPack<SupportedFeatures> supportedFeatures() const override; - - //Getter - QUrl path() const; - -private: - FolderCertificateCollectionPrivate* d_ptr; - Q_DECLARE_PRIVATE(FolderCertificateCollection) -}; -Q_DECLARE_METATYPE(FolderCertificateCollection*) -DECLARE_ENUM_FLAGS(FolderCertificateCollection::Options) diff --git a/src/globalinstances.cpp b/src/globalinstances.cpp index a1413783..f2455160 100644 --- a/src/globalinstances.cpp +++ b/src/globalinstances.cpp @@ -23,15 +23,11 @@ #include "interfaces/dbuserrorhandleri.h" #include "interfaces/itemmodelstateserializeri.h" #include "interfaces/pixmapmanipulatori.h" -#include "interfaces/presenceserializeri.h" #include "interfaces/shortcutcreatori.h" -#include "interfaces/actionextenderi.h" #include "dbuserrorhandlerdefault.h" #include "pixmapmanipulatordefault.h" -#include "presenceserializerdefault.h" #include "shortcutcreatordefault.h" -#include "actionextenderdefault.h" namespace GlobalInstances { @@ -41,9 +37,7 @@ struct InstanceManager std::unique_ptr<Interfaces::DBusErrorHandlerI> m_dBusErrorHandler; std::unique_ptr<Interfaces::ItemModelStateSerializerI> m_itemModelStateSerializer; std::unique_ptr<Interfaces::PixmapManipulatorI> m_pixmapManipulator; - std::unique_ptr<Interfaces::PresenceSerializerI> m_presenceSerializer; std::unique_ptr<Interfaces::ShortcutCreatorI> m_shortcutCreator; - std::unique_ptr<Interfaces::ActionExtenderI> m_actionExtender; }; static InstanceManager& @@ -136,25 +130,6 @@ setPixmapManipulator(std::unique_ptr<Interfaces::PixmapManipulatorI> instance) instanceManager().m_pixmapManipulator = std::move(instance); } -Interfaces::PresenceSerializerI& -presenceSerializer() -{ - if (!instanceManager().m_presenceSerializer) - instanceManager().m_presenceSerializer.reset(new Interfaces::PresenceSerializerDefault); - return *instanceManager().m_presenceSerializer.get(); -} - -void -setPresenceSerializer(std::unique_ptr<Interfaces::PresenceSerializerI> instance) -{ - // do not allow empty pointers - if (!instance) { - qWarning() << "ignoring empty unique_ptr"; - return; - } - instanceManager().m_presenceSerializer = std::move(instance); -} - Interfaces::ShortcutCreatorI& shortcutCreator() { @@ -174,25 +149,6 @@ setShortcutCreator(std::unique_ptr<Interfaces::ShortcutCreatorI> instance) instanceManager().m_shortcutCreator = std::move(instance); } -Interfaces::ActionExtenderI& -actionExtender() -{ - if (!instanceManager().m_shortcutCreator) - instanceManager().m_actionExtender.reset(new Interfaces::ActionExtenderDefault); - return *instanceManager().m_actionExtender.get(); -} - -void -setActionExtender(std::unique_ptr<Interfaces::ActionExtenderI> instance) -{ - // do not allow empty pointers - if (!instance) { - qWarning() << "ignoring empty unique_ptr"; - return; - } - instanceManager().m_actionExtender = std::move(instance); -} - /* * This API have some advantage over a more "explicit" one @@ -218,9 +174,7 @@ REGISTER_INTERFACE(Interfaces::ContactMethodSelectorI , m_contactMethodSelecto REGISTER_INTERFACE(Interfaces::DBusErrorHandlerI , m_dBusErrorHandler ) REGISTER_INTERFACE(Interfaces::ItemModelStateSerializerI, m_itemModelStateSerializer) REGISTER_INTERFACE(Interfaces::PixmapManipulatorI , m_pixmapManipulator ) -REGISTER_INTERFACE(Interfaces::PresenceSerializerI , m_presenceSerializer ) REGISTER_INTERFACE(Interfaces::ShortcutCreatorI , m_shortcutCreator ) -REGISTER_INTERFACE(Interfaces::ActionExtenderI , m_actionExtender ) #pragma GCC diagnostic pop diff --git a/src/globalinstances.h b/src/globalinstances.h index 0276557a..dd54dfb7 100644 --- a/src/globalinstances.h +++ b/src/globalinstances.h @@ -26,9 +26,7 @@ class ContactMethodSelectorI; class DBusErrorHandlerI; class ItemModelStateSerializerI; class PixmapManipulatorI; -class PresenceSerializerI; class ShortcutCreatorI; -class ActionExtenderI; } // namespace Interfaces /** @@ -61,25 +59,16 @@ void LIB_EXPORT setItemModelStateSerializer(std::unique_ptr<Interfaces::ItemMode LIB_EXPORT Interfaces::PixmapManipulatorI& pixmapManipulator(); void LIB_EXPORT setPixmapManipulator(std::unique_ptr<Interfaces::PixmapManipulatorI> instance); -LIB_EXPORT Interfaces::PresenceSerializerI& presenceSerializer(); -void LIB_EXPORT setPresenceSerializer(std::unique_ptr<Interfaces::PresenceSerializerI> instance); - LIB_EXPORT Interfaces::ShortcutCreatorI& shortcutCreator(); void LIB_EXPORT setShortcutCreator(std::unique_ptr<Interfaces::ShortcutCreatorI> instance); -LIB_EXPORT Interfaces::ActionExtenderI& actionExtender(); -void LIB_EXPORT setActionExtender(std::unique_ptr<Interfaces::ActionExtenderI> instance); - - //Private use only void setInterfaceInternal(Interfaces::ContactMethodSelectorI *); void setInterfaceInternal(Interfaces::DBusErrorHandlerI *); void setInterfaceInternal(Interfaces::ItemModelStateSerializerI*); void setInterfaceInternal(Interfaces::PixmapManipulatorI *); -void setInterfaceInternal(Interfaces::PresenceSerializerI *); void setInterfaceInternal(Interfaces::ShortcutCreatorI *); -void setInterfaceInternal(Interfaces::ActionExtenderI *); /** * Generic interface setter. This metamethod can set any type of interface diff --git a/src/historytimecategorymodel.h b/src/historytimecategorymodel.h deleted file mode 100644 index 94385e8f..00000000 --- a/src/historytimecategorymodel.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2012-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 <time.h> - -#include <QtCore/QAbstractListModel> -#include <QtCore/QVector> -#include <QtCore/QString> - -class HistoryTimeCategoryModelPrivate; - -class LIB_EXPORT HistoryTimeCategoryModel : public QAbstractListModel { - Q_OBJECT -public: - ///@enum HistoryConst: History categories - enum class HistoryConst : int { - Today = 0 , - Yesterday = 1 , - Two_days_ago = 2 , - Three_days_ago = 3 , - Four_days_ago = 4 , - Five_days_ago = 5 , - Six_days_ago = 6 , - A_week_ago = 7 , - Two_weeks_ago = 8 , - Three_weeks_ago = 9 , - A_month_ago = 10 , - Two_months_ago = 11 , - Three_months_ago = 12 , - Four_months_ago = 13 , - Five_months_ago = 14 , - Six_months_ago = 15 , - Seven_months_ago = 16 , - Eight_months_ago = 17 , - Nine_months_ago = 18 , - Ten_months_ago = 19 , - Eleven_months_ago = 20 , - Twelve_months_ago = 21 , - A_year_ago = 22 , - Very_long_time_ago= 23 , - Never = 24 , - }; - Q_ENUMS(HistoryConst) - - //Constructor - explicit HistoryTimeCategoryModel(QObject* parent = nullptr); - virtual ~HistoryTimeCategoryModel(); - - //Abstract model member - virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole ) const override; - virtual int rowCount(const QModelIndex& parent = QModelIndex() ) const override; - virtual Qt::ItemFlags flags (const QModelIndex& index ) const override; - virtual bool setData (const QModelIndex& index, const QVariant &value, int role) override; - virtual QHash<int,QByteArray> roleNames() const override; - - //Getters - static QString indexToName(int idx); - - //Helpers - static HistoryConst timeToHistoryConst (const time_t time); - static QString timeToHistoryCategory(const time_t time); - -private: - HistoryTimeCategoryModelPrivate* d_ptr; - Q_DECLARE_PRIVATE(HistoryTimeCategoryModel) -}; -Q_DECLARE_METATYPE(HistoryTimeCategoryModel::HistoryConst) -Q_DECLARE_METATYPE(HistoryTimeCategoryModel*) diff --git a/src/interfaces/actionextenderi.h b/src/interfaces/actionextenderi.h deleted file mode 100644 index 39ba0c31..00000000 --- a/src/interfaces/actionextenderi.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2016 by Emmanuel Lepage Vallee * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 - -// Qt -#include <QtCore/QVariant> - -#include <typedefs.h> - -class Account; -class Person; -class ContactMethod; -class Call; - -namespace Interfaces { - -///Interface for extra User Action Model actions -class ActionExtenderI { -public: - ///Hint the implementation how to sort/filter the persons - enum class SelectPersonHint { - NONE = 0x0 << 0 - // Will be used eventually, let's avoid breaking the API - }; - - ///Hint the implementation how to sort/filter the contact methods - enum class SelectContactMethodHint { - NONE = 0x0 << 0, - RECENT = 0x1 << 0, - WITHOUT_PERSON = 0x1 << 1, - }; - - virtual ~ActionExtenderI() = default; - - virtual void editPerson(Person* p) = 0; - virtual void viewChatHistory(ContactMethod* cm) = 0; - virtual void viewChatHistory(Person* p) = 0; - virtual void copyInformation(QMimeData* data) = 0; - virtual bool warnDeletePerson(Person* p) = 0; - virtual bool warnDeleteCall(Call* c) = 0; - virtual Person* selectPerson(FlagPack<SelectPersonHint> hints = SelectPersonHint::NONE, const QVariant& hintVar = {}) const = 0; - virtual ContactMethod* selectContactMethod(FlagPack<SelectContactMethodHint> hints = SelectContactMethodHint::NONE, const QVariant& hintVar = {}) const = 0; -}; - -} // namespace Interfaces - -DECLARE_ENUM_FLAGS(Interfaces::ActionExtenderI::SelectContactMethodHint) -DECLARE_ENUM_FLAGS(Interfaces::ActionExtenderI::SelectPersonHint ) \ No newline at end of file diff --git a/src/interfaces/pixmapmanipulatori.h b/src/interfaces/pixmapmanipulatori.h index d0bdd7f9..100562a4 100644 --- a/src/interfaces/pixmapmanipulatori.h +++ b/src/interfaces/pixmapmanipulatori.h @@ -26,8 +26,6 @@ class QByteArray ; //Ring #include <securityevaluationmodel.h> -#include <categorizedcontactmodel.h> -#include <categorizedhistorymodel.h> class Person ; class ContactMethod ; @@ -87,8 +85,6 @@ public: virtual QVariant personPhoto(const QByteArray& data, const QString& type = "PNG") = 0; virtual QVariant collectionIcon(const CollectionInterface* colItf, PixmapManipulatorI::CollectionIconHint hint = PixmapManipulatorI::CollectionIconHint::NONE) const = 0; virtual QVariant securityLevelIcon(const SecurityEvaluationModel::SecurityLevel level) const = 0; - virtual QVariant historySortingCategoryIcon(const CategorizedHistoryModel::SortedProxy::Categories cat) const = 0; - virtual QVariant contactSortingCategoryIcon(const CategorizedContactModel::SortedProxy::Categories cat) const = 0; virtual QVariant decorationRole(const QModelIndex& index) = 0; virtual QVariant decorationRole(const Call* c ) = 0; virtual QVariant decorationRole(const ContactMethod* cm ) = 0; diff --git a/src/interfaces/presenceserializeri.h b/src/interfaces/presenceserializeri.h deleted file mode 100644 index 1afdc638..00000000 --- a/src/interfaces/presenceserializeri.h +++ /dev/null @@ -1,35 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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> - -class CollectionInterface; - -namespace Interfaces { - -class PresenceSerializerI { -public: - virtual ~PresenceSerializerI() = default; - virtual void save () = 0; - virtual void load () = 0; - virtual bool isTracked(CollectionInterface* backend) const = 0; - virtual void setTracked(CollectionInterface* backend, bool tracked) = 0; -}; - -} // namespace Interfaces diff --git a/src/itemdataroles.h b/src/itemdataroles.h index f26a5797..5009282f 100644 --- a/src/itemdataroles.h +++ b/src/itemdataroles.h @@ -64,7 +64,6 @@ enum class ObjectType Call, Media, Certificate, - ContactRequest, COUNT__ }; diff --git a/src/localprofilecollection.h b/src/localprofilecollection.h deleted file mode 100644 index 423db004..00000000 --- a/src/localprofilecollection.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016-2019 Savoir-faire Linux Inc. * - * Author : Alexandre Lision <alexandre.lision@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 "collectioninterface.h" -#include "collectioneditor.h" - -class Profile; - -template<typename T> class CollectionMediator; - -class LIB_EXPORT LocalProfileCollection : public CollectionInterface -{ -public: - explicit LocalProfileCollection(CollectionMediator<Profile>* mediator); - virtual ~LocalProfileCollection(); - - virtual bool load () override; - virtual bool reload() override; - virtual bool clear () override; - - virtual QString name () const override; - virtual QString category () const override; - virtual QVariant icon () const override; - virtual bool isEnabled() const override; - virtual QByteArray id () const override; - - virtual FlagPack<SupportedFeatures> supportedFeatures() const override; - -private: - void setupDefaultProfile(); -}; diff --git a/src/localringtonecollection.h b/src/localringtonecollection.h deleted file mode 100644 index f23e3fe5..00000000 --- a/src/localringtonecollection.h +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 <collectioninterface.h> - -class Ringtone; - -class LocalRingtoneCollectionPrivate; - -class LIB_EXPORT LocalRingtoneCollection : public CollectionInterface -{ -public: - explicit LocalRingtoneCollection(CollectionMediator<Ringtone>* mediator); - virtual ~LocalRingtoneCollection(); - - virtual bool load () override; - virtual bool reload() override; - virtual bool clear () override; - - virtual QString name () const override; - virtual QString category () const override; - virtual QVariant icon () const override; - virtual bool isEnabled() const override; - virtual QByteArray id () const override; - - virtual FlagPack<SupportedFeatures> supportedFeatures() const override; - -private: - LocalRingtoneCollectionPrivate* d_ptr; - Q_DECLARE_PRIVATE(LocalRingtoneCollection) -}; - diff --git a/src/media/avrecording.cpp b/src/media/avrecording.cpp index 18273756..b1d8be21 100644 --- a/src/media/avrecording.cpp +++ b/src/media/avrecording.cpp @@ -81,7 +81,7 @@ public Q_SLOTS: void slotUpdatePlaybackScale (const QString& filepath, int position, int size); }; -RecordingPlaybackManager::RecordingPlaybackManager() : QObject(&CallModel::instance()) +RecordingPlaybackManager::RecordingPlaybackManager() : QObject() { CallManagerInterface& callManager = CallManager::instance(); connect(&callManager,&CallManagerInterface::recordPlaybackStopped , this, &RecordingPlaybackManager::slotRecordPlaybackStopped ); diff --git a/src/media/media.h b/src/media/media.h index 8480a5f8..97b40728 100644 --- a/src/media/media.h +++ b/src/media/media.h @@ -22,7 +22,6 @@ #include "typedefs.h" class Call; -class CallModelPrivate; namespace media { class MediaPrivate; @@ -33,7 +32,6 @@ namespace media { class LIB_EXPORT Media : public QObject { Q_OBJECT - friend class ::CallModelPrivate; public: enum class Type { AUDIO = 0, /*!< */ diff --git a/src/media/recordingmodel.cpp b/src/media/recordingmodel.cpp index ec74038f..df46c6b1 100644 --- a/src/media/recordingmodel.cpp +++ b/src/media/recordingmodel.cpp @@ -24,9 +24,7 @@ //Ring #include "recording.h" -#include "textrecording.h" #include "media.h" -#include "localtextrecordingcollection.h" //DRing #include "dbus/configurationmanager.h" @@ -64,7 +62,6 @@ public: QVector<RecordingNode*> m_lCategories ; RecordingNode* m_pText {nullptr}; RecordingNode* m_pAudioVideo {nullptr}; - LocalTextRecordingCollection* m_pTextRecordingCollection; int m_UnreadCount { 0 }; //RecordingNode* m_pFiles ; //TODO uncomment when implemented in DRing @@ -96,9 +93,6 @@ m_pAudioVideo(nullptr)/*,m_pFiles(nullptr)*/ RecordingModelPrivate::~RecordingModelPrivate() { - if (m_pTextRecordingCollection) - delete m_pTextRecordingCollection; - if (m_pText) delete m_pText; @@ -110,7 +104,6 @@ void RecordingModelPrivate::forwardInsertion(const QMap<QString,QString>& messag { Q_UNUSED(message) Q_UNUSED(direction) - emit q_ptr->newTextMessage(static_cast<media::TextRecording*>(sender()), cm); } void RecordingModelPrivate::updateUnreadCount(const int count) @@ -131,13 +124,6 @@ media::RecordingModel::RecordingModel(QObject* parent) : QAbstractItemModel(pare d_ptr(new RecordingModelPrivate(this)) { setObjectName("RecordingModel"); - - d_ptr->m_pTextRecordingCollection = addCollection<LocalTextRecordingCollection>(LoadOptions::NONE); - - d_ptr->m_pTextRecordingCollection->listId([](const QList<CollectionInterface::Element>& e) { - //TODO - Q_UNUSED(e); - }); } media::RecordingModel& media::RecordingModel::instance() @@ -293,12 +279,6 @@ bool media::RecordingModel::addItemCallback(const Recording* item) endInsertRows(); - if (item->type() == Recording::Type::TEXT) { - const TextRecording* r = static_cast<const TextRecording*>(item); - connect(r, &TextRecording::messageInserted, d_ptr, &RecordingModelPrivate::forwardInsertion); - connect(r, &TextRecording::unreadCountChange, d_ptr, &RecordingModelPrivate::updateUnreadCount); - } - return true; } @@ -365,12 +345,4 @@ int media::RecordingModel::unreadCount() const return d_ptr->m_UnreadCount; } -///Create or load the recording associated with the ContactMethod cm -media::TextRecording* media::RecordingModel::createTextRecording(const ContactMethod* cm) -{ - TextRecording* r = d_ptr->m_pTextRecordingCollection->createFor(cm); - - return r; -} - #include <recordingmodel.moc> diff --git a/src/media/recordingmodel.h b/src/media/recordingmodel.h index 1aa251ed..4f0ed990 100644 --- a/src/media/recordingmodel.h +++ b/src/media/recordingmodel.h @@ -32,7 +32,6 @@ class ContactMethod; namespace media { class Recording; - class TextRecording; class AVRecording; /** @@ -80,14 +79,10 @@ public: void setRecordPath ( const QString& path ); void clear ( ); - //Mutator - TextRecording* createTextRecording(const ContactMethod* cm); - //Singleton static RecordingModel& instance(); Q_SIGNALS: - void newTextMessage(::media::TextRecording* t, ContactMethod* cm); void unreadMessagesCountChanged(int unreadCount); private: diff --git a/src/media/text.cpp b/src/media/text.cpp index e0bbb922..0020c37a 100644 --- a/src/media/text.cpp +++ b/src/media/text.cpp @@ -24,17 +24,14 @@ //Ring #include <call.h> -#include <callmodel.h> #include <account.h> #include <person.h> #include <contactmethod.h> #include <mime.h> -#include <media/textrecording.h> #include <media/recordingmodel.h> #include <phonedirectorymodel.h> #include <private/call_p.h> #include <private/vcardutils.h> -#include <private/textrecording_p.h> #include <private/imconversationmanagerprivate.h> #include <accountmodel.h> #include <personmodel.h> @@ -62,7 +59,6 @@ public: MediaTextPrivate(media::Text* parent); //Attributes - media::TextRecording* m_pRecording; bool m_HasChecked; QHash<QString,bool> m_hMimeTypes; QStringList m_lMimeTypes; @@ -140,60 +136,18 @@ Person* ProfileChunk::addChunk(const QMap<QString, QString>& args, const QString ///Called when a new message is incoming void IMConversationManagerPrivate::newMessage(const QString& callId, const QString& from, const QMap<QString,QString>& message) { - Q_UNUSED(from) - - auto call = CallModel::instance().getCall(callId); - if (!call or !call->peerContactMethod()) { - return; - } - - static const int profileSize = QString(RingMimes::PROFILE_VCF).size(); - - //Intercept some messages early, those are intended for internal Ring usage - QMapIterator<QString, QString> iter(message); - while (iter.hasNext()) { - iter.next(); - - if (iter.key().left(profileSize) == RingMimes::PROFILE_VCF) { - auto args = VCardUtils::parseMimeAttributes(iter.key()); - if (auto person = ProfileChunk::addChunk(args, iter.value(), call->peerContactMethod())) { - PersonModel::instance().addPeerProfile(person); - } - return; - } - } - - media::Text* media = call->firstMedia<media::Text>(media::Media::Direction::IN); - - if (!media) { - media = call->d_ptr->mediaFactory<media::Text>(media::Media::Direction::IN); - } - - media->recording()->setCall(call); - media->recording()->d_ptr->insertNewMessage(message,call->peerContactMethod(),media::Media::Direction::IN); - - media->d_ptr->updateMimeList(message); - - emit media->messageReceived(message); + return; } void IMConversationManagerPrivate::newAccountMessage(const QString& accountId, const QString& from, const QMap<QString,QString>& payloads) { - if (auto cm = PhoneDirectoryModel::instance().getNumber(from, AccountModel::instance().getById(accountId.toLatin1()))) { - auto txtRecording = cm->textRecording(); - txtRecording->d_ptr->insertNewMessage(payloads, cm, media::Media::Direction::IN); - } } void IMConversationManagerPrivate::accountMessageStatusChanged(const QString& accountId, uint64_t id, const QString& to, int status) { - if (auto cm = PhoneDirectoryModel::instance().getNumber(to, AccountModel::instance().getById(accountId.toLatin1()))) { - auto txtRecording = cm->textRecording(); - txtRecording->d_ptr->accountMessageStatusChanged(id, static_cast<DRing::Account::MessageStates>(status)); - } } -MediaTextPrivate::MediaTextPrivate(media::Text* parent) : q_ptr(parent),m_pRecording(nullptr),m_HasChecked(false) +MediaTextPrivate::MediaTextPrivate(media::Text* parent) : q_ptr(parent),m_HasChecked(false) { } @@ -212,32 +166,6 @@ media::Text::~Text() delete d_ptr; } -media::TextRecording* media::Text::recording() const -{ - const bool wasChecked = d_ptr->m_HasChecked; - d_ptr->m_HasChecked = true; - - if ((!wasChecked) && !d_ptr->m_pRecording) { - Text* other = call()->firstMedia<Text>(direction() == Media::Direction::OUT ? - Media::Direction::IN - : Media::Direction::OUT - ); - - if (other && other->recording()) - d_ptr->m_pRecording = other->recording(); - - } - - if ((!wasChecked) && !d_ptr->m_pRecording) { - if (auto otherRecording = call()->peerContactMethod()->textRecording()) - d_ptr->m_pRecording = otherRecording; - else - d_ptr->m_pRecording = RecordingModel::instance().createTextRecording(call()->peerContactMethod()); - } - - return d_ptr->m_pRecording; -} - bool media::Text::hasMimeType( const QString& mimeType ) const { @@ -296,12 +224,6 @@ void media::Text::send(const QMap<QString,QString>& message, const bool isMixed) CallManagerInterface& callManager = CallManager::instance(); Q_NOREPLY callManager.sendTextMessage(call()->dringId(), message, isMixed); - //Make sure the recording exist - recording(); - - d_ptr->m_pRecording->setCall(call()); - d_ptr->m_pRecording->d_ptr->insertNewMessage(message,call()->peerContactMethod(),Media::Direction::OUT); - d_ptr->updateMimeList(message); emit messageSent(message); diff --git a/src/media/text.h b/src/media/text.h index 35fe12a7..7f113960 100644 --- a/src/media/text.h +++ b/src/media/text.h @@ -28,8 +28,6 @@ class IMConversationManagerPrivate; namespace media { -class TextRecording; - class LIB_EXPORT Text : public media::Media { Q_OBJECT @@ -40,7 +38,6 @@ public: virtual Media::Type type() override; //Getter - TextRecording* recording ( ) const; bool hasMimeType ( const QString& mimeType ) const; QStringList mimeTypes ( ) const; @@ -60,4 +57,3 @@ Q_SIGNALS: }; } - diff --git a/src/networkinterfacemodel.cpp b/src/networkinterfacemodel.cpp deleted file mode 100644 index 08eb320f..00000000 --- a/src/networkinterfacemodel.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "networkinterfacemodel.h" - -//Qt -#include <QtCore/QCoreApplication> -#include <QtCore/QItemSelectionModel> - -//Ring daemon -#include <account_const.h> - -//Ring -#include "dbus/configurationmanager.h" -#include "account.h" - -class NetworkInterfaceModelPrivate final : public QObject { - Q_OBJECT -public: - NetworkInterfaceModelPrivate(NetworkInterfaceModel*); - QStringList m_Interfaces; - QItemSelectionModel* m_pSelectionModel; - Account* m_pAccount; - - //Helper - QString localInterface() const; - void setLocalInterface(const QString& detail); - -public Q_SLOTS: - void slotSelectionChanged(const QModelIndex& idx, const QModelIndex& prev); - -private: - NetworkInterfaceModel* q_ptr; -}; - -NetworkInterfaceModelPrivate::NetworkInterfaceModelPrivate(NetworkInterfaceModel* parent): QObject(parent),q_ptr(parent),m_pSelectionModel(nullptr),m_pAccount(nullptr) -{ -} - -NetworkInterfaceModel::NetworkInterfaceModel(Account* a) : QAbstractListModel(QCoreApplication::instance()), -d_ptr(new NetworkInterfaceModelPrivate(this)) -{ - //TODO get updates from the daemon - d_ptr->m_pAccount = a; - d_ptr->m_Interfaces = ConfigurationManager::instance().getAllIpInterfaceByName(); -} - -NetworkInterfaceModel::~NetworkInterfaceModel() -{ - delete d_ptr; -} - -QHash<int,QByteArray> NetworkInterfaceModel::roleNames() const -{ - static QHash<int, QByteArray> roles = QAbstractItemModel::roleNames(); - /*static bool initRoles = false; - if (!initRoles) { - initRoles = true; - - }*/ - return roles; -} - -///Return the account local interface -QString NetworkInterfaceModelPrivate::localInterface() const -{ - return m_pAccount->accountDetail(DRing::Account::ConfProperties::LOCAL_INTERFACE); -} - -///Set the local interface -void NetworkInterfaceModelPrivate::setLocalInterface(const QString& detail) -{ - m_pAccount->setAccountProperty(DRing::Account::ConfProperties::LOCAL_INTERFACE, detail); -} - -//Model functions -QVariant NetworkInterfaceModel::data( const QModelIndex& index, int role) const -{ - if (role == Qt::DisplayRole) - return d_ptr->m_Interfaces[index.row()]; - return QVariant(); -} - -int NetworkInterfaceModel::rowCount( const QModelIndex& parent ) const -{ - return parent.isValid()?0:d_ptr->m_Interfaces.size(); -} - -Qt::ItemFlags NetworkInterfaceModel::flags( const QModelIndex& index ) const -{ - if (!index.isValid()) return Qt::NoItemFlags; - return Qt::ItemIsEnabled|Qt::ItemIsSelectable; -} - -bool NetworkInterfaceModel::setData( const QModelIndex& index, const QVariant &value, int role) -{ - Q_UNUSED(index) - Q_UNUSED(value) - Q_UNUSED(role ) - return false; -} - -void NetworkInterfaceModelPrivate::slotSelectionChanged(const QModelIndex& idx, const QModelIndex& prev) -{ - Q_UNUSED(prev) - setLocalInterface(idx.data(Qt::DisplayRole).toString()); -} - -QItemSelectionModel* NetworkInterfaceModel::selectionModel() const -{ - if (!d_ptr->m_pSelectionModel) { - d_ptr->m_pSelectionModel = new QItemSelectionModel(const_cast<NetworkInterfaceModel*>(this)); - - const QString currentInterface = d_ptr->localInterface(); - int idx = d_ptr->m_Interfaces.indexOf(currentInterface); - - //Some interfaces could be currently disconnected - if (idx == -1) { - idx = d_ptr->m_Interfaces.size(); - - const_cast<NetworkInterfaceModel*>(this)->beginInsertRows(QModelIndex(), idx, idx); - d_ptr->m_Interfaces << currentInterface; - const_cast<NetworkInterfaceModel*>(this)->endInsertRows(); - } - d_ptr->m_pSelectionModel->setCurrentIndex(index(idx,0), QItemSelectionModel::ClearAndSelect); - - connect(d_ptr->m_pSelectionModel, &QItemSelectionModel::currentChanged, d_ptr, &NetworkInterfaceModelPrivate::slotSelectionChanged); - } - - return d_ptr->m_pSelectionModel; -} - -///Translate enum type to QModelIndex -// QModelIndex NetworkInterfaceModel::toIndex(NetworkInterfaceModel::Type type) -// { -// return index(static_cast<int>(type),0,QModelIndex()); -// } - - -#include <networkinterfacemodel.moc> diff --git a/src/networkinterfacemodel.h b/src/networkinterfacemodel.h deleted file mode 100644 index 532ac103..00000000 --- a/src/networkinterfacemodel.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 <QtCore/QAbstractListModel> - -//Qt -class QItemSelectionModel; - -//Ring -class NetworkInterfaceModelPrivate; -class Account; - -///Static model for handling encryption types -class LIB_EXPORT NetworkInterfaceModel : public QAbstractListModel { - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" - Q_OBJECT - #pragma GCC diagnostic pop - - friend class Account; - -public: - - //Model functions - virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const override; - virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const override; - virtual Qt::ItemFlags flags ( const QModelIndex& index ) const override; - virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) override; - virtual QHash<int,QByteArray> roleNames() const override; - - //Getter - QItemSelectionModel* selectionModel() const; - -private: - - //Private constructor, can only be called by 'Account' - explicit NetworkInterfaceModel(Account* a); - virtual ~NetworkInterfaceModel(); - - NetworkInterfaceModelPrivate* d_ptr; - Q_DECLARE_PRIVATE(NetworkInterfaceModel) - -}; -Q_DECLARE_METATYPE(NetworkInterfaceModel*) - diff --git a/src/newaccountmodel.cpp b/src/newaccountmodel.cpp index c3045d5d..4b508f91 100644 --- a/src/newaccountmodel.cpp +++ b/src/newaccountmodel.cpp @@ -43,8 +43,7 @@ // old LRC #include "accountmodel.h" -#include "profilemodel.h" -#include "profile.h" +#include "api/profile.h" #include "qtwrapper/conversions_wrap.hpp" // Dbus @@ -123,11 +122,6 @@ public Q_SLOTS: */ void slotAccountDetailsChanged(const std::string& accountID, const std::map<std::string, std::string>& details); - /** - * @param profile - */ - void slotProfileUpdated(const Profile* profile); - /** * Emit nameRegistrationEnded * @param accountId @@ -352,9 +346,6 @@ NewAccountModelPimpl::NewAccountModelPimpl(NewAccountModel& linked, connect(&callbacksHandler, &CallbacksHandler::nameRegistrationEnded, this, &NewAccountModelPimpl::slotNameRegistrationEnded); connect(&callbacksHandler, &CallbacksHandler::registeredNameFound, this, &NewAccountModelPimpl::slotRegisteredNameFound); connect(&callbacksHandler, &CallbacksHandler::migrationEnded, this, &NewAccountModelPimpl::slotMigrationEnded); - - // NOTE: because we still use the legacy LRC for configuration, we are still using old signals - connect(&ProfileModel::instance(), &ProfileModel::profileUpdated, this, &NewAccountModelPimpl::slotProfileUpdated); } NewAccountModelPimpl::~NewAccountModelPimpl() @@ -621,14 +612,6 @@ NewAccountModelPimpl::removeFromAccounts(const std::string& accountId) accounts.erase(accountId); } -void -NewAccountModelPimpl::slotProfileUpdated(const Profile* profile) -{ - auto& accounts = profile->accounts(); - if (!accounts.empty()) - emit linked.profileUpdated(accounts.first()->id().toStdString()); -} - void account::Info::fromDetails(const MapStringString& details) { diff --git a/src/peerprofilecollection.h b/src/peerprofilecollection.h deleted file mode 100644 index f7a16788..00000000 --- a/src/peerprofilecollection.h +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2016-2019 Savoir-faire Linux Inc. * - * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>* - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program 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 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 "collectioninterface.h" -#include "collectioneditor.h" - -class Person; - -template<typename T> class CollectionMediator; - -class LIB_EXPORT PeerProfileCollection : public CollectionInterface -{ -public: - explicit PeerProfileCollection(CollectionMediator<Person>* mediator); - virtual ~PeerProfileCollection(); - - virtual bool load () override; - virtual bool reload() override; - virtual bool clear () override; - - virtual QString name () const override; - virtual QString category () const override; - virtual QVariant icon () const override; - virtual bool isEnabled() const override; - virtual QByteArray id () const override; - - virtual FlagPack<SupportedFeatures> supportedFeatures() const override; - -}; diff --git a/src/person.cpp b/src/person.cpp index ea817235..c1bc43ba 100644 --- a/src/person.cpp +++ b/src/person.cpp @@ -31,13 +31,11 @@ #include "account.h" #include "private/vcardutils.h" #include "personmodel.h" -#include "historytimecategorymodel.h" #include "numbercategorymodel.h" #include "numbercategory.h" #include "globalinstances.h" #include "interfaces/pixmapmanipulatori.h" #include "private/person_p.h" -#include "media/textrecording.h" #include "mime.h" // Std @@ -186,7 +184,6 @@ void PersonPrivate::registerContactMethod(ContactMethod* m) { m_HiddenContactMethods << m; connect(m, &ContactMethod::lastUsedChanged, this, &PersonPrivate::slotLastUsedTimeChanged); - connect(m, &ContactMethod::callAdded, this, &PersonPrivate::slotCallAdded); if (m->lastUsed() > m_LastUsed) slotLastUsedTimeChanged(m->lastUsed()); @@ -379,7 +376,6 @@ void Person::setContactMethods(ContactMethods numbers) connect(n,SIGNAL(presentChanged(bool)),this,SLOT(slotPresenceChanged())); connect(n, &ContactMethod::lastUsedChanged, d_ptr, &PersonPrivate::slotLastUsedTimeChanged); connect(n, &ContactMethod::unreadTextMessageCountChanged, d_ptr, &PersonPrivate::changed); - connect(n, &ContactMethod::callAdded, d_ptr, &PersonPrivate::slotCallAdded); } d_ptr->phoneNumbersChanged(); @@ -568,12 +564,7 @@ bool Person::hasRecording(media::Media::Type type, media::Media::Direction direc case media::Media::Type::AUDIO: case media::Media::Type::VIDEO: return false; //TODO implement - case media::Media::Type::TEXT: - foreach( ContactMethod* cm, phoneNumbers()) { - if (cm->textRecording() && !cm->textRecording()->isEmpty()) - return true; - } - +case media::Media::Type::TEXT: return false; case media::Media::Type::FILE: case media::Media::Type::COUNT__: @@ -614,10 +605,10 @@ QVariant Person::roleData(int role) const return QVariant(preferredEmail()); case static_cast<int>(Ring::Role::FormattedLastUsed): case static_cast<int>(Person::Role::FormattedLastUsed): - return QVariant(HistoryTimeCategoryModel::timeToHistoryCategory(lastUsedTime())); + return QVariant(); case static_cast<int>(Ring::Role::IndexedLastUsed): case static_cast<int>(Person::Role::IndexedLastUsed): - return QVariant(static_cast<int>(HistoryTimeCategoryModel::timeToHistoryConst(lastUsedTime()))); + return QVariant(); case static_cast<int>(Ring::Role::Object): case static_cast<int>(Person::Role::Object): return QVariant::fromValue(const_cast<Person*>(this)); @@ -638,10 +629,6 @@ QVariant Person::roleData(int role) const case static_cast<int>(Ring::Role::UnreadTextMessageCount): { int unread = 0; - for (int i = 0; i < d_ptr->m_Numbers.size(); ++i) { - if (auto rec = d_ptr->m_Numbers.at(i)->textRecording()) - unread += rec->unreadInstantTextMessagingModel()->rowCount(); - } return unread; } break; diff --git a/src/phonedirectorymodel.cpp b/src/phonedirectorymodel.cpp index 53683a77..3ad61541 100644 --- a/src/phonedirectorymodel.cpp +++ b/src/phonedirectorymodel.cpp @@ -41,7 +41,6 @@ #include "personmodel.h" #include "dbus/configurationmanager.h" #include "media/recordingmodel.h" -#include "media/textrecording.h" //Private #include "private/phonedirectorymodel_p.h" @@ -464,21 +463,6 @@ ContactMethod* PhoneDirectoryModel::getNumber(const URI& uri, const QString& typ connect(number,&ContactMethod::contactChanged ,d_ptr.data(), &PhoneDirectoryModelPrivate::slotContactChanged); connect(number,&ContactMethod::rebased ,d_ptr.data(), &PhoneDirectoryModelPrivate::slotContactMethodMerged); - // add the new cm into the historic. - for (auto col : CategorizedHistoryModel::instance().collections(CollectionInterface::SupportedFeatures::ADD)) { - if (col->id() == "mhb") { - QMap<QString,QString> hc; - hc[Call::HistoryMapFields::PEER_NUMBER ] = number->uri(); - // it matters to set a value to hc[Call::HistoryMapFields::CALLID ], but the value itself doesn't matter - hc[Call::HistoryMapFields::CALLID ] = "0"; - - if (auto fakeCall = Call::buildHistoryCall(hc)) - col->add(fakeCall); - else - qDebug() << "buildHistoryCall() has returned an invalid Call object."; - } - } - const QString hn = number->uri().hostname(); emit layoutChanged(); @@ -955,10 +939,7 @@ QAbstractListModel* PhoneDirectoryModel::mostPopularNumberModel() const bool PhoneDirectoryModel::hasUnreadMessage() const { - return std::any_of(d_ptr->m_lNumbers.begin(), d_ptr->m_lNumbers.end(), - [](ContactMethod* cm){ - return cm->textRecording()->unreadInstantTextMessagingModel()->rowCount() > 0; - }); + return false; } #include <phonedirectorymodel.moc> diff --git a/src/phonedirectorymodel.h b/src/phonedirectorymodel.h index 9bb36917..85b0c05a 100644 --- a/src/phonedirectorymodel.h +++ b/src/phonedirectorymodel.h @@ -42,7 +42,6 @@ class PhoneDirectoryModelPrivate; class LIB_EXPORT PhoneDirectoryModel : public QAbstractTableModel { friend class MostPopularNumberModel; - friend class CategorizedBookmarkModel; //Friend unit test class friend class AutoCompletionTest; diff --git a/src/pixmapmanipulatordefault.cpp b/src/pixmapmanipulatordefault.cpp index 2382bc01..3a79bcaa 100644 --- a/src/pixmapmanipulatordefault.cpp +++ b/src/pixmapmanipulatordefault.cpp @@ -112,18 +112,6 @@ QVariant PixmapManipulatorDefault::securityLevelIcon(const SecurityEvaluationMod return QVariant(); } -QVariant PixmapManipulatorDefault::historySortingCategoryIcon(const CategorizedHistoryModel::SortedProxy::Categories cat) const -{ - Q_UNUSED(cat) - return QVariant(); -} - -QVariant PixmapManipulatorDefault::contactSortingCategoryIcon(const CategorizedContactModel::SortedProxy::Categories cat) const -{ - Q_UNUSED(cat) - return QVariant(); -} - QVariant PixmapManipulatorDefault::decorationRole(const QModelIndex& index) { Q_UNUSED(index) diff --git a/src/pixmapmanipulatordefault.h b/src/pixmapmanipulatordefault.h index 00008e67..1b957d16 100644 --- a/src/pixmapmanipulatordefault.h +++ b/src/pixmapmanipulatordefault.h @@ -37,8 +37,6 @@ public: QVariant personPhoto(const QByteArray& data, const QString& type = "PNG") override; QVariant collectionIcon(const CollectionInterface* interface, PixmapManipulatorI::CollectionIconHint hint = PixmapManipulatorI::CollectionIconHint::NONE) const override; QVariant securityLevelIcon(const SecurityEvaluationModel::SecurityLevel level) const override; - QVariant historySortingCategoryIcon(const CategorizedHistoryModel::SortedProxy::Categories cat) const override; - QVariant contactSortingCategoryIcon(const CategorizedContactModel::SortedProxy::Categories cat) const override; QVariant decorationRole(const QModelIndex& index) override; QVariant decorationRole(const Call* c ) override; QVariant decorationRole(const ContactMethod* cm ) override; diff --git a/src/presenceserializerdefault.cpp b/src/presenceserializerdefault.cpp deleted file mode 100644 index b7a12a71..00000000 --- a/src/presenceserializerdefault.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "presenceserializerdefault.h" - -namespace Interfaces { - -bool PresenceSerializerDefault::isTracked(CollectionInterface* backend) const -{ - Q_UNUSED(backend) - return false; -} - -void PresenceSerializerDefault::setTracked(CollectionInterface* backend, bool tracked) -{ - Q_UNUSED(backend) - Q_UNUSED(tracked) -} - -} // namespace Interfaces diff --git a/src/presenceserializerdefault.h b/src/presenceserializerdefault.h deleted file mode 100644 index b058f7c0..00000000 --- a/src/presenceserializerdefault.h +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "interfaces/presenceserializeri.h" - -class CollectionInterface; - -namespace Interfaces { - -///Default implementation of the PresenceSerializer interface; does not actually preform any serialization -class LIB_EXPORT PresenceSerializerDefault : public PresenceSerializerI { -public: - void save () override {} - void load () override {} - - ///Always returns 'false' - bool isTracked (CollectionInterface* backend) const override; - void setTracked (CollectionInterface* backend, bool tracked) override; -}; - -} // namespace Interfaces diff --git a/src/presencestatusmodel.cpp b/src/presencestatusmodel.cpp deleted file mode 100644 index eca9ab34..00000000 --- a/src/presencestatusmodel.cpp +++ /dev/null @@ -1,394 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "presencestatusmodel.h" - -//Qt -#include <QtCore/QCoreApplication> - -//Ring -#include "accountmodel.h" -#include "dbus/presencemanager.h" -#include "globalinstances.h" -#include "interfaces/presenceserializeri.h" - -class PresenceStatusModelPrivate -{ -public: - PresenceStatusModelPrivate(); - //Attributes - QVector<PresenceStatusModel::StatusData*> m_lStatuses; - QString m_CustomMessage ; - bool m_UseCustomStatus ; - bool m_CustomStatus ; - PresenceStatusModel::StatusData* m_pCurrentStatus ; - PresenceStatusModel::StatusData* m_pDefaultStatus ; -}; - -PresenceStatusModelPrivate::PresenceStatusModelPrivate() : -m_pCurrentStatus(nullptr),m_pDefaultStatus(nullptr),m_UseCustomStatus(false),m_CustomStatus(false) -{ - -} - -///Constructor -PresenceStatusModel::PresenceStatusModel(QObject* parent) : QAbstractTableModel(parent?parent:QCoreApplication::instance()), -d_ptr(new PresenceStatusModelPrivate()) -{ - setObjectName("PresenceStatusModel"); -} - -PresenceStatusModel::~PresenceStatusModel() -{ - foreach (StatusData* data, d_ptr->m_lStatuses) { - delete data; - } -} - -QHash<int,QByteArray> PresenceStatusModel::roleNames() const -{ - static QHash<int, QByteArray> roles = QAbstractItemModel::roleNames(); - /*static bool initRoles = false; - if (!initRoles) { - initRoles = true; - - }*/ - return roles; -} - -///Get model data -QVariant PresenceStatusModel::data(const QModelIndex& index, int role ) const -{ - if (index.isValid()) { - switch (static_cast<PresenceStatusModel::Columns>(index.column())) { - case PresenceStatusModel::Columns::Name: - switch (role) { - case Qt::DisplayRole: - case Qt::EditRole: - return d_ptr->m_lStatuses[index.row()]->name; - case Qt::ToolTipRole: - return d_ptr->m_lStatuses[index.row()]->message; - } - break; - case PresenceStatusModel::Columns::Message: - switch (role) { - case Qt::DisplayRole: - case Qt::EditRole: - return d_ptr->m_lStatuses[index.row()]->message; - } - break; - case PresenceStatusModel::Columns::Color: - switch (role) { - case Qt::BackgroundColorRole: - return d_ptr->m_lStatuses[index.row()]->color; - } - break; - case PresenceStatusModel::Columns::Status: - switch (role) { - case Qt::CheckStateRole: - return d_ptr->m_lStatuses[index.row()]->status?Qt::Checked:Qt::Unchecked; - case Qt::TextAlignmentRole: - return Qt::AlignCenter; - } - break; - case PresenceStatusModel::Columns::Default: - switch (role) { - case Qt::CheckStateRole: - return d_ptr->m_lStatuses[index.row()]->defaultStatus?Qt::Checked:Qt::Unchecked; - case Qt::TextAlignmentRole: - return Qt::AlignCenter; - } - break; - } - } - return QVariant(); -} - -///Return the number of pre defined status -int PresenceStatusModel::rowCount(const QModelIndex& parent ) const -{ - if (parent.isValid()) return 0; - return d_ptr->m_lStatuses.size(); -} - -///Return the number of column (static: {"Name","Message","Color","Present","Default"}) -int PresenceStatusModel::columnCount(const QModelIndex& parent ) const -{ - if (parent.isValid()) return 0; - return 5; -} - -///All the items are enabled, selectable and editable -Qt::ItemFlags PresenceStatusModel::flags(const QModelIndex& index ) const -{ - const int col = index.column(); - return Qt::ItemIsEnabled - | Qt::ItemIsSelectable - | (col<2||col>=3?Qt::ItemIsEditable:Qt::NoItemFlags) - | (col>=3?Qt::ItemIsUserCheckable:Qt::NoItemFlags); -} - -///Set model data -bool PresenceStatusModel::setData(const QModelIndex& index, const QVariant &value, int role ) -{ - Q_UNUSED(index) - Q_UNUSED(value) - Q_UNUSED(role) - if (index.isValid()) { - StatusData* dat = d_ptr->m_lStatuses[index.row()]; - switch(static_cast<PresenceStatusModel::Columns>(index.column())) { - case PresenceStatusModel::Columns::Name: - if (role == Qt::EditRole) { - dat->name = value.toString(); - emit dataChanged(index,index); - return true; - } - break; - case PresenceStatusModel::Columns::Message: - if (role == Qt::EditRole) { - dat->message = value.toString(); - emit dataChanged(index,index); - return true; - } - break; - case PresenceStatusModel::Columns::Color: - if (role == Qt::EditRole) { - - } - break; - case PresenceStatusModel::Columns::Status: - if (role == Qt::CheckStateRole) { - dat->status = value.toBool(); - emit dataChanged(index,index); - return true; - } - break; - case PresenceStatusModel::Columns::Default: - if (role == Qt::CheckStateRole) { - dat->defaultStatus = value.toBool(); - setDefaultStatus(index); - return true; - } - break; - }; - } - return false; -} - -///Return header data -QVariant PresenceStatusModel::headerData(int section, Qt::Orientation orientation, int role ) const -{ - Q_UNUSED(section) - Q_UNUSED(orientation) - static const QString rows[] = {tr("Name"),tr("Message"),tr("Color"),tr("Present"),tr("Default")}; - if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { - return QVariant(rows[section]); - } - return QVariant(); -} - -///Add a status to the model -void PresenceStatusModel::addStatus(StatusData* status) -{ - d_ptr->m_lStatuses << status; - if (status->defaultStatus) { - d_ptr->m_pDefaultStatus = status; - if (!d_ptr->m_pCurrentStatus) - setCurrentIndex(index(d_ptr->m_lStatuses.size()-1,0)); - } -} - -///Add a new status -void PresenceStatusModel::addRow() -{ - StatusData* newRow = new StatusData(); - newRow->status = false; - d_ptr->m_lStatuses << newRow; - emit layoutChanged(); -} - -///Remove status[index] -void PresenceStatusModel::removeRow(const QModelIndex& index) -{ - StatusData* toDel = d_ptr->m_lStatuses[index.row()]; - d_ptr->m_lStatuses.remove(index.row()); - emit layoutChanged(); - delete toDel; -} - -///Serialize model TODO a backend visitor need to be created -void PresenceStatusModel::save() -{ - GlobalInstances::presenceSerializer().save(); -} - -///Singleton -PresenceStatusModel& PresenceStatusModel::instance() -{ - static auto instance = new PresenceStatusModel; - return *instance; -} - -///Move idx up -void PresenceStatusModel::moveUp(const QModelIndex& idx) -{ - const int row = idx.row(); - if (row > 0) { - StatusData* tmp = d_ptr->m_lStatuses[row-1]; - d_ptr->m_lStatuses[ row-1 ] = d_ptr->m_lStatuses[row ]; - d_ptr->m_lStatuses[ row] = tmp; - emit dataChanged(index(row-1,0),index(row,0)); - } -} - -///Move idx down -void PresenceStatusModel::moveDown(const QModelIndex& idx) -{ - const int row = idx.row(); - if (row-1 < d_ptr->m_lStatuses.size()) { - StatusData* tmp = d_ptr->m_lStatuses[row+1]; - d_ptr->m_lStatuses[ row+1 ] = d_ptr->m_lStatuses[row ]; - d_ptr->m_lStatuses[ row ] = tmp; - emit dataChanged(index(row,0),index(row+1,0)); - } -} - -///Return the (user defined) custom message; -QString PresenceStatusModel::customMessage() const -{ - return d_ptr->m_CustomMessage; -} - -///Set the (user defined) custom message -void PresenceStatusModel::setCustomMessage(const QString& message) -{ - const bool hasChanged = d_ptr->m_CustomMessage != message; - d_ptr->m_CustomMessage = message; - if (hasChanged) { - emit customMessageChanged(message); - if (d_ptr->m_UseCustomStatus) - emit currentMessageChanged(message); - } -} - -///Set the custom status -void PresenceStatusModel::setCustomStatus(bool status) -{ - const bool hasChanged = status != d_ptr->m_CustomStatus; - d_ptr->m_CustomStatus = status; - if (hasChanged) { - emit customStatusChanged(status); - if (d_ptr->m_UseCustomStatus) - emit currentStatusChanged(status); - } -} - -///Switch between the pre-defined status list and custom ones -void PresenceStatusModel::setUseCustomStatus(bool useCustom) -{ - const bool changed = d_ptr->m_UseCustomStatus != useCustom; - d_ptr->m_UseCustomStatus = useCustom; - if (changed) { - emit useCustomStatusChanged( useCustom ); - emit currentIndexChanged ( useCustom||!d_ptr->m_pCurrentStatus?index(-1,-1):index(d_ptr->m_lStatuses.indexOf(d_ptr->m_pCurrentStatus),0) ); - emit currentNameChanged ( useCustom?tr("Custom"):(d_ptr->m_pCurrentStatus?d_ptr->m_pCurrentStatus->name:tr("N/A")) ); - emit currentStatusChanged ( useCustom?d_ptr->m_CustomStatus:(d_ptr->m_pCurrentStatus?d_ptr->m_pCurrentStatus->status:false) ); - emit currentMessageChanged ( useCustom?d_ptr->m_CustomMessage:(d_ptr->m_pCurrentStatus?d_ptr->m_pCurrentStatus->message:tr("N/A")) ); - } -} - -///Return if the presence status is from the predefined list or custom -bool PresenceStatusModel::useCustomStatus() const -{ - return d_ptr->m_UseCustomStatus; -} - -///Return the custom status -bool PresenceStatusModel::customStatus() const -{ - return d_ptr->m_CustomStatus; -} - -///Set the current status and publish it on the network -void PresenceStatusModel::setCurrentIndex (const QModelIndex& index) -{ - if (!index.isValid()) return; - d_ptr->m_pCurrentStatus = d_ptr->m_lStatuses[index.row()]; - emit currentIndexChanged(index); - emit currentNameChanged(d_ptr->m_pCurrentStatus->name); - emit currentMessageChanged(d_ptr->m_pCurrentStatus->message); - emit currentStatusChanged(d_ptr->m_pCurrentStatus->status); - for (int i=0; i < AccountModel::instance().size(); i++) { - PresenceManager::instance().publish( - AccountModel::instance()[i]->id(), d_ptr->m_pCurrentStatus->status,d_ptr->m_pCurrentStatus->message - ); - } -} - -///Return the current status -bool PresenceStatusModel::currentStatus() const -{ - if (d_ptr->m_UseCustomStatus) return d_ptr->m_CustomStatus; - if (!d_ptr->m_pCurrentStatus) return false; - return d_ptr->m_UseCustomStatus?d_ptr->m_CustomStatus:d_ptr->m_pCurrentStatus->status; -} - -///Return the current status message -QString PresenceStatusModel::currentMessage() const -{ - if (d_ptr->m_UseCustomStatus) return d_ptr->m_CustomMessage; - if (!d_ptr->m_pCurrentStatus) return tr("N/A"); - return d_ptr->m_pCurrentStatus->message; -} - -///Return current name -QString PresenceStatusModel::currentName() const -{ - return d_ptr->m_UseCustomStatus?tr("Custom"):d_ptr->m_pCurrentStatus?d_ptr->m_pCurrentStatus->name:tr("N/A"); -} - -///Return the default status index -QModelIndex PresenceStatusModel::defaultStatus() const -{ - if (!d_ptr->m_pDefaultStatus) return index(-1,-1); - return index(d_ptr->m_lStatuses.indexOf(d_ptr->m_pDefaultStatus),0); -} - -///Set the new default status -void PresenceStatusModel::setDefaultStatus( const QModelIndex& idx ) -{ - if (!idx.isValid()) return; - if (d_ptr->m_pDefaultStatus) { - d_ptr->m_pDefaultStatus->defaultStatus = false; - const QModelIndex& oldIdx = index(d_ptr->m_lStatuses.indexOf(d_ptr->m_pDefaultStatus),static_cast<int>(PresenceStatusModel::Columns::Default)); - emit dataChanged(oldIdx,oldIdx); - } - d_ptr->m_pDefaultStatus = d_ptr->m_lStatuses[idx.row()]; - d_ptr->m_pDefaultStatus->defaultStatus = true; - emit defaultStatusChanged(idx); - emit dataChanged(idx,idx); -} - -bool PresenceStatusModel::isAutoTracked(CollectionInterface* backend) const -{ - return GlobalInstances::presenceSerializer().isTracked(backend); -} - -void PresenceStatusModel::setAutoTracked(CollectionInterface* backend, bool tracked) const -{ - GlobalInstances::presenceSerializer().setTracked(backend,tracked); -} diff --git a/src/presencestatusmodel.h b/src/presencestatusmodel.h deleted file mode 100644 index c089cc87..00000000 --- a/src/presencestatusmodel.h +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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" - -//Qt -#include <QtCore/QString> -#include <QtCore/QAbstractTableModel> - -class CollectionInterface; -class PresenceStatusModelPrivate; - -/** - * This model present the **published** presence status. A published presence - * status is used to notify other users of your status. This is done by sending - * a string of text. This implementation also allow a name to describe each - * string. This is better from an user point of view, as it take less room - * in the GUI. The message is either selected from a list or set by hand. - */ -class LIB_EXPORT PresenceStatusModel : public QAbstractTableModel { - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" - Q_OBJECT - #pragma GCC diagnostic pop -public: - - //Internal representation - struct StatusData { - QString name ; - QString message ; - QVariant color ; - bool status ; - bool defaultStatus; - }; - - //Table columns - enum class Columns { - Name = 0, - Message = 1, - Color = 2, - Status = 3, - Default = 4, - }; - - //Methods - void addStatus(StatusData* status); - - //Properties - Q_PROPERTY( QString customMessage READ customMessage WRITE setCustomMessage NOTIFY customMessageChanged(QString) ) - Q_PROPERTY( bool useCustomStatus READ useCustomStatus WRITE setUseCustomStatus NOTIFY useCustomStatusChanged(bool) ) - Q_PROPERTY( bool customStatus READ customStatus WRITE setCustomStatus NOTIFY customStatusChanged(bool) ) - Q_PROPERTY( bool currentStatus READ currentStatus NOTIFY currentStatusChanged(bool) ) - Q_PROPERTY( QString currentMessage READ currentMessage NOTIFY currentMessageChanged(QString) ) - Q_PROPERTY( QModelIndex defaultStatus READ defaultStatus WRITE setDefaultStatus NOTIFY defaultStatusChanged(QModelIndex) ) - Q_PROPERTY( QString currentName READ currentName NOTIFY currentNameChanged(QString) ) - - //Constructor - explicit PresenceStatusModel(QObject* parent = nullptr); - virtual ~PresenceStatusModel(); - - //Abstract model members - virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole ) 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 bool setData (const QModelIndex& index, const QVariant &value, int role ) override; - virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override; - virtual QHash<int,QByteArray> roleNames() const override; - - //Singleton - static PresenceStatusModel& instance(); - - //Setters - void setDefaultStatus( const QModelIndex& idx ); - void setAutoTracked(CollectionInterface* backend, bool tracked) const; - - //Getters - QString customMessage () const; - bool useCustomStatus () const; - bool customStatus () const; - bool currentStatus () const; - QString currentMessage () const; - QString currentName () const; - QModelIndex defaultStatus () const; - bool isAutoTracked(CollectionInterface* backend) const; - -private: - QScopedPointer<PresenceStatusModelPrivate> d_ptr; - -public Q_SLOTS: - void addRow ( ); - void removeRow ( const QModelIndex& index ); - void save ( ); - void moveUp ( const QModelIndex& index ); - void moveDown ( const QModelIndex& index ); - void setUseCustomStatus( bool useCustom ); - void setCustomStatus ( bool status ); - void setCurrentIndex ( const QModelIndex& index ); - void setCustomMessage ( const QString& message ); - -Q_SIGNALS: - ///The current presence status has changed - void currentIndexChanged ( const QModelIndex& current ); - ///The current presence status name string changed - void currentNameChanged ( const QString& name ); - ///The model now use custom strings instead of predefined ones - void useCustomStatusChanged( bool useCustom ); - ///The current (custom) presence message changed - void customMessageChanged ( const QString& message ); - ///The current (custom) presence status changed - void customStatusChanged ( bool status ); - ///The default presence status changed - void defaultStatusChanged ( const QModelIndex& def ); - ///The current presence message changed - void currentMessageChanged ( const QString& message ); - ///The current presence status changed - void currentStatusChanged ( bool status ); - -}; - -Q_DECLARE_METATYPE( PresenceStatusModel* ) - diff --git a/src/private/account_p.h b/src/private/account_p.h index b41da17a..f87b4835 100644 --- a/src/private/account_p.h +++ b/src/private/account_p.h @@ -27,11 +27,6 @@ class AccountPrivate; class ContactMethod; -class CipherModel; -class TlsMethodModel; -class ProtocolModel; -class NetworkInterfaceModel; -class DaemonCertificateCollection; class Profile; typedef void (AccountPrivate::*account_function)(); @@ -95,22 +90,15 @@ public: void reloadMod() {reload();modify();} KeyExchangeModel* m_pKeyExchangeModel ; - CipherModel* m_pCipherModel ; SecurityEvaluationModel* m_pSecurityEvaluationModel ; - TlsMethodModel* m_pTlsMethodModel ; - ProtocolModel* m_pProtocolModel ; QAbstractItemModel* m_pKnownCertificates ; QAbstractItemModel* m_pBannedCertificates ; QAbstractItemModel* m_pAllowedCertificates ; - NetworkInterfaceModel* m_pNetworkInterfaceModel ; - DaemonCertificateCollection* m_pAllowedCerts ; - DaemonCertificateCollection* m_pBannedCerts ; Account::EditState m_CurrentState ; QMetaObject::Connection m_cTlsCert ; QMetaObject::Connection m_cTlsCaCert ; Profile* m_pProfile {nullptr} ; Account::ContactMethods m_NumbersFromDaemon ; - BannedContactModel* m_pBannedContactModel {nullptr}; QHash<int, Account::RoleStatus> m_hRoleStatus; diff --git a/src/private/accountmodel_p.h b/src/private/accountmodel_p.h index 79984819..136a1762 100644 --- a/src/private/accountmodel_p.h +++ b/src/private/accountmodel_p.h @@ -27,7 +27,6 @@ #include <accountmodel.h> #include "matrixutils.h" class AccountModel; -class ProtocolModel; class QItemSelectionModel; class AccountModelPrivate final : public QObject @@ -52,7 +51,6 @@ public: QStringList m_lDeletedAccounts ; Account* m_pIP2IP ; QList<Account*> m_pRemovedAccounts ; - ProtocolModel* m_pProtocolModel ; QItemSelectionModel* m_pSelectionModel ; QItemSelectionModel* m_pUserSelectionModel {nullptr}; QStringList m_lMimes ; @@ -70,7 +68,6 @@ public Q_SLOTS: void slotVoiceMailNotify( const QString& accountID , int count ); void slotAccountPresenceEnabledChanged(bool state); void slotVolatileAccountDetailsChange(const QString& accountId, const MapStringString& details); - void slotIncomingContactRequest(const QString& accountId, const QString& hash, const QByteArray& payload, time_t time); void slotExportOnRingEnded(const QString& accountId, int status, const QString& pin); void slotMigrationEnded(const QString& accountId, const QString& result); void slotContactAdded(const QString &accountID, const QString &uri, bool confirmed); diff --git a/src/private/call_p.h b/src/private/call_p.h index d7f95f80..c15ace4b 100644 --- a/src/private/call_p.h +++ b/src/private/call_p.h @@ -128,9 +128,6 @@ public: QDate* m_pDateOnly {nullptr}; QString m_FormattedDate ; - //Cache - HistoryTimeCategoryModel::HistoryConst m_HistoryConst; - //State machine /** * actionPerformedStateMap[orig_state][action] diff --git a/src/private/certificatemodel_p.h b/src/private/certificatemodel_p.h index 492facb2..712affc3 100644 --- a/src/private/certificatemodel_p.h +++ b/src/private/certificatemodel_p.h @@ -26,7 +26,6 @@ struct CertificateNode; class Account; class CertificateModel; -class DaemonCertificateCollection; class QAbstractItemModel; class CertificateModelPrivate final : public QObject diff --git a/src/private/contactmethod_p.h b/src/private/contactmethod_p.h index ac991023..0d58ca24 100644 --- a/src/private/contactmethod_p.h +++ b/src/private/contactmethod_p.h @@ -43,7 +43,6 @@ public: QByteArray m_Sha1 ; ContactMethod::Type m_Type ; QList<URI> m_lOtherURIs ; - media::TextRecording* m_pTextRecording; Certificate* m_pCertificate; QString m_RegisteredName ; UsageStatistics m_UsageStats ; @@ -63,7 +62,6 @@ public: void registeredNameSet(const QString& registeredName); //Helpers - void setTextRecording(media::TextRecording* r); void setCertificate (Certificate*); void setRegisteredName(const QString& registeredName); diff --git a/src/private/imconversationmanagerprivate.h b/src/private/imconversationmanagerprivate.h index cdd01679..b9e83dde 100644 --- a/src/private/imconversationmanagerprivate.h +++ b/src/private/imconversationmanagerprivate.h @@ -26,7 +26,6 @@ class ContactMethod; namespace media { class Text; - class TextRecording; } class IMConversationManagerPrivate final : public QObject diff --git a/src/private/sortproxies.cpp b/src/private/sortproxies.cpp index 6362ddc4..7159faa7 100644 --- a/src/private/sortproxies.cpp +++ b/src/private/sortproxies.cpp @@ -27,8 +27,6 @@ //Ring #include "matrixutils.h" -#include <categorizedcontactmodel.h> -#include <categorizedhistorymodel.h> #include <globalinstances.h> #include <interfaces/pixmapmanipulatori.h> @@ -44,23 +42,6 @@ namespace CategoryModelCommon { Q_UNUSED(role) return false; } - - static const Matrix1D<CategorizedContactModel::SortedProxy::Categories,QString> contactSortNames = {{ - QT_TRANSLATE_NOOP("ContactSortingCategoryModel", "Name" ), - QT_TRANSLATE_NOOP("ContactSortingCategoryModel", "Organisation" ), - QT_TRANSLATE_NOOP("ContactSortingCategoryModel", "Recently used"), - QT_TRANSLATE_NOOP("ContactSortingCategoryModel", "Group" ), - QT_TRANSLATE_NOOP("ContactSortingCategoryModel", "Department" ), - }}; - - static const Matrix1D<CategorizedHistoryModel::SortedProxy::Categories,QString> historySortNames = {{ - QT_TRANSLATE_NOOP("HistorySortingCategoryModel", "Date" ), - QT_TRANSLATE_NOOP("HistorySortingCategoryModel", "Name" ), - QT_TRANSLATE_NOOP("HistorySortingCategoryModel", "Popularity" ), - QT_TRANSLATE_NOOP("HistorySortingCategoryModel", "Duration" ), - QT_TRANSLATE_NOOP("HistorySortingCategoryModel", "Total time" ), - }}; - } class RemoveDisabledProxy : public QSortFilterProxyModel @@ -122,59 +103,16 @@ ContactSortingCategoryModel::~ContactSortingCategoryModel() void sortContact(QSortFilterProxyModel* p, int roleIdx); void sortContact(QSortFilterProxyModel* p, int roleIdx) { - static auto& m = CategorizedContactModel::instance(); - switch(static_cast<CategorizedContactModel::SortedProxy::Categories>(roleIdx)) { - case CategorizedContactModel::SortedProxy::Categories::NAME: - m.setSortAlphabetical(true); - m.setDefaultCategory(QT_TRANSLATE_NOOP("CategorizedContactModel", "Empty")); - p->setSortRole(Qt::DisplayRole); - m.setRole(Qt::DisplayRole); - break; - case CategorizedContactModel::SortedProxy::Categories::ORGANIZATION: - m.setSortAlphabetical(false); - m.setDefaultCategory(QT_TRANSLATE_NOOP("CategorizedContactModel", "Unknown")); - p->setSortRole((int)Person::Role::Organization); - m.setRole((int)Person::Role::Organization); - break; - case CategorizedContactModel::SortedProxy::Categories::RECENTLYUSED: - m.setSortAlphabetical(false); - m.setDefaultCategory(QT_TRANSLATE_NOOP("CategorizedContactModel", "Never")); - p->setSortRole((int)Person::Role::IndexedLastUsed); - m.setRole((int)Person::Role::FormattedLastUsed); - break; - case CategorizedContactModel::SortedProxy::Categories::GROUP: - m.setSortAlphabetical(false); - m.setDefaultCategory(QT_TRANSLATE_NOOP("CategorizedContactModel", "Other")); - p->setSortRole((int)Person::Role::Group); - m.setRole((int)Person::Role::Group); - break; - case CategorizedContactModel::SortedProxy::Categories::DEPARTMENT: - m.setSortAlphabetical(false); - m.setDefaultCategory(QT_TRANSLATE_NOOP("CategorizedContactModel", "Unknown")); - p->setSortRole((int)Person::Role::Department); - m.setRole((int)Person::Role::Department); - break; - case CategorizedContactModel::SortedProxy::Categories::COUNT__: - break; - }; } QVariant ContactSortingCategoryModel::data( const QModelIndex& index, int role ) const { - if (index.isValid()) { - switch (role) { - case Qt::DisplayRole: - return CategoryModelCommon::contactSortNames[static_cast<CategorizedContactModel::SortedProxy::Categories>(index.row())]; - case Qt::DecorationRole: - return GlobalInstances::pixmapManipulator().contactSortingCategoryIcon(static_cast<CategorizedContactModel::SortedProxy::Categories>(index.row())); - } - } return QVariant(); } int ContactSortingCategoryModel::rowCount( const QModelIndex& parent) const { - return parent.isValid()? 0 : enum_class_size<CategorizedContactModel::SortedProxy::Categories>(); + return 0; } Qt::ItemFlags ContactSortingCategoryModel::flags( const QModelIndex& index ) const @@ -190,30 +128,7 @@ bool ContactSortingCategoryModel::setData( const QModelIndex& index, const QVari void sortHistory(QSortFilterProxyModel* p, int role); void sortHistory(QSortFilterProxyModel* p, int role) { - switch (static_cast<CategorizedHistoryModel::SortedProxy::Categories>(role)) { - case CategorizedHistoryModel::SortedProxy::Categories::DATE: - CategorizedHistoryModel::instance().setCategoryRole(static_cast<int>(Call::Role::FuzzyDate)); - p->setSortRole(static_cast<int>(Call::Role::Date)); - break; - case CategorizedHistoryModel::SortedProxy::Categories::NAME: - CategorizedHistoryModel::instance().setCategoryRole(static_cast<int>(Call::Role::Name)); - p->setSortRole(Qt::DisplayRole); - break; - case CategorizedHistoryModel::SortedProxy::Categories::POPULARITY: - CategorizedHistoryModel::instance().setCategoryRole(static_cast<int>(Call::Role::CallCount)); - p->setSortRole(static_cast<int>(Call::Role::CallCount)); - break; - case CategorizedHistoryModel::SortedProxy::Categories::LENGTH: - CategorizedHistoryModel::instance().setCategoryRole(static_cast<int>(Call::Role::Length)); - p->setSortRole(static_cast<int>(Call::Role::Length)); - break; - case CategorizedHistoryModel::SortedProxy::Categories::SPENT_TIME: - CategorizedHistoryModel::instance().setCategoryRole(static_cast<int>(Call::Role::TotalSpentTime)); - p->setSortRole(static_cast<int>(Call::Role::TotalSpentTime)); - break; - case CategorizedHistoryModel::SortedProxy::Categories::COUNT__: - break; - } + } HistorySortingCategoryModel::HistorySortingCategoryModel(QObject* parent) : QAbstractListModel(parent) @@ -228,21 +143,12 @@ HistorySortingCategoryModel::~HistorySortingCategoryModel() QVariant HistorySortingCategoryModel::data( const QModelIndex& index, int role) const { - if (index.isValid()) { - switch(role) { - case Qt::DisplayRole: - return CategoryModelCommon::historySortNames[static_cast<CategorizedHistoryModel::SortedProxy::Categories>(index.row())]; - case Qt::DecorationRole: - return GlobalInstances::pixmapManipulator().historySortingCategoryIcon(static_cast<CategorizedHistoryModel::SortedProxy::Categories>(index.row())); - } - } - return QVariant(); } int HistorySortingCategoryModel::rowCount( const QModelIndex& parent) const { - return parent.isValid()? 0 : enum_class_size<CategorizedHistoryModel::SortedProxy::Categories>(); + return 0; } Qt::ItemFlags HistorySortingCategoryModel::flags( const QModelIndex& index ) const @@ -281,22 +187,12 @@ SortingCategory::ModelTuple* createModels(QAbstractItemModel* src, int filterRol SortingCategory::ModelTuple* SortingCategory::getContactProxy() { - return createModels<ContactSortingCategoryModel>(&CategorizedContactModel::instance(),(int)Person::Role::Filter, Qt::DisplayRole, [](QSortFilterProxyModel* proxy,const QModelIndex& idx) { - if (idx.isValid()) { - qDebug() << "Selection changed" << idx.row(); - sortContact(proxy,idx.row()); - } - }); + return nullptr; } SortingCategory::ModelTuple* SortingCategory::getHistoryProxy() { - return createModels<HistorySortingCategoryModel>(&CategorizedHistoryModel::instance(),static_cast<int>(Call::Role::Filter), static_cast<int>(Call::Role::Date), [](QSortFilterProxyModel* proxy,const QModelIndex& idx) { - if (idx.isValid()) { - qDebug() << "Selection changed" << idx.row(); - sortHistory(proxy,idx.row()); - } - }); + return nullptr; } #include <sortproxies.moc> diff --git a/src/private/videorenderermanager.cpp b/src/private/videorenderermanager.cpp index e809e91e..f6ed8baf 100644 --- a/src/private/videorenderermanager.cpp +++ b/src/private/videorenderermanager.cpp @@ -28,7 +28,6 @@ #include <dbus/videomanager.h> #include <video/device.h> #include <call.h> -#include <callmodel.h> #include <video/renderer.h> #include <video/devicemodel.h> #include <video/channel.h> @@ -288,23 +287,7 @@ void VideoRendererManagerPrivate::startedDecoding(const QString& id, const QStri if (id != PREVIEW_RENDERER_ID) { qDebug() << "Starting video for call" << id; - Call* c = CallModel::instance().getCall(id); - - if (c) { - emit q_ptr->remotePreviewStarted(id.toStdString(), r); - c->d_ptr->registerRenderer(r); - } - else { - //We don't have the conference yet - QObject::connect(&CallModel::instance(), &CallModel::conferenceCreated, [=](Call* conf) { - Q_UNUSED(conf) - Call* c = CallModel::instance().getCall(id); - - if (c) { - c->d_ptr->registerRenderer(r); - } - }); - } + emit q_ptr->remotePreviewStarted(id.toStdString(), r); } else { @@ -348,13 +331,6 @@ void VideoRendererManagerPrivate::stoppedDecoding(const QString& id, const QStri auto r = m_hRenderers.value(id.toLatin1()); - Call* c = CallModel::instance().getCall(id); - - // TODO: the current implementeation of CallPrivate::removeRenderer() does nothing - if (c && c->lifeCycleState() == Call::LifeCycleState::FINISHED) { - c->d_ptr->removeRenderer(r); - } - r->stopRendering(); qDebug() << "Video stopped for call" << id << "Renderer found:" << m_hRenderers.contains(id.toLatin1()); @@ -378,11 +354,7 @@ void VideoRendererManagerPrivate::stoppedDecoding(const QString& id, const QStri } // decoding stopped; remove the renderer, if/when call is over - if (c && c->lifeCycleState() == Call::LifeCycleState::FINISHED) { - removeRenderer(r); - } else if (c) { - connect(c, &Call::isOver, this, &VideoRendererManagerPrivate::callIsOver); - } + removeRenderer(r); } void VideoRendererManagerPrivate::callIsOver() @@ -416,13 +388,6 @@ void VideoRendererManagerPrivate::removeRenderer(Video::Renderer* r) qWarning() << "Cannot stop rendering, renderer" << id << "not found"; return; } - - Call* c = CallModel::instance().getCall(id); - - if (c && c->lifeCycleState() == Call::LifeCycleState::FINISHED) { - c->d_ptr->removeRenderer(r); - } - r->stopRendering(); qDebug() << "Video stopped for call" << id << "Renderer found:" << m_hRenderers.contains(id); diff --git a/src/profile.cpp b/src/profile.cpp deleted file mode 100644 index 033677d4..00000000 --- a/src/profile.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016-2019 Savoir-faire Linux Inc. * - * Author : Alexandre Lision <alexandre.lision@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 "profile.h" - -//Qt -#include <QtCore/QUrl> -#include <QtCore/QDir> - -//Ring -#include <account.h> -#include <person.h> - -class ProfilePrivate -{ -public: - ProfilePrivate(); - Profile::Accounts m_Accounts; - Person* m_Person; - -}; - -ProfilePrivate::ProfilePrivate() -{ - -} - -Profile::Profile(CollectionInterface* parent, Person* p) : ItemBase(nullptr), -d_ptr(new ProfilePrivate()) -{ - if (parent) - setCollection(parent); - d_ptr->m_Person = p; -} - -Profile::~Profile() -{ - delete d_ptr; -} - -const QByteArray Profile::id() const -{ - return person()->uid(); -} - -const Profile::Accounts& Profile::accounts() const -{ - return d_ptr->m_Accounts; -} - -Person* Profile::person() const -{ - return d_ptr->m_Person; -} - -void Profile::setAccounts(const Profile::Accounts& accounts) -{ - d_ptr->m_Accounts = accounts; -} - -bool Profile::addAccount(Account* acc) -{ - if (d_ptr->m_Accounts.indexOf(acc) == -1) { - d_ptr->m_Accounts << acc; - - // The Account::setProfile logic should take care of removing the old - // profile. - acc->setProfile(this); - - return true; - } - - return false; -} - -bool Profile::removeAccount(Account* acc) -{ - for (int i = 0 ; i < d_ptr->m_Accounts.size() ; ++i) { - if (d_ptr->m_Accounts[i]->id() == acc->id()) { - d_ptr->m_Accounts.remove(i); - d_ptr->m_Accounts.squeeze(); - return true; - } - } - return false; -} diff --git a/src/profile.h b/src/profile.h deleted file mode 100644 index 2c87b005..00000000 --- a/src/profile.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2016-2019 Savoir-faire Linux Inc. * - * Author : Alexandre Lision <alexandre.lision@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 ProfilePrivate; -class Person; -class Account; - -class LIB_EXPORT Profile : public ItemBase -{ - Q_OBJECT -public: - typedef QVector<Account*> Accounts; - - explicit Profile(CollectionInterface* parent = nullptr, Person* p = nullptr); - virtual ~Profile(); - - Q_PROPERTY( Accounts accounts READ accounts WRITE setAccounts ) - Q_PROPERTY( Person person READ person ) - Q_PROPERTY( QByteArray id READ id ) - - //Getters - const Accounts& accounts() const; - const QByteArray id () const; - Person* person () const; - - //Setters - void setAccounts(const Accounts&); - bool addAccount(Account* acc); - bool removeAccount(Account* acc); - -private: - ProfilePrivate* d_ptr; - Q_DECLARE_PRIVATE(Profile) -}; - -Q_DECLARE_METATYPE(Profile*) diff --git a/src/profilemodel.cpp b/src/profilemodel.cpp deleted file mode 100644 index 5ba967f7..00000000 --- a/src/profilemodel.cpp +++ /dev/null @@ -1,806 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Authors : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com>* - * Alexandre Lision <alexandre.lision@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 "profilemodel.h" - -//Qt -#include <QtCore/QSortFilterProxyModel> -#include <QtCore/QTimer> -#include <QtCore/QObject> -#include <QtCore/QDateTime> -#include <QtCore/QUrl> -#include <QMimeData> -#include <QtCore/QCoreApplication> -#include <QtCore/QPointer> -#include <QtCore/QItemSelectionModel> -#include <QtCore/QDir> -#include <QtCore/QStandardPaths> - -//Ring -#include "accountmodel.h" -#include "collectioninterface.h" -#include "collectioneditor.h" -#include "personmodel.h" -#include "callmodel.h" -#include "contactmethod.h" -#include "person.h" -#include "globalinstances.h" -#include "private/vcardutils.h" -#include "mime.h" -#include "profile.h" - -struct Node final -{ - explicit Node(): type(Node::Type::PROFILE), parent(nullptr),m_Index(0) {} - - virtual ~Node() { - QObject::disconnect(m_ChangedConn); - foreach( Node* n, children) - delete n; - } - - enum class Type : bool { - PROFILE, - ACCOUNT, - }; - - QVector<Node*> children; - Node* parent; - Type type {Node::Type::ACCOUNT}; - union { - Profile* m_pProfile; - Account* m_pAccount; - } m_uContent; - - int m_Index; - uint m_ParentIndex {std::numeric_limits<uint>::max()}; //INT_MAX - QMetaObject::Connection m_ChangedConn; -}; - -class ProfileModelPrivate final : public QObject -{ - Q_OBJECT -public: - ProfileModelPrivate(ProfileModel* parent); - QVector<Node*> m_lProfiles; - QStringList m_lMimes; - QItemSelectionModel* m_pSelectionModel {nullptr}; - QItemSelectionModel* m_pSortedProxySelectionModel {nullptr}; - QSortFilterProxyModel* m_pSortedProxyModel {nullptr}; - - //Helpers - void updateIndexes(); - void regenParentIndexes(); - inline bool addProfile(Person* person, const QString& name, CollectionInterface* col); - - void slotAccountAdded(Account* acc); - Node* profileNodeById(const QByteArray& id); - Node* profileNodeForAccount(const Account* a); - Node* nodeForAccount(const Account* a); - - //Constants - constexpr static const int c_OrderRole = 9999; - -private Q_SLOTS: - void slotDataChanged(const QModelIndex& tl,const QModelIndex& br); - void slotLayoutchanged(); - void slotDelayedInit(); - void slotRowsInserted(const QModelIndex& index, int first, int last); - void slotRowsMoved (const QModelIndex& index, int first, int last, const QModelIndex& newPar, int newIdx); - void slotAccountRemoved(Account* a); - -private: - ProfileModel* q_ptr; -}; - -void ProfileModelPrivate::slotAccountAdded(Account* acc) -{ - auto currentProfile = q_ptr->selectedProfile(); - if (!currentProfile) { - qDebug() << "No profile selected or none exists"; - return; - } - auto currentNode = profileNodeById(q_ptr->selectedProfile()->id()); - if (!currentNode) { - qWarning() << "Account must have a profile parent, doing nothing"; - return; - } - const bool changed = currentProfile->addAccount(acc); - - Node* account_pro = new Node; - account_pro->type = Node::Type::ACCOUNT; - account_pro->parent = currentNode; - account_pro->m_uContent.m_pAccount = acc; - account_pro->m_Index = currentNode->children.size(); - account_pro->m_ParentIndex = acc->index().row(); - - q_ptr->beginInsertRows(ProfileModel::instance().index(currentNode->m_Index,0), currentNode->children.size(), currentNode->children.size()); - currentNode->children << account_pro; - q_ptr->endInsertRows(); - - if (changed) - currentProfile->save(); -} - -QList<Account*> ProfileModel::getAccountsForProfile(const QString& id) -{ - QList<Account*> result; - auto profileNode = d_ptr->profileNodeById(id.toUtf8()); - if(!profileNode) - return result; - - for (auto childNode : profileNode->children) { - result << childNode->m_uContent.m_pAccount; - } - return result; -} - -Node* ProfileModelPrivate::profileNodeById(const QByteArray& id) -{ - foreach(auto p, m_lProfiles) { - if(p->m_uContent.m_pProfile->person()->uid() == id) - return p; - } - return nullptr; -} - -ProfileModel& ProfileModel::instance() -{ - static auto instance = new ProfileModel(QCoreApplication::instance()); - return *instance; -} - -ProfileModelPrivate::ProfileModelPrivate(ProfileModel* parent) : QObject(parent), q_ptr(parent) -{ - -} - -///Avoid creating an initialization loop -void ProfileModelPrivate::slotDelayedInit() -{ - connect(&AccountModel::instance(), &QAbstractItemModel::dataChanged , this, &ProfileModelPrivate::slotDataChanged ); - connect(&AccountModel::instance(), &QAbstractItemModel::rowsInserted , this, &ProfileModelPrivate::slotRowsInserted ); - connect(&AccountModel::instance(), &QAbstractItemModel::rowsMoved , this, &ProfileModelPrivate::slotRowsMoved ); - connect(&AccountModel::instance(), &QAbstractItemModel::layoutChanged, this, &ProfileModelPrivate::slotLayoutchanged ); - connect(&AccountModel::instance(), &AccountModel::accountRemoved , this, &ProfileModelPrivate::slotAccountRemoved); - connect(&AccountModel::instance(), &AccountModel::accountAdded , this, &ProfileModelPrivate::slotAccountAdded); - - // Load existing accounts - for (int i = 0; i < AccountModel::instance().rowCount(); i++) - slotAccountAdded(AccountModel::instance()[i]); -} - -ProfileModel::ProfileModel(QObject* parent) : QAbstractItemModel(parent), -CollectionManagerInterface<Profile>(this), d_ptr(new ProfileModelPrivate(this)) -{ - d_ptr->m_lMimes << RingMimes::PLAIN_TEXT << RingMimes::HTML_TEXT << RingMimes::ACCOUNT << RingMimes::PROFILE; - //Once LibRingClient is ready, start listening - QTimer::singleShot(0,d_ptr,SLOT(slotDelayedInit())); -} - -ProfileModel::~ProfileModel() -{ - while (d_ptr->m_lProfiles.size()) { - auto proNode = d_ptr->m_lProfiles[0]; - d_ptr->m_lProfiles.removeAt(0); - delete proNode; - } - delete d_ptr; -} - -QHash<int,QByteArray> ProfileModel::roleNames() const -{ - static QHash<int, QByteArray> roles = AccountModel::instance().roleNames(); - return roles; -} - -void ProfileModelPrivate::updateIndexes() -{ - for (int i = 0; i < m_lProfiles.size(); ++i) { - m_lProfiles[i]->m_Index = i; - for (int j = 0; j < m_lProfiles[i]->children.size(); ++j) { - m_lProfiles[i]->children[j]->m_Index = j; - } - } -} - -void ProfileModelPrivate::slotDataChanged(const QModelIndex& tl,const QModelIndex& br) -{ - if (!tl.isValid() || (!br.isValid())) - return; - - const QModelIndex& idx = q_ptr->mapFromSource(tl); - emit q_ptr->dataChanged(idx, idx); -} - -void ProfileModelPrivate::slotLayoutchanged() -{ - emit q_ptr->layoutChanged(); -} - -void ProfileModelPrivate::regenParentIndexes() -{ - foreach(auto proNode, m_lProfiles) { - foreach(Node* a, proNode->children) { - a->m_ParentIndex = a->m_uContent.m_pAccount->index().row(); - } - const QModelIndex par = q_ptr->index(proNode->m_Index,0,QModelIndex()); - emit q_ptr->dataChanged(q_ptr->index(0,0,par),q_ptr->index(proNode->children.size()-1,0,par)); - } -} - -void ProfileModelPrivate::slotAccountRemoved(Account* a) -{ - auto n = nodeForAccount(a); - - if (n && n->parent) { - const QModelIndex profIdx = q_ptr->index(n->parent->m_Index, 0); - if (profIdx.isValid()) { - const int accIdx = n->m_Index; - q_ptr->beginRemoveRows(profIdx, accIdx, accIdx); - n->parent->children.removeAt(accIdx); - for (int i = accIdx; i < n->parent->children.size(); i++) - n->parent->children[i]->m_Index--; - n->parent->m_uContent.m_pProfile->save(); - n->parent->m_uContent.m_pProfile->removeAccount(n->m_uContent.m_pAccount); - delete n; - q_ptr->endRemoveRows(); - } - } - regenParentIndexes(); -} - -Node* ProfileModelPrivate::nodeForAccount(const Account* a) -{ - for (auto pro : m_lProfiles) { - for (auto accNode : pro->children) { - if (accNode->m_uContent.m_pAccount == a) { - return accNode; - } - } - } - return nullptr; -} - -Node* ProfileModelPrivate::profileNodeForAccount(const Account* a) -{ - for (auto pro : m_lProfiles) { - for (auto accNode : pro->children) { - if (accNode->m_uContent.m_pAccount == a) { - return pro; - } - } - } - return nullptr; -} - -void ProfileModelPrivate::slotRowsInserted(const QModelIndex& index, int first, int last) -{ - Q_UNUSED(index) - Q_UNUSED(first) - Q_UNUSED(last) - regenParentIndexes(); -} - -void ProfileModelPrivate::slotRowsMoved(const QModelIndex& index, int first, int last, const QModelIndex& newPar, int newIdx) -{ - Q_UNUSED(index) - Q_UNUSED(first) - Q_UNUSED(last) - Q_UNUSED(newPar) - Q_UNUSED(newIdx) - regenParentIndexes(); -} - -QModelIndex ProfileModel::mapToSource(const QModelIndex& idx) const -{ - if (!idx.isValid() || !idx.parent().isValid() || idx.model() != this) - return QModelIndex(); - - Node* profile = static_cast<Node*>(idx.parent().internalPointer()); - return profile->children[idx.row()]->m_uContent.m_pAccount->index(); -} - -QModelIndex ProfileModel::mapFromSource(const QModelIndex& idx) const -{ - if (!idx.isValid() || idx.model() != &AccountModel::instance()) - return QModelIndex(); - - auto acc = AccountModel::instance().getAccountByModelIndex(idx); - auto accNode = d_ptr->nodeForAccount(acc); - - //Something is wrong, there is an orphan - if (!accNode) { - return QModelIndex(); - } - - if (!accNode) { - qDebug() << "No profile is assigned to this account" << acc->alias(); - } - return index(accNode->m_Index, 0, index(accNode->parent->m_Index, 0, QModelIndex())); -} - -QVariant ProfileModel::data(const QModelIndex& index, int role ) const -{ - if (!index.isValid()) - return QVariant(); - - auto currentNode = static_cast<Node*>(index.internalPointer()); - - switch (currentNode->type) { - case Node::Type::PROFILE: - return currentNode->m_uContent.m_pProfile->person()->roleData(role); - case Node::Type::ACCOUNT: - switch(role) { - case ProfileModelPrivate::c_OrderRole: - return currentNode->m_ParentIndex; - default: - return currentNode->m_uContent.m_pAccount->roleData(role); - } - } - - return QVariant(); -} - -int ProfileModel::rowCount(const QModelIndex& parent ) const -{ - if (parent.isValid()) { - auto proNode = static_cast<Node*>(parent.internalPointer()); - return proNode->children.size(); - } - return d_ptr->m_lProfiles.size(); -} - -int ProfileModel::columnCount(const QModelIndex& parent ) const -{ - Q_UNUSED(parent) - return 1; -} - -QModelIndex ProfileModel::parent(const QModelIndex& idx ) const -{ - Node* current = static_cast<Node*>(idx.internalPointer()); - - if (!current) - return QModelIndex(); - switch (current->type) { - case Node::Type::PROFILE: - return QModelIndex(); - case Node::Type::ACCOUNT: - return index(current->parent->m_Index, 0, QModelIndex()); - } - return QModelIndex(); -} - -QModelIndex ProfileModel::index( int row, int column, const QModelIndex& parent ) const -{ - Node* current = static_cast<Node*>(parent.internalPointer()); - if(parent.isValid() && current && !column && row >= 0 && row < current->children.size()) { - return createIndex(row, 0, current->children[row]); - } - else if(row < d_ptr->m_lProfiles.size() && row >= 0 && !column) { - return createIndex(row, 0, d_ptr->m_lProfiles[row]); - } - return QModelIndex(); -} - -Qt::ItemFlags ProfileModel::flags(const QModelIndex& index ) const -{ - if (!index.isValid()) - return Qt::ItemIsEnabled; - - Node* current = static_cast<Node*>(index.internalPointer()); - - if (current && current->parent) - return QAbstractItemModel::flags(index) - | Qt::ItemIsUserCheckable - | Qt::ItemIsEnabled - | Qt::ItemIsSelectable - | Qt::ItemIsDragEnabled - | Qt::ItemIsDropEnabled; - - return QAbstractItemModel::flags(index) - | Qt::ItemIsEnabled - | Qt::ItemIsSelectable - | Qt::ItemIsDragEnabled - | Qt::ItemIsDropEnabled; -} - -QStringList ProfileModel::mimeTypes() const -{ - return d_ptr->m_lMimes; -} - -QMimeData* ProfileModel::mimeData(const QModelIndexList &indexes) const -{ - auto mMimeData = new QMimeData(); - - //FIXME: this won't work for multiple indexes - for (const QModelIndex& index : indexes) { - Node* current = static_cast<Node*>(index.internalPointer()); - - if (!index.isValid() || !current) { - qWarning() << "invalid index to create mimeData, ignoring"; - continue; - } - - switch (current->type) { - case Node::Type::PROFILE: - mMimeData->setData(RingMimes::PROFILE , current->m_uContent.m_pProfile->person()->uid()); - break; - case Node::Type::ACCOUNT: - mMimeData->setData(RingMimes::ACCOUNT , current->m_uContent.m_pAccount->id()); - break; - default: - qWarning() << "Unknown node type to create mimedata"; - return nullptr; - } - - } - return mMimeData; -} - -///Return valid payload types -int ProfileModel::acceptedPayloadTypes() const -{ - return CallModel::DropPayloadType::ACCOUNT; -} - -QItemSelectionModel* ProfileModel::selectionModel() const -{ - if (!d_ptr->m_pSelectionModel) { - d_ptr->m_pSelectionModel = new QItemSelectionModel(const_cast<ProfileModel*>(this)); - - connect(d_ptr->m_pSelectionModel, &QItemSelectionModel::currentChanged, [this](const QModelIndex& i) { - const QModelIndex& accIdx = mapToSource(i); - AccountModel::instance().selectionModel()->setCurrentIndex(accIdx, QItemSelectionModel::ClearAndSelect); - }); - } - - return d_ptr->m_pSelectionModel; -} - -QItemSelectionModel* ProfileModel::sortedProxySelectionModel() const -{ - if (!d_ptr->m_pSortedProxySelectionModel) { - d_ptr->m_pSortedProxySelectionModel = new QItemSelectionModel(static_cast<QSortFilterProxyModel*>(sortedProxyModel())); - - connect(d_ptr->m_pSortedProxySelectionModel, &QItemSelectionModel::currentChanged, [this](const QModelIndex& i) { - const QModelIndex& accIdx = mapToSource( - static_cast<QSortFilterProxyModel*>(sortedProxyModel())->mapToSource(i) - ); - AccountModel::instance().selectionModel()->setCurrentIndex(accIdx, QItemSelectionModel::ClearAndSelect); - }); - } - - return d_ptr->m_pSortedProxySelectionModel; -} - -QAbstractItemModel* ProfileModel::sortedProxyModel() const -{ - if (!d_ptr->m_pSortedProxyModel) { - d_ptr->m_pSortedProxyModel = new QSortFilterProxyModel(&ProfileModel::instance()); - d_ptr->m_pSortedProxyModel->setSourceModel(const_cast<ProfileModel*>(this)); - d_ptr->m_pSortedProxyModel->setSortRole(ProfileModelPrivate::c_OrderRole); - d_ptr->m_pSortedProxyModel->sort(0); - } - - return d_ptr->m_pSortedProxyModel; -} - -bool ProfileModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) -{ - Q_UNUSED(action) - - QModelIndex accountIdx, profileIdx; - - // For some reasons, it seem that row and column are {-1,-1} when using a - // proxy model. The proxy is required to properly sort the accounts, so - // this code "fix" the values - if (parent.parent().isValid()) { - accountIdx = parent; - profileIdx = parent.parent(); - row = accountIdx.row(); - column = accountIdx.column(); - } - else { - accountIdx = index(row, column, parent); - profileIdx = parent; - } - - if(((!profileIdx.isValid()) && row < 0) || column > 0) { - qDebug() << "Row or column invalid"; - return false; - } - - if (data->hasFormat(RingMimes::ACCOUNT)) { - qDebug() << "Dropping account"; - - const QByteArray accountId = data->data(RingMimes::ACCOUNT); - Node* newProfile = nullptr; - int destIdx = 0, indexOfAccountToMove = -1; // Where to insert in account list of profile - - // Dropped on a profile index, append it at the end - if(profileIdx.isValid()) { - qDebug() << "Dropping on profile title"; - newProfile = static_cast<Node*>(profileIdx.internalPointer()); - destIdx = 0; - } - // Dropped on an account - else if (profileIdx.isValid()) { - newProfile = static_cast<Node*>(profileIdx.internalPointer()); - destIdx = row; - } - - if ((!newProfile) || (!newProfile->m_uContent.m_pProfile)) { - qDebug() << "Invalid profile"; - return false; - } - - // Use the account ID to locate the original location - auto acc = AccountModel::instance().getById(accountId); - - if (!acc) - return false; - - Node* accountProfile = d_ptr->profileNodeForAccount(acc); - foreach (auto accNode, accountProfile->children) { - if(accNode->m_uContent.m_pAccount->id() == accountId) { - indexOfAccountToMove = accNode->m_Index; - break; - } - } - - if(indexOfAccountToMove == -1) { - qDebug() << "Failed to obtain the account ID"; - return false; - } - - if(!beginMoveRows(index(accountProfile->m_Index, 0), indexOfAccountToMove, indexOfAccountToMove, parent, destIdx)) { - return false; - } - - Node* accountToMove = accountProfile->children.at(indexOfAccountToMove); - qDebug() << "Moving:" << accountToMove->m_uContent.m_pAccount->alias(); - accountProfile->children.remove(indexOfAccountToMove); - accountToMove->parent = newProfile; - newProfile->children.insert(destIdx, accountToMove); - d_ptr->updateIndexes(); - - for (auto colI :collections(CollectionInterface::SupportedFeatures::ADD)) { - colI->editor<Profile>()->save(newProfile->m_uContent.m_pProfile); - } - endMoveRows(); - } - else if (data->hasFormat(RingMimes::PROFILE)) { - qDebug() << "Dropping profile on row" << row; - - int destinationRow = -1; - if(row < 0) { - // drop on bottom of the list - destinationRow = d_ptr->m_lProfiles.size(); - } - else { - destinationRow = row; - } - - auto moving = d_ptr->profileNodeById(data->data(RingMimes::PROFILE)); - if(!moving) - return false; - - if(!beginMoveRows(QModelIndex(), moving->m_Index, moving->m_Index, QModelIndex(), destinationRow)) { - return false; - } - - d_ptr->m_lProfiles.removeAt(moving->m_Index); - d_ptr->m_lProfiles.insert(destinationRow, moving); - d_ptr->updateIndexes(); - endMoveRows(); - - return true; - } - return false; -} - -bool ProfileModel::setData(const QModelIndex& index, const QVariant &value, int role ) -{ - if (!index.isValid()) - return false; - - Node* current = static_cast<Node*>(index.internalPointer()); - - if (current->parent) { - return AccountModel::instance().setData(mapToSource(index),value,role); - } - return false; -} - -QVariant ProfileModel::headerData(int section, Qt::Orientation orientation, int role ) const -{ - Q_UNUSED(section) - Q_UNUSED(orientation) - if (role == Qt::DisplayRole) return tr("Profiles"); - return QVariant(); -} - -void ProfileModel::collectionAddedCallback(CollectionInterface* backend) -{ - Q_UNUSED(backend) -} - -bool ProfileModel::addItemCallback(const Profile* pro) -{ - auto proNode = new Node ; - proNode->type = Node::Type::PROFILE; - proNode->m_uContent.m_pProfile = const_cast<Profile*>(pro); - proNode->m_Index = d_ptr->m_lProfiles.size(); - - beginInsertRows({}, d_ptr->m_lProfiles.size(), d_ptr->m_lProfiles.size()); - d_ptr->m_lProfiles << proNode; - endInsertRows(); - - selectionModel()->setCurrentIndex(index(proNode->m_Index, 0), QItemSelectionModel::ClearAndSelect); - - proNode->m_ChangedConn = connect(pro->person(), &Person::changed, [this, proNode]() { - if (proNode->m_uContent.m_pProfile->person()->isActive()) { - const QModelIndex idx = index(proNode->m_Index, 0); - emit dataChanged(idx, idx); - } - }); - return true; -} - -bool ProfileModel::removeItemCallback(const Profile* item) -{ - int nodeIdx = -1; - bool isFound = false; - - while (not isFound && ++nodeIdx < d_ptr->m_lProfiles.size()) { - isFound = (d_ptr->m_lProfiles[nodeIdx]->m_uContent.m_pProfile == item); - } - - // Remove the node and update all other indices - if (isFound) { - // Remove the profile - beginRemoveRows(QModelIndex(), nodeIdx, nodeIdx); - auto toDelete = d_ptr->m_lProfiles[nodeIdx]; - d_ptr->m_lProfiles.removeAt(nodeIdx); - d_ptr->updateIndexes(); - delete toDelete; - endRemoveRows(); - } - return true; -} - -/** - * Remove an unused profile - * - * @return If removing the profile has been successful - */ -bool ProfileModel::remove(const QModelIndex& idx) -{ - QModelIndex realIdx = idx; - - // Helper to unwind the proxies - while(realIdx.isValid() && realIdx.model() != this) { - if (qobject_cast<const QAbstractProxyModel*>(realIdx.model())) - realIdx = qobject_cast<const QAbstractProxyModel*>(realIdx.model())->mapToSource(realIdx); - else { - realIdx = QModelIndex(); - break; - } - } - - // Ensure it is a profile that can be removed - if (!realIdx.isValid()) { - qDebug() << "Failed to remove profile: invalid index"; - return false; - } - - Node* n = static_cast<Node*>(realIdx.internalPointer()); - - if (n->type != Node::Type::PROFILE) { - qDebug() << "Failed to remove profile: It is not a profile" - << (int)n->type << n->m_uContent.m_pProfile->person() - << realIdx.data(Qt::DisplayRole); - return false; - } - - if (n->children.size()) { - qDebug() << "Failed to remove profile: It is in use"; - return false; - } - - for (auto colI : collections(CollectionInterface::SupportedFeatures::ADD)) { - colI->editor<Profile>()->remove(n->m_uContent.m_pProfile); - } - return true; -} - -bool ProfileModelPrivate::addProfile(Person* person, const QString& name, CollectionInterface* col) -{ - Profile* profile = nullptr; - if (!col) { - qWarning() << "Can't add profile, no collection specified"; - return false; - } - - if (person) { - profile = new Profile(col, person); - } - else { - auto p = new Person(col); - profile = new Profile(col, p); - QString profileName = name; - if (profileName.isEmpty()) { - profileName = tr("New profile"); - } - profile->person()->setFormattedName(profileName); - } - - col->editor<Profile>()->addNew(profile); - return true; -} - -/** - * Create a new profile - * - * @param person an optional person to use for the vCard template - */ -bool ProfileModel::add(Person* person) -{ - if (collections(CollectionInterface::SupportedFeatures::ADD).size()) - return d_ptr->addProfile(person, QString(), collections(CollectionInterface::SupportedFeatures::ADD)[0]); - return false; -} - -/** - * Create a new profile - * - * @param name The new profile name - */ -bool ProfileModel::add(const QString& name) -{ - if (collections(CollectionInterface::SupportedFeatures::ADD).size()) - return d_ptr->addProfile(nullptr, name, collections(CollectionInterface::SupportedFeatures::ADD)[0]); - return false; -} - -Profile* ProfileModel::selectedProfile() const -{ - return getProfile(ProfileModel::instance().selectionModel()->currentIndex()); -} - -Profile* ProfileModel::getProfile(const QModelIndex& idx) const -{ - if ((!idx.isValid()) || (idx.model() != this)) - return nullptr; - - const auto current = static_cast<Node*>(idx.internalPointer()); - switch (current->type) { - case Node::Type::PROFILE: - return current->m_uContent.m_pProfile; - case Node::Type::ACCOUNT: - return current->parent->m_uContent.m_pProfile; - default: - qWarning() << "Unknown node type to create mimedata"; - return nullptr; - } -} - -#include "profilemodel.moc" diff --git a/src/profilemodel.h b/src/profilemodel.h deleted file mode 100644 index 39fc217f..00000000 --- a/src/profilemodel.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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" - -// Qt -#include <QtCore/QAbstractItemModel> -class QItemSelectionModel; -class QStringList; - -// Ring -#include "collectionmanagerinterface.h" -class Person; -class ProfileContentBackend; -class VCardMapper; -class ProfileModelPrivate; -class Profile; -class Account; - -template<typename T> class CollectionMediator; - -class LIB_EXPORT ProfileModel : - public QAbstractItemModel, public CollectionManagerInterface<Profile> { - Q_OBJECT - friend class ProfileContentBackend; - friend class ProfileEditor; -public: - explicit ProfileModel(QObject* parent = nullptr); - virtual ~ProfileModel(); - static ProfileModel& instance(); - - //Abstract model member - virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) 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 bool setData ( const QModelIndex& index, const QVariant &value, int role ) override; - virtual QModelIndex index ( int row, int column, const QModelIndex& parent=QModelIndex() ) const override; - virtual QModelIndex parent ( const QModelIndex& index ) const override; - virtual QVariant headerData ( int section, Qt::Orientation orientation, int role ) const override; - virtual QStringList mimeTypes ( ) const override; - virtual QMimeData* mimeData ( const QModelIndexList &indexes ) const override; - virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; - virtual QHash<int,QByteArray> roleNames() const override; - - //Getter - QModelIndex mapToSource (const QModelIndex& idx) const; - QModelIndex mapFromSource(const QModelIndex& idx) const; - int acceptedPayloadTypes() const; - QItemSelectionModel* selectionModel() const; - QItemSelectionModel* sortedProxySelectionModel() const; - QAbstractItemModel* sortedProxyModel() const; - Profile* getProfile(const QModelIndex& idx) const; - Profile* selectedProfile() const; - - QList<Account*> getAccountsForProfile(const QString& id); - -private: - ProfileModelPrivate* d_ptr; - Q_DECLARE_PRIVATE(ProfileModel) - - //Backend interface - virtual void collectionAddedCallback(CollectionInterface* backend) override; - virtual bool addItemCallback(const Profile* item) override; - virtual bool removeItemCallback(const Profile* item) override; - -Q_SIGNALS: - bool profileUpdated(const Profile* item); - -public Q_SLOTS: - bool remove(const QModelIndex& idx); - bool add(Person* person = nullptr); - bool add(const QString& name); -}; diff --git a/src/protocolmodel.cpp b/src/protocolmodel.cpp deleted file mode 100644 index 8a4289c3..00000000 --- a/src/protocolmodel.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "protocolmodel.h" - -//Qt -#include <QtCore/QCoreApplication> -#include <QtCore/QItemSelectionModel> - -//Ring daemon -#include <account_const.h> - -//Ring -#include "account.h" - -class ProtocolModelPrivate final : public QObject -{ - Q_OBJECT -public: - - ProtocolModelPrivate(Account* a); - - mutable QItemSelectionModel* m_pSelectionModel; - Account* m_pAccount; - - //Constants - struct ToolTips { - static const QString RING_ACCOUNT_TOOLTIP; - static const QString SIP_ACCOUNT_TOOLTIP ; - }; - -public Q_SLOTS: - void slotSelectionChanged(const QModelIndex& idx); -}; - -const QString ProtocolModelPrivate::ToolTips::RING_ACCOUNT_TOOLTIP = QObject::tr("Ring Account"); -const QString ProtocolModelPrivate::ToolTips::SIP_ACCOUNT_TOOLTIP = QObject::tr("SIP Account" ); - - -ProtocolModelPrivate::ProtocolModelPrivate(Account* a) : m_pSelectionModel(nullptr), m_pAccount(a) -{ - -} - -ProtocolModel::ProtocolModel(Account* a) : QAbstractListModel(QCoreApplication::instance()), -d_ptr(new ProtocolModelPrivate(a)) -{ - -} - -ProtocolModel::~ProtocolModel() -{ - delete d_ptr; -} - -QHash<int,QByteArray> ProtocolModel::roleNames() const -{ - static QHash<int, QByteArray> roles = QAbstractItemModel::roleNames(); - /*static bool initRoles = false; - if (!initRoles) { - initRoles = true; - - }*/ - return roles; -} - -//Model functions -QVariant ProtocolModel::data( const QModelIndex& index, int role) const -{ - if (!index.isValid()) return QVariant(); - Account::Protocol proto = static_cast<Account::Protocol>(index.row()); - if (role == Qt::DisplayRole) { - switch (proto) { - case Account::Protocol::SIP : - return DRing::Account::ProtocolNames::SIP; - case Account::Protocol::RING : - return DRing::Account::ProtocolNames::RING; - case Account::Protocol::COUNT__: - break; - }; - } - else if (role == Qt::UserRole) { - return QVariant::fromValue(proto); - } - return QVariant(); -} - -int ProtocolModel::rowCount( const QModelIndex& parent ) const -{ - return parent.isValid()?0:enum_class_size<Account::Protocol>(); -} - -Qt::ItemFlags ProtocolModel::flags( const QModelIndex& index ) const -{ - const bool isNew = d_ptr->m_pAccount ? d_ptr->m_pAccount->isNew() : true; - if (!index.isValid() || (!isNew)) return Qt::NoItemFlags; - - //Account type cannot be changed, the daemon doesn't support that and crash - //it was considered a client responsibility to disallow it. It is not worth - //fixing - return (Qt::ItemIsEnabled|Qt::ItemIsSelectable); -} - -bool ProtocolModel::setData( const QModelIndex& index, const QVariant &value, int role) -{ - Q_UNUSED(index) - Q_UNUSED(value) - Q_UNUSED(role ) - return false; -} - -QItemSelectionModel* ProtocolModel::selectionModel() const -{ - if (!d_ptr->m_pSelectionModel) { - d_ptr->m_pSelectionModel = new QItemSelectionModel(const_cast<ProtocolModel*>(this)); - - const Account::Protocol proto = d_ptr->m_pAccount ? d_ptr->m_pAccount->protocol() : Account::Protocol::RING; - - const QModelIndex& idx = index(static_cast<int>(proto),0); - d_ptr->m_pSelectionModel->setCurrentIndex(idx,QItemSelectionModel::ClearAndSelect); - - connect(d_ptr->m_pSelectionModel,&QItemSelectionModel::currentChanged,d_ptr,&ProtocolModelPrivate::slotSelectionChanged); - } - - return d_ptr->m_pSelectionModel; -} - -void ProtocolModelPrivate::slotSelectionChanged(const QModelIndex& idx) -{ - if (!m_pAccount || !idx.isValid()) - return; - - m_pAccount->setProtocol(static_cast<Account::Protocol>(idx.row())); -} - -#include <protocolmodel.moc> diff --git a/src/protocolmodel.h b/src/protocolmodel.h deleted file mode 100644 index 988e1996..00000000 --- a/src/protocolmodel.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 <QtCore/QAbstractListModel> - -//Qt -class QItemSelectionModel; - -//Ring -class ProtocolModelPrivate; -class Account; - -/** - * This model is used to select the account protocol when creating a new account. - * It then become a simple readonly model. - */ -class LIB_EXPORT ProtocolModel : public QAbstractListModel { - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" - Q_OBJECT - #pragma GCC diagnostic pop - -public: - - enum class Role { - Protocol = Qt::UserRole - }; - - //Private constructor, can only be called by 'Account' - explicit ProtocolModel(Account* a = nullptr); - virtual ~ProtocolModel(); - - //Model functions - virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const override; - virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const override; - virtual Qt::ItemFlags flags ( const QModelIndex& index ) const override; - virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) override; - virtual QHash<int,QByteArray> roleNames() const override; - - //Getters - QItemSelectionModel* selectionModel() const; - -private: - ProtocolModelPrivate* d_ptr; - Q_DECLARE_PRIVATE(ProtocolModel) - -}; -Q_DECLARE_METATYPE(ProtocolModel*) - diff --git a/src/ringtone.cpp b/src/ringtone.cpp deleted file mode 100644 index a5525054..00000000 --- a/src/ringtone.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "ringtone.h" - -//Qt -#include <QtCore/QUrl> -#include <QtCore/QDir> - -class RingtonePrivate -{ -public: - RingtonePrivate(); - QString m_Path; - QString m_Name; -}; - -RingtonePrivate::RingtonePrivate() -{ - -} - -Ringtone::Ringtone(QObject* parent) : ItemBase(parent), d_ptr(new RingtonePrivate()) -{ - -} - -Ringtone::~Ringtone() -{ - delete d_ptr; -} - -QString Ringtone::path() const -{ - return d_ptr->m_Path; -} - -QString Ringtone::name() const -{ - return d_ptr->m_Name; -} - -void Ringtone::setPath(const QString& path) -{ - d_ptr->m_Path = QDir::toNativeSeparators(path); -} - -void Ringtone::setName(const QString& name) -{ - d_ptr->m_Name = name; -} diff --git a/src/ringtone.h b/src/ringtone.h deleted file mode 100644 index 2e03f0cc..00000000 --- a/src/ringtone.h +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2015-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 RingtonePrivate; - -class LIB_EXPORT Ringtone : public ItemBase -{ - Q_OBJECT -public: - Ringtone(QObject* parent = nullptr); - virtual ~Ringtone(); - - //Getter - QString path () const; - QString name () const; - - //Setter - void setPath (const QString& path ); - void setName (const QString& name ); - -private: - RingtonePrivate* d_ptr; - Q_DECLARE_PRIVATE(Ringtone) -}; diff --git a/src/ringtonemodel.cpp b/src/ringtonemodel.cpp deleted file mode 100644 index 27a8121d..00000000 --- a/src/ringtonemodel.cpp +++ /dev/null @@ -1,300 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "ringtonemodel.h" - -//Qt -#include <QtCore/QTimer> -#include <QtCore/QFileInfo> -#include <QtCore/QItemSelectionModel> -#include <QtCore/QCoreApplication> -#include <QtCore/QUrl> - -//Ring -#include "dbus/configurationmanager.h" -#include "dbus/callmanager.h" -#include "account.h" -#include "accountmodel.h" -#include "ringtone.h" -#include <localringtonecollection.h> - -class RingtoneModelPrivate final : public QObject -{ - Q_OBJECT -public: - - RingtoneModelPrivate(RingtoneModel*); - - //Attributes - QVector<Ringtone*> m_lRingtone ; - QTimer* m_pTimer ; - Ringtone* m_pCurrent ; - QHash<Account*,int> m_hCurrent ; - QHash<Account*,QItemSelectionModel*> m_hSelectionModels ; - LocalRingtoneCollection* m_pCollection ; - QHash<const Ringtone*,Account*> m_hPendingSelection; - bool m_isPlaying ; - - //Helpers - int currentIndex(Account* a) const; - -private: - RingtoneModel* q_ptr; - -public Q_SLOTS: - void slotStopTimer(); - -}; - -RingtoneModelPrivate::RingtoneModelPrivate(RingtoneModel* parent) - : q_ptr(parent) - , m_pTimer(nullptr) - , m_pCurrent(nullptr) - , m_isPlaying(false) -{ - -} - -RingtoneModel::RingtoneModel(QObject* parent) - : QAbstractTableModel(parent) - , CollectionManagerInterface<Ringtone>(this) - , d_ptr(new RingtoneModelPrivate(this)) -{ - d_ptr->m_pCollection = addCollection<LocalRingtoneCollection>(); - QObject::connect(AccountModel::instance().selectionModel(), - &QItemSelectionModel::currentChanged, - [=](const QModelIndex ¤t, const QModelIndex &previous) { - Q_UNUSED(current) - if (d_ptr->m_isPlaying && previous.isValid()) { - auto acc = AccountModel::instance().getAccountByModelIndex(previous); - auto qIdx = d_ptr->m_hSelectionModels[acc]->currentIndex(); - play(qIdx); - } - }); -} - -RingtoneModel& RingtoneModel::instance() -{ - static auto instance = new RingtoneModel(QCoreApplication::instance()); - return *instance; -} - -RingtoneModel::~RingtoneModel() -{ - while (d_ptr->m_lRingtone.size()) { - Ringtone* ringtone = d_ptr->m_lRingtone[0]; - d_ptr->m_lRingtone.removeAt(0); - delete ringtone; - } - delete d_ptr; -} - -QHash<int,QByteArray> RingtoneModel::roleNames() const -{ - static QHash<int, QByteArray> roles = QAbstractItemModel::roleNames(); - static bool initRoles = false; - if (!initRoles) { - initRoles = true; - roles[Role::FullPath ] = "FullPath"; - } - return roles; -} - -bool RingtoneModel::isPlaying() -{ - return d_ptr->m_isPlaying; -} - -QVariant RingtoneModel::data( const QModelIndex& index, int role ) const -{ - if (!index.isValid()) - return QVariant(); - const Ringtone* info = d_ptr->m_lRingtone[index.row()]; - switch (index.column()) { - case 0: - switch (role) { - case Qt::DisplayRole: - return info->name(); - case Role::FullPath: - return info->path(); - }; - break; - case 1: - switch (role) { - case Role::FullPath: - return info->path(); - }; - break; - }; - return QVariant(); -} - -int RingtoneModel::rowCount( const QModelIndex& parent ) const -{ - if (!parent.isValid()) - return d_ptr->m_lRingtone.size(); - return 0; -} - -int RingtoneModel::columnCount( const QModelIndex& parent ) const -{ - if (parent.isValid()) - return 0; - return 1; -} - -Qt::ItemFlags RingtoneModel::flags( const QModelIndex& index ) const -{ - if (index.isValid() && !index.parent().isValid()) - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; - return Qt::NoItemFlags; -} - -///This is a read only model -bool RingtoneModel::setData( const QModelIndex& index, const QVariant &value, int role) -{ - Q_UNUSED(index) - Q_UNUSED(value) - Q_UNUSED(role ) - return false; -} - -Ringtone* RingtoneModel::currentRingTone(Account* a) const -{ - if ((!a) || (!d_ptr->m_hSelectionModels[a])) - return nullptr; - - const QModelIndex& idx = d_ptr->m_hSelectionModels[a]->currentIndex(); - - return idx.isValid() ? d_ptr->m_lRingtone[idx.row()] : nullptr; -} - -int RingtoneModelPrivate::currentIndex(Account* a) const -{ - const QString rt = a->ringtonePath(); - for (int i=0;i<m_lRingtone.size();i++) { - Ringtone* info = m_lRingtone[i]; - if (info->path() == rt) - return i; - } - return 0; -} - -QItemSelectionModel* RingtoneModel::selectionModel(Account* a) const -{ - if (!d_ptr->m_hSelectionModels[a]) { - d_ptr->m_hSelectionModels[a] = new QItemSelectionModel(const_cast<RingtoneModel*>(this)); - d_ptr->m_hSelectionModels[a]->setCurrentIndex(index(d_ptr->currentIndex(a),0), QItemSelectionModel::ClearAndSelect); - - connect(d_ptr->m_hSelectionModels[a],&QItemSelectionModel::currentChanged, [a,this](const QModelIndex& idx) { - if (idx.isValid()) { - a->setRingtonePath(d_ptr->m_lRingtone[idx.row()]->path()); - } - }); - - } - - return d_ptr->m_hSelectionModels[a]; -} - -void RingtoneModel::play(const QModelIndex& idx) -{ - if (idx.isValid()) { - Ringtone* info = d_ptr->m_lRingtone[idx.row()]; - if (d_ptr->m_pCurrent && info == d_ptr->m_pCurrent) { - d_ptr->slotStopTimer(); - return; - } - CallManagerInterface& callManager = CallManager::instance(); - Q_NOREPLY callManager.startRecordedFilePlayback(info->path()); - if (!d_ptr->m_pTimer) { - d_ptr->m_pTimer = new QTimer(this); - d_ptr->m_pTimer->setInterval(10000); - connect(d_ptr->m_pTimer,SIGNAL(timeout()),d_ptr,SLOT(slotStopTimer())); - } - else if (d_ptr->m_pTimer->isActive()) { - d_ptr->m_pTimer->stop(); - } - d_ptr->m_pTimer->start(); - d_ptr->m_isPlaying = true; - emit dataChanged(index(idx.row(),0),index(idx.row(),1)); - d_ptr->m_pCurrent = info; - } -} - -void RingtoneModelPrivate::slotStopTimer() -{ - if (m_pCurrent) { - CallManagerInterface& callManager = CallManager::instance(); - callManager.stopRecordedFilePlayback(); - m_isPlaying = false; - const QModelIndex& idx = q_ptr->index(m_lRingtone.indexOf(m_pCurrent),0); - emit q_ptr->dataChanged(idx,q_ptr->index(idx.row(),1)); - m_pCurrent = nullptr; - m_pTimer->stop(); - } -} - -void RingtoneModel::collectionAddedCallback(CollectionInterface* backend) -{ - Q_UNUSED(backend) -} - -bool RingtoneModel::addItemCallback(const Ringtone* item) -{ - Q_UNUSED(item) - beginInsertRows(QModelIndex(),d_ptr->m_lRingtone.size(),d_ptr->m_lRingtone.size()); - d_ptr->m_lRingtone << const_cast<Ringtone*>(item); - endInsertRows(); - - if (auto a = d_ptr->m_hPendingSelection[item]) { - - if (auto sm = d_ptr->m_hSelectionModels[a]) - sm->setCurrentIndex(index(rowCount()-1,0), QItemSelectionModel::ClearAndSelect); - else - a->setRingtonePath(item->path()); - - d_ptr->m_hPendingSelection[item] = nullptr; - } - - return true; -} - -bool RingtoneModel::removeItemCallback(const Ringtone* item) -{ - Q_UNUSED(item) - return true; -} - -bool RingtoneModel::add(const QUrl& path, Account* autoSelect) -{ - auto r = new Ringtone(this); - r->setPath(path.toLocalFile()); - r->setName(QFile(path.toLocalFile()).fileName()); - - if (autoSelect) - d_ptr->m_hPendingSelection[r] = autoSelect; - - d_ptr->m_pCollection->add(r); - - //TODO check the file type - //TODO avoid duplicates - - return true; -} - -#include <ringtonemodel.moc> diff --git a/src/ringtonemodel.h b/src/ringtonemodel.h deleted file mode 100644 index 2e29fa18..00000000 --- a/src/ringtonemodel.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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" - -//Qt -#include <QtCore/QAbstractTableModel> -class QTimer; -class QItemSelectionModel; - -//Ring -#include "collectionmanagerinterface.h" -class Account; -class RingtoneModelPrivate; -class Ringtone; - -///RingtoneModel: A model for account ringtons -class LIB_EXPORT RingtoneModel : public QAbstractTableModel, public CollectionManagerInterface<Ringtone> -{ - Q_OBJECT -public: - - enum Role { - FullPath = 100, - }; - - virtual ~RingtoneModel(); - - //Model functions - virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) 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 bool setData ( const QModelIndex& index, const QVariant &value, int role) override; - virtual QHash<int,QByteArray> roleNames() const override; - - //Getters - Ringtone* currentRingTone(Account* a) const; - QItemSelectionModel* selectionModel(Account* a) const; - bool isPlaying(); - - //Mutator - void play(const QModelIndex& index); - bool add(const QUrl& path, Account* autoSelect = nullptr); - - static RingtoneModel& instance(); - -private: - explicit RingtoneModel(QObject* parent = nullptr); - - RingtoneModelPrivate* d_ptr; - Q_DECLARE_PRIVATE(RingtoneModel) - - //Collection interface - virtual void collectionAddedCallback(CollectionInterface* backend) override; - virtual bool addItemCallback (const Ringtone* item ) override; - virtual bool removeItemCallback (const Ringtone* item ) override; - -}; diff --git a/src/smartinfohub.cpp b/src/smartinfohub.cpp index cea8c6b5..73288bc0 100644 --- a/src/smartinfohub.cpp +++ b/src/smartinfohub.cpp @@ -18,7 +18,6 @@ #include "smartinfohub.h" #include "private/smartInfoHub_p.h" -#include "callmodel.h" #include "typedefs.h" #include <dbus/videomanager.h> diff --git a/src/tlsmethodmodel.cpp b/src/tlsmethodmodel.cpp deleted file mode 100644 index b7149ed4..00000000 --- a/src/tlsmethodmodel.cpp +++ /dev/null @@ -1,205 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 "tlsmethodmodel.h" - -//Qt -#include <QtCore/QCoreApplication> -#include <QtCore/QItemSelectionModel> - -//Ring daemon -#include <account_const.h> - -//Ring -#include "account.h" - -class TlsMethodModelPrivate final : public QObject { - Q_OBJECT -public: - - TlsMethodModelPrivate(Account* a); - - class Name { - public: - static const QString DEFAULT ; - constexpr static const char* TLSv1 = "TLSv1" ; - constexpr static const char* TLSv1_1 = "TLSv1.1"; - constexpr static const char* TLSv1_2 = "TLSv1.2"; - }; - - - class DaemonName { - public: - constexpr static const char* DEFAULT = "Default"; - constexpr static const char* TLSv1 = "TLSv1" ; - constexpr static const char* TLSv1_1 = "TLSv1.1"; - constexpr static const char* TLSv1_2 = "TLSv1.2"; - }; - - static const char* toDaemonName(TlsMethodModel::Type type); - static TlsMethodModel::Type fromDaemonName(const QString& name); - bool isRing; - - mutable QItemSelectionModel* m_pSelectionModel; - Account* m_pAccount; - -public Q_SLOTS: - void slotSelectionChanged(const QModelIndex& idx); -}; - -const QString TlsMethodModelPrivate::Name::DEFAULT = QObject::tr("Default", "Default TLS protocol version"); - -TlsMethodModelPrivate::TlsMethodModelPrivate(Account* a) : m_pSelectionModel(nullptr), m_pAccount(a), isRing(false) -{ - isRing = a->protocol() == Account::Protocol::RING; -} - -TlsMethodModel::TlsMethodModel(Account* a) : QAbstractListModel(QCoreApplication::instance()), -d_ptr(new TlsMethodModelPrivate(a)) -{ - -} - -TlsMethodModel::~TlsMethodModel() -{ - delete d_ptr; -} - -QHash<int,QByteArray> TlsMethodModel::roleNames() const -{ - static QHash<int, QByteArray> roles = QAbstractItemModel::roleNames(); - /*static bool initRoles = false; - if (!initRoles) { - initRoles = true; - - }*/ - return roles; -} - -//Model functions -QVariant TlsMethodModel::data( const QModelIndex& index, int role) const -{ - if (!index.isValid()) return QVariant(); - TlsMethodModel::Type method = static_cast<TlsMethodModel::Type>(index.row()); - if (role == Qt::DisplayRole) { - - if (d_ptr->isRing) - return tr("Automatic"); - - switch (method) { - case TlsMethodModel::Type::DEFAULT: - return TlsMethodModelPrivate::Name::DEFAULT; - case TlsMethodModel::Type::TLSv1_0: - return TlsMethodModelPrivate::Name::TLSv1; - case TlsMethodModel::Type::TLSv1_1: - return TlsMethodModelPrivate::Name::TLSv1_1; - case TlsMethodModel::Type::TLSv1_2: - return TlsMethodModelPrivate::Name::TLSv1_2; - case TlsMethodModel::Type::COUNT__: - break; - }; - } - return QVariant(); -} - -int TlsMethodModel::rowCount( const QModelIndex& parent ) const - -{ - // In the RING case, only the "default" encryption type can be used - return parent.isValid() ? 0 : d_ptr->isRing ? 1 : static_cast<int>(TlsMethodModel::Type::COUNT__); -} - -Qt::ItemFlags TlsMethodModel::flags( const QModelIndex& index ) const -{ - if (!index.isValid()) return Qt::NoItemFlags; - return Qt::ItemIsEnabled|Qt::ItemIsSelectable; -} - -bool TlsMethodModel::setData( const QModelIndex& index, const QVariant &value, int role) -{ - Q_UNUSED(index) - Q_UNUSED(value) - Q_UNUSED(role ) - return false; -} - -///Translate enum type to QModelIndex -QModelIndex TlsMethodModel::toIndex(TlsMethodModel::Type type) const -{ - return index(static_cast<int>(type),0,QModelIndex()); -} - -QItemSelectionModel* TlsMethodModel::selectionModel() const -{ - if (!d_ptr->m_pSelectionModel) { - d_ptr->m_pSelectionModel = new QItemSelectionModel(const_cast<TlsMethodModel*>(this)); - const QString value = d_ptr->m_pAccount->accountDetail(DRing::Account::ConfProperties::TLS::METHOD); - const QModelIndex& idx = toIndex(TlsMethodModelPrivate::fromDaemonName(value)); - d_ptr->m_pSelectionModel->setCurrentIndex(idx,QItemSelectionModel::ClearAndSelect); - - if (!d_ptr->isRing) - connect(d_ptr->m_pSelectionModel,&QItemSelectionModel::currentChanged,d_ptr,&TlsMethodModelPrivate::slotSelectionChanged); - } - - return d_ptr->m_pSelectionModel; -} - -void TlsMethodModelPrivate::slotSelectionChanged(const QModelIndex& idx) -{ - if (!idx.isValid()) - return; - - const char* value = toDaemonName(static_cast<TlsMethodModel::Type>(idx.row())); - if (value != m_pAccount->accountDetail(DRing::Account::ConfProperties::TLS::METHOD)) - m_pAccount->setAccountProperty(DRing::Account::ConfProperties::TLS::METHOD , value); -} - -///Convert a TlsMethodModel::Type enum to the string expected by the daemon API -const char* TlsMethodModelPrivate::toDaemonName(TlsMethodModel::Type type) -{ - switch (type) { - case TlsMethodModel::Type::DEFAULT: - return TlsMethodModelPrivate::DaemonName::DEFAULT; - case TlsMethodModel::Type::TLSv1_0: - return TlsMethodModelPrivate::DaemonName::TLSv1; - case TlsMethodModel::Type::TLSv1_1: - return TlsMethodModelPrivate::DaemonName::TLSv1_1; - case TlsMethodModel::Type::TLSv1_2: - return TlsMethodModelPrivate::DaemonName::TLSv1_2; - case TlsMethodModel::Type::COUNT__: - // default - break; - }; - return TlsMethodModelPrivate::DaemonName::DEFAULT; -} - -///Convert a Daemon API string to a TlsMethodModel::Type enum -TlsMethodModel::Type TlsMethodModelPrivate::fromDaemonName(const QString& name) -{ - if (name.isEmpty() || name == TlsMethodModelPrivate::DaemonName::DEFAULT) - return TlsMethodModel::Type::DEFAULT; - else if (name == TlsMethodModelPrivate::DaemonName::TLSv1) - return TlsMethodModel::Type::TLSv1_0; - else if (name == TlsMethodModelPrivate::DaemonName::TLSv1_1) - return TlsMethodModel::Type::TLSv1_1; - else if (name == TlsMethodModelPrivate::DaemonName::TLSv1_2) - return TlsMethodModel::Type::TLSv1_2; - qDebug() << "Unknown TLS method" << name; - return TlsMethodModel::Type::DEFAULT; -} - -#include <tlsmethodmodel.moc> diff --git a/src/tlsmethodmodel.h b/src/tlsmethodmodel.h deleted file mode 100644 index c18a0fa6..00000000 --- a/src/tlsmethodmodel.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2013-2019 Savoir-faire Linux Inc. * - * Author : Emmanuel Lepage Vallee <emmanuel.lepage@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 <QtCore/QAbstractListModel> - -//Qt -class QItemSelectionModel; - -//Ring -class TlsMethodModelPrivate; -class Account; - -/**Static model for handling encryption types - * - * This model can be used as a bridge between the Daemon API name (strings) - * and combobox indexes. It can also be used to translate "default" to the - * user locales - */ -class LIB_EXPORT TlsMethodModel : public QAbstractListModel { - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" - Q_OBJECT - #pragma GCC diagnostic pop - -public: - ///@enum Type Every supported encryption types - enum class Type { - DEFAULT = 0, - TLSv1_0 = 1, - TLSv1_1 = 2, - TLSv1_2 = 3, - COUNT__ - }; - - //Private constructor, can only be called by 'Account' - explicit TlsMethodModel(Account* a); - virtual ~TlsMethodModel(); - - //Model functions - virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const override; - virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const override; - virtual Qt::ItemFlags flags ( const QModelIndex& index ) const override; - virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) override; - virtual QHash<int,QByteArray> roleNames() const override; - - //Getters - QModelIndex toIndex (TlsMethodModel::Type type) const; - QItemSelectionModel* selectionModel() const; - -private: - TlsMethodModelPrivate* d_ptr; - Q_DECLARE_PRIVATE(TlsMethodModel) - -}; -Q_DECLARE_METATYPE(TlsMethodModel*) diff --git a/src/typedefs.h b/src/typedefs.h index 47dce77b..7d8656be 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -24,6 +24,7 @@ #include <QtCore/QVector> #include <QtCore/QString> #include <QtCore/QDebug> +#include <QtCore/QDateTime> //Typedefs (required to avoid '<' and '>' in the DBus XML) typedef QMap<QString, QString> MapStringString ; -- GitLab