diff --git a/src/accountadapter.h b/src/accountadapter.h index b911b7e6..7ffcbce7 100644 --- a/src/accountadapter.h +++ b/src/accountadapter.h @@ -87,7 +87,7 @@ public: Q_INVOKABLE bool isPreviewing(); Q_INVOKABLE void setCurrAccDisplayName(const QString& text); Q_INVOKABLE void setCurrentAccountAvatarFile(const QString& source); - Q_INVOKABLE void setCurrentAccountAvatarBase64(const QString& source); + Q_INVOKABLE void setCurrentAccountAvatarBase64(const QString& source = {}); Q_SIGNALS: // Trigger other components to reconnect account related signals. diff --git a/src/commoncomponents/Avatar.qml b/src/commoncomponents/Avatar.qml index 45e66fbb..fbfd99a3 100644 --- a/src/commoncomponents/Avatar.qml +++ b/src/commoncomponents/Avatar.qml @@ -22,6 +22,7 @@ import QtQuick.Controls 2.14 import net.jami.Adapters 1.0 import net.jami.Constants 1.0 +import net.jami.Helpers 1.0 import net.jami.Models 1.0 Item { diff --git a/src/commoncomponents/PhotoboothView.qml b/src/commoncomponents/PhotoboothView.qml index c8ca3c61..4269a924 100644 --- a/src/commoncomponents/PhotoboothView.qml +++ b/src/commoncomponents/PhotoboothView.qml @@ -35,6 +35,8 @@ ColumnLayout { property int size: 224 + signal avatarSet + function startBooth() { AccountAdapter.startPreviewing(false) mode = PhotoboothView.Mode.Previewing @@ -72,6 +74,7 @@ ColumnLayout { onAccepted: { var filePath = UtilsAdapter.getAbsPath(file) AccountAdapter.setCurrentAccountAvatarFile(filePath) + avatarSet() } } @@ -165,6 +168,7 @@ ColumnLayout { flashAnimation.start() AccountAdapter.setCurrentAccountAvatarBase64( preview.takePhoto(size)) + avatarSet() stopBooth() return } diff --git a/src/mainapplication.cpp b/src/mainapplication.cpp index 26d8200c..3fde8635 100644 --- a/src/mainapplication.cpp +++ b/src/mainapplication.cpp @@ -460,7 +460,7 @@ MainApplication::initQmlLayer() QML_REGISTERSINGLETONTYPE_POBJECT(NS_ADAPTERS, pluginAdapter, "PluginAdapter"); auto avatarRegistry = new AvatarRegistry(lrcInstance_.data(), this); - QML_REGISTERSINGLETONTYPE_POBJECT(NS_ADAPTERS, avatarRegistry, "AvatarRegistry"); + QML_REGISTERSINGLETONTYPE_POBJECT(NS_HELPERS, avatarRegistry, "AvatarRegistry"); // TODO: remove these QML_REGISTERSINGLETONTYPE_CUSTOM(NS_MODELS, AVModel, &lrcInstance_->avModel()) diff --git a/src/wizardview/components/ProfilePage.qml b/src/wizardview/components/ProfilePage.qml index e0dd93c1..13dd1b48 100644 --- a/src/wizardview/components/ProfilePage.qml +++ b/src/wizardview/components/ProfilePage.qml @@ -20,7 +20,9 @@ import QtQuick 2.14 import QtQuick.Layouts 1.14 import QtQuick.Controls 2.14 +import net.jami.Adapters 1.0 import net.jami.Constants 1.0 +import net.jami.Helpers 1.0 import "../../commoncomponents" @@ -34,6 +36,7 @@ Rectangle { property alias displayName: aliasEdit.text property bool isRdv: false property alias avatarBooth: setAvatarWidget + property bool avatarSet signal leavePage signal saveProfile @@ -42,6 +45,7 @@ Rectangle { createdAccountId = "dummy" clearAllTextFields() saveProfileBtn.spinnerTriggered = true + avatarSet = false } function clearAllTextFields() { @@ -99,6 +103,7 @@ Rectangle { Layout.fillHeight: true imageId: createdAccountId + onAvatarSet: root.avatarSet = true size: 200 } @@ -106,7 +111,7 @@ Rectangle { MaterialLineEdit { id: aliasEdit - property string lastInitialCharacter: "" + property string lastFirstChar Layout.preferredHeight: fieldLayoutHeight Layout.preferredWidth: fieldLayoutWidth @@ -122,18 +127,14 @@ Rectangle { fieldLayoutWidth: saveProfileBtn.width onTextEdited: { - if (!(setAvatarWidget.avatarSet)) { - if (text.length === 0) { - setAvatarWidget.setAvatarImage(AvatarImage.AvatarMode.FromAccount, - createdAccountId) - return - } - - if (text.length == 1 && text.charAt(0) !== lastInitialCharacter) { - lastInitialCharacter = text.charAt(0) - setAvatarWidget.setAvatarImage(AvatarImage.AvatarMode.FromTemporaryName, - text) - } + if (root.avatarSet) + return + if (text.length === 0) { + lastFirstChar = "" + AccountAdapter.setCurrAccDisplayName(lastFirstChar) + } else if (text.length == 1 && text.charAt(0) !== lastFirstChar) { + lastFirstChar = text.charAt(0) + AccountAdapter.setCurrAccDisplayName(lastFirstChar) } } } @@ -164,7 +165,9 @@ Rectangle { outlined: true onClicked: { - leavePage() + AccountAdapter.setCurrentAccountAvatarBase64() + aliasEdit.clear() + saveProfile() } }