Skip to content

feat: add cancel button state parameter for bluetooth dialog#429

Merged
fly602 merged 1 commit intolinuxdeepin:masterfrom
fly602:master
Apr 21, 2026
Merged

feat: add cancel button state parameter for bluetooth dialog#429
fly602 merged 1 commit intolinuxdeepin:masterfrom
fly602:master

Conversation

@fly602
Copy link
Copy Markdown
Contributor

@fly602 fly602 commented Apr 21, 2026

  1. Add new CancelBtnState constant (index 4) for command line argument parsing
  2. Introduce cancelable variable to control cancel button visibility
  3. Read optional 5th parameter to determine cancel button state
  4. Default cancelable to true when 5th parameter is not provided
  5. Pass cancelable state to PinCodeDialog constructor instead of hardcoded true
  6. Update debug output to include isCancelBtnShown information

Log: Added cancel button visibility parameter for Bluetooth pairing dialog

Influence:

  1. Test Bluetooth pairing dialog with cancel button enabled (pass "true" as 5th argument)
  2. Test Bluetooth pairing dialog with cancel button disabled (pass "false" as 5th argument)
  3. Verify backward compatibility when only 4 arguments are provided (should default to showing cancel button)
  4. Test dialog behavior during pairing process with different cancel button states
  5. Verify command line argument parsing with various parameter combinations

feat: 新增蓝牙弹窗取消按钮状态参数

  1. 添加新的 CancelBtnState 常量(索引 4)用于命令行参数解析
  2. 引入 cancelable 变量控制取消按钮的可见性
  3. 读取可选的第 5 个参数来确定取消按钮状态
  4. 当未提供第 5 个参数时,cancelable 默认为 true
  5. 将 cancelable 状态传递给 PinCodeDialog 构造函数,替代硬编码的 true
  6. 更新调试输出以包含 isCancelBtnShown 信息

Log: 新增蓝牙配对弹窗取消按钮可见性参数

Influence:

  1. 测试启用取消按钮的蓝牙配对弹窗(第 5 个参数传 "true")
  2. 测试禁用取消按钮的蓝牙配对弹窗(第 5 个参数传 "false")
  3. 验证仅提供 4 个参数时的向后兼容性(应默认显示取消按钮)
  4. 测试不同取消按钮状态下配对过程中的弹窗行为
  5. 验证各种参数组合下的命令行参数解析

PMS: BUG-343047
Change-Id: I617b0b24a0709f4c9395879a9b17df69b705cf60

Summary by Sourcery

Add support for controlling the Bluetooth PIN code dialog’s cancel button visibility via an optional command line parameter and propagate this state into the dialog.

New Features:

  • Introduce an optional command line parameter to specify whether the Bluetooth pairing dialog’s cancel button is shown.

Enhancements:

  • Log the resolved cancel button visibility state for the Bluetooth pairing dialog in debug output.

1. Add new CancelBtnState constant (index 4) for command line argument
parsing
2. Introduce cancelable variable to control cancel button visibility
3. Read optional 5th parameter to determine cancel button state
4. Default cancelable to true when 5th parameter is not provided
5. Pass cancelable state to PinCodeDialog constructor instead of
hardcoded true
6. Update debug output to include isCancelBtnShown information

Log: Added cancel button visibility parameter for Bluetooth pairing
dialog

Influence:
1. Test Bluetooth pairing dialog with cancel button enabled (pass "true"
as 5th argument)
2. Test Bluetooth pairing dialog with cancel button disabled (pass
"false" as 5th argument)
3. Verify backward compatibility when only 4 arguments are provided
(should default to showing cancel button)
4. Test dialog behavior during pairing process with different cancel
button states
5. Verify command line argument parsing with various parameter
combinations

feat: 新增蓝牙弹窗取消按钮状态参数

1. 添加新的 CancelBtnState 常量(索引 4)用于命令行参数解析
2. 引入 cancelable 变量控制取消按钮的可见性
3. 读取可选的第 5 个参数来确定取消按钮状态
4. 当未提供第 5 个参数时,cancelable 默认为 true
5. 将 cancelable 状态传递给 PinCodeDialog 构造函数,替代硬编码的 true
6. 更新调试输出以包含 isCancelBtnShown 信息

Log: 新增蓝牙配对弹窗取消按钮可见性参数

Influence:
1. 测试启用取消按钮的蓝牙配对弹窗(第 5 个参数传 "true")
2. 测试禁用取消按钮的蓝牙配对弹窗(第 5 个参数传 "false")
3. 验证仅提供 4 个参数时的向后兼容性(应默认显示取消按钮)
4. 测试不同取消按钮状态下配对过程中的弹窗行为
5. 验证各种参数组合下的命令行参数解析

PMS: BUG-343047
Change-Id: I617b0b24a0709f4c9395879a9b17df69b705cf60
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 21, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a command-line controlled cancel-button visibility flag to the Bluetooth pairing dialog and threads that state through argument parsing, logging, and the PinCodeDialog construction while preserving backward compatibility.

Sequence diagram for Bluetooth dialog cancel button state handling

sequenceDiagram
    actor User
    participant Shell
    participant BluetoothDialogApp as dde_bluetooth_dialog
    participant PinCodeDialog

    User->>Shell: Run dde_bluetooth_dialog with args
    Shell->>BluetoothDialogApp: argc, argv
    BluetoothDialogApp->>BluetoothDialogApp: Parse arguslist
    BluetoothDialogApp->>BluetoothDialogApp: Validate arg count >= 4
    alt arguslist size >= 5
        BluetoothDialogApp->>BluetoothDialogApp: cancelable = (arguslist[4] == "true")
    else only 4 args
        BluetoothDialogApp->>BluetoothDialogApp: cancelable = true
    end
    BluetoothDialogApp->>BluetoothDialogApp: qDebug PingCode, DevicePath, PingTime, isCancelBtnShown
    BluetoothDialogApp->>PinCodeDialog: create with PingCode, DevicePath, PingTime, cancelable
    User->>PinCodeDialog: Interact (enter PIN, optional Cancel)
    PinCodeDialog-->>BluetoothDialogApp: Result (paired, cancelled, timeout)
Loading

File-Level Changes

Change Details Files
Make cancel button visibility configurable via an optional 5th command-line argument and propagate it into the Bluetooth PIN code dialog.
  • Introduce a new CancelBtnState index constant for the 5th command-line parameter.
  • Add a cancelable boolean defaulting to true and set it based on the 5th argument value being the string "true" when provided.
  • Extend the debug logging to print the evaluated cancel button visibility state.
  • Pass the computed cancelable flag to the PinCodeDialog constructor instead of a hardcoded true value.
dde-bluetooth-dialog/src/main.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@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.

Hey - I've left some high level feedback:

  • The cancelable flag currently treats any 5th argument other than the exact string "true" as false; consider explicitly handling/validating supported values (e.g., "true"/"false" or 1/0) and logging unexpected inputs so accidental typos do not silently disable the cancel button.
  • For readability and consistency with the rest of the qDebug() call, consider separating the "Ping Time" label and value with << instead of using string concatenation ("Ping Time:" << arguslist[PingTime]) so all fields are logged in a uniform way.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `cancelable` flag currently treats any 5th argument other than the exact string "true" as `false`; consider explicitly handling/validating supported values (e.g., "true"/"false" or 1/0) and logging unexpected inputs so accidental typos do not silently disable the cancel button.
- For readability and consistency with the rest of the `qDebug()` call, consider separating the "Ping Time" label and value with `<<` instead of using string concatenation (`"Ping Time:" << arguslist[PingTime]`) so all fields are logged in a uniform way.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

以下是对这段代码变更的审查意见,包括语法逻辑、代码质量、代码性能和代码安全方面的改进建议:

1. 语法逻辑

  • 版权年份更新:将版权年份从2022更新到2026是合理的,表示项目会持续维护到该年份。
  • 参数检查逻辑:新增了对第5个参数(CancelBtnState)的检查,逻辑正确。但存在一个潜在问题:代码先检查参数数量是否大于3,然后才检查第5个参数。如果参数数量为4,代码会忽略第4个参数,直接使用默认值true。建议明确说明第4个参数的用途或添加检查。
  • 字符串比较:使用arguslist[CancelBtnState] == "true"来判断布尔值是可行的,但建议使用更严格的方式,如QString::compareQVariant::toBool,以避免大小写敏感问题。

2. 代码质量

  • 常量命名:新增的常量CancelBtnState命名清晰,符合命名规范。
  • 日志输出:新增的日志输出isCancelBtnShown:与之前的日志风格一致,但建议统一使用引号包裹键名,如"isCancelBtnShown:"
  • 代码可读性cancelable变量的命名清晰,但建议在注释中说明其用途,尤其是在PinCodeDialog的构造函数调用处。

3. 代码性能

  • 参数访问:多次访问arguslist(如arguslist[PingCode]arguslist[DevicePath]等)可能会影响性能,尤其是在参数列表较长时。建议将频繁访问的参数提取到局部变量中。
  • 字符串比较:直接使用==比较字符串效率较低,建议使用QString::compareQVariant::toBool

4. 代码安全

  • 参数边界检查:当前代码检查参数数量是否大于3,但未检查arguslist的实际大小是否足够访问PingCodeDevicePathPingTimeCancelBtnState。建议添加更严格的边界检查,例如:
    if (arguslist.size() < 4) {
        qDebug() << "number of parameters must be greater than 3";
        return -1;
    }
  • 字符串转换:直接使用arguslist[CancelBtnState] == "true"可能存在安全隐患,如果传入的参数不是"true""false",可能会导致意外行为。建议使用QVariant::toBool或添加默认值处理:
    bool cancelable = (arguslist.size() >= 5) ? (arguslist[CancelBtnState] == "true") : true;

5. 改进后的代码示例

// SPDX-FileCopyrightText: 2016 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include <DApplication>
#include <DLog>
#include <QDebug>

#include "pincode-dialog.h"

DCORE_USE_NAMESPACE

const int PingCode = 1;
const int DevicePath = 2;
const int PingTime = 3;
const int CancelBtnState = 4;

int main(int argc, char *argv[])
{
    DApplication app(argc, argv);
    app.setOrganizationName("deepin");
    app.setApplicationName("dde-bluetooth-dialog");

    DLogManager::registerConsoleAppender();
    DLogManager::registerFileAppender();

    QStringList arguslist = app.arguments();
    if (arguslist.size() < 4) {
        qDebug() << "number of parameters must be greater than 3";
        return -1;
    }

    // 提取参数到局部变量以提高性能
    QString pingCode = arguslist[PingCode];
    QString devicePath = arguslist[DevicePath];
    QString pingTime = arguslist[PingTime];
    bool cancelable = (arguslist.size() >= 5) ? (arguslist[CancelBtnState].toLower() == "true") : true;

    qDebug() << "PingCode:" << pingCode
             << "Device Path:" << devicePath
             << "Ping Time:" << pingTime
             << "isCancelBtnShown:" << cancelable;

    PinCodeDialog dialog(pingCode, devicePath, pingTime, cancelable);

#if (defined QT_DEBUG) && (defined CHECK_ACCESSIBLENAME)
    AccessibilityCheckerEx checker;
    checker.setOutputFormat(DAccessibilityChecker::FullFormat);
    checker.start();
#endif

    return dialog.exec();
}

总结

  • 优点:代码逻辑清晰,新增功能合理,命名规范。
  • 改进点:增强参数边界检查、优化字符串比较、提高代码可读性和安全性。
  • 建议:在后续开发中,建议统一参数处理逻辑,并添加更多注释以提高代码可维护性。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23, fly602

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

@fly602 fly602 merged commit 58594de into linuxdeepin:master Apr 21, 2026
16 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.

3 participants