Commit 3ff2508f authored by Ronan Abhamon's avatar Ronan Abhamon

feat(src/components/assistant/AssistantModel): supports a `configFilename` property

parent 9d056093
......@@ -164,7 +164,7 @@ void Logger::init () {
}
);
linphone_core_set_log_collection_path(Paths::getLogsDirpath().c_str());
linphone_core_set_log_collection_path(Paths::getLogsDirPath().c_str());
linphone_core_set_log_collection_max_file_size(MAX_LOGS_COLLECTION_SIZE);
linphone_core_enable_log_collection(LinphoneLogCollectionEnabled);
}
......@@ -31,6 +31,7 @@
#include "Paths.hpp"
#include "config.h"
#define PATH_ASSISTANT_CONFIG "/assistant/"
#define PATH_AVATARS "/avatars/"
#define PATH_CAPTURES "/captures/"
#define PATH_LOGS "/logs/"
......@@ -49,14 +50,14 @@ using namespace std;
// =============================================================================
inline bool directoryPathExists (const QString &path) {
inline bool dirPathExists (const QString &path) {
QDir dir(path);
return dir.exists();
}
inline bool filePathExists (const QString &path) {
QFileInfo info(path);
if (!directoryPathExists(info.path()))
if (!dirPathExists(info.path()))
return false;
QFile file(path);
......@@ -67,7 +68,7 @@ inline bool filePathExists (const string &path) {
return filePathExists(Utils::linphoneStringToQString(path));
}
inline void ensureDirectoryPathExists (const QString &path) {
inline void ensureDirPathExists (const QString &path) {
QDir dir(path);
if (!dir.exists() && !dir.mkpath(path))
qFatal("Unable to access at directory: `%s`", path.toStdString().c_str());
......@@ -75,20 +76,20 @@ inline void ensureDirectoryPathExists (const QString &path) {
inline void ensureFilePathExists (const QString &path) {
QFileInfo info(path);
ensureDirectoryPathExists(info.path());
ensureDirPathExists(info.path());
QFile file(path);
if (!file.exists() && !file.open(QIODevice::ReadWrite))
qFatal("Unable to access at path: `%s`", path.toStdString().c_str());
}
inline string getReadableDirectoryPath (const QString &dirname) {
inline string getReadableDirPath (const QString &dirname) {
return Utils::qStringToLinphoneString(QDir::toNativeSeparators(dirname));
}
inline string getWritableDirectoryPath (const QString &dirname) {
ensureDirectoryPathExists(dirname);
return getReadableDirectoryPath(dirname);
inline string getWritableDirPath (const QString &dirname) {
ensureDirPathExists(dirname);
return getReadableDirPath(dirname);
}
inline string getReadableFilePath (const QString &filename) {
......@@ -102,7 +103,7 @@ inline string getWritableFilePath (const QString &filename) {
// -----------------------------------------------------------------------------
inline QString getAppPackageDataDirpath () {
inline QString getAppPackageDataDirPath () {
QDir dir(QCoreApplication::applicationDirPath());
if (dir.dirName() == "MacOS") {
dir.cdUp();
......@@ -114,7 +115,7 @@ inline QString getAppPackageDataDirpath () {
return dir.absolutePath();
}
inline QString getAppPackageMsPluginsDirpath () {
inline QString getAppPackageMsPluginsDirPath () {
QDir dir(QCoreApplication::applicationDirPath());
if (dir.dirName() == "MacOS") {
dir.cdUp();
......@@ -126,91 +127,99 @@ inline QString getAppPackageMsPluginsDirpath () {
return dir.absolutePath();
}
inline QString getAppConfigFilepath () {
inline QString getAppAssistantConfigDirPath () {
return getAppPackageDataDirPath() + PATH_ASSISTANT_CONFIG;
}
inline QString getAppConfigFilePath () {
if (QSysInfo::productType() == "macos")
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_CONFIG;
return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + PATH_CONFIG;
}
inline QString getAppCallHistoryFilepath () {
inline QString getAppCallHistoryFilePath () {
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_CALL_HISTORY_LIST;
}
inline QString getAppFactoryConfigFilepath () {
return getAppPackageDataDirpath() + PATH_FACTORY_CONFIG;
inline QString getAppFactoryConfigFilePath () {
return getAppPackageDataDirPath() + PATH_FACTORY_CONFIG;
}
inline QString getAppRootCaFilepath () {
return getAppPackageDataDirpath() + PATH_ROOT_CA;
inline QString getAppRootCaFilePath () {
return getAppPackageDataDirPath() + PATH_ROOT_CA;
}
inline QString getAppFriendsFilepath () {
inline QString getAppFriendsFilePath () {
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_FRIENDS_LIST;
}
inline QString getAppMessageHistoryFilepath () {
inline QString getAppMessageHistoryFilePath () {
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_MESSAGE_HISTORY_LIST;
}
// -----------------------------------------------------------------------------
string Paths::getAvatarsDirpath () {
return getWritableDirectoryPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_AVATARS);
string Paths::getAssistantConfigDirPath () {
return getReadableDirPath(getAppAssistantConfigDirPath());
}
string Paths::getAvatarsDirPath () {
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_AVATARS);
}
string Paths::getCallHistoryFilepath () {
return getWritableFilePath(getAppCallHistoryFilepath());
string Paths::getCallHistoryFilePath () {
return getWritableFilePath(getAppCallHistoryFilePath());
}
string Paths::getCapturesDirpath () {
return getWritableDirectoryPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_CAPTURES);
string Paths::getCapturesDirPath () {
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_CAPTURES);
}
string Paths::getConfigFilepath (const QString &configPath) {
string Paths::getConfigFilePath (const QString &configPath) {
if (!configPath.isEmpty())
return getWritableFilePath(QFileInfo(configPath).absoluteFilePath());
return getWritableFilePath(getAppConfigFilepath());
return getWritableFilePath(getAppConfigFilePath());
}
string Paths::getFactoryConfigFilepath () {
return getReadableFilePath(getAppFactoryConfigFilepath());
string Paths::getFactoryConfigFilePath () {
return getReadableFilePath(getAppFactoryConfigFilePath());
}
string Paths::getFriendsListFilepath () {
return getWritableFilePath(getAppFriendsFilepath());
string Paths::getFriendsListFilePath () {
return getWritableFilePath(getAppFriendsFilePath());
}
string Paths::getLogsDirpath () {
return getWritableDirectoryPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_LOGS);
string Paths::getLogsDirPath () {
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_LOGS);
}
string Paths::getMessageHistoryFilepath () {
return getWritableFilePath(getAppMessageHistoryFilepath());
string Paths::getMessageHistoryFilePath () {
return getWritableFilePath(getAppMessageHistoryFilePath());
}
string Paths::getPackageDataDirpath () {
return getReadableDirectoryPath(getAppPackageDataDirpath());
string Paths::getPackageDataDirPath () {
return getReadableDirPath(getAppPackageDataDirPath());
}
string Paths::getPackageMsPluginsDirpath () {
return getReadableDirectoryPath(getAppPackageMsPluginsDirpath());
string Paths::getPackageMsPluginsDirPath () {
return getReadableDirPath(getAppPackageMsPluginsDirPath());
}
string Paths::getRootCaFilepath () {
return getReadableFilePath(getAppRootCaFilepath());
string Paths::getRootCaFilePath () {
return getReadableFilePath(getAppRootCaFilePath());
}
string Paths::getThumbnailsDirpath () {
return getWritableDirectoryPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_THUMBNAILS);
string Paths::getThumbnailsDirPath () {
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_THUMBNAILS);
}
string Paths::getUserCertificatesDirpath () {
return getWritableDirectoryPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_USER_CERTIFICATES);
string Paths::getUserCertificatesDirPath () {
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_USER_CERTIFICATES);
}
string Paths::getZrtpSecretsFilepath () {
string Paths::getZrtpSecretsFilePath () {
return getWritableFilePath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_ZRTP_SECRETS);
}
......@@ -218,7 +227,7 @@ string Paths::getZrtpSecretsFilepath () {
static void migrateFile (const QString &oldPath, const QString &newPath) {
QFileInfo info(newPath);
ensureDirectoryPathExists(info.path());
ensureDirPathExists(info.path());
if (QFile::copy(oldPath, newPath)) {
QFile::remove(oldPath);
......@@ -230,7 +239,7 @@ static void migrateFile (const QString &oldPath, const QString &newPath) {
static void migrateConfigurationFile (const QString &oldPath, const QString &newPath) {
QFileInfo info(newPath);
ensureDirectoryPathExists(info.path());
ensureDirPathExists(info.path());
if (QFile::copy(oldPath, newPath)) {
QFile oldFile(oldPath);
......@@ -247,7 +256,7 @@ static void migrateConfigurationFile (const QString &oldPath, const QString &new
}
void Paths::migrate () {
QString newPath = getAppConfigFilepath();
QString newPath = getAppConfigFilePath();
QString oldBaseDir = QSysInfo::productType() == "windows"
? QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
: QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
......@@ -256,19 +265,19 @@ void Paths::migrate () {
if (!filePathExists(newPath) && filePathExists(oldPath))
migrateConfigurationFile(oldPath, newPath);
newPath = getAppCallHistoryFilepath();
newPath = getAppCallHistoryFilePath();
oldPath = oldBaseDir + "/.linphone-call-history.db";
if (!filePathExists(newPath) && filePathExists(oldPath))
migrateFile(oldPath, newPath);
newPath = getAppFriendsFilepath();
newPath = getAppFriendsFilePath();
oldPath = oldBaseDir + "/.linphone-friends.db";
if (!filePathExists(newPath) && filePathExists(oldPath))
migrateFile(oldPath, newPath);
newPath = getAppMessageHistoryFilepath();
newPath = getAppMessageHistoryFilePath();
oldPath = oldBaseDir + "/.linphone-history.db";
if (!filePathExists(newPath) && filePathExists(oldPath))
......
......@@ -30,21 +30,22 @@
// =============================================================================
namespace Paths {
std::string getAvatarsDirpath ();
std::string getCallHistoryFilepath ();
std::string getCapturesDirpath ();
std::string getConfigFilepath (const QString &configPath = QString());
std::string getFactoryConfigFilepath ();
std::string getFriendsListFilepath ();
std::string getLogsDirpath ();
std::string getMessageHistoryFilepath ();
std::string getPackageDataDirpath ();
std::string getPackageMsPluginsDirpath ();
std::string getRootCaFilepath ();
std::string getThumbnailsDirpath ();
std::string getUserCertificatesDirpath ();
std::string getZrtpDataFilepath ();
std::string getZrtpSecretsFilepath ();
std::string getAssistantConfigDirPath ();
std::string getAvatarsDirPath ();
std::string getCallHistoryFilePath ();
std::string getCapturesDirPath ();
std::string getConfigFilePath (const QString &configPath = QString());
std::string getFactoryConfigFilePath ();
std::string getFriendsListFilePath ();
std::string getLogsDirPath ();
std::string getMessageHistoryFilePath ();
std::string getPackageDataDirPath ();
std::string getPackageMsPluginsDirPath ();
std::string getRootCaFilePath ();
std::string getThumbnailsDirPath ();
std::string getUserCertificatesDirPath ();
std::string getZrtpDataFilePath ();
std::string getZrtpSecretsFilePath ();
void migrate ();
}
......
......@@ -33,7 +33,7 @@ AvatarProvider::AvatarProvider () : QQuickImageProvider(
QQmlImageProviderBase::Image,
QQmlImageProviderBase::ForceAsynchronousImageLoading
) {
mAvatarsPath = Utils::linphoneStringToQString(Paths::getAvatarsDirpath());
mAvatarsPath = Utils::linphoneStringToQString(Paths::getAvatarsDirPath());
}
QImage AvatarProvider::requestImage (const QString &id, QSize *, const QSize &) {
......
......@@ -33,7 +33,7 @@ ThumbnailProvider::ThumbnailProvider () : QQuickImageProvider(
QQmlImageProviderBase::Image,
QQmlImageProviderBase::ForceAsynchronousImageLoading
) {
mThumbnailsPath = Utils::linphoneStringToQString(Paths::getThumbnailsDirpath());
mThumbnailsPath = Utils::linphoneStringToQString(Paths::getThumbnailsDirPath());
}
QImage ThumbnailProvider::requestImage (const QString &id, QSize *, const QSize &) {
......
......@@ -20,6 +20,7 @@
* Author: Ronan Abhamon
*/
#include "../../app/paths/Paths.hpp"
#include "../../Utils.hpp"
#include "../core/CoreManager.hpp"
......@@ -287,6 +288,27 @@ void AssistantModel::setDisplayName (const QString &displayName) {
// -----------------------------------------------------------------------------
QString AssistantModel::getConfigFilename () const {
return mConfigFilename;
}
void AssistantModel::setConfigFilename (const QString &configFilename) {
mConfigFilename = configFilename;
QString configPath = ::Utils::linphoneStringToQString(Paths::getAssistantConfigDirPath()) + configFilename;
qInfo() << QStringLiteral("Set config on assistant: `%1`.").arg(configPath);
CoreManager::getInstance()->getCore()->getConfig()->loadFromXmlFile(
::Utils::qStringToLinphoneString(configPath),
nullptr,
nullptr
);
emit configFilenameChanged(configFilename);
}
// -----------------------------------------------------------------------------
QString AssistantModel::mapAccountCreatorUsernameStatusToString (linphone::AccountCreatorUsernameStatus status) const {
shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig();
QString error;
......
......@@ -38,6 +38,7 @@ class AssistantModel : public QObject {
Q_PROPERTY(QString phoneNumber READ getPhoneNumber WRITE setPhoneNumber NOTIFY phoneNumberChanged);
Q_PROPERTY(QString username READ getUsername WRITE setUsername NOTIFY usernameChanged);
Q_PROPERTY(QString displayName READ getDisplayName WRITE setDisplayName NOTIFY displayNameChanged);
Q_PROPERTY(QString configFilename READ getConfigFilename WRITE setConfigFilename NOTIFY configFilenameChanged);
public:
AssistantModel (QObject *parent = Q_NULLPTR);
......@@ -59,6 +60,8 @@ signals:
void createStatusChanged (const QString &error);
void loginStatusChanged (const QString &error);
void configFilenameChanged (const QString &configFilename);
private:
QString getEmail () const;
void setEmail (const QString &email);
......@@ -75,8 +78,13 @@ private:
QString getDisplayName () const;
void setDisplayName (const QString &displayName);
QString getConfigFilename () const;
void setConfigFilename (const QString &configFilename);
QString mapAccountCreatorUsernameStatusToString (linphone::AccountCreatorUsernameStatus status) const;
QString mConfigFilename;
std::shared_ptr<linphone::AccountCreator> mAccountCreator;
std::shared_ptr<Handlers> mHandlers;
};
......
......@@ -73,7 +73,7 @@ inline void createThumbnail (const shared_ptr<linphone::ChatMessage> &message) {
QString uuid = QUuid::createUuid().toString();
QString fileId = QStringLiteral("%1.jpg").arg(uuid.mid(1, uuid.length() - 2));
if (!thumbnail.save(::Utils::linphoneStringToQString(Paths::getThumbnailsDirpath()) + fileId, "jpg", 100)) {
if (!thumbnail.save(::Utils::linphoneStringToQString(Paths::getThumbnailsDirPath()) + fileId, "jpg", 100)) {
qWarning() << QStringLiteral("Unable to create thumbnail of: `%1`.").arg(thumbnailPath);
return;
}
......@@ -87,7 +87,7 @@ inline void removeFileMessageThumbnail (const shared_ptr<linphone::ChatMessage>
string fileId = message->getAppdata();
if (!fileId.empty()) {
QString thumbnailPath = ::Utils::linphoneStringToQString(Paths::getThumbnailsDirpath() + fileId);
QString thumbnailPath = ::Utils::linphoneStringToQString(Paths::getThumbnailsDirPath() + fileId);
if (!QFile::remove(thumbnailPath))
qWarning() << QStringLiteral("Unable to remove `%1`.").arg(thumbnailPath);
}
......
......@@ -80,7 +80,7 @@ VcardModel::~VcardModel () {
QString imagePath(
::Utils::linphoneStringToQString(
Paths::getAvatarsDirpath() +
Paths::getAvatarsDirPath() +
photo->getValue().substr(sizeof(VCARD_SCHEME) - 1)
)
);
......@@ -134,7 +134,7 @@ bool VcardModel::setAvatar (const QString &path) {
.arg(uuid.mid(1, uuid.length() - 2)) // Remove `{}`.
.arg(info.suffix());
QString dest = ::Utils::linphoneStringToQString(Paths::getAvatarsDirpath()) + fileId;
QString dest = ::Utils::linphoneStringToQString(Paths::getAvatarsDirPath()) + fileId;
if (!file.copy(dest))
return false;
......@@ -150,7 +150,7 @@ bool VcardModel::setAvatar (const QString &path) {
if (oldPhoto) {
QString imagePath(
::Utils::linphoneStringToQString(
Paths::getAvatarsDirpath() + oldPhoto->getValue().substr(sizeof(VCARD_SCHEME) - 1)
Paths::getAvatarsDirPath() + oldPhoto->getValue().substr(sizeof(VCARD_SCHEME) - 1)
)
);
......
......@@ -87,26 +87,26 @@ void CoreManager::forceRefreshRegisters () {
// -----------------------------------------------------------------------------
void CoreManager::setDatabasesPaths () {
mCore->setFriendsDatabasePath(Paths::getFriendsListFilepath());
mCore->setCallLogsDatabasePath(Paths::getCallHistoryFilepath());
mCore->setChatDatabasePath(Paths::getMessageHistoryFilepath());
mCore->setFriendsDatabasePath(Paths::getFriendsListFilePath());
mCore->setCallLogsDatabasePath(Paths::getCallHistoryFilePath());
mCore->setChatDatabasePath(Paths::getMessageHistoryFilePath());
}
void CoreManager::setOtherPaths () {
if (mCore->getZrtpSecretsFile().empty())
mCore->setZrtpSecretsFile(Paths::getZrtpSecretsFilepath());
mCore->setZrtpSecretsFile(Paths::getZrtpSecretsFilePath());
if (mCore->getUserCertificatesPath().empty())
mCore->setUserCertificatesPath(Paths::getUserCertificatesDirpath());
mCore->setUserCertificatesPath(Paths::getUserCertificatesDirPath());
if (mCore->getRootCa().empty())
mCore->setRootCa(Paths::getRootCaFilepath());
mCore->setRootCa(Paths::getRootCaFilePath());
}
void CoreManager::setResourcesPaths () {
shared_ptr<linphone::Factory> factory = linphone::Factory::get();
factory->setMspluginsDir(Paths::getPackageMsPluginsDirpath());
factory->setTopResourcesDir(Paths::getPackageDataDirpath());
factory->setMspluginsDir(Paths::getPackageMsPluginsDirPath());
factory->setTopResourcesDir(Paths::getPackageDataDirPath());
}
// -----------------------------------------------------------------------------
......@@ -119,7 +119,7 @@ void CoreManager::createLinphoneCore (const QString &configPath) {
setResourcesPaths();
mCore = linphone::Factory::get()->createCore(mHandlers, Paths::getConfigFilepath(configPath), Paths::getFactoryConfigFilepath());
mCore = linphone::Factory::get()->createCore(mHandlers, Paths::getConfigFilePath(configPath), Paths::getFactoryConfigFilePath());
mCore->setVideoDisplayFilter("MSOGL");
mCore->usePreviewWindow(true);
......
......@@ -617,7 +617,7 @@ void SettingsModel::setDscpVideo (int dscp) {
QString SettingsModel::getSavedScreenshotsFolder () const {
return QDir::cleanPath(
::Utils::linphoneStringToQString(
mConfig->getString(UI_SECTION, "saved_screenshots_folder", Paths::getCapturesDirpath())
mConfig->getString(UI_SECTION, "saved_screenshots_folder", Paths::getCapturesDirPath())
)
) + QDir::separator();
}
......@@ -634,7 +634,7 @@ void SettingsModel::setSavedScreenshotsFolder (const QString &folder) {
QString SettingsModel::getSavedVideosFolder () const {
return QDir::cleanPath(
::Utils::linphoneStringToQString(
mConfig->getString(UI_SECTION, "saved_videos_folder", Paths::getCapturesDirpath())
mConfig->getString(UI_SECTION, "saved_videos_folder", Paths::getCapturesDirPath())
)
) + QDir::separator();
}
......
linphone @ fa2dad63
Subproject commit b3df86baf28d846a98b19983a6b28cb93ad9bdb7
Subproject commit fa2dad63d40078b423bfd9c2a56c59a606e81ed5
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