Skip to content

Commit

Permalink
Merge #838: Port to libQuotient's keychain and account handling
Browse files Browse the repository at this point in the history
  • Loading branch information
KitsuneRal authored Jan 5, 2023
2 parents 316ab44 + c163296 commit 8794402
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 513 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:
run: |
git clone --depth=1 -b $QUOTIENT_REF https://github.com/quotient-im/libQuotient
cd libQuotient
cmake -S . -B build $CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=~/.local
cmake -S . -B build $CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=~/.local -DCMAKE_PREFIX_PATH=~/.local
cmake --build build --target install
if [[ '${{ matrix.composition }}' == 'dynamic' ]]; then
QUOTIENT_SO_PATH=$(dirname $(find ~/.local/lib* -name libQuotient.so))
Expand Down
8 changes: 0 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ if (NOT USE_INTREE_LIBQMC)
endif ()
endif ()

find_package(${Qt}Keychain REQUIRED)

message( STATUS )
message( STATUS "=============================================================================" )
message( STATUS " Quaternion ${quaternion_VERSION} Build Information" )
Expand Down Expand Up @@ -140,13 +138,11 @@ if (USE_INTREE_LIBQMC)
else ()
message( STATUS "Using libQuotient ${Quotient_VERSION} at ${Quotient_DIR}")
endif ()
message( STATUS "Using Qt Keychain ${${Qt}Keychain_VERSION} at ${${Qt}Keychain_DIR}")
message( STATUS "=============================================================================" )
message( STATUS )

# Set up source files
set(quaternion_SRCS
client/accountregistry.cpp
client/quaternionroom.cpp
client/htmlfilter.cpp
client/imageprovider.cpp
Expand Down Expand Up @@ -234,10 +230,6 @@ endif ()
target_link_libraries(${PROJECT_NAME} Quotient
${Qt}::Widgets ${Qt}::Quick ${Qt}::Qml ${Qt}::Gui ${Qt}::Network ${Qt}::QuickControls2 ${Qt}::QuickWidgets)

target_compile_definitions(${PROJECT_NAME} PRIVATE USE_KEYCHAIN) # Legacy, remove in 0.0.96+
target_link_libraries(${PROJECT_NAME} ${QTKEYCHAIN_LIBRARIES})
include_directories(${QTKEYCHAIN_INCLUDE_DIR})

# macOS specific config for bundling
if (APPLE)
set_property(TARGET ${PROJECT_NAME} PROPERTY MACOSX_BUNDLE_INFO_PLIST
Expand Down
24 changes: 0 additions & 24 deletions client/accountregistry.cpp

This file was deleted.

35 changes: 0 additions & 35 deletions client/accountregistry.h

This file was deleted.

48 changes: 28 additions & 20 deletions client/accountselector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,42 @@

#include <connection.h>

AccountSelector::AccountSelector(const AccountRegistry *registry, QWidget *parent)
using namespace Quotient;

AccountSelector::AccountSelector(QWidget *parent)
: QComboBox(parent)
{
connect(this, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
[this] { emit currentAccountChanged(currentAccount()); });

const auto& accounts = registry->accounts();
const auto& accounts = Accounts.accounts();
for (auto* acc: accounts)
addItem(acc->userId(), QVariant::fromValue(acc));

connect(registry, &AccountRegistry::addedAccount, this, [this](Account* acc) {
if (const auto idx = indexOfAccount(acc); idx == -1)
addItem(acc->userId(), QVariant::fromValue(acc));
else
qWarning()
<< "AccountComboBox: refusing to add the same account twice";
connect(&Accounts, &AccountRegistry::rowsInserted, this, [this](const QModelIndex&, int first, int last) {
for (int i = first; i < last; i++) {
auto acc = Accounts.accounts()[i];
if (const auto idx = indexOfAccount(acc); idx == -1)
addItem(acc->userId(), QVariant::fromValue(acc));
else
qWarning()
<< "AccountComboBox: refusing to add the same account twice";
}
});
connect(registry, &AccountRegistry::aboutToDropAccount, this,
[this](Account* acc) {
if (const auto idx = indexOfAccount(acc); idx != -1)
removeItem(idx);
else
qWarning()
<< "AccountComboBox: account to drop not found, ignoring";
connect(&Accounts, &AccountRegistry::rowsAboutToBeRemoved, this,
[this](const QModelIndex&, int first, int last) {
for (int i = first; i < last; i++) {
auto acc = Accounts.accounts()[i];
if (const auto idx = indexOfAccount(acc); idx != -1)
removeItem(idx);
else
qWarning()
<< "AccountComboBox: account to drop not found, ignoring";
}
});
}

void AccountSelector::setAccount(Account *newAccount)
void AccountSelector::setAccount(Connection *newAccount)
{
if (!newAccount) {
setCurrentIndex(-1);
Expand All @@ -45,15 +53,15 @@ void AccountSelector::setAccount(Account *newAccount)
<< "wasn't found in the full list of accounts";
}

AccountSelector::Account* AccountSelector::currentAccount() const
Connection* AccountSelector::currentAccount() const
{
return currentData().value<Account*>();
return currentData().value<Connection*>();
}

int AccountSelector::indexOfAccount(Account* a) const
int AccountSelector::indexOfAccount(Connection* a) const
{
for (int i = 0; i < count(); ++i)
if (itemData(i).value<Account*>() == a)
if (itemData(i).value<Connection*>() == a)
return i;

return -1;
Expand Down
19 changes: 11 additions & 8 deletions client/accountselector.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#pragma once

#include "accountregistry.h"
#include <accountregistry.h>

#include <QtWidgets/QComboBox>

namespace Quotient
{
class Connection;
}

class AccountSelector : public QComboBox
{
Q_OBJECT
public:
using Account = AccountRegistry::Account;

AccountSelector(const AccountRegistry* registry, QWidget* parent = nullptr);
AccountSelector(QWidget* parent = nullptr);

void setAccount(Account* newAccount);
Account* currentAccount() const;
int indexOfAccount(Account* a) const;
void setAccount(Quotient::Connection* newAccount);
Quotient::Connection* currentAccount() const;
int indexOfAccount(Quotient::Connection* a) const;

signals:
void currentAccountChanged(Account* newAccount);
void currentAccountChanged(Quotient::Connection* newAccount);
};

Loading

0 comments on commit 8794402

Please sign in to comment.