2021-07-06 10:20:46 -04:00
|
|
|
/*
|
2022-01-06 11:24:13 -05:00
|
|
|
* Copyright (C) 2015-2022 Savoir-faire Linux Inc.
|
2020-08-03 13:27:42 -04:00
|
|
|
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>
|
|
|
|
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
|
|
|
|
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
|
2020-08-28 12:04:45 -04:00
|
|
|
* Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
|
2020-08-03 13:27:42 -04:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mainapplication.h"
|
|
|
|
|
2021-03-30 15:15:36 -04:00
|
|
|
#include "qmlregister.h"
|
2020-09-01 14:31:31 -04:00
|
|
|
#include "appsettingsmanager.h"
|
2020-09-17 16:08:52 -04:00
|
|
|
#include "connectivitymonitor.h"
|
2021-03-30 15:15:36 -04:00
|
|
|
#include "systemtray.h"
|
2021-07-06 10:20:46 -04:00
|
|
|
#include "previewengine.h"
|
2021-03-30 15:15:36 -04:00
|
|
|
|
2020-08-31 15:57:10 -04:00
|
|
|
#include <QAction>
|
2020-09-17 16:08:52 -04:00
|
|
|
#include <QCommandLineParser>
|
|
|
|
#include <QCoreApplication>
|
2020-08-03 13:27:42 -04:00
|
|
|
#include <QFontDatabase>
|
2020-08-31 15:57:10 -04:00
|
|
|
#include <QMenu>
|
2020-08-03 13:27:42 -04:00
|
|
|
#include <QQmlContext>
|
2021-04-08 16:03:25 -04:00
|
|
|
#include <QResource>
|
|
|
|
#include <QTranslator>
|
|
|
|
#include <QLibraryInfo>
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
#include <locale.h>
|
2021-03-31 14:10:29 -04:00
|
|
|
#include <thread>
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2020-11-27 11:49:34 -05:00
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
#include "globalinstances.h"
|
|
|
|
#include "dbuserrorhandler.h"
|
|
|
|
#endif
|
|
|
|
|
2021-12-07 17:46:06 -05:00
|
|
|
#if defined _MSC_VER
|
2020-08-03 13:27:42 -04:00
|
|
|
#include <gnutls/gnutls.h>
|
|
|
|
#endif
|
|
|
|
|
2020-09-17 16:08:52 -04:00
|
|
|
namespace opts {
|
|
|
|
// Keys used to store command-line options.
|
|
|
|
constexpr static const char STARTMINIMIZED[] = "STARTMINIMIZED";
|
|
|
|
constexpr static const char DEBUG[] = "DEBUG";
|
|
|
|
constexpr static const char DEBUGCONSOLE[] = "DEBUGCONSOLE";
|
|
|
|
constexpr static const char DEBUGFILE[] = "DEBUGFILE";
|
|
|
|
constexpr static const char UPDATEURL[] = "UPDATEURL";
|
2021-06-21 13:15:58 -04:00
|
|
|
constexpr static const char MUTEDAEMON[] = "MUTEDAEMON";
|
2020-09-17 16:08:52 -04:00
|
|
|
} // namespace opts
|
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
static void
|
|
|
|
consoleDebug()
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
AllocConsole();
|
|
|
|
SetConsoleCP(CP_UTF8);
|
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
FILE* fpstdout = stdout;
|
|
|
|
freopen_s(&fpstdout, "CONOUT$", "w", stdout);
|
|
|
|
FILE* fpstderr = stderr;
|
|
|
|
freopen_s(&fpstderr, "CONOUT$", "w", stderr);
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
COORD coordInfo;
|
|
|
|
coordInfo.X = 130;
|
|
|
|
coordInfo.Y = 9000;
|
|
|
|
|
|
|
|
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coordInfo);
|
|
|
|
SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
static QString
|
|
|
|
getDebugFilePath()
|
|
|
|
{
|
|
|
|
QDir logPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation));
|
|
|
|
logPath.cdUp();
|
|
|
|
return QString(logPath.absolutePath() + "/jami/jami.log");
|
|
|
|
}
|
|
|
|
|
2021-02-23 16:22:00 -05:00
|
|
|
void
|
|
|
|
ScreenInfo::setCurrentFocusWindow(QWindow* window)
|
|
|
|
{
|
|
|
|
if (window && !currentFocusWindow_) {
|
|
|
|
currentFocusWindow_ = window;
|
2021-09-08 10:31:38 -04:00
|
|
|
set_devicePixelRatio(currentFocusWindow_->screen()->devicePixelRatio());
|
2021-02-23 16:22:00 -05:00
|
|
|
|
|
|
|
disconnect(devicePixelRatioConnection_);
|
|
|
|
disconnect(currentFocusWindowScreenConnection_);
|
|
|
|
|
|
|
|
currentFocusWindowScreenConnection_
|
|
|
|
= connect(currentFocusWindow_, &QWindow::screenChanged, [this] {
|
|
|
|
currentFocusWindowScreen_ = currentFocusWindow_->screen();
|
2021-09-08 10:31:38 -04:00
|
|
|
set_devicePixelRatio(currentFocusWindowScreen_->devicePixelRatio());
|
2021-02-23 16:22:00 -05:00
|
|
|
|
|
|
|
devicePixelRatioConnection_ = connect(
|
|
|
|
currentFocusWindowScreen_, &QScreen::physicalDotsPerInchChanged, [this] {
|
2021-09-08 10:31:38 -04:00
|
|
|
set_devicePixelRatio(currentFocusWindowScreen_->devicePixelRatio());
|
2021-02-23 16:22:00 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 13:30:45 -05:00
|
|
|
void
|
|
|
|
MainApplication::vsConsoleDebug()
|
|
|
|
{
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
/*
|
|
|
|
* Print debug to output window if using VS.
|
|
|
|
*/
|
|
|
|
QObject::connect(&lrcInstance_->behaviorController(),
|
|
|
|
&lrc::api::BehaviorController::debugMessageReceived,
|
|
|
|
[](const QString& message) {
|
|
|
|
OutputDebugStringA((message + "\n").toStdString().c_str());
|
|
|
|
});
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MainApplication::fileDebug(QFile* debugFile)
|
|
|
|
{
|
|
|
|
QObject::connect(&lrcInstance_->behaviorController(),
|
|
|
|
&lrc::api::BehaviorController::debugMessageReceived,
|
|
|
|
[debugFile](const QString& message) {
|
|
|
|
if (debugFile->open(QIODevice::WriteOnly | QIODevice::Append)) {
|
2021-06-18 17:23:40 -04:00
|
|
|
auto msg = (message + "\n").toStdString();
|
|
|
|
debugFile->write(msg.c_str(), qstrlen(msg.c_str()));
|
2021-03-11 13:30:45 -05:00
|
|
|
debugFile->close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
MainApplication::MainApplication(int& argc, char** argv)
|
|
|
|
: QApplication(argc, argv)
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2020-09-01 14:31:31 -04:00
|
|
|
QObject::connect(this, &QApplication::aboutToQuit, [this] { cleanup(); });
|
2022-01-28 12:11:04 -05:00
|
|
|
QObject::connect(settingsManager_.get(),
|
|
|
|
&AppSettingsManager::retranslate,
|
|
|
|
this,
|
|
|
|
&MainApplication::retranslate);
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
2021-12-22 17:36:29 -05:00
|
|
|
MainApplication::~MainApplication()
|
|
|
|
{
|
|
|
|
engine_.reset();
|
|
|
|
lrcInstance_.reset();
|
|
|
|
}
|
2021-05-14 15:04:12 -04:00
|
|
|
|
2020-11-27 11:49:34 -05:00
|
|
|
bool
|
2020-09-01 14:31:31 -04:00
|
|
|
MainApplication::init()
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2022-01-25 14:57:26 -05:00
|
|
|
// This 2-phase initialisation prevents ephemeral instances from
|
|
|
|
// performing unnecessary tasks, like initializing the webengine.
|
|
|
|
engine_.reset(new QQmlApplicationEngine(this));
|
|
|
|
connectivityMonitor_.reset(new ConnectivityMonitor(this));
|
|
|
|
settingsManager_.reset(new AppSettingsManager(this));
|
|
|
|
systemTray_.reset(new SystemTray(settingsManager_.get(), this));
|
|
|
|
previewEngine_.reset(new PreviewEngine(this));
|
|
|
|
|
2021-07-19 23:52:58 -04:00
|
|
|
setWindowIcon(QIcon(":/images/jami.ico"));
|
2020-09-17 14:17:56 -04:00
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
if (!getenv("QT_QPA_PLATFORMTHEME"))
|
|
|
|
setenv("QT_QPA_PLATFORMTHEME", "gtk3", true);
|
|
|
|
#endif
|
|
|
|
|
2020-09-17 16:08:52 -04:00
|
|
|
auto results = parseArguments();
|
|
|
|
|
|
|
|
if (results[opts::DEBUG].toBool()) {
|
|
|
|
consoleDebug();
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
Utils::removeOldVersions();
|
2022-01-28 12:11:04 -05:00
|
|
|
settingsManager_->loadTranslations();
|
2020-09-01 14:31:31 -04:00
|
|
|
setApplicationFont();
|
|
|
|
|
2021-12-07 17:46:06 -05:00
|
|
|
#if defined _MSC_VER
|
2020-09-01 14:31:31 -04:00
|
|
|
gnutls_global_init();
|
|
|
|
#endif
|
|
|
|
|
2021-06-21 13:15:58 -04:00
|
|
|
initLrc(results[opts::UPDATEURL].toString(),
|
|
|
|
connectivityMonitor_.get(),
|
2021-12-21 12:56:21 -05:00
|
|
|
results[opts::DEBUG].toBool() && !results[opts::MUTEDAEMON].toBool());
|
2021-01-12 17:22:13 +01:00
|
|
|
|
2021-10-18 12:09:08 -04:00
|
|
|
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
2021-08-23 12:43:31 -04:00
|
|
|
using namespace Interfaces;
|
|
|
|
GlobalInstances::setDBusErrorHandler(std::make_unique<DBusErrorHandler>());
|
2020-11-27 11:49:34 -05:00
|
|
|
auto dBusErrorHandlerQObject = dynamic_cast<QObject*>(&GlobalInstances::dBusErrorHandler());
|
2021-08-23 12:43:31 -04:00
|
|
|
QML_REGISTERSINGLETONTYPE_CUSTOM(NS_MODELS, DBusErrorHandler, dBusErrorHandlerQObject);
|
2020-11-27 11:49:34 -05:00
|
|
|
if ((!lrc::api::Lrc::isConnected()) || (!lrc::api::Lrc::dbusIsValid())) {
|
|
|
|
engine_->load(QUrl(QStringLiteral("qrc:/src/DaemonReconnectWindow.qml")));
|
|
|
|
exec();
|
|
|
|
|
|
|
|
if ((!lrc::api::Lrc::isConnected()) || (!lrc::api::Lrc::dbusIsValid()))
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
engine_.reset(new QQmlApplicationEngine());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-05-14 15:04:12 -04:00
|
|
|
connect(connectivityMonitor_.get(), &ConnectivityMonitor::connectivityChanged, [this] {
|
2021-03-11 13:30:45 -05:00
|
|
|
lrcInstance_->connectivityChanged();
|
2020-09-14 13:04:57 -04:00
|
|
|
});
|
|
|
|
|
2021-02-23 16:22:00 -05:00
|
|
|
connect(this, &QGuiApplication::focusWindowChanged, [this] {
|
|
|
|
screenInfo_.setCurrentFocusWindow(this->focusWindow());
|
|
|
|
});
|
|
|
|
|
2020-09-17 16:08:52 -04:00
|
|
|
QObject::connect(
|
2021-03-11 13:30:45 -05:00
|
|
|
lrcInstance_.get(),
|
2020-09-17 16:08:52 -04:00
|
|
|
&LRCInstance::quitEngineRequested,
|
|
|
|
this,
|
|
|
|
[this] { engine_->quit(); },
|
|
|
|
Qt::DirectConnection);
|
|
|
|
|
|
|
|
if (results[opts::DEBUGFILE].toBool()) {
|
|
|
|
debugFile_.reset(new QFile(getDebugFilePath()));
|
|
|
|
debugFile_->open(QIODevice::WriteOnly | QIODevice::Truncate);
|
|
|
|
debugFile_->close();
|
|
|
|
fileDebug(debugFile_.get());
|
|
|
|
}
|
2020-09-01 14:31:31 -04:00
|
|
|
|
2020-09-17 16:08:52 -04:00
|
|
|
if (results[opts::DEBUGCONSOLE].toBool()) {
|
|
|
|
vsConsoleDebug();
|
|
|
|
}
|
|
|
|
|
2021-03-30 15:15:36 -04:00
|
|
|
auto downloadPath = settingsManager_->getValue(Settings::Key::DownloadPath);
|
2021-07-09 16:05:36 -04:00
|
|
|
auto allowTransferFromUntrusted = settingsManager_->getValue(Settings::Key::AllowFromUntrusted)
|
|
|
|
.toBool();
|
|
|
|
auto allowTransferFromTrusted = settingsManager_->getValue(Settings::Key::AutoAcceptFiles)
|
|
|
|
.toBool();
|
|
|
|
auto acceptTransferBelow = settingsManager_->getValue(Settings::Key::AcceptTransferBelow).toInt();
|
2021-05-12 16:55:28 -04:00
|
|
|
lrcInstance_->accountModel().downloadDirectory = downloadPath.toString() + "/";
|
2021-07-09 16:05:36 -04:00
|
|
|
lrcInstance_->accountModel().autoTransferFromUntrusted = allowTransferFromUntrusted;
|
|
|
|
lrcInstance_->accountModel().autoTransferFromTrusted = allowTransferFromTrusted;
|
|
|
|
lrcInstance_->accountModel().autoTransferSizeThreshold = acceptTransferBelow;
|
2021-03-30 15:15:36 -04:00
|
|
|
|
|
|
|
initQmlLayer();
|
2021-12-23 14:22:08 -05:00
|
|
|
|
2022-01-11 13:38:57 -05:00
|
|
|
settingsManager_->setValue(Settings::Key::StartMinimized,
|
|
|
|
results[opts::STARTMINIMIZED].toBool());
|
2021-12-23 14:22:08 -05:00
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
initSystray();
|
2020-11-27 11:49:34 -05:00
|
|
|
|
|
|
|
return true;
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
2021-03-11 13:30:45 -05:00
|
|
|
void
|
|
|
|
MainApplication::restoreApp()
|
|
|
|
{
|
2021-03-29 16:51:53 -04:00
|
|
|
Q_EMIT lrcInstance_->restoreAppRequested();
|
2021-03-11 13:30:45 -05:00
|
|
|
}
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
void
|
2022-01-28 12:11:04 -05:00
|
|
|
MainApplication::retranslate()
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2022-01-28 12:11:04 -05:00
|
|
|
engine_->retranslate();
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-12-21 12:56:21 -05:00
|
|
|
MainApplication::initLrc(const QString& downloadUrl, ConnectivityMonitor* cm, bool logDaemon)
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2021-12-20 12:02:23 -05:00
|
|
|
lrc::api::Lrc::cacheAvatars.store(false);
|
2020-08-03 13:27:42 -04:00
|
|
|
/*
|
|
|
|
* Init mainwindow and finish splash when mainwindow shows up.
|
|
|
|
*/
|
|
|
|
std::atomic_bool isMigrating(false);
|
2021-03-11 13:30:45 -05:00
|
|
|
lrcInstance_.reset(new LRCInstance(
|
2020-08-03 13:27:42 -04:00
|
|
|
[this, &isMigrating] {
|
|
|
|
/*
|
|
|
|
* TODO: splash screen for account migration.
|
|
|
|
*/
|
|
|
|
isMigrating = true;
|
|
|
|
while (isMigrating) {
|
|
|
|
this->processEvents();
|
|
|
|
}
|
|
|
|
},
|
2020-09-01 14:31:31 -04:00
|
|
|
[&isMigrating] {
|
2020-08-03 13:27:42 -04:00
|
|
|
while (!isMigrating) {
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
|
}
|
|
|
|
isMigrating = false;
|
2020-09-17 16:08:52 -04:00
|
|
|
},
|
|
|
|
downloadUrl,
|
2021-06-21 13:15:58 -04:00
|
|
|
cm,
|
2021-12-21 12:56:21 -05:00
|
|
|
!logDaemon));
|
2021-03-11 13:30:45 -05:00
|
|
|
lrcInstance_->subscribeToDebugReceived();
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
2020-09-17 16:08:52 -04:00
|
|
|
const QVariantMap
|
|
|
|
MainApplication::parseArguments()
|
2020-09-11 15:19:19 -04:00
|
|
|
{
|
2020-09-17 16:08:52 -04:00
|
|
|
QVariantMap results;
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
|
|
|
|
2021-06-23 15:38:21 -04:00
|
|
|
// These options are potentially forced into the arg list.
|
2020-09-29 11:41:38 -04:00
|
|
|
QCommandLineOption webSecurityDisableOption(QStringList() << "disable-web-security");
|
|
|
|
parser.addOption(webSecurityDisableOption);
|
|
|
|
|
2021-06-23 15:38:21 -04:00
|
|
|
QCommandLineOption noSandboxOption(QStringList() << "no-sandbox");
|
|
|
|
parser.addOption(noSandboxOption);
|
|
|
|
|
|
|
|
QCommandLineOption singleProcessOption(QStringList() << "single-process");
|
|
|
|
parser.addOption(singleProcessOption);
|
|
|
|
|
2020-09-29 11:41:38 -04:00
|
|
|
QCommandLineOption webDebugOption(QStringList() << "remote-debugging-port",
|
|
|
|
"Web debugging port.",
|
|
|
|
"port");
|
|
|
|
parser.addOption(webDebugOption);
|
|
|
|
|
2021-06-21 13:15:58 -04:00
|
|
|
QCommandLineOption minimizedOption({"m", "minimized"}, "Start minimized.");
|
2020-09-17 16:08:52 -04:00
|
|
|
parser.addOption(minimizedOption);
|
|
|
|
|
2021-06-21 13:15:58 -04:00
|
|
|
QCommandLineOption debugOption({"d", "debug"}, "Debug out.");
|
2020-09-17 16:08:52 -04:00
|
|
|
parser.addOption(debugOption);
|
2020-09-11 15:19:19 -04:00
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
#ifdef Q_OS_WINDOWS
|
2021-06-21 13:15:58 -04:00
|
|
|
QCommandLineOption debugConsoleOption({"c", "console"}, "Debug out to IDE console.");
|
2020-09-17 16:08:52 -04:00
|
|
|
parser.addOption(debugConsoleOption);
|
|
|
|
|
2021-06-21 13:15:58 -04:00
|
|
|
QCommandLineOption debugFileOption({"f", "file"}, "Debug to file.");
|
2020-09-17 16:08:52 -04:00
|
|
|
parser.addOption(debugFileOption);
|
|
|
|
|
2021-06-21 13:15:58 -04:00
|
|
|
QCommandLineOption updateUrlOption({"u", "url"}, "<url> for debugging version queries.", "url");
|
2020-09-17 16:08:52 -04:00
|
|
|
parser.addOption(updateUrlOption);
|
2020-09-01 14:31:31 -04:00
|
|
|
#endif
|
2020-09-17 16:08:52 -04:00
|
|
|
|
2021-12-21 12:56:21 -05:00
|
|
|
QCommandLineOption muteDaemonOption({"q", "quiet"}, "Mute daemon logging. (only if debug)");
|
2021-06-21 13:15:58 -04:00
|
|
|
parser.addOption(muteDaemonOption);
|
|
|
|
|
2020-09-17 16:08:52 -04:00
|
|
|
parser.process(*this);
|
|
|
|
|
|
|
|
results[opts::STARTMINIMIZED] = parser.isSet(minimizedOption);
|
|
|
|
results[opts::DEBUG] = parser.isSet(debugOption);
|
|
|
|
#ifdef Q_OS_WINDOWS
|
|
|
|
results[opts::DEBUGCONSOLE] = parser.isSet(debugConsoleOption);
|
|
|
|
results[opts::DEBUGFILE] = parser.isSet(debugFileOption);
|
|
|
|
results[opts::UPDATEURL] = parser.value(updateUrlOption);
|
|
|
|
#endif
|
2021-06-21 13:15:58 -04:00
|
|
|
results[opts::MUTEDAEMON] = parser.isSet(muteDaemonOption);
|
|
|
|
|
2020-09-17 16:08:52 -04:00
|
|
|
return results;
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MainApplication::setApplicationFont()
|
|
|
|
{
|
|
|
|
QFont font;
|
|
|
|
font.setFamily("Segoe UI");
|
|
|
|
setFont(font);
|
2021-07-19 23:52:58 -04:00
|
|
|
QFontDatabase::addApplicationFont(":/fonts/FontAwesome.otf");
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-03-30 15:15:36 -04:00
|
|
|
MainApplication::initQmlLayer()
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2021-07-13 17:19:43 -04:00
|
|
|
// Expose custom types to the QML engine.
|
|
|
|
Utils::registerTypes(engine_.get(),
|
|
|
|
systemTray_.get(),
|
|
|
|
lrcInstance_.get(),
|
|
|
|
settingsManager_.get(),
|
2021-07-06 10:20:46 -04:00
|
|
|
previewEngine_.get(),
|
2021-07-13 17:19:43 -04:00
|
|
|
&screenInfo_,
|
|
|
|
this);
|
2020-11-27 11:49:34 -05:00
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
engine_->load(QUrl(QStringLiteral("qrc:/src/MainApplicationWindow.qml")));
|
|
|
|
}
|
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
void
|
|
|
|
MainApplication::initSystray()
|
|
|
|
{
|
2021-07-19 23:52:58 -04:00
|
|
|
systemTray_->setIcon(QIcon(":/images/jami.svg"));
|
2020-08-31 15:57:10 -04:00
|
|
|
|
|
|
|
QMenu* systrayMenu = new QMenu();
|
|
|
|
|
2021-05-25 14:52:39 -04:00
|
|
|
QString quitString;
|
|
|
|
#ifdef Q_OS_WINDOWS
|
|
|
|
quitString = tr("E&xit");
|
|
|
|
#else
|
|
|
|
quitString = tr("&Quit");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QAction* quitAction = new QAction(quitString, this);
|
2022-01-11 13:38:57 -05:00
|
|
|
connect(quitAction, &QAction::triggered, this, &MainApplication::closeRequested);
|
2021-05-25 14:52:39 -04:00
|
|
|
|
2021-06-02 11:11:36 -04:00
|
|
|
QAction* restoreAction = new QAction(tr("&Show Jami"), this);
|
|
|
|
connect(restoreAction, &QAction::triggered, this, &MainApplication::restoreApp);
|
|
|
|
|
2021-05-14 15:04:12 -04:00
|
|
|
connect(systemTray_.get(),
|
2021-03-30 15:15:36 -04:00
|
|
|
&QSystemTrayIcon::activated,
|
2022-01-11 13:38:57 -05:00
|
|
|
this,
|
2021-03-30 15:15:36 -04:00
|
|
|
[this](QSystemTrayIcon::ActivationReason reason) {
|
2021-05-31 15:28:30 -04:00
|
|
|
if (reason != QSystemTrayIcon::ActivationReason::Context) {
|
|
|
|
#ifdef Q_OS_WINDOWS
|
2021-03-30 15:15:36 -04:00
|
|
|
restoreApp();
|
2021-05-31 15:28:30 -04:00
|
|
|
#else
|
|
|
|
QWindow* window = focusWindow();
|
|
|
|
if (window)
|
|
|
|
window->close();
|
|
|
|
else
|
|
|
|
restoreApp();
|
|
|
|
#endif
|
|
|
|
}
|
2021-03-30 15:15:36 -04:00
|
|
|
});
|
2020-08-31 15:57:10 -04:00
|
|
|
|
2021-06-02 11:11:36 -04:00
|
|
|
systrayMenu->addAction(restoreAction);
|
2021-05-25 14:52:39 -04:00
|
|
|
systrayMenu->addAction(quitAction);
|
2021-03-30 15:15:36 -04:00
|
|
|
systemTray_->setContextMenu(systrayMenu);
|
|
|
|
systemTray_->show();
|
2020-09-01 14:31:31 -04:00
|
|
|
}
|
2020-08-31 15:57:10 -04:00
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
void
|
|
|
|
MainApplication::cleanup()
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
FreeConsole();
|
|
|
|
#endif
|
|
|
|
QApplication::exit(0);
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|