Skip to content

Commit

Permalink
QT6 support
Browse files Browse the repository at this point in the history
We need to move on to latest supported version of Qt. With this change I
would like to deprecate Qt4 completely and stay with support for only
Qt5 and Qt6.

There are still many code artifacts reflecting Qt4 and old WebKit, which
we can gradually get rid of now.

WebKit is probably supported by early Qt5 but I would like to phase it
out as well.
  • Loading branch information
benapetr committed Jul 19, 2024
1 parent a76e717 commit 52f01d3
Show file tree
Hide file tree
Showing 61 changed files with 485 additions and 142 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Libraries and tools you need to have to build:

* C++11 compiler
* [CMake](https://github.com/Kitware/CMake) 2.8.9 or higher is required
* QT5 sdk (recommended 5.7 or newer, with WebEngine and QJSEngine)
* QT5 or QT6 sdk

[NEW] It is now possible to use a VirtualBox VM as a portable development environment for Huggle. [» Wiki page](https://github.com/huggle/huggle3-qt-lx/wiki/Portable-development-environment)

Expand Down
10 changes: 10 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ CMAKE_ARGS=''
_BUILD=0
_Q=0
QTPATH=''
WEBENG=0
QTVERSION=5
USEDEBUG=0
HAS_PREFIX=0
PREFIX=""
Expand All @@ -55,6 +57,7 @@ do
echo " --debug: build a debuggable huggle"
echo " --disable-dependency-tracking: skip all package checks"
echo " --extension: will build all extensions as well"
echo " --qt6: use qt6 instead of qt5"
echo " --qtpath: path to Qt (for example C:\\Qt\\5.4\\mingw\\"
echo " --folder <folder>: change the default build folder"
echo " --no-audio: don't build huggle with audio engine"
Expand Down Expand Up @@ -115,6 +118,7 @@ do
exit 0
fi
if [ "$var" = "--web-engine" ];then
WEBENG=1
CMAKE_ARGS="$CMAKE_ARGS -DWEB_ENGINE=true"
continue
fi
Expand All @@ -134,6 +138,12 @@ do
CMAKE_ARGS="$CMAKE_ARGS -DHUGGLE_TEST=true"
continue
fi
if [ "$var" = "--qt6" ];then
QTVERSION=6
WEBENG=1
CMAKE_ARGS="$CMAKE_ARGS -DQT6_BUILD=true -DWEB_ENGINE=true"
continue
fi
done

ok()
Expand Down
14 changes: 12 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ endif()

option(LINUX_SNAP "Enable support for snap, use this option only if you are building snapshotable version" false)
option(QT5_BUILD "Build Huggle using the Qt5 framework" true)
option(QT6_BUILD "Build Huggle using the Qt6 framework" false)
option(HUGGLE_PROFILING "Enable profiler" false)
option(HUGGLE_EXT "Build Huggle extensions" false)
option(HUGGLE_TEST "Unit tests" false)
option(WEB_ENGINE "Use Qt WebEngine instead of WebKit library" false)
option(AUDIO "Enable audio backend" true)

if (QT6_BUILD)
set (QT5_BUILD false)
add_definitions( -DQT6_BUILD )
endif()

set(HUGGLE_CMAKE true)

if (NOT AUDIO)
Expand All @@ -44,13 +50,17 @@ if (LINUX_SNAP)
add_definitions(-DHUGGLE_SNAP)
endif()

# Enable c++11
# Enable c++11 or c++17 in case of Qt6
if(WIN32)
if(MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows -std=c++11")
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if (QT6_BUILD)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
endif()

# This will ensure that produced binaries go to right place on windows
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/enwiki
Submodule enwiki updated 1 files
+34 −16 CMakeLists.txt
2 changes: 1 addition & 1 deletion src/extensions/extension-flow
Submodule extension-flow updated 1 files
+35 −16 CMakeLists.txt
2 changes: 1 addition & 1 deletion src/extensions/extension-mass-delete
2 changes: 1 addition & 1 deletion src/extensions/extension-scoring
2 changes: 1 addition & 1 deletion src/extensions/extension-splitter-helper
2 changes: 1 addition & 1 deletion src/extensions/extension-thanks
2 changes: 1 addition & 1 deletion src/extensions/mass-delivery
Submodule mass-delivery updated 1 files
+19 −4 CMakeLists.txt
34 changes: 26 additions & 8 deletions src/huggle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ endif()
project(huggle)
include(GNUInstallDirs)

find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
set(QT_INCLUDES ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
include_directories(${QT_INCLUDES})
if (QT6_BUILD)
find_package(Qt6Core REQUIRED)
find_package(Qt6Gui REQUIRED)
find_package(Qt6Widgets REQUIRED)
set(QT_INCLUDES ${Qt6Gui_INCLUDE_DIRS} ${Qt6Widgets_INCLUDE_DIRS})
include_directories(${QT_INCLUDES})
elseif (QT5_BUILD)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
set(QT_INCLUDES ${Qt5Gui_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS})
include_directories(${QT_INCLUDES})
endif()

file(GLOB srcx "*.cpp")
file(GLOB resx "*.qrc")
Expand All @@ -23,9 +31,15 @@ set(huggle_SOURCES ${srcx})
set(huggle_FORMS ${uixx})
set(huggle_RESOURCES ${resx})

QT5_WRAP_CPP(huggle_HEADERS_MOC ${huggle_HEADERS})
QT5_WRAP_UI(huggle_FORMS_HEADERS ${huggle_FORMS})
QT5_ADD_RESOURCES(huggle_RESOURCES_RCC ${huggle_RESOURCES})
if (QT6_BUILD)
QT6_WRAP_CPP(huggle_HEADERS_MOC ${huggle_HEADERS})
QT6_WRAP_UI(huggle_FORMS_HEADERS ${huggle_FORMS})
QT6_ADD_RESOURCES(huggle_RESOURCES_RCC ${huggle_RESOURCES})
elseif (QT5_BUILD)
QT5_WRAP_CPP(huggle_HEADERS_MOC ${huggle_HEADERS})
QT5_WRAP_UI(huggle_FORMS_HEADERS ${huggle_FORMS})
QT5_ADD_RESOURCES(huggle_RESOURCES_RCC ${huggle_RESOURCES})
endif()

add_definitions(${QT_DEFINITIONS})

Expand All @@ -38,7 +52,11 @@ endif()

target_link_libraries(huggle huggle_l10n huggle_res huggle_core huggle_ui)

if (QT6_BUILD)
target_link_libraries(huggle Qt6::Core Qt6::Gui Qt6::Widgets)
elseif (QT5_BUILD)
target_link_libraries(huggle Qt5::Core Qt5::Gui Qt5::Widgets)
endif()

include_directories(${CMAKE_CURRENT_BINARY_DIR})
install(FILES ${CMAKE_SOURCE_DIR}/huggle/man/huggle.1 DESTINATION share/man/man1)
Expand Down
51 changes: 38 additions & 13 deletions src/huggle_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,26 @@ include(GNUInstallDirs)
set(CMAKE_include_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

find_package(Qt5Core REQUIRED)
find_package(Qt5Xml REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5Qml REQUIRED)
set(QT_INCLUDES ${Qt5Network_INCLUDE_DIRS} ${Qt5Qml_INCLUDE_DIRS} ${Qt5Xml_INCLUDE_DIRS})
if (AUDIO)
find_package(Qt5Multimedia REQUIRED)
set(QT_INCLUDES ${QT_INCLUDES} ${Qt5Multimedia_INCLUDE_DIRS})
if (QT6_BUILD)
find_package(Qt6Core REQUIRED)
find_package(Qt6Xml REQUIRED)
find_package(Qt6Network REQUIRED)
find_package(Qt6Qml REQUIRED)
set(QT_INCLUDES ${Qt6Network_INCLUDE_DIRS} ${Qt6Qml_INCLUDE_DIRS} ${Qt6Xml_INCLUDE_DIRS})
if (AUDIO)
find_package(Qt6Multimedia REQUIRED)
set(QT_INCLUDES ${QT_INCLUDES} ${Qt6Multimedia_INCLUDE_DIRS})
endif()
elseif (QT5_BUILD)
find_package(Qt5Core REQUIRED)
find_package(Qt5Xml REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5Qml REQUIRED)
set(QT_INCLUDES ${Qt5Network_INCLUDE_DIRS} ${Qt5Qml_INCLUDE_DIRS} ${Qt5Xml_INCLUDE_DIRS})
if (AUDIO)
find_package(Qt5Multimedia REQUIRED)
set(QT_INCLUDES ${QT_INCLUDES} ${Qt5Multimedia_INCLUDE_DIRS})
endif()
endif()
include_directories(${QT_INCLUDES})

Expand All @@ -31,8 +43,13 @@ file(GLOB headers "*.hpp" "scripting/*.hpp")
set(huggle_core_SOURCES ${srcx})
set(huggle_core_RESOURCES ${resx})

QT5_WRAP_CPP(huggle_core_HEADERS_MOC ${huggle_core_HEADERS})
QT5_ADD_RESOURCES(huggle_core_RESOURCES_RCC ${huggle_core_RESOURCES})
if (QT6_BUILD)
QT6_WRAP_CPP(huggle_core_HEADERS_MOC ${huggle_core_HEADERS})
QT6_ADD_RESOURCES(huggle_core_RESOURCES_RCC ${huggle_core_RESOURCES})
elseif (QT5_BUILD)
QT5_WRAP_CPP(huggle_core_HEADERS_MOC ${huggle_core_HEADERS})
QT5_ADD_RESOURCES(huggle_core_RESOURCES_RCC ${huggle_core_RESOURCES})
endif()

add_definitions(${QT_DEFINITIONS})
add_definitions( -DQT_USE_QSTRINGBUILDER )
Expand All @@ -46,9 +63,17 @@ if (WIN32)
endif()

target_link_libraries(huggle_core huggle_l10n irc ircclient yaml-cpp)
target_link_libraries(huggle_core Qt5::Core Qt5::Network Qt5::Xml Qt5::Qml)
if (AUDIO)
target_link_libraries(huggle_core Qt5::Multimedia)

if (QT6_BUILD)
target_link_libraries(huggle_core Qt6::Core Qt6::Network Qt6::Xml Qt6::Qml)
if (AUDIO)
target_link_libraries(huggle_core Qt6::Multimedia)
endif()
elseif (QT5_BUILD)
target_link_libraries(huggle_core Qt5::Core Qt5::Network Qt5::Xml Qt5::Qml)
if (AUDIO)
target_link_libraries(huggle_core Qt5::Multimedia)
endif()
endif()

include_directories(${CMAKE_CURRENT_BINARY_DIR})
Expand Down
10 changes: 9 additions & 1 deletion src/huggle_core/collectable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ unsigned long Collectable::LockCt = 0;
#endif

unsigned long Collectable::LastCID = 0;
QMutex *Collectable::WideLock = new QMutex(QMutex::Recursive);
#ifdef QT6_BUILD
HMUTEX_TYPE* Collectable::WideLock = new QRecursiveMutex();
#else
HMUTEX_TYPE* Collectable::WideLock = new QMutex(QMutex::Recursive);
#endif

Collectable::Collectable()
{
Expand All @@ -41,7 +45,11 @@ Collectable::Collectable()
this->_collectableLocked = false;
this->_collectableManaged = false;
this->_collectableRefs = 0;
#ifdef QT6_BUILD
this->_collectableQL = new HMUTEX_TYPE();
#else
this->_collectableQL = new QMutex(QMutex::Recursive);
#endif
}

Collectable::~Collectable()
Expand Down
4 changes: 2 additions & 2 deletions src/huggle_core/collectable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace Huggle
bool HasSomeConsumers();
private:
static QString ConsumerIdToString(int id);
static QMutex *WideLock;
static HMUTEX_TYPE* WideLock;
static unsigned long LastCID;

void SetManaged();
Expand All @@ -151,7 +151,7 @@ namespace Huggle
//! if you aren't sure what number to use, or if you are working
//! in extension you should use string instead
QList<int> iConsumers;
QMutex *_collectableQL;
HMUTEX_TYPE*_collectableQL;
unsigned int _collectableRefs;
bool _collectableLocked;
};
Expand Down
4 changes: 3 additions & 1 deletion src/huggle_core/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ Configuration::Configuration()
//! This is a consumer key for "huggle" on wmf wikis
this->WmfOAuthConsumerKey = "56a6d6de895e3b859faa57b677f6cd21";
this->HuggleVersion = HUGGLE_VERSION;
#if QT_VERSION >= 0x050000
#if QT_VERSION >= 0x060000
this->HomePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
#elif QT_VERSION >= 0x050000
this->HomePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
#else
this->HomePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
Expand Down
4 changes: 3 additions & 1 deletion src/huggle_core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ void Core::Init()
this->HGQP = QueryPool::HugglePool;
this->HuggleSyslog = Syslog::HuggleLogs;
Core::VersionRead();
#if QT_VERSION >= 0x050000
#if QT_VERSION >= 0x060000
// No equivalent required in Qt6 as UTF-8 is used by default
#elif QT_VERSION >= 0x050000
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
#else
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
Expand Down
8 changes: 8 additions & 0 deletions src/huggle_core/definitions_prod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ namespace std { typedef decltype(nullptr) nullptr_t; }

#include <QObject>

#ifdef QT6_BUILD
#define HMUTEX_TYPE QRecursiveMutex
#define HREGEX_TYPE QRegularExpression
#else
#define HMUTEX_TYPE QMutex
#define HREGEX_TYPE QRegExp
#endif

#if QT_VERSION >= 0x050000
#define HUGGLE_QTV5
#else
Expand Down
3 changes: 3 additions & 0 deletions src/huggle_core/editquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#include "wikipage.hpp"
#include "wikiutil.hpp"
#include "wikisite.hpp"
#ifdef QT6_BUILD
#include <QRegularExpression>
#endif

using namespace Huggle;

Expand Down
5 changes: 5 additions & 0 deletions src/huggle_core/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ GC *GC::gc = nullptr;

Huggle::GC::GC()
{
#ifdef QT6_BUILD
this->Lock = new QRecursiveMutex();
#else
this->Lock = new QMutex(QMutex::Recursive);
#endif

#ifdef HUGGLE_USE_MT_GC
this->gc_t = new GC_t();
// this is a background task
Expand Down
4 changes: 2 additions & 2 deletions src/huggle_core/gc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <QList>

class QMutex;
class HMUTEX_TYPE;

#define HUGGLECONSUMER_WIKIEDIT 0
#define HUGGLECONSUMER_QUEUE 1
Expand Down Expand Up @@ -82,7 +82,7 @@ namespace Huggle

//! This lock needs to be aquired every time when you need to access this list
//! from any thread during runtime
QMutex * Lock;
HMUTEX_TYPE* Lock;
private:
GC_t *gc_t;
};
Expand Down
17 changes: 17 additions & 0 deletions src/huggle_core/generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#include "exception.hpp"
#include "hooks.hpp"
#include "localization.hpp"
#ifdef QT6_BUILD
#include <QRegularExpression>
#else
#include <QRegExp>
#endif

using namespace Huggle;

Expand Down Expand Up @@ -210,3 +215,15 @@ bool Generic::SecondsToTimeSpan(int time, int *days, int *hours, int *minutes, i
*seconds = remaining_time;
return true;
}

bool Generic::RegexExactMatch(const QString& regex, const QString& input_text)
{
#ifdef QT6_BUILD
QRegularExpression re(regex);
QRegularExpressionMatch match = re.match(input_text);
return match.hasMatch() && (match.captured(0) == input_text);
#else
QRegExp re(regex);
return re.exactMatch(input_text);
#endif
}
2 changes: 2 additions & 0 deletions src/huggle_core/generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ namespace Huggle
* \return new string
*/
HUGGLE_EX_CORE QString ShrinkText(const QString &text, int size, bool html = true, int minimum = 2);

HUGGLE_EX_CORE bool RegexExactMatch(const QString& regex, const QString& input_text);
}
}

Expand Down
Loading

0 comments on commit 52f01d3

Please sign in to comment.