mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Don't save temp file for native notification userpics on Linux
This commit is contained in:
parent
4484edd212
commit
2bda3c4e2b
1 changed files with 30 additions and 44 deletions
|
@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "platform/linux/notifications_manager_linux.h"
|
||||
|
||||
#include "window/notifications_utilities.h"
|
||||
#include "base/options.h"
|
||||
#include "base/platform/base_platform_info.h"
|
||||
#include "base/platform/linux/base_linux_glibmm_helper.h"
|
||||
|
@ -20,10 +19,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_forum_topic.h"
|
||||
#include "history/history.h"
|
||||
#include "history/history_item.h"
|
||||
#include "ui/empty_userpic.h"
|
||||
#include "main/main_session.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "base/weak_ptr.h"
|
||||
#include "styles/style_window.h"
|
||||
|
||||
#include <QtCore/QBuffer>
|
||||
#include <QtCore/QVersionNumber>
|
||||
#include <QtGui/QGuiApplication>
|
||||
|
||||
|
@ -335,7 +337,7 @@ public:
|
|||
|
||||
void show();
|
||||
void close();
|
||||
void setImage(const QString &imagePath);
|
||||
void setImage(const QImage &image);
|
||||
|
||||
private:
|
||||
const not_null<Manager*> _manager;
|
||||
|
@ -685,24 +687,16 @@ void NotificationData::close() {
|
|||
_manager->clearNotification(_id);
|
||||
}
|
||||
|
||||
void NotificationData::setImage(const QString &imagePath) {
|
||||
if (imagePath.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
void NotificationData::setImage(const QImage &image) {
|
||||
if (_notification) {
|
||||
const auto imageData = [&] {
|
||||
QFile f(imagePath);
|
||||
if (f.open(QIODevice::ReadOnly)) {
|
||||
return f.readAll();
|
||||
}
|
||||
return QByteArray();
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
image.save(&buffer, "PNG");
|
||||
return ba;
|
||||
}();
|
||||
|
||||
if (imageData.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto imageBytes = Glib::Bytes::create(
|
||||
imageData.constData(),
|
||||
imageData.size());
|
||||
|
@ -717,27 +711,20 @@ void NotificationData::setImage(const QString &imagePath) {
|
|||
return;
|
||||
}
|
||||
|
||||
const auto image = [&] {
|
||||
const auto original = QImage(imagePath);
|
||||
return original.hasAlphaChannel()
|
||||
? original.convertToFormat(QImage::Format_RGBA8888)
|
||||
: original.convertToFormat(QImage::Format_RGB888);
|
||||
}();
|
||||
|
||||
if (image.isNull()) {
|
||||
return;
|
||||
}
|
||||
const auto convertedImage = image.hasAlphaChannel()
|
||||
? image.convertToFormat(QImage::Format_RGBA8888)
|
||||
: image.convertToFormat(QImage::Format_RGB888);
|
||||
|
||||
_hints[_imageKey] = MakeGlibVariant(std::tuple{
|
||||
image.width(),
|
||||
image.height(),
|
||||
int(image.bytesPerLine()),
|
||||
image.hasAlphaChannel(),
|
||||
convertedImage.width(),
|
||||
convertedImage.height(),
|
||||
int(convertedImage.bytesPerLine()),
|
||||
convertedImage.hasAlphaChannel(),
|
||||
8,
|
||||
image.hasAlphaChannel() ? 4 : 3,
|
||||
convertedImage.hasAlphaChannel() ? 4 : 3,
|
||||
std::vector<uchar>(
|
||||
image.constBits(),
|
||||
image.constBits() + image.sizeInBytes()),
|
||||
convertedImage.constBits(),
|
||||
convertedImage.constBits() + convertedImage.sizeInBytes()),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -910,8 +897,7 @@ void Create(Window::Notifications::System *system) {
|
|||
|
||||
class Manager::Private : public base::has_weak_ptr {
|
||||
public:
|
||||
using Type = Window::Notifications::CachedUserpics::Type;
|
||||
explicit Private(not_null<Manager*> manager, Type type);
|
||||
explicit Private(not_null<Manager*> manager);
|
||||
|
||||
void showNotification(
|
||||
not_null<PeerData*> peer,
|
||||
|
@ -942,17 +928,14 @@ private:
|
|||
ContextId,
|
||||
base::flat_map<MsgId, Notification>> _notifications;
|
||||
|
||||
Window::Notifications::CachedUserpics _cachedUserpics;
|
||||
|
||||
Glib::RefPtr<Gio::DBus::Connection> _dbusConnection;
|
||||
bool _inhibited = false;
|
||||
uint _inhibitedSignalId = 0;
|
||||
|
||||
};
|
||||
|
||||
Manager::Private::Private(not_null<Manager*> manager, Type type)
|
||||
: _manager(manager)
|
||||
, _cachedUserpics(type) {
|
||||
Manager::Private::Private(not_null<Manager*> manager)
|
||||
: _manager(manager) {
|
||||
const auto serverInformation = CurrentServerInformation;
|
||||
const auto capabilities = CurrentCapabilities;
|
||||
|
||||
|
@ -1054,9 +1037,12 @@ void Manager::Private::showNotification(
|
|||
}
|
||||
|
||||
if (!options.hideNameAndPhoto) {
|
||||
const auto userpicKey = peer->userpicUniqueKey(userpicView);
|
||||
notification->setImage(
|
||||
_cachedUserpics.get(userpicKey, peer, userpicView));
|
||||
const auto userpic = peer->isSelf()
|
||||
? Ui::EmptyUserpic::GenerateSavedMessages(st::notifyMacPhotoSize)
|
||||
: peer->isRepliesChat()
|
||||
? Ui::EmptyUserpic::GenerateRepliesMessages(st::notifyMacPhotoSize)
|
||||
: peer->genUserpic(userpicView, st::notifyMacPhotoSize);
|
||||
notification->setImage(userpic.toImage());
|
||||
}
|
||||
|
||||
auto i = _notifications.find(key);
|
||||
|
@ -1181,7 +1167,7 @@ Manager::Private::~Private() {
|
|||
|
||||
Manager::Manager(not_null<Window::Notifications::System*> system)
|
||||
: NativeManager(system)
|
||||
, _private(std::make_unique<Private>(this, Private::Type::Rounded)) {
|
||||
, _private(std::make_unique<Private>(this)) {
|
||||
}
|
||||
|
||||
void Manager::clearNotification(NotificationId id) {
|
||||
|
|
Loading…
Add table
Reference in a new issue