+
+void SystemTray::setState(State state)
+{
+ if (_state != state) {
+ _state = state;
+ emit stateChanged(state);
+
+ if (state == NeedsAttention && _attentionBehavior == AttentionBehavior::Blink) {
+ _blinkTimer.start();
+ _blinkState = true;
+ }
+ else {
+ _blinkTimer.stop();
+ _blinkState = false;
+ }
+ emit currentIconNameChanged();
+ }
+}
+
+
+QString SystemTray::iconName(State state) const
+{
+ QString name;
+ switch (state) {
+ case State::Passive:
+ name = "inactive-quassel-tray";
+ break;
+ case State::Active:
+ name = "active-quassel-tray";
+ break;
+ case State::NeedsAttention:
+ name = "message-quassel-tray";
+ break;
+ }
+
+ if (_trayIconInverted) {
+ name += "-inverted";
+ }
+
+ return name;
+}
+
+
+QString SystemTray::currentIconName() const
+{
+ if (state() == State::NeedsAttention) {
+ if (_attentionBehavior == AttentionBehavior::ChangeColor) {
+ return iconName(State::NeedsAttention);
+ }
+ if (_attentionBehavior == AttentionBehavior::Blink && _blinkState) {
+ return iconName(State::NeedsAttention);
+ }
+ return iconName(State::Active);
+ }
+ else {
+ return iconName(state());
+ }
+}
+
+
+QString SystemTray::currentAttentionIconName() const
+{
+ if (state() == State::NeedsAttention && _attentionBehavior == AttentionBehavior::Blink && !_blinkState) {
+ return iconName(State::Active);
+ }
+ return iconName(State::NeedsAttention);
+}
+
+
+bool SystemTray::isAlerted() const
+{
+ return state() == State::NeedsAttention;
+}
+
+
+void SystemTray::setAlert(bool alerted)
+{
+ if (alerted) {
+ setState(NeedsAttention);
+ }
+ else {
+ setState(Client::isConnected() ? Active : Passive);
+ }
+}
+
+
+void SystemTray::onBlinkTimeout()
+{
+ _blinkState = !_blinkState;
+ emit currentIconNameChanged();
+}
+
+
+QMenu *SystemTray::trayMenu() const
+{
+ return _trayMenu;
+}
+
+
+void SystemTray::trayMenuAboutToShow()
+{
+ if (GraphicalUi::isMainWidgetVisible())
+ _minimizeRestoreAction->setText(tr("&Minimize"));
+ else
+ _minimizeRestoreAction->setText(tr("&Restore"));
+}
+
+
+void SystemTray::enableChangeColorChanged(const QVariant &v)
+{
+ if (v.toBool()) {
+ _attentionBehavior = AttentionBehavior::ChangeColor;
+ }
+ else {
+ if (_attentionBehavior == AttentionBehavior::ChangeColor) {
+ _attentionBehavior = AttentionBehavior::DoNothing;
+ }
+ }
+ emit currentIconNameChanged();
+}
+
+
+void SystemTray::enableBlinkChanged(const QVariant &v)
+{
+ if (v.toBool()) {
+ _attentionBehavior = AttentionBehavior::Blink;
+ }
+ else {
+ if (_attentionBehavior == AttentionBehavior::Blink) {
+ _attentionBehavior = AttentionBehavior::DoNothing;
+ }
+ }
+ emit currentIconNameChanged();
+}
+
+
+void SystemTray::invertTrayIconChanged(const QVariant &v)
+{
+ _trayIconInverted = v.toBool();
+ emit iconsChanged();
+}
+
+
+QString SystemTray::toolTipTitle() const
+{
+ return _toolTipTitle;
+}
+
+
+QString SystemTray::toolTipSubTitle() const
+{
+ return _toolTipSubTitle;
+}
+
+
+void SystemTray::setToolTip(const QString &title, const QString &subtitle)
+{
+ _toolTipTitle = title;
+ _toolTipSubTitle = subtitle;
+ emit toolTipChanged(title, subtitle);
+}
+
+
+void SystemTray::showMessage(const QString &title, const QString &message, MessageIcon icon, int millisecondsTimeoutHint, uint id)
+{
+ Q_UNUSED(title)
+ Q_UNUSED(message)
+ Q_UNUSED(icon)
+ Q_UNUSED(millisecondsTimeoutHint)
+ Q_UNUSED(id)
+}
+
+
+void SystemTray::closeMessage(uint notificationId)
+{
+ Q_UNUSED(notificationId)
+}
+
+
+void SystemTray::activate(SystemTray::ActivationReason reason)
+{
+ emit activated(reason);
+}
+
+
+void SystemTray::minimizeRestore()
+{
+ GraphicalUi::toggleMainWidget();
+}