Commit b05e003d authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): clean some pieces of code and improve build (cli, logger and paths)

parent 41d21d89
...@@ -331,6 +331,8 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_BIN ...@@ -331,6 +331,8 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_BIN
# Build. # Build.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
include_directories(src/)
find_package(Qt5 COMPONENTS ${QT5_PACKAGES} REQUIRED) find_package(Qt5 COMPONENTS ${QT5_PACKAGES} REQUIRED)
find_package(Qt5 COMPONENTS ${QT5_PACKAGES_OPTIONAL} QUIET) find_package(Qt5 COMPONENTS ${QT5_PACKAGES_OPTIONAL} QUIET)
find_package(Qt5 COMPONENTS Test REQUIRED) find_package(Qt5 COMPONENTS Test REQUIRED)
......
...@@ -22,12 +22,13 @@ ...@@ -22,12 +22,13 @@
#include <iostream> #include <iostream>
#include "../../components/core/CoreManager.hpp" #include "app/App.hpp"
#include "../../utils/Utils.hpp" #include "components/core/CoreManager.hpp"
#include "../App.hpp" #include "utils/Utils.hpp"
#include "Cli.hpp" #include "Cli.hpp"
#include "iostream"
// =============================================================================
using namespace std; using namespace std;
...@@ -52,7 +53,7 @@ static void cliJoinConference (QHash<QString, QString> &args) { ...@@ -52,7 +53,7 @@ static void cliJoinConference (QHash<QString, QString> &args) {
{ {
shared_ptr<linphone::Address> address = core->getPrimaryContactParsed(); shared_ptr<linphone::Address> address = core->getPrimaryContactParsed();
address->setDisplayName(::Utils::appStringToCoreString(args.take("display-name"))); address->setDisplayName(Utils::appStringToCoreString(args.take("display-name")));
core->setPrimaryContact(address->asString()); core->setPrimaryContact(address->asString());
} }
...@@ -73,8 +74,8 @@ static void cliJoinConferenceAs (QHash<QString, QString> &args) { ...@@ -73,8 +74,8 @@ static void cliJoinConferenceAs (QHash<QString, QString> &args) {
const shared_ptr<const linphone::Address> currentSipAddress = proxyConfig->getIdentityAddress(); const shared_ptr<const linphone::Address> currentSipAddress = proxyConfig->getIdentityAddress();
const shared_ptr<const linphone::Address> askedSipAddress = linphone::Factory::get()->createAddress( const shared_ptr<const linphone::Address> askedSipAddress = linphone::Factory::get()->createAddress(
::Utils::appStringToCoreString(fromSipAddress) Utils::appStringToCoreString(fromSipAddress)
); );
if (!currentSipAddress->weakEqual(askedSipAddress)) { if (!currentSipAddress->weakEqual(askedSipAddress)) {
qWarning() << QStringLiteral("Guest sip address `%1` doesn't match with default proxy config.") qWarning() << QStringLiteral("Guest sip address `%1` doesn't match with default proxy config.")
.arg(fromSipAddress); .arg(fromSipAddress);
...@@ -90,7 +91,7 @@ static void cliInitiateConference (QHash<QString, QString> &args) { ...@@ -90,7 +91,7 @@ static void cliInitiateConference (QHash<QString, QString> &args) {
// Check identity. // Check identity.
{ {
shared_ptr<linphone::Address> address = core->interpretUrl(::Utils::appStringToCoreString(args["sip-address"])); shared_ptr<linphone::Address> address = core->interpretUrl(Utils::appStringToCoreString(args["sip-address"]));
if (!address || address->getUsername().empty()) { if (!address || address->getUsername().empty()) {
qWarning() << QStringLiteral("Unable to parse invalid sip address."); qWarning() << QStringLiteral("Unable to parse invalid sip address.");
return; return;
...@@ -107,8 +108,8 @@ static void cliInitiateConference (QHash<QString, QString> &args) { ...@@ -107,8 +108,8 @@ static void cliInitiateConference (QHash<QString, QString> &args) {
const string identity = proxyConfig->getIdentityAddress()->asStringUriOnly(); const string identity = proxyConfig->getIdentityAddress()->asStringUriOnly();
if (sipAddress != identity) { if (sipAddress != identity) {
qWarning() << QStringLiteral("Received different sip address from identity : `%1 != %2`.") qWarning() << QStringLiteral("Received different sip address from identity : `%1 != %2`.")
.arg(::Utils::coreStringToAppString(identity)) .arg(Utils::coreStringToAppString(identity))
.arg(::Utils::coreStringToAppString(sipAddress)); .arg(Utils::coreStringToAppString(sipAddress));
return; return;
} }
} }
...@@ -119,7 +120,7 @@ static void cliInitiateConference (QHash<QString, QString> &args) { ...@@ -119,7 +120,7 @@ static void cliInitiateConference (QHash<QString, QString> &args) {
App *app = App::getInstance(); App *app = App::getInstance();
if (conference) { if (conference) {
if (conference->getId() == ::Utils::appStringToCoreString(id)) { if (conference->getId() == Utils::appStringToCoreString(id)) {
qInfo() << QStringLiteral("Conference `%1` already exists.").arg(id); qInfo() << QStringLiteral("Conference `%1` already exists.").arg(id);
// TODO: Set the view to the "waiting call view". // TODO: Set the view to the "waiting call view".
app->smartShowWindow(app->getCallsWindow()); app->smartShowWindow(app->getCallsWindow());
...@@ -127,13 +128,13 @@ static void cliInitiateConference (QHash<QString, QString> &args) { ...@@ -127,13 +128,13 @@ static void cliInitiateConference (QHash<QString, QString> &args) {
} }
qInfo() << QStringLiteral("Remove existing conference with id: `%1`.") qInfo() << QStringLiteral("Remove existing conference with id: `%1`.")
.arg(::Utils::coreStringToAppString(conference->getId())); .arg(Utils::coreStringToAppString(conference->getId()));
core->terminateConference(); core->terminateConference();
} }
qInfo() << QStringLiteral("Create conference with id: `%1`.").arg(id); qInfo() << QStringLiteral("Create conference with id: `%1`.").arg(id);
conference = core->createConferenceWithParams(core->createConferenceParams()); conference = core->createConferenceWithParams(core->createConferenceParams());
conference->setId(::Utils::appStringToCoreString(id)); conference->setId(Utils::appStringToCoreString(id));
if (core->enterConference() == -1) { if (core->enterConference() == -1) {
qWarning() << QStringLiteral("Unable to join created conference: `%1`.").arg(id); qWarning() << QStringLiteral("Unable to join created conference: `%1`.").arg(id);
...@@ -221,7 +222,7 @@ static string multilineIndent (const QString &str, int indentationNumber = 0) { ...@@ -221,7 +222,7 @@ static string multilineIndent (const QString &str, int indentationNumber = 0) {
out += indentedWord(word, indentedTextCurPos, lineLength, padding); out += indentedWord(word, indentedTextCurPos, lineLength, padding);
out += "\n"; out += "\n";
return ::Utils::appStringToCoreString(out); return Utils::appStringToCoreString(out);
} }
// ============================================================================= // =============================================================================
...@@ -264,7 +265,7 @@ void Cli::Command::execute (QHash<QString, QString> &args) const { ...@@ -264,7 +265,7 @@ void Cli::Command::execute (QHash<QString, QString> &args) const {
(*mFunction)(args); (*mFunction)(args);
else { else {
Function f = mFunction; Function f = mFunction;
::Utils::connectOnce(coreManager->getHandlers().get(), &CoreHandlers::coreStarted, coreManager, [f, args] { Utils::connectOnce(coreManager->getHandlers().get(), &CoreHandlers::coreStarted, coreManager, [f, args] {
QHash<QString, QString> fuckConst = args; QHash<QString, QString> fuckConst = args;
(*f)(fuckConst); (*f)(fuckConst);
}); });
...@@ -275,11 +276,11 @@ void Cli::Command::executeUri (const shared_ptr<linphone::Address> &address) con ...@@ -275,11 +276,11 @@ void Cli::Command::executeUri (const shared_ptr<linphone::Address> &address) con
QHash<QString, QString> args; QHash<QString, QString> args;
// TODO: check if there is too much headers. // TODO: check if there is too much headers.
for (const auto &argName : mArgsScheme.keys()) { for (const auto &argName : mArgsScheme.keys()) {
const string header = address->getHeader(::Utils::appStringToCoreString(argName)); const string header = address->getHeader(Utils::appStringToCoreString(argName));
args[argName] = QByteArray::fromBase64(QByteArray(header.c_str(), int(header.length()))); args[argName] = QByteArray::fromBase64(QByteArray(header.c_str(), int(header.length())));
} }
address->clean(); address->clean();
args["sip-address"] = ::Utils::coreStringToAppString(address->asStringUriOnly()); args["sip-address"] = Utils::coreStringToAppString(address->asStringUriOnly());
execute(args); execute(args);
} }
...@@ -315,17 +316,17 @@ QRegExp Cli::mRegExpArgs("(?:(?:([\\w-]+)\\s*)=\\s*(?:\"([^\"\\\\]*(?:\\\\.[^\"\ ...@@ -315,17 +316,17 @@ QRegExp Cli::mRegExpArgs("(?:(?:([\\w-]+)\\s*)=\\s*(?:\"([^\"\\\\]*(?:\\\\.[^\"\
QRegExp Cli::mRegExpFunctionName("^\\s*([a-z-]+)\\s*"); QRegExp Cli::mRegExpFunctionName("^\\s*([a-z-]+)\\s*");
QMap<QString, Cli::Command> Cli::mCommands = { QMap<QString, Cli::Command> Cli::mCommands = {
createCommand("show", QT_TR_NOOP("showFunctionDescription"), ::cliShow), createCommand("show", QT_TR_NOOP("showFunctionDescription"), cliShow),
createCommand("call", QT_TR_NOOP("callFunctionDescription"), ::cliCall, { createCommand("call", QT_TR_NOOP("callFunctionDescription"), cliCall, {
{ "sip-address", {} } { "sip-address", {} }
}), }),
createCommand("initiate-conference", QT_TR_NOOP("initiateConferenceFunctionDescription"), ::cliInitiateConference, { createCommand("initiate-conference", QT_TR_NOOP("initiateConferenceFunctionDescription"), cliInitiateConference, {
{ "sip-address", {} }, { "conference-id", {} } { "sip-address", {} }, { "conference-id", {} }
}), }),
createCommand("join-conference", QT_TR_NOOP("joinConferenceFunctionDescription"), ::cliJoinConference, { createCommand("join-conference", QT_TR_NOOP("joinConferenceFunctionDescription"), cliJoinConference, {
{ "sip-address", {} }, { "conference-id", {} }, { "display-name", {} } { "sip-address", {} }, { "conference-id", {} }, { "display-name", {} }
}), }),
createCommand("join-conference-as", QT_TR_NOOP("joinConferenceAsFunctionDescription"), ::cliJoinConferenceAs, { createCommand("join-conference-as", QT_TR_NOOP("joinConferenceAsFunctionDescription"), cliJoinConferenceAs, {
{ "sip-address", {} }, { "conference-id", {} }, { "guest-sip-address", {} } { "sip-address", {} }, { "conference-id", {} }, { "guest-sip-address", {} }
}) })
}; };
...@@ -334,7 +335,7 @@ QMap<QString, Cli::Command> Cli::mCommands = { ...@@ -334,7 +335,7 @@ QMap<QString, Cli::Command> Cli::mCommands = {
void Cli::executeCommand (const QString &command, CommandFormat *format) { void Cli::executeCommand (const QString &command, CommandFormat *format) {
shared_ptr<linphone::Address> address = linphone::Factory::get()->createAddress( shared_ptr<linphone::Address> address = linphone::Factory::get()->createAddress(
::Utils::appStringToCoreString(command) Utils::appStringToCoreString(command)
); );
// Execute cli command. // Execute cli command.
...@@ -362,13 +363,13 @@ void Cli::executeCommand (const QString &command, CommandFormat *format) { ...@@ -362,13 +363,13 @@ void Cli::executeCommand (const QString &command, CommandFormat *format) {
if (scheme == validScheme) if (scheme == validScheme)
goto success; goto success;
qWarning() << QStringLiteral("Not a valid uri: `%1` Unsupported scheme: `%2`.") qWarning() << QStringLiteral("Not a valid uri: `%1` Unsupported scheme: `%2`.")
.arg(command).arg(::Utils::coreStringToAppString(scheme)); .arg(command).arg(Utils::coreStringToAppString(scheme));
return; return;
success: success:
const QString functionName = ::Utils::coreStringToAppString(address->getHeader("method")).isEmpty() const QString functionName = Utils::coreStringToAppString(address->getHeader("method")).isEmpty()
? QStringLiteral("call") ? QStringLiteral("call")
: ::Utils::coreStringToAppString(address->getHeader("method")); : Utils::coreStringToAppString(address->getHeader("method"));
if (!functionName.isEmpty() && !mCommands.contains(functionName)) { if (!functionName.isEmpty() && !mCommands.contains(functionName)) {
qWarning() << QStringLiteral("This command doesn't exist: `%1`.").arg(functionName); qWarning() << QStringLiteral("This command doesn't exist: `%1`.").arg(functionName);
......
...@@ -21,11 +21,12 @@ ...@@ -21,11 +21,12 @@
*/ */
#include <bctoolbox/logging.h> #include <bctoolbox/logging.h>
#include <linphone++/linphone.hh>
#include <QDateTime> #include <QDateTime>
#include <QThread> #include <QThread>
#include "../../components/settings/SettingsModel.hpp" #include "components/settings/SettingsModel.hpp"
#include "../../utils/Utils.hpp" #include "utils/Utils.hpp"
#include "Logger.hpp" #include "Logger.hpp"
...@@ -45,15 +46,15 @@ ...@@ -45,15 +46,15 @@
#define RESET "" #define RESET ""
#endif // if defined(__linux__) || defined(__APPLE__) #endif // if defined(__linux__) || defined(__APPLE__)
#define QT_DOMAIN "qt" // =============================================================================
#define MAX_LOGS_COLLECTION_SIZE 10485760 /* 10MB. */
#define SRC_PATTERN "/linphone-desktop/src/"
using namespace std; using namespace std;
// ============================================================================= namespace {
constexpr char cQtDomain[] = "qt";
constexpr size_t cMaxLogsCollectionSize = 10485760; // 10MB.
constexpr char cSrcPattern[] = "/linphone-desktop/src/";
}
QMutex Logger::mMutex; QMutex Logger::mMutex;
...@@ -81,24 +82,25 @@ private: ...@@ -81,24 +82,25 @@ private:
if (!mLogger->isVerbose()) if (!mLogger->isVerbose())
return; return;
using LogLevel = linphone::LogLevel;
const char *format; const char *format;
switch (level) { switch (level) {
case linphone::LogLevel::LogLevelDebug: case LogLevel::LogLevelDebug:
format = GREEN "[%s][Debug]" YELLOW "Core:%s: " RESET "%s\n"; format = GREEN "[%s][Debug]" YELLOW "Core:%s: " RESET "%s\n";
break; break;
case linphone::LogLevel::LogLevelTrace: case LogLevel::LogLevelTrace:
format = BLUE "[%s][Trace]" YELLOW "Core:%s: " RESET "%s\n"; format = BLUE "[%s][Trace]" YELLOW "Core:%s: " RESET "%s\n";
break; break;
case linphone::LogLevel::LogLevelMessage: case LogLevel::LogLevelMessage:
format = BLUE "[%s][Info]" YELLOW "Core:%s: " RESET "%s\n"; format = BLUE "[%s][Info]" YELLOW "Core:%s: " RESET "%s\n";
break; break;
case linphone::LogLevel::LogLevelWarning: case LogLevel::LogLevelWarning:
format = RED "[%s][Warning]" YELLOW "Core:%s: " RESET "%s\n"; format = RED "[%s][Warning]" YELLOW "Core:%s: " RESET "%s\n";
break; break;
case linphone::LogLevel::LogLevelError: case LogLevel::LogLevelError:
format = RED "[%s][Error]" YELLOW "Core:%s: " RESET "%s\n"; format = RED "[%s][Error]" YELLOW "Core:%s: " RESET "%s\n";
break; break;
case linphone::LogLevel::LogLevelFatal: case LogLevel::LogLevelFatal:
format = RED "[%s][Fatal]" YELLOW "Core:%s: " RESET "%s\n"; format = RED "[%s][Fatal]" YELLOW "Core:%s: " RESET "%s\n";
break; break;
} }
...@@ -106,12 +108,12 @@ private: ...@@ -106,12 +108,12 @@ private:
fprintf( fprintf(
stderr, stderr,
format, format,
::getFormattedCurrentTime().constData(), getFormattedCurrentTime().constData(),
domain.empty() ? domain.c_str() : "linphone", domain.empty() ? domain.c_str() : "linphone",
message.c_str() message.c_str()
); );
if (level == linphone::LogLevel::LogLevelFatal) if (level == LogLevel::LogLevelFatal)
terminate(); terminate();
}; };
...@@ -148,10 +150,10 @@ void Logger::log (QtMsgType type, const QMessageLogContext &context, const QStri ...@@ -148,10 +150,10 @@ void Logger::log (QtMsgType type, const QMessageLogContext &context, const QStri
QByteArray contextArr; QByteArray contextArr;
{ {
const char *file = context.file; const char *file = context.file;
const char *pos = file ? ::Utils::rstrstr(file, SRC_PATTERN) : file; const char *pos = file ? Utils::rstrstr(file, cSrcPattern) : file;
contextArr = QStringLiteral("%1:%2: ") contextArr = QStringLiteral("%1:%2: ")
.arg(pos ? pos + sizeof(SRC_PATTERN) - 1 : file) .arg(pos ? pos + sizeof(cSrcPattern) - 1 : file)
.arg(context.line) .arg(context.line)
.toLocal8Bit(); .toLocal8Bit();
contextStr = contextArr.constData(); contextStr = contextArr.constData();
...@@ -161,12 +163,12 @@ void Logger::log (QtMsgType type, const QMessageLogContext &context, const QStri ...@@ -161,12 +163,12 @@ void Logger::log (QtMsgType type, const QMessageLogContext &context, const QStri
#endif // ifdef QT_MESSAGELOGCONTEXT #endif // ifdef QT_MESSAGELOGCONTEXT
QByteArray localMsg = msg.toLocal8Bit(); QByteArray localMsg = msg.toLocal8Bit();
QByteArray dateTime = ::getFormattedCurrentTime(); QByteArray dateTime = getFormattedCurrentTime();
mMutex.lock(); mMutex.lock();
fprintf(stderr, format, dateTime.constData(), QThread::currentThread(), contextStr, localMsg.constData()); fprintf(stderr, format, dateTime.constData(), QThread::currentThread(), contextStr, localMsg.constData());
bctbx_log(QT_DOMAIN, level, "QT: %s%s", contextStr, localMsg.constData()); bctbx_log(cQtDomain, level, "QT: %s%s", contextStr, localMsg.constData());
mMutex.unlock(); mMutex.unlock();
...@@ -201,8 +203,8 @@ void Logger::init (const shared_ptr<linphone::Config> &config) { ...@@ -201,8 +203,8 @@ void Logger::init (const shared_ptr<linphone::Config> &config) {
loggingService->setListener(make_shared<LinphoneLogger>(mInstance)); loggingService->setListener(make_shared<LinphoneLogger>(mInstance));
} }
linphone::Core::setLogCollectionPath(::Utils::appStringToCoreString(folder)); linphone::Core::setLogCollectionPath(Utils::appStringToCoreString(folder));
linphone::Core::setLogCollectionMaxFileSize(MAX_LOGS_COLLECTION_SIZE); linphone::Core::setLogCollectionMaxFileSize(cMaxLogsCollectionSize);
mInstance->enable(SettingsModel::getLogsEnabled(config)); mInstance->enable(SettingsModel::getLogsEnabled(config));
} }
...@@ -23,11 +23,17 @@ ...@@ -23,11 +23,17 @@
#ifndef LOGGER_H_ #ifndef LOGGER_H_
#define LOGGER_H_ #define LOGGER_H_
#include <linphone++/linphone.hh> #include <memory>
#include <QMutex> #include <QMutex>
// ============================================================================= // =============================================================================
namespace linphone {
class Config;
class LoggingService;
}
class Logger { class Logger {
public: public:
~Logger () = default; ~Logger () = default;
......
...@@ -26,31 +26,33 @@ ...@@ -26,31 +26,33 @@
#include <QStandardPaths> #include <QStandardPaths>
#include <QtDebug> #include <QtDebug>
#include "../../utils/Utils.hpp" #include "utils/Utils.hpp"
#include "config.h" #include "config.h"
#include "Paths.hpp" #include "Paths.hpp"
#define PATH_ASSISTANT_CONFIG "/linphone/assistant/" // =============================================================================
#define PATH_AVATARS "/avatars/"
#define PATH_CAPTURES "/Linphone/captures/"
#define PATH_LOGS "/logs/"
#define PATH_PLUGINS "/plugins/"
#define PATH_THUMBNAILS "/thumbnails/"
#define PATH_USER_CERTIFICATES "/usr-crt/"
#define PATH_CALL_HISTORY_LIST "/call-history.db"
#define PATH_CONFIG "/linphonerc"
#define PATH_FACTORY_CONFIG "/linphone/linphonerc-factory"
#define PATH_ROOT_CA "/linphone/rootca.pem"
#define PATH_FRIENDS_LIST "/friends.db"
#define PATH_MESSAGE_HISTORY_LIST "/message-history.db"
#define PATH_ZRTP_SECRETS "/zidcache"
using namespace std; using namespace std;
// ============================================================================= namespace {
constexpr char cPathAssistantConfig[] = "/linphone/assistant/";
constexpr char cPathAvatars[] = "/avatars/";
constexpr char cPathCaptures[] = "/Linphone/captures/";
constexpr char cPathLogs[] = "/logs/";
constexpr char cPathPlugins[] = "/plugins/";
constexpr char cPathThumbnails[] = "/thumbnails/";
constexpr char cPathUserCertificates[] = "/usr-crt/";
constexpr char cPathCallHistoryList[] = "/call-history.db";
constexpr char cPathConfig[] = "/linphonerc";
constexpr char cPathFactoryConfig[] = "/linphone/linphonerc-factory";
constexpr char cPathRootCa[] = "/linphone/rootca.pem";
constexpr char cPathFriendsList[] = "/friends.db";
constexpr char cPathMessageHistoryList[] = "/message-history.db";
constexpr char cPathZrtpSecrets[] = "/zidcache";
}
static inline bool dirPathExists (const QString &path) { static inline bool dirPathExists (const QString &path) {
QDir dir(path); QDir dir(path);
...@@ -59,7 +61,7 @@ static inline bool dirPathExists (const QString &path) { ...@@ -59,7 +61,7 @@ static inline bool dirPathExists (const QString &path) {
static inline bool filePathExists (const QString &path) { static inline bool filePathExists (const QString &path) {
QFileInfo info(path); QFileInfo info(path);
if (!::dirPathExists(info.path())) if (!dirPathExists(info.path()))
return false; return false;
QFile file(path); QFile file(path);
...@@ -74,7 +76,7 @@ static inline void ensureDirPathExists (const QString &path) { ...@@ -74,7 +76,7 @@ static inline void ensureDirPathExists (const QString &path) {
static inline void ensureFilePathExists (const QString &path) { static inline void ensureFilePathExists (const QString &path) {
QFileInfo info(path); QFileInfo info(path);
::ensureDirPathExists(info.path()); ensureDirPathExists(info.path());
QFile file(path); QFile file(path);
if (!file.exists() && !file.open(QIODevice::ReadWrite)) if (!file.exists() && !file.open(QIODevice::ReadWrite))
...@@ -82,21 +84,21 @@ static inline void ensureFilePathExists (const QString &path) { ...@@ -82,21 +84,21 @@ static inline void ensureFilePathExists (const QString &path) {
} }
static inline string getReadableDirPath (const QString &dirname) { static inline string getReadableDirPath (const QString &dirname) {
return ::Utils::appStringToCoreString(QDir::toNativeSeparators(dirname)); return Utils::appStringToCoreString(QDir::toNativeSeparators(dirname));
} }
static inline string getWritableDirPath (const QString &dirname) { static inline string getWritableDirPath (const QString &dirname) {
::ensureDirPathExists(dirname); ensureDirPathExists(dirname);
return ::getReadableDirPath(dirname); return getReadableDirPath(dirname);
} }
static inline string getReadableFilePath (const QString &filename) { static inline string getReadableFilePath (const QString &filename) {
return ::Utils::appStringToCoreString(QDir::toNativeSeparators(filename)); return Utils::appStringToCoreString(QDir::toNativeSeparators(filename));
} }
static inline string getWritableFilePath (const QString &filename) { static inline string getWritableFilePath (const QString &filename) {
::ensureFilePathExists(filename); ensureFilePathExists(filename);
return ::getReadableFilePath(filename); return getReadableFilePath(filename);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -112,134 +114,134 @@ static inline QDir getAppPackageDir () { ...@@ -112,134 +114,134 @@ static inline QDir getAppPackageDir () {
} }
static inline QString getAppPackageDataDirPath () { static inline QString getAppPackageDataDirPath () {
QDir dir = ::getAppPackageDir(); QDir dir = getAppPackageDir();
dir.cd("share"); dir.cd("share");
return dir.absolutePath(); return dir.absolutePath();
} }
static inline QString getAppPackageMsPluginsDirPath () { static inline QString getAppPackageMsPluginsDirPath () {
QDir dir = ::getAppPackageDir(); QDir dir = getAppPackageDir();
dir.cd(MSPLUGINS_DIR); dir.cd(MSPLUGINS_DIR);
return dir.absolutePath(); return dir.absolutePath();
} }
static inline QString getAppAssistantConfigDirPath () { static inline QString getAppAssistantConfigDirPath () {
return ::getAppPackageDataDirPath() + PATH_ASSISTANT_CONFIG; return getAppPackageDataDirPath() + cPathAssistantConfig;
} }
static inline QString getAppConfigFilePath () { static inline QString getAppConfigFilePath () {
return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + PATH_CONFIG; return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + cPathConfig;
} }
static inline QString getAppCallHistoryFilePath () { static inline QString getAppCallHistoryFilePath () {
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_CALL_HISTORY_LIST; return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathCallHistoryList;
} }
static inline QString getAppFactoryConfigFilePath () { static inline QString getAppFactoryConfigFilePath () {
return ::getAppPackageDataDirPath() + PATH_FACTORY_CONFIG; return getAppPackageDataDirPath() + cPathFactoryConfig;
} }
static inline QString getAppPluginsDirPath () { static inline QString getAppPluginsDirPath () {
return ::getAppPackageDataDirPath() + PATH_PLUGINS; return getAppPackageDataDirPath() + cPathPlugins;
} }
static inline QString getAppRootCaFilePath () { static inline QString getAppRootCaFilePath () {
return ::getAppPackageDataDirPath() + PATH_ROOT_CA; return getAppPackageDataDirPath() + cPathRootCa;
} }
static inline QString getAppFriendsFilePath () { static inline QString getAppFriendsFilePath () {
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_FRIENDS_LIST; return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathFriendsList;
} }
static inline QString getAppMessageHistoryFilePath () { static inline QString getAppMessageHistoryFilePath () {
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_MESSAGE_HISTORY_LIST; return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathMessageHistoryList;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool Paths::filePathExists (const string &path) { bool Paths::filePathExists (const string &path) {
return ::filePathExists(Utils::coreStringToAppString(path)); return filePathExists(Utils::coreStringToAppString(path));
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
string Paths::getAssistantConfigDirPath () { string Paths::getAssistantConfigDirPath () {
return ::getReadableDirPath(::getAppAssistantConfigDirPath()); return getReadableDirPath(getAppAssistantConfigDirPath());
} }
string Paths::getAvatarsDirPath () { string Paths::getAvatarsDirPath () {
return ::getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_AVATARS); return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathAvatars);
} }
string Paths::getCallHistoryFilePath () { string Paths::getCallHistoryFilePath () {
return ::getWritableFilePath(::getAppCallHistoryFilePath()); return getWritableFilePath(getAppCallHistoryFilePath());
} }
string Paths::getCapturesDirPath () { string Paths::getCapturesDirPath () {
return ::getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + PATH_CAPTURES); return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + cPathCaptures);
} }
string Paths::getConfigFilePath (const QString &configPath, bool writable) { string Paths::getConfigFilePath (const QString &configPath, bool writable) {
const QString path = configPath.isEmpty() const QString path = configPath.isEmpty()
? ::getAppConfigFilePath() ? getAppConfigFilePath()
: QFileInfo(configPath).absoluteFilePath(); : QFileInfo(configPath).absoluteFilePath();
return writable ? ::getWritableFilePath(path) : ::getReadableFilePath(path); return writable ? ::getWritableFilePath(path) : ::getReadableFilePath(path);
} }
string Paths::getFactoryConfigFilePath () { string Paths::getFactoryConfigFilePath () {
return ::getReadableFilePath(::getAppFactoryConfigFilePath()); return getReadableFilePath(getAppFactoryConfigFilePath());
} }
string Paths::getFriendsListFilePath () { string Paths::getFriendsListFilePath () {
return ::getWritableFilePath(::getAppFriendsFilePath()); return getWritableFilePath(getAppFriendsFilePath());
} }
string Paths::getDownloadDirPath () { string Paths::getDownloadDirPath () {
return ::getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
} }
string Paths::getLogsDirPath () { string Paths::getLogsDirPath () {
return ::getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_LOGS); return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathLogs);
} }
string Paths::getMessageHistoryFilePath () { string Paths::getMessageHistoryFilePath () {
return ::getWritableFilePath(::getAppMessageHistoryFilePath()); return getWritableFilePath(getAppMessageHistoryFilePath());
} }
string Paths::getPackageDataDirPath () { string Paths::getPackageDataDirPath () {
return ::getReadableDirPath(::getAppPackageDataDirPath()); return getReadableDirPath(getAppPackageDataDirPath());
} }
string Paths::getPackageMsPluginsDirPath () { string Paths::getPackageMsPluginsDirPath () {
return ::getReadableDirPath(::getAppPackageMsPluginsDirPath()); return getReadableDirPath(getAppPackageMsPluginsDirPath());
} }
string Paths::getPluginsDirPath () { string Paths::getPluginsDirPath () {
return ::getReadableDirPath(::getAppPluginsDirPath()); return getReadableDirPath(getAppPluginsDirPath());
} }
string Paths::getRootCaFilePath () { string Paths::getRootCaFilePath () {
return ::getReadableFilePath(::getAppRootCaFilePath()); return getReadableFilePath(getAppRootCaFilePath());
} }
string Paths::getThumbnailsDirPath () { string Paths::getThumbnailsDirPath () {
return ::getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_THUMBNAILS); return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathThumbnails);
} }
string Paths::getUserCertificatesDirPath () { string Paths::getUserCertificatesDirPath () {
return ::getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_USER_CERTIFICATES); return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathUserCertificates);
} }
string Paths::getZrtpSecretsFilePath () { string Paths::getZrtpSecretsFilePath () {
return ::getWritableFilePath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_ZRTP_SECRETS); return getWritableFilePath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + cPathZrtpSecrets);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static void migrateFile (const QString &oldPath, const QString &newPath) { static void migrateFile (const QString &oldPath, const QString &newPath) {
QFileInfo info(newPath); QFileInfo info(newPath);
::ensureDirPathExists(info.path()); ensureDirPathExists(info.path());
if (QFile::copy(oldPath, newPath)) { if (QFile::copy(oldPath, newPath)) {
QFile::remove(oldPath); QFile::remove(oldPath);
...@@ -251,7 +253,7 @@ static void migrateFile (const QString &oldPath, const QString &newPath) { ...@@ -251,7 +253,7 @@ static void migrateFile (const QString &oldPath, const QString &newPath) {
static void migrateConfigurationFile (const QString &oldPath, const QString &newPath) { static void migrateConfigurationFile (const QString &oldPath, const QString &newPath) {
QFileInfo info(newPath); QFileInfo info(newPath);
::ensureDirPathExists(info.path()); ensureDirPathExists(info.path());
if (QFile::copy(oldPath, newPath)) { if (QFile::copy(oldPath, newPath)) {
QFile oldFile(oldPath); QFile oldFile(oldPath);
...@@ -268,30 +270,30 @@ static void migrateConfigurationFile (const QString &oldPath, const QString &new ...@@ -268,30 +270,30 @@ static void migrateConfigurationFile (const QString &oldPath, const QString &new
} }
void Paths::migrate () { void Paths::migrate () {
QString newPath = ::getAppConfigFilePath(); QString newPath = getAppConfigFilePath();
QString oldBaseDir = QSysInfo::productType() == "windows" QString oldBaseDir = QSysInfo::productType() == "windows"
? QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) ? QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
: QStandardPaths::writableLocation(QStandardPaths::HomeLocation); : QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
QString oldPath = oldBaseDir + "/.linphonerc"; QString oldPath = oldBaseDir + "/.linphonerc";
if (!::filePathExists(newPath) && ::filePathExists(oldPath)) if (!filePathExists(newPath) && filePathExists(oldPath))
::migrateConfigurationFile(oldPath, newPath); migrateConfigurationFile(oldPath, newPath);
newPath = ::getAppCallHistoryFilePath(); newPath = getAppCallHistoryFilePath();
oldPath = oldBaseDir + "/.linphone-call-history.db"; oldPath = oldBaseDir + "/.linphone-call-history.db";
if (!::filePathExists(newPath) && ::filePathExists(oldPath)) if (!filePathExists(newPath) && filePathExists(oldPath))
::migrateFile(oldPath, newPath); migrateFile(oldPath, newPath);
newPath = ::getAppFriendsFilePath(); newPath = getAppFriendsFilePath();
oldPath = oldBaseDir + "/.linphone-friends.db"; oldPath = oldBaseDir + "/.linphone-friends.db";
if (!::filePathExists(newPath) && ::filePathExists(oldPath)) if (!filePathExists(newPath) && filePathExists(oldPath))
::migrateFile(oldPath, newPath); migrateFile(oldPath, newPath);
newPath = ::getAppMessageHistoryFilePath(); newPath = getAppMessageHistoryFilePath();
oldPath = oldBaseDir + "/.linphone-history.db"; oldPath = oldBaseDir + "/.linphone-history.db";
if (!::filePathExists(newPath) && ::filePathExists(oldPath)) if (!filePathExists(newPath) && filePathExists(oldPath))
::migrateFile(oldPath, newPath); migrateFile(oldPath, newPath);
} }
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