From bd79a5a89c9140ff67513cced513c5b7123567ae Mon Sep 17 00:00:00 2001 From: XMuli Date: Wed, 24 Jan 2024 23:53:43 +0800 Subject: [PATCH] fix: support for mingw and msvg build programming and chore: clean code, and add comment information --- GuiHelper/guiapplicationhelper.cpp | 7 +++-- GuiHelper/guiapplicationhelper.h | 5 ++++ LICENSE | 2 +- ShotX.pro | 17 ++++------- about.cpp | 6 +++- about.h | 5 ++++ convert_to_utf8_bom.py | 48 ++++++++++++++++++++++++++++++ debian/changelog | 6 ++-- main.cpp | 5 ++++ mainwindow.cpp | 5 ++++ mainwindow.h | 5 ++++ screenshots.cpp | 5 ++++ screenshots.h | 5 ++++ systeminfo.cpp | 5 ++++ systeminfo.h | 5 ++++ toolboxwindow.cpp | 5 ++++ toolboxwindow.h | 5 ++++ trayiconwindow.cpp | 5 ++++ trayiconwindow.h | 5 ++++ 19 files changed, 132 insertions(+), 19 deletions(-) create mode 100644 convert_to_utf8_bom.py diff --git a/GuiHelper/guiapplicationhelper.cpp b/GuiHelper/guiapplicationhelper.cpp index af5a60e..a4d2d28 100644 --- a/GuiHelper/guiapplicationhelper.cpp +++ b/GuiHelper/guiapplicationhelper.cpp @@ -1,10 +1,13 @@ -#include "guiapplicationhelper.h" +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli +#include "guiapplicationhelper.h" #include GuiApplicationHelper::GuiApplicationHelper() { - } inline static int adjustColorValue(int base, qint8 increment, int max = 255) diff --git a/GuiHelper/guiapplicationhelper.h b/GuiHelper/guiapplicationhelper.h index bd8d381..1bb5fd4 100644 --- a/GuiHelper/guiapplicationhelper.h +++ b/GuiHelper/guiapplicationhelper.h @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli + #ifndef GUIAPPLICATIONHELPER_H #define GUIAPPLICATIONHELPER_H diff --git a/LICENSE b/LICENSE index 97a5612..183d630 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 偕臧 +Copyright (c) 2020~2024 XMuli Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/ShotX.pro b/ShotX.pro index 502861c..fd617c4 100644 --- a/ShotX.pro +++ b/ShotX.pro @@ -1,20 +1,13 @@ -QT += core gui +# SPDX-License-Identifier: MIT +# SPDX-FileCopyrightText: 2020-2024 XMuli +# SPDX-GitHub: https://github.com/XMuli/shotx +# SPDX-Author: XMuli +QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - CONFIG += c++11 - -# The following define makes your compiler emit warnings if you use -# any Qt feature that has been marked deprecated (the exact warnings -# depend on your compiler). Please consult the documentation of the -# deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS -# You can also make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - SOURCES += \ GuiHelper/guiapplicationhelper.cpp \ main.cpp \ diff --git a/about.cpp b/about.cpp index 5c59e44..513d7a5 100644 --- a/about.cpp +++ b/about.cpp @@ -1,6 +1,10 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli + #include "about.h" #include "ui_about.h" - #include About::About(QWidget *parent) : diff --git a/about.h b/about.h index 360749f..7dfb843 100644 --- a/about.h +++ b/about.h @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli + #ifndef ABOUT_H #define ABOUT_H diff --git a/convert_to_utf8_bom.py b/convert_to_utf8_bom.py new file mode 100644 index 0000000..773444a --- /dev/null +++ b/convert_to_utf8_bom.py @@ -0,0 +1,48 @@ +import os +import subprocess + +try: + import chardet +except ImportError: + print('chardet is not installed. Installing...') + subprocess.run(['pip', 'install', 'chardet']) + import chardet + +# 获取当前路径 +current_dir = os.getcwd() + +# 遍历当前目录及子目录下的所有 .h .cpp 文件 +file_list = [] +for root, dirs, files in os.walk(current_dir): + for filename in files: + if filename.endswith('.h') or filename.endswith('.cpp'): + filepath = os.path.join(root, filename) + file_list.append(filepath) + +# 打印文件信息 +print(f'{"序号":<5} {"文件名":<50} {"原来格式":<20} {"转换后格式":<20} {"是否转换成功":<15}') +success_count = 0 +for i, filepath in enumerate(file_list, 1): + with open(filepath, 'rb') as f: + # 检测原来的编码格式 + before_encoding = chardet.detect(f.read())['encoding'] + if before_encoding is None: + before_encoding = 'unknown' + # 转换编码格式为 UTF-8 BOM + try: + with open(filepath, 'r', encoding=before_encoding) as f: + content = f.read() + with open(filepath, 'w', encoding='utf-8-sig') as f: + f.write(content) + success = True + success_count += 1 + except: + success = False + # 检测转换后的编码格式 + with open(filepath, 'rb') as f: + after_encoding = chardet.detect(f.read())['encoding'] + if after_encoding is None: + after_encoding = 'unknown' + # 打印文件信息 + print(f'{i:<5} {filepath:<50} {before_encoding:<20} {after_encoding:<20} {"Yes" if success else "No":<15}') +print(f'Total: {len(file_list)}, success: {success_count}, failed: {len(file_list)-success_count}') diff --git a/debian/changelog b/debian/changelog index 6b64930..24cd6ae 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,5 @@ -shotx (1.0-1) unstable; urgency=medium +shotx (2.0-1) unstable; urgency=medium - * Initial release (Closes: #nnnn) + * Cleaning Code, and Ensure build success - -- unknown Sat, 20 Feb 2021 15:41:21 +0800 + -- unknown Wen, 24 Jan 2024 23:45:21 +0800 diff --git a/main.cpp b/main.cpp index e5cc96d..2546dcd 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli + #include "mainwindow.h" #include "screenshots.h" #include "trayiconwindow.h" diff --git a/mainwindow.cpp b/mainwindow.cpp index 8bf103b..e53556a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli + #include "mainwindow.h" MainWindow::MainWindow(QWidget *parent) diff --git a/mainwindow.h b/mainwindow.h index 169a041..d524209 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli + #ifndef MAINWINDOW_H #define MAINWINDOW_H diff --git a/screenshots.cpp b/screenshots.cpp index 5fd0d03..2e336d1 100644 --- a/screenshots.cpp +++ b/screenshots.cpp @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli + #include "screenshots.h" #include diff --git a/screenshots.h b/screenshots.h index d1f92e5..926a489 100644 --- a/screenshots.h +++ b/screenshots.h @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli + #ifndef SCREENSHOTS_H #define SCREENSHOTS_H diff --git a/systeminfo.cpp b/systeminfo.cpp index ded8cb0..402e189 100644 --- a/systeminfo.cpp +++ b/systeminfo.cpp @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli + #include "systeminfo.h" #include diff --git a/systeminfo.h b/systeminfo.h index e485f5a..c0334df 100644 --- a/systeminfo.h +++ b/systeminfo.h @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli + #ifndef SYSTEMINFO_H #define SYSTEMINFO_H diff --git a/toolboxwindow.cpp b/toolboxwindow.cpp index fb6e9e0..1cfb639 100644 --- a/toolboxwindow.cpp +++ b/toolboxwindow.cpp @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli + #include "screenshots.h" #include "toolboxwindow.h" diff --git a/toolboxwindow.h b/toolboxwindow.h index b5fa9cd..f907f01 100644 --- a/toolboxwindow.h +++ b/toolboxwindow.h @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli + #ifndef TOOLBOXWINDOW_H #define TOOLBOXWINDOW_H diff --git a/trayiconwindow.cpp b/trayiconwindow.cpp index a181472..b692ae5 100644 --- a/trayiconwindow.cpp +++ b/trayiconwindow.cpp @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli + #include "trayiconwindow.h" #include diff --git a/trayiconwindow.h b/trayiconwindow.h index b5c0166..6e3598e 100644 --- a/trayiconwindow.h +++ b/trayiconwindow.h @@ -1,3 +1,8 @@ +// SPDX-License-Identifier: MIT +// SPDX-FileCopyrightText: 2020-2024 XMuli +// SPDX-GitHub: https://github.com/XMuli/shotx +// SPDX-Author: XMuli + #ifndef TRAYICONWINDOW_H #define TRAYICONWINDOW_H