Skip to content
Snippets Groups Projects
Commit f62a36ac authored by Ming Rui Zhang's avatar Ming Rui Zhang
Browse files

wizardview: make user avatar in profile page change accordingly

Gitlab: #161
Change-Id: I79d8f5e28f2025bd685ea760cd813eeca2e60c8b
parent d73422f6
No related branches found
No related tags found
No related merge requests found
...@@ -100,21 +100,28 @@ AccountAdapter::createJamiAccount(QString registeredName, ...@@ -100,21 +100,28 @@ AccountAdapter::createJamiAccount(QString registeredName,
&& !AppSettingsManager::getValue(Settings::Key::NeverShowMeAgain) && !AppSettingsManager::getValue(Settings::Key::NeverShowMeAgain)
.toBool(); .toBool();
if (!registeredName.isEmpty()) { if (!registeredName.isEmpty()) {
Utils::oneShotConnect(&LRCInstance::accountModel(), QObject::disconnect(registeredNameSavedConnection_);
&lrc::api::NewAccountModel::nameRegistrationEnded, registeredNameSavedConnection_ = connect(
[this, showBackup](const QString& accountId) { &LRCInstance::accountModel(),
emit LRCInstance::instance().accountListChanged(); &lrc::api::NewAccountModel::profileUpdated,
emit accountAdded(showBackup, [this, showBackup, addedAccountId = accountId](const QString& accountId) {
LRCInstance::accountModel() if (addedAccountId == accountId) {
.getAccountList() emit LRCInstance::instance().accountListChanged();
.indexOf(accountId)); emit accountAdded(accountId,
}); showBackup,
LRCInstance::accountModel().getAccountList().indexOf(
accountId));
QObject::disconnect(registeredNameSavedConnection_);
}
});
LRCInstance::accountModel().registerName(accountId, LRCInstance::accountModel().registerName(accountId,
settings["password"].toString(), settings["password"].toString(),
registeredName); registeredName);
} else { } else {
emit LRCInstance::instance().accountListChanged(); emit LRCInstance::instance().accountListChanged();
emit accountAdded(showBackup, emit accountAdded(accountId,
showBackup,
LRCInstance::accountModel().getAccountList().indexOf(accountId)); LRCInstance::accountModel().getAccountList().indexOf(accountId));
} }
...@@ -175,7 +182,8 @@ AccountAdapter::createSIPAccount(const QVariantMap& settings, QString photoBooth ...@@ -175,7 +182,8 @@ AccountAdapter::createSIPAccount(const QVariantMap& settings, QString photoBooth
} }
emit LRCInstance::instance().accountListChanged(); emit LRCInstance::instance().accountListChanged();
emit accountAdded(false, emit accountAdded(accountId,
false,
LRCInstance::accountModel().getAccountList().indexOf( LRCInstance::accountModel().getAccountList().indexOf(
accountId)); accountId));
}); });
...@@ -206,7 +214,8 @@ AccountAdapter::createJAMSAccount(const QVariantMap& settings) ...@@ -206,7 +214,8 @@ AccountAdapter::createJAMSAccount(const QVariantMap& settings)
Q_UNUSED(accountId) Q_UNUSED(accountId)
if (!LRCInstance::accountModel().getAccountList().size()) if (!LRCInstance::accountModel().getAccountList().size())
return; return;
emit accountAdded(false, emit accountAdded(accountId,
false,
LRCInstance::accountModel().getAccountList().indexOf( LRCInstance::accountModel().getAccountList().indexOf(
accountId)); accountId));
emit LRCInstance::instance().accountListChanged(); emit LRCInstance::instance().accountListChanged();
......
...@@ -112,7 +112,7 @@ signals: ...@@ -112,7 +112,7 @@ signals:
* send report failure to QML to make it show the right UI state . * send report failure to QML to make it show the right UI state .
*/ */
void reportFailure(); void reportFailure();
void accountAdded(bool showBackUp, int index); void accountAdded(QString accountId, bool showBackUp, int index);
void contactUnbanned(); void contactUnbanned();
private slots: private slots:
...@@ -145,5 +145,6 @@ private: ...@@ -145,5 +145,6 @@ private:
QMetaObject::Connection addedToConferenceConnection_; QMetaObject::Connection addedToConferenceConnection_;
QMetaObject::Connection accountProfileChangedConnection_; QMetaObject::Connection accountProfileChangedConnection_;
QMetaObject::Connection contactUnbannedConnection_; QMetaObject::Connection contactUnbannedConnection_;
QMetaObject::Connection registeredNameSavedConnection_;
}; };
Q_DECLARE_METATYPE(AccountAdapter*) Q_DECLARE_METATYPE(AccountAdapter*)
...@@ -49,7 +49,7 @@ public: ...@@ -49,7 +49,7 @@ public:
// Id content -> every after account_ // Id content -> every after account_
auto idContent = id.mid(id.indexOf(idType) + idType.length() + 1); auto idContent = id.mid(id.indexOf(idType) + idType.length() + 1);
if (idContent.isEmpty()) if (idContent.isEmpty() && idType != "default")
return QImage(); return QImage();
if (idType == "account") { if (idType == "account") {
...@@ -61,6 +61,10 @@ public: ...@@ -61,6 +61,10 @@ public:
return Utils::contactPhoto(conv.participants[0], requestedSize); return Utils::contactPhoto(conv.participants[0], requestedSize);
} else if (idType == "contact") { } else if (idType == "contact") {
return Utils::contactPhoto(idContent, requestedSize); return Utils::contactPhoto(idContent, requestedSize);
} else if (idType == "fallback") {
return Utils::fallbackAvatar(QString(), idContent, requestedSize);
} else if (idType == "default") {
return Utils::fallbackAvatar(QString(), QString(), requestedSize);
} else { } else {
auto image = Utils::cropImage(QImage(idContent)); auto image = Utils::cropImage(QImage(idContent));
return image.scaled(requestedSize, return image.scaled(requestedSize,
......
...@@ -31,6 +31,7 @@ Item { ...@@ -31,6 +31,7 @@ Item {
FromContactUri, FromContactUri,
FromConvUid, FromConvUid,
FromUrl, FromUrl,
FromTemporaryName,
Default Default
} }
...@@ -47,6 +48,10 @@ Item { ...@@ -47,6 +48,10 @@ Item {
return "contact_" return "contact_"
case AvatarImage.Mode.FromConvUid: case AvatarImage.Mode.FromConvUid:
return "conversation_" return "conversation_"
case AvatarImage.Mode.FromTemporaryName:
return "fallback_"
case AvatarImage.Mode.Default:
return "default_"
default: default:
return "" return ""
} }
...@@ -56,7 +61,6 @@ Item { ...@@ -56,7 +61,6 @@ Item {
property string imageProviderUrl: "image://avatarImage/" + forceUpdateUrl + "_" + property string imageProviderUrl: "image://avatarImage/" + forceUpdateUrl + "_" +
imageProviderIdPrefix imageProviderIdPrefix
property string imageId: "" property string imageId: ""
property string defaultImgUrl: "qrc:/images/default_avatar_overlay.svg"
property string forceUpdateUrl: Date.now() property string forceUpdateUrl: Date.now()
property alias presenceStatus: presenceIndicator.status property alias presenceStatus: presenceIndicator.status
property bool showPresenceIndicator: true property bool showPresenceIndicator: true
...@@ -73,15 +77,10 @@ Item { ...@@ -73,15 +77,10 @@ Item {
if (mode === AvatarImage.Mode.FromUrl) if (mode === AvatarImage.Mode.FromUrl)
rootImage.source = imageId rootImage.source = imageId
else if (imageId) else
rootImage.source = imageProviderUrl + imageId rootImage.source = imageProviderUrl + imageId
} }
onModeChanged: {
if (mode === AvatarImage.Mode.Default)
rootImage.source = defaultImgUrl
}
Image { Image {
id: rootImage id: rootImage
...@@ -89,6 +88,7 @@ Item { ...@@ -89,6 +88,7 @@ Item {
smooth: false smooth: false
antialiasing: true antialiasing: true
asynchronous: true
sourceSize.width: Math.max(24, width) sourceSize.width: Math.max(24, width)
sourceSize.height: Math.max(24, height) sourceSize.height: Math.max(24, height)
...@@ -115,6 +115,7 @@ Item { ...@@ -115,6 +115,7 @@ Item {
smooth: false smooth: false
antialiasing: true antialiasing: true
asynchronous: true
sourceSize.width: Math.max(24, width) sourceSize.width: Math.max(24, width)
sourceSize.height: Math.max(24, height) sourceSize.height: Math.max(24, height)
......
...@@ -8,8 +8,8 @@ import net.jami.Models 1.0 ...@@ -8,8 +8,8 @@ import net.jami.Models 1.0
import net.jami.Adapters 1.0 import net.jami.Adapters 1.0
ColumnLayout { ColumnLayout {
property bool takePhotoState: false property int photoState: PhotoboothView.PhotoState.Default
property bool hasAvatar: false property bool avatarSet: false
// saveToConfig is to specify whether the image should be saved to account config // saveToConfig is to specify whether the image should be saved to account config
property bool saveToConfig: false property bool saveToConfig: false
property string fileName: "" property string fileName: ""
...@@ -17,14 +17,25 @@ ColumnLayout { ...@@ -17,14 +17,25 @@ ColumnLayout {
property int boothWidth: 224 property int boothWidth: 224
enum PhotoState {
Default = 0,
CameraRendering,
Taken
}
readonly property int size: boothWidth + readonly property int size: boothWidth +
buttonsRowLayout.height + buttonsRowLayout.height +
JamiTheme.preferredMarginSize / 2 JamiTheme.preferredMarginSize / 2
function startBooth(force = false){ function initUI() {
hasAvatar = false photoState = PhotoboothView.PhotoState.Default
avatarSet = false
setAvatarImage(AvatarImage.Mode.Default, "")
}
function startBooth(force = false) {
AccountAdapter.startPreviewing(force) AccountAdapter.startPreviewing(force)
takePhotoState = true photoState = PhotoboothView.PhotoState.CameraRendering
} }
function stopBooth(){ function stopBooth(){
...@@ -33,17 +44,18 @@ ColumnLayout { ...@@ -33,17 +44,18 @@ ColumnLayout {
AccountAdapter.stopPreviewing() AccountAdapter.stopPreviewing()
} }
} catch(erro){console.log("Exception: " + erro.message)} } catch(erro){console.log("Exception: " + erro.message)}
takePhotoState = false
} }
function setAvatarImage(mode = AvatarImage.Mode.FromAccount, function setAvatarImage(mode = AvatarImage.Mode.FromAccount,
imageId = AccountAdapter.currentAccountId){ imageId = AccountAdapter.currentAccountId){
if (mode === AvatarImage.Mode.Default)
boothImg = ""
avatarImg.mode = mode avatarImg.mode = mode
if (mode === AvatarImage.Mode.Default) {
boothImg = ""
avatarImg.updateImage(imageId)
return
}
if (imageId) if (imageId)
avatarImg.updateImage(imageId) avatarImg.updateImage(imageId)
} }
...@@ -67,6 +79,9 @@ ColumnLayout { ...@@ -67,6 +79,9 @@ ColumnLayout {
"All files") + " (*)"] "All files") + " (*)"]
onAccepted: { onAccepted: {
avatarSet = true
photoState = PhotoboothView.PhotoState.Default
fileName = file fileName = file
if (fileName.length === 0) { if (fileName.length === 0) {
SettingsAdapter.clearCurrentAvatar() SettingsAdapter.clearCurrentAvatar()
...@@ -82,7 +97,7 @@ ColumnLayout { ...@@ -82,7 +97,7 @@ ColumnLayout {
Label { Label {
id: avatarLabel id: avatarLabel
visible: !takePhotoState visible: photoState !== PhotoboothView.PhotoState.CameraRendering
Layout.fillWidth: true Layout.fillWidth: true
Layout.maximumWidth: boothWidth Layout.maximumWidth: boothWidth
...@@ -101,8 +116,6 @@ ColumnLayout { ...@@ -101,8 +116,6 @@ ColumnLayout {
anchors.fill: parent anchors.fill: parent
imageId: AccountAdapter.currentAccountId
showPresenceIndicator: false showPresenceIndicator: false
fillMode: Image.PreserveAspectCrop fillMode: Image.PreserveAspectCrop
...@@ -139,7 +152,7 @@ ColumnLayout { ...@@ -139,7 +152,7 @@ ColumnLayout {
onHideBooth: stopBooth() onHideBooth: stopBooth()
visible: takePhotoState visible: photoState === PhotoboothView.PhotoState.CameraRendering
focus: visible focus: visible
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
...@@ -201,12 +214,12 @@ ColumnLayout { ...@@ -201,12 +214,12 @@ ColumnLayout {
radius: height / 6 radius: height / 6
source: { source: {
if(takePhotoState) { if(photoState === PhotoboothView.PhotoState.Default) {
toolTipText = qsTr("Take photo") toolTipText = qsTr("Take photo")
return cameraAltIconUrl return cameraAltIconUrl
} }
if(hasAvatar){ if(photoState === PhotoboothView.PhotoState.Taken){
toolTipText = qsTr("Retake photo") toolTipText = qsTr("Retake photo")
return refreshIconUrl return refreshIconUrl
} else { } else {
...@@ -216,7 +229,7 @@ ColumnLayout { ...@@ -216,7 +229,7 @@ ColumnLayout {
} }
onClicked: { onClicked: {
if(!takePhotoState){ if(photoState !== PhotoboothView.PhotoState.CameraRendering){
startBooth() startBooth()
return return
} else { } else {
...@@ -228,7 +241,8 @@ ColumnLayout { ...@@ -228,7 +241,8 @@ ColumnLayout {
setAvatarImage(AvatarImage.Mode.FromUrl, result.url) setAvatarImage(AvatarImage.Mode.FromUrl, result.url)
hasAvatar = true photoState = PhotoboothView.PhotoState.Taken
avatarSet = true
stopBooth() stopBooth()
}) })
} }
......
...@@ -80,16 +80,20 @@ Rectangle { ...@@ -80,16 +80,20 @@ Rectangle {
Connections{ Connections{
target: AccountAdapter target: AccountAdapter
function onAccountAdded(showBackUp, index) { enabled: controlPanelStackView.currentIndex !== WizardView.WizardViewPageIndex.WELCOMEPAGE
function onAccountAdded(accountId, showBackUp, index) {
addedAccountIndex = index addedAccountIndex = index
AccountAdapter.accountChanged(index) AccountAdapter.accountChanged(index)
if (showProfile) { if (showProfile) {
changePageQML(WizardView.WizardViewPageIndex.PROFILEPAGE) changePageQML(WizardView.WizardViewPageIndex.PROFILEPAGE)
profilePage.readyToSaveDetails() profilePage.readyToSaveDetails()
profilePage.isRdv = isRdv profilePage.isRdv = isRdv
profilePage.createdAccountId = accountId
} else if (controlPanelStackView.currentIndex === WizardView.WizardViewPageIndex.PROFILEPAGE) { } else if (controlPanelStackView.currentIndex === WizardView.WizardViewPageIndex.PROFILEPAGE) {
profilePage.readyToSaveDetails() profilePage.readyToSaveDetails()
profilePage.isRdv = isRdv profilePage.isRdv = isRdv
profilePage.createdAccountId = accountId
} else if (showBackUp) { } else if (showBackUp) {
changePageQML(WizardView.WizardViewPageIndex.BACKUPKEYSPAGE) changePageQML(WizardView.WizardViewPageIndex.BACKUPKEYSPAGE)
} else { } else {
...@@ -382,6 +386,8 @@ Rectangle { ...@@ -382,6 +386,8 @@ Rectangle {
changePageQML(WizardView.WizardViewPageIndex.WELCOMEPAGE) changePageQML(WizardView.WizardViewPageIndex.WELCOMEPAGE)
needToShowMainViewWindow(addedAccountIndex) needToShowMainViewWindow(addedAccountIndex)
} }
profilePage.initializeOnShowUp()
} }
onSaveProfile: { onSaveProfile: {
......
...@@ -26,12 +26,18 @@ import "../../commoncomponents" ...@@ -26,12 +26,18 @@ import "../../commoncomponents"
Rectangle { Rectangle {
id: root id: root
property string createdAccountId: ""
property alias profileImg: setAvatarWidget.boothImg property alias profileImg: setAvatarWidget.boothImg
property int preferredHeight: profilePageColumnLayout.implicitHeight property int preferredHeight: profilePageColumnLayout.implicitHeight
property var showBottom: false
property alias displayName: aliasEdit.text
property bool isRdv: false
signal leavePage
signal saveProfile
function initializeOnShowUp() { function initializeOnShowUp() {
setAvatarWidget.hasAvatar = false setAvatarWidget.initUI()
setAvatarWidget.setAvatarImage(AvatarImage.Mode.Default, "")
clearAllTextFields() clearAllTextFields()
saveProfileBtn.spinnerTriggered = true saveProfileBtn.spinnerTriggered = true
} }
...@@ -46,12 +52,10 @@ Rectangle { ...@@ -46,12 +52,10 @@ Rectangle {
color: JamiTheme.backgroundColor color: JamiTheme.backgroundColor
signal leavePage onCreatedAccountIdChanged: {
signal saveProfile setAvatarWidget.setAvatarImage(AvatarImage.Mode.FromAccount,
createdAccountId)
property var showBottom: false }
property alias displayName: aliasEdit.text
property bool isRdv: false
ColumnLayout { ColumnLayout {
id: profilePageColumnLayout id: profilePageColumnLayout
...@@ -102,6 +106,8 @@ Rectangle { ...@@ -102,6 +106,8 @@ Rectangle {
MaterialLineEdit { MaterialLineEdit {
id: aliasEdit id: aliasEdit
property string lastInitialCharacter: ""
Layout.preferredHeight: fieldLayoutHeight Layout.preferredHeight: fieldLayoutHeight
Layout.preferredWidth: fieldLayoutWidth Layout.preferredWidth: fieldLayoutWidth
Layout.alignment: Qt.AlignCenter Layout.alignment: Qt.AlignCenter
...@@ -114,6 +120,22 @@ Rectangle { ...@@ -114,6 +120,22 @@ Rectangle {
borderColorMode: MaterialLineEdit.NORMAL borderColorMode: MaterialLineEdit.NORMAL
fieldLayoutWidth: saveProfileBtn.width fieldLayoutWidth: saveProfileBtn.width
onTextEdited: {
if (!(setAvatarWidget.avatarSet)) {
if (text.length === 0) {
setAvatarWidget.setAvatarImage(AvatarImage.Mode.FromAccount,
createdAccountId)
return
}
if (text.length == 1 && text.charAt(0) !== lastInitialCharacter) {
lastInitialCharacter = text.charAt(0)
setAvatarWidget.setAvatarImage(AvatarImage.Mode.FromTemporaryName,
text)
}
}
}
} }
SpinnerButton { SpinnerButton {
......
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