diff --git a/CMakeLists.txt b/CMakeLists.txt index a2f7942..f9c6b15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ +cmake_minimum_required (VERSION 3.5) project(zeit) -cmake_minimum_required (VERSION 3.1.0) option(BUILD_TESTS "Build tests" OFF) @@ -11,21 +11,26 @@ set(CRONTAB_V "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") file(READ rev ZEIT_REVISION LIMIT 9) -set(QT_MIN_VERSION "5.7.1") -find_package (Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS - Core - Gui - Widgets - Test -) - -# root actions support -find_package(KF5Auth) -if(KF5Auth_FOUND) - find_package(KF5CoreAddons REQUIRED) - if(KF5CoreAddons_FOUND) - set(BUILD_HELPER TRUE) - endif() +if(WITH_QT6) + find_package (Qt6 6.2.0 CONFIG REQUIRED COMPONENTS Core Gui Widgets Test) + # root actions support KF6 + find_package(KF6Auth) + if(KF6Auth_FOUND) + find_package(KF6CoreAddons REQUIRED) + if(KF6CoreAddons_FOUND) + set(BUILD_HELPER TRUE) + endif() + endif() +else() + find_package (Qt5 5.14.0 CONFIG REQUIRED COMPONENTS Core Gui Widgets Test) + # root actions support KF5 + find_package(KF5Auth) + if(KF5Auth_FOUND) + find_package(KF5CoreAddons REQUIRED) + if(KF5CoreAddons_FOUND) + set(BUILD_HELPER TRUE) + endif() + endif() endif() set(CMAKE_AUTOMOC ON) diff --git a/crontablib/CMakeLists.txt b/crontablib/CMakeLists.txt index f30a4fd..b2f5210 100644 --- a/crontablib/CMakeLists.txt +++ b/crontablib/CMakeLists.txt @@ -36,13 +36,24 @@ set(crontablib_HDRS add_library(crontab SHARED ${crontablib_SRCS}) -target_link_libraries(crontab Qt5::Core Qt5::Gui) -target_include_directories(crontab PRIVATE Qt5::Core Qt5::Gui - ${CMAKE_CURRENT_BINARY_DIR}/../src) -if(BUILD_HELPER) - target_link_libraries(crontab KF5::AuthCore) - target_include_directories(crontab PRIVATE KF5::Auth KF5::CoreAddons) +if(WITH_QT6) + target_link_libraries(crontab Qt6::Core Qt6::Gui) + target_include_directories(crontab PRIVATE Qt6::Core Qt6::Gui + ${CMAKE_CURRENT_BINARY_DIR}/../src) + if(BUILD_HELPER) + target_link_libraries(crontab KF6::AuthCore) + target_include_directories(crontab PRIVATE KF6::Auth KF6::CoreAddons) + endif() +else() + target_link_libraries(crontab Qt5::Core Qt5::Gui) + target_include_directories(crontab PRIVATE Qt5::Core Qt5::Gui + ${CMAKE_CURRENT_BINARY_DIR}/../src) + if(BUILD_HELPER) + target_link_libraries(crontab KF5::AuthCore) + target_include_directories(crontab PRIVATE KF5::Auth KF5::CoreAddons) + endif() endif() + target_compile_features(crontab PRIVATE cxx_lambdas cxx_nullptr cxx_unicode_literals) set_target_properties(crontab PROPERTIES VERSION ${CRONTAB_V} SOVERSION ${VERSION_MAJOR}) diff --git a/crontablib/ctcron.cpp b/crontablib/ctcron.cpp index 1d7888d..00ed88f 100644 --- a/crontablib/ctcron.cpp +++ b/crontablib/ctcron.cpp @@ -12,7 +12,7 @@ #include "config.h" #include "ctcron.h" -#include +#include #include #include #include @@ -184,7 +184,8 @@ void CTCron::parseFile(const QString& fileName) { continue; leadingComment = false; // If the first 10 characters don't contain a character, it's probably a disabled entry. - int firstText = line.indexOf(QRegExp(QLatin1String("\\w"))); + static const QRegularExpression firstTextRx(QStringLiteral("\\w")); + int firstText = line.indexOf(firstTextRx); if (firstText < 0) { comment.clear(); continue; @@ -205,7 +206,8 @@ void CTCron::parseFile(const QString& fileName) { } // either a task or a variable - int firstWhiteSpace = line.indexOf(QRegExp(QLatin1String("[ \t]"))); + static const QRegularExpression firstWhitespaceRx(QStringLiteral("[ \t]")); + int firstWhiteSpace = line.indexOf(firstWhitespaceRx); int firstEquals = line.indexOf(QChar::fromLatin1('=')); // if there is an equals sign and either there is no diff --git a/crontablib/cttask.cpp b/crontablib/cttask.cpp index 395d215..b1ac5ae 100644 --- a/crontablib/cttask.cpp +++ b/crontablib/cttask.cpp @@ -11,6 +11,7 @@ #include "cttask.h" +#include #include #include @@ -56,7 +57,8 @@ CTTask::CTTask(const QString& tokenString, const QString& _comment, } } - int spacePos(tokStr.indexOf(QRegExp(QStringLiteral("[ \t]")))); + static const QRegularExpression spacePosRx(QStringLiteral("[ \t]")); + int spacePos(tokStr.indexOf(spacePosRx)); // If reboot bypass initialize functions so no keys selected in modify task if (reboot == false) { @@ -66,25 +68,25 @@ CTTask::CTTask(const QString& tokenString, const QString& _comment, while (isSpace(tokStr, spacePos+1)) spacePos++; tokStr = tokStr.mid(spacePos+1, tokStr.length()-1); - spacePos = tokStr.indexOf(QRegExp(QStringLiteral("[ \t]"))); + spacePos = tokStr.indexOf(spacePosRx); hour.initialize(tokStr.mid(0, spacePos)); while (isSpace(tokStr, spacePos+1)) spacePos++; tokStr = tokStr.mid(spacePos+1, tokStr.length()-1); - spacePos = tokStr.indexOf(QRegExp(QStringLiteral("[ \t]"))); + spacePos = tokStr.indexOf(spacePosRx); dayOfMonth.initialize(tokStr.mid(0, spacePos)); while (isSpace(tokStr, spacePos+1)) spacePos++; tokStr = tokStr.mid(spacePos+1, tokStr.length()-1); - spacePos = tokStr.indexOf(QRegExp(QStringLiteral("[ \t]"))); + spacePos = tokStr.indexOf(spacePosRx); month.initialize(tokStr.mid(0, spacePos)); while (isSpace(tokStr, spacePos+1)) spacePos++; tokStr = tokStr.mid(spacePos+1, tokStr.length()-1); - spacePos = tokStr.indexOf(QRegExp(QStringLiteral("[ \t]"))); + spacePos = tokStr.indexOf(spacePosRx); dayOfWeek.initialize(tokStr.mid(0, spacePos)); } @@ -92,7 +94,7 @@ CTTask::CTTask(const QString& tokenString, const QString& _comment, while (isSpace(tokStr, spacePos+1)) spacePos++; tokStr = tokStr.mid(spacePos+1, tokStr.length()-1); - spacePos = tokStr.indexOf(QRegExp(QStringLiteral("[ \t]"))); + spacePos = tokStr.indexOf(spacePosRx); userLogin = tokStr.mid(0, spacePos); } else { @@ -101,7 +103,7 @@ CTTask::CTTask(const QString& tokenString, const QString& _comment, command = tokStr.mid(spacePos+1, tokStr.length()-1); // remove leading whitespace - while (command.indexOf(QRegExp(QStringLiteral("[ \t]"))) == 0) + while (command.indexOf(spacePosRx) == 0) command = command.mid(1, command.length()-1); comment = _comment; diff --git a/crontablib/ctvariable.cpp b/crontablib/ctvariable.cpp index 70968dc..cb54671 100644 --- a/crontablib/ctvariable.cpp +++ b/crontablib/ctvariable.cpp @@ -11,7 +11,7 @@ #include "ctvariable.h" -#include +#include #include "ctHelper.h" @@ -27,7 +27,8 @@ CTVariable::CTVariable(const QString& tokenString, const QString& _comment, cons int spacepos(0); - spacepos = tokStr.indexOf(QRegExp(QLatin1String( "[ =]" ))); + static const QRegularExpression spacePosRx(QStringLiteral("[ =]")); + spacepos = tokStr.indexOf(spacePosRx); variable = tokStr.mid(0, spacepos); value = tokStr.mid(spacepos+1, tokStr.length()-spacepos-1); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a214c42..11c48cd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,17 +36,33 @@ SET(TRANSLATION ../translations/crontablib_ru_RU.ts ../translations/crontablib_sv_SE.ts ) -find_package(Qt5LinguistTools REQUIRED) -qt5_add_translation(QM_FILES ${TRANSLATION}) -set(qt_LIBS Qt5::Core Qt5::Gui Qt5::Widgets) +if(WITH_QT6) + find_package(Qt6LinguistTools REQUIRED) + qt_add_translation(QM_FILES ${TRANSLATION}) + + set(qt_LIBS Qt6::Core Qt6::Gui Qt6::Widgets) + + qt_wrap_ui(zeit_FORMS_HEADERS ${zeit_FRMS}) + qt_add_resources(zeit_RESOURCES_RCC ${zeit_RSRCS}) + set(QT_INCLUDE_DIRECTORIES ${Qt6Core_INCLUDE_DIRS} + ${Qt6Widgets_INCLUDE_DIRS}) +else() + find_package(Qt5LinguistTools REQUIRED) + qt5_add_translation(QM_FILES ${TRANSLATION}) + + set(qt_LIBS Qt5::Core Qt5::Gui Qt5::Widgets) + + qt5_wrap_ui(zeit_FORMS_HEADERS ${zeit_FRMS}) + qt5_add_resources(zeit_RESOURCES_RCC ${zeit_RSRCS}) + set(QT_INCLUDE_DIRECTORIES ${Qt5Core_INCLUDE_DIRS} + ${Qt5Widgets_INCLUDE_DIRS}) +endif() + -qt5_wrap_ui(zeit_FORMS_HEADERS ${zeit_FRMS}) -qt5_add_resources(zeit_RESOURCES_RCC ${zeit_RSRCS}) add_executable(zeit ${zeit_SRCS} ${zeit_HEADERS_MOC} ${zeit_FORMS_HEADERS} ${QM_FILES} ${zeit_RESOURCES_RCC}) -target_include_directories(zeit PRIVATE ${Qt5Core_INCLUDE_DIRS} - ${Qt5Widgets_INCLUDE_DIRS} +target_include_directories(zeit PRIVATE ${QT_INCLUDE_DIRECTORIES} ${CMAKE_CURRENT_SOURCE_DIR}/../crontablib ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/src/alarmdialog.cpp b/src/alarmdialog.cpp index dcb6298..69cb04b 100644 --- a/src/alarmdialog.cpp +++ b/src/alarmdialog.cpp @@ -46,7 +46,7 @@ AlarmDialog::AlarmDialog(CTTask* _ctTask, QWidget* parent) : QStringList{QStringLiteral("mpv"), QStringLiteral("mplayer")}); proc.waitForFinished(); QStringList players = QString::fromUtf8(proc.readAllStandardOutput()) - .split(QRegExp(QStringLiteral("\n"))); + .split(QChar::fromLatin1('\n')); if(players.length() > 0) ui->lineEditPlayer->setText(players.at(0)); /* file dialog actions */ diff --git a/src/commands.cpp b/src/commands.cpp index 174db96..924bf65 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -18,7 +18,7 @@ * ======================================================================== */ #include -#include +#include #include "commands.h" @@ -30,10 +30,10 @@ void Commands::addCommand(const QByteArray& command, const QString& time) { p.closeWriteChannel(); p.waitForFinished(); QString output = QString::fromUtf8(p.readAllStandardError()); - QRegExp match(QStringLiteral("job\\s(\\d+)\\s(.*)")); - match.setMinimal(true); - if(match.indexIn(output) > -1) { - uint id = match.cap(1).toUInt(); + static const QRegularExpression jobRx(QStringLiteral("job\\s(\\d+?)\\s(.*?)")); + const QRegularExpressionMatch match = jobRx.match(output); + if(match.hasMatch()) { + const uint id = match.captured(1).toUInt(); map.insert(id, command); } } @@ -55,19 +55,14 @@ const QVector& Commands::getCommands() { QString output = QString::fromUtf8(p.readAllStandardOutput()); QStringList entries; if(!output.isEmpty()) - entries = output -#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) - .split(QChar::fromLatin1('\n'), Qt::SkipEmptyParts); -#else - .split(QChar::fromLatin1('\n'), QString::SkipEmptyParts); -#endif + entries = output.split(QChar::fromLatin1('\n'), Qt::SkipEmptyParts); for(QString& entry : entries) { - QRegExp match(QStringLiteral("^(\\d+)\\s+(.*)$")); - match.setMinimal(true); - match.indexIn(entry); + QRegularExpression entryRx(QStringLiteral("^(\\d+?)\\s+?(.*?)$"), + QRegularExpression::MultilineOption); + QRegularExpressionMatch match = entryRx.match(entry); Command command; - command.id = match.cap(1).toUInt(); - command.description = match.cap(2); + command.id = match.captured(1).toUInt(); + command.description = match.captured(2); command.command = map.value(command.id, QStringLiteral("n/a")); commands.append(command); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2b8de42..88fb60f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef BUILD_HELPER #define ROOT_ACTIONS cron->isSystemCron() diff --git a/src/taskdialog.cpp b/src/taskdialog.cpp index cbec79b..d755c91 100644 --- a/src/taskdialog.cpp +++ b/src/taskdialog.cpp @@ -17,6 +17,8 @@ * along with Zeit. If not, see . * ======================================================================== */ +#include + #include "cttask.h" #include "taskdialog.h" #include "ui_taskdialog.h" @@ -84,8 +86,9 @@ void TaskDialog::init() { setText("*", "*", "*", "*", "*"); } else { + static const QRegularExpression whitespaceRx(QStringLiteral("\\s+")); QStringList tokenList = task->schedulingCronFormat() - .split(QRegExp(QStringLiteral("\\s"))); + .split(whitespaceRx); setText(tokenList.at(0), tokenList.at(1), tokenList.at(2), tokenList.at(4), tokenList.at(3)); } @@ -198,13 +201,16 @@ void TaskDialog::validate() { ui->commandEdit->setToolTip(tr("Command field should not be empty")); isInputValid = false; } - QRegExp rx(QStringLiteral("\\*|\\d{1,2}(,\\d{1,2}|-\\d{1,2}(/\\d{1,2})?)*")); const QVector leVector { ui->editMinute,ui->editHour,ui->editDay,ui->editWeekday,ui->editMonth }; for(QLineEdit* le : leVector) { le->setStyleSheet(QString()); le->setToolTip(helpToolTip); - if(!rx.exactMatch(le->text())) { + static const QRegularExpression rx( + QRegularExpression::anchoredPattern( + QStringLiteral("\\*|\\d{1,2}(,\\d{1,2}|-\\d{1,2}(/\\d{1,2})?)*"))); + const QRegularExpressionMatch match = rx.match(le->text()); + if(!match.hasMatch()) { le->setStyleSheet(errorStyleSheet); le->setToolTip(tr("Invalid input
") + helpToolTip); isInputValid = false; diff --git a/src/timerdialog.cpp b/src/timerdialog.cpp index 2dcb568..733a0c4 100644 --- a/src/timerdialog.cpp +++ b/src/timerdialog.cpp @@ -41,8 +41,8 @@ TimerDialog::TimerDialog(Commands* commands_, QWidget* parent) : proc.start(QStringLiteral("which"), QStringList{QStringLiteral("mpv"), QStringLiteral("mplayer")}); proc.waitForFinished(-1); - QStringList players = QString::fromUtf8(proc.readAllStandardOutput()).split( - QRegExp(QStringLiteral("\n"))); + QStringList players = QString::fromUtf8(proc.readAllStandardOutput()) + .split(QChar::fromLatin1('\n')); if(players.length() > 0) ui->lineEditPlayer->setText(players.at(0)); /* get system time with a positive offset of 5 minutes */ diff --git a/src/variabledialog.cpp b/src/variabledialog.cpp index 41956ae..1cca259 100644 --- a/src/variabledialog.cpp +++ b/src/variabledialog.cpp @@ -17,6 +17,8 @@ * along with Zeit. If not, see . * ======================================================================== */ +#include + #include "ctvariable.h" #include "variabledialog.h" #include "ui_variabledialog.h" @@ -45,7 +47,8 @@ VariableDialog::VariableDialog(CTVariable* _ctVar, ui->varEdit->setToolTip(tr("Variable field should not be empty")); isInputValid = false; } - if(ui->varEdit->text().contains(QRegExp(QStringLiteral("\\W")))) { + static const QRegularExpression nonWordRx(QStringLiteral("\\W+")); + if(ui->varEdit->text().contains(nonWordRx)) { ui->varEdit->setToolTip(tr("Invalid variable name")); isInputValid = false; }