sound plugin: delay load sound dbus

Change-Id: If63bf3c874f6fdc7094718a46dd98c87ecedc9e8
This commit is contained in:
石博文 2017-04-12 14:16:57 +08:00
parent fcbc2ba455
commit 9980c78957
Notes: Deepin Code Review 2017-04-12 14:36:57 +08:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Wed, 12 Apr 2017 14:36:56 +0800
Reviewed-on: https://cr.deepin.io/22229
Project: dde/dde-dock
Branch: refs/heads/master
2 changed files with 19 additions and 2 deletions

View File

@ -92,8 +92,7 @@ SoundApplet::SoundApplet(QWidget *parent)
connect(m_audioInter, &DBusAudio::DefaultSinkChanged, this, static_cast<void (SoundApplet::*)()>(&SoundApplet::defaultSinkChanged));
connect(this, static_cast<void (SoundApplet::*)(DBusSink*) const>(&SoundApplet::defaultSinkChanged), this, &SoundApplet::onVolumeChanged);
QMetaObject::invokeMethod(this, "defaultSinkChanged", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "sinkInputsChanged", Qt::QueuedConnection);
QTimer::singleShot(1, this, &SoundApplet::delayLoad);
}
int SoundApplet::volumeValue() const
@ -174,3 +173,20 @@ void SoundApplet::toggleMute()
{
m_defSinkInter->SetMute(!m_defSinkInter->mute());
}
void SoundApplet::delayLoad()
{
static int retry_times = 0;
++retry_times;
const bool valid = m_audioInter->isValid();
qDebug() << "load sound dbus, valid = " << valid << ", retry = " << retry_times;
if (valid || retry_times > 10)
{
QMetaObject::invokeMethod(this, "defaultSinkChanged", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "sinkInputsChanged", Qt::QueuedConnection);
} else {
QTimer::singleShot(1000, this, &SoundApplet::delayLoad);
}
}

View File

@ -32,6 +32,7 @@ private slots:
void volumeSliderValueChanged();
void sinkInputsChanged();
void toggleMute();
void delayLoad();
private:
QWidget *m_centralWidget;