summaryrefslogtreecommitdiff
path: root/plugins/Toaster
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2015-08-29 19:42:01 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2015-08-29 19:42:01 +0000
commitefd0c6a4ad866396e45dc5ab6e4da6d18fceccd3 (patch)
tree226390b8e33e9e55d2766da3e46d5a822aa4a41d /plugins/Toaster
parent084110de8be5ea84ec86d643c9ca4c2ea5aa65dc (diff)
Toaster: converting avatars to png
git-svn-id: http://svn.miranda-ng.org/main/trunk@15102 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Toaster')
-rw-r--r--plugins/Toaster/src/avatars.cpp2
-rw-r--r--plugins/Toaster/src/avatars.h28
-rw-r--r--plugins/Toaster/src/main.cpp2
-rw-r--r--plugins/Toaster/src/services.cpp12
-rw-r--r--plugins/Toaster/src/stdafx.h4
5 files changed, 47 insertions, 1 deletions
diff --git a/plugins/Toaster/src/avatars.cpp b/plugins/Toaster/src/avatars.cpp
new file mode 100644
index 0000000000..716dda68f1
--- /dev/null
+++ b/plugins/Toaster/src/avatars.cpp
@@ -0,0 +1,2 @@
+#include "stdafx.h"
+
diff --git a/plugins/Toaster/src/avatars.h b/plugins/Toaster/src/avatars.h
new file mode 100644
index 0000000000..9321b6bfbf
--- /dev/null
+++ b/plugins/Toaster/src/avatars.h
@@ -0,0 +1,28 @@
+class ToasterAvatar
+{
+ ptrW wszPath;
+ int iFormat;
+ MCONTACT hContact;
+ FIBITMAP *bitmap;
+
+public:
+ ToasterAvatar(PROTO_AVATAR_INFORMATION *pai) : wszPath(pai->filename), iFormat(pai->format), hContact(pai->hContact)
+ {
+ bitmap = (FIBITMAP*)CallService(MS_IMG_LOAD, (WPARAM)wszPath, IMGL_WCHAR | IMGL_RETURNDIB);
+ }
+
+ ~ToasterAvatar()
+ {
+ CallService(MS_IMG_UNLOAD, (WPARAM)bitmap);
+ }
+
+ INT_PTR Save(const wchar_t *wszSavePath)
+ {
+ IMGSRVC_INFO isi = { sizeof(isi) };
+ isi.wszName = mir_wstrdup(wszSavePath);
+ isi.dib = bitmap;
+ isi.dwMask = IMGI_FBITMAP;
+ isi.fif = FREE_IMAGE_FORMAT::FIF_PNG;
+ return CallService(MS_IMG_SAVE, (WPARAM)&isi, IMGL_WCHAR);
+ }
+}; \ No newline at end of file
diff --git a/plugins/Toaster/src/main.cpp b/plugins/Toaster/src/main.cpp
index ccfedcefa1..eb8a9e50f1 100644
--- a/plugins/Toaster/src/main.cpp
+++ b/plugins/Toaster/src/main.cpp
@@ -3,6 +3,7 @@
int hLangpack;
HINSTANCE g_hInstance;
+HANDLE g_hTempAvatarsFolder;
PLUGININFOEX pluginInfo =
{
@@ -40,6 +41,7 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
extern "C" int __declspec(dllexport) Load(void)
{
mir_getLP(&pluginInfo);
+ g_hTempAvatarsFolder = FoldersRegisterCustomPathT(MODULE, Translate("Temp avatars"), VARSW(L"%miranda_userdata%\\Temp"));
HookEvent(ME_SYSTEM_PRESHUTDOWN, &OnPreShutdown);
InitServices();
diff --git a/plugins/Toaster/src/services.cpp b/plugins/Toaster/src/services.cpp
index 20a9303373..dab8258726 100644
--- a/plugins/Toaster/src/services.cpp
+++ b/plugins/Toaster/src/services.cpp
@@ -46,7 +46,17 @@ static void ShowToastNotification(TCHAR* text, TCHAR* title, MCONTACT hContact)
PROTO_AVATAR_INFORMATION pai = { 0 };
pai.hContact = hContact;
CallProtoService(szProto, PS_GETAVATARINFO, (WPARAM)0, (LPARAM)&pai);
- imagePath = mir_tstrdup(pai.filename);
+ if (pai.format != PA_FORMAT_PNG)
+ {
+ wchar_t dir[MAX_PATH];
+ FoldersGetCustomPathT(g_hTempAvatarsFolder, dir, _countof(dir), VARSW(L"%miranda_userdata%\\Temp"));
+ ToasterAvatar *ta = new ToasterAvatar(&pai);
+ CMStringW wszPath(FORMAT, L"%s\\%lld.%d.png", dir, hContact, db_get_dw(hContact, "ContactPhoto", "ImagePath"));
+ ta->Save(wszPath);
+ imagePath = wszPath.Detach();
+ delete ta;
+ }
+ imagePath = pai.filename[0] ? mir_tstrdup(pai.filename) : nullptr;
}
}
diff --git a/plugins/Toaster/src/stdafx.h b/plugins/Toaster/src/stdafx.h
index d198146e97..01c4b0e0d6 100644
--- a/plugins/Toaster/src/stdafx.h
+++ b/plugins/Toaster/src/stdafx.h
@@ -16,6 +16,8 @@
#include <m_popup.h>
#include <m_message.h>
#include <m_chat.h>
+#include <m_imgsrvc.h>
+#include <m_folders.h>
#include "version.h"
#include "resource.h"
@@ -30,10 +32,12 @@ DEFINE_PROPERTYKEY(PKEY_AppUserModel_ID, 0x9F4C2855, 0x9F79, 0x4B39, 0xA8, 0xD0,
#include "toast_event_handler.h"
#include "toast_notification.h"
#include "add_to_start_menu.h"
+#include "avatars.h"
extern HINSTANCE g_hInstance;
extern mir_cs csNotifications;
extern OBJLIST<ToastNotification> lstNotifications;
+extern HANDLE g_hTempAvatarsFolder;
struct callbackArg
{