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

Add some command line options.

parent 0840a90b
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<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>
<name>CallControls</name>
<message>
......
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<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>
<name>CallControls</name>
<message>
......
......@@ -31,12 +31,14 @@
#include "../components/timeline/TimelineModel.hpp"
#include "App.hpp"
#include "Logger.hpp"
#include <QFileSelector>
#include <QMenu>
#include <QQmlComponent>
#include <QQmlContext>
#include <QQuickView>
#include <QTimer>
#include <QtDebug>
#define LANGUAGES_PATH ":/languages/"
......@@ -52,6 +54,8 @@
App *App::m_instance = nullptr;
App::App (int &argc, char **argv) : QApplication(argc, argv) {
this->setApplicationVersion("4.0");
if (m_english_translator.load(QLocale(QLocale::English), LANGUAGES_PATH))
installTranslator(&m_english_translator);
else
......@@ -67,24 +71,6 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) {
qWarning() << QStringLiteral("Unable to found translations for locale: %1.")
.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 {
// -----------------------------------------------------------------------------
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.
CoreManager::init();
CoreManager::init(m_parser.value("config"));
qInfo() << "Core manager initialized.";
qInfo() << "Activated selectors:" << QQmlFileSelector::get(&m_engine)->selector()->allSelectors();
......@@ -141,6 +145,29 @@ void App::initContentApp () {
setTrayIcon();
#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 () {
// trayIcon: Right click actions.
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);
root->connect(restore_action, &QAction::triggered, root, &QQuickWindow::showNormal);
......@@ -288,3 +315,12 @@ void App::setTrayIcon () {
m_system_tray_icon->setToolTip("Linphone");
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 @@
#include "ThumbnailProvider.hpp"
#include <QApplication>
#include <QCommandLineParser>
#include <QQmlApplicationEngine>
#include <QQmlFileSelector>
#include <QQuickWindow>
......@@ -55,15 +56,18 @@ public:
Q_INVOKABLE QQuickWindow *getSettingsWindow () const;
void initContentApp ();
Q_INVOKABLE QString locale () const {
return m_locale;
}
static void init (int &argc, char **argv) {
void parseArgs ();
static void create (int &argc, char **argv) {
if (!m_instance) {
// Instance must be exists before content.
m_instance = new App(argc, argv);
m_instance->initContentApp();
}
}
......@@ -71,16 +75,18 @@ public:
return m_instance;
}
public slots:
void quit ();
private:
App (int &argc, char **argv);
~App () = default;
void initContentApp ();
void registerTypes ();
void createSubWindows ();
void setTrayIcon ();
QCommandLineParser m_parser;
QQmlApplicationEngine m_engine;
QQmlFileSelector *m_file_selector = nullptr;
QSystemTrayIcon *m_system_tray_icon = nullptr;
......
......@@ -136,7 +136,7 @@ void Logger::init () {
linphone_core_set_log_level(ORTP_MESSAGE);
linphone_core_set_log_handler(
[](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);
}
);
......
......@@ -30,11 +30,15 @@
class Logger {
public:
static void init ();
static Logger * instance () { return m_instance; };
bool isVerbose () const { return m_verbose; };
void setVerbose (bool verbose) { m_verbose = verbose; };
private:
Logger () = default;
bool m_display_core_logs = false;
bool m_verbose = false;
static Logger *m_instance;
};
......
......@@ -96,7 +96,10 @@ string Paths::getCallHistoryFilepath () {
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);
}
......
......@@ -24,13 +24,14 @@
#define PATHS_H_
#include <string>
#include <QString>
// =============================================================================
namespace Paths {
std::string getAvatarsDirpath ();
std::string getCallHistoryFilepath ();
std::string getConfigFilepath ();
std::string getConfigFilepath (const QString &configPath);
std::string getFriendsListFilepath ();
std::string getCapturesDirPath ();
std::string getLogsDirpath ();
......
......@@ -35,20 +35,10 @@ using namespace std;
CoreManager *CoreManager::m_instance = nullptr;
CoreManager::CoreManager (QObject *parent) : QObject(parent), m_handlers(make_shared<CoreHandlers>()) {
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()));
}
CoreManager::CoreManager (const QString &configPath, QObject *parent) : QObject(parent), m_handlers(make_shared<CoreHandlers>()) {
setResourcesPaths();
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->usePreviewWindow(true);
......@@ -60,9 +50,9 @@ void CoreManager::enableHandlers () {
m_cbs_timer->start();
}
void CoreManager::init () {
void CoreManager::init (const QString &configPath) {
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_contacts_list_model = new ContactsListModel(m_instance);
......@@ -88,3 +78,17 @@ void CoreManager::setDatabasesPaths () {
m_core->setCallLogsDatabasePath(Paths::getCallHistoryFilepath());
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:
// Initialization.
// ---------------------------------------------------------------------------
static void init ();
static void init (const QString &configPath);
static CoreManager *getInstance () {
return m_instance;
......@@ -81,9 +81,10 @@ public:
Q_INVOKABLE VcardModel *createDetachedVcardModel ();
private:
CoreManager (QObject *parent = Q_NULLPTR);
CoreManager (const QString &configPath, QObject *parent = Q_NULLPTR);
void setDatabasesPaths ();
void setResourcesPaths ();
std::shared_ptr<linphone::Core> m_core;
std::shared_ptr<CoreHandlers> m_handlers;
......
......@@ -42,7 +42,9 @@ int main (int argc, char *argv[]) {
* QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
*/
App::init(argc, argv);
App::create(argc, argv);
App::getInstance()->parseArgs();
App::getInstance()->initContentApp();
// Run!
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