Commit dc10ef59 authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Replace "Open in viewer" action with "Save to gallery" on photos

parent 3efad800
......@@ -10,11 +10,15 @@ DelegateAbstractMessageContent {
optimalWidth: img.width;
additionalContextMenuItems: ObjectModel {
MenuItem {
text: qsTr ("Open image in viewer");
text: qsTr ("Save image in gallery");
visible: (photoSizeItem !== null);
enabled: (photoSizeItem && photoSizeItem.photo && photoSizeItem.photo.local && photoSizeItem.photo.local.isDownloadingCompleted);
enabled: (photoSizeItem &&
photoSizeItem.photo &&
photoSizeItem.photo.local &&
photoSizeItem.photo.local.isDownloadingCompleted);
onClicked: {
Qt.openUrlExternally (TD_Global.urlFromLocalPath (photoSizeItem.photo.local.path));
TD_Global.savePhotoToGallery (photoSizeItem.photo);
emblem.visible = true;
}
}
}
......@@ -47,10 +51,18 @@ DelegateAbstractMessageContent {
visible: img.valid;
anchors.fill: parent;
onClicked: {
compoImgViewer.createObject (window, {
compoImgViewer.createObject (overlay, {
"source" : img.url,
});
}
}
}
LabelFixed {
id: emblem;
text: qsTr ("(Saved in gallery)");
opacity: 0.65;
visible: TD_Global.isPhotoSavedToGallery (photoSizeItem.photo);
font.pixelSize: Theme.fontSizeExtraSmall;
ExtraAnchors.horizontalFill: img;
}
}
......@@ -34,13 +34,16 @@ ApplicationWindow {
property TD_Sticker currentSticker : null;
property TD_StickerSet currentStickerSet : {
var ret = TD_Global.stickerSetsList.getFirst ();
if (TD_Global.stickerSetsList.count > 0 && Helpers.lastUsedStickersetName !== "") {
for (var idx = 0; idx < TD_Global.stickerSetsList.count; ++idx) {
var tmp = TD_Global.stickerSetsList.get (idx);
if (tmp ["name"] === Helpers.lastUsedStickersetName) {
ret = tmp;
break;
var ret = null;
if (TD_Global.stickerSetsList.count > 0) {
ret = TD_Global.stickerSetsList.getFirst ();
if (TD_Global.stickerSetsList.count > 0 && Helpers.lastUsedStickersetName !== "") {
for (var idx = 0; idx < TD_Global.stickerSetsList.count; ++idx) {
var tmp = TD_Global.stickerSetsList.get (idx);
if (tmp ["name"] === Helpers.lastUsedStickersetName) {
ret = tmp;
break;
}
}
}
}
......@@ -913,6 +916,10 @@ ApplicationWindow {
}
}
}
Item {
id: overlay;
anchors.fill: parent;
}
}
Component { id: compoPageCover; CoverPage { } }
Component { id: compoPageMain; PageMain { } }
......
#include "QtTdLibGlobal.h"
#include <QDir>
QtTdLibGlobal::QtTdLibGlobal (QObject * parent)
: QObject { parent }
, m_chatsList { new QQmlObjectListModel<QtTdLibChat> { this } }
......@@ -615,6 +617,25 @@ void QtTdLibGlobal::sendMessageEdit (QtTdLibChat * chatItem, const QString & tex
set_editingMessageId (QString { });
}
static const QString DIR_PHOTOS { QStringLiteral ("/home/nemo/Pictures/Telegrame") };
void QtTdLibGlobal::savePhotoToGallery (QtTdLibFile * fileItem) {
if (fileItem != Q_NULLPTR) {
QDir ().mkpath (DIR_PHOTOS);
QFileInfo info { fileItem->get_local ()->get_path () };
QFile::copy (info.absoluteFilePath (), (DIR_PHOTOS % '/' % info.fileName ()));
}
}
bool QtTdLibGlobal::isPhotoSavedToGallery (QtTdLibFile * fileItem) const {
bool ret { false };
if (fileItem != Q_NULLPTR) {
QFileInfo info { fileItem->get_local ()->get_path () };
ret = QFile::exists (DIR_PHOTOS % '/' % info.fileName ());
}
return ret;
}
void QtTdLibGlobal::sendMessagePhoto (QtTdLibChat * chatItem, const bool groupInAlbum, const QString & caption) {
if (chatItem != Q_NULLPTR && !m_selectedPhotosList.isEmpty ()) {
if (groupInAlbum) {
......
......@@ -129,6 +129,9 @@ public:
Q_INVOKABLE void sendMessageEdit (QtTdLibChat * chatItem, const QString & text);
Q_INVOKABLE void savePhotoToGallery (QtTdLibFile * fileItem);
Q_INVOKABLE bool isPhotoSavedToGallery (QtTdLibFile * fileItem) const;
signals:
void showChatRequested (QtTdLibChat * chatItem);
void editTextRequested (QtTdLibFormattedText * formattedText);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment