Skip to content

pick v20 -v25.#411

Merged
deepin-bot[bot] merged 3 commits intolinuxdeepin:masterfrom
pppanghu77:master
Dec 18, 2025
Merged

pick v20 -v25.#411
deepin-bot[bot] merged 3 commits intolinuxdeepin:masterfrom
pppanghu77:master

Conversation

@pppanghu77
Copy link
Contributor

@pppanghu77 pppanghu77 commented Dec 18, 2025

build

add the toast info for audio device disabled

Log: add the toast info for audio device disabled
Task: https://pms.uniontech.com/task-view-378245.html
modify the 'Text to Speech' reading text

Log: modify the 'Text to Speech' reading text
Task: https://pms.uniontech.com/task-view-378245.html
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Sorry @pppanghu77, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@github-actions
Copy link

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "src/widgets/window.cpp": [
        {
            "line": "    QString key = \"base/enable\";",
            "line_number": 389,
            "rule": "S106",
            "reason": "Var naming | 64f28539d9"
        }
    ]
}

@pppanghu77 pppanghu77 changed the title pick v20 -v25 pick v20 -v25. Dec 18, 2025
This commit includes the following changes:

  1. **Qt5 Compatibility Fix in dtextedit.cpp**:
     - Replaced `QList::removeIf()` (Qt6 only) with Qt5-compatible approach using `QSet::toSet()` and reverse iteration with `removeAt()`
     - This fixes compilation issues on Qt5-based systems

  2. **Code Cleanup in tabbar.cpp**:
     - Removed dead code block wrapped in `#if 0` preprocessor directive
     - Removed orphaned debug output `qDebug() << "Exit createDragPixmapFromTab"`

  3. **Header Fixes**:
     - Added `Q_DECLARE_METATYPE(DockRect)` macro in com_deepin_dde_daemon_dock.h to properly register DockRect type with Qt's meta-object system
     - Added `mousePressEvent` declaration in tabbar.h
     - Added `slotStopReadingAction` slot declaration in dtextedit.h

  4. **Include Fixes**:
     - Added missing `#include <QDebug>` to multiple source files where qDebug() is used
     - Removed duplicate `#include "bottombar.h"` in bottombar.cpp

Log: Fix Qt5 compilation compatibility issue and clean up unused code in tab bar component

Task: https://pms.uniontech.com/task-view-383499.html
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这次代码变更进行审查:

  1. 语法逻辑:
  • 整体语法正确,符合C++规范
  • Qt版本条件编译使用正确(QT_VERSION_CHECK)
  • DBus接口调用规范
  1. 代码质量:
  • 新增了音频设备检测功能,但存在一些可以改进的地方:
    • checkAudioOutputDevice() 和 checkAudioInputDevice() 有大量重复代码,建议抽取公共逻辑
    • onAudioPortEnabledChanged() 中的错误提示信息相同,应该区分输入和输出设备
  1. 代码性能:
  • DBus调用可能会阻塞UI线程,建议考虑异步处理
  • JSON文档解析在每次调用时都重新进行,可以考虑缓存结果
  1. 代码安全:
  • QDBusReply没有检查超时情况
  • JSON解析没有做错误处理
  • 新增的Q_DECLARE_METATYPE(DockRect)可能导致二进制兼容性问题

改进建议:

  1. 重构音频设备检查代码:
bool TextEdit::checkAudioDevice(int direction)
{
    QDBusMessage msg = QDBusMessage::createMethodCall("com.deepin.daemon.Audio",
                                                      "/com/deepin/daemon/Audio",
                                                      "org.freedesktop.DBus.Properties",
                                                      "Get");
    msg << QString("com.deepin.daemon.Audio") << QString("CardsWithoutUnavailable");

    QDBusReply<QVariant> reply = QDBusConnection::sessionBus().call(msg);
    if (!reply.isValid()) {
        qWarning() << "Failed to get audio devices:" << reply.error().message();
        return false;
    }

    QJsonParseError error;
    QJsonDocument doc = QJsonDocument::fromJson(reply.value().toByteArray(), &error);
    if (error.error != QJsonParseError::NoError) {
        qWarning() << "Failed to parse audio device JSON:" << error.errorString();
        return false;
    }

    QJsonArray cards = doc.array();
    for (const QJsonValue &cardValue : cards) {
        QJsonObject card = cardValue.toObject();
        QJsonArray ports = card["Ports"].toArray();
        
        for (const QJsonValue &portValue : ports) {
            QJsonObject port = portValue.toObject();
            if (port["Direction"].toInt() == direction && port["Enabled"].toBool()) {
                return true;
            }
        }
    }
    return false;
}

bool TextEdit::checkAudioOutputDevice()
{
    return checkAudioDevice(1);
}

bool TextEdit::checkAudioInputDevice()
{
    return checkAudioDevice(2);
}
  1. 改进错误提示信息:
void TextEdit::onAudioPortEnabledChanged(quint32 cardId, const QString &portName, bool enabled)
{
    Q_UNUSED(cardId)
    Q_UNUSED(portName)
    
    if (!enabled) {
        bool hasOutputDevice = checkAudioOutputDevice();
        bool hasInputDevice = checkAudioInputDevice();
        
        if (!hasOutputDevice) {
            const QString message = tr("No audio output device was detected. Please ensure your speakers or headphones are properly connected and try again.");
            showAudioDeviceMessage(message);
        }
        
        if (!hasInputDevice) {
            const QString message = tr("No audio input device was detected. Please ensure your microphone is properly connected and try again.");
            showAudioDeviceMessage(message);
        }
    }
}

void TextEdit::showAudioDeviceMessage(const QString &message)
{
#ifdef DTKWIDGET_CLASS_DSizeMode
    Utils::sendFloatMessageFixedFont(this, QIcon(":/images/warning.svg"), message);
#else
    DMessageManager::instance()->sendMessage(this, QIcon(":/images/warning.svg"), message);
#endif
}
  1. 添加异步处理:
void TextEdit::checkAudioDeviceAsync(int direction, std::function<void(bool)> callback)
{
    QDBusMessage msg = QDBusMessage::createMethodCall("com.deepin.daemon.Audio",
                                                      "/com/deepin/daemon/Audio",
                                                      "org.freedesktop.DBus.Properties",
                                                      "Get");
    msg << QString("com.deepin.daemon.Audio") << QString("CardsWithoutUnavailable");

    QDBusPendingCall async = QDBusConnection::sessionBus().asyncCall(msg);
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this);
    
    connect(watcher, &QDBusPendingCallWatcher::finished, [direction, callback](QDBusPendingCallWatcher *watcher) {
        QDBusPendingReply<QVariant> reply = *watcher;
        bool result = false;
        
        if (reply.isValid()) {
            QJsonDocument doc = QJsonDocument::fromJson(reply.value().toByteArray());
            QJsonArray cards = doc.array();
            
            for (const QJsonValue &cardValue : cards) {
                QJsonObject card = cardValue.toObject();
                QJsonArray ports = card["Ports"].toArray();
                
                for (const QJsonValue &portValue : ports) {
                    QJsonObject port = portValue.toObject();
                    if (port["Direction"].toInt() == direction && port["Enabled"].toBool()) {
                        result = true;
                        break;
                    }
                }
            }
        }
        
        callback(result);
        watcher->deleteLater();
    });
}
  1. 添加缓存机制:
class TextEdit {
private:
    mutable QHash<int, bool> m_audioDeviceCache;
    QDateTime m_cacheUpdateTime;
    static const int CACHE_TIMEOUT_MS = 5000; // 5秒缓存超时
    
    bool isCacheValid() const {
        return m_cacheUpdateTime.isValid() && 
               m_cacheUpdateTime.msecsTo(QDateTime::currentDateTime()) < CACHE_TIMEOUT_MS;
    }
    
    bool checkAudioDeviceCached(int direction) {
        if (isCacheValid() && m_audioDeviceCache.contains(direction)) {
            return m_audioDeviceCache[direction];
        }
        
        bool result = checkAudioDevice(direction);
        m_audioDeviceCache[direction] = result;
        m_cacheUpdateTime = QDateTime::currentDateTime();
        return result;
    }
};

这些改进可以:

  1. 提高代码复用性
  2. 增强错误处理
  3. 避免UI阻塞
  4. 减少重复的DBus调用
  5. 提供更好的用户体验

@github-actions
Copy link

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "src/widgets/window.cpp": [
        {
            "line": "    QString key = \"base/enable\";",
            "line_number": 389,
            "rule": "S106",
            "reason": "Var naming | 64f28539d9"
        }
    ]
}

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, pppanghu77

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pppanghu77
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 18, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 215a90a into linuxdeepin:master Dec 18, 2025
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants