feat(main): Improve command-line save path handling with full file pa…#791
feat(main): Improve command-line save path handling with full file pa…#791deepin-bot[bot] merged 1 commit into
Conversation
…th support - Reorder command-line argument processing to handle save-path before screenshot mode options - Add parsePathArgument() method to distinguish between directory paths and complete file paths - Support full file path specification with format detection (PNG, JPEG, BMP) - Add m_shotWithFullPath flag to track whether user specified a complete file path - Extract and store file name and format from full path arguments - Update saveAction() to use specified file path directly when provided via command-line - Improve logging with qCInfo for better debugging of path handling logic - Prevent default screenshot from launching when save-path option is set - Ensure directory creation before saving when using command-line specified paths - Refactor savePath() method to handle both directory and full file path modes
deepin pr auto reviewGit Diff 代码审查报告总体评价这次代码修改主要实现了对截图保存路径的增强功能,允许用户指定完整文件路径(包括文件名和格式)而不仅仅是目录路径。代码整体结构清晰,新增了几个辅助函数来处理路径解析和应用设置,提高了代码的可维护性。 语法逻辑分析1. 参数处理逻辑改进 (src/main.cpp)// 检查是否有其他截图模式参数
bool hasOtherMode = cmdParser.isSet(delayOption) ||
cmdParser.isSet(fullscreenOption) ||
cmdParser.isSet(topWindowOption) ||
cmdParser.isSet(prohibitNotifyOption) ||
cmdParser.isSet(screenRecordFullScreenOption);
// 如果设置了 save-path 且有其他模式,只设置路径不启动截图
if (cmdParser.isSet(savePathOption) && hasOtherMode) {
window.setSavePath(cmdParser.value(savePathOption));
qCDebug(dsrApp) << "Save path set to:" << cmdParser.value(savePathOption);
}优点:
建议:
2. 路径解析函数 (src/main_window.cpp)bool MainWindow::parsePathArgument(const QString &path, QString &outDir, QString &outFileName, QString &outFormat)
{
if (path.isEmpty()) {
qCWarning(dsrApp) << "parsePathArgument: 输入路径为空";
return false;
}
QFileInfo fileInfo(path);
QString suffix = fileInfo.suffix().toLower();
// 检查是否为支持的图片格式
bool isSupportedFormat = (suffix == "png" || suffix == "jpg" || suffix == "jpeg" || suffix == "bmp");
// 如果是支持的图片格式,且不是已存在的目录,则认为是文件路径
if (isSupportedFormat && !fileInfo.isDir()) {
// 这是一个完整的文件路径
outDir = fileInfo.absolutePath();
outFileName = fileInfo.fileName();
// 转换格式名称
if (suffix == "png") {
outFormat = "PNG";
} else if (suffix == "jpg" || suffix == "jpeg") {
outFormat = "JPEG";
} else if (suffix == "bmp") {
outFormat = "BMP";
}
qCInfo(dsrApp) << "parsePathArgument: 完整文件路径 - 目录:" << outDir
<< ", 文件名:" << outFileName << ", 格式:" << outFormat;
return true;
} else {
// 这是一个目录路径
outDir = path;
outFileName.clear();
outFormat.clear();
qCInfo(dsrApp) << "parsePathArgument: 目录路径:" << outDir;
return false;
}
}优点:
建议:
代码质量优点
改进建议
代码性能
代码安全
其他建议
总结这次代码修改实现了对截图保存路径的增强功能,整体代码质量较高,逻辑清晰。主要改进点在于:
建议的改进主要集中在:
总体而言,这是一次有价值的代码改进,增强了功能的同时保持了良好的代码质量。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengzhongyuan365-dev, lzwind The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
7b7ea33
into
linuxdeepin:develop/snipe
…th support