diff --git a/src/llconserverdlg.cpp b/src/llconserverdlg.cpp index bdef1713..07bc3922 100755 --- a/src/llconserverdlg.cpp +++ b/src/llconserverdlg.cpp @@ -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 ) diff --git a/src/llconserverdlg.h b/src/llconserverdlg.h index 68d5d1cd..9f02a912 100755 --- a/src/llconserverdlg.h +++ b/src/llconserverdlg.h @@ -30,6 +30,7 @@ #include #include #include +#include #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(); } }; diff --git a/src/multicolorledbar.cpp b/src/multicolorledbar.cpp index 97bed5c8..192c48ee 100755 --- a/src/multicolorledbar.cpp +++ b/src/multicolorledbar.cpp @@ -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" ) ), diff --git a/src/res/CLEDGreenArrow.png b/src/res/CLEDGreenArrow.png new file mode 100755 index 00000000..7307ba37 Binary files /dev/null and b/src/res/CLEDGreenArrow.png differ diff --git a/src/res/CLEDGreyArrow.png b/src/res/CLEDGreyArrow.png new file mode 100755 index 00000000..0c6e7b54 Binary files /dev/null and b/src/res/CLEDGreyArrow.png differ diff --git a/src/resources.qrc b/src/resources.qrc index 10a6c65e..18f3a77b 100755 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -1,41 +1,16 @@ - res/CLEDBlack.png - res/CLEDBlackSmall.png res/CLEDDisabledSmall.png - res/CLEDGreen.png + res/CLEDGreenArrow.png res/CLEDGreenSmall.png - res/CLEDGrey.png + res/CLEDGreyArrow.png res/CLEDGreySmall.png - res/CLEDRed.png res/CLEDRedSmall.png - res/CLEDYellow.png res/CLEDYellowSmall.png res/HLEDGreenSmall.png res/HLEDGreySmall.png res/HLEDRedSmall.png res/HLEDYellowSmall.png - res/VLEDBlack.png - res/VLEDBlackSmall.png - res/VLEDDisabledSmall.png - res/VLEDGreen.png - res/VLEDGreenSmall.png - res/VLEDGrey.png - res/VLEDGreySmall.png - res/VLEDRed.png - res/VLEDRedSmall.png - res/VLEDYellow.png - res/VLEDYellowSmall.png - res/VRLEDBlack.png - res/VRLEDBlackSmall.png - res/VRLEDGreen.png - res/VRLEDGreenSmall.png - res/VRLEDGrey.png - res/VRLEDGreySmall.png - res/VRLEDRed.png - res/VRLEDRedSmall.png - res/VRLEDYellow.png - res/VRLEDYellowSmall.png res/faderbackground.png diff --git a/src/server.cpp b/src/server.cpp index a56807bf..65b9d17a 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -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(); } } diff --git a/src/server.h b/src/server.h index 1eb18f2b..0b9a48d9 100755 --- a/src/server.h +++ b/src/server.h @@ -224,6 +224,10 @@ protected: // server list CServerListManager ServerListManager; +signals: + void Started(); + void Stopped(); + public slots: void OnTimer(); void OnSendProtMessage ( int iChID, CVector vecMessage );