Skip to content

Commit

Permalink
Use libQuotient 0.9.2 facilities
Browse files Browse the repository at this point in the history
...instead of having them in Quaternion.
  • Loading branch information
KitsuneRal committed Dec 31, 2024
1 parent 8f55424 commit 4874d81
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 33 deletions.
14 changes: 1 addition & 13 deletions client/logindialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ class AccountSettings;
class AccountRegistry;
}

#if QT_VERSION_MAJOR > 5
using DeleteLater = QScopedPointerDeleteLater;
#else
struct DeleteLater {
void operator()(Quotient::Connection* ptr)
{
if (ptr)
ptr->deleteLater();
}
};
#endif

static const auto E2eeEnabledSetting = QStringLiteral("enable_e2ee");

class LoginDialog : public Dialog {
Expand Down Expand Up @@ -66,5 +54,5 @@ private slots:
QLineEdit* serverEdit;
QCheckBox* saveTokenCheck;

std::unique_ptr<Quotient::Connection, DeleteLater> m_connection;
Quotient::QObjectHolder<Quotient::Connection> m_connection;
};
19 changes: 5 additions & 14 deletions client/models/orderbytag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "roomlistmodel.h"

#include <Quotient/ranges_extras.h>
#include <Quotient/settings.h>

static const auto Invite = RoomGroup::SystemPrefix + "invite";
Expand Down Expand Up @@ -60,26 +61,16 @@ QString captionToTag(const QString& caption)
// clang-format on
}

template <typename LT, typename VT>
inline auto findIndex(const QList<LT>& list, const VT& value)
{
// Using std::find() instead of indexOf() so that not found keys were
// naturally sorted after found ones (index == list.end() - list.begin()
// is more than any index in the list, while index == -1 is less).
return std::find(list.begin(), list.end(), value) - list.begin();
}

auto findIndexWithWildcards(const QStringList& list, const QString& value)
{
if (list.empty() || value.isEmpty())
return list.size();

auto i = findIndex(list, value);
auto i = Quotient::findIndex(list, value);
// Try namespace groupings (".*" in the list), from right to left
for (int dotPos = 0;
i == list.size() && (dotPos = value.lastIndexOf('.', --dotPos)) != -1;)
{
i = findIndex(list, value.left(dotPos + 1) + '*');
for (QStringList::size_type dotPos = 0;
i == list.size() && (dotPos = value.lastIndexOf('.', --dotPos)) != -1;) {
i = Quotient::findIndex(list, value.left(dotPos + 1) + '*');
}
return i;
}
Expand Down
9 changes: 3 additions & 6 deletions client/models/userlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
#include <QtWidgets/QAbstractItemView>

#include <Quotient/connection.h>
#include <Quotient/ranges_extras.h>
#include <Quotient/room.h>
#include <Quotient/user.h>

#include <ranges>

UserListModel::UserListModel(QAbstractItemView* parent)
: QAbstractListModel(parent), m_currentRoom(nullptr)
{ }
Expand Down Expand Up @@ -162,11 +161,9 @@ void UserListModel::filter(const QString& filterString)
QElapsedTimer et; et.start();

beginResetModel();
// TODO: use std::ranges::to() once it's available from all stdlibs Quotient builds with
auto filteredMembersView =
auto filteredMembers = Quotient::rangeTo<QList>(
std::views::filter(m_currentRoom->joinedMembers(),
Quotient::memberMatcher(filterString, Qt::CaseInsensitive));
QList filteredMembers(filteredMembersView.begin(), filteredMembersView.end());
Quotient::memberMatcher(filterString, Qt::CaseInsensitive)));
std::ranges::sort(filteredMembers, Quotient::MemberSorter());
const auto sortedIds = std::views::transform(filteredMembers, &RoomMember::id);
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
Expand Down

0 comments on commit 4874d81

Please sign in to comment.