delay to init power item, wait dbus valid

Change-Id: I7e6627499652cdd2c0e17e9c9546215f8f55a8dd
This commit is contained in:
石博文 2017-03-28 09:57:37 +08:00 committed by Deepin Code Review
parent 2845f78ef7
commit 165a64f858
Notes: Deepin Code Review 2017-03-28 14:02:02 +08:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Tue, 28 Mar 2017 14:02:02 +0800
Reviewed-on: https://cr.deepin.io/21857
Project: dde/dde-dock
Branch: refs/heads/master
2 changed files with 22 additions and 2 deletions

View File

@ -68,9 +68,8 @@ QWidget *ShutdownPlugin::itemTipsWidget(const QString &itemKey)
void ShutdownPlugin::init(PluginProxyInterface *proxyInter)
{
m_proxyInter = proxyInter;
m_proxyInter->itemAdded(this, SHUTDOWN_KEY);
displayModeChanged(displayMode());
delayLoader();
}
const QString ShutdownPlugin::itemCommand(const QString &itemKey)
@ -180,3 +179,23 @@ void ShutdownPlugin::requestContextMenu(const QString &itemKey)
{
m_proxyInter->requestContextMenu(this, itemKey);
}
void ShutdownPlugin::delayLoader()
{
static int retryTimes = 0;
++retryTimes;
if (m_powerInter->isValid() || retryTimes > 10)
{
qDebug() << "load power item, dbus valid:" << m_powerInter->isValid();
m_proxyInter->itemAdded(this, SHUTDOWN_KEY);
displayModeChanged(displayMode());
} else {
qDebug() << "load power failed, wait and retry" << retryTimes;
// wait and retry
QTimer::singleShot(1000, this, &ShutdownPlugin::delayLoader);
}
}

View File

@ -30,6 +30,7 @@ public:
private:
void updateBatteryVisible();
void requestContextMenu(const QString &itemKey);
void delayLoader();
private:
PluginWidget *m_shutdownWidget;