'[ui] notification_origin' : option to specify where to display notifications (only supported top-right=1 and bottom-right=0)

This commit is contained in:
Julien Wadel 2024-03-12 09:08:51 +01:00
parent c4f3dba832
commit 1d258362db
4 changed files with 40 additions and 7 deletions

View file

@ -120,6 +120,10 @@ Notifier::~Notifier () {
delete[] mComponents;
}
int Notifier::getNotificationOrigin() {
return CoreManager::getInstance()->getSettingsModel()->getNotificationOrigin();
}
// -----------------------------------------------------------------------------
QObject *Notifier::createNotification (Notifier::NotificationType type, QVariantMap data) {
@ -167,15 +171,24 @@ QObject *Notifier::createNotification (Notifier::NotificationType type, QVariant
int * screenHeightOffset = &mScreenHeightOffset[screen->name()]; // Access optimization
QRect availableGeometry = screen->availableGeometry();
int heightOffset = availableGeometry.y() + (availableGeometry.height() - subWindow->height());//*screen->devicePixelRatio(); when using manual scaler
int heightOffset = availableGeometry.y() + (((getNotificationOrigin() & Top) != Top )
? (availableGeometry.height() - subWindow->height())//*screen->devicePixelRatio(); when using manual scaler
: 0);
if(showAsTool)
subWindow->setProperty("showAsTool",true);
subWindow->setX(availableGeometry.x()+ (availableGeometry.width()-subWindow->property("width").toInt()));//*screen->devicePixelRatio()); when using manual scaler
subWindow->setY(heightOffset-(*screenHeightOffset % heightOffset));
int newScreenHeightOffset = (subWindow->height() + *screenHeightOffset) + NotificationSpacing;
if(((getNotificationOrigin() & Top) == Top )){
subWindow->setY(heightOffset+(*screenHeightOffset));
if (newScreenHeightOffset + heightOffset > availableGeometry.height())
newScreenHeightOffset = 0;
}else{
subWindow->setY(heightOffset-(*screenHeightOffset % heightOffset));
if (newScreenHeightOffset - heightOffset + availableGeometry.y() >= 0)
newScreenHeightOffset = 0;
}
*screenHeightOffset = newScreenHeightOffset;
*screenHeightOffset = (subWindow->height() + *screenHeightOffset) + NotificationSpacing;
if (*screenHeightOffset - heightOffset + availableGeometry.y() >= 0)
*screenHeightOffset = 0;
// if(primaryScreen != screen){ //Useful when doing manual scaling jobs. Need to implement scaler in GUI objects
// //subwindow->setProperty("xScale", (double)screen->availableVirtualGeometry().width()/availableGeometry.width() );

View file

@ -54,6 +54,12 @@ public:
RecordingCompleted
};
enum NotificationOrigin{
BottomRight = 0,
Top = 1,
Left = 2
};
void notifyReceivedMessages (const std::list<std::shared_ptr<linphone::ChatMessage>> &messages);
void notifyReceivedReactions(const QList<QPair<std::shared_ptr<linphone::ChatMessage>, std::shared_ptr<const linphone::ChatMessageReaction>>> &reactions);
void notifyReceivedFileMessage (const std::shared_ptr<linphone::ChatMessage> &message, const std::shared_ptr<linphone::Content> &content);
@ -62,6 +68,8 @@ public:
void notifySnapshotWasTaken (const QString &filePath);
void notifyRecordingCompleted (const QString &filePath);
static int getNotificationOrigin();
public slots:
void deleteNotificationOnTimeout(QVariant notification);
void deleteNotification (QVariant notification);

View file

@ -36,6 +36,7 @@
#include "SettingsModel.hpp"
#include "components/assistant/AssistantModel.hpp"
#include "components/core/CoreManager.hpp"
#include "components/notifier/Notifier.hpp"
#include "components/tunnel/TunnelModel.hpp"
#include "include/LinphoneApp/PluginNetworkHelper.hpp"
#include "utils/Constants.hpp"
@ -553,7 +554,7 @@ void SettingsModel::startEchoCancellerCalibration() {
CoreManager::getInstance()->getCore()->startEchoCancellerCalibration();
}
int SettingsModel::getEchoCancellationCalibration()const {
int SettingsModel::getEchoCancellationCalibration() const {
return CoreManager::getInstance()->getCore()->getEchoCancellationCalibration();
}
// -----------------------------------------------------------------------------
@ -1043,7 +1044,6 @@ void SettingsModel::setChatNotificationSoundEnabled(bool status) {
mConfig->setInt(UiSection, "chat_sound_notification_enabled", status);
emit chatNotificationSoundEnabledChanged(status);
}
// -----------------------------------------------------------------------------
QString SettingsModel::getChatNotificationSoundPath() const {
@ -1057,6 +1057,16 @@ void SettingsModel::setChatNotificationSoundPath(const QString &path) {
emit chatNotificationSoundPathChanged(cleanedPath);
}
int SettingsModel::getNotificationOrigin() const {
return mConfig->getInt(UiSection, "notification_origin",
#ifdef __APPLE__
Notifier::NotificationOrigin::Top
#else
Notifier::NotificationOrigin::BottomRight
#endif
);
}
// -----------------------------------------------------------------------------
QString SettingsModel::getFileTransferUrl() const {

View file

@ -531,6 +531,8 @@ public:
QString getChatNotificationSoundPath() const;
void setChatNotificationSoundPath(const QString &path);
int getNotificationOrigin() const;
QString getFileTransferUrl() const;
void setFileTransferUrl(const QString &url);