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