From e5fcb23f1da0228d227e4397f622fdb38d22bfa3 Mon Sep 17 00:00:00 2001 From: "wishmaster51@gmail.com" Date: Sat, 21 Apr 2012 10:05:59 +0000 Subject: -fixed notifications of duplicate avatars (thanks to xaos for testing and reporting it) git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@246 c086bb3d-8645-0410-b8da-73a8550f86e7 --- Plugins/avatarhistory/AvatarDlg.cpp | 58 ++++---------------- Plugins/avatarhistory/AvatarHistory.cpp | 62 ++++++++-------------- Plugins/avatarhistory/AvatarHistory.h | 9 +++- Plugins/avatarhistory/AvatarHistory.vcxproj | 13 +++-- .../avatarhistory/Docs/avatarhist_changelog.txt | 1 + Plugins/avatarhistory/icolib.cpp | 3 -- Plugins/avatarhistory/options.cpp | 3 +- Plugins/avatarhistory/popup.cpp | 4 +- Plugins/avatarhistory/popup.h | 2 +- Plugins/avatarhistory/sdk/m_folders.h | 30 +++++------ 10 files changed, 69 insertions(+), 116 deletions(-) diff --git a/Plugins/avatarhistory/AvatarDlg.cpp b/Plugins/avatarhistory/AvatarDlg.cpp index 58e6ab1..14bbebc 100644 --- a/Plugins/avatarhistory/AvatarDlg.cpp +++ b/Plugins/avatarhistory/AvatarDlg.cpp @@ -20,14 +20,11 @@ Avatar History Plugin #include "AvatarHistory.h" -#include -#include - extern HINSTANCE hInst; HANDLE hMenu = NULL; DWORD WINAPI AvatarDialogThread(LPVOID param); static INT_PTR CALLBACK AvatarDlgProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam); -int ShowSaveDialog(HWND hwnd, TCHAR* fn); +int ShowSaveDialog(HWND hwnd, TCHAR* fn,HANDLE hContact = NULL); BOOL ProtocolEnabled(const char *proto); int FillAvatarListFromDB(HWND list, HANDLE hContact); @@ -543,8 +540,6 @@ int PreBuildContactMenu(WPARAM wParam,LPARAM lParam) void InitMenuItem() { - hHooks[5] = HookEvent(ME_CLIST_PREBUILDCONTACTMENU, PreBuildContactMenu); - CLISTMENUITEM mi = {0}; hServices[2] = CreateServiceFunction(MS_AVATARHISTORY_SHOWDIALOG, ShowDialogSvc); @@ -574,14 +569,14 @@ TCHAR* GetCurrentSelFile(HWND list) return NULL; } -int ShowSaveDialog(HWND hwnd, TCHAR* fn) +int ShowSaveDialog(HWND hwnd, TCHAR* fn, HANDLE hContact) { - TCHAR initdir[MAX_PATH] = _T("."); TCHAR filter[MAX_PATH]; TCHAR file[MAX_PATH]; OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(OPENFILENAME)); - MyDBGetStringT(NULL, "AvatarHistory", "SavedAvatarFolder", initdir, MAX_PATH); + DBVARIANT dbvInitDir = {0}; + bool ret = (DBGetContactSettingTString(hContact,MODULE_NAME,"SavedAvatarFolder",&dbvInitDir)== 0); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hwnd; ofn.hInstance = hInst; @@ -596,47 +591,16 @@ int ShowSaveDialog(HWND hwnd, TCHAR* fn) ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_PATHMUSTEXIST; ofn.lpstrDefExt = _tcsrchr(fn, '.')+1; - ofn.lpstrInitialDir = initdir[0]?initdir:NULL; - if(GetSaveFileName(&ofn)) - CopyFile(fn, file, FALSE); - return 0; -} - -TCHAR* MyDBGetStringT(HANDLE hContact, char* module, char* setting, TCHAR* out, size_t len) -{ - DBCONTACTGETSETTING dbgcs; - DBVARIANT dbv; - dbgcs.szModule = module; - dbgcs.szSetting = setting; - dbgcs.pValue = &dbv; - dbv.type = DBVT_TCHAR; - - dbv.ptszVal = out; - dbv.cchVal = (int) len; - if (CallService(MS_DB_CONTACT_GETSETTINGSTATIC, (WPARAM)hContact, (LPARAM)&dbgcs) != 0) - return NULL; - else - return out; -} - -char * MyDBGetString(HANDLE hContact, char* module, char* setting, char * out, size_t len) -{ - DBCONTACTGETSETTING dbgcs; - DBVARIANT dbv; - dbgcs.szModule = module; - dbgcs.szSetting = setting; - dbgcs.pValue = &dbv; - dbv.type = DBVT_ASCIIZ; - dbv.pszVal = out; - dbv.cchVal = (int) len; - if (CallService(MS_DB_CONTACT_GETSETTINGSTATIC, (WPARAM)hContact, (LPARAM)&dbgcs) != 0) + if(ret) { - out[len-1] = '\0'; - return NULL; + ofn.lpstrInitialDir = dbvInitDir.ptszVal; + DBFreeVariant(&dbvInitDir); } else { - out[len-1] = '\0'; - return out; + ofn.lpstrInitialDir = _T("."); } + if(GetSaveFileName(&ofn)) + CopyFile(fn, file, FALSE); + return 0; } diff --git a/Plugins/avatarhistory/AvatarHistory.cpp b/Plugins/avatarhistory/AvatarHistory.cpp index a1be638..13781ed 100644 --- a/Plugins/avatarhistory/AvatarHistory.cpp +++ b/Plugins/avatarhistory/AvatarHistory.cpp @@ -23,8 +23,6 @@ Avatar History Plugin */ #include "AvatarHistory.h" -// #define DBGPOPUPS - HINSTANCE hInst; PLUGINLINK *pluginLink; DWORD mirVer; @@ -221,8 +219,9 @@ extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) hHooks[0] = HookEvent(ME_SYSTEM_MODULESLOADED,ModulesLoaded); hHooks[1] = HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown); - hHooks[2] = HookEvent(ME_AV_CONTACTAVATARCHANGED, AvatarChanged); hHooks[3] = HookEvent(ME_OPT_INITIALISE, OptInit); + hHooks[4] = HookEvent(ME_SKIN2_ICONSCHANGED, IcoLibIconsChanged); + hHooks[5] = HookEvent(ME_CLIST_PREBUILDCONTACTMENU, PreBuildContactMenu); hServices[0] = CreateServiceFunction(MS_AVATARHISTORY_ENABLED, IsEnabled); hServices[1] = CreateServiceFunction(MS_AVATARHISTORY_GET_CACHED_AVATAR, GetCachedAvatar); @@ -292,6 +291,8 @@ static int ModulesLoaded(WPARAM wParam, LPARAM lParam) GetHistoryEventText, templates, MAX_REGS(templates)); DestroyIcon(hIcon); } + + hHooks[2] = HookEvent(ME_AV_CONTACTAVATARCHANGED, AvatarChanged); return 0; } @@ -489,52 +490,39 @@ static int AvatarChanged(WPARAM wParam, LPARAM lParam) return 0; } - BOOL removed = (avatar == NULL && DBGetContactSettingWord(hContact, "ContactPhoto", "Format", 0) == 0); - - TCHAR oldhash[1024] = _T(""); - TCHAR * ret = MyDBGetStringT(hContact, MODULE_NAME, "AvatarHash", oldhash, sizeof(oldhash)); - - BOOL first_time = (ret == NULL); - - if( - (avatar != NULL && !_tcscmp(oldhash, avatar->hash)) // Changed it - || (avatar == NULL && oldhash[0] == '\0') // Removed it - ) - { - ShowDebugPopup(hContact, _T("AVH Debug"), _T("Hashes are the same... skipping")); - return 0; - } - - if (removed) - { - SkinPlaySound("avatar_removed"); - DBWriteContactSettingTString(hContact, MODULE_NAME, "AvatarHash", _T("")); - - if (!first_time && ContactEnabled(hContact, "AvatarPopups", AVH_DEF_AVPOPUPS) && opts.popup_show_removed) - ShowPopup(hContact, NULL, opts.popup_removed); + DBVARIANT dbvOldHash = {0}; + bool ret = (DBGetContactSettingTString(hContact,MODULE_NAME,"AvatarHash",&dbvOldHash) == 0); - if (ContactEnabled(hContact, "LogToHistory", AVH_DEF_LOGTOHISTORY)) - HistoryEvents_AddToHistorySimple(hContact, EVENTTYPE_AVATAR_CHANGE, 1, DBEF_READ); - } - else if (avatar == NULL) + if (avatar == NULL) { - if (!_tcscmp(oldhash, _T("-"))) + if (!ret || !_tcscmp(dbvOldHash.ptszVal, _T("-"))) { - ShowDebugPopup(hContact, _T("AVH Debug"), _T("Changed from a flash avatar to a flash avatar... skipping")); + //avoid duplicate "removed avatar" notifications + //do not notify on an empty profile + ShowDebugPopup(hContact, _T("AVH Debug"), _T("Removed avatar, no avatar before...skipping")); + DBFreeVariant(&dbvOldHash); return 0; } + SkinPlaySound("avatar_removed"); // Is a flash avatar or avs could not load it DBWriteContactSettingTString(hContact, MODULE_NAME, "AvatarHash", _T("-")); - if (!first_time && ContactEnabled(hContact, "AvatarPopups", AVH_DEF_AVPOPUPS) && opts.popup_show_changed) + if (ContactEnabled(hContact, "AvatarPopups", AVH_DEF_AVPOPUPS) && opts.popup_show_changed) ShowPopup(hContact, NULL, opts.popup_changed); if (ContactEnabled(hContact, "LogToHistory", AVH_DEF_LOGTOHISTORY)) - HistoryEvents_AddToHistorySimple(hContact, EVENTTYPE_AVATAR_CHANGE, 0, DBEF_READ); + HistoryEvents_AddToHistorySimple(hContact, EVENTTYPE_AVATAR_CHANGE, 1, DBEF_READ); } else { + if(ret && !_tcscmp(dbvOldHash.ptszVal, avatar->hash)) + { + // same avatar hash, skipping + ShowDebugPopup(hContact, _T("AVH Debug"), _T("Hashes are the same... skipping")); + DBFreeVariant(&dbvOldHash); + return 0; + } SkinPlaySound("avatar_changed"); DBWriteContactSettingTString(hContact, "AvatarHistory", "AvatarHash", avatar->hash); @@ -615,7 +603,7 @@ static int AvatarChanged(WPARAM wParam, LPARAM lParam) } - if (!first_time && ContactEnabled(hContact, "AvatarPopups", AVH_DEF_AVPOPUPS) && opts.popup_show_changed) + if (ContactEnabled(hContact, "AvatarPopups", AVH_DEF_AVPOPUPS) && opts.popup_show_changed) ShowPopup(hContact, NULL, opts.popup_changed); if (ContactEnabled(hContact, "LogToHistory", AVH_DEF_LOGTOHISTORY)) @@ -806,10 +794,6 @@ TCHAR * GetOldStyleAvatarName(TCHAR *fn, HANDLE hContact) return fn; } - -#include -#include - BOOL CreateShortcut(TCHAR *file, TCHAR *shortcut) { CoInitialize(NULL); diff --git a/Plugins/avatarhistory/AvatarHistory.h b/Plugins/avatarhistory/AvatarHistory.h index 0973030..b81e24a 100644 --- a/Plugins/avatarhistory/AvatarHistory.h +++ b/Plugins/avatarhistory/AvatarHistory.h @@ -3,6 +3,10 @@ #include #include #include +#include //for ImageList_* +#include +#include +#include #define MIRANDA_VER 0x0A00 @@ -53,7 +57,6 @@ extern HANDLE hAvatarWindowsList; #define DEFAULT_TEMPLATE_REMOVED LPGENT("removed his/her avatar") #define DEFAULT_TEMPLATE_CHANGED LPGENT("changed his/her avatar") -TCHAR * MyDBGetStringT(HANDLE hContact, char* module, char* setting, TCHAR* out, size_t len); void LoadOptions(); // from icolib.cpp @@ -62,6 +65,10 @@ void SetupIcoLib(); HICON createDefaultOverlayedIcon(BOOL big); HICON createProtoOverlayedIcon(HANDLE hContact); +int PreBuildContactMenu(WPARAM wParam,LPARAM lParam); +int IcoLibIconsChanged(WPARAM wParam,LPARAM lParam); + +int OpenAvatarDialog(HANDLE hContact, char* fn); #define MAX_REGS(_A_) ( sizeof(_A_) / sizeof(_A_[0]) ) diff --git a/Plugins/avatarhistory/AvatarHistory.vcxproj b/Plugins/avatarhistory/AvatarHistory.vcxproj index 9656a21..b487096 100644 --- a/Plugins/avatarhistory/AvatarHistory.vcxproj +++ b/Plugins/avatarhistory/AvatarHistory.vcxproj @@ -158,7 +158,7 @@ true EditAndContinue ../../include;sdk;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;AvatarHistory_EXPORTS;%(PreprocessorDefinitions) + DBGPOPUPS;WIN32;_DEBUG;_WINDOWS;_USRDLL;AvatarHistory_EXPORTS;%(PreprocessorDefinitions) true EnableFastChecks @@ -196,7 +196,7 @@ Level3 ProgramDatabase ../../include;sdk;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;AvatarHistory_EXPORTS;%(PreprocessorDefinitions) + DBGPOPUPS;WIN64;_DEBUG;_WINDOWS;_USRDLL;AvatarHistory_EXPORTS;%(PreprocessorDefinitions) true EnableFastChecks @@ -234,7 +234,7 @@ true EditAndContinue ../../include;sdk;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;UNICODE;_USRDLL;AvatarHistory_EXPORTS;%(PreprocessorDefinitions) + DBGPOPUPS;WIN32;_DEBUG;_WINDOWS;_UNICODE;UNICODE;_USRDLL;AvatarHistory_EXPORTS;%(PreprocessorDefinitions) true EnableFastChecks @@ -258,7 +258,6 @@ true true Console - .\Unicode_Debug\avatarhistW.lib comctl32.lib;%(AdditionalDependencies) @@ -272,7 +271,7 @@ Level3 ProgramDatabase ../../include;sdk;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;UNICODE;_USRDLL;AvatarHistory_EXPORTS;%(PreprocessorDefinitions) + DBGPOPUPS;WIN64;_DEBUG;_WINDOWS;_UNICODE;UNICODE;_USRDLL;AvatarHistory_EXPORTS;%(PreprocessorDefinitions) true EnableFastChecks @@ -381,7 +380,7 @@ true Level3 ../../include;sdk;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;UNICODE;_USRDLL;AvatarHistory_EXPORTS;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;_UNICODE;UNICODE;_USRDLL;AvatarHistory_EXPORTS;%(PreprocessorDefinitions) true @@ -418,7 +417,7 @@ true Level3 ../../include;sdk;%(AdditionalIncludeDirectories) - WIN64;NDEBUG;_WINDOWS;UNICODE;_USRDLL;AvatarHistory_EXPORTS;%(PreprocessorDefinitions) + WIN64;NDEBUG;_WINDOWS;_UNICODE;UNICODE;_USRDLL;AvatarHistory_EXPORTS;%(PreprocessorDefinitions) true diff --git a/Plugins/avatarhistory/Docs/avatarhist_changelog.txt b/Plugins/avatarhistory/Docs/avatarhist_changelog.txt index b8a8918..57dfa8b 100644 --- a/Plugins/avatarhistory/Docs/avatarhist_changelog.txt +++ b/Plugins/avatarhistory/Docs/avatarhist_changelog.txt @@ -7,6 +7,7 @@ Changelog: + support for WindowList * fixed some issues reported by borkra + updated m_folders.h +* fixed duplicate avatar notifications . 0.0.3.0 THIS REQUIRES MIRANDA IM 0.10 ALPHA #3 OR ABOVE!! diff --git a/Plugins/avatarhistory/icolib.cpp b/Plugins/avatarhistory/icolib.cpp index c2de441..b8e54b0 100644 --- a/Plugins/avatarhistory/icolib.cpp +++ b/Plugins/avatarhistory/icolib.cpp @@ -1,5 +1,4 @@ #include "AvatarHistory.h" -#include //for ImageList_* enum IconIndex { @@ -64,8 +63,6 @@ int IcoLibIconsChanged(WPARAM wParam, LPARAM lParam) void SetupIcoLib() { - hHooks[4] = HookEvent(ME_SKIN2_ICONSCHANGED, IcoLibIconsChanged); - if (hHooks[4]) { SKINICONDESC sid = {0}; diff --git a/Plugins/avatarhistory/options.cpp b/Plugins/avatarhistory/options.cpp index f05e2e1..1c7e07b 100644 --- a/Plugins/avatarhistory/options.cpp +++ b/Plugins/avatarhistory/options.cpp @@ -222,7 +222,8 @@ static INT_PTR CALLBACK PopupsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA op.popup_use_win_colors = IsDlgButtonChecked(hwndDlg, IDC_WINCOLORS) != 0; op.popup_use_default_colors = IsDlgButtonChecked(hwndDlg, IDC_DEFAULTCOLORS) != 0; - ShowTestPopup(TranslateT("Test Contact"), TranslateT("Test description"), &op); + HANDLE hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDFIRST,0,0); + ShowTestPopup(hContact,TranslateT("Test Contact"), TranslateT("Test description"), &op); break; } diff --git a/Plugins/avatarhistory/popup.cpp b/Plugins/avatarhistory/popup.cpp index f67d07f..cdc21af 100644 --- a/Plugins/avatarhistory/popup.cpp +++ b/Plugins/avatarhistory/popup.cpp @@ -65,9 +65,9 @@ void ShowErrPopup(const TCHAR *description, const TCHAR *title) } -void ShowTestPopup(const TCHAR *title, const TCHAR *description, const Options *op) +void ShowTestPopup(HANDLE hContact,const TCHAR *title, const TCHAR *description, const Options *op) { - ShowPopupEx(NULL, title, description, NULL, POPUP_TYPE_TEST, op); + ShowPopupEx(hContact, title, description, NULL, POPUP_TYPE_TEST, op); } diff --git a/Plugins/avatarhistory/popup.h b/Plugins/avatarhistory/popup.h index d86db2d..74c5323 100644 --- a/Plugins/avatarhistory/popup.h +++ b/Plugins/avatarhistory/popup.h @@ -39,7 +39,7 @@ void DeInitPopups(); void ShowPopup(HANDLE hContact, const TCHAR *title, const TCHAR *description); // Show an test -void ShowTestPopup(const TCHAR *title, const TCHAR *description, const Options *op); +void ShowTestPopup(HANDLE hContact,const TCHAR *title, const TCHAR *description, const Options *op); // Show an error popup void ShowErrPopup(const char *description, const char *title = NULL); diff --git a/Plugins/avatarhistory/sdk/m_folders.h b/Plugins/avatarhistory/sdk/m_folders.h index 71540aa..02d4d35 100644 --- a/Plugins/avatarhistory/sdk/m_folders.h +++ b/Plugins/avatarhistory/sdk/m_folders.h @@ -46,21 +46,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MIRANDA_USERDATAT MIRANDA_USERDATA #endif -#define FOLDER_AVATARS PROFILE_PATHT "\\" CURRENT_PROFILET "\\avatars" -#define FOLDER_VCARDS PROFILE_PATHT "\\" CURRENT_PROFILET "\\vcards" -#define FOLDER_LOGS PROFILE_PATHT "\\" CURRENT_PROFILET "\\logs" -#define FOLDER_RECEIVED_FILES PROFILE_PATHT "\\" CURRENT_PROFILET "\\received files" -#define FOLDER_DOCS MIRANDA_PATHT "\\" "docs" -#define FOLDER_CONFIG PLUGINS_PATHT "\\" "config" -#define FOLDER_SCRIPTS MIRANDA_PATHT "\\" "scripts" -#define FOLDER_UPDATES MIRANDA_PATHT "\\" "updates" - -#define FOLDER_CUSTOMIZE MIRANDA_PATHT "\\" "customize" -#define FOLDER_CUSTOMIZE_SOUNDS FOLDER_CUSTOMIZE "\\sounds" -#define FOLDER_CUSTOMIZE_ICONS FOLDER_CUSTOMIZE "\\icons" -#define FOLDER_CUSTOMIZE_SMILEYS FOLDER_CUSTOMIZE "\\smileys" -#define FOLDER_CUSTOMIZE_SKINS FOLDER_CUSTOMIZE "\\skins" -#define FOLDER_CUSTOMIZE_THEMES FOLDER_CUSTOMIZE "\\themes" +#define FOLDER_AVATARS PROFILE_PATHT _T("\\") CURRENT_PROFILET _T("\\avatars") +#define FOLDER_VCARDS PROFILE_PATHT _T("\\") CURRENT_PROFILET _T("\\vcards") +#define FOLDER_LOGS PROFILE_PATHT _T("\\") CURRENT_PROFILET _T("\\logs") +#define FOLDER_RECEIVED_FILES PROFILE_PATHT _T("\\") CURRENT_PROFILET _T("\\received files") +#define FOLDER_DOCS MIRANDA_PATHT _T("\\") _T("docs") +#define FOLDER_CONFIG PLUGINS_PATHT _T("\\") _T("config") +#define FOLDER_SCRIPTS MIRANDA_PATHT _T("\\") _T("scripts") +#define FOLDER_UPDATES MIRANDA_PATHT _T("\\") _T("updates") + +#define FOLDER_CUSTOMIZE MIRANDA_PATHT _T("\\") _T("customize") +#define FOLDER_CUSTOMIZE_SOUNDS FOLDER_CUSTOMIZE _T("\\sounds") +#define FOLDER_CUSTOMIZE_ICONS FOLDER_CUSTOMIZE _T("\\icons") +#define FOLDER_CUSTOMIZE_SMILEYS FOLDER_CUSTOMIZE _T("\\smileys") +#define FOLDER_CUSTOMIZE_SKINS FOLDER_CUSTOMIZE _T("\\skins") +#define FOLDER_CUSTOMIZE_THEMES FOLDER_CUSTOMIZE _T("\\themes") #define TO_WIDE(x) L ## x -- cgit v1.2.3