Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: QT6 adaptation #75

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,18 @@ set(CMAKE_AUTORCC ON)
#打开全局uic
set(CMAKE_AUTOUIC ON)

set(QT_VERSION_MAJOR 6)
if (${QT_VERSION_MAJOR} GREATER_EQUAL 6)
set(DTK_VERSION 6)
endif()

set(QT Core Gui Widgets Network DBus Sql LinguistTools Svg Test WebChannel WebSockets)
find_package(Qt5 COMPONENTS ${QT} REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${QT} REQUIRED)

#应用DTK库
find_package(DtkWidget REQUIRED)
find_package(DtkCore REQUIRED)
find_package(DtkGui REQUIRED)
find_package(Dtk${DTK_VERSION}Widget REQUIRED)
find_package(Dtk${DTK_VERSION}Core REQUIRED)
find_package(Dtk${DTK_VERSION}Gui REQUIRED)

#安装
# qm files.
Expand Down
18 changes: 10 additions & 8 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ Build-Depends:
debhelper (>= 12),
cmake,
pkg-config,
libqt5widgets5,
qtbase5-dev,
qttools5-dev,
libqt5network5,
libqt5webchannel5-dev,
libqt5websockets5-dev,
libdtkwidget-dev,
libdtkgui-dev,
libqt6widgets6,
qt6-base-dev,
qt6-tools-dev,
qt6-svg-dev,
qt6-l10n-tools,
libqt6network6,
qt6-webchannel-dev,
qt6-websockets-dev,
libdtk6widget-dev,
libdtk6gui-dev,
libdframeworkdbus-dev,
libgtest-dev,
libgmock-dev,
Expand Down
3 changes: 2 additions & 1 deletion src/include/ui/queryurl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class QueryUrl : public QObject
Q_OBJECT

public:
explicit QueryUrl(QObject *parent = nullptr);
explicit QueryUrl(QObject *parent = nullptr)
{};
private:
};

Expand Down
4 changes: 2 additions & 2 deletions src/src/aria2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set (DWM_ARIA_HEADERS
)

#需要生成的moc文件,输出文件名称放在变量 mocfiles中,必须在find QT5 package才能调用
QT5_WRAP_CPP (DWM_ARIA_HEADERS_MOC ${DWM_ARIA_HEADERS})
qt_wrap_cpp (DWM_ARIA_HEADERS_MOC ${DWM_ARIA_HEADERS})

#设置输出dll的名称、类型(动态库、静态库)及所用到的文件
add_library(dlmaria2 SHARED
Expand All @@ -28,7 +28,7 @@ add_library(dlmaria2 SHARED
${DWM_ARIA_HEADERS_MOC}
)

target_link_libraries(dlmaria2 dlmlog Qt5::Core)
target_link_libraries(dlmaria2 dlmlog Qt${QT_VERSION_MAJOR}::Core)

#install(TARGETS dlmaria2 DESTINATION lib)

48 changes: 47 additions & 1 deletion src/src/aria2/aria2rpcinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,51 @@ bool Aria2RPCInterface::startUp()
//QProcess::execute("touch", QStringList() << dhtFile); //创建dht文件
//QProcess::execute("touch", QStringList() << dht6File); //创建dht6文件

#if QT_VERSION_MAJOR > 5
QStringList opt;
opt += "--enable-rpc=true"; //启动RPC
opt += "--rpc-secret=" + getToken();
opt += "--rpc-listen-port=" + this->m_rpcPort; //RPC监听的端口
opt += "--check-certificate=false"; //停用rpc身份验证
opt += "--rpc-allow-origin-all=true"; // 允许所有来源
opt += "--rpc-max-request-size=99999999"; //设置rpc最大接收数
opt += "--rpc-save-upload-metadata=true"; //

//opt += "--not-conf=true";//不使用配置文件
if (!this->m_configPath.isEmpty()) {
opt += "--conf-path=" + this->m_configPath; //加载指定的配置文件
}
if (!this->m_defaultDownloadPath.isEmpty()) {
opt += "--dir=" + this->m_defaultDownloadPath; //配置默认下载路径。优先级高于配置文件,已移动到配置文件中
}
opt += "--continue=true"; //http续传配置
opt += "--disable-ipv6"; //禁用ipv6
//opt += "--seed-time=0";//bt完成不做种
opt += "--bt-metadata-only=true"; //仅下载bt metadata,不自动发起follow下载
opt += "--bt-save-metadata=true"; //保存magnet metadata到同目录下.torrent文件
opt += "--follow-torrent=false"; //当下载的文件是以.torrent结尾的,是否继续下载。true,是;false,否,只下载torrent文件;mem,不写文件保存在内存
//opt += "--follow-metalink=false";//类似torrent
opt += "--bt-remove-unselected-file=true";
//opt += "--input-file=" + inputFile;
opt += "--save-session=" + sessionCacheFile;
opt += "--save-session-interval=" + saveSessionInterval;
opt += "--enable-dht=true"; //启动dht文件
opt += "--enable-dht6=false"; //禁用dht6文件
opt += "--dht-file-path=" + dhtFile;
opt += "--dht-file-path6=" + dht6File;
opt += "--follow-metalink=false";
if(QSysInfo::currentCpuArchitecture() == "loongarch64"){
opt += "--async-dns=false";
}

QProcess proc; // = new QProcess;
proc.setStandardOutputFile("/dev/null");
proc.setStandardErrorFile("/dev/null");
proc.setProgram(m_basePath + m_aria2cCmd);
proc.setArguments(opt);
proc.startDetached();
proc.waitForStarted();
#else
QString opt;
opt += " --enable-rpc=true"; //启动RPC
opt += " --rpc-secret=" + getToken();
Expand Down Expand Up @@ -131,13 +176,14 @@ bool Aria2RPCInterface::startUp()
opt += " --async-dns=false";
}

// qDebug() << m_basePath + m_aria2cCmd << opt.join(' ');
// qDebug() << m_basePath + m_aria2cCmd << opt.join(' ');

QProcess proc; // = new QProcess;
proc.setStandardOutputFile("/dev/null");
proc.setStandardErrorFile("/dev/null");
proc.startDetached("sh -c \"" + m_basePath + m_aria2cCmd + " " + opt + "\"");
proc.waitForStarted();
#endif

// proc.start("ulimit -n 40");
// bool b = proc.waitForFinished();
Expand Down
4 changes: 2 additions & 2 deletions src/src/database/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ set (DWM_DATABASE_HEADERS
)

#需要生成的moc文件,输出文件名称放在变量 mocfiles中,必须在find QT5 package才能调用
QT5_WRAP_CPP (DWM_DATABASE_HEADERS_MOC ${DWM_DATABASE_HEADERS})
qt_wrap_cpp (DWM_DATABASE_HEADERS_MOC ${DWM_DATABASE_HEADERS})

#设置输出dll的名称、类型(动态库、静态库)及所用到的文件
add_library(dlmdatabase SHARED
Expand All @@ -26,6 +26,6 @@ add_library(dlmdatabase SHARED
${DWM_DATABASE_HEADERS_MOC}
)

target_link_libraries(dlmdatabase dlmlog Qt5::Core Qt5::Widgets Qt5::Sql)
target_link_libraries(dlmdatabase dlmlog Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Sql)

#install(TARGETS dlmdatabase DESTINATION lib)
2 changes: 1 addition & 1 deletion src/src/database/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ DataBase::DataBase()
//如果数据库文件不存在
if (!databaseFile.isFile()) {
//拷贝数据库文件
qDebug() << "error: no db file "; //<< QString(UOS_DONWLOAD_DATABASE_PATH) + UOS_DOWNLOAD_DATABASE_FILENAME << QString(_dataBasePath) + UOS_DOWNLOAD_DATABASE_FILENAME << endl;
qDebug() << "error: no db file "; //<< QString(UOS_DONWLOAD_DATABASE_PATH) + UOS_DOWNLOAD_DATABASE_FILENAME << QString(_dataBasePath) + UOS_DOWNLOAD_DATABASE_FILENAME << Qt::endl;
QFile::copy(QString(UOS_DONWLOAD_DATABASE_PATH) + UOS_DOWNLOAD_DATABASE_OLD_FILENAME,
dbPath);
QString strold = UOS_DONWLOAD_DATABASE_PATH + "downloader.db";
Expand Down
2 changes: 1 addition & 1 deletion src/src/downloader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ add_executable(downloader main.cpp
accessiblewidget.cpp
)

target_link_libraries(downloader dlmcontrolui dlmlog Qt5::Core)
target_link_libraries(downloader dlmcontrolui dlmlog Qt${QT_VERSION_MAJOR}::Core)

#INSTALL(TARGETS downloader DESTINATION share/downloader)
#install(TARGETS downloader DESTINATION bin)
Expand Down
11 changes: 11 additions & 0 deletions src/src/downloader/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <DApplication>

Check warning on line 32 in src/src/downloader/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DGuiApplicationHelper>

Check warning on line 33 in src/src/downloader/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DGuiApplicationHelper> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DMainWindow>

Check warning on line 34 in src/src/downloader/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DMainWindow> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DWidgetUtil>

Check warning on line 35 in src/src/downloader/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DWidgetUtil> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DSwitchButton>

Check warning on line 36 in src/src/downloader/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DSwitchButton> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#if QT_VERSION_MAJOR <= 5
#include <DApplicationSettings>

Check warning on line 38 in src/src/downloader/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DApplicationSettings> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#endif
#include <QTranslator>

Check warning on line 40 in src/src/downloader/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTranslator> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QClipboard>

Check warning on line 41 in src/src/downloader/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QClipboard> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QSharedMemory>

Check warning on line 42 in src/src/downloader/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QSharedMemory> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QBuffer>
#include <QCommandLineParser>
#include <QDBusMessage>
Expand Down Expand Up @@ -70,9 +73,11 @@

auto e = QProcessEnvironment::systemEnvironment();
QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
#if QT_VERSION_MAJOR <= 5
if (XDG_SESSION_TYPE == QLatin1String("x11")) {
DlmApplication::loadDXcbPlugin();
}
#endif
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
DlmApplication a(argc, argv);
a.setQuitOnLastWindowClosed(false);
Expand Down Expand Up @@ -134,9 +139,11 @@
char *to = static_cast<char *>(sharedMemory.data());
memset(to, 0, 199);
}
#if QT_VERSION_MAJOR <= 5
// 保存程序的窗口主题设置
DApplicationSettings as;
Q_UNUSED(as)
#endif
QDir dirCheck;
QString LogPath = QString("%1/%2/%3/Log/")
.arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation))
Expand Down Expand Up @@ -204,9 +211,13 @@
bool checkProcessExist()
{
QProcess process;
QStringList list;

Check warning on line 214 in src/src/downloader/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Unused variable: list
#if QT_VERSION_MAJOR > 5
process.start("pgrep", {"downloader"});
#else
process.start("pgrep downloader");
process.start();
#endif
process.waitForStarted(1000);
process.waitForFinished(1000);
QString str = process.readAll();
Expand Down
14 changes: 12 additions & 2 deletions src/src/extensionService/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set (DWM_EXTENSIONSERVICE_HEADERS
)

#需要生成的moc文件,输出文件名称放在变量 mocfiles中,必须在find QT5 package才能调用
QT5_WRAP_CPP (DWM_EXTENSIONSERVICE_HEADERS_MOC ${DWM_EXTENSIONSERVICE_HEADERS})
qt_wrap_cpp (DWM_EXTENSIONSERVICE_HEADERS_MOC ${DWM_EXTENSIONSERVICE_HEADERS})

#设置输出dll的名称、类型(动态库、静态库)及所用到的文件
add_executable(dlmextensionservice
Expand All @@ -30,6 +30,16 @@ add_executable(dlmextensionservice
${DWM_EXTENSIONSERVICE_HEADERS_MOC}
)

target_link_libraries(dlmextensionservice Qt5::Core Qt5::Widgets Qt5::WebChannel Qt5::WebSockets Qt5::Network Qt5::DBus dtkcore dtkwidget )
target_link_libraries(dlmextensionservice
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::WebChannel
Qt${QT_VERSION_MAJOR}::WebSockets
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::DBus
Dtk${DTK_VERSION}::Core
Dtk${DTK_VERSION}::Gui
Dtk${DTK_VERSION}::Widget
)

install(TARGETS dlmextensionservice DESTINATION bin)
2 changes: 1 addition & 1 deletion src/src/log/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ ADD_DEFINITIONS(-DLM_LOG_LIB )
add_library(dlmlog SHARED
log.cpp
)
target_link_libraries(dlmlog Qt5::Core)
target_link_libraries(dlmlog Qt${QT_VERSION_MAJOR}::Core)

#install(TARGETS dlmlog DESTINATION lib)
8 changes: 4 additions & 4 deletions src/src/log/log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void CheckLogTime()
auto logList = GetLogList();
for (int i = 0; i < logList.size() - 1; ++i) {
auto logInfo = logList[i];
auto createdTime = logInfo.created();
auto createdTime = logInfo.birthTime();
auto elapseDays = createdTime.daysTo(curTime);
if (elapseDays > _logDaysRemain) {
auto logPath = logInfo.absoluteFilePath();
Expand Down Expand Up @@ -120,7 +120,7 @@ bool CheckRotateSize()
bool CheckRotateTimePoint()
{
QFileInfo curLogInfo(_logFile);
auto curLogCreateDate = curLogInfo.created();
auto curLogCreateDate = curLogInfo.birthTime();
auto curDate = QDateTime::currentDateTime();
auto dayElapse = curLogCreateDate.daysTo(curDate);
if (dayElapse >= 1) {
Expand Down Expand Up @@ -152,7 +152,7 @@ void WriteVersion()
QTextStream ts(&outFile);
auto appName = QCoreApplication::applicationName();
auto version = QCoreApplication::applicationVersion();
ts << appName << " " << version << endl;
ts << appName << " " << version << Qt::endl;
outFile.close();
s_logMutex.unlock();
}
Expand Down Expand Up @@ -207,7 +207,7 @@ void customLogMessageHandler(QtMsgType type, const QMessageLogContext &ctx, cons
return;
}
QTextStream ts(&outFile);
ts << message.toUtf8() << endl;
ts << message.toUtf8() << Qt::endl;
std::cout << msg.toStdString() << std::endl;
outFile.close();
s_logMutex.unlock();
Expand Down
20 changes: 10 additions & 10 deletions src/src/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ set (UDLC_UI_HEADERS


#需要生成的moc文件,输出文件名称放在变量 mocfiles中,必须在find QT5 package才能调用
QT5_WRAP_CPP (UDLC_UI_HEADERS_MOC ${UDLC_UI_HEADERS})
qt_wrap_cpp (UDLC_UI_HEADERS_MOC ${UDLC_UI_HEADERS})

#添加资源文件
set(QRC_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/resource/resource.qrc)
qt5_add_resources(QRC_FILES ${QRC_SOURCE_FILES})
qt_add_resources(QRC_FILES ${QRC_SOURCE_FILES})

#设置输出dll的名称、类型(动态库、静态库)及所用到的文件
add_library(dlmcontrolui SHARED
Expand Down Expand Up @@ -129,14 +129,14 @@ target_link_libraries(dlmcontrolui
dlmlog
dlmaria2
dlmdatabase
${DtkCore_LIBRARIES}
${DtkWidget_LIBRARIES}
${DtkGui_LIBRARIES}
Qt5::Core
Qt5::Network
Qt5::Widgets
Qt5::Svg
Qt5::DBus
Dtk${DTK_VERSION}::Core
Dtk${DTK_VERSION}::Gui
Dtk${DTK_VERSION}::Widget
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Svg
Qt${QT_VERSION_MAJOR}::DBus
)

#install(TARGETS dlmcontrolui DESTINATION lib)
Expand Down
2 changes: 1 addition & 1 deletion src/src/ui/createTask/btheaderview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void headerView::onPalettetypechanged(DGuiApplicationHelper::ColorType type)
// p.setColor(QPalette::Base, QColor(0,0,0,20));
QColor c = DGuiApplicationHelper::instance()->applicationPalette().base().color();
c.setAlpha(70);
p.setColor(DPalette::Background, c);
p.setColor(DPalette::Window, c);
//p.setColor(QPalette::Base, DGuiApplicationHelper::instance()->applicationPalette().base().color());
}
setPalette(p);
Expand Down
10 changes: 7 additions & 3 deletions src/src/ui/createTask/btinfodialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ void BtInfoDialog::initUI()
QString str = getFileEditText(m_defaultDownloadDir);
m_editDir->setText(str);
m_editDir->setClearButtonEnabled(false);
#if QT_VERSION_MAJOR > 5
m_editDir->setFileMode(QFileDialog::Directory);
#else
m_editDir->setFileMode(QFileDialog::DirectoryOnly);
#endif
m_editDir->lineEdit()->setEnabled(false);
connect(m_editDir, &DFileChooserEdit::fileChoosed, this, &BtInfoDialog::onFilechoosed);
QList<DSuggestButton *> btnList = m_editDir->findChildren<DSuggestButton *>();
Expand Down Expand Up @@ -631,7 +635,7 @@ void BtInfoDialog::onPaletteTypeChanged(DGuiApplicationHelper::ColorType type)
m_delegate->setHoverColor(DGuiApplicationHelper::instance()->applicationPalette().frameBorder());

if (themeType == 1) {
p.setColor(QPalette::Background, Qt::white);
p.setColor(QPalette::Window, Qt::white);
m_delegate->setHoverColor(QColor(0, 0, 0, 13));

QPalette pal;
Expand Down Expand Up @@ -665,7 +669,7 @@ QString BtInfoDialog::getFileEditText(QString text)
for (int i = 0; i < flieEditText.size(); i++) {
//判断字符中是否包含中文或者大写字母
if ((flieEditText[i] >= 'A' && flieEditText[i] <= 'Z')
|| (flieEditText[i] >= 0x4E00 && flieEditText[i] <= 0x9FA5)) {
|| (flieEditText[i] >= QChar(0x4E00) && flieEditText[i] <= QChar(0x9FA5))) {
count++;
}
}
Expand All @@ -675,7 +679,7 @@ QString BtInfoDialog::getFileEditText(QString text)
for (int i = 0; i < text.size(); i++) {
//判断字符中是否包含中文或者大写字母
if ((text[i] >= 'A' && text[i] <= 'Z')
|| (text[i] >= 0x4E00 && text[i] <= 0x9FA5)) {
|| (text[i] >= QChar(0x4E00) && text[i] <= QChar(0x9FA5))) {
hasLongStr++;
}
}
Expand Down
Loading
Loading