Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/dde-dock/sound/soundcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void SoundController::onDefaultSinkChanged(const QDBusObjectPath &path)

// 音量和静音状态变化时手动获取下另外一个的状态,有时候收不到 changed 信号
connect(m_defaultSinkInter, &DBusSink::MuteChanged, &SoundModel::ref(), [this] (bool value) {
SoundModel::ref().setVolume(m_defaultSinkInter->volume());
SoundModel::ref().setMute(m_defaultSinkInter->mute());
SoundModel::ref().setVolume(m_defaultSinkInter->volume());
});
connect(m_defaultSinkInter, &DBusSink::VolumeChanged, &SoundModel::ref(), [this] (double value) {
SoundModel::ref().setVolume(value);
Expand Down
11 changes: 6 additions & 5 deletions plugins/dde-dock/sound/soundview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ SoundView::SoundView(QWidget *parent)
});
connect(m_applet.data(), &SoundApplet::requestHideApplet, this, &SoundView::requestHideApplet);

refresh(SoundModel::ref().volume());
refresh();
}

QWidget *SoundView::tipsWidget()
{
refreshTips(std::min(150, SoundModel::ref().volume()), true);
refreshTips(true);
m_tipsLabel->resize(m_tipsLabel->sizeHint().width() + 10,
m_tipsLabel->sizeHint().height());

Expand Down Expand Up @@ -147,10 +147,10 @@ bool SoundView::eventFilter(QObject *watched, QEvent *event)
return QWidget::eventFilter(watched, event);
}

void SoundView::refresh(const int volume)
void SoundView::refresh()
{
refreshIcon();
refreshTips(volume, false);
refreshTips(false);
}

void SoundView::refreshIcon()
Expand All @@ -176,7 +176,7 @@ void SoundView::refreshIcon()
m_iconWidget->setIcon(QIcon::fromTheme(iconString));
}

void SoundView::refreshTips(const int volume, const bool force)
void SoundView::refreshTips(const bool force)
{
if (!force && !m_tipsLabel->isVisible())
return;
Expand All @@ -187,6 +187,7 @@ void SoundView::refreshTips(const int volume, const bool force)
if (SoundModel::ref().isMute()) {
m_tipsLabel->setText(QString(tr("Mute")));
} else {
auto volume = std::min(150, SoundModel::ref().volume());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Avoid magic number for max volume clamp

Define a named constant (e.g. MAX_VOLUME) or move the clamp into SoundModel so the view doesn’t use a hard-coded limit.

m_tipsLabel->setText(QString(tr("Volume %1").arg(QString::number(volume) + '%')));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Include the percent sign in the translatable string and simplify arg usage

Use tr("Volume %1% ").arg(volume) to include '%' in the translatable string and remove manual concatenation and extra QString wrappers.

Suggested change
m_tipsLabel->setText(QString(tr("Volume %1").arg(QString::number(volume) + '%')));
m_tipsLabel->setText(tr("Volume %1%").arg(volume));

}
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/dde-dock/sound/soundview.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SoundView : public QWidget
const QString contextMenu();
void invokeMenuItem(const QString menuId, const bool checked);
void refreshIcon();
void refreshTips(const int volume, const bool force = false);
void refreshTips(const bool force = false);
void setAppletMinHeight(int minHeight);

signals:
Expand All @@ -47,7 +47,7 @@ class SoundView : public QWidget
bool eventFilter(QObject *watched, QEvent *event) override;

private slots:
void refresh(const int volume);
void refresh();

private:
Dock::TipsWidget *m_tipsLabel;
Expand Down