From c65963cfb2b195173570fd7ee84a72ec17e2c496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Sat, 5 Sep 2015 22:51:28 +0200 Subject: [PATCH 01/15] tray-icon: Add Ricochet icon with dot --- icons/icons.qrc | 1 + icons/ricochet_unread.svg | 1341 +++++++++++++++++++++++++++++++++++++ 2 files changed, 1342 insertions(+) create mode 100644 icons/ricochet_unread.svg diff --git a/icons/icons.qrc b/icons/icons.qrc index b0548c12..41ea64a2 100644 --- a/icons/icons.qrc +++ b/icons/icons.qrc @@ -2,5 +2,6 @@ ricochet.svg ricochet_icons.ttf + ricochet_unread.svg diff --git a/icons/ricochet_unread.svg b/icons/ricochet_unread.svg new file mode 100644 index 00000000..c50db122 --- /dev/null +++ b/icons/ricochet_unread.svg @@ -0,0 +1,1341 @@ + + + +image/svg+xml \ No newline at end of file From 2c710ce63de1793820b8dae9cb92dec87ba68075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Fri, 21 Aug 2015 20:28:17 +0200 Subject: [PATCH 02/15] tray-icon: Implementation of TrayIcon class --- ricochet.pro | 6 ++-- src/ui/TrayIcon.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++ src/ui/TrayIcon.h | 65 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 src/ui/TrayIcon.cpp create mode 100644 src/ui/TrayIcon.h diff --git a/ricochet.pro b/ricochet.pro index c9004142..0e72e138 100644 --- a/ricochet.pro +++ b/ricochet.pro @@ -163,7 +163,8 @@ SOURCES += src/main.cpp \ src/ui/LinkedText.cpp \ src/utils/Settings.cpp \ src/utils/PendingOperation.cpp \ - src/ui/LanguagesModel.cpp + src/ui/LanguagesModel.cpp \ + src/ui/TrayIcon.cpp HEADERS += src/ui/MainWindow.h \ src/ui/ContactsModel.h \ @@ -193,7 +194,8 @@ HEADERS += src/ui/MainWindow.h \ src/ui/LinkedText.h \ src/utils/Settings.h \ src/utils/PendingOperation.h \ - src/ui/LanguagesModel.h + src/ui/LanguagesModel.h \ + src/ui/TrayIcon.h SOURCES += src/protocol/Channel.cpp \ src/protocol/ControlChannel.cpp \ diff --git a/src/ui/TrayIcon.cpp b/src/ui/TrayIcon.cpp new file mode 100644 index 00000000..6efee852 --- /dev/null +++ b/src/ui/TrayIcon.cpp @@ -0,0 +1,69 @@ +/* Ricochet - https://ricochet.im/ + * Copyright (C) 2015, Kacper Kołodziej + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * Neither the names of the copyright owners nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "TrayIcon.h" + +TrayIcon::TrayIcon(QIcon std_icon, QIcon unread_icon) : + m_std_icon(std_icon), + m_unread_icon(unread_icon) +{ + connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(activated(QSystemTrayIcon::ActivationReason))); + setIcon(m_std_icon); + show(); +} + +void TrayIcon::setStdIcon(QIcon std_icon) +{ + m_std_icon = std_icon; +} + +void TrayIcon::setUnreadIcon(QIcon unread_icon) +{ + m_unread_icon = unread_icon; +} + +void TrayIcon::resetIcon() +{ + setIcon(m_std_icon); +} + +void TrayIcon::setUnread(bool unread) +{ + if (unread) setIcon(m_unread_icon); + else resetIcon(); +} + +void TrayIcon::activated(QSystemTrayIcon::ActivationReason reason) +{ + if (reason == QSystemTrayIcon::Trigger) + emit toggleWindow(); +} diff --git a/src/ui/TrayIcon.h b/src/ui/TrayIcon.h new file mode 100644 index 00000000..7d9773bd --- /dev/null +++ b/src/ui/TrayIcon.h @@ -0,0 +1,65 @@ +/* Ricochet - https://ricochet.im/ + * Copyright (C) 2015, Kacper Kołodziej + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * Neither the names of the copyright owners nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TRAYICON_H +#define TRAYICON_H +#include + +class TrayIcon : public QSystemTrayIcon +{ + Q_OBJECT + Q_PROPERTY(bool unread WRITE setUnread) +public: + TrayIcon(QIcon std_icon, QIcon unread_icon); + + void setStdIcon(QIcon std_icon); + void setUnreadIcon(QIcon unread_icon); + + // changes icon to m_std_icon + void resetIcon(); + + // changes icon to m_unread_icon + void setUnread(bool unread); + +public slots: + void activated(QSystemTrayIcon::ActivationReason); + +signals: + void toggleWindow(); + +private: + QIcon m_std_icon; + QIcon m_unread_icon; +}; + +#endif // TRAYICON_H + From c87cbef48014efecfbfec1e98c61edb45726228e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Sat, 5 Sep 2015 22:58:07 +0200 Subject: [PATCH 03/15] tray-icon: Add TrayIcon instance to MainWindow --- src/ui/MainWindow.cpp | 4 ++++ src/ui/MainWindow.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index c76f8114..41830e30 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -45,6 +45,7 @@ #include "utils/Settings.h" #include "utils/PendingOperation.h" #include "ui/LanguagesModel.h" +#include "ui/TrayIcon.h" #include #include #include @@ -67,6 +68,8 @@ MainWindow::MainWindow(QObject *parent) Q_ASSERT(!uiMain); uiMain = this; + trayIcon = new TrayIcon(QIcon(QLatin1String(":/icons/ricochet.svg")), QIcon(QLatin1String(":/icons/ricochet_unread.svg"))); + qml = new QQmlApplicationEngine(this); qmlRegisterUncreatableType("im.ricochet", 1, 0, "ContactUser", QString()); @@ -98,6 +101,7 @@ bool MainWindow::showUI() qml->rootContext()->setContextProperty(QLatin1String("torControl"), torControl); qml->rootContext()->setContextProperty(QLatin1String("torInstance"), Tor::TorManager::instance()); qml->rootContext()->setContextProperty(QLatin1String("uiMain"), this); + qml->rootContext()->setContextProperty(QLatin1String("trayIcon"), trayIcon); qml->load(QUrl(QLatin1String("qrc:/ui/main.qml"))); diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index 575789c9..c654260b 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -33,6 +33,7 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H +#include "TrayIcon.h" #include #include @@ -70,6 +71,7 @@ class MainWindow : public QObject private: QQmlApplicationEngine *qml; + TrayIcon *trayIcon; }; extern MainWindow *uiMain; From 1a433cb79e1f594270e6a28130b4056e810edf04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Sat, 5 Sep 2015 22:58:42 +0200 Subject: [PATCH 04/15] tray-icon: support TrayIcon's toggleWindow signal --- src/ui/qml/main.qml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/ui/qml/main.qml b/src/ui/qml/main.qml index 88291868..bc0a140e 100644 --- a/src/ui/qml/main.qml +++ b/src/ui/qml/main.qml @@ -9,9 +9,8 @@ import "ContactWindow.js" as ContactWindow QtObject { id: root - property MainWindow mainWindow: MainWindow { - onVisibleChanged: if (!visible) Qt.quit() - } + property MainWindow mainWindow: MainWindow {} + property int lastVisibility: Window.Windowed function createDialog(component, properties, parent) { if (typeof(component) === "string") @@ -95,6 +94,20 @@ QtObject { } }, + Connections { + target: trayIcon + onToggleWindow: { + if (mainWindow.visibility == Window.Hidden) + { + mainWindow.visibility = lastVisibility; + } else + { + lastVisibility = mainWindow.visibility; + mainWindow.visibility = Window.Hidden; + } + } + }, + Settings { id: uiSettings path: "ui" From 57d169b2f7db122a5dfa0c56784f54d532200c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Sun, 6 Sep 2015 10:31:28 +0200 Subject: [PATCH 05/15] tray-icon: Add context menu on right click on icon --- src/ui/TrayIcon.cpp | 34 ++++++++++++++++++++++++++++++++++ src/ui/TrayIcon.h | 12 ++++++++++++ src/ui/qml/main.qml | 9 +++++++++ 3 files changed, 55 insertions(+) diff --git a/src/ui/TrayIcon.cpp b/src/ui/TrayIcon.cpp index 6efee852..f78c02de 100644 --- a/src/ui/TrayIcon.cpp +++ b/src/ui/TrayIcon.cpp @@ -38,9 +38,23 @@ TrayIcon::TrayIcon(QIcon std_icon, QIcon unread_icon) : { connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(activated(QSystemTrayIcon::ActivationReason))); setIcon(m_std_icon); + + m_context_menu = new QMenu(); + m_context_menu->addAction(tr("Preferences"), this, SLOT(openPreferences())); + m_context_menu->addAction(tr("Add contact"), this, SLOT(addContact())); + m_context_menu->addAction(tr("Copy my ID"), this, SLOT(copyMyId())); + m_context_menu->addSeparator(); + m_context_menu->addAction(tr("Quit"), this, SLOT(quitApplication())); + setContextMenu(m_context_menu); + show(); } +TrayIcon::~TrayIcon() +{ + delete m_context_menu; +} + void TrayIcon::setStdIcon(QIcon std_icon) { m_std_icon = std_icon; @@ -67,3 +81,23 @@ void TrayIcon::activated(QSystemTrayIcon::ActivationReason reason) if (reason == QSystemTrayIcon::Trigger) emit toggleWindow(); } + +void TrayIcon::openPreferences() +{ + emit preferences(); +} + +void TrayIcon::addContact() +{ + emit contact(); +} + +void TrayIcon::copyMyId() +{ + emit copyId(); +} + +void TrayIcon::quitApplication() +{ + emit quit(); +} diff --git a/src/ui/TrayIcon.h b/src/ui/TrayIcon.h index 7d9773bd..7146bbeb 100644 --- a/src/ui/TrayIcon.h +++ b/src/ui/TrayIcon.h @@ -33,6 +33,7 @@ #ifndef TRAYICON_H #define TRAYICON_H #include +#include class TrayIcon : public QSystemTrayIcon { @@ -40,6 +41,7 @@ class TrayIcon : public QSystemTrayIcon Q_PROPERTY(bool unread WRITE setUnread) public: TrayIcon(QIcon std_icon, QIcon unread_icon); + ~TrayIcon(); void setStdIcon(QIcon std_icon); void setUnreadIcon(QIcon unread_icon); @@ -52,13 +54,23 @@ class TrayIcon : public QSystemTrayIcon public slots: void activated(QSystemTrayIcon::ActivationReason); + void openPreferences(); + void addContact(); + void copyMyId(); + void quitApplication(); signals: void toggleWindow(); + void preferences(); + void contact(); + void copyId(); + void quit(); private: QIcon m_std_icon; QIcon m_unread_icon; + + QMenu* m_context_menu; }; #endif // TRAYICON_H diff --git a/src/ui/qml/main.qml b/src/ui/qml/main.qml index bc0a140e..01ba5365 100644 --- a/src/ui/qml/main.qml +++ b/src/ui/qml/main.qml @@ -106,6 +106,15 @@ QtObject { mainWindow.visibility = Window.Hidden; } } + onPreferences: openPreferences() + onContact: { + var addContactDialog = createDialog("AddContactDialog.qml", {}, mainWindow) + addContactDialog.visible = true + } + onCopyId: { + LinkedText.copyToClipboard(userIdentity.contactID) + } + onQuit: Qt.quit() }, Settings { From 1fa46f6b04e9be5c027663b55f967173a9cb680c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Sun, 6 Sep 2015 11:28:57 +0200 Subject: [PATCH 06/15] tray-icon: Add notifying icon about unread message --- src/ui/qml/MainWindow.qml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ui/qml/MainWindow.qml b/src/ui/qml/MainWindow.qml index fc1c1e47..e1dd9599 100644 --- a/src/ui/qml/MainWindow.qml +++ b/src/ui/qml/MainWindow.qml @@ -44,6 +44,11 @@ ApplicationWindow { w = ContactWindow.getWindow(user) // On OS X, avoid bouncing the dock icon forever w.alert(Qt.platform.os == "osx" ? 1000 : 0) + + trayIcon.unread = true + } else + { + trayIcon.unread = false } } onContactStatusChanged: { From cafd4e3aa89d98eefba9aa00a5c580d366e97ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Sun, 6 Sep 2015 11:37:06 +0200 Subject: [PATCH 07/15] tray-icon: Alternative behaviour for Close button Add to preferences option which changes behaviour of Close button from closing application to hiding MainWindow. --- src/main.cpp | 5 +++++ src/ui/qml/GeneralPreferences.qml | 8 ++++++++ src/ui/qml/MainWindow.qml | 11 +++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index f044912f..3f731116 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,6 +60,11 @@ int main(int argc, char *argv[]) a.setApplicationVersion(QLatin1String("1.1.0")); a.setOrganizationName(QStringLiteral("Ricochet")); + /* avoid closing application when MainWindow is hidden + * and user try to close other opened dialogs + */ + a.setQuitOnLastWindowClosed(false); + #if !defined(Q_OS_WIN) && !defined(Q_OS_MAC) a.setWindowIcon(QIcon(QStringLiteral(":/icons/ricochet.svg"))); #endif diff --git a/src/ui/qml/GeneralPreferences.qml b/src/ui/qml/GeneralPreferences.qml index 1f057a50..f9f4edce 100644 --- a/src/ui/qml/GeneralPreferences.qml +++ b/src/ui/qml/GeneralPreferences.qml @@ -24,6 +24,14 @@ ColumnLayout { } } + CheckBox { + text: qsTr("Close button minimizes window to tray") + checked: uiSettings.data.hideOnX || false + onCheckedChanged: { + uiSettings.write("hideOnX", checked) + } + } + CheckBox { text: qsTr("Play audio notifications") checked: uiSettings.data.playAudioNotification || false diff --git a/src/ui/qml/MainWindow.qml b/src/ui/qml/MainWindow.qml index e1dd9599..fc07c478 100644 --- a/src/ui/qml/MainWindow.qml +++ b/src/ui/qml/MainWindow.qml @@ -19,6 +19,17 @@ ApplicationWindow { onMinimumWidthChanged: width = Math.max(width, minimumWidth) onMaximumWidthChanged: width = Math.min(width, maximumWidth) + onClosing: { + if (uiSettings.data.hideOnX) + { + close.accepted = false + visibility = Window.Hidden + } else + { + Qt.quit() + } + } + // OS X Menu Loader { active: Qt.platform.os == 'osx' From c07de7cdb63b6a30adf986f31870d069cc4522f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Sun, 6 Sep 2015 16:53:48 +0200 Subject: [PATCH 08/15] tray-icon: Modified behaviour when icon is clicked --- src/ui/qml/main.qml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ui/qml/main.qml b/src/ui/qml/main.qml index 01ba5365..cfd58709 100644 --- a/src/ui/qml/main.qml +++ b/src/ui/qml/main.qml @@ -97,7 +97,8 @@ QtObject { Connections { target: trayIcon onToggleWindow: { - if (mainWindow.visibility == Window.Hidden) + if (mainWindow.visibility == Window.Hidden || + mainWindow.visibility == Window.Minimized) { mainWindow.visibility = lastVisibility; } else From 82a798397b7662e1c1f379ee2657416685dc73cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Sun, 6 Sep 2015 20:58:43 +0200 Subject: [PATCH 09/15] tray-icon: fix 'Add Contact' option in icon's menu If MainWindow is hidden, slot for contact signal in main.qml changes visibility of MainWindow first. --- src/ui/qml/main.qml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ui/qml/main.qml b/src/ui/qml/main.qml index cfd58709..9075c2c6 100644 --- a/src/ui/qml/main.qml +++ b/src/ui/qml/main.qml @@ -109,6 +109,9 @@ QtObject { } onPreferences: openPreferences() onContact: { + if (mainWindow.visible == false) + mainWindow.visibility = lastVisibility + var addContactDialog = createDialog("AddContactDialog.qml", {}, mainWindow) addContactDialog.visible = true } From 99ecf048bc1512d557e73e3df97f10b7c77fcd8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Fri, 18 Sep 2015 01:28:48 +0200 Subject: [PATCH 10/15] tray-icon: Fixes problems mentioned by special 1. Destruction of TrayIcon object in MainWindow's destructor 2. Forward declaration of TrayIcon in src/ui/MainWindow.h 3. QIcon objects for TrayIcon's constructor as const references 4. New names for TrayIcon's signals, removes unnecessary slots and connects signals from TrayIcon's context menu to another signals 5. Fixes braces style: brace in the same line as if/else in QML 6. Title case in TrayIcon's context menu --- src/ui/MainWindow.cpp | 1 + src/ui/MainWindow.h | 2 +- src/ui/TrayIcon.cpp | 36 +++++++++--------------------------- src/ui/TrayIcon.h | 11 +++-------- src/ui/qml/MainWindow.qml | 9 +++------ src/ui/qml/main.qml | 3 +-- 6 files changed, 18 insertions(+), 44 deletions(-) diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 41830e30..02edce84 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -92,6 +92,7 @@ MainWindow::MainWindow(QObject *parent) MainWindow::~MainWindow() { + delete trayIcon; } bool MainWindow::showUI() diff --git a/src/ui/MainWindow.h b/src/ui/MainWindow.h index c654260b..fd3fd9e5 100644 --- a/src/ui/MainWindow.h +++ b/src/ui/MainWindow.h @@ -33,10 +33,10 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include "TrayIcon.h" #include #include +class TrayIcon; class ContactUser; class UserIdentity; class IncomingContactRequest; diff --git a/src/ui/TrayIcon.cpp b/src/ui/TrayIcon.cpp index f78c02de..e3cc3a2a 100644 --- a/src/ui/TrayIcon.cpp +++ b/src/ui/TrayIcon.cpp @@ -32,19 +32,21 @@ #include "TrayIcon.h" -TrayIcon::TrayIcon(QIcon std_icon, QIcon unread_icon) : +#include + +TrayIcon::TrayIcon(const QIcon& std_icon, const QIcon& unread_icon) : m_std_icon(std_icon), m_unread_icon(unread_icon) { - connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(activated(QSystemTrayIcon::ActivationReason))); + connect(this, &QSystemTrayIcon::activated, this, &TrayIcon::onActivated); setIcon(m_std_icon); m_context_menu = new QMenu(); - m_context_menu->addAction(tr("Preferences"), this, SLOT(openPreferences())); - m_context_menu->addAction(tr("Add contact"), this, SLOT(addContact())); - m_context_menu->addAction(tr("Copy my ID"), this, SLOT(copyMyId())); + m_context_menu->addAction(tr("Preferences"), this, SIGNAL(preferences())); + m_context_menu->addAction(tr("Add Contact"), this, SIGNAL(addContact())); + m_context_menu->addAction(tr("Copy My ID"), this, SIGNAL(copyId())); m_context_menu->addSeparator(); - m_context_menu->addAction(tr("Quit"), this, SLOT(quitApplication())); + m_context_menu->addAction(tr("Quit"), qApp, SLOT(quit())); setContextMenu(m_context_menu); show(); @@ -76,28 +78,8 @@ void TrayIcon::setUnread(bool unread) else resetIcon(); } -void TrayIcon::activated(QSystemTrayIcon::ActivationReason reason) +void TrayIcon::onActivated(QSystemTrayIcon::ActivationReason reason) { if (reason == QSystemTrayIcon::Trigger) emit toggleWindow(); } - -void TrayIcon::openPreferences() -{ - emit preferences(); -} - -void TrayIcon::addContact() -{ - emit contact(); -} - -void TrayIcon::copyMyId() -{ - emit copyId(); -} - -void TrayIcon::quitApplication() -{ - emit quit(); -} diff --git a/src/ui/TrayIcon.h b/src/ui/TrayIcon.h index 7146bbeb..e5ffd803 100644 --- a/src/ui/TrayIcon.h +++ b/src/ui/TrayIcon.h @@ -40,7 +40,7 @@ class TrayIcon : public QSystemTrayIcon Q_OBJECT Q_PROPERTY(bool unread WRITE setUnread) public: - TrayIcon(QIcon std_icon, QIcon unread_icon); + TrayIcon(const QIcon& std_icon, const QIcon& unread_icon); ~TrayIcon(); void setStdIcon(QIcon std_icon); @@ -53,18 +53,13 @@ class TrayIcon : public QSystemTrayIcon void setUnread(bool unread); public slots: - void activated(QSystemTrayIcon::ActivationReason); - void openPreferences(); - void addContact(); - void copyMyId(); - void quitApplication(); + void onActivated(QSystemTrayIcon::ActivationReason); signals: void toggleWindow(); void preferences(); - void contact(); + void addContact(); void copyId(); - void quit(); private: QIcon m_std_icon; diff --git a/src/ui/qml/MainWindow.qml b/src/ui/qml/MainWindow.qml index fc07c478..8377a4a1 100644 --- a/src/ui/qml/MainWindow.qml +++ b/src/ui/qml/MainWindow.qml @@ -20,12 +20,10 @@ ApplicationWindow { onMaximumWidthChanged: width = Math.min(width, maximumWidth) onClosing: { - if (uiSettings.data.hideOnX) - { + if (uiSettings.data.hideOnX) { close.accepted = false visibility = Window.Hidden - } else - { + } else { Qt.quit() } } @@ -57,8 +55,7 @@ ApplicationWindow { w.alert(Qt.platform.os == "osx" ? 1000 : 0) trayIcon.unread = true - } else - { + } else { trayIcon.unread = false } } diff --git a/src/ui/qml/main.qml b/src/ui/qml/main.qml index 9075c2c6..9aeff7da 100644 --- a/src/ui/qml/main.qml +++ b/src/ui/qml/main.qml @@ -108,7 +108,7 @@ QtObject { } } onPreferences: openPreferences() - onContact: { + onAddContact: { if (mainWindow.visible == false) mainWindow.visibility = lastVisibility @@ -118,7 +118,6 @@ QtObject { onCopyId: { LinkedText.copyToClipboard(userIdentity.contactID) } - onQuit: Qt.quit() }, Settings { From 1789f0c5db8c7db467ab5f76539848506b7063bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Fri, 18 Sep 2015 13:54:11 +0200 Subject: [PATCH 11/15] tray-icon: Fixes problems mentioned by rburchell 1. Removes unused TrayIcon::setStdIcon and TrayIcon::setUnreadIcon 2. Removes code formatting issues --- src/ui/TrayIcon.cpp | 16 ++++------------ src/ui/TrayIcon.h | 3 --- src/ui/qml/main.qml | 6 ++---- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/ui/TrayIcon.cpp b/src/ui/TrayIcon.cpp index e3cc3a2a..c1959afe 100644 --- a/src/ui/TrayIcon.cpp +++ b/src/ui/TrayIcon.cpp @@ -57,16 +57,6 @@ TrayIcon::~TrayIcon() delete m_context_menu; } -void TrayIcon::setStdIcon(QIcon std_icon) -{ - m_std_icon = std_icon; -} - -void TrayIcon::setUnreadIcon(QIcon unread_icon) -{ - m_unread_icon = unread_icon; -} - void TrayIcon::resetIcon() { setIcon(m_std_icon); @@ -74,8 +64,10 @@ void TrayIcon::resetIcon() void TrayIcon::setUnread(bool unread) { - if (unread) setIcon(m_unread_icon); - else resetIcon(); + if (unread) + setIcon(m_unread_icon); + else + resetIcon(); } void TrayIcon::onActivated(QSystemTrayIcon::ActivationReason reason) diff --git a/src/ui/TrayIcon.h b/src/ui/TrayIcon.h index e5ffd803..bee534de 100644 --- a/src/ui/TrayIcon.h +++ b/src/ui/TrayIcon.h @@ -43,9 +43,6 @@ class TrayIcon : public QSystemTrayIcon TrayIcon(const QIcon& std_icon, const QIcon& unread_icon); ~TrayIcon(); - void setStdIcon(QIcon std_icon); - void setUnreadIcon(QIcon unread_icon); - // changes icon to m_std_icon void resetIcon(); diff --git a/src/ui/qml/main.qml b/src/ui/qml/main.qml index 9aeff7da..00604ae7 100644 --- a/src/ui/qml/main.qml +++ b/src/ui/qml/main.qml @@ -98,11 +98,9 @@ QtObject { target: trayIcon onToggleWindow: { if (mainWindow.visibility == Window.Hidden || - mainWindow.visibility == Window.Minimized) - { + mainWindow.visibility == Window.Minimized) { mainWindow.visibility = lastVisibility; - } else - { + } else { lastVisibility = mainWindow.visibility; mainWindow.visibility = Window.Hidden; } From 0e9ec6630c45b142023e090cf022d732e36c81fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Wed, 6 Jan 2016 21:10:21 +0100 Subject: [PATCH 12/15] turns tray icon off on OS X --- src/ui/MainWindow.cpp | 11 ++++++++--- src/ui/qml/GeneralPreferences.qml | 1 + src/ui/qml/MainWindow.qml | 7 +++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 02edce84..686f79d8 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -62,13 +62,17 @@ static QObject *linkedtext_singleton(QQmlEngine *, QJSEngine *) return new LinkedText; } -MainWindow::MainWindow(QObject *parent) - : QObject(parent) +MainWindow::MainWindow(QObject *parent) : + QObject(parent), + trayIcon(nullptr) { Q_ASSERT(!uiMain); uiMain = this; + /* tray icon doesn't behave well on Mac OS X */ +#ifndef Q_OS_MAC trayIcon = new TrayIcon(QIcon(QLatin1String(":/icons/ricochet.svg")), QIcon(QLatin1String(":/icons/ricochet_unread.svg"))); +#endif qml = new QQmlApplicationEngine(this); @@ -92,7 +96,8 @@ MainWindow::MainWindow(QObject *parent) MainWindow::~MainWindow() { - delete trayIcon; + if (trayIcon != nullptr) + delete trayIcon; } bool MainWindow::showUI() diff --git a/src/ui/qml/GeneralPreferences.qml b/src/ui/qml/GeneralPreferences.qml index f9f4edce..0a4fe7a3 100644 --- a/src/ui/qml/GeneralPreferences.qml +++ b/src/ui/qml/GeneralPreferences.qml @@ -26,6 +26,7 @@ ColumnLayout { CheckBox { text: qsTr("Close button minimizes window to tray") + visible: (Qt.platform.os === "osx") ? false : true checked: uiSettings.data.hideOnX || false onCheckedChanged: { uiSettings.write("hideOnX", checked) diff --git a/src/ui/qml/MainWindow.qml b/src/ui/qml/MainWindow.qml index 8377a4a1..2760b69b 100644 --- a/src/ui/qml/MainWindow.qml +++ b/src/ui/qml/MainWindow.qml @@ -54,9 +54,12 @@ ApplicationWindow { // On OS X, avoid bouncing the dock icon forever w.alert(Qt.platform.os == "osx" ? 1000 : 0) - trayIcon.unread = true + if (Qt.platform.os !== "osx") // tray icon is turned off on OS X + trayIcon.unread = true } else { - trayIcon.unread = false + + if (Qt.platform.os !== "osx") // tray icon is turned off on OS X + trayIcon.unread = false } } onContactStatusChanged: { From d26c69eed48dd741811347a7431f62855e85b98d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Sat, 5 Mar 2016 16:36:17 +0100 Subject: [PATCH 13/15] tray-icon: blinking icon when there are unread messages --- src/ui/TrayIcon.cpp | 35 +++++++++++++++++++++++++------ src/ui/TrayIcon.h | 12 ++++++++--- src/ui/qml/GeneralPreferences.qml | 1 + 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/ui/TrayIcon.cpp b/src/ui/TrayIcon.cpp index c1959afe..42f13aff 100644 --- a/src/ui/TrayIcon.cpp +++ b/src/ui/TrayIcon.cpp @@ -36,11 +36,16 @@ TrayIcon::TrayIcon(const QIcon& std_icon, const QIcon& unread_icon) : m_std_icon(std_icon), - m_unread_icon(unread_icon) + m_unread_icon(unread_icon), + m_blink_state(false) { connect(this, &QSystemTrayIcon::activated, this, &TrayIcon::onActivated); setIcon(m_std_icon); + m_blink_timer.setInterval(750); + m_blink_timer.setSingleShot(false); + connect(&m_blink_timer, SIGNAL(timeout()), this, SLOT(blinkIcon())); + m_context_menu = new QMenu(); m_context_menu->addAction(tr("Preferences"), this, SIGNAL(preferences())); m_context_menu->addAction(tr("Add Contact"), this, SIGNAL(addContact())); @@ -57,17 +62,25 @@ TrayIcon::~TrayIcon() delete m_context_menu; } -void TrayIcon::resetIcon() +void TrayIcon::stdIcon() { setIcon(m_std_icon); } +void TrayIcon::unreadIcon() +{ + setIcon(m_unread_icon); +} + void TrayIcon::setUnread(bool unread) { - if (unread) - setIcon(m_unread_icon); - else - resetIcon(); + if (unread) { + unreadIcon(); + m_blink_timer.start(); + } else { + m_blink_timer.stop(); + stdIcon(); + } } void TrayIcon::onActivated(QSystemTrayIcon::ActivationReason reason) @@ -75,3 +88,13 @@ void TrayIcon::onActivated(QSystemTrayIcon::ActivationReason reason) if (reason == QSystemTrayIcon::Trigger) emit toggleWindow(); } + +void TrayIcon::blinkIcon() +{ + if (m_blink_state) + stdIcon(); + else + unreadIcon(); + + m_blink_state = !m_blink_state; +} diff --git a/src/ui/TrayIcon.h b/src/ui/TrayIcon.h index bee534de..04f4661b 100644 --- a/src/ui/TrayIcon.h +++ b/src/ui/TrayIcon.h @@ -33,6 +33,7 @@ #ifndef TRAYICON_H #define TRAYICON_H #include +#include #include class TrayIcon : public QSystemTrayIcon @@ -43,14 +44,16 @@ class TrayIcon : public QSystemTrayIcon TrayIcon(const QIcon& std_icon, const QIcon& unread_icon); ~TrayIcon(); - // changes icon to m_std_icon - void resetIcon(); + // changes icon + inline void stdIcon(); + inline void unreadIcon(); - // changes icon to m_unread_icon + // changes state of tray icon void setUnread(bool unread); public slots: void onActivated(QSystemTrayIcon::ActivationReason); + void blinkIcon(); signals: void toggleWindow(); @@ -61,6 +64,9 @@ public slots: private: QIcon m_std_icon; QIcon m_unread_icon; + bool m_blink_state; + + QTimer m_blink_timer; QMenu* m_context_menu; }; diff --git a/src/ui/qml/GeneralPreferences.qml b/src/ui/qml/GeneralPreferences.qml index 0a4fe7a3..a4c9f8e3 100644 --- a/src/ui/qml/GeneralPreferences.qml +++ b/src/ui/qml/GeneralPreferences.qml @@ -40,6 +40,7 @@ ColumnLayout { uiSettings.write("playAudioNotification", checked) } } + RowLayout { Item { width: 16 } From 15f8fb601d542a4a0e50ae6c0a716422e30b9718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Sat, 5 Mar 2016 16:57:50 +0100 Subject: [PATCH 14/15] tray-icon: change unread icon --- icons/ricochet_unread.svg | 307 ++++++-------------------------------- 1 file changed, 48 insertions(+), 259 deletions(-) diff --git a/icons/ricochet_unread.svg b/icons/ricochet_unread.svg index c50db122..9e88f919 100644 --- a/icons/ricochet_unread.svg +++ b/icons/ricochet_unread.svg @@ -15,7 +15,7 @@ height="1149.8438" id="svg3004" xml:space="preserve" - inkscape:version="0.48.5 r10040" + inkscape:version="0.91 r13725" sodipodi:docname="ricochet_unread.svg">image/svg+xml \ No newline at end of file + id="linearGradient5461" + x1="2.1240001" + y1="15.438" + x2="28.684696" + y2="15.438" + gradientUnits="userSpaceOnUse" /> \ No newline at end of file From 592cfcff346f9671f2f13d4733430d1768937c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Ko=C5=82odziej?= Date: Sat, 5 Mar 2016 17:04:16 +0100 Subject: [PATCH 15/15] tray-icon: information about author of unread icon --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index b7b612b7..8284be24 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -31,3 +31,4 @@ * HD Moore * The Grugq * Lawrence Eastland - "R" icon +* Designerz Base (http://finest.graphics) - unread message icon