From c1e85765281010f1ce9fa7b475f7f42dac677edf Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Mon, 5 Jun 2017 15:53:58 +0200 Subject: [PATCH] Handle version update check. --- cmake_builder/linphoneqt.cmake | 1 + linphone-desktop/CMakeLists.txt | 2 + linphone-desktop/assets/languages/en.ts | 7 ++ linphone-desktop/assets/languages/fr.ts | 7 ++ linphone-desktop/assets/linphonerc-factory | 3 + linphone-desktop/config.h.cmake | 1 + linphone-desktop/resources.qrc | 2 + linphone-desktop/src/app/App.cpp | 4 ++ linphone-desktop/src/app/App.hpp | 1 + .../src/components/core/CoreHandlers.cpp | 25 +++++++ .../src/components/core/CoreHandlers.hpp | 7 ++ .../src/components/notifier/Notifier.cpp | 16 +++++ .../src/components/notifier/Notifier.hpp | 2 + .../NotificationNewVersionAvailable.qml | 68 +++++++++++++++++++ .../NotificationNewVersionAvailableStyle.qml | 22 ++++++ .../ui/modules/Linphone/Styles/qmldir | 1 + 16 files changed, 169 insertions(+) create mode 100644 linphone-desktop/ui/modules/Linphone/Notifications/NotificationNewVersionAvailable.qml create mode 100644 linphone-desktop/ui/modules/Linphone/Styles/Notifications/NotificationNewVersionAvailableStyle.qml diff --git a/cmake_builder/linphoneqt.cmake b/cmake_builder/linphoneqt.cmake index 03e58ecff..494fef8fa 100644 --- a/cmake_builder/linphoneqt.cmake +++ b/cmake_builder/linphoneqt.cmake @@ -24,6 +24,7 @@ lcb_external_source_paths("../linphone-desktop") lcb_dependencies("linphone" "ms2plugins") lcb_groupable(YES) +lcb_cmake_options("-DENABLE_UPDATE_CHECK=${ENABLE_UPDATE_CHECK}") # Add config step for packaging set(LINPHONE_BUILDER_ADDITIONAL_CONFIG_STEPS "${CMAKE_CURRENT_LIST_DIR}/additional_steps.cmake") diff --git a/linphone-desktop/CMakeLists.txt b/linphone-desktop/CMakeLists.txt index 06c546a38..84d2f7a68 100644 --- a/linphone-desktop/CMakeLists.txt +++ b/linphone-desktop/CMakeLists.txt @@ -29,6 +29,8 @@ set(CMAKE_CXX_STANDARD 11) set(ASSETS_DIR assets) +option(ENABLE_UPDATE_CHECK "Enable update check." NO) + include(GNUInstallDirs) include(CheckCXXCompilerFlag) diff --git a/linphone-desktop/assets/languages/en.ts b/linphone-desktop/assets/languages/en.ts index 262fa28de..04e1bd3c7 100644 --- a/linphone-desktop/assets/languages/en.ts +++ b/linphone-desktop/assets/languages/en.ts @@ -887,6 +887,13 @@ your friend's SIP address or username. Play me! + + Notifier + + newVersionAvailable + A new version (%1) of Linphone is available! + + OutgoingMessage diff --git a/linphone-desktop/assets/languages/fr.ts b/linphone-desktop/assets/languages/fr.ts index d35c945b1..23302e84c 100644 --- a/linphone-desktop/assets/languages/fr.ts +++ b/linphone-desktop/assets/languages/fr.ts @@ -886,6 +886,13 @@ un chat ou ajouter un contact. Joue-moi ! + + Notifier + + newVersionAvailable + Une nouvelle version (%1) de Linphone est disponible ! + + OutgoingMessage diff --git a/linphone-desktop/assets/linphonerc-factory b/linphone-desktop/assets/linphonerc-factory index ac033cabd..c2570967f 100644 --- a/linphone-desktop/assets/linphonerc-factory +++ b/linphone-desktop/assets/linphonerc-factory @@ -1,2 +1,5 @@ +[misc] +version_check_url_root=https://linphone.org/releases + [sound] ec_filter=MSWebRTCAEC diff --git a/linphone-desktop/config.h.cmake b/linphone-desktop/config.h.cmake index 3b0e61f61..79a64cd00 100644 --- a/linphone-desktop/config.h.cmake +++ b/linphone-desktop/config.h.cmake @@ -21,3 +21,4 @@ *******************************************************************************/ #cmakedefine MSPLUGINS_DIR "${MSPLUGINS_DIR}" +#cmakedefine ENABLE_UPDATE_CHECK 1 \ No newline at end of file diff --git a/linphone-desktop/resources.qrc b/linphone-desktop/resources.qrc index 42fc588de..58576aa09 100644 --- a/linphone-desktop/resources.qrc +++ b/linphone-desktop/resources.qrc @@ -324,6 +324,7 @@ ui/modules/Linphone/Contact/MessagesCounter.qml ui/modules/Linphone/Menus/SipAddressesMenu.qml ui/modules/Linphone/Notifications/Notification.qml + ui/modules/Linphone/Notifications/NotificationNewVersionAvailable.qml ui/modules/Linphone/Notifications/NotificationReceivedCall.qml ui/modules/Linphone/Notifications/NotificationReceivedFileMessage.qml ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml @@ -344,6 +345,7 @@ ui/modules/Linphone/Styles/Contact/ContactStyle.qml ui/modules/Linphone/Styles/Contact/MessagesCounterStyle.qml ui/modules/Linphone/Styles/Menus/SipAddressesMenuStyle.qml + ui/modules/Linphone/Styles/Notifications/NotificationNewVersionAvailableStyle.qml ui/modules/Linphone/Styles/Notifications/NotificationReceivedCallStyle.qml ui/modules/Linphone/Styles/Notifications/NotificationReceivedFileMessageStyle.qml ui/modules/Linphone/Styles/Notifications/NotificationReceivedMessageStyle.qml diff --git a/linphone-desktop/src/app/App.cpp b/linphone-desktop/src/app/App.cpp index c76a9c4a4..88bca1ec4 100644 --- a/linphone-desktop/src/app/App.cpp +++ b/linphone-desktop/src/app/App.cpp @@ -293,6 +293,10 @@ void App::smartShowWindow (QQuickWindow *window) { window->requestActivate(); } +void App::checkForUpdate () { + CoreManager::getInstance()->getCore()->checkForUpdate(LINPHONE_QT_GIT_VERSION); +} + QString App::convertUrlToLocalPath (const QUrl &url) { return QDir::toNativeSeparators(url.toLocalFile()); } diff --git a/linphone-desktop/src/app/App.hpp b/linphone-desktop/src/app/App.hpp index f712e6faf..4b60e8451 100644 --- a/linphone-desktop/src/app/App.hpp +++ b/linphone-desktop/src/app/App.hpp @@ -77,6 +77,7 @@ public: Q_INVOKABLE QQuickWindow *getSettingsWindow (); Q_INVOKABLE static void smartShowWindow (QQuickWindow *window); + Q_INVOKABLE static void checkForUpdate (); Q_INVOKABLE static QString convertUrlToLocalPath (const QUrl &url); public slots: diff --git a/linphone-desktop/src/components/core/CoreHandlers.cpp b/linphone-desktop/src/components/core/CoreHandlers.cpp index 9b32cc72c..ec909c3fe 100644 --- a/linphone-desktop/src/components/core/CoreHandlers.cpp +++ b/linphone-desktop/src/components/core/CoreHandlers.cpp @@ -31,6 +31,11 @@ #include "CoreHandlers.hpp" +#include "config.h" + +#define VERSION_UPDATE_CHECK_OBJECT_NAME "version-update-check-timer" +#define VERSION_UPDATE_CHECK_INTERVAL 86400000 /* 24 hours in milliseconds */ + using namespace std; // ============================================================================= @@ -83,6 +88,15 @@ void CoreHandlers::notifyCoreStarted () { [this]() { qInfo() << QStringLiteral("Core started."); emit coreStarted(); + +#ifdef ENABLE_UPDATE_CHECK + QTimer *timer = new QTimer(this); + timer->setInterval(VERSION_UPDATE_CHECK_INTERVAL); + timer->setObjectName(VERSION_UPDATE_CHECK_OBJECT_NAME); + QObject::connect(timer, &QTimer::timeout, this, &App::checkForUpdate); + timer->start(); + App::checkForUpdate(); +#endif } ); } @@ -217,3 +231,14 @@ void CoreHandlers::onTransferStateChanged ( break; } } + +void CoreHandlers::onVersionUpdateCheckResultReceived ( + const shared_ptr &, + linphone::VersionUpdateCheckResult result, + const string &version, + const string &url +) { + if (result == linphone::VersionUpdateCheckResultNewVersionAvailable) { + App::getInstance()->getNotifier()->notifyNewVersionAvailable(version, url); + } +} \ No newline at end of file diff --git a/linphone-desktop/src/components/core/CoreHandlers.hpp b/linphone-desktop/src/components/core/CoreHandlers.hpp index 740ea8263..bb31c6399 100644 --- a/linphone-desktop/src/components/core/CoreHandlers.hpp +++ b/linphone-desktop/src/components/core/CoreHandlers.hpp @@ -115,6 +115,13 @@ private: linphone::CallState state ) override; + void onVersionUpdateCheckResultReceived ( + const std::shared_ptr &, + linphone::VersionUpdateCheckResult result, + const std::string &version, + const std::string &url + ) override; + // --------------------------------------------------------------------------- bool mCoreCreated = false; diff --git a/linphone-desktop/src/components/notifier/Notifier.cpp b/linphone-desktop/src/components/notifier/Notifier.cpp index a8a9786c8..a298ea4df 100644 --- a/linphone-desktop/src/components/notifier/Notifier.cpp +++ b/linphone-desktop/src/components/notifier/Notifier.cpp @@ -54,6 +54,7 @@ #define QML_NOTIFICATION_PATH_RECEIVED_MESSAGE "qrc:/ui/modules/Linphone/Notifications/NotificationReceivedMessage.qml" #define QML_NOTIFICATION_PATH_RECEIVED_FILE_MESSAGE "qrc:/ui/modules/Linphone/Notifications/NotificationReceivedFileMessage.qml" #define QML_NOTIFICATION_PATH_RECEIVED_CALL "qrc:/ui/modules/Linphone/Notifications/NotificationReceivedCall.qml" +#define QML_NOTIFICATION_PATH_NEW_VERSION_AVAILABLE "qrc:/ui/modules/Linphone/Notifications/NotificationNewVersionAvailable.qml" // ----------------------------------------------------------------------------- // Timeouts. @@ -62,6 +63,7 @@ #define NOTIFICATION_TIMEOUT_RECEIVED_MESSAGE 10000 #define NOTIFICATION_TIMEOUT_RECEIVED_FILE_MESSAGE 10000 #define NOTIFICATION_TIMEOUT_RECEIVED_CALL 30000 +#define NOTIFICATION_TIMEOUT_NEW_VERSION_AVAILABLE 30000 // ----------------------------------------------------------------------------- // Arbitrary hardcoded values. @@ -106,6 +108,7 @@ Notifier::Notifier (QObject *parent) : mComponents[Notifier::MessageReceived] = new QQmlComponent(engine, QUrl(QML_NOTIFICATION_PATH_RECEIVED_MESSAGE)); mComponents[Notifier::FileMessageReceived] = new QQmlComponent(engine, QUrl(QML_NOTIFICATION_PATH_RECEIVED_FILE_MESSAGE)); mComponents[Notifier::CallReceived] = new QQmlComponent(engine, QUrl(QML_NOTIFICATION_PATH_RECEIVED_CALL)); + mComponents[Notifier::NewVersionAvailable] = new QQmlComponent(engine, QUrl(QML_NOTIFICATION_PATH_NEW_VERSION_AVAILABLE)); // Check errors. for (int i = 0; i < Notifier::MaxNbTypes; ++i) { @@ -271,3 +274,16 @@ void Notifier::notifyReceivedCall (const shared_ptr &call) { ::setProperty(*notification, NOTIFICATION_PROPERTY_DATA, map); showNotification(notification, NOTIFICATION_TIMEOUT_RECEIVED_CALL); } + +void Notifier::notifyNewVersionAvailable (const std::string &version, const std::string &url) { + QObject *notification = createNotification(Notifier::NewVersionAvailable); + if (!notification) + return; + + QVariantMap map; + map["message"] = tr("newVersionAvailable").arg(::Utils::coreStringToAppString(version)); + map["url"] = ::Utils::coreStringToAppString(url); + + ::setProperty(*notification, NOTIFICATION_PROPERTY_DATA, map); + showNotification(notification, NOTIFICATION_TIMEOUT_NEW_VERSION_AVAILABLE); +} \ No newline at end of file diff --git a/linphone-desktop/src/components/notifier/Notifier.hpp b/linphone-desktop/src/components/notifier/Notifier.hpp index 6d38d2bcd..5b2134d9c 100644 --- a/linphone-desktop/src/components/notifier/Notifier.hpp +++ b/linphone-desktop/src/components/notifier/Notifier.hpp @@ -42,12 +42,14 @@ public: MessageReceived, FileMessageReceived, CallReceived, + NewVersionAvailable, MaxNbTypes }; void notifyReceivedMessage (const std::shared_ptr &message); void notifyReceivedFileMessage (const std::shared_ptr &message); void notifyReceivedCall (const std::shared_ptr &call); + void notifyNewVersionAvailable (const std::string &version, const std::string &url); public slots: void deleteNotification (QVariant notification); diff --git a/linphone-desktop/ui/modules/Linphone/Notifications/NotificationNewVersionAvailable.qml b/linphone-desktop/ui/modules/Linphone/Notifications/NotificationNewVersionAvailable.qml new file mode 100644 index 000000000..2370ed18b --- /dev/null +++ b/linphone-desktop/ui/modules/Linphone/Notifications/NotificationNewVersionAvailable.qml @@ -0,0 +1,68 @@ +import QtQuick 2.7 +import QtQuick.Layouts 1.3 + +import Common 1.0 +import Linphone 1.0 +import Linphone.Styles 1.0 +import Utils 1.0 + +// ============================================================================= + +Notification { + id: notification + + // --------------------------------------------------------------------------- + + Rectangle { + color: NotificationNewVersionAvailableStyle.color + height: NotificationNewVersionAvailableStyle.height + width: NotificationNewVersionAvailableStyle.width + + Icon { + anchors { + left: parent.left + top: parent.top + } + + icon: 'file_sign' + iconSize: NotificationNewVersionAvailableStyle.iconSize + } + + Loader { + active: notificationData.url.length > 0 + anchors { + fill: parent + + leftMargin: NotificationNewVersionAvailableStyle.leftMargin + rightMargin: NotificationNewVersionAvailableStyle.rightMargin + } + + sourceComponent: RowLayout { + anchors.fill: parent + spacing: NotificationNewVersionAvailableStyle.spacing + + Text { + Layout.fillWidth: true + Layout.fillHeight: true + + topPadding: NotificationNewVersionAvailableStyle.message.topPadding + color: NotificationNewVersionAvailableStyle.message.color + elide: Text.ElideRight + wrapMode: Text.Wrap + font.pointSize: NotificationNewVersionAvailableStyle.message.fontSize + text: notificationData.message + } + } + + MouseArea { + anchors.fill: parent + cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor + hoverEnabled: true + + onClicked: notification._close(function () { + Qt.openUrlExternally(notificationData.url) + }) + } + } + } +} diff --git a/linphone-desktop/ui/modules/Linphone/Styles/Notifications/NotificationNewVersionAvailableStyle.qml b/linphone-desktop/ui/modules/Linphone/Styles/Notifications/NotificationNewVersionAvailableStyle.qml new file mode 100644 index 000000000..47634e5ee --- /dev/null +++ b/linphone-desktop/ui/modules/Linphone/Styles/Notifications/NotificationNewVersionAvailableStyle.qml @@ -0,0 +1,22 @@ +pragma Singleton +import QtQuick 2.7 + +import Common 1.0 + +// ============================================================================= + +QtObject { + property color color: Colors.k + property int height: 55 + property int iconSize: 40 + property int leftMargin: 25 + property int rightMargin: 15 + property int spacing: 10 + property int width: 300 + + property QtObject message: QtObject { + property color color: Colors.h + property int fontSize: 10 + property real topPadding: 10 + } +} diff --git a/linphone-desktop/ui/modules/Linphone/Styles/qmldir b/linphone-desktop/ui/modules/Linphone/Styles/qmldir index 2c9172222..0c5a7ec68 100644 --- a/linphone-desktop/ui/modules/Linphone/Styles/qmldir +++ b/linphone-desktop/ui/modules/Linphone/Styles/qmldir @@ -25,6 +25,7 @@ singleton MessagesCounterStyle 1.0 Contact/MessagesCounterStyle. singleton SipAddressesMenuStyle 1.0 Menus/SipAddressesMenuStyle.qml +singleton NotificationNewVersionAvailableStyle 1.0 Notifications/NotificationNewVersionAvailableStyle.qml singleton NotificationReceivedCallStyle 1.0 Notifications/NotificationReceivedCallStyle.qml singleton NotificationReceivedMessageStyle 1.0 Notifications/NotificationReceivedMessageStyle.qml singleton NotificationReceivedFileMessageStyle 1.0 Notifications/NotificationReceivedFileMessageStyle.qml