dde-dock/plugins/sound/soundplugin.cpp
donghualin a41df224f6 fix: 增加对控制中心设置不同主题下图标的接口
1、任务栏插件接口中增加根据主题来获取不同图标的接口
2、声音、蓝牙、电源、虚拟键盘、回收站等插件完善控制中心的接口
3、任务栏图标的显示根据不同的主题来获取

Log: 完善对控制中心设置不同主题的接口
Influence: 在控制中心切换主题,观察图标是否发生变化
Bug: https://pms.uniontech.com/bug-view-172365.html
Change-Id: Ia02193c9ebcf10559195c6fb8fe6227f581e165b
2022-11-23 16:08:34 +08:00

168 lines
3.9 KiB
C++

/*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
*
* 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/>.
*/
#include "soundplugin.h"
#include "soundaccessible.h"
#include "soundwidget.h"
#include "sounddeviceswidget.h"
#include <QDebug>
#include <QAccessible>
#define STATE_KEY "enable"
SoundPlugin::SoundPlugin(QObject *parent)
: QObject(parent)
, m_soundItem(nullptr)
, m_soundWidget(nullptr)
{
QAccessible::installFactory(soundAccessibleFactory);
}
const QString SoundPlugin::pluginName() const
{
return "sound";
}
const QString SoundPlugin::pluginDisplayName() const
{
return tr("Sound");
}
void SoundPlugin::init(PluginProxyInterface *proxyInter)
{
m_proxyInter = proxyInter;
if (m_soundItem)
return;
m_soundItem.reset(new SoundItem);
m_soundWidget.reset(new SoundWidget);
m_soundWidget->setFixedHeight(60);
m_soundDeviceWidget.reset(new SoundDevicesWidget);
if (!pluginIsDisable()) {
m_proxyInter->itemAdded(this, SOUND_KEY);
connect(m_soundWidget.data(), &SoundWidget::rightIconClick, this, [ this, proxyInter ] {
proxyInter->requestSetAppletVisible(this, QUICK_ITEM_KEY, true);
});
}
}
void SoundPlugin::pluginStateSwitched()
{
m_proxyInter->saveValue(this, STATE_KEY, pluginIsDisable());
refreshPluginItemsVisible();
}
bool SoundPlugin::pluginIsDisable()
{
return !m_proxyInter->getValue(this, STATE_KEY, true).toBool();
}
QWidget *SoundPlugin::itemWidget(const QString &itemKey)
{
if (itemKey == SOUND_KEY)
return m_soundItem.data();
if (itemKey == QUICK_ITEM_KEY)
return m_soundWidget.data();
return nullptr;
}
QWidget *SoundPlugin::itemTipsWidget(const QString &itemKey)
{
if (itemKey == SOUND_KEY)
return m_soundItem->tipsWidget();
return nullptr;
}
QWidget *SoundPlugin::itemPopupApplet(const QString &itemKey)
{
if (itemKey == SOUND_KEY)
return m_soundItem->popupApplet();
if (itemKey == QUICK_ITEM_KEY)
return m_soundDeviceWidget.data();
return nullptr;
}
void SoundPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked)
{
if (itemKey == SOUND_KEY) {
m_soundItem->invokeMenuItem(menuId, checked);
}
}
int SoundPlugin::itemSortKey(const QString &itemKey)
{
const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient);
return m_proxyInter->getValue(this, key, 2).toInt();
}
void SoundPlugin::setSortKey(const QString &itemKey, const int order)
{
const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient);
m_proxyInter->saveValue(this, key, order);
}
void SoundPlugin::refreshIcon(const QString &itemKey)
{
if (itemKey == SOUND_KEY) {
m_soundItem->refreshIcon();
}
}
void SoundPlugin::pluginSettingsChanged()
{
refreshPluginItemsVisible();
}
QIcon SoundPlugin::icon(const DockPart &)
{
return m_soundItem->pixmap();
}
QIcon SoundPlugin::icon(const DockPart &dockPart, int themeType)
{
return m_soundItem->pixmap(themeType);
}
PluginsItemInterface::PluginStatus SoundPlugin::status() const
{
return SoundPlugin::Active;
}
void SoundPlugin::refreshPluginItemsVisible()
{
if (pluginIsDisable())
m_proxyInter->itemRemoved(this, SOUND_KEY);
else
m_proxyInter->itemAdded(this, SOUND_KEY);
}