00001
00034 #include "desktopalarmwidgetqt.h"
00035
00036 #include <QAction>
00037 #include <QMenu>
00038
00039 using namespace AlarmNotifications;
00040
00041 DesktopAlarmWidgetQt::DesktopAlarmWidgetQt()
00042 : DesktopAlarmWidget ( getBeedoActivated() ),
00043 _trayicon ( this ),
00044 _contextmenu ( nullptr ),
00045 _toggleAction ( nullptr ),
00046 _exitAction ( nullptr )
00047 {
00048 setStatusIcon ( ActiveOK );
00049 _trayicon.setToolTip ( QString::fromUtf8 ( "AlarmNotifications Desktop Widget" ) );
00050 createContextMenu();
00051 connect ( &_trayicon, SIGNAL ( activated ( QSystemTrayIcon::ActivationReason ) ), this, SLOT ( activated ( QSystemTrayIcon::ActivationReason ) ) );
00052 }
00053
00054 DesktopAlarmWidgetQt::~DesktopAlarmWidgetQt()
00055 {
00056
00057 }
00058
00059 void DesktopAlarmWidgetQt::setStatusIcon ( DesktopAlarmWidget::DesktopAlarmWidgetStatus status )
00060 {
00061 switch ( status )
00062 {
00063 case ActiveOK:
00064 _trayicon.setIcon ( QIcon ( QString::fromUtf8 ( ":/icons/activeok.png" ) ) );
00065 break;
00066 case ActiveAlarm:
00067 _trayicon.setIcon ( QIcon ( QString::fromUtf8 ( ":/icons/activealarm.png" ) ) );
00068 break;
00069 case Disabled:
00070 default:
00071 _trayicon.setIcon ( QIcon ( QString::fromUtf8 ( ":/icons/disabled.png" ) ) );
00072 break;
00073 }
00074 }
00075
00076 void DesktopAlarmWidgetQt::createContextMenu()
00077 {
00078 _contextmenu = new QMenu ( QString::fromUtf8 ( "Desktop Alarm Notifications" ), nullptr );
00079 _toggleAction = _contextmenu->addAction (
00080 QIcon ( QString::fromUtf8 ( ":/icons/disable.png" ) ),
00081 QString::fromUtf8 ( "Disable ¬ifications" ),
00082 this,
00083 SLOT ( toggleNotifications() )
00084 );
00085 _configureAction = _contextmenu->addAction (
00086 QIcon ( QString::fromUtf8 ( ":/icons/configure.png" ) ),
00087 QString::fromUtf8 ( "&Configure notification timeout" ),
00088 this,
00089 SLOT ( configureNotificationTimeout() )
00090 );
00091 _exitAction = _contextmenu->addAction (
00092 QIcon ( QString::fromUtf8 ( ":/icons/exit.png" ) ),
00093 QString::fromUtf8 ( "&Exit desktop alarm widget" ),
00094 this,
00095 SLOT ( exitApplication() )
00096 );
00097 _trayicon.setContextMenu ( _contextmenu );
00098 _trayicon.show();
00099 }
00100
00101 void DesktopAlarmWidgetQt::activated ( const QSystemTrayIcon::ActivationReason reason )
00102 {
00103 if ( reason != QSystemTrayIcon::Trigger )
00104 return;
00105 showStatusMessage();
00106 }
00107
00108 void DesktopAlarmWidgetQt::notificationSwitchChange ( bool enabled )
00109 {
00110 if ( enabled )
00111 {
00112 _toggleAction->setIcon ( QIcon ( QString::fromUtf8 ( ":/icons/disable.png" ) ) );
00113 _toggleAction->setText ( QString::fromUtf8 ( "Disable ¬ifications" ) );
00114 setStatusIcon ( ActiveOK );
00115 }
00116 else
00117 {
00118 _toggleAction->setIcon ( QIcon ( QString::fromUtf8 ( ":/icons/enable.png" ) ) );
00119 _toggleAction->setText ( QString::fromUtf8 ( "Enable ¬ifications" ) );
00120 setStatusIcon ( Disabled );
00121 }
00122 }
00123
00124 void DesktopAlarmWidgetQt::changeTrayIcon()
00125 {
00126 if ( getAlarmActive() )
00127 setStatusIcon ( ActiveAlarm );
00128 else
00129 setStatusIcon ( ActiveOK );
00130 }
00131
00132 bool DesktopAlarmWidgetQt::getBeedoActivated() noexcept
00133 {
00134 #ifndef BEEDO
00135 return false;
00136 #else
00137 return true;
00138 #endif
00139 }
00140
00141 #include "desktopalarmwidgetqt.moc"