2017-09-18 14:33:44 +08:00
|
|
|
|
/*
|
2018-02-07 11:52:47 +08:00
|
|
|
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
2017-09-18 14:33:44 +08:00
|
|
|
|
*
|
|
|
|
|
* Author: sbw <sbw@sbw.so>
|
|
|
|
|
*
|
|
|
|
|
* Maintainer: sbw <sbw@sbw.so>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-08-02 11:32:24 +08:00
|
|
|
|
#include "soundapplet.h"
|
2016-08-03 11:23:18 +08:00
|
|
|
|
#include "sinkinputwidget.h"
|
2016-08-02 20:14:45 +08:00
|
|
|
|
#include "componments/horizontalseparator.h"
|
2018-07-04 16:17:01 +08:00
|
|
|
|
#include "../widgets/tipswidget.h"
|
2019-11-05 21:04:07 +08:00
|
|
|
|
#include "../frame/util/imageutil.h"
|
2018-10-24 18:09:44 +08:00
|
|
|
|
#include "util/utils.h"
|
2021-03-20 12:10:45 +08:00
|
|
|
|
|
2019-10-08 17:36:03 +08:00
|
|
|
|
#include <DGuiApplicationHelper>
|
2021-03-20 12:10:45 +08:00
|
|
|
|
#include <DApplication>
|
|
|
|
|
#include <DStandardItem>
|
|
|
|
|
#include <DFontSizeManager>
|
2016-08-02 17:40:32 +08:00
|
|
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QIcon>
|
2020-03-13 12:59:02 +08:00
|
|
|
|
#include <QScrollBar>
|
2021-05-07 13:14:18 +09:00
|
|
|
|
#include <QPainter>
|
2016-08-02 11:32:24 +08:00
|
|
|
|
|
2021-05-07 13:14:18 +09:00
|
|
|
|
#define SEPARATOR_HEIGHT 2
|
2020-08-19 17:13:58 +08:00
|
|
|
|
#define WIDTH 260
|
2019-08-27 15:17:26 +08:00
|
|
|
|
#define MAX_HEIGHT 300
|
2016-08-02 17:40:32 +08:00
|
|
|
|
#define ICON_SIZE 24
|
2020-07-27 13:05:38 +08:00
|
|
|
|
#define ITEM_HEIGHT 24
|
2020-09-01 18:40:01 +08:00
|
|
|
|
#define ITEM_SPACING 5
|
2020-09-17 16:00:45 +08:00
|
|
|
|
#define DEVICE_SPACING 10
|
2021-02-27 15:50:24 +08:00
|
|
|
|
#define SLIDER_HIGHT 32
|
|
|
|
|
#define GSETTING_SOUND_OUTPUT_SLIDER "soundOutputSlider"
|
2016-08-02 11:32:24 +08:00
|
|
|
|
|
2016-08-03 10:08:01 +08:00
|
|
|
|
DWIDGET_USE_NAMESPACE
|
2019-10-08 17:36:03 +08:00
|
|
|
|
DGUI_USE_NAMESPACE
|
2020-06-29 15:35:51 +08:00
|
|
|
|
using namespace Dock;
|
2020-07-27 13:05:38 +08:00
|
|
|
|
|
2021-05-07 13:14:18 +09:00
|
|
|
|
ItemDelegate::ItemDelegate(QAbstractItemView *parent)
|
|
|
|
|
: DStyledItemDelegate(parent)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 17:41:06 +09:00
|
|
|
|
/**
|
|
|
|
|
* @brief ItemDelegate::paint 绘制鼠标移动到音频列表某条item上的选中效果
|
|
|
|
|
* @param painter
|
|
|
|
|
* @param option
|
|
|
|
|
* @param index
|
|
|
|
|
*/
|
2021-05-07 13:14:18 +09:00
|
|
|
|
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
QStyleOptionViewItem styleOption = option;
|
|
|
|
|
|
|
|
|
|
if ((styleOption.state & QStyle::State_MouseOver)) {
|
|
|
|
|
styleOption.showDecorationSelected = true;
|
|
|
|
|
styleOption.state |= QStyle::State_Selected;
|
|
|
|
|
styleOption.rect += QMargins(1, 1, 1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DStyledItemDelegate::paint(painter, styleOption, index);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-27 13:05:38 +08:00
|
|
|
|
Q_DECLARE_METATYPE(const Port *)
|
|
|
|
|
|
|
|
|
|
Port::Port(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
, m_isActive(false)
|
2020-09-30 09:29:10 +08:00
|
|
|
|
, m_direction(Out)
|
2020-07-27 13:05:38 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Port::setId(const QString &id)
|
|
|
|
|
{
|
|
|
|
|
if (id != m_id) {
|
|
|
|
|
m_id = id;
|
|
|
|
|
Q_EMIT idChanged(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Port::setName(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
if (name != m_name) {
|
|
|
|
|
m_name = name;
|
|
|
|
|
Q_EMIT nameChanged(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Port::setCardName(const QString &cardName)
|
|
|
|
|
{
|
|
|
|
|
if (cardName != m_cardName) {
|
|
|
|
|
m_cardName = cardName;
|
|
|
|
|
Q_EMIT cardNameChanged(cardName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Port::setIsActive(bool isActive)
|
|
|
|
|
{
|
|
|
|
|
if (isActive != m_isActive) {
|
|
|
|
|
m_isActive = isActive;
|
|
|
|
|
Q_EMIT isActiveChanged(isActive);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Port::setDirection(const Direction &direction)
|
|
|
|
|
{
|
|
|
|
|
if (direction != m_direction) {
|
|
|
|
|
m_direction = direction;
|
|
|
|
|
Q_EMIT directionChanged(direction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Port::setCardId(const uint &cardId)
|
|
|
|
|
{
|
|
|
|
|
if (cardId != m_cardId) {
|
|
|
|
|
m_cardId = cardId;
|
|
|
|
|
Q_EMIT cardIdChanged(cardId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-02 11:32:24 +08:00
|
|
|
|
SoundApplet::SoundApplet(QWidget *parent)
|
2019-08-27 15:17:26 +08:00
|
|
|
|
: QScrollArea(parent)
|
|
|
|
|
, m_centralWidget(new QWidget)
|
2020-06-13 11:39:32 +08:00
|
|
|
|
, m_volumeBtn(new DIconButton(this))
|
2019-08-27 15:17:26 +08:00
|
|
|
|
, m_volumeIconMax(new QLabel)
|
|
|
|
|
, m_volumeSlider(new VolumeSlider)
|
2020-01-19 12:18:35 +08:00
|
|
|
|
, m_soundShow(new TipsWidget)
|
2021-05-07 13:14:18 +09:00
|
|
|
|
, m_separator(new HorizontalSeparator(this))
|
|
|
|
|
, m_secondSeparator(new HorizontalSeparator(this))
|
2020-10-16 21:26:49 +08:00
|
|
|
|
, m_deviceLabel(nullptr)
|
2020-07-27 13:05:38 +08:00
|
|
|
|
, m_audioInter(new DBusAudio("com.deepin.daemon.Audio", "/com/deepin/daemon/Audio", QDBusConnection::sessionBus(), this))
|
2019-08-27 15:17:26 +08:00
|
|
|
|
, m_defSinkInter(nullptr)
|
2020-07-27 13:05:38 +08:00
|
|
|
|
, m_listView(new DListView(this))
|
|
|
|
|
, m_model(new QStandardItemModel(m_listView))
|
|
|
|
|
, m_deviceInfo("")
|
2020-10-16 21:26:49 +08:00
|
|
|
|
, m_lastPort(nullptr)
|
2021-03-20 12:10:45 +08:00
|
|
|
|
, m_gsettings(Utils::ModuleSettingsPtr("sound", QByteArray(), this))
|
2021-05-07 13:14:18 +09:00
|
|
|
|
, m_itemDelegate(new ItemDelegate(m_listView))
|
2020-09-17 16:00:45 +08:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
initUi();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 17:41:06 +09:00
|
|
|
|
/**
|
|
|
|
|
* @brief SoundApplet::setControlBackground 设置音频界面控件背景颜色
|
|
|
|
|
*/
|
2021-05-07 13:14:18 +09:00
|
|
|
|
void SoundApplet::setControlBackground()
|
|
|
|
|
{
|
|
|
|
|
QPalette soundAppletBackgroud;
|
|
|
|
|
QPalette listViewBackgroud = m_listView->palette();
|
|
|
|
|
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
|
|
|
|
|
soundAppletBackgroud.setColor(QPalette::Background, QColor(255, 255, 255, 0.03 * 255));
|
|
|
|
|
m_separator->setColor(QColor(0, 0, 0, 0.1 * 255));
|
|
|
|
|
m_secondSeparator->setColor(QColor(0, 0, 0, 0.1 * 255));
|
|
|
|
|
} else {
|
|
|
|
|
soundAppletBackgroud.setColor(QPalette::Background, QColor(0, 0, 0, 0.03 * 255));
|
|
|
|
|
m_separator->setColor(QColor(255, 255, 255, 0.1 * 255));
|
|
|
|
|
m_secondSeparator->setColor(QColor(255, 255, 255, 0.1 * 255));
|
|
|
|
|
}
|
|
|
|
|
this->setAutoFillBackground(true);
|
|
|
|
|
this->setPalette(soundAppletBackgroud);
|
|
|
|
|
listViewBackgroud.setColor(QPalette::Base, Qt::transparent);
|
|
|
|
|
m_listView->setAutoFillBackground(true);
|
|
|
|
|
m_listView->setPalette(listViewBackgroud);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 17:41:06 +09:00
|
|
|
|
/**
|
|
|
|
|
* @brief SoundApplet::setItemHoverColor 通过代理方式根据当前主题设置音频列表文字颜色和item选中颜色
|
|
|
|
|
*/
|
2021-05-07 13:14:18 +09:00
|
|
|
|
void SoundApplet::setItemHoverColor()
|
|
|
|
|
{
|
|
|
|
|
QPalette hoverBackgroud = m_listView->palette();
|
|
|
|
|
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) {
|
|
|
|
|
hoverBackgroud.setColor(QPalette::Normal, QPalette::Highlight, QColor(0, 0, 0, 30));
|
|
|
|
|
hoverBackgroud.setColor(QPalette::Normal, QPalette::HighlightedText, QColor(0, 0, 0, 255));
|
|
|
|
|
} else {
|
|
|
|
|
hoverBackgroud.setColor(QPalette::Normal, QPalette::Highlight, QColor(255, 255, 255, 30));
|
|
|
|
|
hoverBackgroud.setColor(QPalette::Normal, QPalette::HighlightedText, QColor(255, 255, 255, 255));
|
|
|
|
|
}
|
|
|
|
|
m_listView->setPalette(hoverBackgroud);
|
|
|
|
|
m_listView->setItemDelegate(m_itemDelegate);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 16:00:45 +08:00
|
|
|
|
void SoundApplet::initUi()
|
2016-08-02 11:32:24 +08:00
|
|
|
|
{
|
2021-05-07 13:14:18 +09:00
|
|
|
|
setControlBackground();
|
2020-07-27 13:05:38 +08:00
|
|
|
|
m_listView->setEditTriggers(DListView::NoEditTriggers);
|
|
|
|
|
m_listView->setSelectionMode(QAbstractItemView::NoSelection);
|
|
|
|
|
m_listView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2021-05-07 13:14:18 +09:00
|
|
|
|
m_listView->setItemRadius(0);
|
2020-07-27 13:05:38 +08:00
|
|
|
|
m_listView->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
|
|
|
|
|
m_listView->setFixedHeight(0);
|
2021-05-07 13:14:18 +09:00
|
|
|
|
m_listView->setItemSpacing(1);
|
2020-07-27 13:05:38 +08:00
|
|
|
|
|
2020-03-13 12:59:02 +08:00
|
|
|
|
m_centralWidget->setAccessibleName("volumn-centralwidget");
|
2020-03-13 12:07:59 +08:00
|
|
|
|
m_volumeBtn->setAccessibleName("volume-button");
|
2020-03-13 12:59:02 +08:00
|
|
|
|
m_volumeIconMax->setAccessibleName("volume-iconmax");
|
|
|
|
|
m_volumeSlider->setAccessibleName("volume-slider");
|
|
|
|
|
m_soundShow->setAccessibleName("volume-soundtips");
|
|
|
|
|
this->horizontalScrollBar()->setAccessibleName("volume-horizontalscrollbar");
|
|
|
|
|
this->verticalScrollBar()->setAccessibleName("volume-verticalscrollbar");
|
|
|
|
|
|
2019-08-27 15:17:26 +08:00
|
|
|
|
m_volumeIconMax->setFixedSize(ICON_SIZE, ICON_SIZE);
|
|
|
|
|
|
2020-01-19 12:18:35 +08:00
|
|
|
|
m_soundShow->setText(QString("%1%").arg(0));
|
2016-10-29 10:18:30 +08:00
|
|
|
|
|
2020-10-16 21:26:49 +08:00
|
|
|
|
m_deviceLabel = new TipsWidget;
|
|
|
|
|
m_deviceLabel->setText(tr("Device"));
|
2020-12-02 17:04:21 +08:00
|
|
|
|
DFontSizeManager::instance()->bind(m_deviceLabel, DFontSizeManager::T4, QFont::Medium);
|
2016-08-02 17:40:32 +08:00
|
|
|
|
|
2020-06-13 11:39:32 +08:00
|
|
|
|
QHBoxLayout *deviceLayout = new QHBoxLayout;
|
2020-01-19 12:18:35 +08:00
|
|
|
|
deviceLayout->addSpacing(2);
|
2020-10-16 21:26:49 +08:00
|
|
|
|
deviceLayout->addWidget(m_deviceLabel, 0, Qt::AlignLeft);
|
2020-06-13 11:39:32 +08:00
|
|
|
|
deviceLayout->addWidget(m_soundShow, 0, Qt::AlignRight);
|
2020-01-19 12:18:35 +08:00
|
|
|
|
deviceLayout->setSpacing(0);
|
|
|
|
|
deviceLayout->setMargin(0);
|
|
|
|
|
|
2019-08-27 15:17:26 +08:00
|
|
|
|
QVBoxLayout *deviceLineLayout = new QVBoxLayout;
|
2020-01-19 12:18:35 +08:00
|
|
|
|
deviceLineLayout->addLayout(deviceLayout);
|
2020-09-17 16:00:45 +08:00
|
|
|
|
deviceLineLayout->addWidget(m_separator);
|
2016-08-02 17:40:32 +08:00
|
|
|
|
deviceLineLayout->setMargin(0);
|
2020-09-17 16:00:45 +08:00
|
|
|
|
deviceLineLayout->setSpacing(DEVICE_SPACING);
|
2016-08-02 17:40:32 +08:00
|
|
|
|
|
|
|
|
|
QHBoxLayout *volumeCtrlLayout = new QHBoxLayout;
|
2021-05-07 13:14:18 +09:00
|
|
|
|
volumeCtrlLayout->addSpacing(8);
|
2016-08-03 10:08:01 +08:00
|
|
|
|
volumeCtrlLayout->addWidget(m_volumeBtn);
|
2016-08-09 14:51:03 +08:00
|
|
|
|
volumeCtrlLayout->addSpacing(10);
|
2016-08-02 17:40:32 +08:00
|
|
|
|
volumeCtrlLayout->addWidget(m_volumeSlider);
|
2019-08-27 15:17:26 +08:00
|
|
|
|
volumeCtrlLayout->addSpacing(10);
|
|
|
|
|
volumeCtrlLayout->addWidget(m_volumeIconMax);
|
2021-05-07 13:14:18 +09:00
|
|
|
|
volumeCtrlLayout->addSpacing(8);
|
2016-08-02 17:40:32 +08:00
|
|
|
|
volumeCtrlLayout->setSpacing(0);
|
|
|
|
|
volumeCtrlLayout->setMargin(0);
|
|
|
|
|
|
2021-05-19 17:41:06 +09:00
|
|
|
|
//音频界面添加第二个分割线
|
2021-05-07 13:14:18 +09:00
|
|
|
|
QVBoxLayout *volumeLineLayout = new QVBoxLayout;
|
|
|
|
|
volumeLineLayout->addLayout(volumeCtrlLayout);
|
|
|
|
|
volumeLineLayout->addWidget(m_secondSeparator);
|
|
|
|
|
volumeLineLayout->setMargin(0);
|
|
|
|
|
|
2016-08-03 10:08:01 +08:00
|
|
|
|
m_volumeBtn->setFixedSize(ICON_SIZE, ICON_SIZE);
|
2020-06-13 11:39:32 +08:00
|
|
|
|
m_volumeBtn->setIconSize(QSize(ICON_SIZE, ICON_SIZE));
|
|
|
|
|
m_volumeBtn->setFlat(true);
|
2021-02-27 15:50:24 +08:00
|
|
|
|
|
|
|
|
|
m_volumeSlider->setFixedHeight(SLIDER_HIGHT);
|
2016-08-02 17:40:32 +08:00
|
|
|
|
m_volumeSlider->setMinimum(0);
|
2020-05-14 18:58:42 +08:00
|
|
|
|
m_volumeSlider->setMaximum(m_audioInter->maxUIVolume() * 100.0f);
|
2021-03-20 12:10:45 +08:00
|
|
|
|
updateVolumeSliderStatus(Utils::SettingValue("com.deepin.dde.dock.module.sound", QByteArray(), "Enabled").toString());
|
2021-02-27 15:50:24 +08:00
|
|
|
|
connect(m_gsettings, &QGSettings::changed, [ = ] (const QString &key) {
|
|
|
|
|
if (key == GSETTING_SOUND_OUTPUT_SLIDER) {
|
|
|
|
|
updateVolumeSliderStatus(m_gsettings->get(GSETTING_SOUND_OUTPUT_SLIDER).toString());
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-08-02 17:40:32 +08:00
|
|
|
|
|
2017-02-06 22:25:47 +08:00
|
|
|
|
m_centralLayout = new QVBoxLayout;
|
2021-05-07 13:14:18 +09:00
|
|
|
|
m_centralLayout->setMargin(0);
|
|
|
|
|
m_centralLayout->setSpacing(0);
|
2017-02-06 22:25:47 +08:00
|
|
|
|
m_centralLayout->addLayout(deviceLineLayout);
|
2021-05-07 13:14:18 +09:00
|
|
|
|
m_centralLayout->addLayout(volumeLineLayout);
|
2020-09-17 16:00:45 +08:00
|
|
|
|
m_centralLayout->setContentsMargins(8, 8, 8, 0);
|
2020-07-27 13:05:38 +08:00
|
|
|
|
|
|
|
|
|
m_listView->setModel(m_model);
|
2021-05-07 13:14:18 +09:00
|
|
|
|
setItemHoverColor();
|
|
|
|
|
m_centralLayout->setMargin(0);
|
|
|
|
|
m_centralLayout->setSpacing(0);
|
2020-07-27 13:05:38 +08:00
|
|
|
|
m_centralLayout->addWidget(m_listView);
|
2017-02-06 22:25:47 +08:00
|
|
|
|
m_centralWidget->setLayout(m_centralLayout);
|
|
|
|
|
m_centralWidget->setFixedWidth(WIDTH);
|
|
|
|
|
m_centralWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
2016-08-02 11:32:24 +08:00
|
|
|
|
|
|
|
|
|
setFixedWidth(WIDTH);
|
2017-02-06 22:25:47 +08:00
|
|
|
|
setWidget(m_centralWidget);
|
2019-10-08 17:36:03 +08:00
|
|
|
|
setFrameShape(QFrame::NoFrame);
|
2016-08-02 11:32:24 +08:00
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2019-10-08 17:36:03 +08:00
|
|
|
|
m_centralWidget->setAutoFillBackground(false);
|
|
|
|
|
viewport()->setAutoFillBackground(false);
|
2016-08-02 15:12:54 +08:00
|
|
|
|
|
2020-09-17 16:00:45 +08:00
|
|
|
|
connect(qApp, &QGuiApplication::fontChanged, this, &SoundApplet::updateListHeight);
|
2020-06-13 11:39:32 +08:00
|
|
|
|
connect(m_volumeBtn, &DIconButton::clicked, this, &SoundApplet::toggleMute);
|
2016-08-02 20:14:45 +08:00
|
|
|
|
connect(m_volumeSlider, &VolumeSlider::valueChanged, this, &SoundApplet::volumeSliderValueChanged);
|
2017-05-27 13:53:54 +08:00
|
|
|
|
connect(m_volumeSlider, &VolumeSlider::requestPlaySoundEffect, this, &SoundApplet::onPlaySoundEffect);
|
2016-08-23 13:05:45 +08:00
|
|
|
|
connect(m_audioInter, &DBusAudio::DefaultSinkChanged, this, static_cast<void (SoundApplet::*)()>(&SoundApplet::defaultSinkChanged));
|
2020-01-19 14:39:36 +08:00
|
|
|
|
connect(m_audioInter, &DBusAudio::IncreaseVolumeChanged, this, &SoundApplet::increaseVolumeChanged);
|
2020-10-16 21:26:49 +08:00
|
|
|
|
connect(m_audioInter, &DBusAudio::PortEnabledChanged, [this](uint cardId, QString portId) {
|
|
|
|
|
portEnableChange(cardId, portId);
|
|
|
|
|
});;
|
2020-07-27 13:05:38 +08:00
|
|
|
|
connect(m_listView, &DListView::clicked, this, [this](const QModelIndex & idx) {
|
|
|
|
|
const Port * port = m_listView->model()->data(idx, Qt::WhatsThisPropertyRole).value<const Port *>();
|
|
|
|
|
if (port) {
|
|
|
|
|
m_audioInter->SetPort(port->cardId(), port->id(), int(port->direction()));
|
2020-10-16 21:26:49 +08:00
|
|
|
|
//手动勾选时启用设备
|
|
|
|
|
m_audioInter->SetPortEnabled(port->cardId(), port->id(), true);
|
2020-07-27 13:05:38 +08:00
|
|
|
|
}
|
2020-10-16 21:26:49 +08:00
|
|
|
|
|
2020-07-27 13:05:38 +08:00
|
|
|
|
});
|
2019-10-08 17:36:03 +08:00
|
|
|
|
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &SoundApplet::refreshIcon);
|
|
|
|
|
connect(qApp, &DApplication::iconThemeChanged, this, &SoundApplet::refreshIcon);
|
2020-07-27 13:05:38 +08:00
|
|
|
|
QDBusConnection::sessionBus().connect("com.deepin.daemon.Audio", "/com/deepin/daemon/Audio", "org.freedesktop.DBus.Properties"
|
|
|
|
|
,"PropertiesChanged", "sa{sv}as", this, SLOT(haldleDbusSignal(QDBusMessage)));
|
2016-08-02 17:40:32 +08:00
|
|
|
|
|
2018-07-31 23:03:37 +08:00
|
|
|
|
QMetaObject::invokeMethod(this, "defaultSinkChanged", Qt::QueuedConnection);
|
2019-10-08 17:36:03 +08:00
|
|
|
|
|
|
|
|
|
refreshIcon();
|
2020-07-27 13:05:38 +08:00
|
|
|
|
|
2020-10-16 21:26:49 +08:00
|
|
|
|
updateCradsInfo();
|
2016-08-02 16:25:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 10:07:30 +08:00
|
|
|
|
int SoundApplet::volumeValue() const
|
|
|
|
|
{
|
|
|
|
|
return m_volumeSlider->value();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-25 17:51:02 +08:00
|
|
|
|
int SoundApplet::maxVolumeValue() const
|
|
|
|
|
{
|
|
|
|
|
return m_volumeSlider->maximum();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-29 10:56:13 +08:00
|
|
|
|
VolumeSlider *SoundApplet::mainSlider()
|
|
|
|
|
{
|
|
|
|
|
return m_volumeSlider;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-02 16:25:01 +08:00
|
|
|
|
void SoundApplet::defaultSinkChanged()
|
|
|
|
|
{
|
2020-09-03 17:32:41 +08:00
|
|
|
|
//防止手动切换设备,与后端交互时,获取到多个信号,设备切换多次,造成混乱
|
|
|
|
|
QThread::msleep(200);
|
|
|
|
|
|
2020-07-27 13:05:38 +08:00
|
|
|
|
if (m_defSinkInter) {
|
|
|
|
|
delete m_defSinkInter;
|
|
|
|
|
m_defSinkInter = nullptr;
|
|
|
|
|
}
|
2016-08-02 16:25:01 +08:00
|
|
|
|
|
2016-12-22 16:26:56 +08:00
|
|
|
|
const QDBusObjectPath defSinkPath = m_audioInter->defaultSink();
|
2020-07-27 13:05:38 +08:00
|
|
|
|
m_defSinkInter = new DBusSink("com.deepin.daemon.Audio", defSinkPath.path(), QDBusConnection::sessionBus(), this);
|
2016-08-02 16:25:01 +08:00
|
|
|
|
|
2016-08-02 17:40:32 +08:00
|
|
|
|
connect(m_defSinkInter, &DBusSink::VolumeChanged, this, &SoundApplet::onVolumeChanged);
|
2020-11-03 14:17:32 +08:00
|
|
|
|
connect(m_defSinkInter, &DBusSink::MuteChanged, this, [ = ] {
|
|
|
|
|
onVolumeChanged(m_defSinkInter->volume());
|
|
|
|
|
});
|
2016-08-02 17:40:32 +08:00
|
|
|
|
|
2020-07-27 13:05:38 +08:00
|
|
|
|
QString portId = m_defSinkInter->activePort().name;
|
|
|
|
|
uint cardId = m_defSinkInter->card();
|
2020-10-16 21:26:49 +08:00
|
|
|
|
//最后一个设备会被移除,但是当在控制中心选中此设备后需要添加,并勾选
|
2020-10-29 08:49:00 +08:00
|
|
|
|
if (!m_lastPort.isNull() && m_lastPort->cardId() == cardId && m_lastPort->id() == portId) {
|
2020-10-16 21:26:49 +08:00
|
|
|
|
startAddPort(m_lastPort);
|
|
|
|
|
}
|
2020-07-27 13:05:38 +08:00
|
|
|
|
activePort(portId,cardId);
|
|
|
|
|
|
2016-08-02 16:25:01 +08:00
|
|
|
|
emit defaultSinkChanged(m_defSinkInter);
|
2020-10-28 09:48:04 +08:00
|
|
|
|
onVolumeChanged(m_defSinkInter->volume());
|
2016-08-02 11:32:24 +08:00
|
|
|
|
}
|
2016-08-02 17:40:32 +08:00
|
|
|
|
|
2020-10-28 09:48:04 +08:00
|
|
|
|
void SoundApplet::onVolumeChanged(double volume)
|
2016-08-02 17:40:32 +08:00
|
|
|
|
{
|
2020-10-28 09:48:04 +08:00
|
|
|
|
m_volumeSlider->setValue(static_cast<int>(std::min(150.0, volume * 100.0)));
|
2017-06-21 16:39:37 +08:00
|
|
|
|
|
2020-03-05 15:13:23 +08:00
|
|
|
|
m_soundShow->setText(QString::number(volume * 100) + '%');
|
2017-02-07 00:18:00 +08:00
|
|
|
|
emit volumeChanged(m_volumeSlider->value());
|
2019-10-08 17:36:03 +08:00
|
|
|
|
refreshIcon();
|
2016-08-02 17:40:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SoundApplet::volumeSliderValueChanged()
|
|
|
|
|
{
|
2020-09-15 20:47:59 +08:00
|
|
|
|
m_defSinkInter->SetVolume(m_volumeSlider->value() / 100.0f, true);
|
2020-10-13 20:10:33 +08:00
|
|
|
|
if (m_defSinkInter->mute())
|
|
|
|
|
m_defSinkInter->SetMuteQueued(false);
|
2016-08-02 17:40:32 +08:00
|
|
|
|
}
|
2016-08-03 10:08:01 +08:00
|
|
|
|
|
2016-08-03 11:23:18 +08:00
|
|
|
|
void SoundApplet::sinkInputsChanged()
|
|
|
|
|
{
|
2017-02-06 22:25:47 +08:00
|
|
|
|
m_centralWidget->setVisible(false);
|
|
|
|
|
QVBoxLayout *appLayout = m_centralLayout;
|
2019-08-27 15:17:26 +08:00
|
|
|
|
while (QLayoutItem *item = appLayout->takeAt(4)) {
|
2016-08-03 11:23:18 +08:00
|
|
|
|
delete item->widget();
|
|
|
|
|
delete item;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-27 15:17:26 +08:00
|
|
|
|
for (auto input : m_audioInter->sinkInputs()) {
|
|
|
|
|
appLayout->addWidget(new HorizontalSeparator);
|
|
|
|
|
|
2016-08-03 11:23:18 +08:00
|
|
|
|
SinkInputWidget *si = new SinkInputWidget(input.path());
|
|
|
|
|
appLayout->addWidget(si);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 22:25:47 +08:00
|
|
|
|
m_centralWidget->setVisible(true);
|
2016-08-03 11:23:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-27 13:05:38 +08:00
|
|
|
|
void SoundApplet::cardsChanged(const QString &cards)
|
|
|
|
|
{
|
|
|
|
|
QMap<uint, QStringList> tmpCardIds;
|
|
|
|
|
|
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(cards.toUtf8());
|
|
|
|
|
QJsonArray jCards = doc.array();
|
|
|
|
|
for (QJsonValue cV : jCards) {
|
|
|
|
|
QJsonObject jCard = cV.toObject();
|
|
|
|
|
const uint cardId = jCard["Id"].toInt();
|
|
|
|
|
const QString cardName = jCard["Name"].toString();
|
|
|
|
|
QJsonArray jPorts = jCard["Ports"].toArray();
|
|
|
|
|
|
|
|
|
|
QStringList tmpPorts;
|
|
|
|
|
|
|
|
|
|
for (QJsonValue pV : jPorts) {
|
|
|
|
|
QJsonObject jPort = pV.toObject();
|
|
|
|
|
const double portAvai = jPort["Available"].toDouble();
|
|
|
|
|
if (portAvai == 2 || portAvai == 0 ) { // 0 Unknow 1 Not available 2 Available
|
|
|
|
|
const QString portId = jPort["Name"].toString();
|
|
|
|
|
const QString portName = jPort["Description"].toString();
|
|
|
|
|
|
|
|
|
|
Port *port = findPort(portId, cardId);
|
|
|
|
|
const bool include = port != nullptr;
|
|
|
|
|
if (!include) { port = new Port(m_model); }
|
|
|
|
|
|
|
|
|
|
port->setId(portId);
|
|
|
|
|
port->setName(portName);
|
|
|
|
|
port->setDirection(Port::Direction(jPort["Direction"].toDouble()));
|
|
|
|
|
port->setCardId(cardId);
|
|
|
|
|
port->setCardName(cardName);
|
|
|
|
|
|
2020-10-16 21:26:49 +08:00
|
|
|
|
if (!include) {
|
|
|
|
|
startAddPort(port);
|
|
|
|
|
}
|
2020-07-27 13:05:38 +08:00
|
|
|
|
|
|
|
|
|
tmpPorts << portId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
tmpCardIds.insert(cardId, tmpPorts);
|
|
|
|
|
}
|
2020-10-16 21:26:49 +08:00
|
|
|
|
|
2020-07-27 13:05:38 +08:00
|
|
|
|
defaultSinkChanged();//重新获取切换的设备信息
|
2020-10-16 21:26:49 +08:00
|
|
|
|
enableDevice(true);
|
2020-07-27 13:05:38 +08:00
|
|
|
|
|
|
|
|
|
for (Port *port : m_ports) {
|
2020-10-16 21:26:49 +08:00
|
|
|
|
//只要有一个设备在控制中心被禁用后,在任务栏声音设备列表中该设备会被移除,
|
|
|
|
|
if (!m_audioInter->IsPortEnabled(port->cardId(), port->id())) {
|
|
|
|
|
removeDisabledDevice(port->id(), port->cardId());
|
|
|
|
|
}
|
2020-07-27 13:05:38 +08:00
|
|
|
|
//判断端口是否在最新的设备列表中
|
|
|
|
|
if (tmpCardIds.contains(port->cardId())) {
|
|
|
|
|
if (!tmpCardIds[port->cardId()].contains(port->id())) {
|
|
|
|
|
startRemovePort(port->id(), port->cardId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
startRemovePort(port->id(), port->cardId());
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-16 21:26:49 +08:00
|
|
|
|
//当只有一个设备剩余时,该设备也需要移除
|
|
|
|
|
removeLastDevice();
|
2020-09-17 16:00:45 +08:00
|
|
|
|
updateListHeight();
|
2020-07-27 13:05:38 +08:00
|
|
|
|
}
|
2016-08-03 10:08:01 +08:00
|
|
|
|
void SoundApplet::toggleMute()
|
|
|
|
|
{
|
2018-01-31 19:36:32 +08:00
|
|
|
|
m_defSinkInter->SetMuteQueued(!m_defSinkInter->mute());
|
2016-08-03 10:08:01 +08:00
|
|
|
|
}
|
2017-04-12 14:16:57 +08:00
|
|
|
|
|
2017-05-27 13:53:54 +08:00
|
|
|
|
void SoundApplet::onPlaySoundEffect()
|
|
|
|
|
{
|
2020-07-22 13:18:13 +08:00
|
|
|
|
|
2017-05-27 13:53:54 +08:00
|
|
|
|
}
|
2019-10-08 17:36:03 +08:00
|
|
|
|
|
2020-01-19 12:18:35 +08:00
|
|
|
|
void SoundApplet::increaseVolumeChanged()
|
|
|
|
|
{
|
2020-05-14 18:58:42 +08:00
|
|
|
|
m_volumeSlider->setMaximum(m_audioInter->maxUIVolume() * 100.0f);
|
2020-01-19 12:18:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-08 17:36:03 +08:00
|
|
|
|
void SoundApplet::refreshIcon()
|
|
|
|
|
{
|
|
|
|
|
if (!m_defSinkInter)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const bool mute = m_defSinkInter->mute();
|
|
|
|
|
|
|
|
|
|
QString volumeString;
|
|
|
|
|
|
|
|
|
|
if (mute) {
|
|
|
|
|
volumeString = "muted";
|
|
|
|
|
} else {
|
2020-10-20 16:13:05 +08:00
|
|
|
|
volumeString = "off";
|
2019-10-08 17:36:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString iconLeft = QString("audio-volume-%1-symbolic").arg(volumeString);
|
|
|
|
|
QString iconRight = QString("audio-volume-high-symbolic");
|
|
|
|
|
|
2020-08-26 14:25:40 +08:00
|
|
|
|
QColor color;
|
|
|
|
|
switch (DGuiApplicationHelper::instance()->themeType()) {
|
|
|
|
|
case DGuiApplicationHelper::LightType:
|
|
|
|
|
color = Qt::black;
|
2019-10-08 17:36:03 +08:00
|
|
|
|
iconLeft.append("-dark");
|
|
|
|
|
iconRight.append("-dark");
|
2020-08-26 14:25:40 +08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
color = Qt::white;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-05-07 13:14:18 +09:00
|
|
|
|
setControlBackground();
|
2020-08-26 14:25:40 +08:00
|
|
|
|
//主题改变时,同步修改item颜色
|
|
|
|
|
for (int i = 0; i < m_model->rowCount(); i++) {
|
|
|
|
|
auto item = m_model->item(i);
|
|
|
|
|
item->setForeground(color);
|
2021-05-07 13:14:18 +09:00
|
|
|
|
item->setBackground(Qt::transparent);
|
2019-10-08 17:36:03 +08:00
|
|
|
|
}
|
2021-05-07 13:14:18 +09:00
|
|
|
|
setItemHoverColor();
|
2019-10-08 17:36:03 +08:00
|
|
|
|
const auto ratio = devicePixelRatioF();
|
2019-11-05 21:04:07 +08:00
|
|
|
|
QPixmap ret = ImageUtil::loadSvg(iconRight, ":/", ICON_SIZE, ratio);
|
2019-10-18 09:52:50 +08:00
|
|
|
|
m_volumeIconMax->setPixmap(ret);
|
|
|
|
|
|
2019-11-05 21:04:07 +08:00
|
|
|
|
ret = ImageUtil::loadSvg(iconLeft, ":/", ICON_SIZE, ratio);
|
2020-06-13 11:39:32 +08:00
|
|
|
|
m_volumeBtn->setIcon(ret);
|
2019-10-08 17:36:03 +08:00
|
|
|
|
}
|
2020-07-27 13:05:38 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief SoundApplet::startAddPort 添加端口前判断
|
|
|
|
|
* @param port 端口
|
|
|
|
|
*/
|
|
|
|
|
void SoundApplet::startAddPort(Port *port)
|
|
|
|
|
{
|
|
|
|
|
if (!containsPort(port) && port->direction() == Port::Out) {
|
|
|
|
|
m_ports.append(port);
|
|
|
|
|
addPort(port);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief SoundApplet::startRemovePort 移除端口前判断
|
|
|
|
|
* @param portId 端口
|
|
|
|
|
* @param cardId 声卡
|
|
|
|
|
*/
|
|
|
|
|
void SoundApplet::startRemovePort(const QString &portId, const uint &cardId)
|
|
|
|
|
{
|
|
|
|
|
Port *port = findPort(portId, cardId);
|
|
|
|
|
if (port) {
|
|
|
|
|
m_ports.removeOne(port);
|
|
|
|
|
port->deleteLater();
|
|
|
|
|
removePort(portId, cardId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SoundApplet::containsPort(const Port *port)
|
|
|
|
|
{
|
|
|
|
|
return findPort(port->id(), port->cardId()) != nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Port *SoundApplet::findPort(const QString &portId, const uint &cardId) const
|
|
|
|
|
{
|
|
|
|
|
for (Port *port : m_ports) {
|
|
|
|
|
if (port->id() == portId && port->cardId() == cardId) {
|
|
|
|
|
return port;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SoundApplet::addPort(const Port *port)
|
|
|
|
|
{
|
|
|
|
|
DStandardItem *pi = new DStandardItem;
|
2020-08-19 17:13:58 +08:00
|
|
|
|
QString deviceName = port->name() + "(" + port->cardName() + ")";
|
|
|
|
|
pi->setText(deviceName);
|
2020-07-27 13:05:38 +08:00
|
|
|
|
pi->setBackground(Qt::transparent);
|
|
|
|
|
pi->setForeground(QBrush(Qt::black));
|
|
|
|
|
pi->setData(QVariant::fromValue<const Port *>(port), Qt::WhatsThisPropertyRole);
|
|
|
|
|
|
2020-08-19 17:13:58 +08:00
|
|
|
|
connect(port, &Port::nameChanged, this, [ = ](const QString &str) {
|
|
|
|
|
QString devName = str + "(" + port->cardName() + ")";
|
|
|
|
|
pi->setText(devName);
|
|
|
|
|
});
|
|
|
|
|
connect(port, &Port::cardNameChanged, this, [ = ](const QString &str) {
|
|
|
|
|
QString devName = port->name() + "(" + str + ")";
|
|
|
|
|
pi->setText(devName);
|
2020-07-27 13:05:38 +08:00
|
|
|
|
});
|
|
|
|
|
connect(port, &Port::isActiveChanged, this, [ = ](bool isActive) {
|
|
|
|
|
pi->setCheckState(isActive ? Qt::CheckState::Checked : Qt::CheckState::Unchecked);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (port->isActive()) {
|
|
|
|
|
pi->setCheckState(Qt::CheckState::Checked);
|
|
|
|
|
}
|
|
|
|
|
m_model->appendRow(pi);
|
|
|
|
|
m_model->sort(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SoundApplet::removePort(const QString &portId, const uint &cardId)
|
|
|
|
|
{
|
|
|
|
|
auto rmFunc = [ = ](QStandardItemModel * model) {
|
|
|
|
|
for (int i = 0; i < model->rowCount();) {
|
|
|
|
|
auto item = model->item(i);
|
|
|
|
|
auto port = item->data(Qt::WhatsThisPropertyRole).value<const Port *>();
|
|
|
|
|
if (port->id() == portId && cardId == port->cardId()) {
|
|
|
|
|
model->removeRow(i);
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
rmFunc(m_model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief SoundApplet::activePort 激活某一指定端口
|
|
|
|
|
* @param portId 端口
|
|
|
|
|
* @param cardId 声卡
|
|
|
|
|
*/
|
|
|
|
|
void SoundApplet::activePort(const QString &portId, const uint &cardId)
|
|
|
|
|
{
|
|
|
|
|
for (Port *it : m_ports) {
|
|
|
|
|
if (it->id() == portId && it->cardId() == cardId) {
|
|
|
|
|
it->setIsActive(true);
|
2020-10-16 21:26:49 +08:00
|
|
|
|
enableDevice(true);
|
2020-07-27 13:05:38 +08:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
it->setIsActive(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-16 21:26:49 +08:00
|
|
|
|
void SoundApplet::updateCradsInfo()
|
2020-07-27 13:05:38 +08:00
|
|
|
|
{
|
|
|
|
|
QDBusInterface inter("com.deepin.daemon.Audio", "/com/deepin/daemon/Audio","com.deepin.daemon.Audio",QDBusConnection::sessionBus(), this);
|
|
|
|
|
QString info = inter.property("CardsWithoutUnavailable").toString();
|
|
|
|
|
if(m_deviceInfo != info){
|
|
|
|
|
cardsChanged(info);
|
|
|
|
|
m_deviceInfo = info;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-16 21:26:49 +08:00
|
|
|
|
void SoundApplet::enableDevice(bool flag)
|
|
|
|
|
{
|
2021-03-20 12:10:45 +08:00
|
|
|
|
QString status = m_gsettings ? m_gsettings->get(GSETTING_SOUND_OUTPUT_SLIDER).toString() : "Enabled";
|
2021-02-27 15:50:24 +08:00
|
|
|
|
if ("Disabled" == status ) {
|
|
|
|
|
m_volumeSlider->setEnabled(false);
|
|
|
|
|
} else if ("Enabled" == status) {
|
|
|
|
|
m_volumeSlider->setEnabled(flag);
|
|
|
|
|
}
|
2020-10-16 21:26:49 +08:00
|
|
|
|
m_volumeBtn->setEnabled(flag);
|
|
|
|
|
m_soundShow->setEnabled(flag);
|
|
|
|
|
m_volumeIconMax->setEnabled(flag);
|
|
|
|
|
m_deviceLabel->setEnabled(flag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SoundApplet::disableAllDevice()
|
|
|
|
|
{
|
|
|
|
|
for (Port *port : m_ports) {
|
|
|
|
|
port->setIsActive(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief SoundApplet::removeLastDevice
|
|
|
|
|
* 移除最后一个设备
|
|
|
|
|
*/
|
|
|
|
|
void SoundApplet::removeLastDevice()
|
|
|
|
|
{
|
|
|
|
|
if (m_ports.count() == 1 && m_ports.at(0)) {
|
|
|
|
|
m_lastPort = new Port(m_model);
|
|
|
|
|
m_lastPort->setId(m_ports.at(0)->id());
|
|
|
|
|
m_lastPort->setName(m_ports.at(0)->name());
|
|
|
|
|
m_lastPort->setDirection(m_ports.at(0)->direction());
|
|
|
|
|
m_lastPort->setCardId(m_ports.at(0)->cardId());
|
|
|
|
|
m_lastPort->setCardName(m_ports.at(0)->cardName());
|
|
|
|
|
startRemovePort(m_ports.at(0)->id(), m_ports.at(0)->cardId());
|
|
|
|
|
qDebug() << "remove last output device";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief SoundApplet::removeDisabledDevice 移除禁用设备
|
|
|
|
|
* @param portId
|
|
|
|
|
* @param cardId
|
|
|
|
|
*/
|
|
|
|
|
void SoundApplet::removeDisabledDevice(QString portId, unsigned int cardId)
|
|
|
|
|
{
|
|
|
|
|
startRemovePort(portId, cardId);
|
|
|
|
|
if (m_defSinkInter->activePort().name == portId && m_defSinkInter->card() == cardId) {
|
|
|
|
|
enableDevice(false);
|
|
|
|
|
disableAllDevice();
|
|
|
|
|
}
|
|
|
|
|
qDebug() << "remove disabled output device";
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 15:50:24 +08:00
|
|
|
|
void SoundApplet::updateVolumeSliderStatus(const QString &status)
|
|
|
|
|
{
|
|
|
|
|
bool flag = true;
|
|
|
|
|
if ("Enabled" == status) {
|
|
|
|
|
flag = true;
|
|
|
|
|
} else if ("Disabled" == status) {
|
|
|
|
|
flag = false;
|
|
|
|
|
}
|
|
|
|
|
m_volumeSlider->setEnabled(flag);
|
|
|
|
|
m_volumeBtn->setEnabled(flag);
|
|
|
|
|
m_volumeIconMax->setEnabled(flag);
|
|
|
|
|
|
|
|
|
|
flag = "Hiden" != status;
|
|
|
|
|
m_volumeSlider->setVisible(flag);
|
|
|
|
|
m_volumeBtn->setVisible(flag);
|
|
|
|
|
m_volumeIconMax->setVisible(flag);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-27 13:05:38 +08:00
|
|
|
|
void SoundApplet::haldleDbusSignal(const QDBusMessage &msg)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(msg)
|
|
|
|
|
|
2020-10-16 21:26:49 +08:00
|
|
|
|
updateCradsInfo();
|
2020-07-27 13:05:38 +08:00
|
|
|
|
}
|
2020-09-17 16:00:45 +08:00
|
|
|
|
|
|
|
|
|
void SoundApplet::updateListHeight()
|
|
|
|
|
{
|
|
|
|
|
//设备数多于10个时显示滚动条,固定高度
|
|
|
|
|
int count = m_model->rowCount();
|
|
|
|
|
if (m_model->rowCount() > 10) {
|
|
|
|
|
count = 10;
|
|
|
|
|
m_listView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
|
|
|
|
} else {
|
|
|
|
|
m_listView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int visualHeight = 0;
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
visualHeight += m_listView->visualRect(m_model->index(i, 0)).height();
|
|
|
|
|
|
|
|
|
|
int listMargin = m_listView->contentsMargins().top() + m_listView->contentsMargins().bottom();
|
|
|
|
|
//显示声音设备列表高度 = 设备的高度 + 间隔 + 边距
|
|
|
|
|
int viewHeight = visualHeight + m_listView->spacing() * count * 2 + listMargin;
|
|
|
|
|
// 设备信息高度 = 设备标签 + 分隔线 + 滚动条 + 间隔
|
2020-12-09 15:43:45 +08:00
|
|
|
|
int labelHeight = m_deviceLabel->height() > m_soundShow->height() ? m_deviceLabel->height() : m_soundShow->height();
|
|
|
|
|
int infoHeight = labelHeight + m_separator->height() + m_volumeSlider->height() + m_centralLayout->spacing() * 3 + DEVICE_SPACING;
|
2020-09-17 16:00:45 +08:00
|
|
|
|
int margain = m_centralLayout->contentsMargins().top() + m_centralLayout->contentsMargins().bottom();
|
|
|
|
|
//整个界面高度 = 显示声音设备列表高度 + 设备信息高度 + 边距
|
|
|
|
|
int totalHeight = viewHeight + infoHeight + margain;
|
2021-05-19 17:41:06 +09:00
|
|
|
|
//加上分割线占用的高度,否则显示界面高度不够显示,会造成音频列表item最后一项比其它项的高度小
|
2021-05-07 13:14:18 +09:00
|
|
|
|
m_listView->setFixedHeight(viewHeight + SEPARATOR_HEIGHT);
|
2020-09-17 16:00:45 +08:00
|
|
|
|
setFixedHeight(totalHeight);
|
2021-05-07 13:14:18 +09:00
|
|
|
|
m_centralWidget->setFixedHeight(totalHeight + SEPARATOR_HEIGHT);
|
2020-09-17 16:00:45 +08:00
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-16 21:26:49 +08:00
|
|
|
|
void SoundApplet::portEnableChange(unsigned int cardId, QString portId)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(cardId)
|
|
|
|
|
Q_UNUSED(portId)
|
|
|
|
|
m_deviceInfo = "";
|
|
|
|
|
updateCradsInfo();
|
|
|
|
|
}
|