2021-07-06 10:20:46 -04:00
|
|
|
/*
|
2023-02-06 01:47:15 -05:00
|
|
|
* Copyright (C) 2015-2023 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"
|
2022-02-11 09:25:33 -05:00
|
|
|
#include "videoprovider.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>
|
2022-08-10 10:36:39 -04:00
|
|
|
#include <QTimer>
|
2021-04-08 16:03:25 -04:00
|
|
|
#include <QTranslator>
|
|
|
|
#include <QLibraryInfo>
|
2022-03-16 17:36:17 -04:00
|
|
|
#include <QQuickWindow>
|
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
|
|
|
|
|
2022-03-16 17:36:17 -04:00
|
|
|
static QString
|
|
|
|
getRenderInterfaceString()
|
|
|
|
{
|
|
|
|
using GAPI = QSGRendererInterface::GraphicsApi;
|
|
|
|
switch (QQuickWindow::graphicsApi()) {
|
|
|
|
case GAPI::Direct3D11Rhi:
|
|
|
|
return "Direct3D11Rhi";
|
|
|
|
case GAPI::MetalRhi:
|
|
|
|
return "MetalRhi";
|
|
|
|
case GAPI::OpenGLRhi:
|
|
|
|
return "OpenGLRhi";
|
|
|
|
case GAPI::VulkanRhi:
|
|
|
|
return "VulkanRhi";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2023-05-16 14:02:14 -04:00
|
|
|
QObject::connect(currentFocusWindow_,
|
|
|
|
&QWindow::screenChanged,
|
|
|
|
this,
|
|
|
|
&ScreenInfo::onScreenChanged,
|
|
|
|
Qt::UniqueConnection);
|
2021-02-23 16:22:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-16 14:02:14 -04:00
|
|
|
void
|
|
|
|
ScreenInfo::onScreenChanged()
|
|
|
|
{
|
|
|
|
currentFocusWindowScreen_ = currentFocusWindow_->screen();
|
|
|
|
set_devicePixelRatio(currentFocusWindowScreen_->devicePixelRatio());
|
|
|
|
|
|
|
|
QObject::connect(currentFocusWindowScreen_,
|
|
|
|
&QScreen::physicalDotsPerInchChanged,
|
|
|
|
this,
|
|
|
|
&ScreenInfo::onPhysicalDotsPerInchChanged,
|
|
|
|
Qt::UniqueConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ScreenInfo::onPhysicalDotsPerInchChanged()
|
|
|
|
{
|
|
|
|
set_devicePixelRatio(currentFocusWindowScreen_->devicePixelRatio());
|
|
|
|
}
|
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
MainApplication::MainApplication(int& argc, char** argv)
|
2023-10-18 16:06:56 -04:00
|
|
|
: QApplication(argc, argv)
|
|
|
|
, isCleanupped(false)
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2022-03-08 14:44:53 -05:00
|
|
|
const char* qtVersion = qVersion();
|
2022-03-24 10:32:00 -04:00
|
|
|
qInfo() << "Using Qt runtime version:" << qtVersion;
|
2022-03-08 14:44:53 -05:00
|
|
|
if (strncmp(qtVersion, QT_VERSION_STR, strnlen(qtVersion, sizeof qtVersion)) != 0) {
|
2022-04-07 08:59:21 -04:00
|
|
|
qFatal("Qt build version mismatch! %s", QT_VERSION_STR);
|
2022-03-08 14:44:53 -05:00
|
|
|
}
|
|
|
|
|
2022-01-21 14:42:35 -05:00
|
|
|
parseArguments();
|
2023-01-06 14:07:33 -05:00
|
|
|
QObject::connect(this, &QApplication::aboutToQuit, this, &MainApplication::cleanup);
|
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));
|
|
|
|
|
2023-11-14 17:53:00 -05:00
|
|
|
connectivityMonitor_ = new ConnectivityMonitor(this);
|
|
|
|
settingsManager_ = new AppSettingsManager(this);
|
|
|
|
systemTray_ = new SystemTray(settingsManager_, this);
|
|
|
|
|
|
|
|
QObject::connect(settingsManager_,
|
2022-02-01 17:07:16 -05:00
|
|
|
&AppSettingsManager::retranslate,
|
|
|
|
engine_.get(),
|
|
|
|
&QQmlApplicationEngine::retranslate);
|
|
|
|
|
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
|
|
|
Utils::removeOldVersions();
|
2023-02-14 14:01:40 -03:00
|
|
|
qputenv("JAMI_LANG", settingsManager_->getLanguage().toUtf8());
|
2022-01-28 12:11:04 -05:00
|
|
|
settingsManager_->loadTranslations();
|
2020-09-01 14:31:31 -04:00
|
|
|
setApplicationFont();
|
|
|
|
|
2022-01-21 14:42:35 -05:00
|
|
|
initLrc(runOptions_[Option::UpdateUrl].toString(),
|
2023-11-14 17:53:00 -05:00
|
|
|
connectivityMonitor_,
|
2023-06-27 07:58:48 -04:00
|
|
|
runOptions_[Option::Debug].toBool(),
|
|
|
|
runOptions_[Option::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())) {
|
2022-09-19 11:19:49 -04:00
|
|
|
engine_->load(QUrl(QStringLiteral("qrc:/DaemonReconnectWindow.qml")));
|
2020-11-27 11:49:34 -05:00
|
|
|
exec();
|
|
|
|
|
2022-01-21 14:42:35 -05:00
|
|
|
if ((!lrc::api::Lrc::isConnected()) || (!lrc::api::Lrc::dbusIsValid())) {
|
|
|
|
qWarning() << "Can't connect to the daemon via D-Bus.";
|
2020-11-27 11:49:34 -05:00
|
|
|
return false;
|
2022-01-21 14:42:35 -05:00
|
|
|
} else {
|
2020-11-27 11:49:34 -05:00
|
|
|
engine_.reset(new QQmlApplicationEngine());
|
2022-01-21 14:42:35 -05:00
|
|
|
}
|
2020-11-27 11:49:34 -05:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-11-14 17:53:00 -05:00
|
|
|
connect(connectivityMonitor_, &ConnectivityMonitor::connectivityChanged, this, [this] {
|
2022-08-10 10:36:39 -04:00
|
|
|
QTimer::singleShot(500, this, [&]() { 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());
|
|
|
|
});
|
|
|
|
|
2021-03-30 15:15:36 -04:00
|
|
|
auto downloadPath = settingsManager_->getValue(Settings::Key::DownloadPath);
|
2023-01-10 16:47:18 -05:00
|
|
|
auto screenshotPath = settingsManager_->getValue(Settings::Key::ScreenshotPath);
|
2021-07-09 16:05:36 -04:00
|
|
|
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() + "/";
|
2023-01-10 16:47:18 -05:00
|
|
|
lrcInstance_->accountModel().screenshotDirectory = screenshotPath.toString();
|
2021-07-09 16:05:36 -04:00
|
|
|
lrcInstance_->accountModel().autoTransferFromTrusted = allowTransferFromTrusted;
|
|
|
|
lrcInstance_->accountModel().autoTransferSizeThreshold = acceptTransferBelow;
|
2021-03-30 15:15:36 -04:00
|
|
|
|
2022-01-25 13:10:12 -05:00
|
|
|
auto startMinimizedSetting = settingsManager_->getValue(Settings::Key::StartMinimized).toBool();
|
|
|
|
// The presence of start URI should override the startMinimized setting for this instance.
|
|
|
|
set_startMinimized(startMinimizedSetting && runOptions_[Option::StartUri].isNull());
|
2022-04-05 15:04:26 -04:00
|
|
|
#ifdef WITH_WEBENGINE
|
|
|
|
engine_.get()->rootContext()->setContextProperty("WITH_WEBENGINE", QVariant(true));
|
|
|
|
#else
|
|
|
|
engine_.get()->rootContext()->setContextProperty("WITH_WEBENGINE", QVariant(false));
|
|
|
|
#endif
|
2022-01-25 13:10:12 -05:00
|
|
|
|
2023-10-18 16:06:56 -04:00
|
|
|
#ifdef APPSTORE
|
|
|
|
engine_.get()->rootContext()->setContextProperty("APPSTORE", QVariant(true));
|
|
|
|
#else
|
|
|
|
engine_.get()->rootContext()->setContextProperty("APPSTORE", QVariant(false));
|
|
|
|
#endif
|
|
|
|
|
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,
|
2022-01-21 14:42:35 -05:00
|
|
|
runOptions_[Option::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
|
|
|
}
|
|
|
|
|
2022-01-25 13:10:12 -05:00
|
|
|
void
|
|
|
|
MainApplication::handleUriAction(const QString& arg)
|
|
|
|
{
|
|
|
|
QString uri {};
|
|
|
|
if (arg.isEmpty() && !runOptions_[Option::StartUri].isNull()) {
|
|
|
|
uri = runOptions_[Option::StartUri].toString();
|
|
|
|
qDebug() << "URI action invoked by run option" << uri;
|
2022-03-28 09:54:32 -04:00
|
|
|
} else if (!arg.isEmpty()) {
|
2022-01-25 13:10:12 -05:00
|
|
|
uri = arg;
|
|
|
|
qDebug() << "URI action invoked by secondary instance" << uri;
|
2022-09-01 15:21:58 -04:00
|
|
|
Q_EMIT searchAndSelect(uri.replace("jami:", ""));
|
2022-01-25 13:10:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
void
|
2023-06-27 07:58:48 -04:00
|
|
|
MainApplication::initLrc(const QString& downloadUrl,
|
|
|
|
ConnectivityMonitor* cm,
|
|
|
|
bool debugMode,
|
|
|
|
bool muteDaemon)
|
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,
|
2023-06-27 07:58:48 -04:00
|
|
|
debugMode,
|
|
|
|
muteDaemon));
|
2021-03-11 13:30:45 -05:00
|
|
|
lrcInstance_->subscribeToDebugReceived();
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
2022-01-21 14:42:35 -05:00
|
|
|
void
|
2020-09-17 16:08:52 -04:00
|
|
|
MainApplication::parseArguments()
|
2020-09-11 15:19:19 -04:00
|
|
|
{
|
2022-01-25 13:10:12 -05:00
|
|
|
// See if the app is being started with a URI.
|
|
|
|
for (const auto& arg : QApplication::arguments()) {
|
|
|
|
if (arg.startsWith("jami:")) {
|
|
|
|
runOptions_[Option::StartUri] = arg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-17 16:08:52 -04:00
|
|
|
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
|
|
|
|
2022-03-11 18:07:50 -05:00
|
|
|
QCommandLineOption logFileOption({"f", "file"}, "Debug to <file>.", "file");
|
|
|
|
parser.addOption(logFileOption);
|
2022-01-21 14:42:35 -05:00
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
#ifdef Q_OS_WINDOWS
|
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);
|
2022-01-21 14:42:35 -05:00
|
|
|
|
2020-09-01 14:31:31 -04:00
|
|
|
#endif
|
2022-01-21 14:42:35 -05:00
|
|
|
QCommandLineOption terminateOption({"t", "term"}, "Terminate all instances.");
|
|
|
|
parser.addOption(terminateOption);
|
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);
|
|
|
|
|
2022-01-21 14:42:35 -05:00
|
|
|
runOptions_[Option::StartMinimized] = parser.isSet(minimizedOption);
|
|
|
|
runOptions_[Option::Debug] = parser.isSet(debugOption);
|
2022-03-11 18:07:50 -05:00
|
|
|
if (parser.isSet(logFileOption)) {
|
|
|
|
auto logFileValue = parser.value(logFileOption);
|
|
|
|
auto logFile = logFileValue.isEmpty() ? Utils::getDebugFilePath() : logFileValue;
|
|
|
|
qputenv("JAMI_LOG_FILE", logFile.toStdString().c_str());
|
|
|
|
}
|
2020-09-17 16:08:52 -04:00
|
|
|
#ifdef Q_OS_WINDOWS
|
2022-01-21 14:42:35 -05:00
|
|
|
runOptions_[Option::UpdateUrl] = parser.value(updateUrlOption);
|
2020-09-17 16:08:52 -04:00
|
|
|
#endif
|
2022-01-21 14:42:35 -05:00
|
|
|
runOptions_[Option::TerminationRequested] = parser.isSet(terminateOption);
|
2023-06-27 07:58:48 -04:00
|
|
|
runOptions_[Option::MuteDaemon] = parser.isSet(muteDaemonOption);
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MainApplication::setApplicationFont()
|
|
|
|
{
|
2022-11-25 16:09:44 -05:00
|
|
|
QStringList fontFamilies {"Ubuntu"};
|
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
QFontDatabase::addApplicationFont(":/fonts/NotoColorEmoji.ttf");
|
|
|
|
fontFamilies += "NotoColorEmoji";
|
|
|
|
#endif
|
2020-08-03 13:27:42 -04:00
|
|
|
QFont font;
|
2022-11-25 16:09:44 -05:00
|
|
|
font.setFamilies(fontFamilies);
|
2020-08-03 13:27:42 -04:00
|
|
|
setFont(font);
|
|
|
|
}
|
|
|
|
|
|
|
|
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(),
|
|
|
|
lrcInstance_.get(),
|
2023-11-14 17:53:00 -05:00
|
|
|
systemTray_,
|
|
|
|
settingsManager_,
|
|
|
|
connectivityMonitor_,
|
2021-07-13 17:19:43 -04:00
|
|
|
&screenInfo_,
|
|
|
|
this);
|
2020-11-27 11:49:34 -05:00
|
|
|
|
2022-02-11 09:25:33 -05:00
|
|
|
auto videoProvider = new VideoProvider(lrcInstance_->avModel(), this);
|
|
|
|
engine_->rootContext()->setContextProperty("videoProvider", videoProvider);
|
|
|
|
|
2022-09-19 11:19:49 -04:00
|
|
|
engine_->load(QUrl(QStringLiteral("qrc:/MainApplicationWindow.qml")));
|
2022-03-16 17:36:17 -04:00
|
|
|
qWarning().noquote() << "Main window loaded using" << getRenderInterfaceString();
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2023-11-14 17:53:00 -05:00
|
|
|
connect(systemTray_,
|
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();
|
2022-03-22 15:58:53 -04:00
|
|
|
#elif !defined(Q_OS_MACOS)
|
2021-05-31 15:28:30 -04:00
|
|
|
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()
|
|
|
|
{
|
2023-10-03 19:18:20 +08:00
|
|
|
// In Qt 6.5, QApplication::exit(0) will signal aboutToQuit, and aboutToQuit is connected to cleanup
|
|
|
|
// TODO: delete cleanup.
|
|
|
|
if (!isCleanupped) {
|
|
|
|
isCleanupped = true;
|
|
|
|
QApplication::exit(0);
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
2022-02-03 17:16:47 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
MainApplication::setEventFilter()
|
|
|
|
{
|
|
|
|
installEventFilter(this);
|
|
|
|
}
|