Merge branch 'feature-notify' into develop

This commit is contained in:
Ximi1970
2020-06-11 23:38:25 +02:00
31 changed files with 1575 additions and 228 deletions

View File

@@ -17,6 +17,8 @@ else
endif
endif
#OPTIONS = "DEFINES += NO_KDE_INTEGRATION"
.PHONY: clean \
systray-x-xpi \
systray-x-app
@@ -56,7 +58,7 @@ systray-x-app:
rm -f SysTray-X ;\
mkdir -p app/build ;\
cd app/build ;\
$(QMAKE) $(EXT_VERSION) ../SysTray-X/SysTray-X.pro ;\
$(QMAKE) $(EXT_VERSION) $(OPTIONS) ../SysTray-X/SysTray-X.pro ;\
make ;\
cd ../.. ;\
cp app/build/SysTray-X .

View File

@@ -118,7 +118,7 @@ sudo apt update
###### 16.04 LTS
```bash
wget -q https://download.opensuse.org/repositories/home:/Ximi1970:/Mozilla:/Add-ons/xUbuntu_16.04/Release.key
wget -q http://download.opensuse.org/repositories/home:/Ximi1970:/Mozilla:/Add-ons/xUbuntu_16.04/Release.key
sudo apt-key add Release.key
sudo bash -c 'echo "deb https://download.opensuse.org/repositories/home:/Ximi1970:/Mozilla:/Add-ons/xUbuntu_16.04 ./" > /etc/apt/sources.list.d/systray-x.list'
sudo apt update
@@ -273,12 +273,18 @@ Requirements:
gnome-shell-extension-tool -e ubuntu-appindicator@ubuntu.com
```
Build:
Build (KDE):
```bash
cd systray-x
make
```
Build (GNOME):
```bash
cd systray-x
make OPTIONS="DEFINES+=NO_KDE_INTEGRATION"
```
Install and run SysTray-X from the build directory in the repository:
```bash
mkdir -p ~/.mozilla/native-messaging-hosts

View File

@@ -1,5 +1,14 @@
#<script>
Notifier
https://stackoverflow.com/questions/52935526/kstatusnotifieritem-instantiation-crashes-qt
kstatusnotifieritem.h => knotifications-devel
Installers

View File

@@ -4,10 +4,28 @@
#
#-------------------------------------------------
QT += core gui
#DEFINES += NO_KDE_INTEGRATION
!contains(DEFINES,NO_KDE_INTEGRATION) {
DEFINES += KDE_INTEGRATION
}
#
# Set the Qt modules
#
QT += core gui
unix:!macx: {
contains(DEFINES,KDE_INTEGRATION) {
QT += dbus KNotifications
}
}
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
#
# Define the target
#
TARGET = SysTray-X
TEMPLATE = app
@@ -158,6 +176,10 @@ SOURCES += \
unix: {
SOURCES += \
windowctrl-unix.cpp
contains(DEFINES,KDE_INTEGRATION) {
SOURCES += \
systrayxstatusnotifier.cpp
}
}
win32: {
SOURCES += \
@@ -175,6 +197,11 @@ HEADERS += \
unix: {
HEADERS += \
windowctrl-unix.h
contains(DEFINES,KDE_INTEGRATION) {
HEADERS += \
systrayxstatusnotifier.h
}
}
win32: {
HEADERS += \

View File

@@ -11,5 +11,6 @@
<file>files/icons/window-restore.png</file>
<file>files/icons/mail-unread.png</file>
<file>files/icons/help-about.png</file>
<file>files/icons/dialog-warning.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@@ -37,6 +37,7 @@ Preferences::Preferences( QObject *parent ) : QObject( parent )
m_default_icon_type = PREF_DEFAULT_ICON_DEFAULT;
m_default_icon_mime = "image/png";
m_default_icon_data = QByteArray();
m_hide_default_icon = false;
m_icon_type = PREF_BLANK_ICON;
m_icon_mime = "image/png";
@@ -218,6 +219,32 @@ void Preferences::setDefaultIconData( const QByteArray& icon_data )
}
/*
* Get the hide default icon state.
*/
bool Preferences::getHideDefaultIcon() const
{
return m_hide_default_icon;
}
/*
* Set the hide default icon state.
*/
void Preferences::setHideDefaultIcon( bool hide )
{
if( m_hide_default_icon != hide)
{
m_hide_default_icon = hide;
/*
* Tell the world the new preference
*/
emit signalHideDefaultIconChange();
}
}
/*
* Get the icon type.
*/

View File

@@ -184,6 +184,20 @@ class Preferences : public QObject
*/
void setDefaultIconData( const QByteArray& icon_data );
/**
* @brief getHideDefaultIcon. Get the hide default icon state.
*
* @return The state.
*/
bool getHideDefaultIcon() const;
/**
* @brief setHideDefaultIcon. Set the hide default icon state.
*
* @param The state.
*/
void setHideDefaultIcon( bool hide );
/**
* @brief getIconType. Get the icon type.
*
@@ -385,6 +399,11 @@ class Preferences : public QObject
*/
void signalDefaultIconDataChange();
/**
* @brief signalHideDefaultIconChange. Signal a hide default icon change.
*/
void signalHideDefaultIconChange();
/**
* @brief signalIconTypeChange. Signal a icon type change.
*/
@@ -472,6 +491,11 @@ class Preferences : public QObject
*/
QByteArray m_default_icon_data;
/**
* @brief m_hide_default_icon. Hide default icon state.
*/
bool m_hide_default_icon;
/**
* @brief m_icon_type. Selected icon type.
*/

View File

@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>525</width>
<width>543</width>
<height>600</height>
</rect>
</property>
@@ -17,160 +17,96 @@
<iconset resource="SysTray-X.qrc">
<normaloff>:/files/icons/SysTray-X.png</normaloff>:/files/icons/SysTray-X.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_15">
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Default icon</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
<layout class="QVBoxLayout" name="verticalLayout_13">
<item>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QRadioButton" name="defaultIconRadioButton">
<property name="text">
<string>Default Thunderbird</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">defaultIconTypeGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="hideDefaultIconRadioButton">
<property name="text">
<string>Hide icon</string>
</property>
<attribute name="buttonGroup">
<string notr="true">defaultIconTypeGroup</string>
</attribute>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QRadioButton" name="customDefaultIconRadioButton">
<property name="text">
<string>Custom icon</string>
</property>
<attribute name="buttonGroup">
<string notr="true">defaultIconTypeGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QLabel" name="defaultImageLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="chooseCustomDefaultIconButton">
<property name="text">
<string>Choose</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="0" column="1" rowspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Windows</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Minimize</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_3">
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Icon</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QRadioButton" name="defaultIconRadioButton">
<property name="text">
<string>Default Thunderbird</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">defaultIconTypeGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="lookThroughDefaultIconRadioButton">
<property name="text">
<string>Lookthrough icon</string>
</property>
<attribute name="buttonGroup">
<string notr="true">defaultIconTypeGroup</string>
</attribute>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QRadioButton" name="defaultMinimizeRadioButton">
<widget class="QRadioButton" name="customDefaultIconRadioButton">
<property name="text">
<string>Default minimize</string>
<string>Custom icon</string>
</property>
<property name="checked">
<attribute name="buttonGroup">
<string notr="true">defaultIconTypeGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QLabel" name="defaultImageLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="chooseCustomDefaultIconButton">
<property name="text">
<string>Choose</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">minimizeTypeGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="minimizeMethod1RadioButton">
<property name="text">
<string>Minimize to tray, method 1</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">minimizeTypeGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="minimizeMethod2RadioButton">
<property name="text">
<string>Minimize to tray, method 2</string>
</property>
<attribute name="buttonGroup">
<string notr="true">minimizeTypeGroup</string>
</attribute>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QCheckBox" name="startMinimizedCheckBox">
<property name="text">
<string>Start application minimized</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="minimizeOnCloseCheckBox">
<property name="text">
<string>Minimize on close</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="hideDefaultIconCheckBox">
<property name="text">
<string>KDE integration (Hide)</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" rowspan="2">
<item>
<widget class="QGroupBox" name="iconTypeGroupBox">
<property name="title">
<string>Mail notification icon</string>
@@ -307,7 +243,107 @@
</layout>
</widget>
</item>
<item row="2" column="1" rowspan="2">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>113</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_14">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Windows</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Minimize</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QRadioButton" name="defaultMinimizeRadioButton">
<property name="text">
<string>Default minimize</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">minimizeTypeGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="minimizeMethod1RadioButton">
<property name="text">
<string>Minimize to tray, method 1</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">minimizeTypeGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="minimizeMethod2RadioButton">
<property name="text">
<string>Minimize to tray, method 2</string>
</property>
<attribute name="buttonGroup">
<string notr="true">minimizeTypeGroup</string>
</attribute>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QCheckBox" name="startMinimizedCheckBox">
<property name="text">
<string>Start application minimized</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="minimizeOnCloseCheckBox">
<property name="text">
<string>Minimize on close</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Number properties</string>
@@ -411,20 +447,7 @@
</layout>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>113</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="1">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -439,7 +462,7 @@
</item>
</layout>
</item>
<item row="1" column="0">
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QCheckBox" name="debugWindowCheckBox">
@@ -484,9 +507,9 @@
</connection>
</connections>
<buttongroups>
<buttongroup name="countTypeGroup"/>
<buttongroup name="minimizeTypeGroup"/>
<buttongroup name="defaultIconTypeGroup"/>
<buttongroup name="minimizeTypeGroup"/>
<buttongroup name="iconTypeGroup"/>
<buttongroup name="countTypeGroup"/>
</buttongroups>
</ui>

View File

@@ -42,6 +42,14 @@ PreferencesDialog::PreferencesDialog( SysTrayXLink *link, Preferences *pref, QWi
m_ui->minimizeMethod1RadioButton->setText( "Minimize to tray" );
m_ui->minimizeMethod2RadioButton->hide();
m_ui->hideDefaultIconCheckBox->hide();
#endif
#if defined( Q_OS_UNIX ) && defined( NO_KDE_INTEGRATION )
m_ui->hideDefaultIconCheckBox->hide();
#endif
/*
@@ -75,7 +83,7 @@ PreferencesDialog::PreferencesDialog( SysTrayXLink *link, Preferences *pref, QWi
* Set default icon type button Ids
*/
m_ui->defaultIconTypeGroup->setId( m_ui->defaultIconRadioButton, Preferences::PREF_DEFAULT_ICON_DEFAULT );
m_ui->defaultIconTypeGroup->setId( m_ui->hideDefaultIconRadioButton, Preferences::PREF_DEFAULT_ICON_HIDE );
m_ui->defaultIconTypeGroup->setId( m_ui->lookThroughDefaultIconRadioButton, Preferences::PREF_DEFAULT_ICON_HIDE );
m_ui->defaultIconTypeGroup->setId( m_ui->customDefaultIconRadioButton, Preferences::PREF_DEFAULT_ICON_CUSTOM );
/*
@@ -230,6 +238,16 @@ void PreferencesDialog::setDefaultIcon()
m_ui->defaultImageLabel->setPixmap( pixmap.scaledToHeight( m_ui->chooseCustomButton->size().height() ) );
}
/*
* Set the hide default icon
*/
void PreferencesDialog::setHideDefaultIcon( bool hide )
{
m_ui->hideDefaultIconCheckBox->setChecked( hide );
}
/*
* Set the enable number state
*/
@@ -287,6 +305,7 @@ void PreferencesDialog::slotAccept()
m_pref->setDefaultIconType( static_cast< Preferences::DefaultIconType >( m_ui->defaultIconTypeGroup->checkedId() ) );
m_pref->setDefaultIconMime( m_tmp_default_icon_mime );
m_pref->setDefaultIconData( m_tmp_default_icon_data );
m_pref->setHideDefaultIcon( m_ui->hideDefaultIconCheckBox->isChecked() );
m_pref->setIconType( static_cast< Preferences::IconType >( m_ui->iconTypeGroup->checkedId() ) );
m_pref->setIconMime( m_tmp_icon_mime );
@@ -477,6 +496,15 @@ void PreferencesDialog::slotDefaultIconDataChange()
}
/*
* Handle the hide default icon change signal
*/
void PreferencesDialog::slotHideDefaultIconChange()
{
setHideDefaultIcon( m_pref->getHideDefaultIcon() );
}
/*
* Handle the enable number state change
*/

View File

@@ -109,6 +109,13 @@ class PreferencesDialog : public QDialog
*/
void setDefaultIcon();
/**
* @brief setHideDefaultIcon. Set the hide default icon.
*
* @param hide The state.
*/
void setHideDefaultIcon( bool hide );
/**
* @brief setShowNumber. Set the show number state.
*
@@ -183,6 +190,11 @@ class PreferencesDialog : public QDialog
*/
void slotDefaultIconTypeChange();
/**
* @brief slotHideDefaultIconChange. Slot for handling hide default icon change signals.
*/
void slotHideDefaultIconChange();
/**
* @brief slotIconDataChange. Slot for handling icon data change signals.
*/

View File

@@ -7,6 +7,7 @@
#include "preferencesdialog.h"
#include "systrayxlink.h"
#include "systrayxicon.h"
#include "systrayxstatusnotifier.h"
#include "windowctrl.h"
/*
@@ -14,8 +15,8 @@
*/
#include <QCoreApplication>
#include <QMenu>
#include <QStyle>
#include <QIcon>
#include <QTimer>
/*
* Constants
@@ -32,6 +33,11 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent )
* Initialize
*/
m_tray_icon = nullptr;
m_kde_tray_icon = nullptr;
m_tray_icon_menu = nullptr;
m_unread_mail = 0;
/*
* Setup preferences storage
@@ -65,12 +71,6 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent )
*/
m_pref_dialog = new PreferencesDialog( m_link, m_preferences );
/*
* Setup tray icon
*/
createMenu();
showTrayIcon();
/*
* Setup debug window
*/
@@ -83,9 +83,6 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent )
* Connect debug link signals
*/
connect( m_link, &SysTrayXLink::signalUnreadMail, m_debug, &DebugWidget::slotUnreadMail );
// connect( m_link, &SysTrayXLink::signalUnreadMail, this, &SysTrayX::slotUnreadMail );
// connect( m_win_ctrl, &WindowCtrl::signalShow, this, &SysTrayX::slotShow );
// connect( m_win_ctrl, &WindowCtrl::signalHide, this, &SysTrayX::slotHide );
connect( this, &SysTrayX::signalConsole, m_debug, &DebugWidget::slotConsole );
connect( m_preferences, &Preferences::signalConsole, m_debug, &DebugWidget::slotConsole );
@@ -97,6 +94,14 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent )
connect( m_debug, &DebugWidget::signalTest2ButtonClicked, m_win_ctrl, &WindowCtrl::slotWindowTest2 );
connect( m_debug, &DebugWidget::signalTest3ButtonClicked, m_win_ctrl, &WindowCtrl::slotWindowTest3 );
#ifdef Q_OS_UNIX
connect( m_win_ctrl, &WindowCtrl::signalHideDefaultIconChange, this, &SysTrayX::slotSelectIconObject );
#endif
connect( this, &SysTrayX::signalConsole, m_debug, &DebugWidget::slotConsole );
/*
* Connect preferences signals
*/
@@ -105,6 +110,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent )
connect( m_preferences, &Preferences::signalDefaultIconTypeChange, m_pref_dialog, &PreferencesDialog::slotDefaultIconTypeChange );
connect( m_preferences, &Preferences::signalDefaultIconDataChange, m_pref_dialog, &PreferencesDialog::slotDefaultIconDataChange );
connect( m_preferences, &Preferences::signalHideDefaultIconChange, m_pref_dialog, &PreferencesDialog::slotHideDefaultIconChange );
connect( m_preferences, &Preferences::signalIconTypeChange, m_pref_dialog, &PreferencesDialog::slotIconTypeChange );
connect( m_preferences, &Preferences::signalIconDataChange, m_pref_dialog, &PreferencesDialog::slotIconDataChange );
connect( m_preferences, &Preferences::signalShowNumberChange, m_pref_dialog, &PreferencesDialog::slotShowNumberChange );
@@ -118,6 +124,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent )
connect( m_preferences, &Preferences::signalDefaultIconTypeChange, m_link, &SysTrayXLink::slotDefaultIconTypeChange );
connect( m_preferences, &Preferences::signalDefaultIconDataChange, m_link, &SysTrayXLink::slotDefaultIconDataChange );
connect( m_preferences, &Preferences::signalHideDefaultIconChange, m_link, &SysTrayXLink::slotHideDefaultIconChange );
connect( m_preferences, &Preferences::signalIconTypeChange, m_link, &SysTrayXLink::slotIconTypeChange );
connect( m_preferences, &Preferences::signalIconDataChange, m_link, &SysTrayXLink::slotIconDataChange );
connect( m_preferences, &Preferences::signalShowNumberChange, m_link, &SysTrayXLink::slotShowNumberChange );
@@ -128,6 +135,7 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent )
connect( m_preferences, &Preferences::signalStartMinimizedChange, m_link, &SysTrayXLink::slotStartMinimizedChange );
connect( m_preferences, &Preferences::signalMinimizeOnCloseChange, m_link, &SysTrayXLink::slotMinimizeOnCloseChange );
connect( m_preferences, &Preferences::signalDebugChange, m_link, &SysTrayXLink::slotDebugChange );
connect( m_preferences, &Preferences::signalHideDefaultIconChange, this, &SysTrayX::slotSelectIconObjectPref );
connect( m_preferences, &Preferences::signalDebugChange, m_debug, &DebugWidget::slotDebugChange );
@@ -136,8 +144,10 @@ SysTrayX::SysTrayX( QObject *parent ) : QObject( parent )
*/
connect( m_link, &SysTrayXLink::signalAddOnShutdown, this, &SysTrayX::slotAddOnShutdown );
connect( m_link, &SysTrayXLink::signalWindowState, m_win_ctrl, &WindowCtrl::slotWindowState );
connect( m_link, &SysTrayXLink::signalUnreadMail, this, &SysTrayX::slotSetUnreadMail );
connect( m_link, &SysTrayXLink::signalTitle, m_win_ctrl, &WindowCtrl::slotWindowTitle );
connect( m_link, &SysTrayXLink::signalVersion, this, &SysTrayX::slotVersion );
connect( m_link, &SysTrayXLink::signalKdeIntegration, this, &SysTrayX::slotSelectIconObject );
/*
* SysTrayX
@@ -199,13 +209,31 @@ void SysTrayX::createMenu()
}
/*
* Destroy the icon menu
*/
void SysTrayX::destroyMenu()
{
if( m_tray_icon_menu )
{
delete m_tray_icon_menu;
m_tray_icon_menu = nullptr;
}
}
/*
* Show / create tray icon
*/
void SysTrayX::showTrayIcon()
{
if( !m_tray_icon )
{
{
/*
* Setup tray menu
*/
createMenu();
/*
* Create system tray icon
*/
@@ -241,10 +269,14 @@ void SysTrayX::showTrayIcon()
connect( m_link, &SysTrayXLink::signalUnreadMail, m_tray_icon, &SysTrayXIcon::slotSetUnreadMail );
connect( this, &SysTrayX::signalUnreadMail, m_tray_icon, &SysTrayXIcon::slotSetUnreadMail );
/*
* Show it
*/
m_tray_icon->show();
QTimer::singleShot(500, this, &SysTrayX::resendUnreadMail);
}
}
@@ -271,6 +303,8 @@ void SysTrayX::hideTrayIcon()
disconnect( m_link, &SysTrayXLink::signalUnreadMail, m_tray_icon, &SysTrayXIcon::slotSetUnreadMail );
disconnect( this, &SysTrayX::signalUnreadMail, m_tray_icon, &SysTrayXIcon::slotSetUnreadMail );
/*
* Hide the icon first to prevent "ghosts"
*/
@@ -281,49 +315,172 @@ void SysTrayX::hideTrayIcon()
*/
delete m_tray_icon;
m_tray_icon = nullptr;
/*
* Destroy the mennu
*/
destroyMenu();
}
}
#if defined( Q_OS_UNIX ) && defined( KDE_INTEGRATION )
/*
* Show / create tray icon
*/
void SysTrayX::showKdeTrayIcon()
{
if( !m_kde_tray_icon )
{
/*
* Setup tray menu
*/
createMenu();
/*
* Create system tray icon
*/
m_kde_tray_icon = new SysTrayXStatusNotifier( m_link, m_preferences );
m_kde_tray_icon->setStandardActionsEnabled( false );
m_kde_tray_icon->setContextMenu( m_tray_icon_menu );
/*
* Set default icon
*/
m_kde_tray_icon->setDefaultIconMime( m_preferences->getDefaultIconMime() );
m_kde_tray_icon->setDefaultIconData( m_preferences->getDefaultIconData() );
m_kde_tray_icon->setDefaultIconType( m_preferences->getDefaultIconType() );
/*
* Set icon
*/
m_kde_tray_icon->setIconMime( m_preferences->getIconMime() );
m_kde_tray_icon->setIconData( m_preferences->getIconData() );
m_kde_tray_icon->setIconType( m_preferences->getIconType() );
/*
* Connect the world
*/
connect( m_kde_tray_icon, &SysTrayXStatusNotifier::signalShowHide, m_win_ctrl, &WindowCtrl::slotShowHide );
connect( m_preferences, &Preferences::signalDefaultIconTypeChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotDefaultIconTypeChange );
connect( m_preferences, &Preferences::signalDefaultIconDataChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotDefaultIconDataChange );
connect( m_preferences, &Preferences::signalHideDefaultIconChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotHideDefaultIconChange );
connect( m_preferences, &Preferences::signalIconTypeChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotIconTypeChange );
connect( m_preferences, &Preferences::signalIconDataChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotIconDataChange );
connect( m_preferences, &Preferences::signalShowNumberChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotShowNumberChange );
connect( m_preferences, &Preferences::signalNumberColorChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotNumberColorChange );
connect( m_preferences, &Preferences::signalNumberSizeChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotNumberSizeChange );
connect( m_link, &SysTrayXLink::signalUnreadMail, m_kde_tray_icon, &SysTrayXStatusNotifier::slotSetUnreadMail );
connect( this, &SysTrayX::signalUnreadMail, m_kde_tray_icon, &SysTrayXStatusNotifier::slotSetUnreadMail );
/*
* Show
*/
QTimer::singleShot(500, this, &SysTrayX::resendUnreadMail);
}
}
/*
* Handle icon show signal
* Hide / remove tray icon
*/
void SysTrayX::slotShow()
void SysTrayX::hideKdeTrayIcon()
{
showTrayIcon();
}
/*
* Handle icon hide signal
*/
void SysTrayX::slotHide()
{
hideTrayIcon();
}
/*
* Hndle the unread mail signal
*/
void SysTrayX::slotUnreadMail( int unread_mail )
{
if( m_preferences->getDefaultIconType() == Preferences::PREF_DEFAULT_ICON_HIDE )
if( m_kde_tray_icon )
{
if( unread_mail > 0 )
{
showTrayIcon();
}
else
{
hideTrayIcon();
}
/*
* Disconnect all signals
*/
disconnect( m_kde_tray_icon, &SysTrayXStatusNotifier::signalShowHide, m_win_ctrl, &WindowCtrl::slotShowHide );
disconnect( m_preferences, &Preferences::signalDefaultIconTypeChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotDefaultIconTypeChange );
disconnect( m_preferences, &Preferences::signalDefaultIconDataChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotDefaultIconDataChange );
disconnect( m_preferences, &Preferences::signalHideDefaultIconChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotHideDefaultIconChange );
disconnect( m_preferences, &Preferences::signalIconTypeChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotIconTypeChange );
disconnect( m_preferences, &Preferences::signalIconDataChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotIconDataChange );
disconnect( m_preferences, &Preferences::signalShowNumberChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotShowNumberChange );
disconnect( m_preferences, &Preferences::signalNumberColorChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotNumberColorChange );
disconnect( m_preferences, &Preferences::signalNumberSizeChange, m_kde_tray_icon, &SysTrayXStatusNotifier::slotNumberSizeChange );
disconnect( m_link, &SysTrayXLink::signalUnreadMail, m_kde_tray_icon, &SysTrayXStatusNotifier::slotSetUnreadMail );
disconnect( this, &SysTrayX::signalUnreadMail, m_kde_tray_icon, &SysTrayXStatusNotifier::slotSetUnreadMail );
/*
* Remove the notifier icon
*/
delete m_kde_tray_icon;
m_kde_tray_icon = nullptr;
/*
* Destroy the mennu
*/
m_tray_icon_menu = nullptr;
//destroyMenu();
}
}
#endif
/*
* Select the prefered icon
*/
void SysTrayX::slotSelectIconObjectPref()
{
slotSelectIconObject( m_preferences->getHideDefaultIcon() );
}
void SysTrayX::slotSelectIconObject( bool state )
{
#if defined( Q_OS_UNIX ) && defined( KDE_INTEGRATION )
if( state )
{
// Use the KDE icon object
// emit signalConsole("Enable KDE icon");
// Remove the Qt tray icon
hideTrayIcon();
// Setup KDE tray icon
showKdeTrayIcon();
}
else
{
showTrayIcon();
// Use default Qt system tray icon
// emit signalConsole("Enable Qt icon");
// Remove KDE trsy icon
hideKdeTrayIcon();
// Setup the Qt tray icon
showTrayIcon();
}
#else
Q_UNUSED( state )
// Setup the Qt tray icon
showTrayIcon();
#endif
}
/*
* Resend unread mail
*/
void SysTrayX::resendUnreadMail()
{
emit signalUnreadMail( m_unread_mail );
}
@@ -335,7 +492,10 @@ void SysTrayX::slotAddOnShutdown()
/*
* Hide systray icon to prevent ghost systray icon in Windows
*/
m_tray_icon->hide();
if( m_tray_icon )
{
m_tray_icon->hide();
}
/*
* Close the TB window
@@ -364,7 +524,10 @@ void SysTrayX::slotShutdown()
/*
* Hide systray icon to prevent ghost systray icon in Windows
*/
m_tray_icon->hide();
if( m_tray_icon )
{
m_tray_icon->hide();
}
/*
* Close the TB window
@@ -410,5 +573,24 @@ void SysTrayX::slotVersion( QString version )
m_tray_icon->showMessage("SysTray-X Warning", "Version mismatch addon and app",
QSystemTrayIcon::Warning );
}
#if defined( Q_OS_UNIX ) && defined( KDE_INTEGRATION )
if( m_kde_tray_icon )
{
m_kde_tray_icon->showMessage("SysTray-X Warning", "Version mismatch addon and app", ":/files/icons/dialog-warning.png" );
}
#endif
}
}
/*
* Handle unread mail signal
*/
void SysTrayX::slotSetUnreadMail( int unread )
{
m_unread_mail = unread;
}

View File

@@ -25,6 +25,8 @@ class SysTrayXIcon;
class SysTrayXLink;
class WindowCtrl;
class SysTrayXStatusNotifier;
/**
* @brief The SysTrayX class
*/
@@ -57,6 +59,11 @@ class SysTrayX : public QObject
*/
void createMenu();
/**
* @brief destroyMenu. Destroy the menu.
*/
void destroyMenu();
/**
* @brief showTrayIcon. Create and show the icon.
*/
@@ -67,8 +74,34 @@ class SysTrayX : public QObject
*/
void hideTrayIcon();
#ifdef Q_OS_UNIX
/**
* @brief showKdeTrayIcon. Create and show the KDE icon.
*/
void showKdeTrayIcon();
/**
* @brief hideKdeTrayIcon. Hide and destroy the KDE icon.
*/
void hideKdeTrayIcon();
#endif
/**
* @brief resendUnreadMail. Send another unread mail signal to the icon.
*/
void resendUnreadMail();
signals:
/**
* @brief signalUnreadMail. Signal numder of unread mails.
*
* @param unreadMail The number of unread mails.
*/
void signalUnreadMail( int unread_mail );
/**
* @brief signalWriteMessage
*
@@ -88,17 +121,24 @@ class SysTrayX : public QObject
*/
void signalConsole( QString message );
private slots:
void slotShow();
void slotHide();
public slots:
/**
* @brief slotUnreadMail. Handle unread mail signal.
* @brief slotSetUnreadMail. Handle the unred mail signal.
*
* @param unread_mail Number of unread mail.
* @param unread Number of unread mail.
*/
void slotUnreadMail( int unread_mail );
void slotSetUnreadMail( int unread );
private slots:
/**
* @brief slotSelectIconObject. Select the prefered icon.
*
* @param state The state.
*/
void slotSelectIconObjectPref();
void slotSelectIconObject( bool state );
/**
* @brief slotAddOnShutdown. Handle shutdown request from the add-on.
@@ -152,6 +192,11 @@ class SysTrayX : public QObject
*/
SysTrayXIcon* m_tray_icon;
/**
* @brief m_kde_tray_icon. Pointer to the KDE system tray icon.
*/
SysTrayXStatusNotifier* m_kde_tray_icon;
/**
* @brief m_tray_icon_menu. Pointer to the tray icon menu.
*/
@@ -164,6 +209,11 @@ class SysTrayX : public QObject
QAction* m_pref_action;
QAction* m_about_action;
QAction* m_quit_action;
/**
* @brief m_unread_mail. Number of unread mails
*/
int m_unread_mail;
};
#endif // SYSTRAYX_H

View File

@@ -212,8 +212,8 @@ void SysTrayXIcon::setNumberSize( int size )
*/
void SysTrayXIcon::setUnreadMail( int unread_mail )
{
if( unread_mail != m_unread_mail ) {
if( m_unread_mail != unread_mail )
{
/*
* Store the new value
*/
@@ -279,7 +279,6 @@ void SysTrayXIcon::renderIcon()
case Preferences::PREF_DEFAULT_ICON_HIDE:
{
pixmap = QPixmap();
break;
}
@@ -403,6 +402,7 @@ void SysTrayXIcon::slotIconActivated( QSystemTrayIcon::ActivationReason reaso
{
switch (reason) {
case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::MiddleClick:
{
// Clicked
emit signalShowHide();
@@ -410,7 +410,6 @@ void SysTrayXIcon::slotIconActivated( QSystemTrayIcon::ActivationReason reaso
}
case QSystemTrayIcon::DoubleClick:
case QSystemTrayIcon::MiddleClick:
{
break;
}

View File

@@ -250,6 +250,26 @@ void SysTrayXLink::sendShutdown()
}
/*
* Send disable KDE integration to the add-on
*/
void SysTrayXLink::sendDisableKdeIntegration()
{
QJsonObject shutdownObject;
shutdownObject.insert("kdeIntegration", QJsonValue::fromVariant( "false" ) );
/*
* Store the new document
*/
QJsonDocument json_doc = QJsonDocument( shutdownObject );
/*
* Send it to the add-on
*/
linkWrite( json_doc.toJson( QJsonDocument::Compact ) );
}
/*
* Decode JSON message
*/
@@ -262,6 +282,14 @@ void SysTrayXLink::DecodeMessage( const QByteArray& message )
{
QJsonObject jsonObject = jsonResponse.object();
/*
QStringList list = jsonObject.keys();
for( int i = 0 ; i < list.length() ; ++i )
{
emit signalConsole( QString("Message %1").arg(list.at(i)) );
}
*/
if( jsonObject.contains( "unreadMail" ) && jsonObject[ "unreadMail" ].isDouble() )
{
int unreadMail = jsonObject[ "unreadMail" ].toInt();
@@ -289,10 +317,6 @@ void SysTrayXLink::DecodeMessage( const QByteArray& message )
{
QString window_state_str = jsonObject[ "window" ].toString();
emit signalConsole( QString( "Window state (%1)" ).arg( window_state_str ) );
int window_state;
if( window_state_str == Preferences::STATE_NORMAL_STR )
{
@@ -323,14 +347,28 @@ void SysTrayXLink::DecodeMessage( const QByteArray& message )
/*
* Unknown state
*/
emit signalConsole( QString( "Error: unknow window state (%1)" ).arg( window_state_str ) );
window_state = Preferences::STATE_NORMAL;
}
emit signalWindowState( window_state );
}
if( jsonObject.contains( "hideDefaultIcon" ) && jsonObject[ "hideDefaultIcon" ].isBool() )
{
bool hide_default_icon = jsonObject[ "hideDefaultIcon" ].toBool();
/*
* Signal the KDE integration or hide default icon
*/
emit signalKdeIntegration( hide_default_icon );
#if defined( Q_OS_UNIX ) && defined( NO_KDE_INTEGRATION )
sendDisableKdeIntegration();
#endif
}
if( jsonObject.contains( "platformInfo" ) && jsonObject[ "platformInfo" ].isObject() )
{
DecodePlatform( jsonObject[ "platformInfo" ].toObject() );
@@ -477,6 +515,16 @@ void SysTrayXLink::DecodePreferences( const QJsonObject& pref )
m_pref->setDefaultIconData( QByteArray::fromBase64( icon_base64.toUtf8() ) );
}
if( pref.contains( "hideDefaultIcon" ) && pref[ "hideDefaultIcon" ].isString() )
{
bool hide_default_icon = pref[ "hideDefaultIcon" ].toString() == "true";
/*
* Store the new start minimized state
*/
m_pref->setHideDefaultIcon( hide_default_icon );
}
if( pref.contains( "iconType" ) && pref[ "iconType" ].isString() )
{
Preferences::IconType icon_type = static_cast< Preferences::IconType >( pref[ "iconType" ].toString().toInt() );
@@ -604,6 +652,7 @@ void SysTrayXLink::EncodePreferences( const Preferences& pref )
prefObject.insert("defaultIconType", QJsonValue::fromVariant( QString::number( pref.getDefaultIconType() ) ) );
prefObject.insert("defaultIconMime", QJsonValue::fromVariant( pref.getDefaultIconMime() ) );
prefObject.insert("defaultIcon", QJsonValue::fromVariant( QString( pref.getDefaultIconData().toBase64() ) ) );
prefObject.insert("hideDefaultIcon", QJsonValue::fromVariant( QString( pref.getHideDefaultIcon() ? "true" : "false" ) ) );
prefObject.insert("iconType", QJsonValue::fromVariant( QString::number( pref.getIconType() ) ) );
prefObject.insert("iconMime", QJsonValue::fromVariant( pref.getIconMime() ) );
prefObject.insert("icon", QJsonValue::fromVariant( QString( pref.getIconData().toBase64() ) ) );
@@ -715,6 +764,18 @@ void SysTrayXLink::slotDefaultIconDataChange()
}
/*
* Handle the hide default icon change signal
*/
void SysTrayXLink::slotHideDefaultIconChange()
{
if( m_pref->getAppPrefChanged() )
{
sendPreferences();
}
}
/*
* Handle the icon type change signal
*/

View File

@@ -115,6 +115,11 @@ class SysTrayXLink : public QObject
*/
void sendShutdown();
/**
* @brief sendDisableKdeIntegration. Disable KDE integration.
*/
void sendDisableKdeIntegration();
private:
/**
@@ -181,6 +186,13 @@ class SysTrayXLink : public QObject
*/
void signalWindowState( int state );
/**
* @brief signalKdeIntegration. Signal KDE integration (and use the KStatusNotifierItem icon)
*
* @param state The prefered state
*/
void signalKdeIntegration( bool state );
/**
* @brief signalUnreadMail. Signal numder of unread mails.
*
@@ -220,6 +232,11 @@ class SysTrayXLink : public QObject
*/
void slotDefaultIconDataChange();
/**
* @brief slotHideDefaultIconChange. Slot for handling hide default icon change signals.
*/
void slotHideDefaultIconChange();
/**
* @brief slotIconTypeChange. Slot for handling icon type change signals.
*/

View File

@@ -0,0 +1,485 @@
#include "systrayxstatusnotifier.h"
#if defined( Q_OS_UNIX ) && defined( KDE_INTEGRATION )
/*
* Local includes
*/
#include "preferences.h"
/*
* System includes
*/
#include "systrayxlink.h"
/*
* Qt includes
*/
#include <QIcon>
#include <QTimer>
#include <QPixmap>
#include <QPainter>
/*
* Constructor
*/
SysTrayXStatusNotifier::SysTrayXStatusNotifier( SysTrayXLink* link, Preferences* pref, QObject* parent )
: KStatusNotifierItem( parent )
{
/*
* Initialize
*/
m_link = link;
m_pref = pref;
m_unread_mail = 0;
m_show_number = m_pref->getShowNumber();
m_number_color = m_pref->getNumberColor();
m_number_size = m_pref->getNumberSize();
/*
* Setup notifier
*/
setCategory( KStatusNotifierItem::ApplicationStatus );
setIconByPixmap( QIcon( QPixmap( ":/files/icons/Thunderbird.png") ) );
setTitle("SysTray-X");
setStatus( KStatusNotifierItem::ItemStatus::Passive );
m_hide_default_icon = true;
// setStatus(KStatusNotifierItem::ItemStatus::Active);
// setStatus(KStatusNotifierItem::ItemStatus::NeedsAttention);
connect( this, &KStatusNotifierItem::activateRequested, this, &SysTrayXStatusNotifier::slotActivateRequested );
connect( this, &KStatusNotifierItem::secondaryActivateRequested, this, &SysTrayXStatusNotifier::slotSecondaryActivateRequested );
}
/*
* Set the default icon type
*/
void SysTrayXStatusNotifier::setDefaultIconType( Preferences::DefaultIconType icon_type )
{
if( m_default_icon_type != icon_type )
{
/*
* Store the new value
*/
m_default_icon_type = icon_type;
/*
* Render and set a new icon in the tray
*/
renderIcon();
}
}
/*
* Set the default icon mime
*/
void SysTrayXStatusNotifier::setDefaultIconMime( const QString& icon_mime )
{
if( m_default_icon_mime != icon_mime )
{
/*
* Store the new value
*/
m_default_icon_mime = icon_mime;
}
}
/*
* Set the default icon data
*/
void SysTrayXStatusNotifier::setDefaultIconData( const QByteArray& icon_data )
{
if( m_default_icon_data != icon_data )
{
/*
* Store the new value
*/
m_default_icon_data = icon_data;
/*
* Render and set a new icon in the tray
*/
renderIcon();
}
}
/*
* Set the hide default icon
*/
void SysTrayXStatusNotifier::setHideDefaultIcon( bool hide )
{
if( m_hide_default_icon != hide )
{
/*
* Store the new value
*/
m_hide_default_icon = hide;
}
}
/*
* Set the icon type
*/
void SysTrayXStatusNotifier::setIconType( Preferences::IconType icon_type )
{
if( icon_type != m_icon_type )
{
/*
* Store the new value
*/
m_icon_type = icon_type;
/*
* Render and set a new icon in the tray
*/
renderIcon();
}
}
/*
* Set the icon mime
*/
void SysTrayXStatusNotifier::setIconMime( const QString& icon_mime )
{
if( m_icon_mime != icon_mime )
{
/*
* Store the new value
*/
m_icon_mime = icon_mime;
}
}
/*
* Set the icon data
*/
void SysTrayXStatusNotifier::setIconData( const QByteArray& icon_data )
{
if( m_icon_data != icon_data )
{
/*
* Store the new value
*/
m_icon_data = icon_data;
/*
* Render and set a new icon in the tray
*/
renderIcon();
}
}
/*
* Enable/disable number
*/
void SysTrayXStatusNotifier::showNumber( bool state )
{
if( m_show_number != state )
{
/*
* Store the new value
*/
m_show_number = state;
/*
* Render and set a new icon in the tray
*/
renderIcon();
}
}
/*
* Set number color
*/
void SysTrayXStatusNotifier::setNumberColor( const QString& color )
{
if( m_number_color != color )
{
/*
* Store the new value
*/
m_number_color = color;
/*
* Render and set a new icon in the tray
*/
renderIcon();
}
}
/*
* Set number size
*/
void SysTrayXStatusNotifier::setNumberSize( int size )
{
if( m_number_size != size )
{
/*
* Store the new value
*/
m_number_size = size;
/*
* Render and set a new icon in the tray
*/
renderIcon();
}
}
/*
* Set the number of unread mails
*/
void SysTrayXStatusNotifier::setUnreadMail( int unread_mail )
{
if( m_unread_mail != unread_mail )
{
/*
* Store the new value
*/
m_unread_mail = unread_mail;
/*
* Render and set a new icon in the tray
*/
renderIcon();
}
}
/*
* Set and render the icon in the system tray
*/
void SysTrayXStatusNotifier::renderIcon()
{
QPixmap pixmap;
if( m_unread_mail > 0 )
{
switch( m_icon_type )
{
case Preferences::PREF_BLANK_ICON:
{
pixmap = QPixmap( ":/files/icons/blank-icon.png" );
break;
}
case Preferences::PREF_NEWMAIL_ICON:
{
QIcon new_mail = QIcon::fromTheme("mail-unread", QIcon(":/files/icons/mail-unread.png"));
pixmap = new_mail.pixmap( 256, 256 );
break;
}
case Preferences::PREF_CUSTOM_ICON:
{
pixmap.loadFromData( m_icon_data );
break;
}
case Preferences::PREF_NO_ICON:
{
QPixmap lookthrough( 256, 256 );
lookthrough.fill( Qt::transparent );
pixmap = lookthrough;
break;
}
}
}
else
{
switch( m_default_icon_type )
{
case Preferences::PREF_DEFAULT_ICON_DEFAULT:
{
pixmap = QPixmap( ":/files/icons/Thunderbird.png" );
break;
}
case Preferences::PREF_DEFAULT_ICON_HIDE:
{
pixmap = QPixmap();
break;
}
case Preferences::PREF_DEFAULT_ICON_CUSTOM:
{
pixmap.loadFromData( m_default_icon_data );
break;
}
}
}
if( m_show_number && ( m_unread_mail > 0 ) )
{
/*
* Paint the number
*/
QPainter painter( &pixmap );
painter.setFont( QFont("Sans") );
#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0)
double factor = pixmap.width() / ( 3 * painter.fontMetrics().width( "0" ) );
#else
double factor = pixmap.width() / ( 3 * painter.fontMetrics().horizontalAdvance( "0" ) );
#endif
QFont font = painter.font();
font.setPointSizeF( font.pointSizeF() * ( factor * m_number_size / 10 ) );
font.setBold( true );
painter.setFont( font );
painter.setPen( QColor( m_number_color ) );
painter.drawText( pixmap.rect(), Qt::AlignCenter, QString::number( m_unread_mail ) );
}
/*
* Set the tray icon
*/
setIconByPixmap( QIcon( pixmap ) );
/*
* Hide the icon?
*/
if( m_hide_default_icon && m_unread_mail == 0 )
{
setStatus( KStatusNotifierItem::ItemStatus::Passive );
}
else
{
QTimer::singleShot(500, this, &SysTrayXStatusNotifier::showIcon);
}
}
void SysTrayXStatusNotifier::showIcon()
{
if( !m_hide_default_icon || m_unread_mail > 0 )
{
setStatus( KStatusNotifierItem::ItemStatus::Active );
}
}
/*
* Handle unread mail signal
*/
void SysTrayXStatusNotifier::slotSetUnreadMail( int unread_mail )
{
setUnreadMail( unread_mail );
}
/*
* Handle the default icon type change signal
*/
void SysTrayXStatusNotifier::slotDefaultIconTypeChange()
{
setDefaultIconType( m_pref->getDefaultIconType() );
}
/*
* Handle the default icon data change signal
*/
void SysTrayXStatusNotifier::slotDefaultIconDataChange()
{
setDefaultIconMime( m_pref->getDefaultIconMime() );
setDefaultIconData( m_pref->getDefaultIconData() );
}
/*
* Handle the hide default icon change signal
*/
void SysTrayXStatusNotifier::slotHideDefaultIconChange()
{
setHideDefaultIcon( m_pref->getHideDefaultIcon() );
}
/*
* Handle the icon type change signal
*/
void SysTrayXStatusNotifier::slotIconTypeChange()
{
setIconType( m_pref->getIconType() );
}
/*
* Handle the icon data change signal
*/
void SysTrayXStatusNotifier::slotIconDataChange()
{
setIconMime( m_pref->getIconMime() );
setIconData( m_pref->getIconData() );
}
/*
* Handle the enable number state change signal
*/
void SysTrayXStatusNotifier::slotShowNumberChange()
{
showNumber( m_pref->getShowNumber() );
}
/*
* Handle the number color change signal
*/
void SysTrayXStatusNotifier::slotNumberColorChange()
{
setNumberColor( m_pref->getNumberColor() );
}
/*
* Handle the number size change signal
*/
void SysTrayXStatusNotifier::slotNumberSizeChange()
{
setNumberSize( m_pref->getNumberSize() );
}
/*
* Handle activate request of the notification icon
*/
void SysTrayXStatusNotifier::slotActivateRequested( bool active, const QPoint &pos )
{
Q_UNUSED( active )
Q_UNUSED( pos )
emit signalShowHide();
}
/*
* Handle secondary activate request of the notification icon
*/
void SysTrayXStatusNotifier::slotSecondaryActivateRequested( const QPoint &pos )
{
Q_UNUSED( pos )
emit signalShowHide();
}
#endif

View File

@@ -0,0 +1,272 @@
#include <QtGlobal>
#if defined( Q_OS_UNIX ) && defined( KDE_INTEGRATION )
#ifndef SYSTRAYXSTATUSNOTIFIER_H
#define SYSTRAYXSTATUSNOTIFIER_H
/*
* Local includes
*/
#include "preferences.h"
/*
* Qt includes
*/
#include <KStatusNotifierItem>
/*
* Predefines
*/
class SysTrayXLink;
/**
* @brief The SysTrayXStatusNotifier class. The system tray icon.
*/
class SysTrayXStatusNotifier : public KStatusNotifierItem
{
Q_OBJECT
public:
/**
* @brief SysTrayXStatusNotifier. Constructor.
*
* @param parent My parent.
*/
SysTrayXStatusNotifier( SysTrayXLink* link, Preferences* pref, QObject* parent = nullptr );
/**
* @brief setDefaultIconType. Set the sytem tray default icon type.
*
* @param icon_type The icon type
*/
void setDefaultIconType( Preferences::DefaultIconType icon_type );
/**
* @brief setDefaultIconMime. Set the sytem tray icon mime.
*
* @param icon_mime The icon mime
*/
void setDefaultIconMime( const QString& icon_mime );
/**
* @brief setDefaultIconData. Set the custom icon data.
*
* @param icon_data The icon data.
*/
void setDefaultIconData( const QByteArray& icon_data );
/**
* @brief setHideDefaultIcon. Set hide default icon.
*
* @param hide The state
*/
void setHideDefaultIcon( bool hide );
/**
* @brief setIconType. Set the sytem tray icon type.
*
* @param icon_type The icon type
*/
void setIconType( Preferences::IconType icon_type );
/**
* @brief setIconMime. Set the sytem tray icon mime.
*
* @param icon_mime The icon mime
*/
void setIconMime( const QString& icon_mime );
/**
* @brief setIconData. Set the custom icon data.
*
* @param icon_data The icon data.
*/
void setIconData( const QByteArray& icon_data );
/**
* @brief showNumber. Set the show number state.
*
* @param state Show / hide.
*/
void showNumber( bool state );
/**
* @brief setNumberColor. Set the number color.
*
* @param color The color.
*/
void setNumberColor( const QString& color );
/**
* @brief setNumberSize. Set the number size.
*
* @param size The size.
*/
void setNumberSize( int size );
/**
* @brief setUnreadMail. Set the number of unread mails.
*
* @param unread_mail The number of unread mails.
*/
void setUnreadMail( int unread_mail );
private:
/**
* @brief setIcon. Set a new rendered icon.
*/
void renderIcon();
/**
* @brief showIcon. Show the icon.
*/
void showIcon();
signals:
/**
* @brief signalShowHide. Signal show / hide window.
*/
void signalShowHide();
public slots:
/**
* @brief slotSetUnreadMail. Slot for handling unread mail signals.
*
* @param unread_mail The number of unread mails.
*/
void slotSetUnreadMail( int unread_mail );
/**
* @brief slotDefaultIconTypeChange. Slot for handling default icon type change signals.
*/
void slotDefaultIconTypeChange();
/**
* @brief slotDefaultIconDataChange. Slot for handling default icon data change signals.
*/
void slotDefaultIconDataChange();
/**
* @brief slotHideDefaultIconChange. Slot for handling hide default icon change signals.
*/
void slotHideDefaultIconChange();
/**
* @brief slotIconTypeChange. Slot for handling icon type change signals.
*/
void slotIconTypeChange();
/**
* @brief slotIconDataChange. Slot for handling icon data change signals.
*/
void slotIconDataChange();
/**
* @brief slotShowNumberChange. Slot for handling show number change signals.
*/
void slotShowNumberChange();
/**
* @brief slotNumberColorChange. Slot for handling number color change signals.
*/
void slotNumberColorChange();
/**
* @brief slotNumberSizeChange. Slot for handling number size change signals.
*/
void slotNumberSizeChange();
private slots:
/**
* @brief slotActivateRequested. Handle a activate request of the notifier.
*
* @param active Window request show / hide.
* @param pos Click position.
*/
void slotActivateRequested( bool active, const QPoint &pos );
/**
* @brief slotSecondaryActivateRequested. Handle a secondary activate request of the notifier.
*
* @param pos Click position.
*/
void slotSecondaryActivateRequested( const QPoint &pos );
private:
/**
* @brief m_link. Pointer to the link.
*/
SysTrayXLink* m_link;
/**
* @brief m_pref Pointer to the preferences storage.
*/
Preferences* m_pref;
/**
* @brief m_default_icon_type. Storage for the default icon type.
*/
Preferences::DefaultIconType m_default_icon_type;
/**
* @brief m_default_icon_mime. Storage for the default icon mime.
*/
QString m_default_icon_mime;
/**
* @brief m_default_icon_data. Storage for the default icon.
*/
QByteArray m_default_icon_data;
/**
* @brief m_hide_default_icon. Storage for the hide default icon state.
*/
bool m_hide_default_icon;
/**
* @brief m_icon_type. Storage for the icon type.
*/
Preferences::IconType m_icon_type;
/**
* @brief m_icon_mime. Storage for the icon mime.
*/
QString m_icon_mime;
/**
* @brief m_icon_data. Storage for the icon.
*/
QByteArray m_icon_data;
/**
* @brief m_show_number. Show the unread mail count.
*/
bool m_show_number;
/**
* @brief m_number_color. Color of the unread mail number.
*/
QString m_number_color;
/**
* @brief m_number_size. Size of the unread mail number.
*/
int m_number_size;
/**
* @brief m_unread_mail. Storage for the number of unread mails.
*/
int m_unread_mail;
};
#endif // SYSTRAYXSTATUSNOTIFIER_H
#endif

View File

@@ -68,6 +68,8 @@ void WindowCtrl::slotWindowTest1()
// Do something.
// signalHideDefaultIconChange( true );
// emit signalShow();
// emit signalConsole( QString( "Found Ppid: %1" ).arg( getPpid() ) );
@@ -91,6 +93,8 @@ void WindowCtrl::slotWindowTest2()
// Do something.
// signalHideDefaultIconChange( false );
// emit signalHide();
// hideWindow( getWinId(), true );

View File

@@ -49,8 +49,10 @@ class WindowCtrl : public QObject
signals:
void signalShow();
void signalHide();
// void signalShow();
// void signalHide();
void signalHideDefaultIconChange(bool hide );
public slots:

View File

@@ -2,7 +2,7 @@ Source: systray-x-gnome
Section: misc
Priority: optional
Maintainer: Maxime Rijnders <ximi.obs@gmail.com>
Build-Depends: debhelper (>= 4.1.16), zip, qt5-default, qtbase5-dev, thunderbird
Build-Depends: debhelper (>= 4.1.16), zip, qt5-default, qtbase5-dev, qdbus-qt5, libkf5notifications-dev, thunderbird
Package: systray-x-gnome
Architecture: any

View File

@@ -34,7 +34,7 @@ build-stamp:
# Add here commands to compile the package.
sed < app/config/linux/SysTray_X.json.template -e 's|SYSTRAY_X_PATH|/usr/bin/SysTray-X|' > SysTray_X.json
make EXT_VERSION="DEFINES+=EXT_VERSION DEFINES+=APP_VERSION_MAJOR=\\\\\\\\\\\\\\\"$(VERSION_MAJOR)\\\\\\\\\\\\\\\" DEFINES+=APP_VERSION_MINOR=\\\\\\\\\\\\\\\"$(VERSION_MINOR)\\\\\\\\\\\\\\\" DEFINES+=APP_VERSION_PATCH=\\\\\\\\\\\\\\\"$(VERSION_PATCH)\\\\\\\\\\\\\\\" DEFINES+=APP_BUILD=\\\\\\\\\\\\\\\"$(BUILD_NUMBER)\\\\\\\\\\\\\\\" DEFINES+=APP_GITHASH=\\\\\\\\\\\\\\\"$(GIT_HASH)\\\\\\\\\\\\\\\" DEFINES+=APP_GITBRANCH=\\\\\\\\\\\\\\\"$(GIT_BRANCH)\\\\\\\\\\\\\\\""
make OPTIONS="DEFINES+=NO_KDE_INTEGRATION" EXT_VERSION="DEFINES+=EXT_VERSION DEFINES+=APP_VERSION_MAJOR=\\\\\\\\\\\\\\\"$(VERSION_MAJOR)\\\\\\\\\\\\\\\" DEFINES+=APP_VERSION_MINOR=\\\\\\\\\\\\\\\"$(VERSION_MINOR)\\\\\\\\\\\\\\\" DEFINES+=APP_VERSION_PATCH=\\\\\\\\\\\\\\\"$(VERSION_PATCH)\\\\\\\\\\\\\\\" DEFINES+=APP_BUILD=\\\\\\\\\\\\\\\"$(BUILD_NUMBER)\\\\\\\\\\\\\\\" DEFINES+=APP_GITHASH=\\\\\\\\\\\\\\\"$(GIT_HASH)\\\\\\\\\\\\\\\" DEFINES+=APP_GITBRANCH=\\\\\\\\\\\\\\\"$(GIT_BRANCH)\\\\\\\\\\\\\\\""
# --- end custom part for compiling

View File

@@ -4,4 +4,4 @@ Version: 0
Binary: systray-x-gnome
Maintainer: Maxime Rijnders <ximi.obs@gmail.com>
Architecture: any
Build-Depends: debhelper (>= 4.1.16), zip, qt5-default, qtbase5-dev, thunderbird
Build-Depends: debhelper (>= 4.1.16), zip, qt5-default, qtbase5-dev, qdbus-qt5, libkf5notifications-dev, thunderbird

View File

@@ -2,7 +2,7 @@ Source: systray-x
Section: misc
Priority: optional
Maintainer: Maxime Rijnders <ximi.obs@gmail.com>
Build-Depends: debhelper (>= 4.1.16), zip, qt5-default, qtbase5-dev, thunderbird
Build-Depends: debhelper (>= 4.1.16), zip, qt5-default, qtbase5-dev, qdbus-qt5, libkf5notifications-dev, thunderbird
Package: systray-x
Architecture: any

View File

@@ -4,4 +4,4 @@ Version: 0
Binary: SysTray-X
Maintainer: Maxime Rijnders <ximi.obs@gmail.com>
Architecture: any
Build-Depends: debhelper (>= 4.1.16), zip, qt5-default, qtbase5-dev, thunderbird
Build-Depends: debhelper (>= 4.1.16), zip, qt5-default, qtbase5-dev, qdbus-qt5, libkf5notifications-dev, thunderbird

View File

@@ -28,12 +28,15 @@ BuildRequires: unzip
BuildRequires: zip
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Widgets)
BuildRequires: pkgconfig(Qt5DBus)
BuildRequires: pkgconfig(x11)
Requires: gnome-shell-extension-appindicator
%if 0%{?fedora_version}
BuildRequires: kf5-knotifications-devel
Requires: qt5-qtwayland
Requires: thunderbird >= 68
%else
BuildRequires: knotifications-devel
Requires: MozillaThunderbird >= 68
%endif
@@ -65,7 +68,7 @@ export BUILD_NUMBER=`cat %{S:1} | grep BUILD_NUMBER | sed -e "s/BUILD_NUMBER=\(.
export GIT_HASH=`cat %{S:1} | grep GIT_HASH | sed -e "s/GIT_HASH=\(.*\)/\1/"`
export GIT_BRANCH=`cat %{S:1} | grep GIT_BRANCH | sed -e "s/GIT_BRANCH=\(.*\)/\1/"`
make %{?_smp_mflags} EXT_VERSION="DEFINES+=EXT_VERSION DEFINES+=APP_VERSION_MAJOR=\\\\\\\\\\\\\\\"$VERSION_MAJOR\\\\\\\\\\\\\\\" DEFINES+=APP_VERSION_MINOR=\\\\\\\\\\\\\\\"$VERSION_MINOR\\\\\\\\\\\\\\\" DEFINES+=APP_VERSION_PATCH=\\\\\\\\\\\\\\\"$VERSION_PATCH\\\\\\\\\\\\\\\" DEFINES+=APP_BUILD=\\\\\\\\\\\\\\\"$BUILD_NUMBER\\\\\\\\\\\\\\\" DEFINES+=APP_GITHASH=\\\\\\\\\\\\\\\"$GIT_HASH\\\\\\\\\\\\\\\" DEFINES+=APP_GITBRANCH=\\\\\\\\\\\\\\\"$GIT_BRANCH\\\\\\\\\\\\\\\""
make %{?_smp_mflags} OPTIONS="DEFINES+=NO_KDE_INTEGRATION" EXT_VERSION="DEFINES+=EXT_VERSION DEFINES+=APP_VERSION_MAJOR=\\\\\\\\\\\\\\\"$VERSION_MAJOR\\\\\\\\\\\\\\\" DEFINES+=APP_VERSION_MINOR=\\\\\\\\\\\\\\\"$VERSION_MINOR\\\\\\\\\\\\\\\" DEFINES+=APP_VERSION_PATCH=\\\\\\\\\\\\\\\"$VERSION_PATCH\\\\\\\\\\\\\\\" DEFINES+=APP_BUILD=\\\\\\\\\\\\\\\"$BUILD_NUMBER\\\\\\\\\\\\\\\" DEFINES+=APP_GITHASH=\\\\\\\\\\\\\\\"$GIT_HASH\\\\\\\\\\\\\\\" DEFINES+=APP_GITBRANCH=\\\\\\\\\\\\\\\"$GIT_BRANCH\\\\\\\\\\\\\\\""
sed < app/config/linux/SysTray_X.json.template -e 's|SYSTRAY_X_PATH|%{_bindir}/SysTray-X|' > SysTray_X.json

View File

@@ -28,11 +28,14 @@ BuildRequires: unzip
BuildRequires: zip
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Widgets)
BuildRequires: pkgconfig(Qt5DBus)
BuildRequires: pkgconfig(x11)
%if 0%{?fedora_version}
BuildRequires: kf5-knotifications-devel
Requires: qt5-qtwayland
Requires: thunderbird >= 68
%else
BuildRequires: knotifications-devel
Requires: MozillaThunderbird >= 68
%endif

View File

@@ -3,6 +3,8 @@ var SysTrayX = {
startupState: undefined,
hideDefaultIcon: false,
platformInfo: undefined,
browserInfo: undefined,
@@ -31,6 +33,9 @@ SysTrayX.Messaging = {
// Send version to app
SysTrayX.Messaging.sendVersion();
// Send hide default icon preference
SysTrayX.Messaging.sendHideDefaultIcon();
// Send preferences to app
SysTrayX.Messaging.sendPreferences();
@@ -137,6 +142,12 @@ SysTrayX.Messaging = {
SysTrayX.Link.postSysTrayXMessage({ version: SysTrayX.version });
},
sendHideDefaultIcon: function () {
SysTrayX.Link.postSysTrayXMessage({
hideDefaultIcon: SysTrayX.hideDefaultIcon,
});
},
sendPreferences: function () {
const getter = browser.storage.sync.get([
"debug",
@@ -146,6 +157,7 @@ SysTrayX.Messaging = {
"defaultIconType",
"defaultIconMime",
"defaultIcon",
"hideDefaultIcon",
"iconType",
"iconMime",
"icon",
@@ -165,6 +177,7 @@ SysTrayX.Messaging = {
const defaultIconType = result.defaultIconType || "0";
const defaultIconMime = result.defaultIconMime || "image/png";
const defaultIcon = result.defaultIcon || [];
const hideDefaultIcon = result.hideDefaultIcon || "false";
const iconType = result.iconType || "0";
const iconMime = result.iconMime || "image/png";
const icon = result.icon || [];
@@ -183,6 +196,7 @@ SysTrayX.Messaging = {
defaultIconType: defaultIconType,
defaultIconMime: defaultIconMime,
defaultIcon: defaultIcon,
hideDefaultIcon: hideDefaultIcon,
iconType: iconType,
iconMime: iconMime,
icon: icon,
@@ -256,6 +270,13 @@ SysTrayX.Link = {
SysTrayX.Link.postSysTrayXMessage({ shutdown: "true" });
}
const kdeIntegration = response["kdeIntegration"];
if (kdeIntegration) {
browser.storage.sync.set({
kdeIntegration: kdeIntegration,
});
}
if (response["preferences"]) {
// Store the preferences from the app
const defaultIconMime = response["preferences"].defaultIconMime;
@@ -279,6 +300,13 @@ SysTrayX.Link = {
});
}
const hideDefaultIcon = response["preferences"].hideDefaultIcon;
if (hideDefaultIcon) {
browser.storage.sync.set({
hideDefaultIcon: hideDefaultIcon,
});
}
const iconMime = response["preferences"].iconMime;
if (iconMime) {
browser.storage.sync.set({
@@ -391,6 +419,10 @@ async function start() {
);
}
// Hide the default icon
const hideDefaultIcon = await getHideDefaultIcon();
SysTrayX.hideDefaultIcon = hideDefaultIcon;
// Set platform
SysTrayX.platformInfo = await browser.runtime
.getPlatformInfo()
@@ -424,6 +456,11 @@ async function start() {
browserInfo: SysTrayX.browserInfo,
});
// Reset KDE integration
browser.storage.sync.set({
kdeIntegration: true,
});
// Get addon version
SysTrayX.version = browser.runtime.getManifest().version;
console.log("Addon version: " + SysTrayX.version);

View File

@@ -146,6 +146,26 @@ async function getMinimizeOnClose() {
);
}
//
// Get KDE integration, default icon hide
//
async function getHideDefaultIcon() {
function getHideDefaultIconPref(result) {
const hideDefaultIcon = result.hideDefaultIcon || "false";
return hideDefaultIcon === "true";
}
function onHideDefaultIconPrefError() {
return false;
}
const getState = browser.storage.sync.get("hideDefaultIcon");
return await getState.then(
getHideDefaultIconPref,
onHideDefaultIconPrefError
);
}
// Check if the filters are for existing accounts
function checkAccountFilters(filters) {
let filtersChanged = false;

View File

@@ -35,7 +35,7 @@
<h3>Windows</h3>
<table id="minimizeselect">
<caption>
Minimize type
Minimize
</caption>
<tr id="minimizedefault">
<td>
@@ -86,7 +86,8 @@
</tr>
<tr>
<td>
<input type="radio" name="defaultIconType" value="1" /> Hide icon
<input type="radio" name="defaultIconType" value="1" />
Lookthrough icon
</td>
</tr>
<tr>
@@ -123,6 +124,11 @@
</tr>
</table>
<div id="kdeintegration">
<input type="checkbox" name="hideDefaultIcon" value="" /> KDE
integration (Hide)<br />
</div>
<table id="iconselect">
<caption>
Unread mail icon

View File

@@ -109,6 +109,16 @@ SysTrayX.SaveOptions = {
defaultIcon: defaultIconBase64,
});
//
// Save hide default icon state
//
let hideDefaultIcon = document.querySelector(
'input[name="hideDefaultIcon"]'
).checked;
browser.storage.sync.set({
hideDefaultIcon: `${hideDefaultIcon}`,
});
//
// Save icon preferences
//
@@ -234,6 +244,18 @@ SysTrayX.RestoreOptions = {
SysTrayX.RestoreOptions.onDefaultIconError
);
//
// Restore hide default icon
//
const getHideDefaultIcon = browser.storage.sync.get([
"kdeIntegration",
"hideDefaultIcon",
]);
getHideDefaultIcon.then(
SysTrayX.RestoreOptions.setHideDefaultIcon,
SysTrayX.RestoreOptions.onHideDefaultIconError
);
//
// Restore icon type
//
@@ -452,6 +474,26 @@ SysTrayX.RestoreOptions = {
console.log(`Default icon Error: ${error}`);
},
//
// Restore hide default icon callbacks
//
setHideDefaultIcon: function (result) {
const kdeIntegration = result.kdeIntegration || "true";
const hideDefaultIcon = result.hideDefaultIcon || "false";
const checkbox = document.querySelector(`input[name="hideDefaultIcon"]`);
if (kdeIntegration === "false") {
checkbox.parentNode.setAttribute("style", "display: none;");
}
checkbox.checked = hideDefaultIcon === "true";
},
onHideDefaultIconError: function (error) {
console.log(`hideDefaultIcon Error: ${error}`);
},
//
// Restore icon
//
@@ -677,6 +719,11 @@ SysTrayX.StorageChanged = {
defaultIconType: changes[item].newValue,
});
}
if (item === "hideDefaultIcon") {
SysTrayX.RestoreOptions.setHideDefaultIcon({
hideDefaultIcon: changes[item].newValue,
});
}
if (item === "showNumber") {
SysTrayX.RestoreOptions.setShowNumber({
showNumber: changes[item].newValue,