AlarmNotifications
PANDA Slow Control Alarm Daemon
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
desktopalarmwidgetqt.cpp
Go to the documentation of this file.
1 
34 #include "desktopalarmwidgetqt.h"
35 
36 #include <QAction>
37 #include <QMenu>
38 
39 using namespace AlarmNotifications;
40 
42  : DesktopAlarmWidget ( getBeedoActivated() ),
43  _trayicon ( this ),
44  _contextmenu ( nullptr ),
45  _toggleAction ( nullptr ),
46  _exitAction ( nullptr )
47 {
49  _trayicon.setToolTip ( QString::fromUtf8 ( "AlarmNotifications Desktop Widget" ) );
51  connect ( &_trayicon, SIGNAL ( activated ( QSystemTrayIcon::ActivationReason ) ), this, SLOT ( activated ( QSystemTrayIcon::ActivationReason ) ) );
52 }
53 
55 {
56 
57 }
58 
60 {
61  switch ( status )
62  {
63  case ActiveOK:
64  _trayicon.setIcon ( QIcon ( QString::fromUtf8 ( ":/icons/activeok.png" ) ) );
65  break;
66  case ActiveAlarm:
67  _trayicon.setIcon ( QIcon ( QString::fromUtf8 ( ":/icons/activealarm.png" ) ) );
68  break;
69  case Disabled:
70  default:
71  _trayicon.setIcon ( QIcon ( QString::fromUtf8 ( ":/icons/disabled.png" ) ) );
72  break;
73  }
74 }
75 
77 {
78  _contextmenu = new QMenu ( QString::fromUtf8 ( "Desktop Alarm Notifications" ), nullptr );
79  _toggleAction = _contextmenu->addAction (
80  QIcon ( QString::fromUtf8 ( ":/icons/disable.png" ) ),
81  QString::fromUtf8 ( "Disable &notifications" ),
82  this,
83  SLOT ( toggleNotifications() )
84  );
85  _configureAction = _contextmenu->addAction (
86  QIcon ( QString::fromUtf8 ( ":/icons/configure.png" ) ),
87  QString::fromUtf8 ( "&Configure notification timeout" ),
88  this,
90  );
91  _exitAction = _contextmenu->addAction (
92  QIcon ( QString::fromUtf8 ( ":/icons/exit.png" ) ),
93  QString::fromUtf8 ( "&Exit desktop alarm widget" ),
94  this,
95  SLOT ( exitApplication() )
96  );
97  _trayicon.setContextMenu ( _contextmenu );
98  _trayicon.show();
99 }
100 
101 void DesktopAlarmWidgetQt::activated ( const QSystemTrayIcon::ActivationReason reason )
102 {
103  if ( reason != QSystemTrayIcon::Trigger )
104  return; // Only react on single click
106 }
107 
109 {
110  if ( enabled )
111  {
112  _toggleAction->setIcon ( QIcon ( QString::fromUtf8 ( ":/icons/disable.png" ) ) );
113  _toggleAction->setText ( QString::fromUtf8 ( "Disable &notifications" ) );
114  setStatusIcon ( ActiveOK ); // The newly generated AlarmServerConnector will have zero alarms...
115  }
116  else
117  {
118  _toggleAction->setIcon ( QIcon ( QString::fromUtf8 ( ":/icons/enable.png" ) ) );
119  _toggleAction->setText ( QString::fromUtf8 ( "Enable &notifications" ) );
121  }
122 }
123 
125 {
126  if ( getAlarmActive() )
128  else
130 }
131 
133 {
134 #ifndef BEEDO
135  return false;
136 #else
137  return true;
138 #endif
139 }
140 
141 #include "desktopalarmwidgetqt.moc"
void exitApplication()
Close the desktop widget.
void configureNotificationTimeout()
Change timespan between alarm trigger and notification display.
DesktopAlarmWidgetStatus
Status of the desktop widget.
void toggleNotifications()
Toggles the &quot;main switch&quot;.
QAction * _toggleAction
Context menu entry to toggle the desktop widget.
void activated(const QSystemTrayIcon::ActivationReason reason)
React on click on tray icon.
#define nullptr
Allow using the nullptr keyword with GCC &lt; 4.6.
Definition: oldgcccompat.h:56
Abstract base class for desktop alarm widgets.
virtual void notificationSwitchChange(bool enabled)
React on widget enable/disable.
bool getAlarmActive() const noexcept
Show alarm active flag to derived class.
void showStatusMessage()
Show status dialog box.
QAction * _exitAction
Context menu entry to close the application.
QSystemTrayIcon _trayicon
Tray icon object.
virtual void changeTrayIcon()
Change the tray icon due to status change.
void setStatusIcon(DesktopAlarmWidgetStatus status)
Adjust tray icon.
static bool getBeedoActivated() noexcept
Return compile-time Beedo activation flag.
QMenu * _contextmenu
Tray icon context menu.
QAction * _configureAction
Context menu entry to configure notification timeout.
Implementation if DesktopAlarmWidget for QSystemTrayIcon.
#define noexcept
Allow using the noexcept keyword with GCC &lt; 4.6.
Definition: oldgcccompat.h:52
virtual void createContextMenu()
Create context menu objects.