Skip to content
Snippets Groups Projects
Commit cf8970ac authored by Emmanuel Lepage Vallée's avatar Emmanuel Lepage Vallée Committed by Stepan Salenikovich
Browse files

profile: Partially fix multiple profiles

This commit implements some logic necessary to assign a profile per account
rather than a global one. This will require more work to add both a global
profile mode and a per account one.

A profile is now assigned to an account at all times to avoid any account
belonging to multiple profiles at once. This should make sense in itself
as it avoids a potential logical cardinality issue.

Again, it is not intended to break the Gnome/OS X/Windows clients way of
handling profiles, but make other models possible to implement.

Change-Id: Ibd675210dc2939244454cee338cf9cda263aa2ae
parent e9b0a777
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,8 @@ ...@@ -48,6 +48,8 @@
#include "bootstrapmodel.h" #include "bootstrapmodel.h"
#include "trustrequest.h" #include "trustrequest.h"
#include "person.h" #include "person.h"
#include "profile.h"
#include "profilemodel.h"
#include "pendingtrustrequestmodel.h" #include "pendingtrustrequestmodel.h"
#include "private/pendingtrustrequestmodel_p.h" #include "private/pendingtrustrequestmodel_p.h"
#include "accountstatusmodel.h" #include "accountstatusmodel.h"
...@@ -1875,6 +1877,49 @@ void Account::setDTMFType(DtmfType type) ...@@ -1875,6 +1877,49 @@ void Account::setDTMFType(DtmfType type)
d_ptr->setAccountProperty(DRing::Account::ConfProperties::DTMF_TYPE,(type==OverRtp)?"overrtp":"oversip"); 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;
}
#define CAST(item) static_cast<int>(item) #define CAST(item) static_cast<int>(item)
///Proxy for AccountModel::setData ///Proxy for AccountModel::setData
void Account::setRoleData(int role, const QVariant& value) void Account::setRoleData(int role, const QVariant& value)
......
...@@ -43,6 +43,7 @@ class BootstrapModel ; ...@@ -43,6 +43,7 @@ class BootstrapModel ;
class NetworkInterfaceModel ; class NetworkInterfaceModel ;
class KeyExchangeModelPrivate ; class KeyExchangeModelPrivate ;
class PendingTrustRequestModel; class PendingTrustRequestModel;
class Profile;
//Private //Private
class AccountPrivate; class AccountPrivate;
...@@ -143,6 +144,7 @@ class LIB_EXPORT Account : public ItemBase { ...@@ -143,6 +144,7 @@ class LIB_EXPORT Account : public ItemBase {
Q_PROPERTY(int audioPortMin READ audioPortMin WRITE setAudioPortMin ) Q_PROPERTY(int audioPortMin READ audioPortMin WRITE setAudioPortMin )
Q_PROPERTY(bool upnpEnabled READ isUpnpEnabled WRITE setUpnpEnabled ) Q_PROPERTY(bool upnpEnabled READ isUpnpEnabled WRITE setUpnpEnabled )
Q_PROPERTY(bool hasCustomUserAgent READ hasCustomUserAgent WRITE setHasCustomUserAgent ) 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(QString userAgent READ userAgent WRITE setUserAgent )
Q_PROPERTY(bool useDefaultPort READ useDefaultPort WRITE setUseDefaultPort ) Q_PROPERTY(bool useDefaultPort READ useDefaultPort WRITE setUseDefaultPort )
...@@ -431,6 +433,7 @@ class LIB_EXPORT Account : public ItemBase { ...@@ -431,6 +433,7 @@ class LIB_EXPORT Account : public ItemBase {
RegistrationState registrationState () const; RegistrationState registrationState () const;
Protocol protocol () const; Protocol protocol () const;
ContactMethod* contactMethod () const; ContactMethod* contactMethod () const;
Profile* profile () const;
bool allowIncomingFromUnknown () const; bool allowIncomingFromUnknown () const;
bool allowIncomingFromHistory () const; bool allowIncomingFromHistory () const;
bool allowIncomingFromContact () const; bool allowIncomingFromContact () const;
...@@ -510,6 +513,7 @@ class LIB_EXPORT Account : public ItemBase { ...@@ -510,6 +513,7 @@ class LIB_EXPORT Account : public ItemBase {
void setAllowIncomingFromContact (bool value ); void setAllowIncomingFromContact (bool value );
void setAllowIncomingFromUnknown (bool value ); void setAllowIncomingFromUnknown (bool value );
void setHasActiveCallLimit (bool value ); void setHasActiveCallLimit (bool value );
void setProfile (Profile* p );
void setRoleData(int role, const QVariant& value); void setRoleData(int role, const QVariant& value);
......
...@@ -35,6 +35,7 @@ class NetworkInterfaceModel; ...@@ -35,6 +35,7 @@ class NetworkInterfaceModel;
class BootstrapModel; class BootstrapModel;
class DaemonCertificateCollection; class DaemonCertificateCollection;
class PendingTrustRequestModel; class PendingTrustRequestModel;
class Profile;
typedef void (AccountPrivate::*account_function)(); typedef void (AccountPrivate::*account_function)();
...@@ -139,6 +140,7 @@ public: ...@@ -139,6 +140,7 @@ public:
Account::EditState m_CurrentState ; Account::EditState m_CurrentState ;
QMetaObject::Connection m_cTlsCert ; QMetaObject::Connection m_cTlsCert ;
QMetaObject::Connection m_cTlsCaCert ; QMetaObject::Connection m_cTlsCaCert ;
Profile* m_pProfile {nullptr} ;
PendingTrustRequestModel* m_pPendingTrustRequestModel; PendingTrustRequestModel* m_pPendingTrustRequestModel;
QHash<int, Account::RoleStatus> m_hRoleStatus; QHash<int, Account::RoleStatus> m_hRoleStatus;
......
...@@ -77,6 +77,10 @@ bool Profile::addAccount(Account* acc) ...@@ -77,6 +77,10 @@ bool Profile::addAccount(Account* acc)
if (d_ptr->m_Accounts.indexOf(acc) == -1) { if (d_ptr->m_Accounts.indexOf(acc) == -1) {
d_ptr->m_Accounts << acc; d_ptr->m_Accounts << acc;
// The Account::setProfile logic should take care of removing the old
// profile.
acc->setProfile(this);
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment