diff --git a/linphone-desktop/assets/languages/en.ts b/linphone-desktop/assets/languages/en.ts
index 7e957001b..94941a1de 100644
--- a/linphone-desktop/assets/languages/en.ts
+++ b/linphone-desktop/assets/languages/en.ts
@@ -1110,6 +1110,14 @@ your friend's SIP address or username.
systemLocale
System locale
+
+ cleanAvatars
+ CLEAN AVATARS
+
+
+ cleanAvatarsDescription
+ Are you sure you want to clean all avatars?
+
SettingsVideo
diff --git a/linphone-desktop/assets/languages/fr.ts b/linphone-desktop/assets/languages/fr.ts
index 5049e8322..221098897 100644
--- a/linphone-desktop/assets/languages/fr.ts
+++ b/linphone-desktop/assets/languages/fr.ts
@@ -1109,6 +1109,14 @@ un chat ou ajouter un contact.
systemLocale
Locale du système
+
+ cleanAvatars
+ SUPPRIMER AVATARS
+
+
+ cleanAvatarsDescription
+ Voulez-vous vraiment supprimer tous les avatars ?
+
SettingsVideo
diff --git a/linphone-desktop/resources.qrc b/linphone-desktop/resources.qrc
index de09cb5a0..dad24434c 100644
--- a/linphone-desktop/resources.qrc
+++ b/linphone-desktop/resources.qrc
@@ -377,6 +377,7 @@
ui/views/App/Settings/SettingsSipAccountsEdit.qml
ui/views/App/Settings/SettingsSipAccounts.js
ui/views/App/Settings/SettingsSipAccounts.qml
+ ui/views/App/Settings/SettingsUi.js
ui/views/App/Settings/SettingsUi.qml
ui/views/App/Settings/SettingsVideo.js
ui/views/App/Settings/SettingsVideoPreview.qml
diff --git a/linphone-desktop/src/Utils.hpp b/linphone-desktop/src/Utils.hpp
index 4c3b9e20b..8f0f89fcd 100644
--- a/linphone-desktop/src/Utils.hpp
+++ b/linphone-desktop/src/Utils.hpp
@@ -52,10 +52,6 @@ namespace Utils {
return findParentType(parent);
}
- // Bring a window to front.
- // See: http://stackoverflow.com/questions/6087887/bring-window-to-front-raise-show-activatewindow-don-t-work
- void smartShowWindow (QQuickWindow *window);
-
// Reverse function of strstr.
char *rstrstr (const char *a, const char *b);
}
diff --git a/linphone-desktop/src/app/App.cpp b/linphone-desktop/src/app/App.cpp
index 7886188ae..bbea3aad9 100644
--- a/linphone-desktop/src/app/App.cpp
+++ b/linphone-desktop/src/app/App.cpp
@@ -303,7 +303,7 @@ void registerType (const char *name) {
}
void App::registerTypes () {
- qInfo() << "Registering types...";
+ qInfo() << QStringLiteral("Registering types...");
registerType("AssistantModel");
registerType("AuthenticationNotifier");
diff --git a/linphone-desktop/src/components/contact/VcardModel.cpp b/linphone-desktop/src/components/contact/VcardModel.cpp
index 741f2adb3..5b4992fb0 100644
--- a/linphone-desktop/src/components/contact/VcardModel.cpp
+++ b/linphone-desktop/src/components/contact/VcardModel.cpp
@@ -56,7 +56,8 @@ inline shared_ptr findBelCardValue (const list > &list, const Q
return nullptr;
}
-inline shared_ptr findBelCardPhoto (const list > &photos) {
+inline shared_ptr findBelcardPhoto (const shared_ptr &belcard) {
+ const list > &photos = belcard->getPhotos();
auto it = find_if(
photos.cbegin(), photos.cend(), [](const shared_ptr &photo) {
return !photo->getValue().compare(0, sizeof(VCARD_SCHEME) - 1, VCARD_SCHEME);
@@ -69,6 +70,21 @@ inline shared_ptr findBelCardPhoto (const list &belcard) {
+ shared_ptr oldPhoto = findBelcardPhoto(belcard);
+ if (oldPhoto) {
+ QString imagePath(
+ ::Utils::linphoneStringToQString(
+ Paths::getAvatarsDirPath() + oldPhoto->getValue().substr(sizeof(VCARD_SCHEME) - 1)
+ )
+ );
+
+ if (!QFile::remove(imagePath))
+ qWarning() << QStringLiteral("Unable to remove `%1`.").arg(imagePath);
+ belcard->removePhoto(oldPhoto);
+ }
+}
+
// -----------------------------------------------------------------------------
VcardModel::VcardModel (shared_ptr vcard) {
@@ -77,9 +93,11 @@ VcardModel::VcardModel (shared_ptr vcard) {
}
VcardModel::~VcardModel () {
- // If it's a detached Vcard, the linked photo must be destroyed from fs.
+ // If it's a detached Vcard and if necessary the linked photo must be destroyed from fs.
if (App::getInstance()->getEngine()->objectOwnership(this) != QQmlEngine::CppOwnership) {
- shared_ptr photo(findBelCardPhoto(mVcard->getVcard()->getPhotos()));
+ qInfo() << QStringLiteral("Destroy detached vcard:") << this;
+
+ shared_ptr photo(findBelcardPhoto(mVcard->getVcard()));
if (!photo)
return;
@@ -92,8 +110,6 @@ VcardModel::~VcardModel () {
if (!QFile::remove(imagePath))
qWarning() << QStringLiteral("Unable to remove `%1`.").arg(imagePath);
-
- qInfo() << QStringLiteral("Destroy detached vcard:") << this;
} else
qInfo() << QStringLiteral("Destroy attached vcard:") << this;
}
@@ -113,24 +129,9 @@ VcardModel *VcardModel::clone () const {
// -----------------------------------------------------------------------------
-QString VcardModel::getUsername () const {
- return ::Utils::linphoneStringToQString(mVcard->getFullName());
-}
-
-void VcardModel::setUsername (const QString &username) {
- if (username.length() == 0 || username == getUsername())
- return;
-
- mVcard->setFullName(::Utils::qStringToLinphoneString(username));
- emit vcardUpdated();
-}
-
-// -----------------------------------------------------------------------------
-
QString VcardModel::getAvatar () const {
// Find desktop avatar.
- list > photos = mVcard->getVcard()->getPhotos();
- shared_ptr photo = findBelCardPhoto(photos);
+ shared_ptr photo = findBelcardPhoto(mVcard->getVcard());
// No path found.
if (!photo)
@@ -143,6 +144,16 @@ QString VcardModel::getAvatar () const {
}
bool VcardModel::setAvatar (const QString &path) {
+ shared_ptr belcard = mVcard->getVcard();
+
+ // Remove avatar if path is empty.
+ if (path.isEmpty()) {
+ removeBelcardPhoto(belcard);
+ emit vcardUpdated();
+
+ return true;
+ }
+
// 1. Try to copy photo in avatars folder.
QFile file(path);
@@ -162,37 +173,37 @@ bool VcardModel::setAvatar (const QString &path) {
qInfo() << QStringLiteral("Update avatar of `%1`. (path=%2)").arg(getUsername()).arg(dest);
- // 2. Edit vcard.
- shared_ptr belcard = mVcard->getVcard();
- list > photos = belcard->getPhotos();
+ // 2. Remove oldest photo.
+ removeBelcardPhoto(belcard);
- // 3. Remove oldest photo.
- shared_ptr oldPhoto = findBelCardPhoto(photos);
- if (oldPhoto) {
- QString imagePath(
- ::Utils::linphoneStringToQString(
- Paths::getAvatarsDirPath() + oldPhoto->getValue().substr(sizeof(VCARD_SCHEME) - 1)
- )
- );
-
- if (!QFile::remove(imagePath))
- qWarning() << QStringLiteral("Unable to remove `%1`.").arg(imagePath);
- belcard->removePhoto(oldPhoto);
- }
-
- // 4. Update.
+ // 3. Update new photo.
shared_ptr photo = belcard::BelCardGeneric::create();
photo->setValue(VCARD_SCHEME + ::Utils::qStringToLinphoneString(fileId));
+ emit vcardUpdated();
+
if (!belcard->addPhoto(photo))
return false;
- emit vcardUpdated();
return true;
}
// -----------------------------------------------------------------------------
+QString VcardModel::getUsername () const {
+ return ::Utils::linphoneStringToQString(mVcard->getFullName());
+}
+
+void VcardModel::setUsername (const QString &username) {
+ if (username.length() == 0 || username == getUsername())
+ return;
+
+ mVcard->setFullName(::Utils::qStringToLinphoneString(username));
+ emit vcardUpdated();
+}
+
+// -----------------------------------------------------------------------------
+
inline shared_ptr getOrCreateBelCardAddress (shared_ptr belcard) {
list > addresses = belcard->getAddresses();
shared_ptr address;
diff --git a/linphone-desktop/src/components/contact/VcardModel.hpp b/linphone-desktop/src/components/contact/VcardModel.hpp
index 637e59c63..9d82a3b9d 100644
--- a/linphone-desktop/src/components/contact/VcardModel.hpp
+++ b/linphone-desktop/src/components/contact/VcardModel.hpp
@@ -41,13 +41,30 @@ class VcardModel : public QObject {
Q_PROPERTY(QVariantList emails READ getEmails NOTIFY vcardUpdated);
Q_PROPERTY(QVariantList urls READ getUrls NOTIFY vcardUpdated);
+ // ---------------------------------------------------------------------------
+
public:
VcardModel (std::shared_ptr vcard);
~VcardModel ();
+ // ---------------------------------------------------------------------------
+
+ QString getAvatar () const;
+ bool setAvatar (const QString &path);
+
QString getUsername () const;
+ void setUsername (const QString &username);
+
+ // ---------------------------------------------------------------------------
+
QVariantList getSipAddresses () const;
+ QVariantMap getAddress () const;
+ QVariantList getEmails () const;
+ QVariantList getCompanies () const;
+ QVariantList getUrls () const;
+
+ // ---------------------------------------------------------------------------
Q_INVOKABLE VcardModel *clone () const;
@@ -72,20 +89,14 @@ public:
Q_INVOKABLE void setPostalCode (const QString &postalCode);
Q_INVOKABLE void setCountry (const QString &country);
+ // ---------------------------------------------------------------------------
+
signals:
void vcardUpdated ();
+ // ---------------------------------------------------------------------------
+
private:
- void setUsername (const QString &username);
-
- QString getAvatar () const;
- bool setAvatar (const QString &path);
-
- QVariantMap getAddress () const;
- QVariantList getCompanies () const;
- QVariantList getEmails () const;
- QVariantList getUrls () const;
-
std::shared_ptr mVcard;
};
diff --git a/linphone-desktop/src/components/contacts/ContactsListModel.cpp b/linphone-desktop/src/components/contacts/ContactsListModel.cpp
index 17bc86a26..b328352a1 100644
--- a/linphone-desktop/src/components/contacts/ContactsListModel.cpp
+++ b/linphone-desktop/src/components/contacts/ContactsListModel.cpp
@@ -139,6 +139,18 @@ void ContactsListModel::removeContact (ContactModel *contact) {
// -----------------------------------------------------------------------------
+void ContactsListModel::cleanAvatars () {
+ qInfo() << QStringLiteral("Delete all avatars.");
+
+ for (const auto &contact : mList) {
+ contact->startEdit();
+ contact->getVcardModel()->setAvatar("");
+ contact->endEdit();
+ }
+}
+
+// -----------------------------------------------------------------------------
+
void ContactsListModel::addContact (ContactModel *contact) {
QObject::connect(
contact, &ContactModel::contactUpdated,
diff --git a/linphone-desktop/src/components/contacts/ContactsListModel.hpp b/linphone-desktop/src/components/contacts/ContactsListModel.hpp
index 3d502fd7f..ca30d9af4 100644
--- a/linphone-desktop/src/components/contacts/ContactsListModel.hpp
+++ b/linphone-desktop/src/components/contacts/ContactsListModel.hpp
@@ -50,6 +50,8 @@ public:
Q_INVOKABLE ContactModel *addContact (VcardModel *vcard);
Q_INVOKABLE void removeContact (ContactModel *contact);
+ Q_INVOKABLE void cleanAvatars ();
+
signals:
void contactAdded (ContactModel *contact);
void contactRemoved (const ContactModel *contact);
diff --git a/linphone-desktop/ui/views/App/Main/ContactEdit.js b/linphone-desktop/ui/views/App/Main/ContactEdit.js
index 248bc0f9c..82470bf6d 100644
--- a/linphone-desktop/ui/views/App/Main/ContactEdit.js
+++ b/linphone-desktop/ui/views/App/Main/ContactEdit.js
@@ -8,6 +8,19 @@
// =============================================================================
+function handleContactUpdated () {
+ var contact = contactEdit._contact
+
+ if (!contactEdit._edition) {
+ // Edition ended.
+ handleVcardChanged(contact.vcard)
+ } else {
+ // Edition not ended, the contact was updated in other place.
+ // Update fields with new data.
+ contactEdit._vcard = contact.vcard.clone()
+ }
+}
+
function handleCreation () {
var sipAddress = contactEdit.sipAddress
var contact = contactEdit._contact = Linphone.SipAddressesModel.mapSipAddressToContact(
@@ -74,6 +87,8 @@ function save () {
var contact = contactEdit._contact
var vcard = contactEdit._vcard
+ contactEdit._edition = false
+
if (contact) {
contact.vcard = vcard
contact.endEdit()
@@ -81,8 +96,6 @@ function save () {
} else {
contactEdit._contact = Linphone.ContactsListModel.addContact(vcard)
}
-
- contactEdit._edition = false
}
function cancel () {
@@ -121,7 +134,6 @@ function handleValueChanged (fields, index, oldValue, newValue, add, update) {
return
}
- console.log('handle', oldValue, newValue)
var vcard = contactEdit._vcard
var soFarSoGood = (oldValue.length === 0)
? vcard[add](newValue)
diff --git a/linphone-desktop/ui/views/App/Main/ContactEdit.qml b/linphone-desktop/ui/views/App/Main/ContactEdit.qml
index f549eb14f..23eef558b 100644
--- a/linphone-desktop/ui/views/App/Main/ContactEdit.qml
+++ b/linphone-desktop/ui/views/App/Main/ContactEdit.qml
@@ -39,7 +39,7 @@ ColumnLayout {
sourceComponent: Connections {
target: contactEdit._contact
- onContactUpdated: Logic.handleVcardChanged(contactEdit._contact.vcard)
+ onContactUpdated: Logic.handleContactUpdated()
}
}
diff --git a/linphone-desktop/ui/views/App/Settings/SettingsUi.js b/linphone-desktop/ui/views/App/Settings/SettingsUi.js
new file mode 100644
index 000000000..e7f5b09ee
--- /dev/null
+++ b/linphone-desktop/ui/views/App/Settings/SettingsUi.js
@@ -0,0 +1,19 @@
+// =============================================================================
+// `SettingsUi.qml` Logic.
+// =============================================================================
+
+.import Linphone 1.0 as Linphone
+
+.import 'qrc:/ui/scripts/Utils/utils.js' as Utils
+
+// =============================================================================
+
+function cleanAvatars () {
+ window.attachVirtualWindow(Utils.buildDialogUri('ConfirmDialog'), {
+ descriptionText: qsTr('cleanAvatarsDescription'),
+ }, function (status) {
+ if (status) {
+ Linphone.ContactsListModel.cleanAvatars()
+ }
+ })
+}
diff --git a/linphone-desktop/ui/views/App/Settings/SettingsUi.qml b/linphone-desktop/ui/views/App/Settings/SettingsUi.qml
index 6785cf699..b46064464 100644
--- a/linphone-desktop/ui/views/App/Settings/SettingsUi.qml
+++ b/linphone-desktop/ui/views/App/Settings/SettingsUi.qml
@@ -6,6 +6,8 @@ import Utils 1.0
import App.Styles 1.0
+import 'SettingsUi.js' as Logic
+
// =============================================================================
TabContainer {
@@ -106,6 +108,15 @@ TabContainer {
}
}
}
+
+ FormEmptyLine {}
+ }
+
+ TextButtonB {
+ anchors.right: parent.right
+ text: qsTr('cleanAvatars')
+
+ onClicked: Logic.cleanAvatars()
}
}
}