mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-08-29 19:23:40 +02:00
ptt: use 1 instance only and register as a QML singleton
- Prevents resetting the app-scope context property which prevents the Windows global listener callback from working. - Removes unused QScopedPointers Change-Id: I836d803d5a1f4093e241330c1e5dd478c743ed54
This commit is contained in:
parent
8d41ab6eb9
commit
52f95ac8ed
9 changed files with 48 additions and 49 deletions
|
@ -26,23 +26,30 @@
|
||||||
#include "calladapter.h"
|
#include "calladapter.h"
|
||||||
|
|
||||||
#include "systemtray.h"
|
#include "systemtray.h"
|
||||||
#include "utils.h"
|
|
||||||
#include "qmlregister.h"
|
#include "qmlregister.h"
|
||||||
|
#include "appsettingsmanager.h"
|
||||||
#include <QApplication>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QJsonObject>
|
|
||||||
|
|
||||||
#include <api/callmodel.h>
|
#include <api/callmodel.h>
|
||||||
#include <api/callparticipantsmodel.h>
|
#include <api/callparticipantsmodel.h>
|
||||||
|
|
||||||
#include <media_const.h>
|
#include <media_const.h>
|
||||||
|
|
||||||
CallAdapter::CallAdapter(SystemTray* systemTray, LRCInstance* instance, QObject* parent)
|
#include <QApplication>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
CallAdapter::CallAdapter(AppSettingsManager* settingsManager,
|
||||||
|
SystemTray* systemTray,
|
||||||
|
LRCInstance* instance,
|
||||||
|
QObject* parent)
|
||||||
: QmlAdapterBase(instance, parent)
|
: QmlAdapterBase(instance, parent)
|
||||||
, systemTray_(systemTray)
|
, systemTray_(systemTray)
|
||||||
, callInformationListModel_(std::make_unique<CallInformationListModel>())
|
, callInformationListModel_(std::make_unique<CallInformationListModel>())
|
||||||
|
, listener_(new PTTListener(settingsManager, this))
|
||||||
{
|
{
|
||||||
|
// Expose the Push-to-talk listener to QML as a singleton
|
||||||
|
QML_REGISTERSINGLETONTYPE_POBJECT(NS_MODELS, listener_, "PttListener");
|
||||||
|
|
||||||
set_callInformationList(QVariant::fromValue(callInformationListModel_.get()));
|
set_callInformationList(QVariant::fromValue(callInformationListModel_.get()));
|
||||||
|
|
||||||
timer = new QTimer(this);
|
timer = new QTimer(this);
|
||||||
|
@ -232,7 +239,7 @@ CallAdapter::onCallStarted(const QString& callId)
|
||||||
// update call Information list by adding the new information related to the callId
|
// update call Information list by adding the new information related to the callId
|
||||||
callInformationListModel_->addElement(
|
callInformationListModel_->addElement(
|
||||||
qMakePair(callId, callModel->advancedInformationForCallId(callId)));
|
qMakePair(callId, callModel->advancedInformationForCallId(callId)));
|
||||||
if (listener_->getPttState()){
|
if (listener_->getPttState()) {
|
||||||
#ifdef HAVE_GLOBAL_PTT
|
#ifdef HAVE_GLOBAL_PTT
|
||||||
listener_->startListening();
|
listener_->startListening();
|
||||||
toMute += callId;
|
toMute += callId;
|
||||||
|
@ -976,7 +983,8 @@ CallAdapter::muteCameraToggle()
|
||||||
callModel->removeMedia(callId,
|
callModel->removeMedia(callId,
|
||||||
libjami::Media::Details::MEDIA_TYPE_VIDEO,
|
libjami::Media::Details::MEDIA_TYPE_VIDEO,
|
||||||
libjami::Media::VideoProtocolPrefix::CAMERA,
|
libjami::Media::VideoProtocolPrefix::CAMERA,
|
||||||
mute, false);
|
mute,
|
||||||
|
false);
|
||||||
else
|
else
|
||||||
callModel->addMedia(callId,
|
callModel->addMedia(callId,
|
||||||
lrcInstance_->avModel().getCurrentVideoCaptureDevice(),
|
lrcInstance_->avModel().getCurrentVideoCaptureDevice(),
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include "callInformationListModel.h"
|
#include "callInformationListModel.h"
|
||||||
|
|
||||||
class SystemTray;
|
class SystemTray;
|
||||||
|
class AppSettingsManager;
|
||||||
|
|
||||||
class CallAdapter final : public QmlAdapterBase
|
class CallAdapter final : public QmlAdapterBase
|
||||||
{
|
{
|
||||||
|
@ -49,7 +50,10 @@ public:
|
||||||
enum MuteStates { UNMUTED, LOCAL_MUTED, MODERATOR_MUTED, BOTH_MUTED };
|
enum MuteStates { UNMUTED, LOCAL_MUTED, MODERATOR_MUTED, BOTH_MUTED };
|
||||||
Q_ENUM(MuteStates)
|
Q_ENUM(MuteStates)
|
||||||
|
|
||||||
explicit CallAdapter(SystemTray* systemTray, LRCInstance* instance, QObject* parent = nullptr);
|
explicit CallAdapter(AppSettingsManager* settingsManager,
|
||||||
|
SystemTray* systemTray,
|
||||||
|
LRCInstance* instance,
|
||||||
|
QObject* parent = nullptr);
|
||||||
~CallAdapter();
|
~CallAdapter();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -131,7 +135,7 @@ private:
|
||||||
VectorString currentConfSubcalls_;
|
VectorString currentConfSubcalls_;
|
||||||
std::unique_ptr<CallInformationListModel> callInformationListModel_;
|
std::unique_ptr<CallInformationListModel> callInformationListModel_;
|
||||||
|
|
||||||
PTTListener* listener_ = new PTTListener(systemTray_->getSettingsManager());
|
PTTListener* listener_;
|
||||||
bool isMicrophoneMuted_ = true;
|
bool isMicrophoneMuted_ = true;
|
||||||
QSet<QString> toMute;
|
QSet<QString> toMute;
|
||||||
};
|
};
|
||||||
|
|
|
@ -102,7 +102,7 @@ BaseModalDialog {
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (!(pressedKey === Qt.Key_unknown)){
|
if (!(pressedKey === Qt.Key_unknown)){
|
||||||
pttListener.setPttKey(pressedKey);
|
PttListener.setPttKey(pressedKey);
|
||||||
choiceMade(pressedKey);
|
choiceMade(pressedKey);
|
||||||
}
|
}
|
||||||
close();
|
close();
|
||||||
|
@ -113,7 +113,7 @@ BaseModalDialog {
|
||||||
id: keyItem
|
id: keyItem
|
||||||
|
|
||||||
Keys.onPressed: (event)=>{
|
Keys.onPressed: (event)=>{
|
||||||
keyLabel.text = pttListener.keyToString(event.key);
|
keyLabel.text = PttListener.keyToString(event.key);
|
||||||
pressedKey = event.key;
|
pressedKey = event.key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
#include "pttlistener.h"
|
|
||||||
|
|
||||||
#include "qmlregister.h"
|
#include "qmlregister.h"
|
||||||
#include "appsettingsmanager.h"
|
#include "appsettingsmanager.h"
|
||||||
|
@ -131,12 +130,12 @@ MainApplication::init()
|
||||||
// This 2-phase initialisation prevents ephemeral instances from
|
// This 2-phase initialisation prevents ephemeral instances from
|
||||||
// performing unnecessary tasks, like initializing the webengine.
|
// performing unnecessary tasks, like initializing the webengine.
|
||||||
engine_.reset(new QQmlApplicationEngine(this));
|
engine_.reset(new QQmlApplicationEngine(this));
|
||||||
connectivityMonitor_.reset(new ConnectivityMonitor(this));
|
|
||||||
settingsManager_.reset(new AppSettingsManager(this));
|
|
||||||
systemTray_.reset(new SystemTray(settingsManager_.get(), this));
|
|
||||||
listener_ = new PTTListener(settingsManager_.get(), this);
|
|
||||||
|
|
||||||
QObject::connect(settingsManager_.get(),
|
connectivityMonitor_ = new ConnectivityMonitor(this);
|
||||||
|
settingsManager_ = new AppSettingsManager(this);
|
||||||
|
systemTray_ = new SystemTray(settingsManager_, this);
|
||||||
|
|
||||||
|
QObject::connect(settingsManager_,
|
||||||
&AppSettingsManager::retranslate,
|
&AppSettingsManager::retranslate,
|
||||||
engine_.get(),
|
engine_.get(),
|
||||||
&QQmlApplicationEngine::retranslate);
|
&QQmlApplicationEngine::retranslate);
|
||||||
|
@ -149,7 +148,7 @@ MainApplication::init()
|
||||||
setApplicationFont();
|
setApplicationFont();
|
||||||
|
|
||||||
initLrc(runOptions_[Option::UpdateUrl].toString(),
|
initLrc(runOptions_[Option::UpdateUrl].toString(),
|
||||||
connectivityMonitor_.get(),
|
connectivityMonitor_,
|
||||||
runOptions_[Option::Debug].toBool(),
|
runOptions_[Option::Debug].toBool(),
|
||||||
runOptions_[Option::MuteDaemon].toBool());
|
runOptions_[Option::MuteDaemon].toBool());
|
||||||
|
|
||||||
|
@ -171,7 +170,7 @@ MainApplication::init()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
connect(connectivityMonitor_.get(), &ConnectivityMonitor::connectivityChanged, this, [this] {
|
connect(connectivityMonitor_, &ConnectivityMonitor::connectivityChanged, this, [this] {
|
||||||
QTimer::singleShot(500, this, [&]() { lrcInstance_->connectivityChanged(); });
|
QTimer::singleShot(500, this, [&]() { lrcInstance_->connectivityChanged(); });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -350,16 +349,15 @@ MainApplication::initQmlLayer()
|
||||||
{
|
{
|
||||||
// Expose custom types to the QML engine.
|
// Expose custom types to the QML engine.
|
||||||
Utils::registerTypes(engine_.get(),
|
Utils::registerTypes(engine_.get(),
|
||||||
systemTray_.get(),
|
|
||||||
lrcInstance_.get(),
|
lrcInstance_.get(),
|
||||||
settingsManager_.get(),
|
systemTray_,
|
||||||
connectivityMonitor_.get(),
|
settingsManager_,
|
||||||
|
connectivityMonitor_,
|
||||||
&screenInfo_,
|
&screenInfo_,
|
||||||
this);
|
this);
|
||||||
|
|
||||||
auto videoProvider = new VideoProvider(lrcInstance_->avModel(), this);
|
auto videoProvider = new VideoProvider(lrcInstance_->avModel(), this);
|
||||||
engine_->rootContext()->setContextProperty("videoProvider", videoProvider);
|
engine_->rootContext()->setContextProperty("videoProvider", videoProvider);
|
||||||
engine_->rootContext()->setContextProperty("pttListener", listener_);
|
|
||||||
|
|
||||||
engine_->load(QUrl(QStringLiteral("qrc:/MainApplicationWindow.qml")));
|
engine_->load(QUrl(QStringLiteral("qrc:/MainApplicationWindow.qml")));
|
||||||
qWarning().noquote() << "Main window loaded using" << getRenderInterfaceString();
|
qWarning().noquote() << "Main window loaded using" << getRenderInterfaceString();
|
||||||
|
@ -385,7 +383,7 @@ MainApplication::initSystray()
|
||||||
QAction* restoreAction = new QAction(tr("&Show Jami"), this);
|
QAction* restoreAction = new QAction(tr("&Show Jami"), this);
|
||||||
connect(restoreAction, &QAction::triggered, this, &MainApplication::restoreApp);
|
connect(restoreAction, &QAction::triggered, this, &MainApplication::restoreApp);
|
||||||
|
|
||||||
connect(systemTray_.get(),
|
connect(systemTray_,
|
||||||
&QSystemTrayIcon::activated,
|
&QSystemTrayIcon::activated,
|
||||||
this,
|
this,
|
||||||
[this](QSystemTrayIcon::ActivationReason reason) {
|
[this](QSystemTrayIcon::ActivationReason reason) {
|
||||||
|
@ -424,4 +422,3 @@ MainApplication::setEventFilter()
|
||||||
{
|
{
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,10 +20,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "imagedownloader.h"
|
|
||||||
#include "lrcinstance.h"
|
#include "lrcinstance.h"
|
||||||
#include "qtutils.h"
|
#include "qtutils.h"
|
||||||
#include "pttlistener.h"
|
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
@ -37,7 +35,6 @@
|
||||||
class ConnectivityMonitor;
|
class ConnectivityMonitor;
|
||||||
class AppSettingsManager;
|
class AppSettingsManager;
|
||||||
class SystemTray;
|
class SystemTray;
|
||||||
class CallAdapter;
|
|
||||||
|
|
||||||
// Provides information about the screen the app is displayed on
|
// Provides information about the screen the app is displayed on
|
||||||
class ScreenInfo : public QObject
|
class ScreenInfo : public QObject
|
||||||
|
@ -116,15 +113,14 @@ private:
|
||||||
private:
|
private:
|
||||||
std::map<Option, QVariant> runOptions_;
|
std::map<Option, QVariant> runOptions_;
|
||||||
|
|
||||||
|
// We want to be explicit about the destruction order of these objects
|
||||||
QScopedPointer<QQmlApplicationEngine> engine_;
|
QScopedPointer<QQmlApplicationEngine> engine_;
|
||||||
QScopedPointer<LRCInstance> lrcInstance_;
|
QScopedPointer<LRCInstance> lrcInstance_;
|
||||||
|
|
||||||
QScopedPointer<ConnectivityMonitor> connectivityMonitor_;
|
// These are injected into the QML layer along with our LRCInstance
|
||||||
QScopedPointer<AppSettingsManager> settingsManager_;
|
ConnectivityMonitor* connectivityMonitor_;
|
||||||
QScopedPointer<SystemTray> systemTray_;
|
SystemTray* systemTray_;
|
||||||
QScopedPointer<ImageDownloader> imageDownloader_;
|
AppSettingsManager* settingsManager_;
|
||||||
|
|
||||||
PTTListener* listener_;
|
|
||||||
|
|
||||||
ScreenInfo screenInfo_;
|
ScreenInfo screenInfo_;
|
||||||
|
|
||||||
|
|
|
@ -80,13 +80,12 @@ public:
|
||||||
HHOOK keyboardHook;
|
HHOOK keyboardHook;
|
||||||
|
|
||||||
static quint32 qtKeyToVKey(Qt::Key key);
|
static quint32 qtKeyToVKey(Qt::Key key);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PTTListener::PTTListener(AppSettingsManager* settingsManager, QObject* parent)
|
PTTListener::PTTListener(AppSettingsManager* settingsManager, QObject* parent)
|
||||||
: settingsManager_(settingsManager)
|
: QObject(parent)
|
||||||
, QObject(parent)
|
|
||||||
, pimpl_(std::make_unique<Impl>(this))
|
, pimpl_(std::make_unique<Impl>(this))
|
||||||
|
, settingsManager_(settingsManager)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
PTTListener::~PTTListener() = default;
|
PTTListener::~PTTListener() = default;
|
||||||
|
@ -294,7 +293,7 @@ PTTListener::Impl::qtKeyToVKey(Qt::Key key)
|
||||||
return 'Z';
|
return 'Z';
|
||||||
|
|
||||||
default:
|
default:
|
||||||
//Try to get virtual key from current keyboard layout or US.
|
// Try to get virtual key from current keyboard layout or US.
|
||||||
const HKL layout = GetKeyboardLayout(0);
|
const HKL layout = GetKeyboardLayout(0);
|
||||||
int vk = VkKeyScanEx(key, layout);
|
int vk = VkKeyScanEx(key, layout);
|
||||||
if (vk == -1) {
|
if (vk == -1) {
|
||||||
|
@ -305,5 +304,4 @@ PTTListener::Impl::qtKeyToVKey(Qt::Key key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "pttlistener.moc"
|
||||||
#include "pttlistener.moc"
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "systemtray.h"
|
|
||||||
#include "appsettingsmanager.h"
|
#include "appsettingsmanager.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
@ -23,6 +22,7 @@ public:
|
||||||
{
|
{
|
||||||
return QKeySequence(key).toString();
|
return QKeySequence(key).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_INVOKABLE void setPttKey(Qt::Key key)
|
Q_INVOKABLE void setPttKey(Qt::Key key)
|
||||||
{
|
{
|
||||||
settingsManager_->setValue(Settings::Key::pttKey, key);
|
settingsManager_->setValue(Settings::Key::pttKey, key);
|
||||||
|
@ -48,5 +48,6 @@ public Q_SLOTS:
|
||||||
private:
|
private:
|
||||||
class Impl;
|
class Impl;
|
||||||
std::unique_ptr<Impl> pimpl_;
|
std::unique_ptr<Impl> pimpl_;
|
||||||
|
|
||||||
AppSettingsManager* settingsManager_;
|
AppSettingsManager* settingsManager_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,7 +34,7 @@ SettingsPageBase {
|
||||||
|
|
||||||
property bool isSIP: CurrentAccount.type === Profile.Type.SIP
|
property bool isSIP: CurrentAccount.type === Profile.Type.SIP
|
||||||
property int itemWidth: 132
|
property int itemWidth: 132
|
||||||
property string key: pttListener.keyToString(pttListener.getCurrentKey())
|
property string key: PttListener.keyToString(PttListener.getCurrentKey())
|
||||||
title: JamiStrings.callSettingsTitle
|
title: JamiStrings.callSettingsTitle
|
||||||
|
|
||||||
function updateAndShowModeratorsSlot() {
|
function updateAndShowModeratorsSlot() {
|
||||||
|
@ -437,7 +437,7 @@ SettingsPageBase {
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var dlg = viewCoordinator.presentDialog(appWindow, "commoncomponents/ChangePttKeyPopup.qml");
|
var dlg = viewCoordinator.presentDialog(appWindow, "commoncomponents/ChangePttKeyPopup.qml");
|
||||||
dlg.choiceMade.connect(function (chosenKey) {
|
dlg.choiceMade.connect(function (chosenKey) {
|
||||||
keyLabel.text = pttListener.keyToString(chosenKey);
|
keyLabel.text = PttListener.keyToString(chosenKey);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,6 @@ public:
|
||||||
explicit SystemTray(AppSettingsManager* settingsManager, QObject* parent = nullptr);
|
explicit SystemTray(AppSettingsManager* settingsManager, QObject* parent = nullptr);
|
||||||
~SystemTray();
|
~SystemTray();
|
||||||
|
|
||||||
AppSettingsManager* getSettingsManager()
|
|
||||||
{
|
|
||||||
return settingsManager_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void onNotificationCountChanged(int count);
|
void onNotificationCountChanged(int count);
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
bool hideNotification(const QString& id);
|
bool hideNotification(const QString& id);
|
||||||
|
|
Loading…
Add table
Reference in a new issue