/* Copyright (C) 2013 * swift project Community / Contributors * * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, * including this file, may be copied, modified, propagated, or distributed except according to the terms * contained in the LICENSE file. */ #include "infobarstatuscomponent.h" #include "ui_infobarstatuscomponent.h" #include "blackmisc/icons.h" #include #include #include using namespace BlackCore; using namespace BlackGui; using namespace BlackMisc; namespace BlackGui { namespace Components { CInfoBarStatusComponent::CInfoBarStatusComponent(QWidget *parent) : QFrame(parent), ui(new Ui::CInfoBarStatusComponent) { ui->setupUi(this); this->initLeds(); this->ui->lbl_Audio->setContextMenuPolicy(Qt::CustomContextMenu); connect(this->ui->lbl_Audio, &QLabel::customContextMenuRequested, this, &CInfoBarStatusComponent::ps_customAudioContextMenuRequested); } CInfoBarStatusComponent::~CInfoBarStatusComponent() { delete ui; } void CInfoBarStatusComponent::initLeds() { CLed::LedShapes shape = CLed::Circle; this->ui->led_DBus->setValues(CLed::Yellow, CLed::Black, shape, "DBus connected", "DBus disconnected", 14); this->ui->led_Network->setValues(CLed::Yellow, CLed::Black, shape, "Network connected", "Network disconnected", 14); this->ui->led_Simulator->setValues(CLed::Yellow, CLed::Black, shape, "Simulator connected", "Simulator disconnected", 14); shape = CLed::Rounded; this->ui->led_Ptt->setValues(CLed::Yellow, CLed::Red, shape, "Ptt", "Silence", 18); this->ui->led_Audio->setValues(CLed::Yellow, CLed::Red, shape, "On", "Muted", 18); } void CInfoBarStatusComponent::setDBusStatus(bool dbus) { this->ui->led_DBus->setValue(dbus); } void CInfoBarStatusComponent::setDBusTooltip(const QString &tooltip) { this->ui->led_DBus->setOnToolTip(tooltip); } void CInfoBarStatusComponent::setVolume(int volume) { if (volume < 1) { this->ui->led_Audio->setValue(false); } else { this->ui->led_Audio->setValue(true); } } void CInfoBarStatusComponent::runtimeHasBeenSet() { Q_ASSERT(getIContextSimulator()); Q_ASSERT(getIContextAudio()); Q_ASSERT(getIContextNetwork()); if (this->getIContextSimulator()) { connect(this->getIContextSimulator(), &IContextSimulator::connectionChanged, this, &CInfoBarStatusComponent::ps_simulatorConnectionChanged); } if (this->getIContextNetwork()) { connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CInfoBarStatusComponent::ps_networkConnectionChanged); } if (this->getIContextApplication()) { if (this->getIContextApplication()->usingLocalObjects()) { this->ui->led_DBus->setValue(false); } else { this->ui->led_DBus->setValue(true); } } } void CInfoBarStatusComponent::ps_simulatorConnectionChanged(bool connected) { this->ui->led_Simulator->setValue(connected); } void CInfoBarStatusComponent::ps_networkConnectionChanged(uint from, uint to, const QString &message) { INetwork::ConnectionStatus fromStatus = static_cast(from); INetwork::ConnectionStatus toStatus = static_cast(to); Q_UNUSED(fromStatus); Q_UNUSED(message); switch (toStatus) { case INetwork::Disconnected: case INetwork::DisconnectedError: case INetwork::DisconnectedFailed: case INetwork::DisconnectedLost: this->ui->led_Network->setValue(false); break; case INetwork::Connected: this->ui->led_Network->setValue(true); break; case INetwork::Connecting: this->ui->led_Network->setTemporaryColor(CLed::Yellow); break; default: this->ui->led_Network->setValue(false); break; } } void CInfoBarStatusComponent::ps_customAudioContextMenuRequested(const QPoint &position) { QWidget *sender = qobject_cast(QWidget::sender()); Q_ASSERT(sender); QPoint globalPosition = sender->mapToGlobal(position); QMenu menuAudio(this); menuAudio.addAction("Toogle mute"); #if defined(Q_OS_WIN) // QSysInfo::WindowsVersion only available on Win platforms if (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based) { menuAudio.addAction("Mixer"); } #endif QAction *selectedItem = menuAudio.exec(globalPosition); if (selectedItem) { // http://forum.technical-assistance.co.uk/sndvol32exe-command-line-parameters-vt1348.html const QList actions = menuAudio.actions(); if (selectedItem == actions.at(0)) { // TODO: toogle mute } else if (actions.size() > 1 && selectedItem == actions.at(1)) { QStringList parameterlist; QProcess::startDetached("SndVol.exe", parameterlist); } } } // custom menu } }