diff --git a/Linphone/core/path/Paths.cpp b/Linphone/core/path/Paths.cpp index 670566ef9..75e24ed1e 100644 --- a/Linphone/core/path/Paths.cpp +++ b/Linphone/core/path/Paths.cpp @@ -194,6 +194,11 @@ QString Paths::getAvatarsDirPath() { Constants::PathAvatars); } +QString Paths::getVCardsPath() { + return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + + Constants::PathVCards); +} + QString Paths::getCallHistoryFilePath() { return getWritableFilePath(getAppCallHistoryFilePath()); } diff --git a/Linphone/core/path/Paths.hpp b/Linphone/core/path/Paths.hpp index 94d3b3abb..166a82e6d 100644 --- a/Linphone/core/path/Paths.hpp +++ b/Linphone/core/path/Paths.hpp @@ -31,6 +31,7 @@ bool filePathExists(const QString &path, const bool isWritable = false); QString getAppLocalDirPath(); QString getAssistantConfigDirPath(); QString getAvatarsDirPath(); +QString getVCardsPath(); QString getCallHistoryFilePath(); QString getCapturesDirPath(); QString getCodecsDirPath(); diff --git a/Linphone/tool/Constants.hpp b/Linphone/tool/Constants.hpp index 0db40fc30..4f92b8076 100644 --- a/Linphone/tool/Constants.hpp +++ b/Linphone/tool/Constants.hpp @@ -132,6 +132,7 @@ public: static constexpr char PathData[] = "/" EXECUTABLE_NAME; static constexpr char PathTools[] = "/tools/"; static constexpr char PathLogs[] = "/logs/"; + static constexpr char PathVCards[] = "/vcards/"; #ifdef APPLE static constexpr char PathPlugins[] = "/Plugins/"; #else diff --git a/Linphone/tool/Utils.cpp b/Linphone/tool/Utils.cpp index eea7c3dd9..bf22122e9 100644 --- a/Linphone/tool/Utils.cpp +++ b/Linphone/tool/Utils.cpp @@ -29,7 +29,9 @@ #include "model/object/VariantObject.hpp" #include "model/tool/ToolModel.hpp" #include "tool/providers/AvatarProvider.hpp" + #include +#include #include #include #include @@ -378,6 +380,29 @@ bool Utils::copyToClipboard(const QString &text) { return !clipboardText.isEmpty(); } +QString Utils::createVCardFile(const QString &username, const QString &vcardAsString) { + auto filepath = Paths::getVCardsPath() + username + ".vcf"; + QFile file(filepath); + if (file.open(QIODevice::ReadWrite)) { + QTextStream stream(&file); + stream << vcardAsString; + return filepath; + } + return QString(); +} + +void Utils::shareByEmail(const QString &subject, + const QString &body, + const QString &attachment, + const QString &receiver) { + QString url = QString("mailto:?to=%1&subject=%2&body=%3&attachment=%4") + .arg(receiver) + .arg(subject) + .arg(body) + .arg("/home/gaelle/ligneconsolevscode"); + QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode)); +} + QString Utils::getClipboardText() { QClipboard *clipboard = QApplication::clipboard(); return clipboard->text(); diff --git a/Linphone/tool/Utils.hpp b/Linphone/tool/Utils.hpp index 582d309ca..8bd3b1af2 100644 --- a/Linphone/tool/Utils.hpp +++ b/Linphone/tool/Utils.hpp @@ -85,6 +85,11 @@ public: Q_INVOKABLE static QStringList generateSecurityLettersArray(int arraySize, int correctIndex, QString correctCode); Q_INVOKABLE static int getRandomIndex(int size); Q_INVOKABLE static bool copyToClipboard(const QString &text); + Q_INVOKABLE static QString createVCardFile(const QString &username, const QString &vcardAsString); + Q_INVOKABLE static void shareByEmail(const QString &subject, + const QString &body = QString(), + const QString &attachment = QString(), + const QString &receiver = QString()); Q_INVOKABLE static QString getClipboardText(); Q_INVOKABLE static QString toDateString(QDateTime date, const QString &format = ""); Q_INVOKABLE static QString toDateString(QDate date, const QString &format = ""); diff --git a/Linphone/view/Item/Contact/ContactsList.qml b/Linphone/view/Item/Contact/ContactsList.qml index 3d79b7bcf..1d533a20b 100644 --- a/Linphone/view/Item/Contact/ContactsList.qml +++ b/Linphone/view/Item/Contact/ContactsList.qml @@ -205,52 +205,50 @@ ListView { popup.contentItem: ColumnLayout { Button { + text: modelData.core.starred ? qsTr("Enlever des favoris") : qsTr("Mettre en favori") background: Item{} - contentItem: RowLayout { - EffectImage { - imageSource: modelData.core.starred ? AppIcons.heartFill : AppIcons.heart - colorizationColor: modelData.core.starred ? DefaultStyle.danger_500main : DefaultStyle.main2_600 - fillMode: Image.PreserveAspectFit - width: 24 * DefaultStyle.dp - height: 24 * DefaultStyle.dp - Layout.preferredWidth: 24 * DefaultStyle.dp - Layout.preferredHeight: 24 * DefaultStyle.dp - } - Text { - text: modelData.core.starred ? qsTr("Enlever des favoris") : qsTr("Mettre en favori") - color: DefaultStyle.main2_500main - font { - pixelSize: 14 * DefaultStyle.dp - weight: 400 * DefaultStyle.dp - } - } - } + icon.source: modelData.core.starred ? AppIcons.heartFill : AppIcons.heart + icon.width: 24 * DefaultStyle.dp + icon.height: 24 * DefaultStyle.dp + spacing: 10 * DefaultStyle.dp + textSize: 14 * DefaultStyle.dp + textWeight: 400 * DefaultStyle.dp + textColor: DefaultStyle.main2_500main + contentImageColor: modelData.core.starred ? DefaultStyle.danger_500main : DefaultStyle.main2_600 onClicked: { modelData.core.lSetStarred(!modelData.core.starred) friendPopup.close() } } Button { + text: qsTr("Partager") background: Item{} - contentItem: RowLayout { - EffectImage { - imageSource: AppIcons.trashCan - width: 24 * DefaultStyle.dp - height: 24 * DefaultStyle.dp - Layout.preferredWidth: 24 * DefaultStyle.dp - Layout.preferredHeight: 24 * DefaultStyle.dp - fillMode: Image.PreserveAspectFit - colorizationColor: DefaultStyle.danger_500main - } - Text { - text: qsTr("Supprimer") - color: DefaultStyle.danger_500main - font { - pixelSize: 14 * DefaultStyle.dp - weight: 400 * DefaultStyle.dp - } - } + icon.source: AppIcons.shareNetwork + icon.width: 24 * DefaultStyle.dp + icon.height: 24 * DefaultStyle.dp + spacing: 10 * DefaultStyle.dp + textSize: 14 * DefaultStyle.dp + textWeight: 400 * DefaultStyle.dp + textColor: DefaultStyle.main2_500main + onClicked: { + var vcard = modelData.core.getVCard() + var username = modelData.core.givenName + modelData.core.familyName + var filepath = UtilsCpp.createVCardFile(username, vcard) + if (filepath == "") UtilsCpp.showInformationPopup(qsTr("Erreur"), qsTr("La création du fichier vcard a échoué")) + UtilsCpp.shareByEmail(qsTr("Partage de contact"), vcard, filepath) } + } + Button { + text: qsTr("Supprimer") + background: Item{} + icon.source: AppIcons.trashCan + icon.width: 24 * DefaultStyle.dp + icon.height: 24 * DefaultStyle.dp + spacing: 10 * DefaultStyle.dp + textSize: 14 * DefaultStyle.dp + textWeight: 400 * DefaultStyle.dp + textColor: DefaultStyle.danger_500main + contentImageColor: DefaultStyle.danger_500main onClicked: { mainItem.contactDeletionRequested(modelData) friendPopup.close() @@ -267,6 +265,7 @@ ListView { hoverEnabled: mainItem.hoverEnabled anchors.fill: itemDelegate height: mainItem.height + acceptedButtons: Qt.AllButtons z: -1 Rectangle { anchors.fill: contactArea @@ -274,16 +273,20 @@ ListView { color: DefaultStyle.main2_100 visible: contactArea.containsMouse || friendPopup.hovered || (!mainItem.multiSelectionEnabled && mainItem.currentIndex === index) } - onClicked: { - mainItem.currentIndex = -1 - mainItem.currentIndex = index - if (mainItem.multiSelectionEnabled) { - var indexInSelection = mainItem.selectedContacts.indexOf(modelData.core.defaultAddress) - if (indexInSelection == -1) { - mainItem.addContactToSelection(modelData.core.defaultAddress) - } - else { - mainItem.removeContactFromSelection(indexInSelection, 1) + onClicked: (mouse) => { + if (mouse.button == Qt.RightButton) { + friendPopup.open() + } else { + mainItem.currentIndex = -1 + mainItem.currentIndex = index + if (mainItem.multiSelectionEnabled) { + var indexInSelection = mainItem.selectedContacts.indexOf(modelData.core.defaultAddress) + if (indexInSelection == -1) { + mainItem.addContactToSelection(modelData.core.defaultAddress) + } + else { + mainItem.removeContactFromSelection(indexInSelection, 1) + } } } } diff --git a/Linphone/view/Item/PopupButton.qml b/Linphone/view/Item/PopupButton.qml index 49d72bcd4..95dd01256 100644 --- a/Linphone/view/Item/PopupButton.qml +++ b/Linphone/view/Item/PopupButton.qml @@ -22,6 +22,9 @@ Button { function close() { popup.close() } + function open() { + popup.open() + } background: Rectangle { anchors.fill: mainItem diff --git a/Linphone/view/Page/Main/ContactPage.qml b/Linphone/view/Page/Main/ContactPage.qml index f1cd58e76..891f1b64e 100644 --- a/Linphone/view/Page/Main/ContactPage.qml +++ b/Linphone/view/Page/Main/ContactPage.qml @@ -712,8 +712,10 @@ AbstractMainPage { onClicked: { if (mainItem.selectedContact) { var vcard = mainItem.selectedContact.core.getVCard() - UtilsCpp.copyToClipboard(vcard) - UtilsCpp.showInformationPopup(qsTr("Copié"), qsTr("VCard copiée dans le presse-papier")) + var username = mainItem.selectedContact.core.givenName + mainItem.selectedContact.core.familyName + var filepath = UtilsCpp.createVCardFile(username, vcard) + if (filepath == "") UtilsCpp.showInformationPopup(qsTr("Erreur"), qsTr("La création du fichier vcard a échoué")) + UtilsCpp.shareByEmail(qsTr("Partage de contact"), vcard, filepath) } } }