Skip to content

Commit

Permalink
finished huggle-core
Browse files Browse the repository at this point in the history
  • Loading branch information
benapetr committed Jul 18, 2024
1 parent 8de821c commit b618d72
Show file tree
Hide file tree
Showing 34 changed files with 248 additions and 66 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ option(AUDIO "Enable audio backend" true)

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

set(HUGGLE_CMAKE true)
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(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})
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})

QT6_WRAP_CPP(huggle_core_HEADERS_MOC ${huggle_core_HEADERS})
QT6_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 Qt6::Core Qt6::Network Qt6::Xml Qt6::Qml)
if (AUDIO)
target_link_libraries(huggle_core Qt6::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
6 changes: 6 additions & 0 deletions src/huggle_core/definitions_prod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ namespace std { typedef decltype(nullptr) nullptr_t; }

#include <QObject>

#ifdef QT6_BUILD
#define HMUTEX_TYPE QRecursiveMutex
#else
#define HMUTEX_TYPE QMutex
#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
4 changes: 4 additions & 0 deletions src/huggle_core/hugglefeed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ unsigned long long HuggleFeed::GetTotalBytesSent()

HuggleFeed::HuggleFeed(WikiSite *site) : MediaWikiObject(site)
{
#ifdef QT6_BUILD
this->statisticsMutex = new QRecursiveMutex();
#else
this->statisticsMutex = new QMutex(QMutex::Recursive);
#endif
this->statisticsBlocks.append(new StatisticsBlock());
this->editCounter = 0;
this->rvCounter = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/huggle_core/hugglefeed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace Huggle
double editCounter;
//! Number of reverts made since you logged in
double rvCounter;
QMutex *statisticsMutex;
HMUTEX_TYPE *statisticsMutex;
QDateTime startupTime;
QList<StatisticsBlock*> statisticsBlocks;
};
Expand Down
12 changes: 10 additions & 2 deletions src/huggle_core/hugglefeedproviderirc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <libirc/libircclient/parser.h>
#include <libirc/libircclient/network.h>
#include <libirc/libircclient/channel.h>
#include <random>
#include <chrono>

using namespace Huggle;

Expand Down Expand Up @@ -57,8 +59,10 @@ bool HuggleFeedProviderIRC::Start()
delete this->network;

QString nick = "huggle";
qsrand(static_cast<unsigned int>(QTime::currentTime().msec()));
nick += QString::number(qrand());
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
std::uniform_int_distribution<int> dist(0, 65535);
int randomNumber = dist(rng);
nick += QString::number(randomNumber);
libirc::ServerAddress server(hcfg->SystemConfig_IRCServer, false, hcfg->SystemConfig_IRCPort, nick);
server.SetSuffix(this->GetSite()->IRCChannel);
this->network = new libircclient::Network(server, "Wikimedia IRC");
Expand Down Expand Up @@ -214,7 +218,11 @@ void HuggleFeedProviderIRC::ParseEdit(QString line)
edit->DecRef();
return;
}
#ifdef QT6_BUILD
edit->OldID = line.mid(0, line.indexOf(QString(QChar(003)))).toInt();
#else
edit->OldID = line.midRef(0, line.indexOf(QString(QChar(003)))).toInt();
#endif
if (!line.contains(QString(QChar(003)) + "03"))
{
HUGGLE_DEBUG("Invalid line, no user: " + line, 1);
Expand Down
4 changes: 4 additions & 0 deletions src/huggle_core/hugglefeedproviderxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ void HuggleFeedProviderXml::processBufs()
edit->SetSize(size);
}
edit->OldID = element.attribute("oldid").toInt();
#ifdef QT6_BUILD
ts.setSecsSinceEpoch(element.attribute("timestamp").toUInt());
#else
ts.setTime_t(element.attribute("timestamp").toUInt());
#endif
this->insertEdit(edit);
continue;

Expand Down
4 changes: 4 additions & 0 deletions src/huggle_core/huggleparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ static QList<ScoreWord> ParseScoreWords(QString text, const QString& wt)
{
return contents;
}
#ifdef QT6_BUILD
int score = text.mid(0, text.indexOf(")")).toInt();
#else
int score = text.midRef(0, text.indexOf(")")).toInt();
#endif
if (score == 0)
{
continue;
Expand Down
8 changes: 8 additions & 0 deletions src/huggle_core/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,11 @@ QString Message::appendText(QString text, QString original_text, QString section
// there is nothing to insert this to
return original_text += "\n\n" + text + "\n\n";
}
#ifdef QT6_BUILD
QRegularExpression regex("\\s*==\\s*" + QRegularExpression::escape(section_name) + "\\s*==");
#else
QRegExp regex("\\s*==\\s*" + QRegExp::escape(section_name) + "\\s*==");
#endif
if (!original_text.contains(regex))
{
// there is no section to append to
Expand All @@ -386,7 +390,11 @@ QString Message::appendText(QString text, QString original_text, QString section
original_text += "== " + section_name + " ==\n\n" + text;
return original_text;
}
#ifdef QT6_BUILD
QRegularExpression header("\\s*==.*==\\s*");
#else
QRegExp header("\\s*==.*==\\s*");
#endif
int start_of_desired_section = original_text.lastIndexOf(regex);
// we need to check if there is any other section after this one
QString section = original_text.mid(start_of_desired_section);
Expand Down
8 changes: 8 additions & 0 deletions src/huggle_core/projectconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,11 @@ bool ProjectConfiguration::Parse(const QString& config, QString *reason, WikiSit
int xx = 0;
while (xx < this->RevertPatterns.count())
{
#ifdef QT6_BUILD
this->_revertPatterns.append(QRegularExpression(this->RevertPatterns.at(xx)));
#else
this->_revertPatterns.append(QRegExp(this->RevertPatterns.at(xx)));
#endif
xx++;
}
if (!HuggleQueueFilter::Filters.contains(site))
Expand Down Expand Up @@ -821,7 +825,11 @@ bool ProjectConfiguration::ParseYAML(const QString& yaml_src, QString *reason, W
int xx = 0;
while (xx < this->RevertPatterns.count())
{
#ifdef QT6_BUILD
this->_revertPatterns.append(QRegularExpression(this->RevertPatterns.at(xx)));
#else
this->_revertPatterns.append(QRegExp(this->RevertPatterns.at(xx)));
#endif
xx++;
}
if (!HuggleQueueFilter::Filters.contains(site))
Expand Down
7 changes: 7 additions & 0 deletions src/huggle_core/projectconfiguration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include <QStringList>
#include <QHash>
#include <QString>
#ifdef QT6_BUILD
#include <QRegularExpression>
#endif

// Private key names
// these need to be stored in separate variables so that we can
Expand Down Expand Up @@ -282,7 +285,11 @@ namespace Huggle
//! Where the welcome message is stored
QString WelcomeMP = "Project:Huggle/Message";
// This is internal only do not prefix it!!
#ifdef QT6_BUILD
QList<QRegularExpression> _revertPatterns;
#else
QList<QRegExp> _revertPatterns;
#endif
score_ht BotScore = -200;
score_ht WarningScore = 2000;
QStringList WarningTypes;
Expand Down
Loading

0 comments on commit b618d72

Please sign in to comment.