summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/ContactsPlus/contacts_10.vcxproj8
-rw-r--r--plugins/ContactsPlus/contacts_11.vcxproj8
-rw-r--r--plugins/ContactsPlus/contacts_12.vcxproj8
-rw-r--r--plugins/ContactsPlus/src/Version.h4
-rw-r--r--plugins/ContactsPlus/src/main.cpp144
-rw-r--r--plugins/ContactsPlus/src/receive.cpp273
-rw-r--r--plugins/ContactsPlus/src/receive.h40
-rw-r--r--plugins/ContactsPlus/src/send.cpp919
-rw-r--r--plugins/ContactsPlus/src/send.h11
-rw-r--r--plugins/ContactsPlus/src/utils.cpp674
-rw-r--r--plugins/ContactsPlus/src/utils.h37
11 files changed, 771 insertions, 1355 deletions
diff --git a/plugins/ContactsPlus/contacts_10.vcxproj b/plugins/ContactsPlus/contacts_10.vcxproj
index fbd45ff691..8c25dc7604 100644
--- a/plugins/ContactsPlus/contacts_10.vcxproj
+++ b/plugins/ContactsPlus/contacts_10.vcxproj
@@ -25,20 +25,20 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
diff --git a/plugins/ContactsPlus/contacts_11.vcxproj b/plugins/ContactsPlus/contacts_11.vcxproj
index 50929699d8..a795dc115d 100644
--- a/plugins/ContactsPlus/contacts_11.vcxproj
+++ b/plugins/ContactsPlus/contacts_11.vcxproj
@@ -25,23 +25,23 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v110_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v110_xp</PlatformToolset>
</PropertyGroup>
diff --git a/plugins/ContactsPlus/contacts_12.vcxproj b/plugins/ContactsPlus/contacts_12.vcxproj
index c9d4371c6b..765874d4f2 100644
--- a/plugins/ContactsPlus/contacts_12.vcxproj
+++ b/plugins/ContactsPlus/contacts_12.vcxproj
@@ -25,23 +25,23 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
- <CharacterSet>MultiByte</CharacterSet>
+ <CharacterSet>Unicode</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
<PlatformToolset>v120_xp</PlatformToolset>
</PropertyGroup>
diff --git a/plugins/ContactsPlus/src/Version.h b/plugins/ContactsPlus/src/Version.h
index f76c68b170..9c1160df62 100644
--- a/plugins/ContactsPlus/src/Version.h
+++ b/plugins/ContactsPlus/src/Version.h
@@ -1,6 +1,6 @@
#define __MAJOR_VERSION 1
-#define __MINOR_VERSION 5
-#define __RELEASE_NUM 2
+#define __MINOR_VERSION 6
+#define __RELEASE_NUM 0
#define __BUILD_NUM 0
#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM
diff --git a/plugins/ContactsPlus/src/main.cpp b/plugins/ContactsPlus/src/main.cpp
index 615b126000..4590e10d12 100644
--- a/plugins/ContactsPlus/src/main.cpp
+++ b/plugins/ContactsPlus/src/main.cpp
@@ -48,49 +48,46 @@ PLUGININFOEX pluginInfo = {
__AUTHORWEB,
UNICODE_AWARE,
// {0324785E-74CE-4600-B781-851773B3EFC5}
- {0x0324785E, 0x74CE, 0x4600, {0xB7, 0x81, 0x85, 0x17, 0x73, 0xB3, 0xEF, 0xC5}}
+ { 0x0324785E, 0x74CE, 0x4600, { 0xB7, 0x81, 0x85, 0x17, 0x73, 0xB3, 0xEF, 0xC5 } }
};
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
- hInst = hinstDLL;
- return TRUE;
+ hInst = hinstDLL;
+ return TRUE;
}
static int HookDBEventAdded(WPARAM wParam, LPARAM lParam)
{
- HANDLE hContact = (HANDLE)wParam;
- HANDLE hDbEvent = (HANDLE)lParam;
- //process the event
- DBEVENTINFO dbe = { sizeof(dbe) };
- db_event_get(hDbEvent, &dbe);
- //check if we should process the event
- if (dbe.flags & (DBEF_SENT|DBEF_READ) || dbe.eventType != EVENTTYPE_CONTACTS) return 0;
- //get event contents
- dbe.cbBlob = db_event_getBlobSize(hDbEvent);
- if (dbe.cbBlob != -1)
- dbe.pBlob = (PBYTE)_alloca(dbe.cbBlob);
- db_event_get(hDbEvent, &dbe);
- //play received sound
- SkinPlaySound("RecvContacts");
- { //add event to the contact list
- CLISTEVENT cle = {0};
- TCHAR caToolTip[128];
-
- cle.cbSize = sizeof(cle);
- cle.hContact = hContact;
- cle.hDbEvent = hDbEvent;
- cle.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_CONTACTS));
- cle.pszService = MS_CONTACTS_RECEIVE;
-
- WCHAR tmp[MAX_PATH];
- mir_sntprintf(caToolTip, SIZEOF(caToolTip), "%s %s", SRCTranslateT("Contacts received from", tmp), (TCHAR*)GetContactDisplayNameT(hContact));
-
- cle.ptszTooltip = caToolTip;
- cle.flags |= CLEF_UNICODE;
- CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle);
- }
- return 0; //continue processing by other hooks
+ HANDLE hContact = (HANDLE)wParam;
+ HANDLE hDbEvent = (HANDLE)lParam;
+ //process the event
+ DBEVENTINFO dbe = { sizeof(dbe) };
+ db_event_get(hDbEvent, &dbe);
+ //check if we should process the event
+ if (dbe.flags & (DBEF_SENT | DBEF_READ) || dbe.eventType != EVENTTYPE_CONTACTS) return 0;
+ //get event contents
+ dbe.cbBlob = db_event_getBlobSize(hDbEvent);
+ if (dbe.cbBlob != -1)
+ dbe.pBlob = (PBYTE)_alloca(dbe.cbBlob);
+ db_event_get(hDbEvent, &dbe);
+ //play received sound
+ SkinPlaySound("RecvContacts");
+ {
+ //add event to the contact list
+ TCHAR caToolTip[128];
+ mir_sntprintf(caToolTip, SIZEOF(caToolTip), _T("%s %s"), TranslateT("Contacts received from"), pcli->pfnGetContactDisplayName(hContact, 0));
+
+ CLISTEVENT cle = { sizeof(cle) };
+ cle.hContact = hContact;
+ cle.hDbEvent = hDbEvent;
+ cle.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_CONTACTS));
+ cle.pszService = MS_CONTACTS_RECEIVE;
+ cle.ptszTooltip = caToolTip;
+ cle.flags |= CLEF_UNICODE;
+ CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle);
+ }
+ return 0; //continue processing by other hooks
}
static void ProcessUnreadEvents(void)
@@ -100,7 +97,7 @@ static void ProcessUnreadEvents(void)
while (hDbEvent) {
DBEVENTINFO dbei = { sizeof(dbei) };
db_event_get(hDbEvent, &dbei);
- if (!(dbei.flags & (DBEF_SENT|DBEF_READ)) && dbei.eventType == EVENTTYPE_CONTACTS) {
+ if (!(dbei.flags & (DBEF_SENT | DBEF_READ)) && dbei.eventType == EVENTTYPE_CONTACTS) {
//process the event
HookDBEventAdded((WPARAM)hContact, (LPARAM)hDbEvent);
}
@@ -138,17 +135,14 @@ static int HookPreBuildContactMenu(WPARAM wParam, LPARAM lParam)
static int HookModulesLoaded(WPARAM wParam, LPARAM lParam)
{
- char* modules[2] = {0};
- WCHAR tmp[MAX_PATH];
+ char* modules[2] = { 0 };
modules[0] = MODULENAME;
- CallService("DBEditorpp/RegisterModule",(WPARAM)modules,(LPARAM)1);
+ CallService("DBEditorpp/RegisterModule", (WPARAM)modules, (LPARAM)1);
CLISTMENUITEM mi = { sizeof(mi) };
- mi.ptszName = SRCTranslateT("Contacts", tmp);
+ mi.pszName = LPGEN("Contacts");
mi.position = -2000009990; //position in menu
- mi.flags = CMIF_KEEPUNTRANSLATED;
- mi.flags |= CMIF_UNICODE;
mi.pszService = MS_CONTACTS_SEND;
mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_CONTACTS));
hContactMenuItem = Menu_AddContactMenuItem(&mi);
@@ -164,56 +158,49 @@ static int HookModulesLoaded(WPARAM wParam, LPARAM lParam)
static int HookContactSettingChanged(WPARAM wParam, LPARAM lParam)
{
- DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam;
- char *szProto =GetContactProto((HANDLE)wParam);
+ DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam;
+ char *szProto = GetContactProto((HANDLE)wParam);
- if (strcmpnull(cws->szModule,"CList") && strcmpnull(cws->szModule, szProto)) return 0;
+ if (strcmpnull(cws->szModule, "CList") && strcmpnull(cws->szModule, szProto)) return 0;
- WindowList_Broadcast(ghSendWindowList,DM_UPDATETITLE,0,0);
- WindowList_Broadcast(ghRecvWindowList,DM_UPDATETITLE,0,0);
-
- return 0;
+ WindowList_Broadcast(ghSendWindowList, DM_UPDATETITLE, 0, 0);
+ WindowList_Broadcast(ghRecvWindowList, DM_UPDATETITLE, 0, 0);
+ return 0;
}
static int HookContactDeleted(WPARAM wParam, LPARAM lParam)
{ // if our contact gets deleted close his window
- HWND h = WindowList_Find(ghSendWindowList,(HANDLE)wParam);
-
- if (h)
- {
- SendMessageT(h,WM_CLOSE,0,0);
- }
-
- while (h = WindowList_Find(ghRecvWindowList, (HANDLE)wParam))
- { // since we hack the window list - more windows for one contact, we need to close them all
- SendMessageT(h, WM_CLOSE,0,0);
- }
- return 0;
+ HWND h = WindowList_Find(ghSendWindowList, (HANDLE)wParam);
+
+ if (h)
+ {
+ SendMessage(h, WM_CLOSE, 0, 0);
+ }
+
+ while (h = WindowList_Find(ghRecvWindowList, (HANDLE)wParam))
+ { // since we hack the window list - more windows for one contact, we need to close them all
+ SendMessage(h, WM_CLOSE, 0, 0);
+ }
+ return 0;
}
static INT_PTR ServiceSendCommand(WPARAM wParam, LPARAM lParam)
{
- HWND hWnd;
- //find window for hContact
- hWnd = WindowList_Find(ghSendWindowList, (HANDLE)wParam);
-
- if (!hWnd)
- CreateDialogParamT(hInst, MAKEINTRESOURCE(IDD_SEND), NULL, SendDlgProc, (LPARAM)(HANDLE)wParam);
- else
- {
- SetForegroundWindow(hWnd);
- SetFocus(hWnd);
- }
- return 0;
+ //find window for hContact
+ HWND hWnd = WindowList_Find(ghSendWindowList, (HANDLE)wParam);
+ if (!hWnd)
+ CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SEND), NULL, SendDlgProc, wParam);
+ else {
+ SetForegroundWindow(hWnd);
+ SetFocus(hWnd);
+ }
+ return 0;
}
static INT_PTR ServiceReceiveCommand(WPARAM wParam, LPARAM lParam)
{
- CLISTEVENT* pcle = (CLISTEVENT*)lParam;
-
- CreateDialogParamT(hInst, MAKEINTRESOURCE(IDD_RECEIVE), NULL, RecvDlgProc, (LPARAM)pcle);
-
- return 0;
+ CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_RECEIVE), NULL, RecvDlgProc, lParam);
+ return 0;
}
extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
@@ -227,7 +214,6 @@ extern "C" __declspec(dllexport) int Load(void)
mir_getCLI();
InitCommonControls();
- InitI18N();
//init hooks
HookEvent(ME_SYSTEM_MODULESLOADED, HookModulesLoaded);
diff --git a/plugins/ContactsPlus/src/receive.cpp b/plugins/ContactsPlus/src/receive.cpp
index 93bb89a48e..5e61067781 100644
--- a/plugins/ContactsPlus/src/receive.cpp
+++ b/plugins/ContactsPlus/src/receive.cpp
@@ -25,11 +25,31 @@
/* TRecvContactsData */
-TReceivedItem* TRecvContactsData::AddReceivedItem() {
+TRecvContactsData::TRecvContactsData(HANDLE contact)
+{
+ mhContact = contact;
+ hHook = NULL;
+ cbReceived = 0;
+ maReceived = NULL;
+ haUin = NULL;
+}
+
+TRecvContactsData::~TRecvContactsData()
+{
+ if (cbReceived) {
+ for (int i = 0; i < cbReceived; i++)
+ delete maReceived[i];
+ mir_free(maReceived);
+ mir_free(haUin);
+ }
+}
+
+TReceivedItem* TRecvContactsData::AddReceivedItem()
+{
int iItem = cbReceived;
cbReceived++;
- maReceived = (TReceivedItem**)realloc(maReceived, cbReceived*sizeof(TReceivedItem*));
+ maReceived = (TReceivedItem**)mir_realloc(maReceived, cbReceived*sizeof(TReceivedItem*));
maReceived[iItem] = new TReceivedItem();
return maReceived[iItem];
@@ -38,8 +58,7 @@ TReceivedItem* TRecvContactsData::AddReceivedItem() {
static int RecvDlg_Resize(HWND hwndDlg,LPARAM lParam,UTILRESIZECONTROL *urc)
{
- switch (urc->wId)
- {
+ switch (urc->wId) {
case IDC_CONTACTS:
return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT;
break;
@@ -62,28 +81,24 @@ static int RecvDlg_Resize(HWND hwndDlg,LPARAM lParam,UTILRESIZECONTROL *urc)
return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; // default
}
-
-static char* ListView_GetItemTextEx(HWND hLV, int iItem, int iSubItem)
+static TCHAR* ListView_GetItemTextEx(HWND hLV, int iItem, int iSubItem)
{
LVITEM lvi = {0};
-
lvi.mask = LVIF_TEXT;
lvi.iSubItem = iSubItem;
lvi.cchTextMax = 64;
- lvi.pszText = (char*)malloc(lvi.cchTextMax);
- while (SendMessageT(hLV, LVM_GETITEMTEXT, iItem, (LPARAM)&lvi) == lvi.cchTextMax - 1)
- { // loop until the returned size is smaller than buffer size
- SAFE_FREE((void**)&lvi.pszText);
+ lvi.pszText = (TCHAR*)mir_alloc(lvi.cchTextMax * sizeof(TCHAR));
+ // loop until the returned size is smaller than buffer size
+ while (SendMessage(hLV, LVM_GETITEMTEXT, iItem, (LPARAM)&lvi) == lvi.cchTextMax - 1) {
lvi.cchTextMax += 64;
- lvi.pszText = (char*)malloc(lvi.cchTextMax);
+ lvi.pszText = (TCHAR*)mir_realloc(lvi.pszText, lvi.cchTextMax * sizeof(TCHAR));
}
return lvi.pszText;
}
-
static void EnableGroupCombo(HWND hwndDlg)
{
- EnableDlgItem(hwndDlg, IDC_GROUPS, SendMessageT(GetDlgItem(hwndDlg, IDC_ENABLEGROUPS), BM_GETCHECK, 0, 0));
+ EnableDlgItem(hwndDlg, IDC_GROUPS, SendMessage(GetDlgItem(hwndDlg, IDC_ENABLEGROUPS), BM_GETCHECK, 0, 0));
}
static void RebuildGroupCombo(HWND hwndDlg)
@@ -92,81 +107,70 @@ static void RebuildGroupCombo(HWND hwndDlg)
HWND hGroupsCombo = GetDlgItem(hwndDlg, IDC_GROUPS);
if (bHasGroups) {
- int curs = SendMessageT(hGroupsCombo, CB_GETCURSEL, 0, 0);
+ int curs = SendMessage(hGroupsCombo, CB_GETCURSEL, 0, 0);
TCHAR* curst;
EnableDlgItem(hwndDlg, IDC_ENABLEGROUPS, TRUE);
EnableGroupCombo(hwndDlg);
if (curs != CB_ERR) {
- curst = (char*)_alloca((SendMessageT(hGroupsCombo, CB_GETLBTEXTLEN, curs, 0) + 1) * sizeof(WCHAR));
- SendMessageT(hGroupsCombo, CB_GETLBTEXT, curs, (LPARAM)curst);
+ curst = (TCHAR*)_alloca((SendMessage(hGroupsCombo, CB_GETLBTEXTLEN, curs, 0) + 1) * sizeof(TCHAR));
+ SendMessage(hGroupsCombo, CB_GETLBTEXT, curs, (LPARAM)curst);
}
- SendMessageT(hGroupsCombo, CB_RESETCONTENT, 0, 0);
+ SendMessage(hGroupsCombo, CB_RESETCONTENT, 0, 0);
TCHAR *szGroup;
for (int i=1; (szGroup = pcli->pfnGetGroupName(i, NULL)) != NULL; i++) {
- int nIndex = SendMessageT(hGroupsCombo, CB_ADDSTRING, 0, (LPARAM)szGroup);
- SendMessageT(hGroupsCombo, CB_SETITEMDATA, nIndex, i);
+ int nIndex = SendMessage(hGroupsCombo, CB_ADDSTRING, 0, (LPARAM)szGroup);
+ SendMessage(hGroupsCombo, CB_SETITEMDATA, nIndex, i);
}
if (curs != CB_ERR)
- SendMessageT(hGroupsCombo, CB_SELECTSTRING, -1, (LPARAM)curst);
+ SendMessage(hGroupsCombo, CB_SELECTSTRING, -1, (LPARAM)curst);
else
- SendMessageT(hGroupsCombo, CB_SETCURSEL, 0, 0);
+ SendMessage(hGroupsCombo, CB_SETCURSEL, 0, 0);
}
- else
- { // no groups available
+ else {
+ // no groups available
EnableDlgItem(hwndDlg, IDC_ENABLEGROUPS, FALSE);
EnableDlgItem(hwndDlg, IDC_GROUPS, FALSE);
}
}
-static HANDLE CreateTemporaryContactForItem(HWND hwndDlg, TRecvContactsData* wndData, int iItem)
+static HANDLE CreateTemporaryContactForItem(HWND hwndDlg, TRecvContactsData *wndData, int iItem)
{
- char* caUIN = ListView_GetItemTextEx(GetDlgItem(hwndDlg, IDC_CONTACTS), iItem, 0);
- char* szProto =GetContactProto(wndData->mhContact);
+ TCHAR *caUIN = ListView_GetItemTextEx(GetDlgItem(hwndDlg, IDC_CONTACTS), iItem, 0);
+ char *szProto = GetContactProto(wndData->mhContact);
wndData->rhSearch = (HANDLE)CallProtoService(szProto, PS_BASICSEARCH, 0, (LPARAM)caUIN); // find it
- SAFE_FREE((void**)&wndData->haUin);
- wndData->haUin = caUIN;
+ replaceStrT(wndData->haUin, caUIN);
for (int j = 0; j < wndData->cbReceived; j++)
- if (!strcmpnull(wndData->maReceived[j]->mcaUIN, caUIN))
+ if (!lstrcmp(wndData->maReceived[j]->mcaUIN, caUIN))
return (HANDLE)CallProtoService(szProto, PS_ADDTOLISTBYEVENT, MAKEWPARAM(PALF_TEMPORARY, j), (LPARAM)wndData->mhDbEvent);
return NULL;
}
-void RecvListView_AddColumn(HWND hList, int nWidth, const char* szTitle, int nTranslate, int nItem)
+void RecvListView_AddColumn(HWND hList, int nWidth, TCHAR *szTitle, int nItem)
{
LVCOLUMN col;
- WCHAR tmp[MAX_PATH];
-
- col.mask = LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
+ col.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
col.fmt = LVCFMT_LEFT;
col.cx = nWidth;
- if (nTranslate) {
- col.pszText = SRCTranslateT(szTitle, tmp);
- }
- else {
- if (!szTitle) szTitle = "UID";
- col.pszText = ansi_to_tchar(szTitle, CallService(MS_LANGPACK_GETCODEPAGE, 0, 0));
- }
+ col.pszText = szTitle;
col.iSubItem = nItem;
- ListView_InsertColumnT(hList, nItem, &col);
- if (!nTranslate)
- SAFE_FREE((void**)&col.pszText);
+ ListView_InsertColumn(hList, nItem, &col);
}
INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- TRecvContactsData* wndData = (TRecvContactsData*)GetWindowLongPtr(hwndDlg, DWLP_USER);
+ TRecvContactsData *wndData = (TRecvContactsData*)GetWindowLongPtr(hwndDlg, DWLP_USER);
+ HANDLE hContact;
switch (msg) {
case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
{
- CLISTEVENT* pcle = (CLISTEVENT*)lParam; /// got it
-
- TranslateDialogDefault(hwndDlg);
+ CLISTEVENT *pcle = (CLISTEVENT*)lParam;
WindowList_Add(ghRecvWindowList, hwndDlg, pcle->hContact);
- SendMessageT(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_CONTACTS)));
+ SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_CONTACTS)));
EnableDlgItem(hwndDlg, IDOK, FALSE);
EnableDlgItem(hwndDlg, IDDETAILS, FALSE);
wndData = new TRecvContactsData(pcle->hContact);
@@ -182,13 +186,13 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
HWND hLV = GetDlgItem(hwndDlg, IDC_CONTACTS);
ListView_SetExtendedListViewStyle(hLV, LVS_EX_CHECKBOXES|LVS_EX_FULLROWSELECT);
// add columns
- RecvListView_AddColumn(hLV, 120, (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDTEXT, 0), FALSE, 0);
- RecvListView_AddColumn(hLV, 100, "Nick", TRUE, 1);
- RecvListView_AddColumn(hLV, 100, "First Name", TRUE, 2);
- RecvListView_AddColumn(hLV, 100, "Last Name", TRUE, 3);
+ RecvListView_AddColumn(hLV, 120, _A2T((char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDTEXT, 0)), 0);
+ RecvListView_AddColumn(hLV, 100, TranslateT("Nick"), 1);
+ RecvListView_AddColumn(hLV, 100, TranslateT("First Name"), 2);
+ RecvListView_AddColumn(hLV, 100, TranslateT("Last Name"), 3);
// fill in groups
- SendMessageT(GetDlgItem(hwndDlg, IDC_ENABLEGROUPS), BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
+ SendMessage(GetDlgItem(hwndDlg, IDC_ENABLEGROUPS), BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
RebuildGroupCombo(hwndDlg);
{ // fill listview with received contacts
@@ -216,19 +220,19 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
TReceivedItem* pItem = wndData->AddReceivedItem();
if (dbe.flags & DBEF_UTF)
- pItem->mcaNick = utf8_to_tchar((unsigned char*)pcBlob);
+ pItem->mcaNick = mir_utf8decodeT(pcBlob);
else
- pItem->mcaNick = ansi_to_tchar(pcBlob);
+ pItem->mcaNick = mir_a2t(pcBlob);
pcBlob += strsize + 1;
// UIN
strsize = (int)strlennull(pcBlob);
- pItem->mcaUIN = null_strdup(pcBlob);
+ pItem->mcaUIN = mir_a2t(pcBlob);
pcBlob += strsize + 1;
// add to listview
lvi.iItem = nItem;
lvi.pszText = pItem->mcaUIN;
ListView_InsertItem(hLV, &lvi); // with image
- ListView_SetItemTextT(hLV, nItem, 1, pItem->mcaNick);
+ ListView_SetItemText(hLV, nItem, 1, pItem->mcaNick);
// check for end of contacts
if (pcBlob >= pcEnd)
break;
@@ -240,7 +244,7 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
wndData->hIcons[2] = InitMButton(hwndDlg, IDC_HISTORY, MAKEINTRESOURCEA(IDI_HISTORY), LPGEN("View User's History"));
wndData->hIcons[3] = InitMButton(hwndDlg, IDC_USERMENU, MAKEINTRESOURCEA(IDI_DOWNARROW), LPGEN("User Menu"));
- SendMessageT(hwndDlg,DM_UPDATETITLE,0,0);
+ SendMessage(hwndDlg,DM_UPDATETITLE,0,0);
// new dialog init done
Utils_RestoreWindowPosition(hwndDlg, NULL, MODULENAME, "");
return TRUE;
@@ -254,7 +258,7 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
if (ListView_GetSelectedCount(hLV) != 1) break; // if not clicking on item, bye
wndData->iPopupItem = ListView_GetNextItem(hLV, -1, LVNI_ALL|LVNI_SELECTED);
if (wndData->iPopupItem == -1) break; // if no item selected no user details available
- return SendMessageT(hwndDlg, WM_COMMAND, ID_POPUP_USERDETAILS, 0); // show user details
+ return SendMessage(hwndDlg, WM_COMMAND, ID_POPUP_USERDETAILS, 0); // show user details
}
case LVN_ITEMCHANGED:
{
@@ -293,39 +297,37 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
case IDOK: // "Add Selected" button click
{ // for each selected item, find its index in the hDbEvent
// and after that add this item to the DB permanently
- char* caUIN;
HWND hLV = GetDlgItem(hwndDlg, IDC_CONTACTS);
HWND hGroupsCombo = GetDlgItem(hwndDlg, IDC_GROUPS);
HWND hGroupsCheck = GetDlgItem(hwndDlg, IDC_ENABLEGROUPS);
- int curs = SendMessageT(hGroupsCombo, CB_GETCURSEL, 0, 0);
+ int curs = SendMessage(hGroupsCombo, CB_GETCURSEL, 0, 0);
TCHAR* caGroup = NULL;
int nGroupId = -1;
- if (curs != CB_ERR && IsWindowEnabled(hGroupsCheck) && SendMessageT(hGroupsCheck, BM_GETCHECK, 0, 0))
+ if (curs != CB_ERR && IsWindowEnabled(hGroupsCheck) && SendMessage(hGroupsCheck, BM_GETCHECK, 0, 0))
{ //got groups, get the one selected in combo
- TCHAR* caGroup = (TCHAR*)_alloca((SendMessageT(hGroupsCombo, CB_GETLBTEXTLEN, curs, 0) + 1) * sizeof(WCHAR));
- SendMessageT(hGroupsCombo, CB_GETLBTEXT, curs, (LPARAM)caGroup);
- nGroupId = SendMessageT(hGroupsCombo, CB_GETITEMDATA, curs, 0);
+ TCHAR* caGroup = (TCHAR*)_alloca((SendMessage(hGroupsCombo, CB_GETLBTEXTLEN, curs, 0) + 1) * sizeof(TCHAR));
+ SendMessage(hGroupsCombo, CB_GETLBTEXT, curs, (LPARAM)caGroup);
+ nGroupId = SendMessage(hGroupsCombo, CB_GETITEMDATA, curs, 0);
}
for (int i = 0; i < ListView_GetItemCount(hLV); i++)
- if (ListView_GetCheckState(hLV, i))
- { // found checked contact item, add it
- caUIN = ListView_GetItemTextEx(hLV, i, 0);
+ if (ListView_GetCheckState(hLV, i)) {
+ // found checked contact item, add it
+ TCHAR *caUIN = ListView_GetItemTextEx(hLV, i, 0);
for (int j = 0; j < wndData->cbReceived; j++) // determine item index in packet
- if (!strcmpnull(wndData->maReceived[j]->mcaUIN, caUIN))
- {
- char* szProto =GetContactProto(wndData->mhContact);
- HANDLE hContact = (HANDLE)CallProtoService(szProto, PS_ADDTOLISTBYEVENT, MAKEWPARAM(0, j), (LPARAM)wndData->mhDbEvent);
- if (hContact && caGroup)
- { // use newest group API if available
+ if (!lstrcmp(wndData->maReceived[j]->mcaUIN, caUIN)) {
+ char *szProto =GetContactProto(wndData->mhContact);
+ hContact = (HANDLE)CallProtoService(szProto, PS_ADDTOLISTBYEVENT, MAKEWPARAM(0, j), (LPARAM)wndData->mhDbEvent);
+ if (hContact && caGroup) {
+ // use newest group API if available
if (ServiceExists(MS_CLIST_CONTACTCHANGEGROUP))
CallService(MS_CLIST_CONTACTCHANGEGROUP, (WPARAM)hContact, (LPARAM)nGroupId);
else
- DBWriteContactSettingStringT(hContact, "CList", "Group", caGroup);
+ db_set_ts(hContact, "CList", "Group", caGroup);
}
break;
}
- SAFE_FREE((void**)&caUIN);
+ mir_free(caUIN);
} // move to next item
break;
}
@@ -336,22 +338,21 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
HWND hLV = GetDlgItem(hwndDlg, IDC_CONTACTS);
for (int i = 0; i < ListView_GetItemCount(hLV); i++)
if (ListView_GetItemState(hLV, i, LVIS_SELECTED)) {
- HANDLE hContact = CreateTemporaryContactForItem(hwndDlg, wndData, i);
+ hContact = CreateTemporaryContactForItem(hwndDlg, wndData, i);
if (hContact)
CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)hContact, 0);
}
- break;
}
+ break;
+
case IDCANCEL:
- {
- SendMessageT(hwndDlg, WM_CLOSE, 0, 0);
- break;
- }
+ SendMessage(hwndDlg, WM_CLOSE, 0, 0);
+ break;
+
case IDC_ENABLEGROUPS:
- {
- EnableGroupCombo(hwndDlg);
- break;
- }
+ EnableGroupCombo(hwndDlg);
+ break;
+
case IDC_GROUPS:
// rebuild group list on popup
if (HIWORD(wParam) == CBN_DROPDOWN)
@@ -359,26 +360,23 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
break;
case ID_POPUP_ADDUSER:
- {
- HANDLE hContact = CreateTemporaryContactForItem(hwndDlg, wndData, wndData->iPopupItem);
- if (hContact)
- DialogAddContactExecute(hwndDlg, hContact);
- break;
- }
+ hContact = CreateTemporaryContactForItem(hwndDlg, wndData, wndData->iPopupItem);
+ if (hContact)
+ DialogAddContactExecute(hwndDlg, hContact);
+ break;
+
case ID_POPUP_USERDETAILS:
- {
- HANDLE hContact = CreateTemporaryContactForItem(hwndDlg, wndData, wndData->iPopupItem);
- if (hContact)
- CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)hContact, 0 );
- break;
- }
+ hContact = CreateTemporaryContactForItem(hwndDlg, wndData, wndData->iPopupItem);
+ if (hContact)
+ CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)hContact, 0 );
+ break;
+
case ID_POPUP_SENDMESSAGE:
- {
- HANDLE hContact = CreateTemporaryContactForItem(hwndDlg, wndData, wndData->iPopupItem);
- if (hContact)
- CallService(MS_MSG_SENDMESSAGE, (WPARAM)hContact, 0);
- break;
- }
+ hContact = CreateTemporaryContactForItem(hwndDlg, wndData, wndData->iPopupItem);
+ if (hContact)
+ CallService(MS_MSG_SENDMESSAGE, (WPARAM)hContact, 0);
+ break;
+
case IDC_USERMENU:
{
RECT rc;
@@ -386,8 +384,9 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
GetWindowRect(GetDlgItem(hwndDlg,IDC_USERMENU), &rc);
TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL);
DestroyMenu(hMenu);
- break;
}
+ break;
+
case IDC_HISTORY:
CallService(MS_HISTORY_SHOWCONTACTHISTORY,(WPARAM)wndData->mhContact,0);
break;
@@ -400,8 +399,9 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
DialogAddContactExecute(hwndDlg, wndData->mhContact);
break;
}
- break;
}
+ break;
+
case WM_CONTEXTMENU:
{
HWND hLV = GetDlgItem(hwndDlg, IDC_CONTACTS);
@@ -418,48 +418,50 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
if (ci==-1) break; // mouse is not over any item
wndData->iPopupItem = ci;
TrackPopupMenu(GetSubMenu(wndData->mhPopup, 0), TPM_LEFTALIGN|TPM_TOPALIGN, LOWORD(lParam), HIWORD(lParam), 0, hwndDlg, NULL);
- break;
}
+ break;
+
case HM_EVENTSENT:
{
- ACKDATA *ack=(ACKDATA*)lParam;
- if (ack->type!=ACKTYPE_SEARCH) break; // not search ack, go away
- if (ack->hProcess!=wndData->rhSearch) break; //not our search, go away
- if (ack->result==ACKRESULT_DATA)
- {
+ ACKDATA *ack = (ACKDATA*)lParam;
+ if (ack->type != ACKTYPE_SEARCH) break; // not search ack, go away
+ if (ack->hProcess != wndData->rhSearch) break; //not our search, go away
+ if (ack->result == ACKRESULT_DATA) {
HWND hLV = GetDlgItem(hwndDlg, IDC_CONTACTS);
- PROTOSEARCHRESULT* psr = (PROTOSEARCHRESULT*)ack->lParam;
+ PROTOSEARCHRESULT *psr = (PROTOSEARCHRESULT*)ack->lParam;
LVFINDINFO fi;
fi.flags = LVFI_STRING;
fi.psz = wndData->haUin;
int iLPos = ListView_FindItem(hLV, -1, &fi);
- if (iLPos==-1) iLPos=0;
- // ListView_SetItemText(hLV, iLPos, 0, psr->email); // not sent by ICQ, and currently unsupported either
- if (strcmpnull(psr->nick, "") && psr->nick) ListView_SetItemText(hLV, iLPos, 1, psr->nick);
+ if (iLPos == -1) iLPos = 0;
+ if (lstrcmp(psr->nick, _T("")) && psr->nick)
+ ListView_SetItemText(hLV, iLPos, 1, psr->nick);
ListView_SetItemText(hLV, iLPos, 2, psr->firstName);
ListView_SetItemText(hLV, iLPos, 3, psr->lastName);
break;
}
- SAFE_FREE((void**)&wndData->haUin);
- break;
+ mir_free(wndData->haUin);
}
+ break;
+
case WM_CLOSE: // user closed window, so destroy it
WindowList_Remove(ghRecvWindowList, hwndDlg);
DestroyWindow(hwndDlg);
break;
case WM_DESTROY: // last message received by this dialog, cleanup
+ db_event_markRead(wndData->mhContact, wndData->mhDbEvent);
+ Utils_SaveWindowPosition(hwndDlg, NULL, MODULENAME, "");
+ ImageList_Destroy(wndData->mhListIcon);
+ UnhookEvent(wndData->hHook);
+ DestroyMenu(wndData->mhPopup);
{
- db_event_markRead(wndData->mhContact, wndData->mhDbEvent);
- Utils_SaveWindowPosition(hwndDlg, NULL, MODULENAME, "");
- ImageList_Destroy(wndData->mhListIcon);
- UnhookEvent(wndData->hHook);
- DestroyMenu(wndData->mhPopup);
- for (int i=0; i < SIZEOF(wndData->hIcons); i++)
+ for (int i = 0; i < SIZEOF(wndData->hIcons); i++)
DestroyIcon(wndData->hIcons[i]);
- delete wndData; // automatically calls destructor
- break;
}
+ delete wndData; // automatically calls destructor
+ break;
+
case WM_MEASUREITEM:
return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam);
@@ -468,28 +470,27 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara
return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam);
case WM_SIZE:
- { // make the dlg resizeable
- UTILRESIZEDIALOG urd = {0};
-
- if (IsIconic(hwndDlg)) break;
- urd.cbSize = sizeof(urd);
+ if (!IsIconic(hwndDlg)) {
+ // make the dlg resizeable
+ UTILRESIZEDIALOG urd = { sizeof(urd) };
urd.hInstance = hInst;
urd.hwndDlg = hwndDlg;
- urd.lParam = 0; // user-defined
urd.lpTemplate = MAKEINTRESOURCEA(IDD_RECEIVE);
urd.pfnResizer = RecvDlg_Resize;
CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM) & urd);
- break;
}
+ break;
+
case WM_GETMINMAXINFO:
{
MINMAXINFO* mmi=(MINMAXINFO*)lParam;
mmi->ptMinTrackSize.x = 480+2*GetSystemMetrics(SM_CXSIZEFRAME);
mmi->ptMinTrackSize.y = 130+2*GetSystemMetrics(SM_CYSIZEFRAME);
- break;
}
+ break;
+
case DM_UPDATETITLE:
- UpdateDialogTitle(hwndDlg, wndData?wndData->mhContact:NULL, "Contacts from");
+ UpdateDialogTitle(hwndDlg, wndData ? wndData->mhContact : NULL, LPGENT("Contacts from"));
if (wndData)
UpdateDialogAddButton(hwndDlg, wndData->mhContact);
break;
diff --git a/plugins/ContactsPlus/src/receive.h b/plugins/ContactsPlus/src/receive.h
index fe35d94be6..dce1b023ac 100644
--- a/plugins/ContactsPlus/src/receive.h
+++ b/plugins/ContactsPlus/src/receive.h
@@ -35,27 +35,29 @@
#define IDI_DOWNARROW 264
struct TReceivedItem {
- char* mcaUIN;
- TCHAR* mcaNick;
- ~TReceivedItem() { SAFE_FREE((void**)&mcaUIN); SAFE_FREE((void**)&mcaNick); }
- TReceivedItem() { mcaUIN = NULL; mcaNick = NULL; }
+ TCHAR* mcaUIN;
+ TCHAR* mcaNick;
+ ~TReceivedItem() { mir_free(mcaUIN); mir_free(mcaNick); }
+ TReceivedItem() { mcaUIN = NULL; mcaNick = NULL; }
};
-struct TRecvContactsData {
- HANDLE mhDbEvent; // handle to recv DB event
- HANDLE mhContact; // from whom we received this
- HIMAGELIST mhListIcon;// icons for listview
- HMENU mhPopup; // popup menu for listview
- HANDLE hHook; // hook to event
- HANDLE rhSearch; // handle to uin-search
- char* haUin;
- int iPopupItem;
- TReceivedItem** maReceived;// received contacts
- int cbReceived;
- TReceivedItem* AddReceivedItem();
- HICON hIcons[4]; // icons for dialog
- TRecvContactsData(HANDLE contact) { mhContact = contact; hHook = NULL; cbReceived = 0; maReceived = NULL; haUin = NULL; };
- ~TRecvContactsData() { if (cbReceived) { for(int i=0;i<cbReceived;i++) delete maReceived[i]; SAFE_FREE((void**)&maReceived); SAFE_FREE((void**)&haUin); }; };
+struct TRecvContactsData
+{
+ TRecvContactsData(HANDLE contact);
+ ~TRecvContactsData();
+
+ HANDLE mhDbEvent; // handle to recv DB event
+ HANDLE mhContact; // from whom we received this
+ HIMAGELIST mhListIcon;// icons for listview
+ HMENU mhPopup; // popup menu for listview
+ HANDLE hHook; // hook to event
+ HANDLE rhSearch; // handle to uin-search
+ TCHAR* haUin;
+ int iPopupItem;
+ TReceivedItem** maReceived;// received contacts
+ int cbReceived;
+ TReceivedItem* AddReceivedItem();
+ HICON hIcons[4]; // icons for dialog
};
extern HANDLE ghRecvWindowList;
diff --git a/plugins/ContactsPlus/src/send.cpp b/plugins/ContactsPlus/src/send.cpp
index 7c3677d040..4ee9b17b91 100644
--- a/plugins/ContactsPlus/src/send.cpp
+++ b/plugins/ContactsPlus/src/send.cpp
@@ -26,172 +26,165 @@
/* TSendProcessList */
-void TSendProcessList::Add(HANDLE hProcc) {
- EnterCriticalSection(&lock);
- Items=(HANDLE*)realloc(Items, (Count+1)*sizeof(HANDLE));
- Items[Count]=hProcc;
- Count++;
- LeaveCriticalSection(&lock);
+TSendProcessList::TSendProcessList()
+{
+ InitializeCriticalSection(&lock);
+ Count = 0;
+ Items = NULL;
}
-
-void TSendProcessList::Remove(HANDLE hProcc) {
- EnterCriticalSection(&lock);
- for (int i=0; i<Count; i++)
- if (Items[i]==hProcc) {
- memmove(Items+i, Items+i+1, (Count-i-1)*sizeof(HANDLE));
- Count--;
- break;
- }
- LeaveCriticalSection(&lock);
+TSendProcessList::~TSendProcessList()
+{
+ mir_free(Items);
+ DeleteCriticalSection(&lock);
}
-
-TSendProcessList::TSendProcessList() {
- InitializeCriticalSection(&lock);
- Count = 0;
- Items = NULL;
+void TSendProcessList::Add(HANDLE hProcc)
+{
+ mir_cslock lck(lock);
+ Items = (HANDLE*)mir_realloc(Items, (Count + 1)*sizeof(HANDLE));
+ Items[Count] = hProcc;
+ Count++;
}
-
-TSendProcessList::~TSendProcessList() {
- if (Count)
- SAFE_FREE((void**)&Items);
- DeleteCriticalSection(&lock);
+void TSendProcessList::Remove(HANDLE hProcc)
+{
+ mir_cslock lck(lock);
+ for (int i = 0; i < Count; i++)
+ if (Items[i] == hProcc) {
+ memmove(Items + i, Items + i + 1, (Count - i - 1)*sizeof(HANDLE));
+ Count--;
+ break;
+ }
}
-
/* TSendContactsData */
-TSendContactsData::TSendContactsData(HANDLE contact): uacklist() {
- hContact = contact;
- hHook = NULL;
- hError = NULL;
- aContacts = NULL;
- nContacts = 0;
+TSendContactsData::TSendContactsData(HANDLE contact) : uacklist()
+{
+ hContact = contact;
+ hHook = NULL;
+ hError = NULL;
+ aContacts = NULL;
+ nContacts = 0;
}
-
-TSendContactsData::~TSendContactsData() {
- ClearContacts();
- UnhookProtoAck();
+TSendContactsData::~TSendContactsData()
+{
+ ClearContacts();
+ UnhookProtoAck();
}
-
-void TSendContactsData::HookProtoAck(HWND hwndDlg) {
- if (!hHook)
- hHook = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_EVENTSENT);
-};
+void TSendContactsData::HookProtoAck(HWND hwndDlg)
+{
+ if (!hHook)
+ hHook = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_EVENTSENT);
+}
-void TSendContactsData::UnhookProtoAck() {
- if (hHook)
- {
- UnhookEvent(hHook);
- hHook=NULL;
- };
+void TSendContactsData::UnhookProtoAck()
+{
+ if (hHook) {
+ UnhookEvent(hHook);
+ hHook = NULL;
+ }
}
+void TSendContactsData::ShowErrorDlg(HWND hwndDlg, char* szMsg, bool bAllowRetry)
+{
+ ShowWindow(hwndDlg, SW_SHOWNORMAL);
+ EnableWindow(hwndDlg, FALSE);
+ if (!hError) {
+ hError = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MSGSENDERROR), hwndDlg, ErrorDlgProc, (LPARAM)(LPTSTR)_A2T(szMsg));
+ if (!bAllowRetry)
+ EnableDlgItem(hError, IDOK, FALSE); // do not allow again - fatal, could not be better
+ }
+}
-void TSendContactsData::ShowErrorDlg(HWND hwndDlg, char* szMsg, bool bAllowRetry) {
- ShowWindow(hwndDlg, SW_SHOWNORMAL);
- EnableWindow(hwndDlg, FALSE);
- if (!hError)
- {
- hError = CreateDialogParamT(hInst, MAKEINTRESOURCEA(IDD_MSGSENDERROR), hwndDlg, ErrorDlgProc, (LPARAM)szMsg);
- if (!bAllowRetry)
- EnableDlgItem(hError, IDOK, FALSE); // do not allow again - fatal, could not be better
- }
+void TSendContactsData::ClearContacts()
+{
+ mir_free(aContacts);
+ nContacts = 0;
}
+void TSendContactsData::AddContact(HANDLE hContact)
+{
+ aContacts = (HANDLE*)mir_realloc(aContacts, (nContacts + 1)*sizeof(HANDLE));
+ aContacts[nContacts] = hContact;
+ nContacts++;
+}
-void TSendContactsData::ClearContacts() {
- if (nContacts)
- SAFE_FREE((void**)&aContacts);
- nContacts=0;
+int TSendContactsData::SendContactsPacket(HWND hwndDlg, HANDLE *phContacts, int nContacts)
+{
+ HANDLE hProcc = (HANDLE)CallContactService(hContact, PSS_CONTACTS, MAKEWPARAM(0, nContacts), (LPARAM)phContacts);
+ if (!hProcc) {
+ // on trivial error - do not close dialog
+ ShowErrorDlg(hwndDlg, "Contacts transfer failed!", FALSE);
+ return FALSE; // Failure
+ }
+
+ TAckData *ackData = gaAckData.Add(hProcc, new TAckData(hContact));
+ uacklist.Add(hProcc);
+ ackData->nContacts = nContacts;
+ ackData->aContacts = (HANDLE*)mir_alloc(nContacts*sizeof(HANDLE));
+ memmove(ackData->aContacts, phContacts, nContacts*sizeof(HANDLE)); // copy the array of hContact for ack array
+ EnableDlgItem(hwndDlg, IDOK, FALSE);
+ EnableDlgItem(hwndDlg, IDC_LIST, FALSE);
+ return TRUE; // Success
}
+int TSendContactsData::SendContacts(HWND hwndDlg)
+{
+ char *szProto = GetContactProto(hContact);
+ int nMaxContacts = CallProtoService(szProto, PS_GETCAPS, PFLAG_MAXCONTACTSPERPACKET, (LPARAM)hContact);
-void TSendContactsData::AddContact(HANDLE hContact) {
- aContacts = (HANDLE*)realloc(aContacts, (nContacts+1)*sizeof(HANDLE));
- aContacts[nContacts] = hContact;
- nContacts++;
-}
+ if (!nMaxContacts) {
+ ShowErrorDlg(hwndDlg, "The selected contact does not support receiving contacts.", FALSE);
+ return FALSE;
+ }
+ // hook event - we want to receive protocol acknowledgements
+ HookProtoAck(hwndDlg);
-int TSendContactsData::SendContactsPacket(HWND hwndDlg, HANDLE *phContacts, int nContacts) {
- HANDLE hProcc = (HANDLE)CallContactService(hContact, PSS_CONTACTS, MAKEWPARAM(0, nContacts), (LPARAM)phContacts);
- if (!hProcc)
- { // on trivial error - do not close dialog
- ShowErrorDlg(hwndDlg, "Contacts transfer failed!", FALSE);
- return FALSE; // Failure
- }
- TAckData* ackData = gaAckData.Add(hProcc, new TAckData(hContact));
- uacklist.Add(hProcc);
- ackData->nContacts = nContacts;
- ackData->aContacts = (HANDLE*)malloc(nContacts*sizeof(HANDLE));
- memmove(ackData->aContacts, phContacts, nContacts*sizeof(HANDLE)); // copy the array of hContact for ack array
- EnableDlgItem(hwndDlg, IDOK, FALSE);
- EnableDlgItem(hwndDlg, IDC_LIST, FALSE);
-
- return TRUE; // Success
-}
+ // send in packets, each of nMaxContacts contacts
+ for (int j = 0; j < nContacts / nMaxContacts; j++)
+ if (!SendContactsPacket(hwndDlg, aContacts + j*nMaxContacts, nMaxContacts))
+ return FALSE;
+ if (nContacts%nMaxContacts != 0)
+ if (!SendContactsPacket(hwndDlg, aContacts + nContacts / nMaxContacts*nMaxContacts, nContacts%nMaxContacts))
+ return FALSE;
-int TSendContactsData::SendContacts(HWND hwndDlg) {
- char* szProto =GetContactProto(hContact);
- int nMaxContacts = CallProtoService(szProto, PS_GETCAPS, PFLAG_MAXCONTACTSPERPACKET, (LPARAM)hContact);
-
- if (!nMaxContacts) {
- ShowErrorDlg(hwndDlg, "The selected contact does not support receiving contacts.", FALSE);
- return FALSE;
- }
- // hook event - we want to receive protocol acknowledgements
- HookProtoAck(hwndDlg);
-
- for (int j = 0; j < nContacts / nMaxContacts; j++ )
- { // send in packets, each of nMaxContacts contacts
- if (!SendContactsPacket(hwndDlg, aContacts + j*nMaxContacts, nMaxContacts))
- return FALSE;
- }
- if (nContacts%nMaxContacts!=0)
- {
- if (!SendContactsPacket(hwndDlg, aContacts + nContacts/nMaxContacts*nMaxContacts, nContacts%nMaxContacts))
- return FALSE;
- }
- return TRUE;
+ return TRUE;
}
-
/* Send Dialog Implementation */
static void ResetListOptions(HWND hwndList)
{
- COLORREF bgColour,fgColour;
-
- SendMessageT(hwndList,CLM_SETBKBITMAP,0,(LPARAM)(HBITMAP)NULL);
- bgColour=GetSysColor(COLOR_WINDOW);
- SendMessageT(hwndList,CLM_SETBKCOLOR,bgColour,0);
- SendMessageT(hwndList,CLM_SETGREYOUTFLAGS,0,0);
- SendMessageT(hwndList,CLM_SETLEFTMARGIN,4,0);
- SendMessageT(hwndList,CLM_SETINDENT,10,0);
- for(int i=0; i<=FONTID_MAX; i++)
- {
- fgColour=(COLORREF)SendMessageT(hwndList,CLM_GETTEXTCOLOR,i,0);
- if(abs(GetRValue(fgColour)-GetRValue(bgColour))<10 &&
- abs(GetGValue(fgColour)-GetGValue(bgColour))<10 &&
- abs(GetBValue(fgColour)-GetBValue(bgColour))<10)
- SendMessageT(hwndList,CLM_SETTEXTCOLOR,i,GetSysColor(COLOR_WINDOWTEXT));
- }
+ COLORREF bgColour, fgColour;
+
+ SendMessage(hwndList, CLM_SETBKBITMAP, 0, (LPARAM)(HBITMAP)NULL);
+ bgColour = GetSysColor(COLOR_WINDOW);
+ SendMessage(hwndList, CLM_SETBKCOLOR, bgColour, 0);
+ SendMessage(hwndList, CLM_SETGREYOUTFLAGS, 0, 0);
+ SendMessage(hwndList, CLM_SETLEFTMARGIN, 4, 0);
+ SendMessage(hwndList, CLM_SETINDENT, 10, 0);
+ for (int i = 0; i <= FONTID_MAX; i++) {
+ fgColour = (COLORREF)SendMessage(hwndList, CLM_GETTEXTCOLOR, i, 0);
+ if (abs(GetRValue(fgColour) - GetRValue(bgColour)) < 10 &&
+ abs(GetGValue(fgColour) - GetGValue(bgColour)) < 10 &&
+ abs(GetBValue(fgColour) - GetBValue(bgColour)) < 10)
+ SendMessage(hwndList, CLM_SETTEXTCOLOR, i, GetSysColor(COLOR_WINDOWTEXT));
+ }
}
-
static HANDLE FindNextClistContact(HWND hList, HANDLE hContact, HANDLE *phItem)
{
HANDLE hNextContact = db_find_next(hContact);
HANDLE hNextItem = NULL;
-
- while (hNextContact && !(hNextItem = (HANDLE)SendMessageT(hList, CLM_FINDCONTACT, (WPARAM)hNextContact,0)))
+
+ while (hNextContact && !(hNextItem = (HANDLE)SendMessage(hList, CLM_FINDCONTACT, (WPARAM)hNextContact, 0)))
hNextContact = db_find_next(hNextContact);
if (phItem)
@@ -204,11 +197,11 @@ static HANDLE FindNextClistContact(HWND hList, HANDLE hContact, HANDLE *phItem)
static HANDLE FindFirstClistContact(HWND hList, HANDLE *phItem)
{
HANDLE hContact = db_find_first();
- HANDLE hItem = (HANDLE)SendMessageT(hList, CLM_FINDCONTACT, (WPARAM)hContact, 0);
+ HANDLE hItem = (HANDLE)SendMessage(hList, CLM_FINDCONTACT, (WPARAM)hContact, 0);
if (hContact && !hItem)
return FindNextClistContact(hList, hContact, phItem);
-
+
if (phItem)
*phItem = hItem;
@@ -220,317 +213,289 @@ bool binListEvent = FALSE;
static void SetAllContactChecks(HWND hwndList, HANDLE hReceiver) // doubtful name
{
- HANDLE hContact, hItem;
-
- if (binListEvent) return;
- binListEvent = TRUE;
- char* szProto =GetContactProto(hReceiver);
- if (szProto == NULL) return;
-
- if (CallService(MS_CLUI_GETCAPS, 0, 0) & CLUIF_HIDEEMPTYGROUPS && db_get_b(NULL, "CList", "HideEmptyGroups", SETTING_USEGROUPS_DEFAULT))
- SendMessageT(hwndList, CLM_SETHIDEEMPTYGROUPS, (WPARAM) TRUE, 0);
- else
- SendMessageT(hwndList, CLM_SETHIDEEMPTYGROUPS, (WPARAM) FALSE, 0);
-
- hContact = FindFirstClistContact(hwndList, &hItem);
- while (hContact)
- {
- char* szProto2 =GetContactProto(hContact);
-
- if (strcmpnull(szProto, szProto2))
- { // different protocols or protocol undefined, remove contact, useless anyway
- SendMessageT(hwndList, CLM_DELETEITEM, (WPARAM)hItem, 0);
- }
- else // otherwise uncheck
- SendMessageT(hwndList, CLM_SETCHECKMARK,(WPARAM)hItem, 0);
-
- hContact = FindNextClistContact(hwndList, hContact, &hItem);
- }
-
- binListEvent = FALSE;
-}
+ if (binListEvent)
+ return;
+
+ binListEvent = TRUE;
+ char *szProto = GetContactProto(hReceiver);
+ if (szProto == NULL)
+ return;
+
+ if (CallService(MS_CLUI_GETCAPS, 0, 0) & CLUIF_HIDEEMPTYGROUPS && db_get_b(NULL, "CList", "HideEmptyGroups", SETTING_USEGROUPS_DEFAULT))
+ SendMessage(hwndList, CLM_SETHIDEEMPTYGROUPS, (WPARAM)TRUE, 0);
+ else
+ SendMessage(hwndList, CLM_SETHIDEEMPTYGROUPS, (WPARAM)FALSE, 0);
+ HANDLE hItem, hContact = FindFirstClistContact(hwndList, &hItem);
+ while (hContact) {
+ char* szProto2 = GetContactProto(hContact);
+
+ // different protocols or protocol undefined, remove contact, useless anyway
+ if (strcmpnull(szProto, szProto2))
+ SendMessage(hwndList, CLM_DELETEITEM, (WPARAM)hItem, 0);
+ else // otherwise uncheck
+ SendMessage(hwndList, CLM_SETCHECKMARK, (WPARAM)hItem, 0);
+
+ hContact = FindNextClistContact(hwndList, hContact, &hItem);
+ }
+
+ binListEvent = FALSE;
+}
-INT_PTR CALLBACK SendDlgProc( HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+INT_PTR CALLBACK SendDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- TSendContactsData* wndData = (TSendContactsData*)GetWindowLongPtr(hwndDlg, DWLP_USER);
-
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- TranslateDialogDefault(hwndDlg);
- SendMessageT(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_CONTACTS)));
- ResetListOptions(GetDlgItem(hwndDlg,IDC_LIST));
- SetAllContactChecks(GetDlgItem(hwndDlg,IDC_LIST), (HANDLE)lParam);
- WindowList_Add(ghSendWindowList, hwndDlg, (HANDLE)lParam);
- wndData = new TSendContactsData((HANDLE)lParam);
- SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG)wndData);
- // new dlg init
- wndData->hIcons[0] = InitMButton(hwndDlg, IDC_ADD, MAKEINTRESOURCEA(IDI_ADDCONTACT), LPGEN("Add Contact Permanently to List"));
- wndData->hIcons[1] = InitMButton(hwndDlg, IDC_DETAILS, MAKEINTRESOURCEA(IDI_USERDETAILS), LPGEN("View User's Details"));
- wndData->hIcons[2] = InitMButton(hwndDlg, IDC_HISTORY, MAKEINTRESOURCEA(IDI_HISTORY), LPGEN("View User's History"));
- wndData->hIcons[3] = InitMButton(hwndDlg, IDC_USERMENU, MAKEINTRESOURCEA(IDI_DOWNARROW), LPGEN("User Menu"));
-
- SendMessageT(hwndDlg,DM_UPDATETITLE,0,0);
- // new dialog init done
- return TRUE;
- }
-
- case WM_SETFOCUS:
- SetFocus(GetDlgItem(hwndDlg,IDC_LIST));
- break;
-
- case WM_NOTIFY:
- if (((LPNMHDR)lParam)->idFrom == IDC_LIST)
- {
- switch (((LPNMHDR)lParam)->code)
- {
- case CLN_NEWCONTACT:
- case CLN_LISTREBUILT: // rebuild list
- if (wndData) SetAllContactChecks(GetDlgItem(hwndDlg,IDC_LIST), wndData->hContact);
- case CLN_OPTIONSCHANGED:
- ResetListOptions(GetDlgItem(hwndDlg,IDC_LIST));
- break;
- }
- }
- break;
-
- case WM_TIMER:
- if (wParam == TIMERID_MSGSEND)
- {
- KillTimer(hwndDlg,wParam);
- wndData->ShowErrorDlg(hwndDlg, "The contacts send timed out.", TRUE);
- }
- break;
-
- case DM_ERRORDECIDED:
- {
- EnableWindow(hwndDlg,TRUE);
- wndData->hError = NULL;
- switch(wParam)
- {
- case MSGERROR_CANCEL:
- {
- wndData->UnhookProtoAck();
- if (wndData->uacklist.Count)
- {
- for (int i=0; i<wndData->uacklist.Count; i++)
- {
- delete gaAckData.Remove(wndData->uacklist.Items[i]); // remove our ackdata & release structure
- }
- SAFE_FREE((void**)&wndData->uacklist.Items);
- wndData->uacklist.Count = 0;
- }
- EnableDlgItem(hwndDlg,IDOK,TRUE);
- EnableDlgItem(hwndDlg,IDC_LIST,TRUE);
- ShowWindow(hwndDlg,SW_SHOWNORMAL);
- SetFocus(GetDlgItem(hwndDlg,IDC_LIST));
- break;
- }
- case MSGERROR_DONE:
- // contacts were delivered succesfully after timeout
- SetFocus(GetDlgItem(hwndDlg,IDC_LIST));
- wndData->UnhookProtoAck();
- break;
-
- case MSGERROR_RETRY:// resend timeouted packets
-
- for (int i=0; i<wndData->uacklist.Count; i++)
- {
- TAckData* lla = gaAckData.Remove(wndData->uacklist.Items[i]);
- HANDLE hProcc = (HANDLE)CallContactService(wndData->hContact, PSS_CONTACTS, MAKEWPARAM(0, lla->nContacts), (LPARAM)lla->aContacts);
-
- if (!hProcc) // if fatal do not include
- {
- wndData->uacklist.Remove(wndData->uacklist.Items[i]);
- delete lla; // release the structure
- continue;
- }
- else
- { // update process code
- wndData->uacklist.Items[i] = hProcc;
- gaAckData.Add(hProcc, lla);
- }
- }// collect TAckData for our window, resend
- break;
- }
- break;
- }
-
- case WM_COMMAND:
- {
- if (!lParam && CallService(MS_CLIST_MENUPROCESSCOMMAND,MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)wndData->hContact))
- break;
-
- switch(LOWORD(wParam))
- {
- case IDOK:
- {
- if (!IsWindowEnabled(GetDlgItem(hwndDlg,IDOK))) break;
- HANDLE hContact, hItem;
- wndData->ClearContacts(); // do not include contacts twice
-
- HWND hList = GetDlgItem(hwndDlg, IDC_LIST);
- hContact = FindFirstClistContact(hList, &hItem);
- while (hContact)
- {
- if (SendMessageT(hList, CLM_GETCHECKMARK, (WPARAM)hItem, 0))
- { // build list of contacts to send
- wndData->AddContact(hContact);
- }
- hContact = FindNextClistContact(hList, hContact, &hItem);
- }
- /* send contacts */
- if (!wndData->SendContacts(hwndDlg))
- break;
-
- SetTimer(hwndDlg,TIMERID_MSGSEND,db_get_dw(NULL,"SRMsg","MessageTimeout",TIMEOUT_MSGSEND),NULL);
-
- break;
- }
- case IDCANCEL:
- {
- DestroyWindow(hwndDlg);
- break;
- }
- case ID_SELECTALL:
- { // select all contacts
- HANDLE hContact, hItem;
- HWND hwndList = GetDlgItem(hwndDlg, IDC_LIST);
-
- hContact = FindFirstClistContact(hwndList, &hItem);
- while (hContact) {
- SendMessageT(hwndList,CLM_SETCHECKMARK,(WPARAM)hItem, 1);
- hContact = FindNextClistContact(hwndList, hContact, &hItem);
- };
- break;
- }
- case IDC_USERMENU:
- {
- RECT rc;
- HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT,(WPARAM)wndData->hContact,0);
-
- GetWindowRect(GetDlgItem(hwndDlg,IDC_USERMENU),&rc);
- TrackPopupMenu(hMenu,0,rc.left,rc.bottom,0,hwndDlg,NULL);
- DestroyMenu(hMenu);
- break;
- }
- case IDC_HISTORY:
- CallService(MS_HISTORY_SHOWCONTACTHISTORY,(WPARAM)wndData->hContact,0);
- break;
-
- case IDC_DETAILS:
- CallService(MS_USERINFO_SHOWDIALOG,(WPARAM)wndData->hContact,0);
- break;
-
- case IDC_ADD:
- DialogAddContactExecute(hwndDlg, wndData->hContact);
- break;
- }
- break;
- }
- case HM_EVENTSENT:
- {
- ACKDATA *ack=(ACKDATA*)lParam;
- DBEVENTINFO dbei={0};
-
- if (ack->type != ACKTYPE_CONTACTS) break;
-
- TAckData* ackData = gaAckData.Get(ack->hProcess);
-
- if (ackData == NULL) break; // on unknown hprocc go away
-
- if (ackData->hContact != ack->hContact) break; // this is not ours, strange
-
- if (ack->result == ACKRESULT_FAILED)
- { // some process failed, show error dialog
- KillTimer(hwndDlg, TIMERID_MSGSEND);
- wndData->ShowErrorDlg(hwndDlg, (char *)ack->lParam, TRUE);
- // ackData get used in error handling, released there
- break;
- }
-
- dbei.cbSize = sizeof(dbei);
- dbei.szModule =GetContactProto(ackData->hContact);
- dbei.eventType = EVENTTYPE_CONTACTS;
- dbei.flags = DBEF_SENT| DBEF_UTF;
- dbei.timestamp = time(NULL);
- //make blob
- TCTSend* maSend = (TCTSend*)_alloca(ackData->nContacts*sizeof(TCTSend));
- ZeroMemory(maSend, ackData->nContacts*sizeof(TCTSend));
- dbei.cbBlob=0;
- char* pBlob;
- int i;
- for (i=0; i<ackData->nContacts; i++)
- { // prepare data & count size
- maSend[i].mcaNick = make_utf8_string((WCHAR*)GetContactDisplayNameT(ackData->aContacts[i]));
- maSend[i].mcaUIN = GetContactUID(ackData->aContacts[i], FALSE);
- dbei.cbBlob += (DWORD)strlennull(maSend[i].mcaUIN) + (DWORD)strlennull((char*)maSend[i].mcaNick) + 2;
- }
- dbei.pBlob = (PBYTE)_alloca(dbei.cbBlob);
- for (i=0, pBlob=(char*)dbei.pBlob; i < ackData->nContacts; i++)
- {
- strcpy(pBlob, (char*)maSend[i].mcaNick);
- pBlob += strlennull(pBlob) + 1;
- strcpy(pBlob, maSend[i].mcaUIN);
- pBlob += strlennull(pBlob) + 1;
- }
- db_event_add(ackData->hContact, &dbei);
- gaAckData.Remove(ack->hProcess); // do not release here, still needed
- wndData->uacklist.Remove(ack->hProcess); // packet confirmed
- for (i=0; i<ackData->nContacts; i++)
- {
- SAFE_FREE((void**)&maSend[i].mcaUIN);
- SAFE_FREE((void**)&maSend[i].mcaNick);
- }
- delete ackData; // all done, release structure
- if (!wndData->uacklist.Count)
- {
- SkinPlaySound("SentContacts");
- KillTimer(hwndDlg, TIMERID_MSGSEND);
-
- if (wndData->hError)
- SendMessageT(wndData->hError, DM_ERRORDECIDED, MSGERROR_DONE, 0);
-
- SendMessageT(hwndDlg, WM_CLOSE, 0, 0); // all packets confirmed, close the dialog
- }
- break;
- }
-
- case WM_CLOSE:
- {
- wndData->UnhookProtoAck();
- DestroyWindow(hwndDlg);
- break;
- }
- case WM_DESTROY:
- {
- int i;
- for (i = 0; i < SIZEOF(wndData->hIcons); i++)
- DestroyIcon(wndData->hIcons[i]);
- WindowList_Remove(ghSendWindowList, hwndDlg);
- delete wndData;
- break;
- }
- case WM_MEASUREITEM:
- return CallService(MS_CLIST_MENUMEASUREITEM,wParam,lParam);
-
- case WM_DRAWITEM:
- {
- DrawProtocolIcon(hwndDlg, lParam, wndData->hContact);
- return CallService(MS_CLIST_MENUDRAWITEM,wParam,lParam);
- }
- case DM_UPDATETITLE:
- {
- UpdateDialogTitle(hwndDlg, wndData?wndData->hContact:NULL, "Send Contacts to");
- if (wndData)
- UpdateDialogAddButton(hwndDlg, wndData->hContact);
- break;
- }
- }
-
- return FALSE;
+ TSendContactsData* wndData = (TSendContactsData*)GetWindowLongPtr(hwndDlg, DWLP_USER);
+
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+ SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_CONTACTS)));
+ ResetListOptions(GetDlgItem(hwndDlg, IDC_LIST));
+ SetAllContactChecks(GetDlgItem(hwndDlg, IDC_LIST), (HANDLE)lParam);
+ WindowList_Add(ghSendWindowList, hwndDlg, (HANDLE)lParam);
+ wndData = new TSendContactsData((HANDLE)lParam);
+ SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG)wndData);
+ // new dlg init
+ wndData->hIcons[0] = InitMButton(hwndDlg, IDC_ADD, MAKEINTRESOURCEA(IDI_ADDCONTACT), LPGEN("Add Contact Permanently to List"));
+ wndData->hIcons[1] = InitMButton(hwndDlg, IDC_DETAILS, MAKEINTRESOURCEA(IDI_USERDETAILS), LPGEN("View User's Details"));
+ wndData->hIcons[2] = InitMButton(hwndDlg, IDC_HISTORY, MAKEINTRESOURCEA(IDI_HISTORY), LPGEN("View User's History"));
+ wndData->hIcons[3] = InitMButton(hwndDlg, IDC_USERMENU, MAKEINTRESOURCEA(IDI_DOWNARROW), LPGEN("User Menu"));
+
+ SendMessage(hwndDlg, DM_UPDATETITLE, 0, 0);
+ // new dialog init done
+ return TRUE;
+
+ case WM_SETFOCUS:
+ SetFocus(GetDlgItem(hwndDlg, IDC_LIST));
+ break;
+
+ case WM_NOTIFY:
+ if (((LPNMHDR)lParam)->idFrom == IDC_LIST) {
+ switch (((LPNMHDR)lParam)->code) {
+ case CLN_NEWCONTACT:
+ case CLN_LISTREBUILT: // rebuild list
+ if (wndData) SetAllContactChecks(GetDlgItem(hwndDlg, IDC_LIST), wndData->hContact);
+ case CLN_OPTIONSCHANGED:
+ ResetListOptions(GetDlgItem(hwndDlg, IDC_LIST));
+ break;
+ }
+ }
+ break;
+
+ case WM_TIMER:
+ if (wParam == TIMERID_MSGSEND) {
+ KillTimer(hwndDlg, wParam);
+ wndData->ShowErrorDlg(hwndDlg, "The contacts send timed out.", TRUE);
+ }
+ break;
+
+ case DM_ERRORDECIDED:
+ EnableWindow(hwndDlg, TRUE);
+ wndData->hError = NULL;
+ switch (wParam) {
+ case MSGERROR_CANCEL:
+ wndData->UnhookProtoAck();
+ if (wndData->uacklist.Count) {
+ for (int i = 0; i < wndData->uacklist.Count; i++)
+ delete gaAckData.Remove(wndData->uacklist.Items[i]); // remove our ackdata & release structure
+
+ mir_free(wndData->uacklist.Items);
+ wndData->uacklist.Items = NULL;
+ wndData->uacklist.Count = 0;
+ }
+ EnableDlgItem(hwndDlg, IDOK, TRUE);
+ EnableDlgItem(hwndDlg, IDC_LIST, TRUE);
+ ShowWindow(hwndDlg, SW_SHOWNORMAL);
+ SetFocus(GetDlgItem(hwndDlg, IDC_LIST));
+ break;
+
+ case MSGERROR_DONE:
+ // contacts were delivered succesfully after timeout
+ SetFocus(GetDlgItem(hwndDlg, IDC_LIST));
+ wndData->UnhookProtoAck();
+ break;
+
+ case MSGERROR_RETRY:// resend timeouted packets
+ for (int i = 0; i < wndData->uacklist.Count; i++) {
+ TAckData *lla = gaAckData.Remove(wndData->uacklist.Items[i]);
+ HANDLE hProcc = (HANDLE)CallContactService(wndData->hContact, PSS_CONTACTS, MAKEWPARAM(0, lla->nContacts), (LPARAM)lla->aContacts);
+
+ if (!hProcc) { // if fatal do not include
+ wndData->uacklist.Remove(wndData->uacklist.Items[i]);
+ delete lla; // release the structure
+ continue;
+ }
+ else {
+ // update process code
+ wndData->uacklist.Items[i] = hProcc;
+ gaAckData.Add(hProcc, lla);
+ }
+ }// collect TAckData for our window, resend
+ break;
+ }
+ break;
+
+ case WM_COMMAND:
+ if (!lParam && CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)wndData->hContact))
+ break;
+
+ switch (LOWORD(wParam)) {
+ case IDOK:
+ if (IsWindowEnabled(GetDlgItem(hwndDlg, IDOK))) {
+ HANDLE hContact, hItem;
+ wndData->ClearContacts(); // do not include contacts twice
+
+ HWND hList = GetDlgItem(hwndDlg, IDC_LIST);
+ hContact = FindFirstClistContact(hList, &hItem);
+ while (hContact)
+ {
+ if (SendMessage(hList, CLM_GETCHECKMARK, (WPARAM)hItem, 0))
+ { // build list of contacts to send
+ wndData->AddContact(hContact);
+ }
+ hContact = FindNextClistContact(hList, hContact, &hItem);
+ }
+ /* send contacts */
+ if (!wndData->SendContacts(hwndDlg))
+ break;
+
+ SetTimer(hwndDlg, TIMERID_MSGSEND, db_get_dw(NULL, "SRMsg", "MessageTimeout", TIMEOUT_MSGSEND), NULL);
+ }
+ break;
+
+ case IDCANCEL:
+ DestroyWindow(hwndDlg);
+ break;
+
+ case ID_SELECTALL:
+ {
+ // select all contacts
+ HWND hwndList = GetDlgItem(hwndDlg, IDC_LIST);
+ HANDLE hItem, hContact = FindFirstClistContact(hwndList, &hItem);
+ while (hContact) {
+ SendMessage(hwndList, CLM_SETCHECKMARK, (WPARAM)hItem, 1);
+ hContact = FindNextClistContact(hwndList, hContact, &hItem);
+ }
+ }
+ break;
+
+ case IDC_USERMENU:
+ {
+ RECT rc;
+ HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)wndData->hContact, 0);
+
+ GetWindowRect(GetDlgItem(hwndDlg, IDC_USERMENU), &rc);
+ TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL);
+ DestroyMenu(hMenu);
+ }
+ break;
+
+ case IDC_HISTORY:
+ CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)wndData->hContact, 0);
+ break;
+
+ case IDC_DETAILS:
+ CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)wndData->hContact, 0);
+ break;
+
+ case IDC_ADD:
+ DialogAddContactExecute(hwndDlg, wndData->hContact);
+ break;
+ }
+ break;
+
+ case HM_EVENTSENT:
+ {
+ ACKDATA *ack = (ACKDATA*)lParam;
+ if (ack->type != ACKTYPE_CONTACTS)
+ break;
+
+ TAckData *ackData = gaAckData.Get(ack->hProcess);
+ if (ackData == NULL)
+ break; // on unknown hprocc go away
+
+ if (ackData->hContact != ack->hContact)
+ break; // this is not ours, strange
+
+ if (ack->result == ACKRESULT_FAILED) {
+ // some process failed, show error dialog
+ KillTimer(hwndDlg, TIMERID_MSGSEND);
+ wndData->ShowErrorDlg(hwndDlg, (char *)ack->lParam, TRUE);
+ // ackData get used in error handling, released there
+ break;
+ }
+
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.szModule = GetContactProto(ackData->hContact);
+ dbei.eventType = EVENTTYPE_CONTACTS;
+ dbei.flags = DBEF_SENT | DBEF_UTF;
+ dbei.timestamp = time(NULL);
+ //make blob
+ TCTSend* maSend = (TCTSend*)_alloca(ackData->nContacts*sizeof(TCTSend));
+ ZeroMemory(maSend, ackData->nContacts*sizeof(TCTSend));
+ dbei.cbBlob = 0;
+ char* pBlob;
+ int i;
+ for (i = 0; i < ackData->nContacts; i++) {
+ // prepare data & count size
+ maSend[i].mcaNick = mir_utf8encodeT(pcli->pfnGetContactDisplayName(ackData->aContacts[i], 0));
+ maSend[i].mcaUIN = mir_utf8encodeT(ptrT(GetContactUID(ackData->aContacts[i])));
+ dbei.cbBlob += (DWORD)strlennull(maSend[i].mcaUIN) + (DWORD)strlennull((char*)maSend[i].mcaNick) + 2;
+ }
+ dbei.pBlob = (PBYTE)_alloca(dbei.cbBlob);
+ for (i = 0, pBlob = (char*)dbei.pBlob; i < ackData->nContacts; i++) {
+ strcpy(pBlob, (char*)maSend[i].mcaNick);
+ pBlob += strlennull(pBlob) + 1;
+ strcpy(pBlob, maSend[i].mcaUIN);
+ pBlob += strlennull(pBlob) + 1;
+ }
+ db_event_add(ackData->hContact, &dbei);
+ gaAckData.Remove(ack->hProcess); // do not release here, still needed
+ wndData->uacklist.Remove(ack->hProcess); // packet confirmed
+ for (i = 0; i < ackData->nContacts; i++) {
+ mir_free(maSend[i].mcaUIN);
+ mir_free(maSend[i].mcaNick);
+ }
+ delete ackData; // all done, release structure
+ if (!wndData->uacklist.Count) {
+ SkinPlaySound("SentContacts");
+ KillTimer(hwndDlg, TIMERID_MSGSEND);
+
+ if (wndData->hError)
+ SendMessage(wndData->hError, DM_ERRORDECIDED, MSGERROR_DONE, 0);
+
+ SendMessage(hwndDlg, WM_CLOSE, 0, 0); // all packets confirmed, close the dialog
+ }
+ }
+ break;
+
+ case WM_MEASUREITEM:
+ return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam);
+
+ case WM_DRAWITEM:
+ DrawProtocolIcon(hwndDlg, lParam, wndData->hContact);
+ return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam);
+
+ case DM_UPDATETITLE:
+ UpdateDialogTitle(hwndDlg, wndData ? wndData->hContact : NULL, TranslateT("Send Contacts to"));
+ if (wndData)
+ UpdateDialogAddButton(hwndDlg, wndData->hContact);
+ break;
+
+ case WM_CLOSE:
+ wndData->UnhookProtoAck();
+ DestroyWindow(hwndDlg);
+ break;
+
+ case WM_DESTROY:
+ for (int i = 0; i < SIZEOF(wndData->hIcons); i++)
+ DestroyIcon(wndData->hIcons[i]);
+ WindowList_Remove(ghSendWindowList, hwndDlg);
+ delete wndData;
+ break;
+ }
+
+ return FALSE;
}
@@ -538,49 +503,43 @@ INT_PTR CALLBACK SendDlgProc( HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar
INT_PTR CALLBACK ErrorDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch(msg)
- {
- case WM_INITDIALOG:
- {
- RECT rc, rcParent;
-
- TranslateDialogDefault(hwndDlg);
-
- if (lParam)
- {
- WCHAR tmp[MAX_PATH];
-
- SetDlgItemTextT(hwndDlg, IDC_ERRORTEXT, SRCTranslateT((char*)lParam, tmp));
- }
- GetWindowRect(hwndDlg, &rc);
- GetWindowRect(GetParent(hwndDlg), &rcParent);
- SetWindowPos(hwndDlg, 0,
- (rcParent.left+rcParent.right-(rc.right-rc.left))/2,
- (rcParent.top+rcParent.bottom-(rc.bottom-rc.top))/2,
- 0, 0, SWP_NOZORDER|SWP_NOSIZE);
- }
- return TRUE;
-
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDOK:
- SendMessageT(GetParent(hwndDlg), DM_ERRORDECIDED, MSGERROR_RETRY, 0);
- DestroyWindow(hwndDlg);
- break;
-
- case IDCANCEL:
- SendMessageT(GetParent(hwndDlg), DM_ERRORDECIDED, MSGERROR_CANCEL, 0);
- DestroyWindow(hwndDlg);
- break;
- }
- break;
- case DM_ERRORDECIDED:
- if (wParam!=MSGERROR_DONE) break;
- SendMessageT(GetParent(hwndDlg), DM_ERRORDECIDED, MSGERROR_DONE, 0);
- DestroyWindow(hwndDlg);
- break;
- }
-
- return FALSE;
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+ {
+ if (lParam)
+ SetDlgItemText(hwndDlg, IDC_ERRORTEXT, TranslateTS((TCHAR*)lParam));
+
+ RECT rc, rcParent;
+ GetWindowRect(hwndDlg, &rc);
+ GetWindowRect(GetParent(hwndDlg), &rcParent);
+ SetWindowPos(hwndDlg, 0,
+ (rcParent.left + rcParent.right - (rc.right - rc.left)) / 2,
+ (rcParent.top + rcParent.bottom - (rc.bottom - rc.top)) / 2,
+ 0, 0, SWP_NOZORDER | SWP_NOSIZE);
+ }
+ return TRUE;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDOK:
+ SendMessage(GetParent(hwndDlg), DM_ERRORDECIDED, MSGERROR_RETRY, 0);
+ DestroyWindow(hwndDlg);
+ break;
+
+ case IDCANCEL:
+ SendMessage(GetParent(hwndDlg), DM_ERRORDECIDED, MSGERROR_CANCEL, 0);
+ DestroyWindow(hwndDlg);
+ break;
+ }
+ break;
+
+ case DM_ERRORDECIDED:
+ if (wParam != MSGERROR_DONE) break;
+ SendMessage(GetParent(hwndDlg), DM_ERRORDECIDED, MSGERROR_DONE, 0);
+ DestroyWindow(hwndDlg);
+ break;
+ }
+
+ return FALSE;
}
diff --git a/plugins/ContactsPlus/src/send.h b/plugins/ContactsPlus/src/send.h
index c8580a4eb1..73908b4ecf 100644
--- a/plugins/ContactsPlus/src/send.h
+++ b/plugins/ContactsPlus/src/send.h
@@ -68,19 +68,20 @@ struct TSendContactsData { // hope uack is released automaticly, static propert
~TSendContactsData();
};
-struct TAckData {
+struct TAckData
+{
HANDLE hContact; // to whom was it sent
HANDLE* aContacts; // obj
int nContacts; // how many
TAckData(HANDLE contact) { hContact = contact; aContacts = NULL; nContacts = 0;};
- ~TAckData() { if (nContacts) SAFE_FREE((void**)&aContacts); }
+ ~TAckData() { mir_free(aContacts); }
};
typedef TAckData* PAckData;
struct TCTSend {
char* mcaUIN;
- unsigned char* mcaNick;
+ char* mcaNick;
};
struct gAckItem { // some shit here
@@ -94,10 +95,10 @@ struct gAckList {
gAckItem** Items;
int Count;
TAckData* Get(HANDLE hProcc) { for (int i=0; i<Count; i++) if (Items[i]->hProcc==hProcc) { return Items[i]->ackData; }; return NULL; };
- TAckData* Add(HANDLE hProcc, TAckData* ackData) { Items=(gAckItem**)realloc(Items, (Count+1)*sizeof(gAckItem*)); Items[Count]=new gAckItem(hProcc, ackData); Count++; return ackData; };
+ TAckData* Add(HANDLE hProcc, TAckData* ackData) { Items=(gAckItem**)mir_realloc(Items, (Count+1)*sizeof(gAckItem*)); Items[Count]=new gAckItem(hProcc, ackData); Count++; return ackData; };
TAckData* Remove(HANDLE hProcc) { for (int i=0; i<Count; i++) if (Items[i]->hProcc==hProcc) { TAckData* data=Items[i]->ackData; delete Items[i]; memmove(Items+i, Items+i+1, (Count-i-1)*sizeof(gAckItem*)); Count--; return data; }; return NULL; };
gAckList() { Count = 0; Items = NULL; }
- ~gAckList() { if (Count) { for (int i=0; i<Count; i++) delete Items[i]; SAFE_FREE((void**)&Items); }; }
+ ~gAckList() { if (Count) { for (int i=0; i<Count; i++) delete Items[i]; mir_free(Items); }; }
};
extern HANDLE ghSendWindowList;
diff --git a/plugins/ContactsPlus/src/utils.cpp b/plugins/ContactsPlus/src/utils.cpp
index 7fe3a4a4bf..dcfdda958b 100644
--- a/plugins/ContactsPlus/src/utils.cpp
+++ b/plugins/ContactsPlus/src/utils.cpp
@@ -28,661 +28,161 @@ int utf8_decode(const unsigned char *from, char **to);
/* a strlennull() that likes NULL */
size_t __fastcall strlennull(const char *string)
{
- if (string)
- return strlen(string);
+ if (string)
+ return strlen(string);
- return 0;
+ return 0;
}
-
int __fastcall strcmpnull(const char *str1, const char *str2)
{
- if (!str1 || !str2) return 1;
+ if (!str1 || !str2) return 1;
- return strcmp(str1, str2);
+ return strcmp(str1, str2);
}
-
char* __fastcall null_strdup(const char *string)
{
- if (string)
- return strdup(string);
-
- return NULL;
-}
-
-
-void __fastcall SAFE_FREE(void** p)
-{
- if (*p)
- {
- free(*p);
- *p = NULL;
- }
-}
+ if (string)
+ return strdup(string);
-TCHAR *GetContactDisplayNameT(HANDLE hContact)
-{
- return (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_UNICODE);
+ return NULL;
}
-char *GetContactUID(HANDLE hContact, int bTchar)
+TCHAR* GetContactUID(HANDLE hContact)
{
- DBVARIANT vrUid;
- char *szUid = NULL;
-
- char *szProto = GetContactProto(hContact);
- char *uid = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); // v0.3+ only
-
- if (((int)uid != CALLSERVICE_NOTFOUND) && uid)
- { // it worked, yeah :)
- if (!DBGetContactSettingT(hContact, szProto, uid, &vrUid))
- {
- if (vrUid.type == DBVT_DWORD)
- {
- szUid = (char*)_alloca(17);
- szUid[0] = 0; // empty string
- _itoa(vrUid.dVal, szUid, 10);
- }
- else if (vrUid.type == DBVT_ASCIIZ)
- {
- szUid = (char*)_alloca(strlennull(vrUid.pszVal) + 1);
- strcpy(szUid, vrUid.pszVal);
- }
- else if (vrUid.type == DBVT_UTF8)
- { // yeah, jabber gives this!
- char *szAnsi = NULL;
-
- if (utf8_decode((unsigned char*)vrUid.pszVal, &szAnsi))
- {
- szUid = (char*)_alloca(strlennull(szAnsi) + 1);
- strcpy(szUid, szAnsi);
- SAFE_FREE((void**)&szAnsi);
- }
- }
- db_free(&vrUid);
- }
- }
- if (bTchar)
- return ansi_to_tchar(szUid);
- else
- return null_strdup(szUid);
-}
+ DBVARIANT vrUid;
-int DBGetContactSettingT(HANDLE hContact, const char *szModule, const char* szSetting, DBVARIANT *dbv)
-{
- return db_get_s(hContact, szModule, szSetting, dbv, 0);
-}
+ char *szProto = GetContactProto(hContact);
+ char *uid = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); // v0.3+ only
+ if (((INT_PTR)uid != CALLSERVICE_NOTFOUND) || uid == 0)
+ return NULL;
-TCHAR* DBGetContactSettingStringT(HANDLE hContact, const char *szModule, const char* szSetting, TCHAR* szDef)
-{
- DBVARIANT dbv = {DBVT_DELETED};
- TCHAR* szRes;
+ if (db_get_s(hContact, szProto, uid, &vrUid, 0))
+ return NULL;
- if (db_get_ws(hContact, szModule, szSetting, &dbv))
- return strdupT(szDef);
+ if (vrUid.type == DBVT_DWORD) {
+ TCHAR tmp[100];
+ _itot(vrUid.dVal, tmp, 10);
+ return mir_tstrdup(tmp);
+ }
- szRes = strdupT(dbv.ptszVal);
- db_free(&dbv);
+ if (vrUid.type == DBVT_ASCIIZ) {
+ TCHAR *res = mir_a2t(vrUid.pszVal);
+ mir_free(vrUid.pszVal);
+ return res;
+ }
- return szRes;
-}
+ if (vrUid.type == DBVT_UTF8) {
+ TCHAR *res = mir_utf8decodeT(vrUid.pszVal);
+ mir_free(vrUid.pszVal);
+ return res;
+ }
-int DBWriteContactSettingStringT(HANDLE hContact, const char *szModule, const char* szSetting, TCHAR* szValue)
-{
- return db_set_ws(hContact, szModule, szSetting, (WCHAR*)szValue);
+ return NULL;
}
-
-
void DialogAddContactExecute(HWND hwndDlg, HANDLE hNewContact)
{
- ADDCONTACTSTRUCT acs={0};
+ ADDCONTACTSTRUCT acs = { 0 };
- acs.handle = hNewContact;
- acs.handleType = HANDLE_CONTACT;
+ acs.handle = hNewContact;
+ acs.handleType = HANDLE_CONTACT;
- CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)&acs);
+ CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)&acs);
}
void DrawProtocolIcon(HWND hwndDlg, LPARAM lParam, HANDLE hContact)
{
- LPDRAWITEMSTRUCT dis=(LPDRAWITEMSTRUCT)lParam;
-
- if (dis->hwndItem==GetDlgItem(hwndDlg, IDC_PROTOCOL))
- {
- HICON hIcon = LoadContactProtoIcon(hContact);
- if (hIcon)
- {
- DrawIconEx(dis->hDC,dis->rcItem.left,dis->rcItem.top,hIcon,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0,NULL,DI_NORMAL);
- DestroyIcon(hIcon);
- }
- }
+ LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam;
+
+ if (dis->hwndItem == GetDlgItem(hwndDlg, IDC_PROTOCOL))
+ {
+ HICON hIcon = LoadContactProtoIcon(hContact);
+ if (hIcon)
+ {
+ DrawIconEx(dis->hDC, dis->rcItem.left, dis->rcItem.top, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL);
+ DestroyIcon(hIcon);
+ }
+ }
}
-void UpdateDialogTitle(HWND hwndDlg, HANDLE hContact, char* pszTitleStart)
+void UpdateDialogTitle(HWND hwndDlg, HANDLE hContact, TCHAR *pszTitleStart)
{
- TCHAR newtitle[512];
- WCHAR str[MAX_PATH];
- TCHAR *oldTitle;
- TCHAR *szStatus;
- char *szProto;
-
- if (hContact)
- {
- szProto =GetContactProto(hContact);
- if (szProto)
- {
- TCHAR *uid = GetContactUID(hContact, TRUE);
- TCHAR *contactName = GetContactDisplayNameT(hContact);
-
- oldTitle = GetDlgItemTextT(hwndDlg, IDC_NAME);
-
- if (strcmpT(uid?uid:contactName, oldTitle))
- SetDlgItemTextT(hwndDlg, IDC_NAME, uid?uid:contactName);
-
- szStatus = pcli->pfnGetStatusModeDescription(szProto == NULL ? ID_STATUS_OFFLINE : db_get_w(hContact,szProto,"Status",ID_STATUS_OFFLINE), 0);
- mir_sntprintf(newtitle, 256, "%s %s (%s)", SRCTranslateT(pszTitleStart, str), contactName, szStatus);
-
- SAFE_FREE((void**)&uid);
- SAFE_FREE((void**)&oldTitle);
- }
- else
- strncpyT(newtitle, SRCTranslateT(pszTitleStart, str), 256);
- }
- else
- strncpyT(newtitle, SRCTranslateT(pszTitleStart, str), 256);
-
- oldTitle = GetWindowTextT(hwndDlg);
-
- if (strcmpT(newtitle, oldTitle))
- SetWindowTextT(hwndDlg, newtitle);
-
- SAFE_FREE((void**)&oldTitle);
+ TCHAR newtitle[512];
+ lstrcpyn(newtitle, TranslateTS(pszTitleStart), SIZEOF(newtitle));
+
+ if (hContact) {
+ char *szProto = GetContactProto(hContact);
+ if (szProto) {
+ ptrT uid(GetContactUID(hContact));
+ TCHAR *contactName = pcli->pfnGetContactDisplayName(hContact, 0);
+
+ TCHAR oldTitle[MAX_PATH];
+ GetDlgItemText(hwndDlg, IDC_NAME, oldTitle, SIZEOF(oldTitle));
+
+ if (lstrcmp(uid ? uid : contactName, oldTitle))
+ SetDlgItemText(hwndDlg, IDC_NAME, uid ? uid : contactName);
+
+ TCHAR *szStatus = pcli->pfnGetStatusModeDescription(szProto == NULL ? ID_STATUS_OFFLINE : db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE), 0);
+ mir_sntprintf(newtitle, 256, _T("%s %s (%s)"), TranslateTS(pszTitleStart), contactName, szStatus);
+ }
+ }
+
+ SetWindowText(hwndDlg, newtitle);
}
void UpdateDialogAddButton(HWND hwndDlg, HANDLE hContact)
{
- int bVisible = db_get_b(hContact,"CList","NotOnList",0);
-
- ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), bVisible?SW_SHOW:SW_HIDE);
+ int bVisible = db_get_b(hContact, "CList", "NotOnList", 0);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), bVisible ? SW_SHOW : SW_HIDE);
}
HICON InitMButton(HWND hDlg, int idButton, LPCSTR szIcon, char *szTip)
{
- HWND hButton = GetDlgItem(hDlg, idButton);
- HICON hIcon = (HICON)LoadImage(GetModuleHandle(NULL),szIcon,IMAGE_ICON,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),0);
+ HWND hButton = GetDlgItem(hDlg, idButton);
+ HICON hIcon = (HICON)LoadImageA(GetModuleHandle(NULL), szIcon, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0);
- SendMessageT(hButton, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
- SendMessageT(hButton, BUTTONSETASFLATBTN, TRUE, 0);
- SendMessageT(hButton, BUTTONADDTOOLTIP, (WPARAM)szTip, 0);
-
- return hIcon;
+ SendMessage(hButton, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
+ SendMessage(hButton, BUTTONSETASFLATBTN, TRUE, 0);
+ SendMessage(hButton, BUTTONADDTOOLTIP, (WPARAM)szTip, 0);
+ return hIcon;
}
HICON LoadContactProtoIcon(HANDLE hContact)
{
- char* szProto =GetContactProto(hContact);
- if (szProto)
- return (HICON)CallProtoService(szProto, PS_LOADICON, PLI_PROTOCOL|PLIF_SMALL, 0);
- return NULL;
+ char *szProto = GetContactProto(hContact);
+ if (szProto)
+ return (HICON)CallProtoService(szProto, PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL, 0);
+ return NULL;
}
void EnableDlgItem(HWND hwndDlg, UINT control, int state)
{
- EnableWindow(GetDlgItem(hwndDlg, control), state);
+ EnableWindow(GetDlgItem(hwndDlg, control), state);
}
-LRESULT SendMessageT(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
-{
- return SendMessageW(hWnd, Msg, wParam, lParam);
-}
-
TCHAR* GetWindowTextT(HWND hWnd)
{
- int len = GetWindowTextLengthW(hWnd) + 1;
- WCHAR* txt = (WCHAR*)malloc(len * sizeof(WCHAR));
+ int len = GetWindowTextLength(hWnd) + 1;
+ TCHAR* txt = (TCHAR*)mir_alloc(len * sizeof(TCHAR));
if (txt) {
txt[0] = 0;
- GetWindowTextW(hWnd, txt, len);
+ GetWindowText(hWnd, txt, len);
}
- return (TCHAR*)txt;
-}
-
-BOOL SetWindowTextT(HWND hWnd, TCHAR* lpString)
-{
- return SetWindowTextW(hWnd, (WCHAR*)lpString);
-}
-
-TCHAR* GetDlgItemTextT(HWND hDlg, int nIDDlgItem)
-{
- return GetWindowTextT(GetDlgItem(hDlg, nIDDlgItem));
-}
-
-BOOL SetDlgItemTextT(HWND hDlg, int nIDDlgItem, TCHAR* lpString)
-{
- return SetWindowTextT(GetDlgItem(hDlg, nIDDlgItem), lpString);
-}
-
-HWND CreateDialogParamT(HINSTANCE hInstance, const char* szTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam)
-{
- return CreateDialogParamW(hInstance, (LPCWSTR)szTemplate, hWndParent, lpDialogFunc, dwInitParam);
-}
-
-int ListView_InsertColumnT(HWND hwnd, int iCol, const LPLVCOLUMN pcol)
-{
- return SendMessageT(hwnd, LVM_INSERTCOLUMNW, (WPARAM)iCol, (LPARAM)pcol);
-}
-
-void ListView_SetItemTextT(HWND hwnd, int i, int iSubItem, TCHAR* pszText)
-{
- LV_ITEM lvi = {0};
-
- lvi.iSubItem = iSubItem;
- lvi.pszText = pszText;
- SendMessageT(hwnd, LVM_SETITEMTEXTW, (WPARAM)i, (LPARAM)&lvi);
-}
-
-
-
-size_t __fastcall strlenT(const TCHAR *string)
-{
- if (string)
- return wcslen((WCHAR*)string);
- return 0;
+ return txt;
}
TCHAR* __fastcall strdupT(const TCHAR *string)
{
if (string)
- return (TCHAR*)wcsdup((WCHAR*)string);
+ return (TCHAR*)wcsdup((TCHAR*)string);
return NULL;
}
-
-int __fastcall strcmpT(const TCHAR *string1, const TCHAR *string2)
-{
- if (!string1 || !string2) return 1;
-
- return wcscmp((WCHAR*)string1, (WCHAR*)string2);
-}
-
-TCHAR* __fastcall strcpyT(TCHAR* dest, const TCHAR* src)
-{
- if (src)
- return (TCHAR*)wcscpy((WCHAR*)dest, (WCHAR*)src);
- return dest;
-}
-
-TCHAR* __fastcall strncpyT(TCHAR* dest, const TCHAR* src, size_t len)
-{
- if (src)
- return (TCHAR*)wcsncpy((WCHAR*)dest, (WCHAR*)src, len);
- return dest;
-}
-
-TCHAR* __fastcall strcatT(TCHAR* dest, const TCHAR* src)
-{
- if (src)
- return (TCHAR*)wcscat((WCHAR*)dest, (WCHAR*)src);
- return dest;
-}
-
-TCHAR* __fastcall SRCTranslateT(const char* src, const WCHAR* unibuf)
-{ // this takes Ascii strings only!!!
- char* szRes = NULL;
-
- if (!strlennull(src))
- { // for the case of empty strings
- return "";
- }
-
- WCHAR *unicode;
- int wchars, err;
-
- wchars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, src,
- (int)strlennull(src), NULL, 0);
-
- if (wchars == 0) return NULL; // Failure
-
- unicode = (WCHAR*)unibuf;
- if (!unicode)
- unicode = (WCHAR*)malloc((wchars + 1) * sizeof(WCHAR));
-
- unicode[wchars] = 0;
-
- err = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, src,
- (int)strlennull(src), unicode, wchars);
- if (err != wchars) return NULL; // Failure
-
- return (TCHAR*)TranslateW(unicode);
-}
-
-static BOOL bHasCP_UTF8 = FALSE;
-
-
-void InitI18N(void)
-{
- CPINFO CPInfo;
-
-
- bHasCP_UTF8 = GetCPInfo(CP_UTF8, &CPInfo);
-}
-
-
-// Scans a string encoded in UTF-8 to verify that it contains
-// only valid sequences. It will return 1 if the string contains
-// only legitimate encoding sequences; otherwise it will return 0;
-// From 'Secure Programming Cookbook', John Viega & Matt Messier, 2003
-int UTF8_IsValid(const unsigned char* pszInput)
-{
- int nb, i;
- const unsigned char* c = pszInput;
-
- if (!pszInput) return 0;
-
- for (c = pszInput; *c; c += (nb + 1))
- {
- if (!(*c & 0x80))
- nb = 0;
- else if ((*c & 0xc0) == 0x80) return 0;
- else if ((*c & 0xe0) == 0xc0) nb = 1;
- else if ((*c & 0xf0) == 0xe0) nb = 2;
- else if ((*c & 0xf8) == 0xf0) nb = 3;
- else if ((*c & 0xfc) == 0xf8) nb = 4;
- else if ((*c & 0xfe) == 0xfc) nb = 5;
-
- for (i = 1; i<=nb; i++) // we this forward, do not cross end of string
- if ((*(c + i) & 0xc0) != 0x80)
- return 0;
- }
-
- return 1;
-}
-
-
-/*
- * The following UTF8 routines are
- *
- * Copyright (C) 2001 Peter Harris <peter.harris@hummingbird.com>
- * Copyright (C) 2001 Edmund Grimley Evans <edmundo@rano.org>
- *
- * under a GPL license
- *
- * --------------------------------------------------------------
- * Convert a string between UTF-8 and the locale's charset.
- * Invalid bytes are replaced by '#', and characters that are
- * not available in the target encoding are replaced by '?'.
- *
- * If the locale's charset is not set explicitly then it is
- * obtained using nl_langinfo(CODESET), where available, the
- * environment variable CHARSET, or assumed to be US-ASCII.
- *
- * Return value of conversion functions:
- *
- * -1 : memory allocation failed
- * 0 : data was converted exactly
- * 1 : valid data was converted approximately (using '?')
- * 2 : input was invalid (but still converted, using '#')
- * 3 : unknown encoding (but still converted, using '?')
- */
-
-
-
-/*
- * Convert a string between UTF-8 and the locale's charset.
- */
-unsigned char *make_utf8_string(const wchar_t *unicode)
-{
- int size = 0;
- int index = 0;
- int out_index = 0;
- unsigned char* out;
- unsigned short c;
-
- if (!unicode) return NULL;
-
- /* first calculate the size of the target string */
- c = unicode[index++];
- while (c)
- {
- if (c < 0x0080)
- size += 1;
- else if (c < 0x0800)
- size += 2;
- else
- size += 3;
- c = unicode[index++];
- }
-
- out = (unsigned char*)malloc(size + 1);
- if (out == NULL)
- return NULL;
- index = 0;
-
- c = unicode[index++];
- while (c)
- {
- if (c < 0x080)
- {
- out[out_index++] = (unsigned char)c;
- }
- else if (c < 0x800)
- {
- out[out_index++] = 0xc0 | (c >> 6);
- out[out_index++] = 0x80 | (c & 0x3f);
- }
- else
- {
- out[out_index++] = 0xe0 | (c >> 12);
- out[out_index++] = 0x80 | ((c >> 6) & 0x3f);
- out[out_index++] = 0x80 | (c & 0x3f);
- }
- c = unicode[index++];
- }
- out[out_index] = 0x00;
-
- return out;
-}
-
-
-
-WCHAR *make_unicode_string(const unsigned char *utf8)
-{
- int size = 0, index = 0, out_index = 0;
- wchar_t *out;
- unsigned char c;
-
- if (!utf8) return NULL;
-
- /* first calculate the size of the target string */
- c = utf8[index++];
- while (c)
- {
- if ((c & 0x80) == 0)
- {
- index += 0;
- }
- else if ((c & 0xe0) == 0xe0)
- {
- index += 2;
- }
- else
- {
- index += 1;
- }
- size += 1;
- c = utf8[index++];
- }
-
- out = (wchar_t*)malloc((size + 1) * sizeof(wchar_t));
- if (out == NULL)
- return NULL;
- index = 0;
-
- c = utf8[index++];
- while (c)
- {
- if ((c & 0x80) == 0)
- {
- out[out_index++] = c;
- }
- else if ((c & 0xe0) == 0xe0)
- {
- out[out_index] = (c & 0x1F) << 12;
- c = utf8[index++];
- out[out_index] |= (c & 0x3F) << 6;
- c = utf8[index++];
- out[out_index++] |= (c & 0x3F);
- }
- else
- {
- out[out_index] = (c & 0x3F) << 6;
- c = utf8[index++];
- out[out_index++] |= (c & 0x3F);
- }
- c = utf8[index++];
- }
- out[out_index] = 0;
-
- return out;
-}
-
-
-// Returns 0 on error, 1 on success
-static int utf8_decode(const unsigned char *from, char **to)
-{
- int nResult = 0;
-
-// _ASSERTE(!(*to)); // You passed a non-zero pointer, make sure it doesnt point to unfreed memory
-
- // Validate the string
- if (!UTF8_IsValid(from))
- return 0;
-
- // Use the native conversion routines when available
- if (bHasCP_UTF8)
- {
- WCHAR *wszTemp = NULL;
- int inlen = (int)strlennull((char*)from);
-
- wszTemp = (WCHAR *)_alloca(sizeof(WCHAR) * (inlen + 1));
-
- // Convert the UTF-8 string to UCS
- if (MultiByteToWideChar(CP_UTF8, 0, (char*)from, -1, wszTemp, inlen + 1))
- {
- // Convert the UCS string to local ANSI codepage
- *to = (char*)malloc(inlen+1);
- if (WideCharToMultiByte(CP_ACP, 0, wszTemp, -1, *to, inlen+1, NULL, NULL))
- {
- nResult = 1;
- }
- else
- {
- SAFE_FREE((void**)to);
- }
- }
- }
- else
- {
- wchar_t *unicode;
- int chars;
- int err;
-
- unicode = make_unicode_string(from);
- if (unicode == NULL)
- {
-// fprintf(stderr, "Out of memory processing string from UTF8 to UNICODE16\n");
- return 0;
- }
-
- chars = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, unicode, -1, NULL, 0, NULL, NULL);
-
- if(chars == 0)
- {
-// fprintf(stderr, "Unicode translation error %d\n", GetLastError());
- SAFE_FREE((void**)&unicode);
- return 0;
- }
-
- *to = (char*)malloc((chars + 1)*sizeof(unsigned char));
- if (*to == NULL)
- {
-// fprintf(stderr, "Out of memory processing string to local charset\n");
- SAFE_FREE((void**)&unicode);
- return 0;
- }
-
- err = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, unicode, -1, *to, chars, NULL, NULL);
- if (err != chars)
- {
-// fprintf(stderr, "Unicode translation error %d\n", GetLastError());
- SAFE_FREE((void**)&unicode);
- SAFE_FREE((void**)to);
- return 0;
- }
-
- SAFE_FREE((void**)&unicode);
-
- nResult = 1;
- }
-
- return nResult;
-}
-
-
-
-TCHAR* ansi_to_tchar(const char* src, int codepage)
-{
- WCHAR *unicode;
- int wchars, err;
-
- wchars = MultiByteToWideChar(codepage, MB_PRECOMPOSED, src, (int)strlennull(src), NULL, 0);
-
- if (wchars == 0) return NULL; // Failure
-
- unicode = (WCHAR*)malloc((wchars + 1) * sizeof(WCHAR));
- unicode[wchars] = 0;
-
- err = MultiByteToWideChar(codepage, MB_PRECOMPOSED, src, (int)strlennull(src), unicode, wchars);
- if (err != wchars)
- {
- SAFE_FREE((void**)&unicode);
- return NULL; // Failure
- }
-
- return (TCHAR*)unicode;
-}
-
-char* tchar_to_ansi(const TCHAR* src)
-{
- char *ansi;
- int chars;
- int err;
-
- chars = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, (WCHAR*)src, -1, NULL, 0, NULL, NULL);
-
- if (chars == 0) return NULL; // Failure
-
- ansi = (char*)malloc((chars + 1)*sizeof(char));
- if (ansi == NULL) return NULL; // Failure
-
- err = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, (WCHAR*)src, -1, ansi, chars, NULL, NULL);
- if (err != chars)
- {
- SAFE_FREE((void**)&ansi);
- return NULL;
- }
- return ansi;
-}
-
-TCHAR* utf8_to_tchar(const unsigned char* utf)
-{
- return (TCHAR*)make_unicode_string(utf);
-} \ No newline at end of file
diff --git a/plugins/ContactsPlus/src/utils.h b/plugins/ContactsPlus/src/utils.h
index adb29ff1fd..f89ee6ca9b 100644
--- a/plugins/ContactsPlus/src/utils.h
+++ b/plugins/ContactsPlus/src/utils.h
@@ -24,24 +24,17 @@
#ifndef __UTILS_H
#define __UTILS_H
-
extern HINSTANCE hInst;
// utils.cpp
-void __fastcall SAFE_FREE(void** p);
size_t __fastcall strlennull(const char *string);
int __fastcall strcmpnull(const char *str1, const char *str2);
char* __fastcall null_strdup(const char *string);
-char *GetContactUID(HANDLE hContact, int bTchar);
-TCHAR *GetContactDisplayNameT(HANDLE hContact);
-
-int DBGetContactSettingT(HANDLE hContact, const char *szModule, const char* szSetting, DBVARIANT *dbv);
-TCHAR* DBGetContactSettingStringT(HANDLE hContact, const char *szModule,const char* szSetting, TCHAR* szDef);
-int DBWriteContactSettingStringT(HANDLE hContact, const char *szModule, const char* szSetting, TCHAR* szValue);
+TCHAR* GetContactUID(HANDLE hContact);
void DrawProtocolIcon(HWND hwndDlg, LPARAM lParam, HANDLE hContact);
-void UpdateDialogTitle(HWND hwndDlg, HANDLE hContact, char* pszTitleStart);
+void UpdateDialogTitle(HWND hwndDlg, HANDLE hContact, TCHAR *pszTitleStart);
void UpdateDialogAddButton(HWND hwndDlg, HANDLE hContact);
HICON InitMButton(HWND hDlg, int idButton, LPCSTR szIcon, char* szTip);
@@ -52,30 +45,4 @@ HICON LoadContactProtoIcon(HANDLE hContact);
void EnableDlgItem(HWND hwndDlg, UINT control, int state);
-/// Unicode 2 in 1 Framework
-size_t __fastcall strlenT(const TCHAR *string);
-TCHAR* __fastcall strdupT(const TCHAR *string);
-int __fastcall strcmpT(const TCHAR *string1, const TCHAR *string2);
-TCHAR* __fastcall strcpyT(TCHAR* dest, const TCHAR* src);
-TCHAR* __fastcall strncpyT(TCHAR* dest, const TCHAR* src, size_t len);
-TCHAR* __fastcall strcatT(TCHAR* dest, const TCHAR* src);
-
-LRESULT SendMessageT(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
-TCHAR* GetWindowTextT(HWND hWnd);
-BOOL SetWindowTextT(HWND hWnd, TCHAR* lpString);
-TCHAR* GetDlgItemTextT(HWND hDlg, int nIDDlgItem);
-BOOL SetDlgItemTextT(HWND hDlg, int nIDDlgItem, TCHAR* lpString);
-HWND CreateDialogParamT(HINSTANCE hInstance, const char* szTemplate, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam);
-int ListView_InsertColumnT(HWND hwnd, int iCol, const LPLVCOLUMN pcol);
-void ListView_SetItemTextT(HWND hwnd, int i, int iSubItem, TCHAR* pszText);
-
-TCHAR* __fastcall SRCTranslateT(const char* src, const WCHAR* unibuf);
-
-void InitI18N(void);
-TCHAR* ansi_to_tchar(const char* string, int codepage = CP_ACP);
-char* tchar_to_ansi(const TCHAR* src);
-TCHAR* utf8_to_tchar(const unsigned char* utf);
-unsigned char *make_utf8_string(const wchar_t *unicode);
-
-
#endif /* __UTILS_H */ \ No newline at end of file