AlarmNotifications::DesktopAlarmWidget Class Reference

Abstract base class for desktop alarm widgets. More...

#include <desktopalarmwidget.h>

Inheritance diagram for AlarmNotifications::DesktopAlarmWidget:
Inheritance graph
[legend]
Collaboration diagram for AlarmNotifications::DesktopAlarmWidget:
Collaboration graph
[legend]

List of all members.

Public Types

enum  DesktopAlarmWidgetStatus { ActiveOK = 0, ActiveAlarm = 1, Disabled = 2 }
 

Status of the desktop widget.

More...

Signals

void alarmStatusChanged ()
 Alarm has been triggered or acknowledged.
void notificationSwitchChanged (bool enabled)
 Widget has been enabled or disabled.

Public Member Functions

 DesktopAlarmWidget (const bool activateBeedo=false)
 Constructor.
virtual ~DesktopAlarmWidget ()
 Destructor.
 DesktopAlarmWidget (const DesktopAlarmWidget &other)
 Copy constructor (deleted).
 DesktopAlarmWidget (DesktopAlarmWidget &&other)
 Move constructor (C++11, deleted).
DesktopAlarmWidgetoperator= (const DesktopAlarmWidget &other)
 Copy assignment (deleted).
DesktopAlarmWidgetoperator= (DesktopAlarmWidget &&other)
 Move assignment (C++11, deleted).

Protected Slots

void toggleNotifications ()
 Toggles the "main switch".
void exitApplication ()
 Close the desktop widget.
virtual void changeTrayIcon ()=0
 Change the tray icon due to status change.
void configureNotificationTimeout ()
 Change timespan between alarm trigger and notification display.
virtual void notificationSwitchChange (bool enabled)=0
 React on widget enable/disable.

Protected Member Functions

bool getAlarmActive () const noexcept
 Show alarm active flag to derived class.
DesktopAlarmWidgetStatus getStatus () const noexcept
 Query alarm status.
void showStatusMessage ()
 Show status dialog box.

Private Member Functions

virtual void createContextMenu ()=0
 Abstract context menu method.
void observeAlarmStatus ()
 Thread to periodically check the status.

Private Attributes

const bool _activateBeedo
 Beedo activation flag.
AlarmServerConnector_asc
 Pointer to the AlarmServerConnector instance.
bool _run
 Thread run flag.
bool _alarmActive
 Alarm flag.
QFuture< void > _iconThread
 Alarm status observer thread.
boost::mutex _ascmutex
 Protect access to the _asc pointer.

Detailed Description

Abstract base class for desktop alarm widgets.

This class provides most of the functionality for an application showing desktop notifications to the user when an alarm occurcs. The derived classes only have to provide the interface to the desktop environment to display a tray icon, status notifier item etc.

Definition at line 59 of file desktopalarmwidget.h.


Member Enumeration Documentation

Status of the desktop widget.

The current status can be queried from the derived class by calling getStatus(). This status is used e.g. to display the correct icon in the notification area.

Enumerator:
ActiveOK 

Widget active, status OK.

The desktop widget is active and no alarm is present

ActiveAlarm 

Widget active, status alarm.

The desktop widget is active and alarms are currently reported.

Disabled 

Widget inactive.

The desktop widet is inactive, the connection to the alarm server has been closed.

Definition at line 68 of file desktopalarmwidget.h.


Constructor & Destructor Documentation

DesktopAlarmWidget::DesktopAlarmWidget ( const bool  activateBeedo = false  ) 

Constructor.

Instanciates an initial instance of AlarmServerConnector and spawns the _iconThread running observeAlarmStatus().

Parameters:
activateBeedo Flag whether to use the Beedo engine

Definition at line 51 of file desktopalarmwidget.cpp.

DesktopAlarmWidget::~DesktopAlarmWidget (  )  [virtual]

Destructor.

Sets the _run flag to false and waits for _iconThread to finish.

Definition at line 65 of file desktopalarmwidget.cpp.

AlarmNotifications::DesktopAlarmWidget::DesktopAlarmWidget ( const DesktopAlarmWidget other  ) 

Copy constructor (deleted).

This class cannot be copied.

Parameters:
other Another instance of DesktopAlarmWidget
AlarmNotifications::DesktopAlarmWidget::DesktopAlarmWidget ( DesktopAlarmWidget &&  other  ) 

Move constructor (C++11, deleted).

This class cannot be moved.

Parameters:
other Another instance of DesktopAlarmWidget

Member Function Documentation

void AlarmNotifications::DesktopAlarmWidget::alarmStatusChanged (  )  [signal]

Alarm has been triggered or acknowledged.

This signal is fired by the observeAlarmStatus() method/thread to notify derived classes about a status change.

Returns:
Nothing
virtual void AlarmNotifications::DesktopAlarmWidget::changeTrayIcon (  )  [protected, pure virtual, slot]

Change the tray icon due to status change.

This slot is connected to the alarmStatusChanged() signal in the constructor of this abstract base class. Derived classes must implement their logic to change the tray icon here, so that the icon always represents the current status.

Returns:
Nothing

Implemented in AlarmNotifications::DesktopAlarmWidgetKde4, and AlarmNotifications::DesktopAlarmWidgetQt.

void DesktopAlarmWidget::configureNotificationTimeout (  )  [protected, slot]

Change timespan between alarm trigger and notification display.

Shows a window where the user can adjust the DesktopNotificationTimeout setting (see AlarmConfiguration). Derived classes should connect this slot to the appropriate item in their context menu.

Returns:
Nothing

Definition at line 107 of file desktopalarmwidget.cpp.

virtual void AlarmNotifications::DesktopAlarmWidget::createContextMenu (  )  [private, pure virtual]

Abstract context menu method.

Derived classes must implement this method to create the context menu for their system tray icon or status notifier item. The context menu should provide an option to enable or disable the notifications via toggleNotifications(), change the timespan between alarm trigger and notification display via configureNotificationTimeout() and close the widget via exitApplication(). Also, a single click on the widget should call showStatusMessage() to display the current status.

Returns:
void

Implemented in AlarmNotifications::DesktopAlarmWidgetKde4, and AlarmNotifications::DesktopAlarmWidgetQt.

void DesktopAlarmWidget::exitApplication (  )  [protected, slot]

Close the desktop widget.

This tells QApplication to stop the event loop which will cause QApplication::exec() to return in the main method. It will then exit and cause the destruction of all objects, including the derived desktop widget class. Derived classes should connect this slot to the appropriate item in their context menu.

Returns:
Nothing

Definition at line 182 of file desktopalarmwidget.cpp.

bool AlarmNotifications::DesktopAlarmWidget::getAlarmActive (  )  const [inline, protected]

Show alarm active flag to derived class.

Derived classes can access _alarmActive through this method. As this flag should only be changed by observeAlarmStatus(), the derived classes have read-only access.

Returns:
bool

Definition at line 204 of file desktopalarmwidget.h.

DesktopAlarmWidget::DesktopAlarmWidgetStatus DesktopAlarmWidget::getStatus (  )  const [protected]

Query alarm status.

Returns the current status so derived classes can display the correct icon.

Returns:
Item of the status enum

Definition at line 74 of file desktopalarmwidget.cpp.

virtual void AlarmNotifications::DesktopAlarmWidget::notificationSwitchChange ( bool  enabled  )  [protected, pure virtual, slot]

React on widget enable/disable.

The constructor of this abstract base class connects this slot to the notificationSwitchChanged() signal. Derived classes must implement their logic to show the proper icon for a disabled alarm widget.

Parameters:
enabled New status of the desktop alarm widget
Returns:
Nothing

Implemented in AlarmNotifications::DesktopAlarmWidgetKde4, and AlarmNotifications::DesktopAlarmWidgetQt.

void AlarmNotifications::DesktopAlarmWidget::notificationSwitchChanged ( bool  enabled  )  [signal]

Widget has been enabled or disabled.

This signal is fired by the toggleNotifications() method to inform the base classes about a switch change.

Parameters:
enabled New status of the desktop widget.
Returns:
Nothing
void DesktopAlarmWidget::observeAlarmStatus (  )  [private]

Thread to periodically check the status.

This method runs in a separate thread controlled by _iconThread. It continously checks the current status and emits the signal alarmStatusChanged() if anything happens, so the derived classes can act accordingly.

Returns:
void

Definition at line 187 of file desktopalarmwidget.cpp.

DesktopAlarmWidget& AlarmNotifications::DesktopAlarmWidget::operator= ( DesktopAlarmWidget &&  other  ) 

Move assignment (C++11, deleted).

This class cannot be moved.

Parameters:
other Another instance of DesktopAlarmWidget
Returns:
Nothing (deleted)

Reimplemented in AlarmNotifications::DesktopAlarmWidgetKde4, and AlarmNotifications::DesktopAlarmWidgetQt.

DesktopAlarmWidget& AlarmNotifications::DesktopAlarmWidget::operator= ( const DesktopAlarmWidget other  ) 

Copy assignment (deleted).

This class cannot be copied.

Parameters:
other Another instance of DesktopAlarmWidget
Returns:
Nothing (deleted)

Reimplemented in AlarmNotifications::DesktopAlarmWidgetKde4, and AlarmNotifications::DesktopAlarmWidgetQt.

void DesktopAlarmWidget::showStatusMessage (  )  [protected]

Show status dialog box.

Shows a message box explaining the current status of the desktop alarm widget to the user.

Returns:
Nothing

Definition at line 130 of file desktopalarmwidget.cpp.

void DesktopAlarmWidget::toggleNotifications (  )  [protected, slot]

Toggles the "main switch".

If the widget is currently active, it will disabled, and vice versa. When it is disabled, the instance of AlarmServerConnector will be destroyed and _asc set to nullptr. When it is enabled, a new instance of AlarmServerConnector will be created. Derived classes should connect this slot to the appropriate item in their context menu.

Returns:
Nothing

Definition at line 91 of file desktopalarmwidget.cpp.


Member Data Documentation

Beedo activation flag.

Indicates whether to Beedo engine shall be used to provide opto-acoustic alarms. Forwarded to the constructor of AlarmServerConnector.

Definition at line 95 of file desktopalarmwidget.h.

Alarm flag.

Indicates whether there is a currently active alarm.

Definition at line 116 of file desktopalarmwidget.h.

Pointer to the AlarmServerConnector instance.

The actual connection to the CSS Alarm Server and the displaying of desktop notifications is done in the AlarmServerConnector class. The initial instance is created in the constructor. When the desktop widget is disabled, the AlarmServerConnector instance is destroyed and the pointer set to nullptr. This is to close the connection to message broker and save resources when the messages from the alarm server are not needed anyway. When the desktop widget is re-enabled, a new instance is created.

As the pointer will be set to nullptr when the widget is disabled and this class uses multithreading, dereferencing and writing to this pointer must ALWAYS be protected by a lock on _ascmutex.

Definition at line 103 of file desktopalarmwidget.h.

Protect access to the _asc pointer.

Because the _asc pointer will be changed and set to nullptr in this multi-threaded class, a mutex must be used to protect access to the _asc pointer.

Definition at line 128 of file desktopalarmwidget.h.

Alarm status observer thread.

This thread runs the observeAlarmStatus() method that will periodically check the alarm status and signal the derived class on a status change.

Definition at line 122 of file desktopalarmwidget.h.

Thread run flag.

Set to true in the constructor before spawning _iconThread. When it is set to false, _iconThread will leave its loop and exit.

Definition at line 110 of file desktopalarmwidget.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 2 Dec 2014 for AlarmNotifications by  doxygen 1.6.1