Skip to content

Commit

Permalink
Merge pull request #1748 from matterhorn103/qt6
Browse files Browse the repository at this point in the history
QRegExp ports, compile plugins on Qt6, remove Qt6Core5Compat dependency
  • Loading branch information
ghutchis authored Oct 24, 2024
2 parents 7468e5f + 6e64a9d commit 5c6c81e
Show file tree
Hide file tree
Showing 40 changed files with 557 additions and 502 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
}
- {
name: "Ubuntu AppImage", artifact: "Avogadro2.AppImage",
os: ubuntu-20.04,
os: ubuntu-22.04,
cc: "gcc", cxx: "g++",
build_type: "Release",
cmake_flags: "-G Ninja -DBUILD_MOLEQUEUE=OFF -DINSTALL_BUNDLE_FILES=ON -USE_SYSTEM_ZLIB=ON",
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/build_qt6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
}
- {
name: "Ubuntu Qt6 AppImage", artifact: "",
os: ubuntu-20.04,
os: ubuntu-22.04,
cc: "gcc", cxx: "g++",
build_type: "Release",
cmake_flags: "-G Ninja -DINSTALL_BUNDLE_FILES=ON",
Expand Down Expand Up @@ -135,6 +135,13 @@ jobs:
if (NOT result EQUAL 0)
message(FATAL_ERROR "Running tests failed!")
endif()
- name: Upload
if: matrix.config.artifact != 0
uses: actions/upload-artifact@v4
with:
path: ${{ runner.workspace }}/build/avogadroapp/Avogadro2*.*
name: ${{ matrix.config.artifact }}

- name: Setup tmate session
if: ${{ failure() }}
Expand Down
5 changes: 1 addition & 4 deletions avogadro/molequeue/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if(QT_VERSION EQUAL 6)
find_package(Qt6 COMPONENTS Widgets Network Core5Compat REQUIRED)
find_package(Qt6 COMPONENTS Widgets Network REQUIRED)
else()
find_package(Qt5 COMPONENTS Widgets Network REQUIRED)
endif()
Expand Down Expand Up @@ -43,6 +43,3 @@ target_sources(MoleQueue PRIVATE ${UI_SOURCES})
avogadro_add_library(MoleQueue ${HEADERS} ${SOURCES})
set_target_properties(MoleQueue PROPERTIES AUTOMOC TRUE)
target_link_libraries(MoleQueue PUBLIC Avogadro::QtGui Qt::Widgets Qt::Network)
if(QT_VERSION EQUAL 6)
target_link_libraries(MoleQueue PRIVATE Qt6::Core5Compat)
endif()
151 changes: 67 additions & 84 deletions avogadro/molequeue/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@

#include "client.h"

#include "jsonrpcclient.h"
#include "jobobject.h"
#include "jsonrpcclient.h"

#include <QtCore/QJsonDocument>

namespace Avogadro::MoleQueue {

Client::Client(QObject *parent_) : QObject(parent_), m_jsonRpcClient(nullptr)
{
}
Client::Client(QObject* parent_) : QObject(parent_), m_jsonRpcClient(nullptr) {}

Client::~Client()
{
}
Client::~Client() {}

bool Client::isConnected() const
{
Expand All @@ -28,7 +24,7 @@ bool Client::isConnected() const
return m_jsonRpcClient->isConnected();
}

bool Client::connectToServer(const QString &serverName)
bool Client::connectToServer(const QString& serverName)
{
if (!m_jsonRpcClient) {
m_jsonRpcClient = new JsonRpcClient(this);
Expand Down Expand Up @@ -60,7 +56,7 @@ int Client::requestQueueList()
return localId;
}

int Client::submitJob(const JobObject &job)
int Client::submitJob(const JobObject& job)
{
if (!m_jsonRpcClient)
return -1;
Expand Down Expand Up @@ -112,8 +108,8 @@ int Client::cancelJob(unsigned int moleQueueId)
return localId;
}

int Client::registerOpenWith(const QString &name, const QString &executable,
const QList<QRegExp> &filePatterns)
int Client::registerOpenWith(const QString& name, const QString& executable,
const QList<QRegularExpression>& filePatterns)
{
if (!m_jsonRpcClient)
return -1;
Expand All @@ -131,9 +127,9 @@ int Client::registerOpenWith(const QString &name, const QString &executable,
return localId;
}

int Client::registerOpenWith(const QString &name,
const QString &rpcServer, const QString &rpcMethod,
const QList<QRegExp> &filePatterns)
int Client::registerOpenWith(const QString& name, const QString& rpcServer,
const QString& rpcMethod,
const QList<QRegularExpression>& filePatterns)
{
if (!m_jsonRpcClient)
return -1;
Expand Down Expand Up @@ -167,7 +163,7 @@ int Client::listOpenWithNames()
return localId;
}

int Client::unregisterOpenWith(const QString &handlerName)
int Client::unregisterOpenWith(const QString& handlerName)
{
if (!m_jsonRpcClient)
return -1;
Expand All @@ -191,60 +187,60 @@ void Client::flush()
m_jsonRpcClient->flush();
}

void Client::processResult(const QJsonObject &response)
void Client::processResult(const QJsonObject& response)
{
if (response["id"] != QJsonValue::Null
&& m_requests.contains(static_cast<int>(response["id"].toDouble()))) {
if (response["id"] != QJsonValue::Null &&
m_requests.contains(static_cast<int>(response["id"].toDouble()))) {
int localId = static_cast<int>(response["id"].toDouble());
switch (m_requests[localId]) {
case ListQueues:
emit queueListReceived(response["result"].toObject());
break;
case SubmitJob:
emit submitJobResponse(localId,
static_cast<unsigned int>(response["result"]
.toObject()["moleQueueId"].toDouble()));
break;
case LookupJob:
emit lookupJobResponse(localId, response["result"].toObject());
break;
case CancelJob:
emit cancelJobResponse(static_cast<unsigned int>(response["result"]
.toObject()["moleQueueId"].toDouble()));
break;
case RegisterOpenWith:
emit registerOpenWithResponse(localId);
break;
case ListOpenWithNames:
emit listOpenWithNamesResponse(localId, response["result"].toArray());
break;
case UnregisterOpenWith:
emit unregisterOpenWithResponse(localId);
break;
default:
break;
case ListQueues:
emit queueListReceived(response["result"].toObject());
break;
case SubmitJob:
emit submitJobResponse(
localId, static_cast<unsigned int>(
response["result"].toObject()["moleQueueId"].toDouble()));
break;
case LookupJob:
emit lookupJobResponse(localId, response["result"].toObject());
break;
case CancelJob:
emit cancelJobResponse(static_cast<unsigned int>(
response["result"].toObject()["moleQueueId"].toDouble()));
break;
case RegisterOpenWith:
emit registerOpenWithResponse(localId);
break;
case ListOpenWithNames:
emit listOpenWithNamesResponse(localId, response["result"].toArray());
break;
case UnregisterOpenWith:
emit unregisterOpenWithResponse(localId);
break;
default:
break;
}
}
}

void Client::processNotification(const QJsonObject &notification)
void Client::processNotification(const QJsonObject& notification)
{
if (notification["method"].toString() == "jobStateChanged") {
QJsonObject params = notification["params"].toObject();
emit jobStateChanged(
static_cast<unsigned int>(params["moleQueueId"].toDouble()),
params["oldState"].toString(), params["newState"].toString());
static_cast<unsigned int>(params["moleQueueId"].toDouble()),
params["oldState"].toString(), params["newState"].toString());
}
}

void Client::processError(const QJsonObject &error)
void Client::processError(const QJsonObject& error)
{
int localId = static_cast<int>(error["id"].toDouble());
int errorCode = -1;
QString errorMessage = tr("No message specified.");
QJsonValue errorData;

const QJsonValue &errorValue = error.value(QLatin1String("error"));
const QJsonValue& errorValue = error.value(QLatin1String("error"));
if (errorValue.isObject()) {
const QJsonObject errorObject = errorValue.toObject();
if (errorObject.value("code").isDouble())
Expand All @@ -258,41 +254,28 @@ void Client::processError(const QJsonObject &error)
}

QJsonObject Client::buildRegisterOpenWithRequest(
const QString &name, const QList<QRegExp> &filePatterns,
const QJsonObject &handlerMethod)
const QString& name, const QList<QRegularExpression>& filePatterns,
const QJsonObject& handlerMethod)
{
QJsonArray patterns;
foreach (const QRegExp &regex, filePatterns) {
QJsonObject pattern;
switch (regex.patternSyntax()) {
case QRegExp::RegExp:
case QRegExp::RegExp2:
pattern["regexp"] = regex.pattern();
break;
case QRegExp::Wildcard:
case QRegExp::WildcardUnix:
pattern["wildcard"] = regex.pattern();
break;
default:
case QRegExp::FixedString:
case QRegExp::W3CXmlSchema11:
continue;
}

pattern["caseSensitive"] = regex.caseSensitivity() == Qt::CaseSensitive;
patterns.append(pattern);
}

QJsonObject params;
params["name"] = name;
params["method"] = handlerMethod;
params["patterns"] = patterns;

QJsonObject packet = m_jsonRpcClient->emptyRequest();
packet["method"] = QLatin1String("registerOpenWith");
packet["params"] = params;

return packet;
QJsonArray patterns;
foreach (const QRegularExpression& regex, filePatterns) {
QJsonObject pattern;
pattern["regex"] = regex.pattern();
pattern["caseSensitive"] = regex.patternOptions().testFlag(
QRegularExpression::CaseInsensitiveOption);
patterns.append(pattern);
}

QJsonObject params;
params["name"] = name;
params["method"] = handlerMethod;
params["patterns"] = patterns;

QJsonObject packet = m_jsonRpcClient->emptyRequest();
packet["method"] = QLatin1String("registerOpenWith");
packet["params"] = params;

return packet;
}

} // End namespace Avogadro
} // namespace Avogadro::MoleQueue
Loading

0 comments on commit 5c6c81e

Please sign in to comment.