Skip to content

Commit

Permalink
feat: support qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
xinhecuican committed Aug 10, 2024
1 parent 03a1d5d commit ba1a052
Show file tree
Hide file tree
Showing 28 changed files with 285 additions and 210 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ jobs:
# 5.12.12
- qt_version: 5.12.12
qt_arch: gcc_64
modules: "qtwebengine qtnetworkauth qtmultimedia"
# 5.15.2
- qt_version: 5.15.2
qt_arch: gcc_64
modules: "qtwebengine qtnetworkauth qtmultimedia"
- qt_version: 6.2.4
qt_arch: gcc_64
modules: "qtwebengine qtnetworkauth qtmultimedia"

env:
BUILD_TYPE: Release
BUILD_PATH: build
Expand Down Expand Up @@ -50,7 +56,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 1
submodule: true
submodules: true
- uses: actions/setup-node@v4
with:
node-version: "latest"
Expand Down
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
include(GNUInstallDirs)

find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Multimedia Network Test)


file(GLOB COMMON_SOURCES Utils/*.cpp Recorder/*.cpp)
file(GLOB COMMON_HEADERS Utils/*.h Recorder/*.h)

Expand Down
10 changes: 9 additions & 1 deletion Conversation/NLU/rasanlu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ ParsedIntent RasaNLU::parseIntent(const QString &text) {
connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
bool writeSample = false;
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
if (!reply->error()) {
Intent intent;
QByteArray replyData = reply->readAll();
Expand All @@ -65,7 +64,12 @@ ParsedIntent RasaNLU::parseIntent(const QString &text) {
intent.conf = intentObj.value("confidence").toDouble();
QFile file(Config::getDataPath("Tmp/rasa/" + intent.name + ".yml"));
QTextStream out(&file);
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
out.setEncoding(QStringConverter::Utf8);
#else
QTextCodec *codec = QTextCodec::codecForName("UTF-8");
out.setCodec(codec);
#endif
if (recordSamples) {
QDir dir;
dir.mkpath(Config::getDataPath("Tmp/rasa"));
Expand Down Expand Up @@ -119,7 +123,11 @@ ParsedIntent RasaNLU::parseIntent(const QString &text) {
if (recordSamples) {
QFile qaFile(Config::getDataPath("Tmp/rasa/qa.csv"));
QTextStream qaStream(&qaFile);
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
qaStream.setEncoding(QStringConverter::Utf8);
#else
qaStream.setCodec(codec);
#endif
bool qaExists = qaFile.exists();
if (qaFile.open(QIODevice::WriteOnly | QIODevice::Append)) {
if (!qaExists) {
Expand Down
5 changes: 3 additions & 2 deletions Conversation/conversation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "../Recorder/player.h"
#include "../Utils/config.h"
#include <QDebug>
#include <QRegularExpression>
#if defined(ASR_SHERPA)
#include "ASR/sherpaasr.h"
#endif
Expand Down Expand Up @@ -116,7 +117,7 @@ void Conversation::say(const QString &text, bool block, const QString &type) {
}
qInfo() << "say" << text;
QStringList list =
text.split(QRegExp("[\t.。!\??!;\n]"), Qt::SkipEmptyParts);
text.split(QRegularExpression("[\t.。!\??!;\n]"), Qt::SkipEmptyParts);
endIndex = index + list.size() - 1;
for (QString &line : list) {
if (line != "")
Expand Down Expand Up @@ -179,4 +180,4 @@ void Conversation::stopSay(const QString &type,

ParsedIntent Conversation::parse(const QString &text) {
return nlu->parseIntent(text);
}
}
9 changes: 7 additions & 2 deletions Plugins/chat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)

find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Network Multimedia)

PLUGIN_COMMON()
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Network Qt5::Multimedia lpcommon)
target_link_libraries(
${PROJECT_NAME}
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Multimedia
lpcommon)
4 changes: 2 additions & 2 deletions Plugins/chat/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ void Chat::handleInner(const QString &text, const ParsedIntent &intent,
if (stream) {
for (int i = 0; i < content.size(); i++) {
if (content[i] == '\t' || content[i] == '.' ||
content[i] == "" || content[i] == "" ||
content[i] == QChar(0x3002) || content[i] == QChar(0xff01) ||
content[i] == '!' || content[i] == '?' ||
content[i] == "" || content[i] == "" ||
content[i] == QChar(0xff1f) || content[i] == QChar(0xff1b) ||
content[i] == '\n') {
split = true;
list.append(content.mid(begin, i - begin));
Expand Down
4 changes: 2 additions & 2 deletions Plugins/fallback/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)

find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Multimedia)
PLUGIN_COMMON()
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Multimedia lpcommon)
target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Multimedia lpcommon)
10 changes: 8 additions & 2 deletions Plugins/hass/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)

find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Network Multimedia)

PLUGIN_COMMON()
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Network Qt5::Multimedia lpcommon)
target_link_libraries(
${PROJECT_NAME}
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Multimedia
lpcommon)

39 changes: 21 additions & 18 deletions Plugins/hass/hass.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "hass.h"
#include "../../Utils/config.h"

#include <QRegularExpression>
Hass::Hass() {}

QString Hass::getName() { return "Hass"; }
Expand All @@ -12,7 +12,7 @@ bool Hass::handle(const QString &text, const ParsedIntent &parsedIntent,
QList<HassService> hassServices = services[intent.name];
for (auto &service : hassServices) {
if (service.pattern != "") {
if (text.contains(QRegExp(service.pattern))) {
if (text.contains(QRegularExpression(service.pattern))) {
QJsonObject params = parseParams(intent, service);
executeService(service.path, params, service.notify);
return true;
Expand Down Expand Up @@ -103,31 +103,34 @@ QJsonObject Hass::parseObject(const Intent &intent, const QJsonObject &object) {
}

QString Hass::parseValue(const Intent &intent, const QJsonValue &v) {
QRegExp keyFinder("\\{(.*)\\|(.*)\\}");
keyFinder.setMinimal(true);
QRegularExpression keyFinder("\\{(.*)\\|(.*)\\}", QRegularExpression::InvertedGreedinessOption);
QString value = v.toString();
QString result = "";
int pos = 0;
int lastPos = 0;
while ((pos = keyFinder.indexIn(value, pos)) != -1) {
pos += keyFinder.matchedLength();
QString key = keyFinder.cap(1);
bool success = false;
IntentSlot slot = intent.getSlot(key, success);
if (success) {
result += value.midRef(lastPos, keyFinder.pos(1) - lastPos - 1);
result += slot.value;
lastPos = pos;
} else {
QString defaultValue = keyFinder.cap(2);
if (defaultValue != "--") {
result += defaultValue;

while(pos < value.size()) {
QRegularExpressionMatch match = keyFinder.match(value, pos);
if(match.hasMatch()){
QString key = match.captured(1);
bool success = false;
IntentSlot slot = intent.getSlot(key, success);
if (success) {
result += value.mid(lastPos, match.capturedStart(1) - lastPos - 1);
result += slot.value;
} else {
QString defaultValue = match.captured(2);
if (defaultValue != "--") {
result += defaultValue;
}
}
pos = match.capturedEnd();
lastPos = pos;
}
else break;
}
if (lastPos < value.size()) {
result += value.midRef(lastPos);
result += value.mid(lastPos);
}
return result;
}
Expand Down
9 changes: 7 additions & 2 deletions Plugins/neteasemusic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ set(CMAKE_AUTOMOC ON)

option(NETEASE_USE_JS "use node js api" OFF)

find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Multimedia)
PLUGIN_COMMON()
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Multimedia lpcommon)
target_link_libraries(
${PROJECT_NAME}
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Multimedia
lpcommon)

if(NETEASE_USE_JS)
message(STATUS "netease use js")
find_file(NeteaseAPP app.js
Expand Down
4 changes: 2 additions & 2 deletions Plugins/neteasemusic/neteasemusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void NeteaseMusic::setPluginHelper(IPluginHelper *helper) {
QString homeDir = neteaseConfig.value("homeDir").toString();
QString port = neteaseConfig.value("port").toString();
this->port = "3000";
if (port != 0) {
if (port != "") {
this->port = port;
qputenv("PORT", port.toStdString().c_str());
}
Expand Down Expand Up @@ -550,4 +550,4 @@ void NeteaseMusic::likeCurrent(bool like) {
params["like"] = like;
invokeMethod("like", params);
}
}
}
4 changes: 2 additions & 2 deletions Plugins/quitrobot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)

find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Multimedia)
PLUGIN_COMMON()
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Multimedia lpcommon)
target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Multimedia lpcommon)
4 changes: 2 additions & 2 deletions Plugins/systeminfo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)

find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Multimedia)
PLUGIN_COMMON()
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Multimedia lpcommon)
target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Multimedia lpcommon)
4 changes: 2 additions & 2 deletions Plugins/voicecontrol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)

find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Multimedia)
PLUGIN_COMMON()
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Multimedia lpcommon)
target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Multimedia lpcommon)
10 changes: 8 additions & 2 deletions Plugins/weather/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)

find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Network Multimedia)
PLUGIN_COMMON()
target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Network Qt5::Multimedia lpcommon)
target_link_libraries(
${PROJECT_NAME}
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Multimedia
lpcommon)

34 changes: 28 additions & 6 deletions Recorder/audiobuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#include "audiobuffer.h"
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
#include <QMediaDevices>
#include <QAudioDevice>
#include <QUrl>
#else
#include <QAudioDeviceInfo>
#endif
#include <QFileInfo>

AudioBuffer::AudioBuffer(QObject* parent)
Expand All @@ -10,14 +16,21 @@ AudioBuffer::AudioBuffer(QObject* parent)

setOpenMode(QIODevice::ReadOnly);
connect(decoder, &QAudioDecoder::bufferReady, this, [=](){

const QAudioBuffer& buffer = decoder->read();
const int length = buffer.byteCount();
const char *data = buffer.data<char>();
this->buffer.write(data, length);
emit readyRead();
qDebug() << decoder->bufferAvailable();
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
if(decoder->bufferAvailable()){
#endif
const QAudioBuffer& buffer = decoder->read();
const int length = buffer.byteCount();
const char *data = buffer.data<char>();
this->buffer.write(data, length);
emit readyRead();
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
}
#endif
});
connect(decoder, &QAudioDecoder::finished, this, [=](){
qDebug() << "finished";
isFinish = true;
});
connect(decoder, QOverload<QAudioDecoder::Error>::of(&QAudioDecoder::error), this, [=](QAudioDecoder::Error error){
Expand All @@ -26,7 +39,11 @@ AudioBuffer::AudioBuffer(QObject* parent)
state = Stopped;
emit stateChange(state);
});
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
QAudioDevice device = QMediaDevices::defaultAudioOutput();
#else
QAudioDeviceInfo device = QAudioDeviceInfo::defaultOutputDevice();
#endif
QAudioFormat format = device.preferredFormat();
decoder->setAudioFormat(format);
state = Idle;
Expand All @@ -49,6 +66,7 @@ qint64 AudioBuffer::readData(char* data, qint64 size) {
else{
size = 0;
}
qDebug() << state << size;
return size;
}

Expand All @@ -66,7 +84,11 @@ QAudioFormat AudioBuffer::getFormat(){

void AudioBuffer::start(const QString& fileName){
QFileInfo info(fileName);
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
decoder->setSource(QUrl::fromLocalFile(info.absoluteFilePath()));
#else
decoder->setSourceFilename(info.absoluteFilePath());
#endif
isFinish = false;
state = Playing;
buffer.reset();
Expand Down
Loading

0 comments on commit ba1a052

Please sign in to comment.