00001
00034 #include "desktopalarmwidgetkde4.h"
00035
00036 using namespace AlarmNotifications;
00037
00038 DesktopAlarmWidgetKde4::DesktopAlarmWidgetKde4()
00039 : DesktopAlarmWidget ( getBeedoActivated() ),
00040 _trayicon ( QString::fromUtf8 ( "AlarmNotificationsStatus" ), this ),
00041 _contextmenu ( nullptr )
00042 {
00043 _trayicon.setStandardActionsEnabled ( false );
00044 _trayicon.setAssociatedWidget ( nullptr );
00045 _trayicon.setCategory ( KStatusNotifierItem::SystemServices );
00046 _trayicon.setTitle ( QString::fromUtf8 ( "AlarmNotifications Desktop Widget" ) );
00047 setStatusIconAndTooltip ( ActiveOK );
00048 createContextMenu();
00049
00050 connect ( &_trayicon, SIGNAL ( activateRequested ( bool,QPoint ) ), this, SLOT ( activated ( bool,QPoint ) ) );
00051 }
00052
00053 DesktopAlarmWidgetKde4::~DesktopAlarmWidgetKde4()
00054 {
00055
00056 }
00057
00058 void DesktopAlarmWidgetKde4::createContextMenu()
00059 {
00060 _contextmenu = new KMenu ( QString::fromUtf8 ( "Desktop Alarm Notifications" ), nullptr );
00061 _toggleAction = _contextmenu->addAction (
00062 QIcon::fromTheme ( QString::fromUtf8 ( "dialog-cancel" ) ),
00063 QString::fromUtf8 ( "Disable ¬ifications" ),
00064 this,
00065 SLOT ( toggleNotifications() )
00066 );
00067 _configureAction = _contextmenu->addAction (
00068 QIcon::fromTheme ( QString::fromUtf8 ( "configure" ) ),
00069 QString::fromUtf8 ( "&Configure notification timeout" ),
00070 this,
00071 SLOT ( configureNotificationTimeout() )
00072 );
00073 _exitAction = _contextmenu->addAction (
00074 QIcon::fromTheme ( QString::fromUtf8 ( "application-exit" ) ),
00075 QString::fromUtf8 ( "&Exit desktop alarm widget" ),
00076 this,
00077 SLOT ( exitApplication() )
00078 );
00079 _trayicon.setContextMenu ( _contextmenu );
00080 }
00081
00082 void DesktopAlarmWidgetKde4::setStatusIconAndTooltip ( DesktopAlarmWidget::DesktopAlarmWidgetStatus status )
00083 {
00084 switch ( status )
00085 {
00086 case ActiveOK:
00087 _trayicon.setIconByName ( QString::fromUtf8 ( "help-feedback" ) );
00088 _trayicon.setStatus ( KStatusNotifierItem::Passive );
00089 _trayicon.setToolTip ( QString::fromUtf8 ( "help-feedback" ), QString::fromUtf8 ( "AlarmNotifications Desktop Widget" ), QString::fromUtf8 ( "No active alarm in the Detector Control System." ) );
00090 break;
00091 case ActiveAlarm:
00092 _trayicon.setIconByName ( QString::fromUtf8 ( "dialog-warning" ) );
00093 _trayicon.setStatus ( KStatusNotifierItem::NeedsAttention );
00094 _trayicon.setToolTip ( QString::fromUtf8 ( "dialog-warning" ), QString::fromUtf8 ( "AlarmNotifications Desktop Widget" ), QString::fromUtf8 ( "ATTENTION! There are active alarms in the Detector Control System!" ) );
00095 break;
00096 case Disabled:
00097 default:
00098 _trayicon.setIconByName ( QString::fromUtf8 ( "face-plain" ) );
00099 _trayicon.setStatus ( KStatusNotifierItem::Active );
00100 _trayicon.setToolTip ( QString::fromUtf8 ( "face-plain" ), QString::fromUtf8 ( "AlarmNotifications Desktop Widget" ), QString::fromUtf8 ( "Alarm notifications disabled!" ) );
00101 break;
00102 }
00103 }
00104
00105 void DesktopAlarmWidgetKde4::notificationSwitchChange ( bool enabled )
00106 {
00107 if ( enabled )
00108 {
00109 _toggleAction->setIcon ( QIcon::fromTheme ( QString::fromUtf8 ( "dialog-cancel" ) ) );
00110 _toggleAction->setText ( QString::fromUtf8 ( "Disable ¬ifications" ) );
00111 setStatusIconAndTooltip ( ActiveOK );
00112 }
00113 else
00114 {
00115 _toggleAction->setIcon ( QIcon::fromTheme ( QString::fromUtf8 ( "dialog-ok-apply" ) ) );
00116 _toggleAction->setText ( QString::fromUtf8 ( "Enable ¬ifications" ) );
00117 setStatusIconAndTooltip ( Disabled );
00118 }
00119 }
00120
00121 void DesktopAlarmWidgetKde4::changeTrayIcon()
00122 {
00123 if ( getAlarmActive() )
00124 setStatusIconAndTooltip ( ActiveAlarm );
00125 else
00126 setStatusIconAndTooltip ( ActiveOK );
00127 }
00128
00129 void DesktopAlarmWidgetKde4::activated ( bool active, const QPoint& posparameter )
00130 {
00131 Q_UNUSED ( active )
00132 Q_UNUSED ( posparameter )
00133 showStatusMessage();
00134 }
00135
00136 bool DesktopAlarmWidgetKde4::getBeedoActivated() noexcept
00137 {
00138 #ifndef BEEDO
00139 return false;
00140 #else
00141 return true;
00142 #endif
00143 }
00144
00145 #include "desktopalarmwidgetkde4.moc"