| 1 | // For license of this file, see <project-root-folder>/LICENSE.md.cxx . . $ `<file>/src/librssguard/gui/systemtrayicon.cpp`/ |
| 2 | |
| 3 | #include "gui/systemtrayicon.h"cxx . . $ `<file>/src/librssguard/gui/systemtrayicon.h`/ |
| 4 | |
| 5 | #include "definitions/definitions.h"cxx . . $ `<file>/src/librssguard/definitions/definitions.h`/ |
| 6 | #include "gui/dialogs/formmain.h"cxx . . $ `<file>/src/librssguard/gui/dialogs/formmain.h`/ |
| 7 | #include "miscellaneous/application.h"cxx . . $ `<file>/src/librssguard/miscellaneous/application.h`/ |
| 8 | #include "miscellaneous/settings.h"cxx . . $ `<file>/src/librssguard/miscellaneous/settings.h`/ |
| 9 | |
| 10 | #include <QPainter> |
| 11 | #include <QTimer> |
| 12 | |
| 13 | #if defined(Q_OS_WIN) |
| 14 | TrayIconMenu::TrayIconMenu(const QString& title, QWidget* parent) : QMenu(title, parent) {} |
| 15 | |
| 16 | bool TrayIconMenu::event(QEvent* event) { |
| 17 | if (event->type() == QEvent::Type::Show && QApplication::activeModalWidget() != nullptr) { |
| 18 | QTimer::singleShot(0, this, &TrayIconMenu::hide); |
| 19 | qApp->showGuiMessage(Notification::Event::GeneralEvent, |
| 20 | {tr("Close dialogs"), |
| 21 | tr("Close opened modal dialogs first."), |
| 22 | QSystemTrayIcon::MessageIcon::Warning}); |
| 23 | } |
| 24 | |
| 25 | return QMenu::event(event); |
| 26 | } |
| 27 | |
| 28 | #endif |
| 29 | |
| 30 | SystemTrayIconcxx . . $ SystemTrayIcon#::SystemTrayIconcxx . . $ SystemTrayIcon#SystemTrayIcon(ec5011742eb0b5cf).(const QStringcxx . . $ QString#& normal_icon, const QStringcxx . . $ QString#& plain_icon, FormMaincxx . . $ FormMain#* parent) |
| 31 | : QSystemTrayIconcxx . . $ QSystemTrayIcon#(parent), m_normalIconcxx . . $ SystemTrayIcon#m_normalIcon.(normal_icon), m_plainPixmapcxx . . $ SystemTrayIcon#m_plainPixmap.(plain_icon) { |
| 32 | qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_GUIcxx . . $ `src/librssguard/definitions/definitions.h:174:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Creating SystemTrayIcon instance."; |
| 33 | m_fontcxx . . $ SystemTrayIcon#m_font..setBoldcxx . . $ QFont#setBold(b45ddcbc8423892c).(true); |
| 34 | |
| 35 | m_tmrDoubleFirecxx . . $ SystemTrayIcon#m_tmrDoubleFire..setSingleShotcxx . . $ QTimer#setSingleShot(b45ddcbc8423892c).(true); |
| 36 | m_tmrDoubleFirecxx . . $ SystemTrayIcon#m_tmrDoubleFire..setIntervalcxx . . $ QTimer#setInterval(d4f767463ce0a6b3).(100); |
| 37 | |
| 38 | // Initialize icon. |
| 39 | setNumbercxx . . $ SystemTrayIcon#setNumber(918ebd27a9ddbad3).(); |
| 40 | setContextMenucxx . . $ QSystemTrayIcon#setContextMenu(cb52c12b49e9b51b).(parent->trayMenucxx . . $ FormMain#trayMenu(ed4378587ff805df).()); |
| 41 | |
| 42 | // Create necessary connections. |
| 43 | connectcxx . . $ QObject#connect(dad3a9587f3dce3c).(this, &SystemTrayIconcxx . . $ SystemTrayIcon#::activatedcxx . . $ QSystemTrayIcon#activated(dc7279b31293a212)., this, &SystemTrayIconcxx . . $ SystemTrayIcon#::onActivatedcxx . . $ SystemTrayIcon#onActivated(dc7279b31293a212).); |
| 44 | } |
| 45 | |
| 46 | SystemTrayIconcxx . . $ SystemTrayIcon#::~cxx . . $ SystemTrayIcon#`~SystemTrayIcon`(ced63f7c635d850d).SystemTrayIconcxx . . $ SystemTrayIcon#() { |
| 47 | qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_GUIcxx . . $ `src/librssguard/definitions/definitions.h:174:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Destroying SystemTrayIcon instance."; |
| 48 | hidecxx . . $ QSystemTrayIcon#hide(49f6e7a06ebc5aa8).(); |
| 49 | } |
| 50 | |
| 51 | void SystemTrayIconcxx . . $ SystemTrayIcon#::onActivatedcxx . . $ SystemTrayIcon#onActivated(dc7279b31293a212).(QSystemTrayIconcxx . . $ QSystemTrayIcon#::ActivationReasoncxx . . $ QSystemTrayIcon#ActivationReason# reason) { |
| 52 | if (m_tmrDoubleFirecxx . . $ SystemTrayIcon#m_tmrDoubleFire..isActivecxx . . $ QTimer#isActive(50ce9a9e25b4a850).()) { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | m_tmrDoubleFirecxx . . $ SystemTrayIcon#m_tmrDoubleFire..startcxx . . $ QTimer#start(49f6e7a06ebc5aa8).(); |
| 57 | |
| 58 | switch (reason) { |
| 59 | case SystemTrayIconcxx . . $ SystemTrayIcon#::ActivationReasoncxx . . $ QSystemTrayIcon#ActivationReason#::Triggercxx . . $ QSystemTrayIcon#Trigger.: |
| 60 | case SystemTrayIconcxx . . $ SystemTrayIcon#::ActivationReasoncxx . . $ QSystemTrayIcon#ActivationReason#::DoubleClickcxx . . $ QSystemTrayIcon#DoubleClick.: |
| 61 | case SystemTrayIconcxx . . $ SystemTrayIcon#::ActivationReasoncxx . . $ QSystemTrayIcon#ActivationReason#::MiddleClickcxx . . $ QSystemTrayIcon#MiddleClick.: |
| 62 | static_cast<FormMaincxx . . $ FormMain#*>(parentcxx . . $ QObject#parent(2dbb680a34285c44).())->switchVisibilitycxx . . $ FormMain#switchVisibility(b45ddcbc8423892c).(); |
| 63 | break; |
| 64 | |
| 65 | default: |
| 66 | break; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | bool SystemTrayIconcxx . . $ SystemTrayIcon#::isSystemTrayAreaAvailablecxx . . $ SystemTrayIcon#isSystemTrayAreaAvailable(c9857a73d68e59ba).() { |
| 71 | return QSystemTrayIconcxx . . $ QSystemTrayIcon#::isSystemTrayAvailablecxx . . $ QSystemTrayIcon#isSystemTrayAvailable(c9857a73d68e59ba).() && QSystemTrayIconcxx . . $ QSystemTrayIcon#::supportsMessagescxx . . $ QSystemTrayIcon#supportsMessages(c9857a73d68e59ba).(); |
| 72 | } |
| 73 | |
| 74 | bool SystemTrayIconcxx . . $ SystemTrayIcon#::isSystemTrayDesiredcxx . . $ SystemTrayIcon#isSystemTrayDesired(c9857a73d68e59ba).() { |
| 75 | return qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->settingscxx . . $ Application#settings(951936487a2d9252).()->valuecxx . . $ Settings#value(8f1f29a69568d71a).(GROUPcxx . . $ `src/librssguard/miscellaneous/settings.h:32:9`!(GUI), SETTINGcxx . . $ `src/librssguard/miscellaneous/settings.h:30:9`!(GUI::UseTrayIcon)).toBoolcxx . . $ QVariant#toBool(50ce9a9e25b4a850).(); |
| 76 | } |
| 77 | |
| 78 | void SystemTrayIconcxx . . $ SystemTrayIcon#::showPrivatecxx . . $ SystemTrayIcon#showPrivate(49f6e7a06ebc5aa8).() { |
| 79 | // Make sure that application does not exit some window (for example |
| 80 | // the settings window) gets closed. Behavior for main window |
| 81 | // is handled explicitly by FormMain::closeEvent() method. |
| 82 | qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->setQuitOnLastWindowClosedcxx . . $ QGuiApplication#setQuitOnLastWindowClosed(b45ddcbc8423892c).(false); |
| 83 | |
| 84 | // Display the tray icon. |
| 85 | QSystemTrayIconcxx . . $ QSystemTrayIcon#::showcxx . . $ QSystemTrayIcon#show(49f6e7a06ebc5aa8).(); |
| 86 | emitcxx . . $ `<external>/4830994369567095248/qtmetamacros.h:51:10`! showncxx . . $ SystemTrayIcon#shown(49f6e7a06ebc5aa8).(); |
| 87 | |
| 88 | qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_GUIcxx . . $ `src/librssguard/definitions/definitions.h:174:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Tray icon displayed."; |
| 89 | } |
| 90 | |
| 91 | void SystemTrayIconcxx . . $ SystemTrayIcon#::showcxx . . $ SystemTrayIcon#show(49f6e7a06ebc5aa8).() { |
| 92 | // Show immediately. |
| 93 | qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_GUIcxx . . $ `src/librssguard/definitions/definitions.h:174:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Showing tray icon immediately."; |
| 94 | showPrivatecxx . . $ SystemTrayIcon#showPrivate(49f6e7a06ebc5aa8).(); |
| 95 | } |
| 96 | |
| 97 | void SystemTrayIconcxx . . $ SystemTrayIcon#::setNumbercxx . . $ SystemTrayIcon#setNumber(918ebd27a9ddbad3).(int number, bool any_feed_has_new_unread_messages) { |
| 98 | Q_UNUSEDcxx . . $ `<external>/17563275351362271547/qtpreprocessorsupport.h:20:9`!(any_feed_has_new_unread_messages) |
| 99 | |
| 100 | if (number <= 0 || !qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->settingscxx . . $ Application#settings(951936487a2d9252).()->valuecxx . . $ Settings#value(8f1f29a69568d71a).(GROUPcxx . . $ `src/librssguard/miscellaneous/settings.h:32:9`!(GUI), SETTINGcxx . . $ `src/librssguard/miscellaneous/settings.h:30:9`!(GUI::UnreadNumbersInTrayIcon)).toBoolcxx . . $ QVariant#toBool(50ce9a9e25b4a850).()) { |
| 101 | // Either no unread messages or numbers in tray icon are disabled. |
| 102 | setToolTipcxx . . $ QSystemTrayIcon#setToolTip(3520e46b33348bf6).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(APP_LONG_NAMEcxx . . $ `<built-in>:484:9`!)); |
| 103 | QSystemTrayIconcxx . . $ QSystemTrayIcon#::setIconcxx . . $ QSystemTrayIcon#setIcon(71dcdac178620ed6).(QIconcxx . . $ QIcon#QIcon(71dcdac178620ed6).(m_normalIconcxx . . $ SystemTrayIcon#m_normalIcon.)); |
| 104 | } |
| 105 | else { |
| 106 | setToolTipcxx . . $ QSystemTrayIcon#setToolTip(3520e46b33348bf6).(trcxx . . $ SystemTrayIcon#tr(75d9f1c324b4579d).("%1\nUnread news: %2").argcxx . . $ QString#arg(89b093bd48b6d6c0).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(APP_LONG_NAMEcxx . . $ `<built-in>:484:9`!), QStringcxx . . $ QString#::numbercxx . . $ QString#number(f4fd9db251ca774b).(number))); |
| 107 | QPixmapcxx . . $ QPixmap# backgroundcxx . . $ QPixmap#QPixmap(8887f7d25b86c3f4).(m_plainPixmapcxx . . $ SystemTrayIcon#m_plainPixmap.); |
| 108 | QPaintercxx . . $ QPainter# tray_paintercxx . . $ QPainter#QPainter(49f6e7a06ebc5aa8).; |
| 109 | |
| 110 | tray_painter.begincxx . . $ QPainter#begin(3d42010d693361d5).(&background); |
| 111 | |
| 112 | if (qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->settingscxx . . $ Application#settings(951936487a2d9252).()->valuecxx . . $ Settings#value(8f1f29a69568d71a).(GROUPcxx . . $ `src/librssguard/miscellaneous/settings.h:32:9`!(GUI), SETTINGcxx . . $ `src/librssguard/miscellaneous/settings.h:30:9`!(GUI::MonochromeTrayIcon)).toBoolcxx . . $ QVariant#toBool(50ce9a9e25b4a850).() && |
| 113 | !qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->settingscxx . . $ Application#settings(951936487a2d9252).()->valuecxx . . $ Settings#value(8f1f29a69568d71a).(GROUPcxx . . $ `src/librssguard/miscellaneous/settings.h:32:9`!(GUI), SETTINGcxx . . $ `src/librssguard/miscellaneous/settings.h:30:9`!(GUI::ColoredBusyTrayIcon)).toBoolcxx . . $ QVariant#toBool(50ce9a9e25b4a850).()) { |
| 114 | tray_painter.setPencxx . . $ QPainter#setPen(129a55e114526ad3).(Qtcxx . . $ QColor#QColor(408ec4d5924bfb00).::GlobalColorcxx . . $ Qt/GlobalColor#::whitecxx . . $ Qt/white.); |
| 115 | } |
| 116 | else { |
| 117 | tray_painter.setPencxx . . $ QPainter#setPen(129a55e114526ad3).(Qtcxx . . $ QColor#QColor(408ec4d5924bfb00).::GlobalColorcxx . . $ Qt/GlobalColor#::blackcxx . . $ Qt/black.); |
| 118 | } |
| 119 | |
| 120 | tray_painter.setRenderHintcxx . . $ QPainter#setRenderHint(df747a77a7bbbce1).(QPaintercxx . . $ QPainter#::RenderHintcxx . . $ QPainter#RenderHint#::SmoothPixmapTransformcxx . . $ QPainter#SmoothPixmapTransform., true); |
| 121 | tray_painter.setRenderHintcxx . . $ QPainter#setRenderHint(df747a77a7bbbce1).(QPaintercxx . . $ QPainter#::RenderHintcxx . . $ QPainter#RenderHint#::TextAntialiasingcxx . . $ QPainter#TextAntialiasing., true); |
| 122 | |
| 123 | // Numbers with more than 5 digits won't be readable, display |
| 124 | // infinity symbol in that case. |
| 125 | QStringcxx . . $ QString# num_txtcxx . . $ QString#QString(ced63f7c635d850d).; |
| 126 | |
| 127 | if (number > 99999) { |
| 128 | num_txt =cxx . . $ QString#`operator=`(3a2ffbdf8ecc25e2). QCharcxx . . $ QChar#QChar(93d577a3e9528307).(8734); |
| 129 | m_fontcxx . . $ SystemTrayIcon#m_font..setPixelSizecxx . . $ QFont#setPixelSize(d4f767463ce0a6b3).(background.widthcxx . . $ QPixmap#width(455f465bc33b4cdf).() * 0.78); |
| 130 | } |
| 131 | else if (number > 999) { |
| 132 | num_txt =cxx . . $ QString#`operator=`(4f35bf974e7f8568). QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("%1k").argcxx . . $ QString#arg(ed67e9a87de2cd4e).(int(number / 1000)); |
| 133 | m_fontcxx . . $ SystemTrayIcon#m_font..setPixelSizecxx . . $ QFont#setPixelSize(d4f767463ce0a6b3).(background.widthcxx . . $ QPixmap#width(455f465bc33b4cdf).() * 0.43); |
| 134 | } |
| 135 | else if (number > 99) { |
| 136 | num_txt =cxx . . $ QString#`operator=`(4f35bf974e7f8568). QStringcxx . . $ QString#::numbercxx . . $ QString#number(f4fd9db251ca774b).(number); |
| 137 | m_fontcxx . . $ SystemTrayIcon#m_font..setPixelSizecxx . . $ QFont#setPixelSize(d4f767463ce0a6b3).(background.widthcxx . . $ QPixmap#width(455f465bc33b4cdf).() * 0.43); |
| 138 | } |
| 139 | else if (number > 9) { |
| 140 | num_txt =cxx . . $ QString#`operator=`(4f35bf974e7f8568). QStringcxx . . $ QString#::numbercxx . . $ QString#number(f4fd9db251ca774b).(number); |
| 141 | m_fontcxx . . $ SystemTrayIcon#m_font..setPixelSizecxx . . $ QFont#setPixelSize(d4f767463ce0a6b3).(background.widthcxx . . $ QPixmap#width(455f465bc33b4cdf).() * 0.56); |
| 142 | } |
| 143 | else { |
| 144 | num_txt =cxx . . $ QString#`operator=`(4f35bf974e7f8568). QStringcxx . . $ QString#::numbercxx . . $ QString#number(f4fd9db251ca774b).(number); |
| 145 | m_fontcxx . . $ SystemTrayIcon#m_font..setPixelSizecxx . . $ QFont#setPixelSize(d4f767463ce0a6b3).(background.widthcxx . . $ QPixmap#width(455f465bc33b4cdf).() * 0.78); |
| 146 | } |
| 147 | |
| 148 | tray_painter.setFontcxx . . $ QPainter#setFont(d0a4bd0c8524b912).(m_fontcxx . . $ SystemTrayIcon#m_font.); |
| 149 | tray_painter.drawTextcxx . . $ QPainter#drawText(5e6899f7fbe08e9d).(background.rectcxx . . $ QPixmap#rect(d857385bac04cbf7).(), Qtcxx . . $ Qt/::AlignmentFlagcxx . . $ Qt/AlignmentFlag#::AlignCentercxx . . $ Qt/AlignCenter., num_txt); |
| 150 | tray_painter.endcxx . . $ QPainter#end(c9857a73d68e59ba).(); |
| 151 | |
| 152 | QSystemTrayIconcxx . . $ QSystemTrayIcon#::setIconcxx . . $ QSystemTrayIcon#setIcon(71dcdac178620ed6).(QIconcxx . . $ QIcon#QIcon(8887f7d25b86c3f4).(background)); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | void SystemTrayIconcxx . . $ SystemTrayIcon#::showMessagecxx . . $ SystemTrayIcon#showMessage(5a7ad92df912dbeb).(const QStringcxx . . $ QString#& title, |
| 157 | const QStringcxx . . $ QString#& message, |
| 158 | QSystemTrayIconcxx . . $ QSystemTrayIcon#::MessageIconcxx . . $ QSystemTrayIcon#MessageIcon# icon, |
| 159 | int milliseconds_timeout_hint, |
| 160 | const stdcxx . . $ std/::functioncxx . . $ std/function#<void()>& functor) { |
| 161 | if (m_connectioncxx . . $ SystemTrayIcon#m_connection. != nullptr) { |
| 162 | // Disconnect previous bubble click signalling. |
| 163 | disconnectcxx . . $ QObject#disconnect(14933e9feb207a26).(m_connectioncxx . . $ SystemTrayIcon#m_connection.); |
| 164 | } |
| 165 | |
| 166 | if (functor) { |
| 167 | // Establish new connection for bubble click. |
| 168 | m_connectioncxx . . $ SystemTrayIcon#m_connection. =cxx . . $ QMetaObject#Connection#`operator=`(a092d28922a077af). connectcxx . . $ QObject#connect(93770ac28d6bf547).(this, &SystemTrayIconcxx . . $ SystemTrayIcon#::messageClickedcxx . . $ QSystemTrayIcon#messageClicked(49f6e7a06ebc5aa8)., functor); |
| 169 | } |
| 170 | |
| 171 | // NOTE: If connections do not work, then use QMetaObject::invokeMethod(...). |
| 172 | QSystemTrayIconcxx . . $ QSystemTrayIcon#::showMessagecxx . . $ QSystemTrayIcon#showMessage(d234e6c04c1013f3).(title, message, icon, milliseconds_timeout_hint); |
| 173 | } |