Skip to content
Snippets Groups Projects
Commit 53a42379 authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Sébastien Blin
Browse files

newaccountmodel: adds save and load for complete account config


- adds ConfProperties structure in account::Info
- binds accountDetailsChanged signal in ConfigurationManagaer
- call NewAccountModel::getAccountConfig to get a copy
  of the current account details
- call NewAccountModel::setAccountConfig with a ConfProperties
  struct as a parameter to save any configuration changes
- enabled, alias, and username (in the case of SIP) will have
  seperate setters for now
- device name setting can be changed using the NewDeviceModel API
- WARNING: if the account details map won't be directly used
  to manage an account configuration detail, then the details
  should be removed from the ConfProperties_t struct and
  ConfProperties_t::toDetails and Info::fromDetails

Change-Id: I666da2ce9750befaa358ba5319e14ecbaf2cec0d
Reviewed-by: default avatarSebastien Blin <sebastien.blin@savoirfairelinux.com>
parent 579031bd
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
// Data // Data
#include "profile.h" #include "profile.h"
// old LRC
#include "typedefs.h"
namespace lrc namespace lrc
{ {
...@@ -74,20 +77,120 @@ to_status(const std::string& type) ...@@ -74,20 +77,120 @@ to_status(const std::string& type)
#pragma pop_macro("REGISTERED") #pragma pop_macro("REGISTERED")
struct ConfProperties_t {
std::string displayName;
std::string mailbox;
std::string dtmfType;
bool autoAnswer;
int activeCallLimit;
std::string hostname;
std::string username;
std::string routeset;
std::string password;
std::string realm;
std::string localInterface;
bool publishedSameAsLocal;
int localPort;
int publishedPort;
std::string publishedAddress;
std::string userAgent;
bool upnpEnabled;
bool hasCustomUserAgent;
bool allowIncomingFromHistory;
bool allowIncomingFromContact;
bool allowIncomingFromTrusted;
std::string archivePassword;
bool archiveHasPassword;
std::string archivePath;
std::string archivePin;
// in NewDeviceModel: deviceID;
// in NewDeviceModel: deviceName;
bool proxyEnabled;
std::string proxyServer;
std::string proxyPushToken;
struct Audio_t {
int audioPortMax;
int audioPortMin;
} Audio;
struct Video_t {
bool videoEnabled;
int videoPortMax;
int videoPortMin;
} Video;
struct STUN_t {
std::string server;
bool enable;
} STUN;
struct TURN_t {
std::string server;
bool enable;
std::string username;
std::string password;
std::string realm;
} TURN;
struct Presence_t {
bool presencePublishSupported;
bool presenceSubscribeSupported;
bool presenceEnabled;
} Presence;
struct Ringtone_t {
std::string ringtonePath;
bool ringtoneEnabled;
} Ringtone;
struct SRTP_t {
std::string keyExchange;
bool enable;
bool rtpFallback;
} SRTP;
struct TLS_t {
int listenerPort;
bool enable;
int port;
std::string certificateListFile;
std::string certificateFile;
std::string privateKeyFile;
std::string password;
std::string method;
std::string ciphers;
std::string serverName;
bool verifyServer;
bool verifyClient;
bool requireClientCertificate;
int negotiationTimeoutSec;
} TLS;
struct DHT_t {
int port;
bool PublicInCalls;
bool AllowFromTrusted;
} DHT;
struct RingNS_t {
std::string uri;
std::string account;
} RingNS;
MapStringString toDetails() const;
};
struct Info struct Info
{ {
std::string id;
std::string registeredName;
bool enabled;
bool freeable = false; bool freeable = false;
bool valid = true; bool valid = true;
std::string registeredName;
Status status = account::Status::INVALID; Status status = account::Status::INVALID;
profile::Info profileInfo;
std::unique_ptr<lrc::api::NewCallModel> callModel; std::unique_ptr<lrc::api::NewCallModel> callModel;
std::unique_ptr<lrc::api::ContactModel> contactModel; std::unique_ptr<lrc::api::ContactModel> contactModel;
std::unique_ptr<lrc::api::ConversationModel> conversationModel; std::unique_ptr<lrc::api::ConversationModel> conversationModel;
std::unique_ptr<lrc::api::NewDeviceModel> deviceModel; std::unique_ptr<lrc::api::NewDeviceModel> deviceModel;
NewAccountModel* accountModel {nullptr}; NewAccountModel* accountModel {nullptr};
// daemon config
std::string id;
profile::Info profileInfo; // contains: type, alias
bool enabled;
ConfProperties_t confProperties;
// load/save
void fromDetails(const MapStringString& details);
}; };
} // namespace account } // namespace account
......
...@@ -45,7 +45,10 @@ namespace api ...@@ -45,7 +45,10 @@ namespace api
class Lrc; class Lrc;
class BehaviorController; class BehaviorController;
namespace account { struct Info; } namespace account {
struct ConfProperties_t;
struct Info;
}
/** /**
* @brief Class that manages account information. * @brief Class that manages account information.
...@@ -75,7 +78,20 @@ public: ...@@ -75,7 +78,20 @@ public:
/** /**
* flag account corresponding to passed id as freeable. * flag account corresponding to passed id as freeable.
*/ */
void flagFreeable(const std::string& accountID) const; void flagFreeable(const std::string& accountId) const;
/**
* saves account config to .yml
* @param accountId.
* @param reference to the confProperties
*/
void setAccountConfig(const std::string& accountID,
const account::ConfProperties_t& confProperties) const;
/**
* gets a copy of the accounts config
* @param accountId.
* @return an account::Info::ConfProperties_t structure.
*/
account::ConfProperties_t getAccountConfig(const std::string& accountId) const;
/** /**
* Call exportToFile from the daemon * Call exportToFile from the daemon
* @param accountId * @param accountId
...@@ -99,6 +115,12 @@ public: ...@@ -99,6 +115,12 @@ public:
bool changeAccountPassword(const std::string& accountId, bool changeAccountPassword(const std::string& accountId,
const std::string& currentPassword, const std::string& currentPassword,
const std::string& newPassword) const; const std::string& newPassword) const;
/**
* Enable or disable an account
* @param accountId
* @param enable
*/
void enableAccount(const std::string& accountId, bool enabled);
Q_SIGNALS: Q_SIGNALS:
/** /**
......
...@@ -79,6 +79,11 @@ CallbacksHandler::CallbacksHandler(const Lrc& parent) ...@@ -79,6 +79,11 @@ CallbacksHandler::CallbacksHandler(const Lrc& parent)
this, this,
&CallbacksHandler::slotRegisteredNameFound); &CallbacksHandler::slotRegisteredNameFound);
connect(&ConfigurationManager::instance(),
&ConfigurationManagerInterface::accountDetailsChanged,
this,
&CallbacksHandler::slotAccountDetailsChanged);
connect(&ConfigurationManager::instance(), connect(&ConfigurationManager::instance(),
&ConfigurationManagerInterface::registrationStateChanged, &ConfigurationManagerInterface::registrationStateChanged,
this, this,
...@@ -222,6 +227,13 @@ CallbacksHandler::slotCallStateChanged(const QString& callId, const QString& sta ...@@ -222,6 +227,13 @@ CallbacksHandler::slotCallStateChanged(const QString& callId, const QString& sta
emit callStateChanged(callId.toStdString(), state.toStdString(), code); emit callStateChanged(callId.toStdString(), state.toStdString(), code);
} }
void
CallbacksHandler::slotAccountDetailsChanged(const QString& accountId,
const MapStringString& details)
{
emit accountDetailsChanged(accountId.toStdString(), convertMap(details));
}
void void
CallbacksHandler::slotRegistrationStateChanged(const QString& accountId, CallbacksHandler::slotRegistrationStateChanged(const QString& accountId,
const QString& registration_state, const QString& registration_state,
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "typedefs.h" #include "typedefs.h"
#include "namedirectory.h" #include "namedirectory.h"
#include "api/datatransfer.h" #include "api/datatransfer.h"
#include "qtwrapper/conversions_wrap.hpp"
namespace lrc namespace lrc
{ {
...@@ -104,6 +105,13 @@ Q_SIGNALS: ...@@ -104,6 +105,13 @@ Q_SIGNALS:
* @param code * @param code
*/ */
void callStateChanged(const std::string& callId, const std::string &state, int code); void callStateChanged(const std::string& callId, const std::string &state, int code);
/**
* Connect this signal to know when the account details have changed
* @param accountId the one who changes
* @param details the new details
*/
void accountDetailsChanged(const std::string& accountId,
const std::map<std::string,std::string>& details);
/** /**
* Connect this signal to know when the account status changed * Connect this signal to know when the account status changed
* @param accountId the one who changes * @param accountId the one who changes
...@@ -237,6 +245,13 @@ private Q_SLOTS: ...@@ -237,6 +245,13 @@ private Q_SLOTS:
void slotIncomingContactRequest(const QString& accountId, void slotIncomingContactRequest(const QString& accountId,
const QString& ringId, const QString& ringId,
const QByteArray& payload, time_t time); const QByteArray& payload, time_t time);
/**
* Emit accountDetailsChanged
* @param accountId
* @param details
*/
void slotAccountDetailsChanged(const QString& accountId,
const MapStringString& details);
/** /**
* Emit accountStatusChanged * Emit accountStatusChanged
* @param accountId * @param accountId
......
This diff is collapsed.
...@@ -64,6 +64,12 @@ public: ...@@ -64,6 +64,12 @@ public:
[this] () { [this] () {
Q_EMIT this->accountsChanged(); Q_EMIT this->accountsChanged();
}), }),
exportable_callback<ConfigurationSignal::AccountDetailsChanged>(
[this] (const std::string& account_id,
const std::map<std::string, std::string>& details) {
Q_EMIT this->accountDetailsChanged(QString(account_id.c_str()),
convertMap(details));
}),
exportable_callback<ConfigurationSignal::StunStatusFailed>( exportable_callback<ConfigurationSignal::StunStatusFailed>(
[this] (const std::string &reason) { [this] (const std::string &reason) {
Q_EMIT this->stunStatusFailure(QString(reason.c_str())); Q_EMIT this->stunStatusFailure(QString(reason.c_str()));
...@@ -657,6 +663,7 @@ public Q_SLOTS: // METHODS ...@@ -657,6 +663,7 @@ public Q_SLOTS: // METHODS
Q_SIGNALS: // SIGNALS Q_SIGNALS: // SIGNALS
void volumeChanged(const QString& device, double value); void volumeChanged(const QString& device, double value);
void accountsChanged(); void accountsChanged();
void accountDetailsChanged(const QString& accountId, const MapStringString& details);
void historyChanged(); void historyChanged();
void stunStatusFailure(const QString& reason); void stunStatusFailure(const QString& reason);
void registrationStateChanged(const QString& accountID, const QString& registration_state, unsigned detail_code, const QString& detail_str); void registrationStateChanged(const QString& accountID, const QString& registration_state, unsigned detail_code, const QString& detail_str);
......
...@@ -103,4 +103,43 @@ inline MapStringInt convertStringInt(const std::map<std::string, int>& m) { ...@@ -103,4 +103,43 @@ inline MapStringInt convertStringInt(const std::map<std::string, int>& m) {
return temp; return temp;
} }
constexpr static const char* TRUE_STR = "true";
constexpr static const char* FALSE_STR = "false";
static inline QString
toQString(bool b) noexcept
{
return b ? TRUE_STR : FALSE_STR;
}
static inline QString
toQString(const std::string& str) noexcept
{
return QString::fromStdString(str);
}
static inline QString
toQString(int i) noexcept
{
return QString::number(i);
}
static inline bool
toBool(QString qs) noexcept
{
return qs == TRUE_STR ? true : false;
}
static inline int
toInt(QString qs) noexcept
{
return qs.toInt();
}
static inline std::string
toStdString(QString qs) noexcept
{
return qs.toStdString();
}
#endif //CONVERSIONS_WRAP_H #endif //CONVERSIONS_WRAP_H
...@@ -814,6 +814,7 @@ public Q_SLOTS: // METHODS ...@@ -814,6 +814,7 @@ public Q_SLOTS: // METHODS
Q_SIGNALS: // SIGNALS Q_SIGNALS: // SIGNALS
void volumeChanged(const QString& device, double value); void volumeChanged(const QString& device, double value);
void accountsChanged(); void accountsChanged();
void accountDetailsChanged(const QString& accountId, const MapStringString& details);
void historyChanged(); void historyChanged();
void stunStatusFailure(const QString& reason); void stunStatusFailure(const QString& reason);
void registrationStateChanged(const QString& accountId, const QString& registration_state, unsigned detail_code, const QString& detail_str); void registrationStateChanged(const QString& accountId, const QString& registration_state, unsigned detail_code, const QString& detail_str);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment