Commit 93371b87 authored by Ghislain MARY's avatar Ghislain MARY

Add some command line options.

parent 0840a90b
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS> <!DOCTYPE TS>
<TS version="2.1"> <TS version="2.1">
<context>
<name>App</name>
<message>
<source>Linphone seems to be running correctly</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Log to stdout some debug information while running.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Specify the linphone configuration file to use.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Run self test and exit 0 if it succeeded.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>A free SIP video-phone</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>CallControls</name> <name>CallControls</name>
<message> <message>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS> <!DOCTYPE TS>
<TS version="2.1"> <TS version="2.1">
<context>
<name>App</name>
<message>
<source>Linphone seems to be running correctly</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Log to stdout some debug information while running.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Specify the linphone configuration file to use.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Run self test and exit 0 if it succeeded.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>A free SIP video-phone</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>CallControls</name> <name>CallControls</name>
<message> <message>
......
...@@ -31,12 +31,14 @@ ...@@ -31,12 +31,14 @@
#include "../components/timeline/TimelineModel.hpp" #include "../components/timeline/TimelineModel.hpp"
#include "App.hpp" #include "App.hpp"
#include "Logger.hpp"
#include <QFileSelector> #include <QFileSelector>
#include <QMenu> #include <QMenu>
#include <QQmlComponent> #include <QQmlComponent>
#include <QQmlContext> #include <QQmlContext>
#include <QQuickView> #include <QQuickView>
#include <QTimer>
#include <QtDebug> #include <QtDebug>
#define LANGUAGES_PATH ":/languages/" #define LANGUAGES_PATH ":/languages/"
...@@ -52,6 +54,8 @@ ...@@ -52,6 +54,8 @@
App *App::m_instance = nullptr; App *App::m_instance = nullptr;
App::App (int &argc, char **argv) : QApplication(argc, argv) { App::App (int &argc, char **argv) : QApplication(argc, argv) {
this->setApplicationVersion("4.0");
if (m_english_translator.load(QLocale(QLocale::English), LANGUAGES_PATH)) if (m_english_translator.load(QLocale(QLocale::English), LANGUAGES_PATH))
installTranslator(&m_english_translator); installTranslator(&m_english_translator);
else else
...@@ -67,24 +71,6 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) { ...@@ -67,24 +71,6 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) {
qWarning() << QStringLiteral("Unable to found translations for locale: %1.") qWarning() << QStringLiteral("Unable to found translations for locale: %1.")
.arg(current_locale.name()); .arg(current_locale.name());
} }
// Provide avatars/thumbnails providers.
m_engine.addImageProvider(AvatarProvider::PROVIDER_ID, &m_avatar_provider);
m_engine.addImageProvider(ThumbnailProvider::PROVIDER_ID, &m_thumbnail_provider);
setWindowIcon(QIcon(WINDOW_ICON_PATH));
// Provide `+custom` folders for custom components.
m_file_selector = new QQmlFileSelector(&m_engine);
m_file_selector->setExtraSelectors(QStringList("custom"));
// Set modules paths.
m_engine.addImportPath(":/ui/modules");
m_engine.addImportPath(":/ui/scripts");
m_engine.addImportPath(":/ui/views");
// Don't quit if last window is closed!!!
setQuitOnLastWindowClosed(false);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -111,8 +97,26 @@ bool App::hasFocus () const { ...@@ -111,8 +97,26 @@ bool App::hasFocus () const {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void App::initContentApp () { void App::initContentApp () {
// Provide avatars/thumbnails providers.
m_engine.addImageProvider(AvatarProvider::PROVIDER_ID, &m_avatar_provider);
m_engine.addImageProvider(ThumbnailProvider::PROVIDER_ID, &m_thumbnail_provider);
setWindowIcon(QIcon(WINDOW_ICON_PATH));
// Provide `+custom` folders for custom components.
m_file_selector = new QQmlFileSelector(&m_engine);
m_file_selector->setExtraSelectors(QStringList("custom"));
// Set modules paths.
m_engine.addImportPath(":/ui/modules");
m_engine.addImportPath(":/ui/scripts");
m_engine.addImportPath(":/ui/views");
// Don't quit if last window is closed!!!
setQuitOnLastWindowClosed(false);
// Init core. // Init core.
CoreManager::init(); CoreManager::init(m_parser.value("config"));
qInfo() << "Core manager initialized."; qInfo() << "Core manager initialized.";
qInfo() << "Activated selectors:" << QQmlFileSelector::get(&m_engine)->selector()->allSelectors(); qInfo() << "Activated selectors:" << QQmlFileSelector::get(&m_engine)->selector()->allSelectors();
...@@ -141,6 +145,29 @@ void App::initContentApp () { ...@@ -141,6 +145,29 @@ void App::initContentApp () {
setTrayIcon(); setTrayIcon();
#endif // ifndef __APPLE__ #endif // ifndef __APPLE__
if (m_parser.isSet("selftest")) {
QTimer::singleShot(300, this, &App::quit);
}
}
// -----------------------------------------------------------------------------
void App::parseArgs () {
m_parser.setApplicationDescription(tr("A free SIP video-phone"));
m_parser.addHelpOption();
m_parser.addVersionOption();
m_parser.addOptions({
{ "config", tr("Specify the linphone configuration file to use."), "file" },
{ "selftest", tr("Run self test and exit 0 if it succeeded.") },
{ { "V", "verbose" }, tr("Log to stdout some debug information while running.") }
});
m_parser.process(*this);
if (m_parser.isSet("verbose")) {
Logger::instance()->setVerbose(true);
}
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -259,7 +286,7 @@ void App::setTrayIcon () { ...@@ -259,7 +286,7 @@ void App::setTrayIcon () {
// trayIcon: Right click actions. // trayIcon: Right click actions.
QAction *quit_action = new QAction("Quit", root); QAction *quit_action = new QAction("Quit", root);
root->connect(quit_action, &QAction::triggered, qApp, &QCoreApplication::quit); root->connect(quit_action, &QAction::triggered, this, &App::quit);
QAction *restore_action = new QAction("Restore", root); QAction *restore_action = new QAction("Restore", root);
root->connect(restore_action, &QAction::triggered, root, &QQuickWindow::showNormal); root->connect(restore_action, &QAction::triggered, root, &QQuickWindow::showNormal);
...@@ -288,3 +315,12 @@ void App::setTrayIcon () { ...@@ -288,3 +315,12 @@ void App::setTrayIcon () {
m_system_tray_icon->setToolTip("Linphone"); m_system_tray_icon->setToolTip("Linphone");
m_system_tray_icon->show(); m_system_tray_icon->show();
} }
// -----------------------------------------------------------------------------
void App::quit () {
if (m_parser.isSet("selftest")) {
cout << tr("Linphone seems to be running correctly").toStdString() << endl;
}
QCoreApplication::quit();
}
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "ThumbnailProvider.hpp" #include "ThumbnailProvider.hpp"
#include <QApplication> #include <QApplication>
#include <QCommandLineParser>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include <QQmlFileSelector> #include <QQmlFileSelector>
#include <QQuickWindow> #include <QQuickWindow>
...@@ -55,15 +56,18 @@ public: ...@@ -55,15 +56,18 @@ public:
Q_INVOKABLE QQuickWindow *getSettingsWindow () const; Q_INVOKABLE QQuickWindow *getSettingsWindow () const;
void initContentApp ();
Q_INVOKABLE QString locale () const { Q_INVOKABLE QString locale () const {
return m_locale; return m_locale;
} }
static void init (int &argc, char **argv) { void parseArgs ();
static void create (int &argc, char **argv) {
if (!m_instance) { if (!m_instance) {
// Instance must be exists before content. // Instance must be exists before content.
m_instance = new App(argc, argv); m_instance = new App(argc, argv);
m_instance->initContentApp();
} }
} }
...@@ -71,16 +75,18 @@ public: ...@@ -71,16 +75,18 @@ public:
return m_instance; return m_instance;
} }
public slots:
void quit ();
private: private:
App (int &argc, char **argv); App (int &argc, char **argv);
~App () = default; ~App () = default;
void initContentApp ();
void registerTypes (); void registerTypes ();
void createSubWindows (); void createSubWindows ();
void setTrayIcon (); void setTrayIcon ();
QCommandLineParser m_parser;
QQmlApplicationEngine m_engine; QQmlApplicationEngine m_engine;
QQmlFileSelector *m_file_selector = nullptr; QQmlFileSelector *m_file_selector = nullptr;
QSystemTrayIcon *m_system_tray_icon = nullptr; QSystemTrayIcon *m_system_tray_icon = nullptr;
......
...@@ -136,7 +136,7 @@ void Logger::init () { ...@@ -136,7 +136,7 @@ void Logger::init () {
linphone_core_set_log_level(ORTP_MESSAGE); linphone_core_set_log_level(ORTP_MESSAGE);
linphone_core_set_log_handler( linphone_core_set_log_handler(
[](const char *domain, OrtpLogLevel type, const char *fmt, va_list args) { [](const char *domain, OrtpLogLevel type, const char *fmt, va_list args) {
if (m_instance->m_display_core_logs) if (m_instance->isVerbose())
linphoneLogger(domain, type, fmt, args); linphoneLogger(domain, type, fmt, args);
} }
); );
......
...@@ -30,11 +30,15 @@ ...@@ -30,11 +30,15 @@
class Logger { class Logger {
public: public:
static void init (); static void init ();
static Logger * instance () { return m_instance; };
bool isVerbose () const { return m_verbose; };
void setVerbose (bool verbose) { m_verbose = verbose; };
private: private:
Logger () = default; Logger () = default;
bool m_display_core_logs = false; bool m_verbose = false;
static Logger *m_instance; static Logger *m_instance;
}; };
......
...@@ -96,7 +96,10 @@ string Paths::getCallHistoryFilepath () { ...@@ -96,7 +96,10 @@ string Paths::getCallHistoryFilepath () {
return getFilePath(MAIN_PATH + PATH_CALL_HISTORY_LIST); return getFilePath(MAIN_PATH + PATH_CALL_HISTORY_LIST);
} }
string Paths::getConfigFilepath () { string Paths::getConfigFilepath (const QString &configPath) {
if (!configPath.isEmpty()) {
return getFilePath(QFileInfo(configPath).absoluteFilePath());
}
return getFilePath(MAIN_PATH + PATH_CONFIG); return getFilePath(MAIN_PATH + PATH_CONFIG);
} }
......
...@@ -24,13 +24,14 @@ ...@@ -24,13 +24,14 @@
#define PATHS_H_ #define PATHS_H_
#include <string> #include <string>
#include <QString>
// ============================================================================= // =============================================================================
namespace Paths { namespace Paths {
std::string getAvatarsDirpath (); std::string getAvatarsDirpath ();
std::string getCallHistoryFilepath (); std::string getCallHistoryFilepath ();
std::string getConfigFilepath (); std::string getConfigFilepath (const QString &configPath);
std::string getFriendsListFilepath (); std::string getFriendsListFilepath ();
std::string getCapturesDirPath (); std::string getCapturesDirPath ();
std::string getLogsDirpath (); std::string getLogsDirpath ();
......
...@@ -35,20 +35,10 @@ using namespace std; ...@@ -35,20 +35,10 @@ using namespace std;
CoreManager *CoreManager::m_instance = nullptr; CoreManager *CoreManager::m_instance = nullptr;
CoreManager::CoreManager (QObject *parent) : QObject(parent), m_handlers(make_shared<CoreHandlers>()) { CoreManager::CoreManager (const QString &configPath, QObject *parent) : QObject(parent), m_handlers(make_shared<CoreHandlers>()) {
QDir dir(QCoreApplication::applicationDirPath()); setResourcesPaths();
if (dir.dirName() == "MacOS") {
dir.cdUp();
dir.cd("Resources");
QDir mspluginsdir(dir);
mspluginsdir.cd("lib/mediastreamer/plugins");
QDir datadir(dir);
datadir.cd("share");
linphone::Factory::get()->setMspluginsDir(::Utils::qStringToLinphoneString(mspluginsdir.absolutePath()));
linphone::Factory::get()->setTopResourcesDir(::Utils::qStringToLinphoneString(datadir.absolutePath()));
}
m_core = linphone::Factory::get()->createCore(m_handlers, Paths::getConfigFilepath(), ""); m_core = linphone::Factory::get()->createCore(m_handlers, Paths::getConfigFilepath(configPath), "");
m_core->setVideoDisplayFilter("MSOGL"); m_core->setVideoDisplayFilter("MSOGL");
m_core->usePreviewWindow(true); m_core->usePreviewWindow(true);
...@@ -60,9 +50,9 @@ void CoreManager::enableHandlers () { ...@@ -60,9 +50,9 @@ void CoreManager::enableHandlers () {
m_cbs_timer->start(); m_cbs_timer->start();
} }
void CoreManager::init () { void CoreManager::init (const QString &configPath) {
if (!m_instance) { if (!m_instance) {
m_instance = new CoreManager(); m_instance = new CoreManager(configPath);
m_instance->m_calls_list_model = new CallsListModel(m_instance); m_instance->m_calls_list_model = new CallsListModel(m_instance);
m_instance->m_contacts_list_model = new ContactsListModel(m_instance); m_instance->m_contacts_list_model = new ContactsListModel(m_instance);
...@@ -88,3 +78,17 @@ void CoreManager::setDatabasesPaths () { ...@@ -88,3 +78,17 @@ void CoreManager::setDatabasesPaths () {
m_core->setCallLogsDatabasePath(Paths::getCallHistoryFilepath()); m_core->setCallLogsDatabasePath(Paths::getCallHistoryFilepath());
m_core->setChatDatabasePath(Paths::getMessageHistoryFilepath()); m_core->setChatDatabasePath(Paths::getMessageHistoryFilepath());
} }
void CoreManager::setResourcesPaths () {
QDir dir(QCoreApplication::applicationDirPath());
if (dir.dirName() == "MacOS") {
dir.cdUp();
dir.cd("Resources");
QDir mspluginsdir(dir);
mspluginsdir.cd("lib/mediastreamer/plugins");
QDir datadir(dir);
datadir.cd("share");
linphone::Factory::get()->setMspluginsDir(::Utils::qStringToLinphoneString(mspluginsdir.absolutePath()));
linphone::Factory::get()->setTopResourcesDir(::Utils::qStringToLinphoneString(datadir.absolutePath()));
}
}
...@@ -68,7 +68,7 @@ public: ...@@ -68,7 +68,7 @@ public:
// Initialization. // Initialization.
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
static void init (); static void init (const QString &configPath);
static CoreManager *getInstance () { static CoreManager *getInstance () {
return m_instance; return m_instance;
...@@ -81,9 +81,10 @@ public: ...@@ -81,9 +81,10 @@ public:
Q_INVOKABLE VcardModel *createDetachedVcardModel (); Q_INVOKABLE VcardModel *createDetachedVcardModel ();
private: private:
CoreManager (QObject *parent = Q_NULLPTR); CoreManager (const QString &configPath, QObject *parent = Q_NULLPTR);
void setDatabasesPaths (); void setDatabasesPaths ();
void setResourcesPaths ();
std::shared_ptr<linphone::Core> m_core; std::shared_ptr<linphone::Core> m_core;
std::shared_ptr<CoreHandlers> m_handlers; std::shared_ptr<CoreHandlers> m_handlers;
......
...@@ -42,7 +42,9 @@ int main (int argc, char *argv[]) { ...@@ -42,7 +42,9 @@ int main (int argc, char *argv[]) {
* QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); * QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
*/ */
App::init(argc, argv); App::create(argc, argv);
App::getInstance()->parseArgs();
App::getInstance()->initContentApp();
// Run! // Run!
return App::getInstance()->exec(); return App::getInstance()->exec();
......
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