Skip to content
Snippets Groups Projects
Commit f2ba34ca authored by Andreas Traczyk's avatar Andreas Traczyk
Browse files

accounts: introduce currentaccount

A structure to represent the currently selected account and it's
properties as observables.

Change-Id: I6b4ae92e15b492a4c4d61ec5da019e2c7e937401
parent 2410262f
No related branches found
No related tags found
No related merge requests found
......@@ -88,7 +88,8 @@ set(COMMON_SOURCES
${SRC_DIR}/filestosendlistmodel.cpp
${SRC_DIR}/wizardviewstepmodel.cpp
${SRC_DIR}/avatarregistry.cpp
${SRC_DIR}/currentconversation.cpp)
${SRC_DIR}/currentconversation.cpp
${SRC_DIR}/currentaccount.cpp)
set(COMMON_HEADERS
${SRC_DIR}/avatarimageprovider.h
......@@ -147,7 +148,8 @@ set(COMMON_HEADERS
${SRC_DIR}/filestosendlistmodel.h
${SRC_DIR}/wizardviewstepmodel.h
${SRC_DIR}/avatarregistry.h
${SRC_DIR}/currentconversation.h)
${SRC_DIR}/currentconversation.h
${SRC_DIR}/currentaccount.h)
set(QML_LIBS
Qt5::Quick
......
/*
* Copyright (C) 2021 by Savoir-faire Linux
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "currentaccount.h"
CurrentAccount::CurrentAccount(LRCInstance* lrcInstance, QObject* parent)
: QObject(parent)
, lrcInstance_(lrcInstance)
{
connect(&lrcInstance_->accountModel(),
&NewAccountModel::accountStatusChanged,
this,
&CurrentAccount::onAccountUpdated);
connect(&lrcInstance_->accountModel(),
&NewAccountModel::profileUpdated,
this,
&CurrentAccount::onAccountUpdated);
connect(lrcInstance_, &LRCInstance::currentAccountIdChanged, [this] { updateData(); });
updateData();
}
void
CurrentAccount::onAccountUpdated(const QString& id)
{
// filter for our currently set id
if (id_ != id)
return;
updateData();
}
void
CurrentAccount::updateData()
{
set_id(lrcInstance_->get_currentAccountId());
try {
const auto& accInfo = lrcInstance_->getAccountInfo(id_);
set_uri(accInfo.profileInfo.uri);
set_registeredName(accInfo.registeredName);
set_alias(accInfo.profileInfo.alias);
set_bestId(lrcInstance_->accountModel().bestIdForAccount(id_));
set_bestName(lrcInstance_->accountModel().bestNameForAccount(id_));
set_hasAvatarSet(!accInfo.profileInfo.avatar.isEmpty());
set_status(accInfo.status);
set_type(accInfo.profileInfo.type);
} catch (...) {
qWarning() << "Can't update current account data for" << id_;
}
}
/*
* Copyright (C) 2021 by Savoir-faire Linux
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "lrcinstance.h"
#include <QObject>
#include <QString>
class CurrentAccount final : public QObject
{
Q_OBJECT
QML_RO_PROPERTY(QString, id)
QML_RO_PROPERTY(QString, uri)
QML_RO_PROPERTY(QString, registeredName)
QML_RO_PROPERTY(QString, alias)
QML_RO_PROPERTY(QString, bestId)
QML_RO_PROPERTY(QString, bestName)
QML_RO_PROPERTY(bool, hasAvatarSet)
QML_RO_PROPERTY(lrc::api::account::Status, status)
QML_RO_PROPERTY(lrc::api::profile::Type, type)
public:
explicit CurrentAccount(LRCInstance* lrcInstance, QObject* parent = nullptr);
~CurrentAccount() = default;
private Q_SLOTS:
void updateData();
void onAccountUpdated(const QString& id);
private:
LRCInstance* lrcInstance_;
};
......@@ -103,20 +103,6 @@ Label {
}
}
Connections {
target: AccountListModel
function onModelReset() {
avatar.imageId = LRCInstance.currentAccountId
avatar.presenceStatus = AccountListModel.data(AccountListModel.index(0, 0),
AccountList.Status)
userAliasText.text = AccountListModel.data(AccountListModel.index(0,0),
AccountList.Alias)
usernameText.text = AccountListModel.data(AccountListModel.index(0,0),
AccountList.Username)
}
}
RowLayout {
anchors.fill: parent
anchors.leftMargin: 15
......@@ -130,11 +116,9 @@ Label {
Layout.preferredHeight: JamiTheme.accountListAvatarSize
Layout.alignment: Qt.AlignVCenter
imageId: LRCInstance.currentAccountId
mode: Avatar.Mode.Account
presenceStatus: AccountListModel.data(
AccountListModel.index(0, 0), AccountList.Status)
imageId: CurrentAccount.id
presenceStatus: CurrentAccount.status
}
ColumnLayout {
......@@ -143,28 +127,26 @@ Label {
spacing: 2
Text {
id: userAliasText
id: bestNameText
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
text: AccountListModel.data(AccountListModel.index(0,0),
AccountList.Alias)
text: CurrentAccount.bestName
font.pointSize: JamiTheme.textFontSize
color: JamiTheme.textColor
elide: Text.ElideRight
}
Text {
id: usernameText
id: bestIdText
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
visible: text.length && text != userAliasText.text
visible: text.length && text !== bestNameText.text
text: AccountListModel.data(AccountListModel.index(0,0),
AccountList.Username)
text: CurrentAccount.bestId
font.pointSize: JamiTheme.textFontSize
color: JamiTheme.faddedLastInteractionFontColor
elide: Text.ElideRight
......
......@@ -22,7 +22,6 @@ import QtQuick.Layouts 1.14
import net.jami.Models 1.0
import net.jami.Adapters 1.0
import net.jami.Constants 1.0
import "../../commoncomponents"
......@@ -49,12 +48,7 @@ ModalPopup {
smooth: false
fillMode: Image.PreserveAspectFit
source: {
if (LRCInstance.currentAccountId &&
LRCInstance.currentAccountType === Profile.Type.JAMI)
return "image://qrImage/account_" + LRCInstance.currentAccountId
return ""
}
source: "image://qrImage/account_" + CurrentAccount.id
}
}
}
......@@ -28,6 +28,7 @@
#include "utilsadapter.h"
#include "conversationsadapter.h"
#include "currentconversation.h"
#include "currentaccount.h"
#include "accountlistmodel.h"
#include "accountstomigratelistmodel.h"
......@@ -116,6 +117,7 @@ registerTypes(QQmlEngine* engine,
auto settingsAdapter = new SettingsAdapter(appSettingsManager, lrcInstance, parent);
auto pluginAdapter = new PluginAdapter(lrcInstance, parent);
auto currentConversation = new CurrentConversation(lrcInstance, parent);
auto currentAccount = new CurrentAccount(lrcInstance, parent);
// qml adapter registration
QML_REGISTERSINGLETONTYPE_POBJECT(NS_ADAPTERS, callAdapter, "CallAdapter");
......@@ -128,6 +130,7 @@ registerTypes(QQmlEngine* engine,
QML_REGISTERSINGLETONTYPE_POBJECT(NS_ADAPTERS, settingsAdapter, "SettingsAdapter");
QML_REGISTERSINGLETONTYPE_POBJECT(NS_ADAPTERS, pluginAdapter, "PluginAdapter");
QML_REGISTERSINGLETONTYPE_POBJECT(NS_ADAPTERS, currentConversation, "CurrentConversation");
QML_REGISTERSINGLETONTYPE_POBJECT(NS_ADAPTERS, currentAccount, "CurrentAccount");
// TODO: remove these
QML_REGISTERSINGLETONTYPE_CUSTOM(NS_MODELS, AVModel, &lrcInstance->avModel())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment