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

qml interop: refactor and remove utilsadapter from clientwrapper

- Separate utilsadapter into files and expose it to Qml so it can
  be used without passing through clientwrapper.

Change-Id: I7c351d7191cd166521b6e0a685ea9d4a9731f165
Gitlab: #66
parent a364b619
No related branches found
No related tags found
No related merge requests found
Showing
with 63 additions and 63 deletions
......@@ -153,7 +153,9 @@ HEADERS += ./src/smartlistmodel.h \
./src/videoformatfpsmodel.h \
./src/videoformatresolutionmodel.h \
./src/audiomanagerlistmodel.h \
src/qmlregister.h
src/qmlregister.h \
src/qtutils.h \
src/utilsadapter.h
SOURCES += ./src/bannedlistmodel.cpp \
./src/accountlistmodel.cpp \
......@@ -192,7 +194,8 @@ SOURCES += ./src/bannedlistmodel.cpp \
./src/videoformatfpsmodel.cpp \
./src/videoformatresolutionmodel.cpp \
./src/audiomanagerlistmodel.cpp \
src/qmlregister.cpp
src/qmlregister.cpp \
src/utilsadapter.cpp
RESOURCES += ./resources.qrc \
./qml.qrc
......@@ -29,7 +29,7 @@ ApplicationWindow {
// If we're in the onboarding wizard or 'MinimizeOnClose'
// is set, then we can quit
if (!SettingsAdapter.getAppValue(Settings.MinimizeOnClose) ||
!ClientWrapper.utilsAdaptor.getAccountListSize()) {
!UtilsAdapter.getAccountListSize()) {
Qt.quit()
} else {
// hide to the systray
......@@ -53,7 +53,7 @@ ApplicationWindow {
setX(Screen.width / 2 - width / 2)
setY(Screen.height / 2 - height / 2)
if (!ClientWrapper.utilsAdaptor.getAccountListSize()) {
if (!UtilsAdapter.getAccountListSize()) {
wizardView.show()
} else {
mainViewLoader.setSource("qrc:/src/mainview/MainView.qml")
......
......@@ -23,6 +23,8 @@
#include "accountadapter.h"
#include "qtutils.h"
#undef REGISTERED
#include "../daemon/src/dring/account_const.h"
......@@ -58,14 +60,12 @@ AccountAdapter::connectFailure()
&lrc::api::NewAccountModel::accountRemoved,
[this](const QString &accountId) {
Q_UNUSED(accountId);
emit reportFailure();
});
Utils::oneShotConnect(&LRCInstance::accountModel(),
&lrc::api::NewAccountModel::invalidAccountDetected,
[this](const QString &accountId) {
Q_UNUSED(accountId);
emit reportFailure();
});
}
......@@ -113,7 +113,7 @@ AccountAdapter::createJamiAccount(QString registeredName,
connectFailure();
QtConcurrent::run([this, settings] {
QtConcurrent::run([settings] {
QMap<QString, QString> additionalAccountConfig;
additionalAccountConfig.insert(DRing::Account::ConfProperties::Ringtone::PATH,
Utils::GetRingtonePath());
......@@ -162,7 +162,7 @@ AccountAdapter::createSIPAccount(const QVariantMap &settings, QString photoBooth
connectFailure();
QtConcurrent::run([this, settings] {
QtConcurrent::run([settings] {
QMap<QString, QString> additionalAccountConfig;
additionalAccountConfig.insert(DRing::Account::ConfProperties::Ringtone::PATH,
Utils::GetRingtonePath());
......@@ -194,7 +194,7 @@ AccountAdapter::createJAMSAccount(const QVariantMap &settings)
connectFailure();
QtConcurrent::run([this, settings] {
QtConcurrent::run([settings] {
QMap<QString, QString> additionalAccountConfig;
additionalAccountConfig.insert(DRing::Account::ConfProperties::Ringtone::PATH,
Utils::GetRingtonePath());
......@@ -302,7 +302,7 @@ AccountAdapter::exportToFile(const QString &accountId,
void
AccountAdapter::setArchivePasswordAsync(const QString &accountID, const QString &password)
{
QtConcurrent::run([this, accountID, password] {
QtConcurrent::run([accountID, password] {
auto config = LRCInstance::accountModel().getAccountConfig(accountID);
config.archivePassword = password;
LRCInstance::accountModel().setAccountConfig(accountID, config);
......@@ -404,7 +404,7 @@ AccountAdapter::connectAccount(const QString &accountId)
addedToConferenceConnection_
= QObject::connect(accInfo.callModel.get(),
&NewCallModel::callAddedToConference,
[this](const QString &callId, const QString &confId) {
[](const QString &callId, const QString &confId) {
Q_UNUSED(callId);
LRCInstance::renderer()->addDistantRenderer(confId);
});
......
......@@ -75,9 +75,9 @@ AccountListModel::data(const QModelIndex &index, int role) const
return QVariant(Utils::secondBestNameForAccount(accountInfo));
case Role::Type:
return QVariant(
Utils::toUnderlyingValue<lrc::api::profile::Type>(accountInfo.profileInfo.type));
static_cast<int>(accountInfo.profileInfo.type));
case Role::Status:
return QVariant(Utils::toUnderlyingValue<lrc::api::account::Status>(accountInfo.status));
return QVariant(static_cast<int>(accountInfo.status));
case Role::Picture:
return QString::fromLatin1(
Utils::QImageToByteArray(Utils::accountPhoto(accountInfo)).toBase64().data());
......
......@@ -62,7 +62,7 @@ public:
static QString toString(Key key)
{
return QMetaEnum::fromType<Key>().valueToKey(
Utils::toUnderlyingValue(key));
static_cast<int>(key));
}
static QVariant defaultValue(const Key key)
{
......@@ -88,8 +88,7 @@ class AppSettingsManager : public QObject
public:
virtual ~AppSettingsManager() = default;
static AppSettingsManager&
instance()
static AppSettingsManager &instance()
{
static AppSettingsManager *instance_ =
new AppSettingsManager(nullptr);
......@@ -120,9 +119,9 @@ public:
initValues()
{
for (int i = 0;
i < Utils::toUnderlyingValue(Settings::Key::COUNT__);
i < static_cast<int>(Settings::Key::COUNT__);
++i) {
auto key = Utils::toEnum<Settings::Key>(i);
auto key = static_cast<Settings::Key>(i);
if (!instance().settings_->contains(Settings::toString(key)))
setValue(key, Settings::defaultValue(key));
}
......
......@@ -22,6 +22,7 @@
#include "lrcinstance.h"
#include <QApplication>
#include <QScreen>
AvAdapter::AvAdapter(QObject *parent)
......
......@@ -62,9 +62,9 @@ BannedListModel::data(const QModelIndex &index, int role) const
case Role::ContactID:
return QVariant(contactInfo.profileInfo.uri);
case Role::ContactPicture:
QImage avatarImage = Utils::fallbackAvatar(QSize(48, 48),
contactInfo.profileInfo.uri,
contactInfo.registeredName);
QImage avatarImage = Utils::fallbackAvatar(contactInfo.profileInfo.uri,
contactInfo.registeredName,
QSize(48, 48));
return QString::fromLatin1(Utils::QImageToByteArray(avatarImage).toBase64().data());
}
......
......@@ -596,7 +596,7 @@ CallAdapter::getCurrentLayoutType() const
auto* callModel = LRCInstance::getAccountInfo(accountId_).callModel.get();
try {
auto call = callModel->getCall(convInfo.confId);
return Utils::toUnderlyingValue(call.layout);
return static_cast<int>(call.layout);
} catch (...) {
}
}
......
......@@ -36,12 +36,6 @@ ClientWrapper::getNameDirectory()
return &(NameDirectory::instance());
}
UtilsAdapter *
ClientWrapper::getUtilsAdapter()
{
return &(UtilsAdapter::instance());
}
SettingsAdapter *
ClientWrapper::getSettingsAdapter()
{
......
......@@ -41,7 +41,6 @@
#include "previewrenderer.h"
#include "qrimageprovider.h"
#include "settingsadapter.h"
#include "utils.h"
#include "version.h"
#include "videocodeclistmodel.h"
......@@ -51,7 +50,6 @@ class ClientWrapper : public QObject
{
Q_OBJECT
Q_PROPERTY(UtilsAdapter *utilsAdaptor READ getUtilsAdapter NOTIFY utilsAdaptorChanged)
Q_PROPERTY(SettingsAdapter *SettingsAdapter READ getSettingsAdapter NOTIFY SettingsAdapterChanged)
Q_PROPERTY(NameDirectory *nameDirectory READ getNameDirectory NOTIFY nameDirectoryChanged)
Q_PROPERTY(LRCInstance *lrcInstance READ getLRCInstance NOTIFY lrcInstanceChanged)
......@@ -67,7 +65,6 @@ public:
explicit ClientWrapper(QObject *parent = nullptr);
NameDirectory *getNameDirectory();
UtilsAdapter *getUtilsAdapter();
SettingsAdapter *getSettingsAdapter();
LRCInstance *getLRCInstance();
AccountAdapter *getAccountAdapter();
......@@ -82,7 +79,6 @@ public:
lrc::api::PluginModel *getPluginModel();
signals:
void utilsAdaptorChanged();
void SettingsAdapterChanged();
void nameDirectoryChanged();
void lrcInstanceChanged();
......
......@@ -112,8 +112,11 @@ Dialog {
function exportAccountQML() {
var success = false
if(path.length > 0){
success = ClientWrapper.accountAdaptor.exportToFile(ClientWrapper.utilsAdaptor.getCurrAccId(),path,currentPasswordEdit.text)
if (path.length > 0) {
success = ClientWrapper.accountAdaptor.exportToFile(
UtilsAdapter.getCurrAccId(),
path,
currentPasswordEdit.text)
}
if (success) {
......@@ -126,8 +129,10 @@ Dialog {
function savePasswordQML() {
var success = false
success = ClientWrapper.accountAdaptor.savePassword(ClientWrapper.utilsAdaptor.getCurrAccId(),currentPasswordEdit.text, passwordEdit.text)
success = ClientWrapper.accountAdaptor.savePassword(
UtilsAdapter.getCurrAccId(),
currentPasswordEdit.text,
passwordEdit.text)
if (success) {
ClientWrapper.accountAdaptor.setArchiveHasPassword(passwordEdit.text.length !== 0)
haveDone(successCode, root.purpose)
......
......@@ -61,12 +61,13 @@ ColumnLayout {
onAccepted: {
fileName = file
if(fileName.length === 0) {
if (fileName.length === 0) {
imageCleared()
return
}
imgBase64 = ClientWrapper.utilsAdaptor.getCroppedImageBase64FromFile(
ClientWrapper.utilsAdaptor.getAbsPath(fileName),boothWidth)
imgBase64 = UtilsAdapter.getCroppedImageBase64FromFile(
UtilsAdapter.getAbsPath(fileName),
boothWidth)
imageAcquired()
stopBooth()
}
......
......@@ -80,7 +80,7 @@ ItemDelegate {
folder: "file://" + currentPath
onAccepted: {
var url = ClientWrapper.utilsAdaptor.getAbsPath(fileUrl.toString())
var url = UtilsAdapter.getAbsPath(fileUrl.toString())
preferenceNewValue = url
btnPreferenceClicked()
}
......
......@@ -34,7 +34,7 @@ ContactAdapter::getContactSelectableModel(int type)
/*
* Called from qml every time contact picker refreshes.
*/
listModeltype_ = Utils::toEnum<SmartListModel::Type>(type);
listModeltype_ = static_cast<SmartListModel::Type>(type);
smartListModel_.reset(new SmartListModel(LRCInstance::getCurrAccId(),
this,
listModeltype_,
......
......@@ -208,10 +208,10 @@ public:
return *conv;
}
} else {
for (int i = Utils::toUnderlyingValue(profile::Type::RING);
i <= Utils::toUnderlyingValue(profile::Type::TEMPORARY);
for (int i = static_cast<int>(profile::Type::RING);
i <= static_cast<int>(profile::Type::TEMPORARY);
++i) {
auto filter = Utils::toEnum<profile::Type>(i);
auto filter = static_cast<profile::Type>(i);
auto &convs = convModel->getFilteredConversations(filter);
auto conv = std::find_if(convs.begin(), convs.end(), pred);
if (conv != convs.end()) {
......
......@@ -22,6 +22,7 @@ import QtQuick.Layouts 1.14
import QtQuick.Controls.Universal 2.12
import QtGraphicalEffects 1.14
import net.jami.Models 1.0
import net.jami.Adapters 1.0
// Import qml component files.
......@@ -196,9 +197,9 @@ Window {
toggleSettingsView()
}
var index = ClientWrapper.utilsAdaptor.getCurrAccList().indexOf(accountId)
var name = ClientWrapper.utilsAdaptor.getBestName(accountId, convUid)
var id = ClientWrapper.utilsAdaptor.getBestId(accountId, convUid)
var index = UtilsAdapter.getCurrAccList().indexOf(accountId)
var name = UtilsAdapter.getBestName(accountId, convUid)
var id = UtilsAdapter.getBestId(accountId, convUid)
communicationPageMessageWebView.headerUserAliasLabelText = name
communicationPageMessageWebView.headerUserUserNameLabelText = (name !== id) ? id : ""
......@@ -308,7 +309,7 @@ Window {
settingsView.setSelected(settingsView.selectedMenu, true)
if (needToShowCallStack
&& callStackView.responsibleAccountId === ClientWrapper.utilsAdaptor.getCurrAccId()){
&& callStackView.responsibleAccountId === UtilsAdapter.getCurrAccId()){
if (!ClientWrapper.accountAdaptor.hasVideoCall()) {
pushCommunicationMessageWebView()
needToShowCallStack = false
......@@ -419,20 +420,18 @@ Window {
communicationPageMessageWebView.headerUserUserNameLabelText = currentUserDisplayName
callStackView.needToCloseInCallConversationAndPotentialWindow()
callStackView.responsibleAccountId = ClientWrapper.utilsAdaptor.getCurrAccId()
callStackView.responsibleAccountId = UtilsAdapter.getCurrAccId()
callStackView.responsibleConvUid = currentUID
callStackView.updateCorrspondingUI()
if (callStackViewShouldShow) {
if (callState === Call.Status.IN_PROGRESS || callState === Call.Status.PAUSED) {
ClientWrapper.utilsAdaptor.setCurrentCall(
ClientWrapper.utilsAdaptor.getCurrAccId(),
currentUID)
UtilsAdapter.setCurrentCall(UtilsAdapter.getCurrAccId(), currentUID)
if (isAudioOnly)
callStackView.showAudioCallPage()
else
callStackView.showVideoCallPage(
ClientWrapper.utilsAdaptor.getCallId(
UtilsAdapter.getCallId(
callStackView.responsibleAccountId,
callStackView.responsibleConvUid))
} else {
......@@ -751,7 +750,7 @@ Window {
sequence: "Ctrl+Shift+A"
context: Qt.ApplicationShortcut
onActivated: {
ClientWrapper.utilsAdaptor.makePermanentCurrentConv()
UtilsAdapter.makePermanentCurrentConv()
communicationPageMessageWebView.setSendContactRequestButtonVisible(false)
}
}
......
/*
* Copyright (C) 2020 by Savoir-faire Linux
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
......@@ -16,10 +15,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import net.jami.Models 1.0
import net.jami.Adapters 1.0
import "../../commoncomponents"
......@@ -30,7 +31,6 @@ Dialog {
// When dialog is opened, trigger mainViewWindow overlay which is defined in overlay.model (model : true is necessary).
modal: true
// Content height + margin.
contentHeight: aboutPopUpContentRectColumnLayout.height + 5 * 7
......@@ -83,7 +83,7 @@ Dialog {
TextMetrics {
id: textMetricsjamiVersionText
font: jamiVersionText.font
text: qsTr("version") + ": " + ClientWrapper.utilsAdaptor.getVersionStr()
text: qsTr("version") + ": " + UtilsAdapter.getVersionStr()
}
}
......
/*
* Copyright (C) 2020 by Savoir-faire Linux
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
......@@ -16,11 +15,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import QtQuick.Controls.Universal 2.12
import net.jami.Models 1.0
import net.jami.Adapters 1.0
import "../../commoncomponents"
......@@ -34,11 +35,11 @@ Rectangle {
property var linkedWebview: null
function updateUI(accountId, convUid) {
contactImgSource = "data:image/png;base64," + ClientWrapper.utilsAdaptor.getContactImageString(
contactImgSource = "data:image/png;base64," + UtilsAdapter.getContactImageString(
accountId, convUid)
bestName = ClientWrapper.utilsAdaptor.getBestName(accountId, convUid)
bestName = UtilsAdapter.getBestName(accountId, convUid)
var id = ClientWrapper.utilsAdaptor.getBestId(accountId, convUid)
var id = UtilsAdapter.getBestId(accountId, convUid)
bestId = (bestName !== id) ? id : ""
}
......
/*
* Copyright (C) 2020 by Savoir-faire Linux
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
......@@ -18,12 +17,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import QtQuick.Controls.Universal 2.12
import QtQml 2.14
import net.jami.Models 1.0
import net.jami.Adapters 1.0
import "../js/contactpickercreation.js" as ContactPickerCreation
import "../js/mediahandlerpickercreation.js" as MediaHandlerPickerCreation
......
......@@ -149,7 +149,7 @@ Rectangle {
}
function onUpdateParticipantsInfos(infos, accountId, callId) {
var responsibleCallId = ClientWrapper.utilsAdaptor.getCallId(responsibleAccountId, responsibleConvUid)
var responsibleCallId = UtilsAdapter.getCallId(responsibleAccountId, responsibleConvUid)
if (responsibleCallId === callId) {
videoCallPage.handleParticipantsInfo(infos)
}
......
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