From e9bfd222064176e6084b57be778fe5ffee169703 Mon Sep 17 00:00:00 2001 From: Vadim Dashevskiy Date: Sun, 7 Apr 2013 07:34:36 +0000 Subject: - YahooGroups added to MSVC 2010 solutions, added precompiled header, overal project adjustment git-svn-id: http://svn.miranda-ng.org/main/trunk@4355 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/YahooGroups/src/YahooGroups.cpp | 80 ++++++ plugins/YahooGroups/src/commonheaders.h | 62 ++++ plugins/YahooGroups/src/dlg_handlers.cpp | 84 ++++++ plugins/YahooGroups/src/dlg_handlers.h | 29 ++ plugins/YahooGroups/src/hooked_events.cpp | 70 +++++ plugins/YahooGroups/src/hooked_events.h | 36 +++ plugins/YahooGroups/src/list.cpp | 106 +++++++ plugins/YahooGroups/src/list.h | 54 ++++ plugins/YahooGroups/src/resource.h | 19 ++ plugins/YahooGroups/src/services.cpp | 213 ++++++++++++++ plugins/YahooGroups/src/services.h | 39 +++ plugins/YahooGroups/src/stdafx.cpp | 18 ++ plugins/YahooGroups/src/utils.cpp | 453 ++++++++++++++++++++++++++++++ plugins/YahooGroups/src/utils.h | 64 +++++ plugins/YahooGroups/src/version.h | 45 +++ 15 files changed, 1372 insertions(+) create mode 100644 plugins/YahooGroups/src/YahooGroups.cpp create mode 100644 plugins/YahooGroups/src/commonheaders.h create mode 100644 plugins/YahooGroups/src/dlg_handlers.cpp create mode 100644 plugins/YahooGroups/src/dlg_handlers.h create mode 100644 plugins/YahooGroups/src/hooked_events.cpp create mode 100644 plugins/YahooGroups/src/hooked_events.h create mode 100644 plugins/YahooGroups/src/list.cpp create mode 100644 plugins/YahooGroups/src/list.h create mode 100644 plugins/YahooGroups/src/resource.h create mode 100644 plugins/YahooGroups/src/services.cpp create mode 100644 plugins/YahooGroups/src/services.h create mode 100644 plugins/YahooGroups/src/stdafx.cpp create mode 100644 plugins/YahooGroups/src/utils.cpp create mode 100644 plugins/YahooGroups/src/utils.h create mode 100644 plugins/YahooGroups/src/version.h (limited to 'plugins/YahooGroups/src') diff --git a/plugins/YahooGroups/src/YahooGroups.cpp b/plugins/YahooGroups/src/YahooGroups.cpp new file mode 100644 index 0000000000..38f5656335 --- /dev/null +++ b/plugins/YahooGroups/src/YahooGroups.cpp @@ -0,0 +1,80 @@ +/* +YahooGroups plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" + +char ModuleName[] = "YahooGroups"; +HINSTANCE hInstance; + +UINT currentCodePage = 0; +int hLangpack = 0; + +PLUGININFOEX pluginInfo = { + sizeof(PLUGININFOEX), + __PLUGIN_DISPLAY_NAME, + VERSION, + __DESC, + __AUTHOR, + __AUTHOREMAIL, + __COPYRIGHT, + __AUTHORWEB, + 0, //unicode aware + {0x2f3fe8b9, 0x7327, 0x4008, {0xa6, 0x0d, 0x93, 0xf0, 0xf4, 0xf7, 0xf0, 0xf1}} //{2f3fe8b9-7327-4008-a60d-93f0f4f7f0f1} +}; //not used + + +extern "C" __declspec(dllexport) PLUGININFOEX *MirandaPluginInfoEx(DWORD mirandaVersion) +{ + return &pluginInfo; +} + +extern "C" int __declspec(dllexport) Load() +{ + mir_getLP(&pluginInfo); + LogInit(); + + currentCodePage = (UINT) CallService(MS_LANGPACK_GETCODEPAGE, 0, 0); + + InitServices(); + + HookEvents(); + + return 0; +} + +extern "C" int __declspec(dllexport) Unload() +{ + DestroyServices(); + + UnhookEvents(); + + return 0; +} + +bool WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) +{ + hInstance = hinstDLL; + if (fdwReason == DLL_PROCESS_ATTACH) + { + DisableThreadLibraryCalls(hinstDLL); + } + + return TRUE; +} diff --git a/plugins/YahooGroups/src/commonheaders.h b/plugins/YahooGroups/src/commonheaders.h new file mode 100644 index 0000000000..20125002f1 --- /dev/null +++ b/plugins/YahooGroups/src/commonheaders.h @@ -0,0 +1,62 @@ +/* +YahooGroups plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + + +#ifndef M_YAHOOGROUPS_COMMONHEADERS_H +#define M_YAHOOGROUPS_COMMONHEADERS_H + +#define _CRT_SECURE_NO_WARNINGS + +#include +#include +#include +#include +#include + +#include "version.h" +#include "dlg_handlers.h" +#include "hooked_events.h" +#include "services.h" +#include "list.h" +#include "services.h" +#include "utils.h" + +#include "resource.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern char ModuleName[]; +extern HINSTANCE hInstance; +extern UINT currentCodePage; + +#endif //M_YAHOOGROUPS_COMMONHEADERS_H \ No newline at end of file diff --git a/plugins/YahooGroups/src/dlg_handlers.cpp b/plugins/YahooGroups/src/dlg_handlers.cpp new file mode 100644 index 0000000000..4c23c92f9b --- /dev/null +++ b/plugins/YahooGroups/src/dlg_handlers.cpp @@ -0,0 +1,84 @@ +/* +YahooGroups plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" + +INT_PTR CALLBACK DlgProcOptions(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) + { + case WM_INITDIALOG: + { + TranslateDialogDefault(hWnd); + + int autoMove = db_get_b(NULL, ModuleName, "MoveAutomatically", 0); + CheckDlgButton(hWnd, IDC_MOVEAUTOMATICALLY, autoMove ? BST_CHECKED : BST_UNCHECKED); + + return 0; + break; + } + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDC_YAHOOGROUPS: + { + YahooGroupsMoveService(0,0); + break; + } + + case IDC_MOVEAUTOMATICALLY: + { + SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0); + break; + } + } + + break; + } + + case WM_NOTIFY: + { + switch(((LPNMHDR)lParam)->idFrom) + { + case 0: + { + switch (((LPNMHDR)lParam)->code) + { + case PSN_APPLY: + { + int autoMove = IsDlgButtonChecked(hWnd, IDC_MOVEAUTOMATICALLY); + db_set_b(NULL, ModuleName, "MoveAutomatically", autoMove); + break; + } + } + + break; + } + } + + break; + } + + } + + return 0; +} \ No newline at end of file diff --git a/plugins/YahooGroups/src/dlg_handlers.h b/plugins/YahooGroups/src/dlg_handlers.h new file mode 100644 index 0000000000..77dbb1948e --- /dev/null +++ b/plugins/YahooGroups/src/dlg_handlers.h @@ -0,0 +1,29 @@ +/* +YahooGroups plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef M_YAHOOGROUPS_DLGHANDLERS_H +#define M_YAHOOGROUPS_DLGHANDLERS_H + +#include "commonheaders.h" + +INT_PTR CALLBACK DlgProcOptions(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + + +#endif //M_YAHOOGROUPS_DLG_HANDLERS_H \ No newline at end of file diff --git a/plugins/YahooGroups/src/hooked_events.cpp b/plugins/YahooGroups/src/hooked_events.cpp new file mode 100644 index 0000000000..76b31d4802 --- /dev/null +++ b/plugins/YahooGroups/src/hooked_events.cpp @@ -0,0 +1,70 @@ +/* +YahooGroups plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" + +HANDLE hModulesLoaded; +HANDLE hOptionsInitialize; + + +int HookEvents() +{ + hModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + hOptionsInitialize = HookEvent(ME_OPT_INITIALISE, OnOptionsInitialise); + + return 0; +} + +int UnhookEvents() +{ + UnhookEvent(hModulesLoaded); + UnhookEvent(hOptionsInitialize); + + return 0; +} + +int OnModulesLoaded(WPARAM wParam, LPARAM lParam) +{ + int autoMove = db_get_b(NULL, ModuleName, "MoveAutomatically", 0); + if (autoMove) + { + YahooGroupsMoveService(0,0); + } + + return 0; +} + +int OnOptionsInitialise(WPARAM wParam, LPARAM) +{ + OPTIONSDIALOGPAGE odp = {0}; + + odp.cbSize = sizeof(odp); + odp.position = 100000000; + odp.hInstance = hInstance; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS); + odp.ptszTitle = LPGENT("Yahoo Groups"); + odp.ptszGroup = LPGENT("Plugins"); + odp.groupPosition = 810000000; + odp.flags= ODPF_BOLDGROUPS | ODPF_TCHAR; + odp.pfnDlgProc = DlgProcOptions; + Options_AddPage(wParam, &odp); + + return 0; +} diff --git a/plugins/YahooGroups/src/hooked_events.h b/plugins/YahooGroups/src/hooked_events.h new file mode 100644 index 0000000000..224667a78a --- /dev/null +++ b/plugins/YahooGroups/src/hooked_events.h @@ -0,0 +1,36 @@ +/* +YahooGroups plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + + +#ifndef M_YAHOOGROUPS_HOOKED_EVENTS_H +#define M_YAHOOGROUPS_HOOKED_EVENTS_H + +#include "commonheaders.h" + +extern HANDLE hModulesLoaded; +extern HANDLE hOptionsInitialise; + +int HookEvents(); +int UnhookEvents(); + +int OnModulesLoaded(WPARAM wParam, LPARAM lParam); +int OnOptionsInitialise(WPARAM wParam, LPARAM lParam); + +#endif \ No newline at end of file diff --git a/plugins/YahooGroups/src/list.cpp b/plugins/YahooGroups/src/list.cpp new file mode 100644 index 0000000000..364f468926 --- /dev/null +++ b/plugins/YahooGroups/src/list.cpp @@ -0,0 +1,106 @@ +/* +YahooGroups plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" + +CGroupsList &availableGroups = CGroupsList(); + +void CGroupsList::Enlarge(int amount) +{ + size += amount; + groups = (char **) realloc(groups, size * sizeof(char *)); +} + +void CGroupsList::EnsureCapacity() +{ + if (count >= size - 1) + { + Enlarge(size / 2); + } +} + +CGroupsList::CGroupsList() +{ + groups = NULL; + size = 0; + count = 0; + Enlarge(10); +} + +CGroupsList::~CGroupsList() +{ + Clear(); + + free(groups); + groups = NULL; +} + +void CGroupsList::Clear() +{ + if (groups) + { + for (int i = 0; i < count; i++) + { + delete groups[i]; + } + + count = 0; + } +} + +void CGroupsList::Add(char *group) +{ + EnsureCapacity(); + groups[count++] = group; +} + +char *CGroupsList::operator [](int index) +{ + if ((index < 0) || (index >= count)) + { + return NULL; + } + + return groups[index]; +} + +int CGroupsList::Count() +{ + return count; +} + +int CGroupsList::Contains(char *group) +{ + return (Index(group) >= 0); +} + +int CGroupsList::Index(char *group) +{ + int i; + for (i = 0; i < count; i++) + { + if (_stricmp(groups[i], group) == 0) + { + return i; + } + } + + return -1; +} \ No newline at end of file diff --git a/plugins/YahooGroups/src/list.h b/plugins/YahooGroups/src/list.h new file mode 100644 index 0000000000..2bc3c160a8 --- /dev/null +++ b/plugins/YahooGroups/src/list.h @@ -0,0 +1,54 @@ +/* +YahooGroups plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef M_YAHOOGROUPS_LIST_H +#define M_YAHOOGROUPS_LIST_H + +#include "commonheaders.h" + + +class CGroupsList +{ + protected: + char **groups; + int size; + int count; + + void Enlarge(int amount); + void EnsureCapacity(); + + public: + CGroupsList(); + ~CGroupsList(); + + void Add(char *group); + void Clear(); + + int Count(); + + int Contains(char *group); + int Index(char *group); + + char *operator [](int index); +}; + +extern CGroupsList &availableGroups; + +#endif //M_VIUPLOADER_LIST_H \ No newline at end of file diff --git a/plugins/YahooGroups/src/resource.h b/plugins/YahooGroups/src/resource.h new file mode 100644 index 0000000000..1f15e3a8a1 --- /dev/null +++ b/plugins/YahooGroups/src/resource.h @@ -0,0 +1,19 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by YahooGroups.rc +// +#define IDD_OPTIONS 101 +#define IDC_YAHOOGROUPS 1001 +#define IDC_CHECK1 1003 +#define IDC_MOVEAUTOMATICALLY 1003 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1004 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/plugins/YahooGroups/src/services.cpp b/plugins/YahooGroups/src/services.cpp new file mode 100644 index 0000000000..b896f5598f --- /dev/null +++ b/plugins/YahooGroups/src/services.cpp @@ -0,0 +1,213 @@ +/* +YahooGroups plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" + +#define CLIST_GROUPS "CListGroups" + +HANDLE hsYGMove = NULL; +HANDLE hsYGReset = NULL; + +int InitServices() +{ + hsYGMove = CreateServiceFunction(MS_YAHOOGROUPS_MOVE, YahooGroupsMoveService); + hsYGReset = CreateServiceFunction(MS_YAHOOGROUPS_RESET, YahooGroupsResetService); + + ReadAvailableGroups(); + + return 0; +} + +int DestroyServices() +{ + DestroyServiceFunction(hsYGMove); + DestroyServiceFunction(hsYGReset); + + return 0; +} + +void ReadAvailableGroups() +{ + int ok = 1; + int index = 0; + + char group[1024] = {0}; + char tmp[128] = {0}; + + while (ok) + { + mir_snprintf(tmp, sizeof(tmp), "%d", index); + GetStringFromDatabase(NULL, CLIST_GROUPS, tmp, NULL, group, sizeof(group)); + if (strlen(group) > 0) + { + availableGroups.Add(_strdup(group + 1)); + index += 1; + } + else{ + ok = 0; + } + } +} + +int GetNextGroupIndex() +{ + int index = 0; + int found = 0; + + char buffer[1024] = {0}; + char tmp[128] = {0}; + + while (!found) + { + mir_snprintf(tmp, sizeof(tmp), "%d", index++); + + if (GetStringFromDatabase(NULL, CLIST_GROUPS, tmp, NULL, buffer, sizeof(buffer))) + { + found = 1; + } + } + + return index - 1; +} + +void AddNewGroup(char *newGroup) +{ + int index = GetNextGroupIndex(); + + char tmp[128] = {0}; + char group[1024] = {0}; + *group = 1; + mir_snprintf(group + 1, sizeof(group) - 1, "%s", newGroup); + + mir_snprintf(tmp, sizeof(tmp), "%d", index); + const int MAX_SIZE = 1024; + wchar_t wide[MAX_SIZE] = {0}; + *wide = 1; + MultiByteToWideChar(currentCodePage, 0, group + 1, -1, wide + 1, MAX_SIZE - 1); + DBWriteContactSettingWString(NULL, CLIST_GROUPS, tmp, wide); + + availableGroups.Add(_strdup(group + 1)); +} + +void AddContactToGroup(HANDLE hContact, char *group) +{ + const int MAX_SIZE = 1024; + wchar_t wide[MAX_SIZE] = {0}; + MultiByteToWideChar(currentCodePage, 0, group, -1, wide, MAX_SIZE); + DBWriteContactSettingWString(hContact, "CList", "Group", wide); +} + +void CreateGroup(char *group) +{ + char *p = group; + char *sub = group; + char buffer[1024] = {0}; + + while ((p = strchr(sub, '\\'))) + { + *p = 0; + if (strlen(buffer) > 0) + { + strncat(buffer, "\\", sizeof(buffer)); + strncat(buffer, sub, sizeof(buffer)); + } + else{ + mir_snprintf(buffer, sizeof(buffer), "%s", sub); + } + + if (!availableGroups.Contains(buffer)) + { + AddNewGroup(buffer); + } + + *p++ = '\\'; + sub = p; + } + + if (sub) + { + if (strlen(buffer) > 0) + { + strncat(buffer, "\\", sizeof(buffer)); + strncat(buffer, sub, sizeof(buffer)); + } + else{ + mir_snprintf(buffer, sizeof(buffer), "%s", sub); + } + + if (!availableGroups.Contains(buffer)) + { + AddNewGroup(buffer); + } + } +} + +void ProcessContacts(void (*callback)(HANDLE, char *), char *protocol) +{ + HANDLE hContact = db_find_first(); + while (hContact) + { + callback(hContact, protocol); + hContact = db_find_next(hContact); + } +} + +void YahooMoveCallback(HANDLE hContact, char *unused) +{ + char protocol[128] = {0}; + GetContactProtocol(hContact, protocol, sizeof(protocol)); + + if (strlen(protocol) > 0) + { + char ygroup[128] = {0}; + + if (!GetStringFromDatabase(hContact, protocol, "YGroup", NULL, ygroup, sizeof(ygroup))) + { + CreateGroup(ygroup); + AddContactToGroup(hContact, ygroup); + } + } +} + +void ResetGroupCallback(HANDLE hContact, char *protocol) +{ + char p[128] = {0}; + + GetContactProtocol(hContact, p, sizeof(protocol)); + + if ((!protocol) || (_stricmp(protocol, p) == 0)) + { + db_unset(hContact, "CList", "Group"); + } +} + +INT_PTR YahooGroupsMoveService(WPARAM wParam, LPARAM lParam) +{ + ProcessContacts(YahooMoveCallback, NULL); + + return 0; +} + +INT_PTR YahooGroupsResetService(WPARAM wParam, LPARAM lParam) +{ + ProcessContacts(ResetGroupCallback, NULL); + + return 0; +} diff --git a/plugins/YahooGroups/src/services.h b/plugins/YahooGroups/src/services.h new file mode 100644 index 0000000000..4e7b424fee --- /dev/null +++ b/plugins/YahooGroups/src/services.h @@ -0,0 +1,39 @@ +/* +YahooGroups plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + + +#ifndef M_YAHOOGROUPS_SERVICES_H +#define M_YAHOOGROUPS_SERVICES_H + +#include "commonheaders.h" +#include "list.h" + +#define MS_YAHOOGROUPS_MOVE "YahooGroups/Groups/MoveToOfficialGroups" +#define MS_YAHOOGROUPS_RESET "YahooGroups/Groups/Reset" + +int InitServices(); +int DestroyServices(); + +INT_PTR YahooGroupsMoveService(WPARAM wParam, LPARAM lParam); +INT_PTR YahooGroupsResetService(WPARAM wParam, LPARAM lParam); + +void ReadAvailableGroups(); + +#endif //M_CMDLINE_SERVICES_H diff --git a/plugins/YahooGroups/src/stdafx.cpp b/plugins/YahooGroups/src/stdafx.cpp new file mode 100644 index 0000000000..e7e41dae3c --- /dev/null +++ b/plugins/YahooGroups/src/stdafx.cpp @@ -0,0 +1,18 @@ +/* +Copyright (C) 2012-13 Miranda NG Project (http://miranda-ng.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation version 2 +of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include "commonheaders.h" \ No newline at end of file diff --git a/plugins/YahooGroups/src/utils.cpp b/plugins/YahooGroups/src/utils.cpp new file mode 100644 index 0000000000..a2108af1f0 --- /dev/null +++ b/plugins/YahooGroups/src/utils.cpp @@ -0,0 +1,453 @@ +/* +YahooGroups plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" + +int LogInit() +{ +#ifdef USE_LOG + //FILE *fout = fopen(LOG_FILE, "wt"); + //fclose(fout); + Log("********************** Miranda started **********************"); +#endif + return 0; +} + +int Log(char *format, ...) +{ +#ifdef USE_LOG + char str[4096]; + va_list vararg; + int tBytes; + FILE *fout = fopen(LOG_FILE, "at"); + if (!fout) + { +// MessageBox(0, "can't open file", NULL, MB_OK); + return -1; + } + time_t tNow = time(NULL); + struct tm *now = localtime(&tNow); + strftime(str, sizeof(str), "%d %b %Y @ %H:%M:%S: ", now); + fputs(str, fout); + va_start(vararg, format); + + tBytes = _vsnprintf(str, sizeof(str), format, vararg); + if (tBytes > 0) + { + str[tBytes] = 0; + } + + va_end(vararg); + if (str[strlen(str) - 1] != '\n') + { + strcat(str, "\n"); + } + fputs(str, fout); + fclose(fout); +#endif + return 0; +} + +int Info(char *title, char *format, ...) +{ + char str[4096]; + va_list vararg; + int tBytes; + va_start(vararg, format); + tBytes = _vsnprintf(str, sizeof(str), format, vararg); + if (tBytes > 0) + { + str[tBytes] = 0; + } + va_end(vararg); + return MessageBoxA(0, str, title, MB_OK | MB_ICONINFORMATION); +} + +int MyPUShowMessage(char *lpzText, BYTE kind) +{ + if (ServiceExists(MS_POPUP_SHOWMESSAGE)) + { + return PUShowMessage(lpzText, kind); + } + else{ + char *title = (kind == SM_NOTIFY) ? Translate("Notify") : Translate("Warning"); + + return MessageBox(NULL, lpzText, title, MB_OK | (kind == SM_NOTIFY) ? MB_ICONINFORMATION : MB_ICONEXCLAMATION); + } +} + +#define HEX_SIZE 8 + +char *BinToHex(int size, PBYTE data) +{ + char *szresult = NULL; + char buffer[32] = {0}; //should be more than enough + int maxSize = size * 2 + HEX_SIZE + 1; + szresult = (char *) new char[ maxSize ]; + memset(szresult, 0, maxSize); + sprintf(buffer, "%0*X", HEX_SIZE, size); + strcpy(szresult, buffer); + int i; + for (i = 0; i < size; i++) + { + sprintf(buffer, "%02X", data[i]); + strcpy(szresult + (HEX_SIZE + i * 2), buffer); + } + return szresult; +} + +void HexToBin(char *inData, ULONG &size, LPBYTE &outData) +{ + char buffer[32] = {0}; + strcpy(buffer, "0x"); + STRNCPY(buffer + 2, inData, HEX_SIZE); + sscanf(buffer, "%x", &size); + outData = (unsigned char*)new char[size*2]; + UINT i; + //size = i; + char *tmp = inData + HEX_SIZE; + buffer[4] = '\0'; //mark the end of the string + for (i = 0; i < size; i++) + { + STRNCPY(buffer + 2, &tmp[i * 2], 2); + sscanf(buffer, "%x", &outData[i]); + } + i = size; +} + +int GetStringFromDatabase(HANDLE hContact, char *szModule, char *szSettingName, char *szError, char *szResult, int size) +{ + DBVARIANT dbv = {0}; + int res = 1; + int len; + dbv.type = DBVT_ASCIIZ; + if (db_get_ts(hContact, szModule, szSettingName, &dbv) == 0) + { + res = 0; + int tmp = strlen(dbv.pszVal); + len = (tmp < size - 1) ? tmp : size - 1; + strncpy(szResult, dbv.pszVal, len); + szResult[len] = '\0'; + mir_free(dbv.pszVal); + } + else{ + res = 1; + if (szError) + { + int tmp = strlen(szError); + len = (tmp < size - 1) ? tmp : size - 1; + strncpy(szResult, szError, len); + szResult[len] = '\0'; + } + else{ + szResult[0] = '\0'; + } + } + return res; +} + +int GetStringFromDatabase(HANDLE hContact, char *szModule, char *szSettingName, WCHAR *szError, WCHAR *szResult, int count) +{ + DBVARIANT dbv = {0}; + int res = 1; + int len; + dbv.type = DBVT_WCHAR; + if (DBGetContactSettingWString(hContact, szModule, szSettingName, &dbv) == 0) + { + res = 0; + if (dbv.type != DBVT_WCHAR) + { + MultiByteToWideChar(CP_ACP, 0, dbv.pszVal, -1, szResult, count); + } + else{ + int tmp = wcslen(dbv.pwszVal); + len = (tmp < count - 1) ? tmp : count - 1; + wcsncpy(szResult, dbv.pwszVal, len); + szResult[len] = L'\0'; + } + mir_free(dbv.pwszVal); + } + else{ + res = 1; + if (szError) + { + int tmp = wcslen(szError); + len = (tmp < count - 1) ? tmp : count - 1; + wcsncpy(szResult, szError, len); + szResult[len] = L'\0'; + } + else{ + szResult[0] = L'\0'; + } + } + return res; +} + +int GetStringFromDatabase(char *szSettingName, char *szError, char *szResult, int size) +{ + return GetStringFromDatabase(NULL, ModuleName, szSettingName, szError, szResult, size); +} + +int GetStringFromDatabase(char *szSettingName, WCHAR *szError, WCHAR *szResult, int count) +{ + return GetStringFromDatabase(NULL, ModuleName, szSettingName, szError, szResult, count); +} + +#pragma warning (disable: 4312) +TCHAR *GetContactName(HANDLE hContact, char *szProto) +{ + CONTACTINFO ctInfo; + char proto[200]; + + ZeroMemory((void *) &ctInfo, sizeof(ctInfo)); + ctInfo.cbSize = sizeof(ctInfo); + if (szProto) + { + ctInfo.szProto = szProto; + } + else{ + GetContactProtocol(hContact, proto, sizeof(proto)); + ctInfo.szProto = proto; + } + ctInfo.dwFlag = CNF_DISPLAY | CNF_TCHAR; + ctInfo.hContact = hContact; + //_debug_message("retrieving contact name for %d", hContact); + INT_PTR ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo); + //_debug_message(" contact name %s", ctInfo.pszVal); + TCHAR *buffer; + if (!ret) + { + buffer = _tcsdup(ctInfo.pszVal); + } + mir_free(ctInfo.pszVal); + if (!ret) + { + return buffer; + } + else{ + return NULL; + } + return buffer; +} +#pragma warning (default: 4312) + +#pragma warning (disable: 4312) +void GetContactProtocol(HANDLE hContact, char *szProto, int size) +{ + GetStringFromDatabase(hContact, "Protocol", "p", NULL, szProto, size); +} +#pragma warning (default: 4312) + +#pragma warning (disable: 4312) +TCHAR *GetContactID(HANDLE hContact) +{ + char protocol[256]; + GetContactProtocol(hContact, protocol, sizeof(protocol)); + + return GetContactID(hContact, protocol); +} + +TCHAR *GetContactID(HANDLE hContact, char *szProto) +{ + CONTACTINFO ctInfo; + + ZeroMemory((void *) &ctInfo, sizeof(ctInfo)); + ctInfo.cbSize = sizeof(ctInfo); + ctInfo.szProto = szProto; + ctInfo.dwFlag = CNF_DISPLAY | CNF_TCHAR; + ctInfo.hContact = hContact; + INT_PTR ret = CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM) &ctInfo); + TCHAR *buffer; + if (!ret) + { + TCHAR tmp[16]; + switch (ctInfo.type) + { + case CNFT_BYTE: + { + _stprintf(tmp, _T("%d"), ctInfo.bVal); + buffer = _tcsdup(tmp); + + break; + } + + case CNFT_WORD: + { + _stprintf(tmp, _T("%d"), ctInfo.wVal); + buffer = _tcsdup(tmp); + + break; + } + + case CNFT_DWORD: + { + _stprintf(tmp, _T("%ld"), ctInfo.dVal); + buffer = _tcsdup(tmp); + + break; + } + + case CNFT_ASCIIZ: + default: + { + buffer = _tcsdup(ctInfo.pszVal); + + break; + } + } + + + } + mir_free(ctInfo.pszVal); + if (!ret) + { + return buffer; + } + else{ + return NULL; + } +} +#pragma warning (default: 4312) + +#pragma warning (disable: 4312) +HANDLE GetContactFromID(TCHAR *szID, char *szProto) +{ + HANDLE hContact = db_find_first(); + TCHAR *szHandle; + TCHAR dispName[1024]; + char cProtocol[256]; + char *tmp; + + int found = 0; + while (hContact) + { + GetContactProtocol(hContact, cProtocol, sizeof(cProtocol)); + szHandle = GetContactID(hContact, cProtocol); + + tmp = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, 0); + STRNCPY(dispName, tmp, sizeof(dispName)); + + if ((szHandle) && ((_tcsicmp(szHandle, szID) == 0) || (_tcsicmp(dispName, szID) == 0)) && ((szProto == NULL) || (_stricmp(szProto, cProtocol) == 0))) + { + found = 1; + } + if (szHandle) { free(szHandle); } + + if (found) { break; } + hContact = db_find_next(hContact); + } + + return hContact; +} +#pragma warning (default: 4312) + +#pragma warning (disable: 4312) +HANDLE GetContactFromID(TCHAR *szID, wchar_t *szProto) +{ + char protocol[1024]; + WideCharToMultiByte(CP_ACP, 0, szProto, -1, protocol, sizeof(protocol), NULL, NULL); + return GetContactFromID(szID, protocol); +} +#pragma warning (default: 4312) + +void ScreenToClient(HWND hWnd, LPRECT rect) +{ + POINT pt; + int cx = rect->right - rect->left; + int cy = rect->bottom - rect->top; + pt.x = rect->left; + pt.y = rect->top; + ScreenToClient(hWnd, &pt); + rect->left = pt.x; + rect->top = pt.y; + rect->right = pt.x + cx; + rect->bottom = pt.y + cy; +} + +void AnchorMoveWindow(HWND window, const WINDOWPOS *parentPos, int anchors) +{ + RECT rParent; + RECT rChild; + + if (parentPos->flags & SWP_NOSIZE) + { + return; + } + GetWindowRect(parentPos->hwnd, &rParent); + rChild = AnchorCalcPos(window, &rParent, parentPos, anchors); + MoveWindow(window, rChild.left, rChild.top, rChild.right - rChild.left, rChild.bottom - rChild.top, FALSE); +} + +RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos, int anchors) +{ + RECT rChild; + RECT rTmp; + + GetWindowRect(window, &rChild); + ScreenToClient(parentPos->hwnd, &rChild); + + int cx = rParent->right - rParent->left; + int cy = rParent->bottom - rParent->top; + if ((cx == parentPos->cx) && (cy == parentPos->cy)) + { + return rChild; + } + if (parentPos->flags & SWP_NOSIZE) + { + return rChild; + } + + rTmp.left = parentPos->x - rParent->left; + rTmp.right = (parentPos->x + parentPos->cx) - rParent->right; + rTmp.bottom = (parentPos->y + parentPos->cy) - rParent->bottom; + rTmp.top = parentPos->y - rParent->top; + + cx = (rTmp.left) ? -rTmp.left : rTmp.right; + cy = (rTmp.top) ? -rTmp.top : rTmp.bottom; + + rChild.right += cx; + rChild.bottom += cy; + //expanded the window accordingly, now we need to enforce the anchors + if ((anchors & ANCHOR_LEFT) && (!(anchors & ANCHOR_RIGHT))) + { + rChild.right -= cx; + } + if ((anchors & ANCHOR_TOP) && (!(anchors & ANCHOR_BOTTOM))) + { + rChild.bottom -= cy; + } + if ((anchors & ANCHOR_RIGHT) && (!(anchors & ANCHOR_LEFT))) + { + rChild.left += cx; + } + if ((anchors & ANCHOR_BOTTOM) && (!(anchors & ANCHOR_TOP))) + { + rChild.top += cy; + } + return rChild; +} + +inline char *STRNCPY(char *output, const char *input, size_t size) +{ + char *res = strncpy(output, input, size); + output[size - 1] = 0; + + return res; +} \ No newline at end of file diff --git a/plugins/YahooGroups/src/utils.h b/plugins/YahooGroups/src/utils.h new file mode 100644 index 0000000000..f2f0411de7 --- /dev/null +++ b/plugins/YahooGroups/src/utils.h @@ -0,0 +1,64 @@ +/* +YahooGroups plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + + +#ifndef M_YAHOOGROUPS_UTILS_H +#define M_YAHOOGROUPS_UTILS_H + +#include +#include "commonheaders.h" + +//#define USE_LOG +#define LOG_FILE "yahoogroups.log" + +#define ANCHOR_LEFT 0x000001 +#define ANCHOR_RIGHT 0x000002 +#define ANCHOR_TOP 0x000004 +#define ANCHOR_BOTTOM 0x000008 +#define ANCHOR_ALL ANCHOR_LEFT | ANCHOR_RIGHT | ANCHOR_TOP | ANCHOR_BOTTOM + +int LogInit(); +int Log(char *format, ...); +int Info(char *title, char *format, ...); + +char *BinToHex(int size, PBYTE data); +void HexToBin(char *inData, ULONG &size, PBYTE &outData); + +void ScreenToClient(HWND hWnd, LPRECT rect); +void AnchorMoveWindow(HWND window, const WINDOWPOS *parentPos, int anchors); +RECT AnchorCalcPos(HWND window, const RECT *rParent, const WINDOWPOS *parentPos, int anchors); + +int GetStringFromDatabase(HANDLE hContact, char *szModule, char *szSettingName, char *szError, char *szResult, int size); +int GetStringFromDatabase(HANDLE hContact, char *szModule, char *szSettingName, WCHAR *szError, WCHAR *szResult, int count); +int GetStringFromDatabase(char *szSettingName, char *szError, char *szResult, int size); +int GetStringFromDatabase(char *szSettingName, WCHAR *szError, WCHAR *szResult, int count); + +TCHAR *GetContactName(HANDLE hContact, char *szProto); +TCHAR *GetContactID(HANDLE hContact); +TCHAR *GetContactID(HANDLE hContact, char *szProto); +HANDLE GetContactFromID(TCHAR *szID, char *szProto); +HANDLE GetContactFromID(TCHAR *szID, wchar_t *szProto); +void GetContactProtocol(HANDLE hContact, char *szProto, int size); + +int MyPUShowMessage(char *lpzText, BYTE kind); + +inline char *STRNCPY(char *output, const char *input, size_t size); + +#endif \ No newline at end of file diff --git a/plugins/YahooGroups/src/version.h b/plugins/YahooGroups/src/version.h new file mode 100644 index 0000000000..cae2c6fa1f --- /dev/null +++ b/plugins/YahooGroups/src/version.h @@ -0,0 +1,45 @@ +/* +YahooGroups plugin for Miranda IM + +Copyright © 2007 Cristian Libotean + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef M_CMDLINE_VERSION_H +#define M_CMDLINE_VERSION_H + +#define __MAJOR_VERSION 0 +#define __MINOR_VERSION 0 +#define __RELEASE_NUM 1 +#define __BUILD_NUM 1 + +#define VERSION PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM) + +#define __PLUGINVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM +#define __PLUGINVERSION_STRING_DOTS __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM +#define __STRINGIFY_(x) #x +#define __STRINGIFY(x) __STRINGIFY_(x) +#define __VERSION_STRING __STRINGIFY(__PLUGINVERSION_STRING_DOTS) + +#define __DESC "This plugin imports and creates the Yahoo groups defined in Yahoo Messenger." +#define __AUTHOR "Cristian Libotean" +#define __AUTHOREMAIL "eblis102@yahoo.com" +#define __COPYRIGHT "© 2007 Cristian Libotean" +#define __AUTHORWEB "http://www.miranda-im.org/" + +#define __PLUGIN_DISPLAY_NAME "Yahoo Groups" + +#endif //M_CMDLINE_VERSION_H -- cgit v1.2.3