Commit 6a6d3752 authored by Ronan Abhamon's avatar Ronan Abhamon

unstable

parent 69bb766e
...@@ -117,6 +117,7 @@ ...@@ -117,6 +117,7 @@
<file>ui/modules/Linphone/Contact/Avatar.qml</file> <file>ui/modules/Linphone/Contact/Avatar.qml</file>
<file>ui/modules/Linphone/Contact/ContactDescription.qml</file> <file>ui/modules/Linphone/Contact/ContactDescription.qml</file>
<file>ui/modules/Linphone/Contact/Contact.qml</file> <file>ui/modules/Linphone/Contact/Contact.qml</file>
<file>ui/modules/Linphone/Notifications/CallNotification.qml</file>
<file>ui/modules/Linphone/Presence/PresenceLevel.qml</file> <file>ui/modules/Linphone/Presence/PresenceLevel.qml</file>
<file>ui/modules/Linphone/Presence/PresenceString.qml</file> <file>ui/modules/Linphone/Presence/PresenceString.qml</file>
<file>ui/modules/Linphone/qmldir</file> <file>ui/modules/Linphone/qmldir</file>
......
#include <QDesktopWidget>
#include <QMenu> #include <QMenu>
#include <QQmlComponent> #include <QQmlComponent>
#include <QQmlContext> #include <QQmlContext>
...@@ -6,7 +7,6 @@ ...@@ -6,7 +7,6 @@
#include "../components/contacts/ContactsListProxyModel.hpp" #include "../components/contacts/ContactsListProxyModel.hpp"
#include "../components/linphone/LinphoneCore.hpp" #include "../components/linphone/LinphoneCore.hpp"
#include "../components/notification/Notification.hpp"
#include "../components/settings/AccountSettingsModel.hpp" #include "../components/settings/AccountSettingsModel.hpp"
#include "../components/timeline/TimelineModel.hpp" #include "../components/timeline/TimelineModel.hpp"
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
// =================================================================== // ===================================================================
App *App::m_instance = nullptr;
App::App (int &argc, char **argv) : QApplication(argc, argv) { App::App (int &argc, char **argv) : QApplication(argc, argv) {
// Try to use default locale. Otherwise use english. // Try to use default locale. Otherwise use english.
if (m_translator.load(QString(LANGUAGES_PATH) + QLocale::system().name()) || if (m_translator.load(QString(LANGUAGES_PATH) + QLocale::system().name()) ||
...@@ -36,7 +38,11 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) { ...@@ -36,7 +38,11 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) {
m_engine.addImportPath(":/ui/modules"); m_engine.addImportPath(":/ui/modules");
m_engine.addImportPath(":/ui/scripts"); m_engine.addImportPath(":/ui/scripts");
m_engine.addImportPath(":/ui/views"); m_engine.addImportPath(":/ui/views");
}
// -------------------------------------------------------------------
void App::initContentApp () {
// Register types and load context properties. // Register types and load context properties.
registerTypes(); registerTypes();
addContextProperties(); addContextProperties();
...@@ -51,9 +57,10 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) { ...@@ -51,9 +57,10 @@ App::App (int &argc, char **argv) : QApplication(argc, argv) {
qWarning("System tray not found on this system."); qWarning("System tray not found on this system.");
else else
setTrayIcon(); setTrayIcon();
}
// ------------------------------------------------------------------- // Set notification attr.
setNotificationAttributes();
}
void App::registerTypes () { void App::registerTypes () {
qmlRegisterUncreatableType<Presence>( qmlRegisterUncreatableType<Presence>(
...@@ -92,13 +99,16 @@ void App::addContextProperties () { ...@@ -92,13 +99,16 @@ void App::addContextProperties () {
// Other. // Other.
context->setContextProperty("LinphoneCore", LinphoneCore::getInstance()); context->setContextProperty("LinphoneCore", LinphoneCore::getInstance());
context->setContextProperty("Notification", new Notification());
m_notification = new Notification();
context->setContextProperty("Notification", m_notification);
} }
void App::setTrayIcon () { void App::setTrayIcon () {
QQuickWindow *root = qobject_cast<QQuickWindow *>(m_engine.rootObjects().at(0)); QQuickWindow *root = qobject_cast<QQuickWindow *>(m_engine.rootObjects().at(0));
QMenu *menu = new QMenu(); QMenu *menu = new QMenu();
m_tray_icon = new QSystemTrayIcon(root);
m_system_tray_icon = new QSystemTrayIcon(root);
// trayIcon: Right click actions. // trayIcon: Right click actions.
QAction *quit_action = new QAction("Quit", root); QAction *quit_action = new QAction("Quit", root);
...@@ -108,7 +118,7 @@ void App::setTrayIcon () { ...@@ -108,7 +118,7 @@ void App::setTrayIcon () {
root->connect(restore_action, &QAction::triggered, root, &QQuickWindow::showNormal); root->connect(restore_action, &QAction::triggered, root, &QQuickWindow::showNormal);
// trayIcon: Left click actions. // trayIcon: Left click actions.
root->connect(m_tray_icon, &QSystemTrayIcon::activated, [root](QSystemTrayIcon::ActivationReason reason) { root->connect(m_system_tray_icon, &QSystemTrayIcon::activated, [root](QSystemTrayIcon::ActivationReason reason) {
if (reason == QSystemTrayIcon::Trigger) { if (reason == QSystemTrayIcon::Trigger) {
if (root->visibility() == QWindow::Hidden) if (root->visibility() == QWindow::Hidden)
root->showNormal(); root->showNormal();
...@@ -122,8 +132,32 @@ void App::setTrayIcon () { ...@@ -122,8 +132,32 @@ void App::setTrayIcon () {
menu->addSeparator(); menu->addSeparator();
menu->addAction(quit_action); menu->addAction(quit_action);
m_tray_icon->setContextMenu(menu); m_system_tray_icon->setContextMenu(menu);
m_tray_icon->setIcon(QIcon(WINDOW_ICON_PATH)); m_system_tray_icon->setIcon(QIcon(WINDOW_ICON_PATH));
m_tray_icon->setToolTip("Linphone"); m_system_tray_icon->setToolTip("Linphone");
m_tray_icon->show(); m_system_tray_icon->show();
}
void App::setNotificationAttributes () {
QDesktopWidget *desktop = QApplication::desktop();
// The primary screen is the default given by Qt or the screen of
// system tray icon.
int primary_screen = desktop->primaryScreen();
if (m_system_tray_icon) {
// primary_screen = QDesktopWidget::screenNumber(m_system_tray_icon);
QRect icon_rect = m_system_tray_icon->geometry();
QRect screen_rect = desktop->screenGeometry(primary_screen);
int x = icon_rect.x() + icon_rect.width() / 2;
int y = icon_rect.y() + icon_rect.height() / 2;
Qt::Edges edge = (x < screen_rect.width() / 2) ? Qt::LeftEdge : Qt::RightEdge;
edge |= (y < screen_rect.height() / 2) ? Qt::TopEdge : Qt::BottomEdge;
m_notification->setEdge(edge);
}
m_notification->setScreenNumber(primary_screen);
} }
...@@ -7,22 +7,46 @@ ...@@ -7,22 +7,46 @@
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QTranslator> #include <QTranslator>
#include "../components/notification/Notification.hpp"
// =================================================================== // ===================================================================
class App : public QApplication { class App : public QApplication {
public: public:
App (int &argc, char **argv); static void init (int &argc, char **argv) {
virtual ~App () {} if (!m_instance) {
m_instance = new App(argc, argv);
m_instance->initContentApp();
}
}
static App *getInstance () {
return m_instance;
}
QQmlEngine *getEngine () {
return &m_engine;
}
private: private:
App (int &argc, char **argv);
void initContentApp ();
void registerTypes (); void registerTypes ();
void addContextProperties (); void addContextProperties ();
void setTrayIcon (); void setTrayIcon ();
void setNotificationAttributes ();
QQmlApplicationEngine m_engine; QQmlApplicationEngine m_engine;
QQmlFileSelector *m_file_selector; QQmlFileSelector *m_file_selector = nullptr;
QSystemTrayIcon *m_tray_icon; QSystemTrayIcon *m_system_tray_icon = nullptr;
QTranslator m_translator; QTranslator m_translator;
Notification *m_notification = nullptr;
static App *m_instance;
}; };
#endif // APP_H_ #endif // APP_H_
#include <QDesktopWidget>
#include <QTimer>
#include <QtDebug> #include <QtDebug>
#include "../../app/App.hpp"
#include "Notification.hpp" #include "Notification.hpp"
#define NOTIFICATION_X_PROPERTY "popupX"
#define NOTIFICATION_Y_PROPERTY "popupY"
#define NOTIFICATION_HEIGHT_PROPERTY "popupHeight"
#define NOTIFICATION_WIDTH_PROPERTY "popupWidth"
#define NOTIFICATION_SHOW_METHOD_NAME "show"
#define N_MAX_NOTIFICATIONS 3
// =================================================================== // ===================================================================
Notification::Notification (QObject *parent) : Notification::Notification (QObject *parent) :
QObject(parent) { QObject(parent) {
QQmlEngine *engine = App::getInstance()->getEngine();
// Build components.
m_components[Notification::Call] = new QQmlComponent(
engine, QUrl("qrc:/ui/modules/Linphone/Notifications/CallNotification.qml")
);
// Check errors.
for (int i = 0; i < Notification::MaxNbTypes; i++) {
QQmlComponent &component = *m_components[i];
if (component.isError()) {
qWarning() << "Errors found in `Notification` component "
<< i << ":" << component.errors();
abort();
}
}
}
Notification::~Notification () {
for (int i = 0; i < Notification::MaxNbTypes; i++)
delete m_components[i];
} }
void Notification::showMessage ( // -------------------------------------------------------------------
const QString &summary,
const QString &body, inline int getNotificationSize (const QObject &object, const char *size_property) {
const QString &icon, QVariant variant = object.property(size_property);
int timeout bool so_far_so_good;
int size = variant.toInt(&so_far_so_good);
if (!so_far_so_good || size < 0) {
qWarning() << "Unable to get notification size.";
return -1;
}
return size;
}
inline bool setNotificationPosition (
QObject &object, const char *position_property, int value
) { ) {
qDebug() << QVariant position(value);
"Notification.showMessage(" << summary << ", " <<
body << ", " << icon << ", " << timeout << ")"; if (!object.setProperty(position_property, position)) {
qWarning() << "Unable to set notification position.";
return false;
}
return true;
}
void Notification::showCallMessage (
int timeout,
const QString &sip_address
) {
qDebug() << "Show call notification message. (addr=" <<
sip_address << ")";
QObject *object = m_components[Notification::Call]->create();
int width, height;
if (
(width = getNotificationSize(*object, NOTIFICATION_WIDTH_PROPERTY)) == -1 ||
(height = getNotificationSize(*object, NOTIFICATION_HEIGHT_PROPERTY)) == -1
) {
delete object;
return;
}
QRect screen_rect = QApplication::desktop()->screenGeometry(m_screen_number);
int x = (m_edge & Qt::LeftEdge) ? 5 : screen_rect.width() - 5 - width;
int y = (m_edge & Qt::TopEdge) ? 5 : screen_rect.height() - 5 - height;
if (
!setNotificationPosition(*object, NOTIFICATION_X_PROPERTY, x) ||
!setNotificationPosition(*object, NOTIFICATION_Y_PROPERTY, y)
) {
delete object;
return;
}
QMetaObject::invokeMethod(object, "show", Qt::DirectConnection);
QTimer::singleShot(timeout, object, [object]() {
delete object;
});
} }
#ifndef NOTIFICATION_H_ #ifndef NOTIFICATION_H_
#define NOTIFICATION_H_ #define NOTIFICATION_H_
#include <QMutex>
#include <QObject> #include <QObject>
#include <QQmlComponent>
// =================================================================== // ===================================================================
...@@ -10,14 +12,33 @@ class Notification : public QObject { ...@@ -10,14 +12,33 @@ class Notification : public QObject {
public: public:
Notification (QObject *parent = Q_NULLPTR); Notification (QObject *parent = Q_NULLPTR);
virtual ~Notification ();
enum Type {
Call,
MaxNbTypes
};
Q_ENUM(Type);
void setEdge (Qt::Edges edge) {
m_edge = edge;
}
void setScreenNumber (int screen_number) {
m_screen_number = screen_number;
}
public slots: public slots:
void showMessage ( void showCallMessage (int timeout, const QString &sip_address);
const QString &summary,
const QString &body, private:
const QString &icon = "", Qt::Edges m_edge = Qt::RightEdge | Qt::TopEdge;
int timeout = 10000 QQmlComponent *m_components[MaxNbTypes];
);
int m_screen_number = 0;
int m_n_instances = 0;
QMutex m_mutex;
}; };
#endif // NOTIFICATION_H_ #endif // NOTIFICATION_H_
...@@ -7,8 +7,8 @@ int main (int argc, char *argv[]) { ...@@ -7,8 +7,8 @@ int main (int argc, char *argv[]) {
qInstallMessageHandler(qmlLogger); qInstallMessageHandler(qmlLogger);
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
App app(argc, argv); App::init(argc, argv);
// Run! // Run!
return app.exec(); return App::getInstance()->exec();
} }
...@@ -11,6 +11,9 @@ Item { ...@@ -11,6 +11,9 @@ Item {
property alias popupX: popup.x property alias popupX: popup.x
property alias popupY: popup.y property alias popupY: popup.y
readonly property alias popupWidth: popup.width
readonly property alias popupHeight: popup.height
default property alias _content: content.data default property alias _content: content.data
property bool _isOpen: false property bool _isOpen: false
......
import QtQuick 2.7
import Common 1.0
DesktopPopup {
Rectangle {
color: 'red'
width: 200
height: 100
}
}
...@@ -20,6 +20,9 @@ Avatar 1.0 Contact/Avatar.qml ...@@ -20,6 +20,9 @@ Avatar 1.0 Contact/Avatar.qml
Contact 1.0 Contact/Contact.qml Contact 1.0 Contact/Contact.qml
ContactDescription 1.0 Contact/ContactDescription.qml ContactDescription 1.0 Contact/ContactDescription.qml
# Notifications
CallNotification 1.0 Notifications/CallNotification.qml
# Presence # Presence
PresenceLevel 1.0 Presence/PresenceLevel.qml PresenceLevel 1.0 Presence/PresenceLevel.qml
PresenceString 1.0 Presence/PresenceString.qml PresenceString 1.0 Presence/PresenceString.qml
......
...@@ -36,7 +36,7 @@ ColumnLayout { ...@@ -36,7 +36,7 @@ ColumnLayout {
}) })
} }
spacing: 0 spacing: Notification.showCallMessage(10000, "toto@toto.com") || 0
// ----------------------------------------------------------------- // -----------------------------------------------------------------
// Search Bar & actions. // Search Bar & actions.
......
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