add support for a system tray icon for the server

This commit is contained in:
Volker Fischer 2011-05-06 20:18:20 +00:00
parent ef661255a4
commit f5120f272a
8 changed files with 92 additions and 31 deletions

View file

@ -29,7 +29,10 @@
CLlconServerDlg::CLlconServerDlg ( CServer* pNServP,
QWidget* parent,
Qt::WindowFlags f )
: QDialog ( parent, f ), pServer ( pNServP )
: QDialog ( parent, f ),
pServer ( pNServP ),
BitmapSystemTrayInactive ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDGreyArrow.png" ) ),
BitmapSystemTrayActive ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDGreenArrow.png" ) )
{
setupUi ( this );
@ -102,6 +105,31 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP,
"Country where the server is located combo box" ) );
// check if system tray icon can be used
bSystemTrayIconAvaialbe = SystemTrayIcon.isSystemTrayAvailable();
// init system tray icon
if ( bSystemTrayIconAvaialbe )
{
// prepare context menu to be added to the system tray icon
pSystemTrayIconMenu = new QMenu ( this );
pSystemTrayIconMenu->addAction ( tr ( "E&xit" ),
this, SLOT ( OnSysTrayMenuExit() ) );
pSystemTrayIconMenu->addSeparator();
pSystemTrayIconMenu->setDefaultAction ( pSystemTrayIconMenu->addAction (
tr ( "&Open " ) + APP_NAME + tr ( " server" ),
this, SLOT ( OnSysTrayMenuOpen() ) ) );
SystemTrayIcon.setContextMenu ( pSystemTrayIconMenu );
// show icon of state "inactive"
SystemTrayIcon.setIcon ( QIcon ( BitmapSystemTrayInactive ) );
SystemTrayIcon.show();
}
// set text for version and application name
TextLabelNameVersion->setText ( QString ( APP_NAME ) +
tr ( " server " ) + QString ( VERSION ) );
@ -210,6 +238,13 @@ CLlconServerDlg::CLlconServerDlg ( CServer* pNServP,
// timers
QObject::connect ( &Timer, SIGNAL ( timeout() ), this, SLOT ( OnTimer() ) );
// other
QObject::connect ( pServer, SIGNAL ( Started() ),
this, SLOT ( OnServerStarted() ) );
QObject::connect ( pServer, SIGNAL ( Stopped() ),
this, SLOT ( OnServerStopped() ) );
// Timers ------------------------------------------------------------------
// start timer for GUI controls
@ -381,6 +416,34 @@ void CLlconServerDlg::UpdateGUIDependencies()
!bCurUseDefCentServAddr && bCurSerListEnabled );
}
void CLlconServerDlg::UpdateSystemTrayIcon ( const bool bIsActive )
{
if ( bSystemTrayIconAvaialbe )
{
if ( bIsActive )
{
SystemTrayIcon.setIcon ( QIcon ( BitmapSystemTrayActive ) );
}
else
{
SystemTrayIcon.setIcon ( QIcon ( BitmapSystemTrayInactive ) );
}
}
}
void CLlconServerDlg::hideEvent ( QHideEvent* )
{
// TODO seems not to work correctly...
/*
// if we have a system tray icon, we make the window invisible if it is
// minimized
if ( bSystemTrayIconAvaialbe )
{
setVisible ( false );
}
*/
}
void CLlconServerDlg::customEvent ( QEvent* Event )
{
if ( Event->type() == QEvent::User + 11 )

View file

@ -30,6 +30,7 @@
#include <qslider.h>
#include <qmenubar.h>
#include <qlayout.h>
#include <qsystemtrayicon.h>
#include "global.h"
#include "server.h"
#include "multicolorled.h"
@ -60,6 +61,11 @@ public:
Qt::WindowFlags f = 0 );
protected:
virtual void customEvent ( QEvent* Event );
virtual void hideEvent ( QHideEvent* );
void UpdateGUIDependencies();
void UpdateSystemTrayIcon ( const bool bIsActive );
QTimer Timer;
CServer* pServer;
@ -68,8 +74,11 @@ protected:
QMenuBar* pMenu;
virtual void customEvent ( QEvent* Event );
void UpdateGUIDependencies();
bool bSystemTrayIconAvaialbe;
QSystemTrayIcon SystemTrayIcon;
QPixmap BitmapSystemTrayInactive;
QPixmap BitmapSystemTrayActive;
QMenu* pSystemTrayIconMenu;
public slots:
void OnRegisterServerStateChanged ( int value );
@ -79,4 +88,8 @@ public slots:
void OnLineEditLocationCityTextChanged ( const QString& strNewCity );
void OnComboBoxLocationCountryActivated ( int iCntryListItem );
void OnTimer();
void OnServerStarted() { UpdateSystemTrayIcon ( true ); }
void OnServerStopped() { UpdateSystemTrayIcon ( false ); }
void OnSysTrayMenuOpen() { showNormal(); raise(); }
void OnSysTrayMenuExit() { close(); }
};

View file

@ -134,7 +134,7 @@ void CMultiColorLEDBar::setValue ( const int value )
}
CMultiColorLEDBar::cLED::cLED ( QWidget* parent ) :
BitmCubeRoundDisabled ( QString::fromUtf8 ( ":/png/LEDs/res/VLEDDisabledSmall.png" ) ),
BitmCubeRoundDisabled ( QString::fromUtf8 ( ":/png/LEDs/res/CLEDDisabledSmall.png" ) ),
BitmCubeRoundGrey ( QString::fromUtf8 ( ":/png/LEDs/res/HLEDGreySmall.png" ) ),
BitmCubeRoundGreen ( QString::fromUtf8 ( ":/png/LEDs/res/HLEDGreenSmall.png" ) ),
BitmCubeRoundYellow ( QString::fromUtf8 ( ":/png/LEDs/res/HLEDYellowSmall.png" ) ),

BIN
src/res/CLEDGreenArrow.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
src/res/CLEDGreyArrow.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -1,41 +1,16 @@
<RCC>
<qresource prefix="/png/LEDs" >
<file>res/CLEDBlack.png</file>
<file>res/CLEDBlackSmall.png</file>
<file>res/CLEDDisabledSmall.png</file>
<file>res/CLEDGreen.png</file>
<file>res/CLEDGreenArrow.png</file>
<file>res/CLEDGreenSmall.png</file>
<file>res/CLEDGrey.png</file>
<file>res/CLEDGreyArrow.png</file>
<file>res/CLEDGreySmall.png</file>
<file>res/CLEDRed.png</file>
<file>res/CLEDRedSmall.png</file>
<file>res/CLEDYellow.png</file>
<file>res/CLEDYellowSmall.png</file>
<file>res/HLEDGreenSmall.png</file>
<file>res/HLEDGreySmall.png</file>
<file>res/HLEDRedSmall.png</file>
<file>res/HLEDYellowSmall.png</file>
<file>res/VLEDBlack.png</file>
<file>res/VLEDBlackSmall.png</file>
<file>res/VLEDDisabledSmall.png</file>
<file>res/VLEDGreen.png</file>
<file>res/VLEDGreenSmall.png</file>
<file>res/VLEDGrey.png</file>
<file>res/VLEDGreySmall.png</file>
<file>res/VLEDRed.png</file>
<file>res/VLEDRedSmall.png</file>
<file>res/VLEDYellow.png</file>
<file>res/VLEDYellowSmall.png</file>
<file>res/VRLEDBlack.png</file>
<file>res/VRLEDBlackSmall.png</file>
<file>res/VRLEDGreen.png</file>
<file>res/VRLEDGreenSmall.png</file>
<file>res/VRLEDGrey.png</file>
<file>res/VRLEDGreySmall.png</file>
<file>res/VRLEDRed.png</file>
<file>res/VRLEDRedSmall.png</file>
<file>res/VRLEDYellow.png</file>
<file>res/VRLEDYellowSmall.png</file>
</qresource>
<qresource prefix="/png/fader" >
<file>res/faderbackground.png</file>

View file

@ -415,6 +415,9 @@ void CServer::Start()
// init time for response time evaluation
CycleTimeVariance.Reset();
// emit start signal
emit Started();
}
}
@ -431,6 +434,9 @@ void CServer::Stop()
// logging (add "server stopped" logging entry)
Logging.AddServerStopped();
// emit stopped signal
emit Stopped();
}
}

View file

@ -224,6 +224,10 @@ protected:
// server list
CServerListManager ServerListManager;
signals:
void Started();
void Stopped();
public slots:
void OnTimer();
void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage );