Skip to content

Conversation

@mhduiy
Copy link
Contributor

@mhduiy mhduiy commented Jan 31, 2026

  1. Fixed incorrect D-Bus interface pointer checks in PersonalizationDBusProxy (m_WMInter -> m_EffectsInter) for effect- related operations
  2. Added isEffectSupported() method to check if specific window effects are available on the system
  3. Extended PersonalizationModel to track supported effects list via new supportEffects property
  4. Updated X11Worker to query and populate supported effects (magiclamp, scale, kwin4_effect_translucency)
  5. Fixed CustomComboBox.qml to properly handle model data access when using textRole, iconNameRole, enableRole, and visibleRole
  6. Updated WindowEffectPage.qml to conditionally show minimize effect and transparent window move options based on actual system support
  7. Extended copyright years from 2023/2024 to 2026 across modified files

Log: Fixed window effect options not appearing correctly when effects are unsupported
Log: Fixed combo box display issues with role-based model data access

fix: 修复窗口特效功能可用性和组合框模型处理问题

  1. 修复PersonalizationDBusProxy中特效相关操作的D-Bus接口指针检查错误 (m_WMInter -> m_EffectsInter)
  2. 新增isEffectSupported()方法用于检查系统是否支持特定窗口特效
  3. 扩展PersonalizationModel以通过新的supportEffects属性跟踪支持的特效 列表
  4. 更新X11Worker以查询并填充支持的特效(magiclamp、scale、 kwin4_effect_translucency)
  5. 修复CustomComboBox.qml在使用textRole、iconNameRole、enableRole和 visibleRole时正确处理模型数据访问
  6. 更新WindowEffectPage.qml根据实际系统支持条件显示最小化特效和透明窗口 移动选项
  7. 将修改文件的版权年份从2023/2024扩展到2026

Log: 修复特效不支持时窗口特效选项显示不正确的问题
Log: 修复组合框基于角色的模型数据访问显示问题

PMS: BUG-294317
PMS: BUG-301403
PMS: BUG-301407

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 @mhduiy, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy

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

1. Fixed incorrect D-Bus interface pointer checks in
PersonalizationDBusProxy (m_WMInter -> m_EffectsInter) for effect-
related operations
2. Added isEffectSupported() method to check if specific window effects
are available on the system
3. Extended PersonalizationModel to track supported effects list via new
supportEffects property
4. Updated X11Worker to query and populate supported effects (magiclamp,
scale, kwin4_effect_translucency)
5. Fixed CustomComboBox.qml to properly handle model data access when
using textRole, iconNameRole, enableRole, and visibleRole
6. Updated WindowEffectPage.qml to conditionally show minimize effect
and transparent window move options based on actual system support
7. Extended copyright years from 2023/2024 to 2026 across modified files

Log: Fixed window effect options not appearing correctly when effects
are unsupported
Log: Fixed combo box display issues with role-based model data access

fix: 修复窗口特效功能可用性和组合框模型处理问题

1. 修复PersonalizationDBusProxy中特效相关操作的D-Bus接口指针检查错误
(m_WMInter -> m_EffectsInter)
2. 新增isEffectSupported()方法用于检查系统是否支持特定窗口特效
3. 扩展PersonalizationModel以通过新的supportEffects属性跟踪支持的特效
列表
4. 更新X11Worker以查询并填充支持的特效(magiclamp、scale、
kwin4_effect_translucency)
5. 修复CustomComboBox.qml在使用textRole、iconNameRole、enableRole和
visibleRole时正确处理模型数据访问
6. 更新WindowEffectPage.qml根据实际系统支持条件显示最小化特效和透明窗口
移动选项
7. 将修改文件的版权年份从2023/2024扩展到2026

Log: 修复特效不支持时窗口特效选项显示不正确的问题
Log: 修复组合框基于角色的模型数据访问显示问题

PMS: BUG-294317
PMS: BUG-301403
PMS: BUG-301407
@deepin-ci-robot
Copy link

deepin pr auto review

Git Diff 代码审查报告

总体评价

这段代码主要实现了窗口特效功能的增强,包括添加了对特效支持情况的检测和动态显示。代码整体结构合理,但存在一些可以改进的地方,特别是在错误处理、性能优化和代码健壮性方面。

详细审查意见

1. 语法逻辑

personalizationdbusproxy.cpp

  • loadEffectisEffectLoaded 和新添加的 isEffectSupported 函数中,检查 m_EffectsInter 是否为空是好的做法,但可以统一错误处理逻辑。

x11worker.cpp

  • active() 方法中连续调用 isEffectSupported 三次,可以考虑优化为一次调用获取所有支持的效果列表。
  • setMiniEffect() 方法中的 switch 语句只处理了两种情况(0和1),但注释显示可能存在更多效果类型。建议添加 default 分支处理未知情况。

2. 代码质量

personalizationdbusproxy.cpp

  • 建议为 isEffectSupported 函数添加文档注释,说明其功能和返回值含义。
  • 函数返回 QDBusPendingReply<bool> 直接转换为 bool 可能会忽略错误情况,建议添加错误处理。

personalizationmodel.cpp

  • setSupportEffects 方法中的相等性检查 if (m_supportEffects == value) 是好的实践,可以避免不必要的信号发射。

x11worker.cpp

  • 建议将特效名称常量(如 EffectMiniLampArg)集中管理,避免分散在代码中。
  • active() 方法中的特效支持检查可以提取为单独的方法,提高代码可读性。

CustomComboBox.qml

  • QML 代码中的复杂条件表达式可以简化,提高可读性。

3. 代码性能

x11worker.cpp

  • 连续三次调用 isEffectSupported 可能造成性能开销,建议修改为一次调用获取所有支持的效果列表。

WindowEffectPage.qml

  • minimizeEffectObject 中,每次访问 supportEffects 都会触发 indexOf 操作,可以考虑缓存结果。

4. 代码安全

personalizationdbusproxy.cpp

  • DBus 调用没有错误处理,可能导致未捕获的异常。建议添加错误处理逻辑。

x11worker.cpp

  • 没有对 m_personalizationDBusProxym_model 进行空指针检查,如果这些指针未正确初始化可能导致崩溃。

改进建议

1. personalizationdbusproxy.cpp

bool PersonalizationDBusProxy::isEffectSupported(const QString &name)
{
    if (!m_EffectsInter) {
        return false;
    }
    
    QDBusPendingReply<bool> reply = m_EffectsInter->asyncCall(QStringLiteral("isEffectSupported"), QVariant::fromValue(name));
    reply.waitForFinished();
    
    if (reply.isError()) {
        qWarning() << "Failed to check effect support:" << reply.error().message();
        return false;
    }
    
    return reply.value();
}

2. x11worker.cpp

void X11Worker::active()
{
    // ... 其他代码 ...
    
    // 获取所有支持的效果列表
    QStringList allSupportedEffects;
    const QStringList effectsToCheck = {EffectMiniLampArg, EffectMiniScaleArg, EffectMoveWindowArg};
    
    for (const QString &effect : effectsToCheck) {
        if (m_personalizationDBusProxy->isEffectSupported(effect)) {
            allSupportedEffects.append(effect);
        }
    }
    
    m_model->setSupportEffects(allSupportedEffects);
}

void X11Worker::setMiniEffect(int effect)
{
    switch (effect) {
    case 0:
        qCDebug(DdcPersonnalizationX11Worker) << EffectMiniScaleArg;
        m_personalizationDBusProxy->unloadEffect(EffectMiniLampArg);
        m_model->setMiniEffect(effect);
        break;
    case 1:
        qCDebug(DdcPersonnalizationX11Worker) << EffectMiniLampArg;
        m_personalizationDBusProxy->loadEffect(EffectMiniLampArg);
        m_model->setMiniEffect(effect);
        break;
    default:
        qCWarning(DdcPersonnalizationX11Worker) << "Unknown mini effect type:" << effect;
        break;
    }
}

3. CustomComboBox.qml

D.ComboBox {
    id: control
    flat: true
    
    delegate: D.MenuItem {
        id: menuItem
        useIndicatorPadding: true
        // 简化条件表达式
        text: {
            if (!control.textRole) return modelData;
            var source = Array.isArray(control.model) ? modelData : model;
            return source[control.textRole] !== undefined ? source[control.textRole] : modelData[control.textRole];
        }
        // 其他属性类似处理
    }
}

4. WindowEffectPage.qml

DccObject {
    id: minimizeEffectObject
    property var supportEffects: dccData.model.supportEffects
    
    // 添加计算属性来缓存结果
    readonly property bool hasScaleEffect: supportEffects.indexOf("scale") !== -1
    readonly property bool hasMagicLampEffect: supportEffects.indexOf("magiclamp") !== -1
    
    name: "minimizeEffect"
    parentName: "personalization/windowEffect/windowSettingsGroup"
    displayName: qsTr("Window Minimize Effect")
    visible: dccData.model.windowEffectType <= InterfaceEffectListview.WindowEffectType.Best 
            && dccData.platformName() !== "wayland"
            && (hasScaleEffect || hasMagicLampEffect)
    
    page: CustomComboBox {
        flat: true
        currentIndex: dccData.model.miniEffect
        textRole: "text"
        visibleRole: "support"
        
        model: [
            {text: qsTr("Scale"), support: minimizeEffectObject.hasScaleEffect}, 
            {text: qsTr("Magic Lamp"), support: minimizeEffectObject.hasMagicLampEffect}
        ]
        
        onCurrentIndexChanged: {
            dccData.worker.setMiniEffect(currentIndex)
        }
    }
}

总结

这段代码实现了窗口特效功能的增强,整体结构合理,但在错误处理、性能优化和代码健壮性方面还有改进空间。建议按照上述建议进行修改,以提高代码质量和可维护性。

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.

2 participants