From 4061c75765c2aa1e96d79711baaa735996007cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sun, 24 Oct 2010 09:57:16 +0200 Subject: Scale avatars in freedesktop notifications. Resolves: #616 Release-Notes: Pictures in the message popups on Linux are now scaled down. diff --git a/Swift/QtUI/FreeDesktopNotifier.cpp b/Swift/QtUI/FreeDesktopNotifier.cpp index 6f680da..eacaa09 100644 --- a/Swift/QtUI/FreeDesktopNotifier.cpp +++ b/Swift/QtUI/FreeDesktopNotifier.cpp @@ -39,7 +39,7 @@ void FreeDesktopNotifier::showMessage(Type type, const String& subject, const St QMap hints; msg << P2QSTRING(applicationName); msg << quint32(0); // ID of previous notification to replace - msg << picture.string().c_str(); // Icon to display + msg << imageScaler.getScaledImage(picture, 48).string().c_str(); // Icon to display msg << P2QSTRING(subject); // Summary / Header of the message to display msg << P2QSTRING(description); // Body of the message to display msg << actions; // Actions from which the user may choose diff --git a/Swift/QtUI/FreeDesktopNotifier.h b/Swift/QtUI/FreeDesktopNotifier.h index 6583493..0bbf6bb 100644 --- a/Swift/QtUI/FreeDesktopNotifier.h +++ b/Swift/QtUI/FreeDesktopNotifier.h @@ -7,6 +7,7 @@ #pragma once #include "SwifTools/Notifier/Notifier.h" +#include "QtCachedImageScaler.h" namespace Swift { class FreeDesktopNotifier : public Notifier { @@ -17,5 +18,6 @@ namespace Swift { private: String applicationName; + QtCachedImageScaler imageScaler; }; } diff --git a/Swift/QtUI/QtCachedImageScaler.cpp b/Swift/QtUI/QtCachedImageScaler.cpp new file mode 100644 index 0000000..7307577 --- /dev/null +++ b/Swift/QtUI/QtCachedImageScaler.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "QtCachedImageScaler.h" + +#include +#include + +namespace Swift { + +QtCachedImageScaler::QtCachedImageScaler() { +} + +boost::filesystem::path QtCachedImageScaler::getScaledImage(const boost::filesystem::path& imagePath, int size) { + boost::filesystem::path scaledImagePath(imagePath.string() + "." + boost::lexical_cast(size)); + if (!boost::filesystem::exists(scaledImagePath)) { + QImage image(imagePath.string().c_str()); + if (!image.isNull()) { + if (image.width() > size || image.height() > size) { + QImage scaledImage = image.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation); + scaledImage.save(QString::fromUtf8(scaledImagePath.string().c_str()), "PNG"); + } + else { + image.save(QString::fromUtf8(scaledImagePath.string().c_str()), "PNG"); + } + } + else { + return imagePath; + } + } + return scaledImagePath; + +} + +} diff --git a/Swift/QtUI/QtCachedImageScaler.h b/Swift/QtUI/QtCachedImageScaler.h new file mode 100644 index 0000000..f85357f --- /dev/null +++ b/Swift/QtUI/QtCachedImageScaler.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include + +namespace Swift { + class QtCachedImageScaler { + public: + QtCachedImageScaler(); + + boost::filesystem::path getScaledImage(const boost::filesystem::path& image, int size); + }; +} + diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index 0bb0708..53c023a 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -77,6 +77,7 @@ sources = [ "QtChatTabs.cpp", "QtSoundPlayer.cpp", "QtSystemTray.cpp", + "QtCachedImageScaler.cpp", "QtTabbable.cpp", "QtTabWidget.cpp", "QtTextEdit.cpp", -- cgit v0.10.2-6-g49f6