Skip to content

Commit

Permalink
Merge #709(tobias): Remove compatibility with Qt5
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneRal authored Apr 16, 2024
2 parents 70043ce + 66e84fc commit f5ef960
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 202 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ jobs:
max-parallel: 1
matrix:
os: [ ubuntu-22.04, macos-11, windows-2019 ]
qt-version: [ '6.4', '5.15' ]
qt-version: [ '6.4' ]
override-compiler: [ '', GCC ] # Defaults: MSVC on Windows, Clang elsewhere
# Not using binary values here, to make the job captions more readable
e2ee: [ e2ee, '' ]
exclude: # Drop less important combinations to lower the jobs number
- qt-version: '5.15'
e2ee: ''
- qt-version: '5.15'
override-compiler: GCC
- os: macos-11
override-compiler: GCC
- os: windows-2019
Expand Down Expand Up @@ -58,10 +54,7 @@ jobs:
COMMON_PKGS="$COMMON_PKGS clang-15" # Workaround for https://github.com/actions/runner-images/issues/8659
sudo apt-get -qq update
sudo apt-get -qq install $COMMON_PKGS \
${{ startsWith(matrix.qt-version, '5')
&& 'qtmultimedia5-dev qttools5-dev qt5keychain-dev'
|| 'qt6-base-dev libgl1-mesa-dev qt6-l10n-tools qt6-tools-dev qt6-tools-dev-tools qtkeychain-qt6-dev'
}}
qt6-base-dev libgl1-mesa-dev qt6-l10n-tools qt6-tools-dev qt6-tools-dev-tools qtkeychain-qt6-dev
gnome-keyring-daemon -d --unlock <<<'' # Create a login keyring with no password
- name: Install dependencies (non-Linux)
Expand Down
22 changes: 5 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,9 @@ set_directory_properties(PROPERTIES
CXX_VISIBILITY_PRESET hidden
)

option(BUILD_WITH_QT6 "Build Quotient with Qt 6 (EXPERIMENTAL)" OFF)
if (BUILD_WITH_QT6)
set(QUOTIENT_LIB_NAME ${PROJECT_NAME}Qt6)
else()
set(QUOTIENT_LIB_NAME ${PROJECT_NAME})
endif()
set(QtMinVersion "6.0")
string(REGEX REPLACE "^(.).*" "Qt\\1" Qt ${QtMinVersion}) # makes "Qt<MajorVersionDigit>"
set(QUOTIENT_LIB_NAME ${PROJECT_NAME}${Qt})

if (WIN32)
if (NOT CMAKE_INSTALL_LIBDIR)
Expand Down Expand Up @@ -97,14 +94,8 @@ set(${PROJECT_NAME}_INSTALL_INCLUDEDIR
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

if (BUILD_WITH_QT6)
set(QtMinVersion "6.0")
else()
set(QtMinVersion "5.15")
set(QtExtraModules "Multimedia") # See #483
endif()
string(REGEX REPLACE "^(.).*" "Qt\\1" Qt ${QtMinVersion}) # makes "Qt5" or "Qt6"
find_package(${Qt} ${QtMinVersion} REQUIRED Core Network Gui Test ${QtExtraModules})

find_package(${Qt} ${QtMinVersion} REQUIRED Core Network Gui Test)
get_filename_component(Qt_Prefix "${${Qt}_DIR}/../../../.." ABSOLUTE)

find_package(${Qt}Keychain REQUIRED)
Expand Down Expand Up @@ -322,9 +313,6 @@ target_include_directories(${QUOTIENT_LIB_NAME} PUBLIC
)

target_link_libraries(${QUOTIENT_LIB_NAME} PUBLIC ${Qt}::Core ${Qt}::Network ${Qt}::Gui qt${${Qt}Core_VERSION_MAJOR}keychain)
if (Qt STREQUAL Qt5) # See #483
target_link_libraries(${QUOTIENT_LIB_NAME} PRIVATE ${Qt}::Multimedia)
endif()

if (${PROJECT_NAME}_ENABLE_E2EE)
target_link_libraries(${QUOTIENT_LIB_NAME}
Expand Down
2 changes: 1 addition & 1 deletion Quotient.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@

Name: Quotient
Description: A Qt5 library to write cross-platfrom clients for Matrix
Description: A Qt library to write cross-platfrom clients for Matrix
Version: @API_VERSION@
Cflags: -I${includedir}
Libs: -L${libdir} -lQuotient
6 changes: 1 addition & 5 deletions Quotient/accountregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

#include <QtCore/QAbstractListModel>

#if QT_VERSION_MAJOR >= 6
#include <qt6keychain/keychain.h>
#else
#include <qt5keychain/keychain.h>
#endif
#include <qt6keychain/keychain.h>

namespace Quotient {
class Connection;
Expand Down
6 changes: 1 addition & 5 deletions Quotient/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@
#include "e2ee/qolminboundsession.h"
#endif // Quotient_E2EE_ENABLED

#if QT_VERSION_MAJOR >= 6
#include <qt6keychain/keychain.h>
#else
#include <qt5keychain/keychain.h>
#endif
#include <qt6keychain/keychain.h>

#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
Expand Down
6 changes: 1 addition & 5 deletions Quotient/connectionencryptiondata_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@
#include "events/encryptedevent.h"
#include "events/roomkeyevent.h"

#if QT_VERSION_MAJOR >= 6
#include <qt6keychain/keychain.h>
#else
#include <qt5keychain/keychain.h>
#endif
#include <qt6keychain/keychain.h>

#include <QtCore/QCoreApplication>

Expand Down
5 changes: 0 additions & 5 deletions Quotient/converters.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,6 @@ struct JsonConverter<std::array<T, N>> {
}
};

#if QT_VERSION_MAJOR < 6 // QVector is an alias of QList in Qt6 but not in Qt 5
template <typename T>
struct JsonConverter<QVector<T>> : public JsonArrayConverter<QVector<T>> {};
#endif

template <typename T>
struct JsonConverter<QList<T>> : public JsonArrayConverter<QList<T>> {};

Expand Down
40 changes: 0 additions & 40 deletions Quotient/events/roommessageevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
#include <QtCore/QMimeDatabase>
#include <QtGui/QImageReader>

#if QT_VERSION_MAJOR < 6
#include <QtMultimedia/QMediaResource>
#endif

using namespace Quotient;
using namespace EventContent;

Expand Down Expand Up @@ -139,42 +135,6 @@ RoomMessageEvent::RoomMessageEvent(const QString& plainBody, MsgType msgType,
: RoomMessageEvent(plainBody, msgTypeToJson(msgType), content)
{}

#if QT_VERSION_MAJOR < 6
TypedBase* contentFromFile(const QFileInfo& file, bool asGenericFile)
{
auto filePath = file.absoluteFilePath();
auto localUrl = QUrl::fromLocalFile(filePath);
auto mimeType = QMimeDatabase().mimeTypeForFile(file);
if (!asGenericFile) {
auto mimeTypeName = mimeType.name();
if (mimeTypeName.startsWith("image/"_ls))
return new ImageContent(localUrl, file.size(), mimeType,
QImageReader(filePath).size(),
file.fileName());

// duration can only be obtained asynchronously and can only be reliably
// done by starting to play the file. Left for a future implementation.
if (mimeTypeName.startsWith("video/"_ls))
return new VideoContent(localUrl, file.size(), mimeType,
QMediaResource(localUrl).resolution(),
file.fileName());

if (mimeTypeName.startsWith("audio/"_ls))
return new AudioContent(localUrl, file.size(), mimeType,
file.fileName());
}
return new FileContent(localUrl, file.size(), mimeType, file.fileName());
}

RoomMessageEvent::RoomMessageEvent(const QString& plainBody,
const QFileInfo& file, bool asGenericFile)
: RoomMessageEvent(plainBody,
asGenericFile ? QStringLiteral("m.file")
: rawMsgTypeForFile(file),
contentFromFile(file, asGenericFile))
{}
#endif

RoomMessageEvent::RoomMessageEvent(const QJsonObject& obj)
: RoomEvent(obj), _content(nullptr)
{
Expand Down
7 changes: 1 addition & 6 deletions Quotient/events/roommessageevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ class QUOTIENT_API RoomMessageEvent : public RoomEvent {
explicit RoomMessageEvent(const QString& plainBody,
MsgType msgType = MsgType::Text,
EventContent::TypedBase* content = nullptr);
#if QT_VERSION_MAJOR < 6
[[deprecated("Create an EventContent object on the client side"
" and pass it to other constructors")]] //
explicit RoomMessageEvent(const QString& plainBody, const QFileInfo& file,
bool asGenericFile = false);
#endif

explicit RoomMessageEvent(const QJsonObject& obj);

MsgType msgtype() const;
Expand Down
23 changes: 0 additions & 23 deletions Quotient/qt_connection_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,9 @@ inline auto connectSingleShot(auto* sender, auto signal, ContextT* context,
SlotT slot,
Qt::ConnectionType connType = Qt::AutoConnection)
{
#if QT_VERSION_MAJOR >= 6
return QObject::connect(sender, signal, context, slot,
Qt::ConnectionType(connType
| Qt::SingleShotConnection));
#else
// In case of classic Qt pointer-to-member-function slots the receiver
// object has to be pre-bound to the slot to make it self-contained
if constexpr (_impl::PmfSlot<SlotT, ContextT>) {
auto&& boundSlot =
#if __cpp_lib_bind_front // Needs Apple Clang 13 (other platforms are fine)
std::bind_front(slot, context);
#else
[context, slot](const auto&... args)
requires requires { (context->*slot)(args...); }
{
(context->*slot)(args...);
};
#endif
return _impl::connect<_impl::SingleShot>(
sender, signal, context,
std::forward<decltype(boundSlot)>(boundSlot), connType);
} else {
return _impl::connect<_impl::SingleShot>(sender, signal, context, slot,
connType);
}
#endif
}

/*! \brief A guard pointer that disconnects an interested object upon destruction
Expand Down
24 changes: 2 additions & 22 deletions Quotient/room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2409,18 +2409,6 @@ QString Room::postFile(const QString& plainText,
fileInfo->url());
}

#if QT_VERSION_MAJOR < 6
QString Room::postFile(const QString& plainText, const QUrl& localPath,
bool asGenericFile)
{
QFileInfo localFile { localPath.toLocalFile() };
Q_ASSERT(localFile.isFile());
return d->doPostFile(makeEvent<RoomMessageEvent>(plainText, localFile,
asGenericFile),
localPath);
}
#endif

QString Room::postEvent(RoomEvent* event)
{
return d->sendEvent(RoomEventPtr(event));
Expand Down Expand Up @@ -3701,11 +3689,7 @@ bool MemberSorter::operator()(const RoomMember& u1, QStringView u2name) const
auto n1 = u1.displayName();
if (n1.startsWith(u'@'))
n1.remove(0, 1);
const auto n2 = u2name.mid(u2name.startsWith(u'@') ? 1 : 0)
#if QT_VERSION_MAJOR < 6
.toString() // Qt 5 doesn't have QStringView::localeAwareCompare
#endif
;
const auto n2 = u2name.mid(u2name.startsWith(u'@') ? 1 : 0);

return n1.localeAwareCompare(n2) < 0;
}
Expand All @@ -3715,11 +3699,7 @@ bool MemberSorter::operator()(User* u1, QStringView u2name) const
QT_IGNORE_DEPRECATIONS(auto n1 = room->disambiguatedMemberName(u1->id());)
if (n1.startsWith(u'@'))
n1.remove(0, 1);
const auto n2 = u2name.mid(u2name.startsWith(u'@') ? 1 : 0)
#if QT_VERSION_MAJOR < 6
.toString() // Qt 5 doesn't have QStringView::localeAwareCompare
#endif
;
const auto n2 = u2name.mid(u2name.startsWith(u'@') ? 1 : 0);

return n1.localeAwareCompare(n2) < 0;
}
Expand Down
6 changes: 1 addition & 5 deletions Quotient/room.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,11 +847,7 @@ public Q_SLOTS:
QString postReaction(const QString& eventId, const QString& key);

QString postFile(const QString& plainText, EventContent::TypedBase* content);
#if QT_VERSION_MAJOR < 6
Q_DECL_DEPRECATED_X("Use postFile(QString, MessageEventType, EventContent)") //
QString postFile(const QString& plainText, const QUrl& localPath,
bool asGenericFile = false);
#endif

/** Post a pre-created room message event
*
* Takes ownership of the event, deleting it once the matching one
Expand Down
6 changes: 1 addition & 5 deletions Quotient/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ void Settings::setLegacyNames(const QString& organizationName,
}

Settings::Settings(QObject* parent) : QSettings(parent)
{
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
setIniCodec("UTF-8");
#endif
}
{}

void Settings::setValue(const QString& key, const QVariant& value)
{
Expand Down
17 changes: 0 additions & 17 deletions Quotient/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@
#include <memory>
#include <unordered_map>

#ifndef Q_DISABLE_MOVE
// Q_DISABLE_MOVE was introduced in Q_VERSION_CHECK(5,13,0)
#define Q_DISABLE_MOVE(_ClassName) \
_ClassName(_ClassName&&) Q_DECL_EQ_DELETE; \
_ClassName& operator=(_ClassName&&) Q_DECL_EQ_DELETE;
#endif

#ifndef Q_DISABLE_COPY_MOVE
#define Q_DISABLE_COPY_MOVE(Class) \
Q_DISABLE_COPY(Class) \
Q_DISABLE_MOVE(Class)
#endif

#define DISABLE_MOVE(_ClassName) \
static_assert(false, "Use Q_DISABLE_MOVE instead; Quotient enables it across all used versions of Qt");

Expand Down Expand Up @@ -61,11 +48,7 @@ template <typename T>
struct HashQ {
size_t operator()(const T& s) const Q_DECL_NOEXCEPT
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
return qHash(s, uint(QHashSeed::globalSeed()));
#else
return qHash(s, uint(qGlobalQHashSeed()));
#endif
}
};
/// A wrapper around std::unordered_map compatible with types that have qHash
Expand Down
Loading

0 comments on commit f5ef960

Please sign in to comment.