Commit 53a42379 authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Sébastien Blin

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: Sébastien Blin's avatarSebastien Blin <sebastien.blin@savoirfairelinux.com>
parent 579031bd
......@@ -25,6 +25,9 @@
// Data
#include "profile.h"
// old LRC
#include "typedefs.h"
namespace lrc
{
......@@ -74,20 +77,120 @@ to_status(const std::string& type)
#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
{
std::string id;
std::string registeredName;
bool enabled;
bool freeable = false;
bool valid = true;
std::string registeredName;
Status status = account::Status::INVALID;
profile::Info profileInfo;
std::unique_ptr<lrc::api::NewCallModel> callModel;
std::unique_ptr<lrc::api::ContactModel> contactModel;
std::unique_ptr<lrc::api::ConversationModel> conversationModel;
std::unique_ptr<lrc::api::NewDeviceModel> deviceModel;
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
......
......@@ -45,7 +45,10 @@ namespace api
class Lrc;
class BehaviorController;
namespace account { struct Info; }
namespace account {
struct ConfProperties_t;
struct Info;
}
/**
* @brief Class that manages account information.
......@@ -75,7 +78,20 @@ public:
/**
* 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
* @param accountId
......@@ -99,6 +115,12 @@ public:
bool changeAccountPassword(const std::string& accountId,
const std::string& currentPassword,
const std::string& newPassword) const;
/**
* Enable or disable an account
* @param accountId
* @param enable
*/
void enableAccount(const std::string& accountId, bool enabled);
Q_SIGNALS:
/**
......
......@@ -79,6 +79,11 @@ CallbacksHandler::CallbacksHandler(const Lrc& parent)
this,
&CallbacksHandler::slotRegisteredNameFound);
connect(&ConfigurationManager::instance(),
&ConfigurationManagerInterface::accountDetailsChanged,
this,
&CallbacksHandler::slotAccountDetailsChanged);
connect(&ConfigurationManager::instance(),
&ConfigurationManagerInterface::registrationStateChanged,
this,
......@@ -222,6 +227,13 @@ CallbacksHandler::slotCallStateChanged(const QString& callId, const QString& sta
emit callStateChanged(callId.toStdString(), state.toStdString(), code);
}
void
CallbacksHandler::slotAccountDetailsChanged(const QString& accountId,
const MapStringString& details)
{
emit accountDetailsChanged(accountId.toStdString(), convertMap(details));
}
void
CallbacksHandler::slotRegistrationStateChanged(const QString& accountId,
const QString& registration_state,
......
......@@ -30,6 +30,7 @@
#include "typedefs.h"
#include "namedirectory.h"
#include "api/datatransfer.h"
#include "qtwrapper/conversions_wrap.hpp"
namespace lrc
{
......@@ -104,6 +105,13 @@ Q_SIGNALS:
* @param 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
* @param accountId the one who changes
......@@ -237,6 +245,13 @@ private Q_SLOTS:
void slotIncomingContactRequest(const QString& accountId,
const QString& ringId,
const QByteArray& payload, time_t time);
/**
* Emit accountDetailsChanged
* @param accountId
* @param details
*/
void slotAccountDetailsChanged(const QString& accountId,
const MapStringString& details);
/**
* Emit accountStatusChanged
* @param accountId
......
This diff is collapsed.
......@@ -64,6 +64,12 @@ public:
[this] () {
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>(
[this] (const std::string &reason) {
Q_EMIT this->stunStatusFailure(QString(reason.c_str()));
......@@ -657,6 +663,7 @@ public Q_SLOTS: // METHODS
Q_SIGNALS: // SIGNALS
void volumeChanged(const QString& device, double value);
void accountsChanged();
void accountDetailsChanged(const QString& accountId, const MapStringString& details);
void historyChanged();
void stunStatusFailure(const QString& reason);
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) {
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
......@@ -812,32 +812,33 @@ public Q_SLOTS: // METHODS
void stopProxyClient(const std::string& /*accountID*/) { }
Q_SIGNALS: // SIGNALS
void volumeChanged(const QString& device, double value);
void accountsChanged();
void historyChanged();
void stunStatusFailure(const QString& reason);
void registrationStateChanged(const QString& accountId, const QString& registration_state, unsigned detail_code, const QString& detail_str);
void stunStatusSuccess(const QString& message);
void errorAlert(int code);
void volatileAccountDetailsChanged(const QString& accountId, MapStringString details);
void certificatePinned(const QString& certId);
void certificatePathPinned(const QString& path, const QStringList& certIds);
void certificateExpired(const QString& certId);
void certificateStateChanged(const QString& accountId, const QString& certId, const QString& status);
void incomingTrustRequest(const QString& accountId, const QString& from, const QByteArray& payload, qulonglong timeStamp);
void knownDevicesChanged(const QString& accountId, const MapStringString& devices);
void exportOnRingEnded(const QString& accountId, int status, const QString& pin);
void incomingAccountMessage(const QString& accountId, const QString& from, const MapStringString& payloads);
void mediaParametersChanged(const QString& accountId);
void audioDeviceEvent();
void accountMessageStatusChanged(const QString& accountId, const uint64_t id, const QString& to, int status);
void nameRegistrationEnded(const QString& accountId, int status, const QString& name);
void registeredNameFound(const QString& accountId, int status, const QString& address, const QString& name); // used by conversationModel
void migrationEnded(const QString &accountId, const QString &result);
void contactAdded(const QString &accountId, const QString &uri, bool banned);
void contactRemoved(const QString &accountId, const QString &uri, bool banned);
void dataTransferEvent(uint64_t transfer_id, uint32_t code);
void deviceRevocationEnded(const QString& accountId, const QString& deviceId, int status);
void volumeChanged(const QString& device, double value);
void accountsChanged();
void accountDetailsChanged(const QString& accountId, const MapStringString& details);
void historyChanged();
void stunStatusFailure(const QString& reason);
void registrationStateChanged(const QString& accountId, const QString& registration_state, unsigned detail_code, const QString& detail_str);
void stunStatusSuccess(const QString& message);
void errorAlert(int code);
void volatileAccountDetailsChanged(const QString& accountId, MapStringString details);
void certificatePinned(const QString& certId);
void certificatePathPinned(const QString& path, const QStringList& certIds);
void certificateExpired(const QString& certId);
void certificateStateChanged(const QString& accountId, const QString& certId, const QString& status);
void incomingTrustRequest(const QString& accountId, const QString& from, const QByteArray& payload, qulonglong timeStamp);
void knownDevicesChanged(const QString& accountId, const MapStringString& devices);
void exportOnRingEnded(const QString& accountId, int status, const QString& pin);
void incomingAccountMessage(const QString& accountId, const QString& from, const MapStringString& payloads);
void mediaParametersChanged(const QString& accountId);
void audioDeviceEvent();
void accountMessageStatusChanged(const QString& accountId, const uint64_t id, const QString& to, int status);
void nameRegistrationEnded(const QString& accountId, int status, const QString& name);
void registeredNameFound(const QString& accountId, int status, const QString& address, const QString& name); // used by conversationModel
void migrationEnded(const QString &accountId, const QString &result);
void contactAdded(const QString &accountId, const QString &uri, bool banned);
void contactRemoved(const QString &accountId, const QString &uri, bool banned);
void dataTransferEvent(uint64_t transfer_id, uint32_t code);
void deviceRevocationEnded(const QString& accountId, const QString& deviceId, int status);
};
namespace org {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment