share friend

This commit is contained in:
Gaelle Braud 2024-07-08 18:38:42 +02:00
parent 7a21e17c55
commit 035b9af8a9
8 changed files with 94 additions and 49 deletions

View file

@ -194,6 +194,11 @@ QString Paths::getAvatarsDirPath() {
Constants::PathAvatars); Constants::PathAvatars);
} }
QString Paths::getVCardsPath() {
return getWritableDirPath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) +
Constants::PathVCards);
}
QString Paths::getCallHistoryFilePath() { QString Paths::getCallHistoryFilePath() {
return getWritableFilePath(getAppCallHistoryFilePath()); return getWritableFilePath(getAppCallHistoryFilePath());
} }

View file

@ -31,6 +31,7 @@ bool filePathExists(const QString &path, const bool isWritable = false);
QString getAppLocalDirPath(); QString getAppLocalDirPath();
QString getAssistantConfigDirPath(); QString getAssistantConfigDirPath();
QString getAvatarsDirPath(); QString getAvatarsDirPath();
QString getVCardsPath();
QString getCallHistoryFilePath(); QString getCallHistoryFilePath();
QString getCapturesDirPath(); QString getCapturesDirPath();
QString getCodecsDirPath(); QString getCodecsDirPath();

View file

@ -132,6 +132,7 @@ public:
static constexpr char PathData[] = "/" EXECUTABLE_NAME; static constexpr char PathData[] = "/" EXECUTABLE_NAME;
static constexpr char PathTools[] = "/tools/"; static constexpr char PathTools[] = "/tools/";
static constexpr char PathLogs[] = "/logs/"; static constexpr char PathLogs[] = "/logs/";
static constexpr char PathVCards[] = "/vcards/";
#ifdef APPLE #ifdef APPLE
static constexpr char PathPlugins[] = "/Plugins/"; static constexpr char PathPlugins[] = "/Plugins/";
#else #else

View file

@ -29,7 +29,9 @@
#include "model/object/VariantObject.hpp" #include "model/object/VariantObject.hpp"
#include "model/tool/ToolModel.hpp" #include "model/tool/ToolModel.hpp"
#include "tool/providers/AvatarProvider.hpp" #include "tool/providers/AvatarProvider.hpp"
#include <QClipboard> #include <QClipboard>
#include <QDesktopServices>
#include <QImageReader> #include <QImageReader>
#include <QQuickWindow> #include <QQuickWindow>
#include <QRandomGenerator> #include <QRandomGenerator>
@ -378,6 +380,29 @@ bool Utils::copyToClipboard(const QString &text) {
return !clipboardText.isEmpty(); 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() { QString Utils::getClipboardText() {
QClipboard *clipboard = QApplication::clipboard(); QClipboard *clipboard = QApplication::clipboard();
return clipboard->text(); return clipboard->text();

View file

@ -85,6 +85,11 @@ public:
Q_INVOKABLE static QStringList generateSecurityLettersArray(int arraySize, int correctIndex, QString correctCode); Q_INVOKABLE static QStringList generateSecurityLettersArray(int arraySize, int correctIndex, QString correctCode);
Q_INVOKABLE static int getRandomIndex(int size); Q_INVOKABLE static int getRandomIndex(int size);
Q_INVOKABLE static bool copyToClipboard(const QString &text); 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 getClipboardText();
Q_INVOKABLE static QString toDateString(QDateTime date, const QString &format = ""); Q_INVOKABLE static QString toDateString(QDateTime date, const QString &format = "");
Q_INVOKABLE static QString toDateString(QDate date, const QString &format = ""); Q_INVOKABLE static QString toDateString(QDate date, const QString &format = "");

View file

@ -205,52 +205,50 @@ ListView {
popup.contentItem: ColumnLayout { popup.contentItem: ColumnLayout {
Button { Button {
text: modelData.core.starred ? qsTr("Enlever des favoris") : qsTr("Mettre en favori")
background: Item{} background: Item{}
contentItem: RowLayout { icon.source: modelData.core.starred ? AppIcons.heartFill : AppIcons.heart
EffectImage { icon.width: 24 * DefaultStyle.dp
imageSource: modelData.core.starred ? AppIcons.heartFill : AppIcons.heart icon.height: 24 * DefaultStyle.dp
colorizationColor: modelData.core.starred ? DefaultStyle.danger_500main : DefaultStyle.main2_600 spacing: 10 * DefaultStyle.dp
fillMode: Image.PreserveAspectFit textSize: 14 * DefaultStyle.dp
width: 24 * DefaultStyle.dp textWeight: 400 * DefaultStyle.dp
height: 24 * DefaultStyle.dp textColor: DefaultStyle.main2_500main
Layout.preferredWidth: 24 * DefaultStyle.dp contentImageColor: modelData.core.starred ? DefaultStyle.danger_500main : DefaultStyle.main2_600
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
}
}
}
onClicked: { onClicked: {
modelData.core.lSetStarred(!modelData.core.starred) modelData.core.lSetStarred(!modelData.core.starred)
friendPopup.close() friendPopup.close()
} }
} }
Button { Button {
text: qsTr("Partager")
background: Item{} background: Item{}
contentItem: RowLayout { icon.source: AppIcons.shareNetwork
EffectImage { icon.width: 24 * DefaultStyle.dp
imageSource: AppIcons.trashCan icon.height: 24 * DefaultStyle.dp
width: 24 * DefaultStyle.dp spacing: 10 * DefaultStyle.dp
height: 24 * DefaultStyle.dp textSize: 14 * DefaultStyle.dp
Layout.preferredWidth: 24 * DefaultStyle.dp textWeight: 400 * DefaultStyle.dp
Layout.preferredHeight: 24 * DefaultStyle.dp textColor: DefaultStyle.main2_500main
fillMode: Image.PreserveAspectFit onClicked: {
colorizationColor: DefaultStyle.danger_500main var vcard = modelData.core.getVCard()
} var username = modelData.core.givenName + modelData.core.familyName
Text { var filepath = UtilsCpp.createVCardFile(username, vcard)
text: qsTr("Supprimer") if (filepath == "") UtilsCpp.showInformationPopup(qsTr("Erreur"), qsTr("La création du fichier vcard a échoué"))
color: DefaultStyle.danger_500main UtilsCpp.shareByEmail(qsTr("Partage de contact"), vcard, filepath)
font {
pixelSize: 14 * DefaultStyle.dp
weight: 400 * DefaultStyle.dp
}
}
} }
}
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: { onClicked: {
mainItem.contactDeletionRequested(modelData) mainItem.contactDeletionRequested(modelData)
friendPopup.close() friendPopup.close()
@ -267,6 +265,7 @@ ListView {
hoverEnabled: mainItem.hoverEnabled hoverEnabled: mainItem.hoverEnabled
anchors.fill: itemDelegate anchors.fill: itemDelegate
height: mainItem.height height: mainItem.height
acceptedButtons: Qt.AllButtons
z: -1 z: -1
Rectangle { Rectangle {
anchors.fill: contactArea anchors.fill: contactArea
@ -274,16 +273,20 @@ ListView {
color: DefaultStyle.main2_100 color: DefaultStyle.main2_100
visible: contactArea.containsMouse || friendPopup.hovered || (!mainItem.multiSelectionEnabled && mainItem.currentIndex === index) visible: contactArea.containsMouse || friendPopup.hovered || (!mainItem.multiSelectionEnabled && mainItem.currentIndex === index)
} }
onClicked: { onClicked: (mouse) => {
mainItem.currentIndex = -1 if (mouse.button == Qt.RightButton) {
mainItem.currentIndex = index friendPopup.open()
if (mainItem.multiSelectionEnabled) { } else {
var indexInSelection = mainItem.selectedContacts.indexOf(modelData.core.defaultAddress) mainItem.currentIndex = -1
if (indexInSelection == -1) { mainItem.currentIndex = index
mainItem.addContactToSelection(modelData.core.defaultAddress) if (mainItem.multiSelectionEnabled) {
} var indexInSelection = mainItem.selectedContacts.indexOf(modelData.core.defaultAddress)
else { if (indexInSelection == -1) {
mainItem.removeContactFromSelection(indexInSelection, 1) mainItem.addContactToSelection(modelData.core.defaultAddress)
}
else {
mainItem.removeContactFromSelection(indexInSelection, 1)
}
} }
} }
} }

View file

@ -22,6 +22,9 @@ Button {
function close() { function close() {
popup.close() popup.close()
} }
function open() {
popup.open()
}
background: Rectangle { background: Rectangle {
anchors.fill: mainItem anchors.fill: mainItem

View file

@ -712,8 +712,10 @@ AbstractMainPage {
onClicked: { onClicked: {
if (mainItem.selectedContact) { if (mainItem.selectedContact) {
var vcard = mainItem.selectedContact.core.getVCard() var vcard = mainItem.selectedContact.core.getVCard()
UtilsCpp.copyToClipboard(vcard) var username = mainItem.selectedContact.core.givenName + mainItem.selectedContact.core.familyName
UtilsCpp.showInformationPopup(qsTr("Copié"), qsTr("VCard copiée dans le presse-papier")) 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)
} }
} }
} }