From dba46ff81f211542c359349371c1d932977b5e36 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 29 Nov 2012 18:38:28 +0000 Subject: unicode metacontacts git-svn-id: http://svn.miranda-ng.org/main/trunk@2561 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MetaContacts/MetaContacts_10.vcxproj | 8 +- plugins/MetaContacts/src/addto.cpp | 204 ++++----- plugins/MetaContacts/src/edit.cpp | 650 +++++++++++---------------- plugins/MetaContacts/src/icons.cpp | 6 +- plugins/MetaContacts/src/meta_main.cpp | 4 +- plugins/MetaContacts/src/meta_menu.cpp | 438 ++++++++---------- plugins/MetaContacts/src/meta_options.cpp | 338 +++++++------- plugins/MetaContacts/src/meta_services.cpp | 579 ++++++++++-------------- plugins/MetaContacts/src/meta_utils.cpp | 501 ++++++++------------- plugins/MetaContacts/src/metacontacts.h | 26 +- 10 files changed, 1125 insertions(+), 1629 deletions(-) (limited to 'plugins/MetaContacts') diff --git a/plugins/MetaContacts/MetaContacts_10.vcxproj b/plugins/MetaContacts/MetaContacts_10.vcxproj index 2688d89597..81185178d8 100644 --- a/plugins/MetaContacts/MetaContacts_10.vcxproj +++ b/plugins/MetaContacts/MetaContacts_10.vcxproj @@ -25,21 +25,21 @@ DynamicLibrary - MultiByte + Unicode true DynamicLibrary - MultiByte + Unicode DynamicLibrary true - MultiByte + Unicode DynamicLibrary - MultiByte + Unicode diff --git a/plugins/MetaContacts/src/addto.cpp b/plugins/MetaContacts/src/addto.cpp index 7be0f40a6f..bfe3098bf4 100644 --- a/plugins/MetaContacts/src/addto.cpp +++ b/plugins/MetaContacts/src/addto.cpp @@ -73,12 +73,12 @@ int FillList(HWND list, BOOL sort) char *szCDN = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hMetaUser, 0); if (os_unicode_enabled) { - wchar_t *swzCDN = (wchar_t *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hMetaUser, GCDNF_UNICODE), + wchar_t *ptszCDN = (wchar_t *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hMetaUser, GCDNF_UNICODE), *swzContactDisplayName; // detect if the clist provided unicode display name by comparing with non-unicode - if (szCDN && swzCDN && strncmp(szCDN, (char *)swzCDN, strlen(szCDN)) != 0) { - swzContactDisplayName = swzCDN; + if (szCDN && ptszCDN && strncmp(szCDN, (char *)ptszCDN, strlen(szCDN)) != 0) { + swzContactDisplayName = ptszCDN; } else { // no? convert to unicode if (szCDN) { @@ -162,139 +162,99 @@ int BuildList(HWND list, BOOL sort) * * @return \c TRUE if the dialog processed the message, \c FALSE if it did not. */ + +#define szConvMsg "Either there is no MetaContact in the database (in this case you should first convert a contact into one)\n\ +or there is none that can host this contact.\n\ +Another solution could be to convert this contact into a new MetaContact.\n\nConvert this contact into a new MetaContact?" + INT_PTR CALLBACK Meta_SelectDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) - { - case WM_INITDIALOG: - { - TranslateDialogDefault( hwndDlg ); + switch(msg) { + case WM_INITDIALOG: + TranslateDialogDefault( hwndDlg ); + + if ( db_get_dw((HANDLE)lParam, META_PROTO, META_ID, (DWORD)-1) != (DWORD)-1) { + MessageBox(hwndDlg, + TranslateT("This contact is a MetaContact.\nYou can't add a MetaContact to another MetaContact.\n\nPlease choose another."), + TranslateT("MetaContact Conflict"),MB_ICONERROR); + DestroyWindow(hwndDlg); + return TRUE; + } + if (db_get_dw((HANDLE)lParam, META_PROTO, META_LINK, (DWORD)-1) != (DWORD)-1) { + MessageBox(hwndDlg, + TranslateT("This contact is already associated to a MetaContact.\nYou cannot add a contact to multiple MetaContacts."), + TranslateT("Multiple MetaContacts"),MB_ICONERROR); + DestroyWindow(hwndDlg); + return TRUE; + } - if (db_get_dw((HANDLE)lParam, META_PROTO, META_ID,(DWORD)-1)!=(DWORD)-1) - { - MessageBox(hwndDlg,Translate("This contact is a MetaContact.\nYou can't add a MetaContact to another MetaContact.\n\nPlease choose another."), - Translate("MetaContact Conflict"),MB_ICONERROR); - DestroyWindow(hwndDlg); - return TRUE; - } - if (db_get_dw((HANDLE)lParam, META_PROTO, META_LINK,(DWORD)-1)!=(DWORD)-1) - { - MessageBox(hwndDlg,Translate("This contact is already associated to a MetaContact.\nYou cannot add a contact to multiple MetaContacts."), - Translate("Multiple MetaContacts"),MB_ICONERROR); - DestroyWindow(hwndDlg); - return TRUE; - } + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); // user data is contact handle - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); // user data is contact handle + SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx(I_ADD)); - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx(I_ADD)); - //SendMessage(GetDlgItem(hwndDlg,IDC_METALIST),LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_FULLROWSELECT); + // Initialize the graphical part + CheckDlgButton(hwndDlg, IDC_ONLYAVAIL, BST_CHECKED); // Initially checked; display all metacontacts is only an option + // Besides, we can check if there is at least one metacontact to add the contact to. + if ( BuildList(GetDlgItem(hwndDlg, IDC_METALIST), FALSE) <= 0) { + if ( MessageBox(hwndDlg, TranslateT(szConvMsg), TranslateT("No suitable MetaContact found"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1) == IDYES) + Meta_Convert((WPARAM)lParam,0); + DestroyWindow(hwndDlg); + return TRUE; + } + else { + // get contact display name from clist + TCHAR *ptszCDN = (TCHAR*) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, lParam, GCDNF_TCHAR); + if (!ptszCDN) + ptszCDN = TranslateT("a contact"); + + // ... and set it to the Window title. + TCHAR buf[256]; + mir_sntprintf(buf, SIZEOF(buf), TranslateT("Adding %s..."), ptszCDN); + SetWindowText(hwndDlg, buf); + } + ShowWindow(hwndDlg,SW_SHOWNORMAL); + return TRUE; + + case WM_COMMAND: + if (HIWORD(wParam)!=BN_CLICKED) + break; // Only clicks of buttons are relevant, let other COMMANDs through - // Initialize the graphical part - CheckDlgButton(hwndDlg,IDC_ONLYAVAIL,BST_CHECKED); // Initially checked; display all metacontacts is only an option - // Besides, we can check if there is at least one metacontact to add the contact to. - if (BuildList(GetDlgItem(hwndDlg,IDC_METALIST), FALSE)<=0) + switch(LOWORD(wParam)) { + case IDOK: { - if (MessageBox(hwndDlg,Translate("Either there is no MetaContact in the database (in this case you should first convert a contact into one)\n" - "or there is none that can host this contact.\n" - "Another solution could be to convert this contact into a new MetaContact.\n\nConvert this contact into a new MetaContact?"), - Translate("No suitable MetaContact found"),MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON1)==IDYES) - Meta_Convert((WPARAM)lParam,0); - DestroyWindow(hwndDlg); - return TRUE; + HANDLE hContact = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + int item; // Get the index of the selected metacontact + if ((item = SendMessage(GetDlgItem(hwndDlg, IDC_METALIST),LB_GETCURSEL, 0, 0))==-1) + return IDOK == MessageBox(hwndDlg, TranslateT("Please select a MetaContact"), TranslateT("No MetaContact selected"), MB_ICONHAND); + + HANDLE hMeta = (HANDLE)SendMessage(GetDlgItem(hwndDlg, IDC_METALIST), LB_GETITEMDATA, (WPARAM)item, 0); + if ( !Meta_Assign(hContact,hMeta, FALSE)) + MessageBox(hwndDlg, TranslateT("Assignment to the MetaContact failed."), TranslateT("Assignment failure"),MB_ICONERROR); } - else - { - // Get the name displayed in the CList... - - // get contact display name from clist - char *szCDN = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)lParam, 0); - if (os_unicode_enabled) { - wchar_t *swzCDN = (wchar_t *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)lParam, GCDNF_UNICODE), - *swzContactDisplayName; - wchar_t buf[256]; - - // detect if the clist provided unicode display name by comparing with non-unicode - if (szCDN && swzCDN && strncmp(szCDN, (char *)swzCDN, strlen(szCDN)) != 0) { - swzContactDisplayName = swzCDN; - } else { - // no? convert to unicode - if (szCDN) { - swzContactDisplayName = (wchar_t *) _alloca(sizeof(wchar_t) * (strlen(szCDN) + 1)); - MultiByteToWideChar(CP_ACP, 0, (char *) szCDN, -1, swzContactDisplayName, (int)strlen((char *)szCDN) + 1); - } else { - swzContactDisplayName = TranslateW(L"a contact"); - } - } - - // ... and set it to the Window title. - //MessageBoxW(hwndDlg, swzContactDisplayName, L"Setting window title", MB_OK); - - // note - the swprintf function has changed (includes size_t for vc8+) - //swprintf(buf, 256, TranslateW(L"Adding %s..."), swzContactDisplayName); - // this *should* work for vc6, 7, and 8 (thx George) - _snwprintf(buf, 256, TranslateW(L"Adding %s..."), swzContactDisplayName); - - SetWindowTextW(hwndDlg, buf); - } else { - char buf[256]; - sprintf(buf,Translate("Adding %s..."), szCDN); - SetWindowText(hwndDlg, buf); - } + case IDCANCEL: + DestroyWindow(hwndDlg); + break; - ShowWindow(hwndDlg,SW_SHOWNORMAL); + case IDC_CHK_SRT: + SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_METALIST), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_METALIST), GWL_STYLE) ^ LBS_SORT); + if (BuildList(GetDlgItem(hwndDlg,IDC_METALIST), IsDlgButtonChecked(hwndDlg, IDC_CHK_SRT) ? TRUE : FALSE) <= 0) { + if (MessageBox(hwndDlg, TranslateT(szConvMsg), TranslateT("No suitable MetaContact found"),MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON1) == IDYES) + Meta_Convert((WPARAM)lParam, 0); + DestroyWindow(hwndDlg); return TRUE; } - } - case WM_COMMAND: - if (HIWORD(wParam)!=BN_CLICKED) - break; // Only clicks of buttons are relevant, let other COMMANDs through - switch(LOWORD(wParam)) - { - case IDOK: - { - HANDLE hMeta, hContact = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - int item; // Get the index of the selected metacontact - if ((item = SendMessage(GetDlgItem(hwndDlg, IDC_METALIST),LB_GETCURSEL, 0, 0))==-1) - return IDOK == MessageBox(hwndDlg,Translate("Please select a MetaContact"),Translate("No MetaContact selected"),MB_ICONHAND); - - hMeta = (HANDLE)SendMessage(GetDlgItem(hwndDlg, IDC_METALIST), LB_GETITEMDATA, (WPARAM)item, 0); - - { - if ( !Meta_Assign(hContact,hMeta, FALSE)) - { - MessageBox(hwndDlg, Translate("Assignment to the MetaContact failed."), Translate("Assignment failure"),MB_ICONERROR); - } - } - } - case IDCANCEL: - DestroyWindow(hwndDlg); - break; - - case IDC_CHK_SRT: - SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_METALIST), GWL_STYLE, GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_METALIST), GWL_STYLE) ^ LBS_SORT); - if (BuildList(GetDlgItem(hwndDlg,IDC_METALIST), IsDlgButtonChecked(hwndDlg, IDC_CHK_SRT) ? TRUE : FALSE)<=0) - { - if (MessageBox(hwndDlg,Translate("Either there is no MetaContact in the database (in this case you should first convert a contact into one)\n" - "or there is none that can host this contact.\n" - "Another solution could be to convert this contact into a new MetaContact.\n\nConvert this contact into a new MetaContact?"), - Translate("No suitable MetaContact found"),MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON1)==IDYES) - Meta_Convert((WPARAM)lParam,0); - DestroyWindow(hwndDlg); - return TRUE; - } - break; - } break; - case WM_DESTROY: - { // Free all allocated memory and return the focus to the CList - HWND clist = GetParent(hwndDlg); - ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); - EndDialog(hwndDlg,TRUE); - SetFocus(clist); - return TRUE; } + break; + + case WM_DESTROY: + // Free all allocated memory and return the focus to the CList + HWND clist = GetParent(hwndDlg); + ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); + EndDialog(hwndDlg,TRUE); + SetFocus(clist); + return TRUE; } return FALSE; // All other Message are not handled } diff --git a/plugins/MetaContacts/src/edit.cpp b/plugins/MetaContacts/src/edit.cpp index cf21c42edb..a908734c50 100644 --- a/plugins/MetaContacts/src/edit.cpp +++ b/plugins/MetaContacts/src/edit.cpp @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Contains all the functions and all the structures * needed to display and control the 'Edit' Dialog. */ + #include "metacontacts.h" //! Holds the differents changes that have to made @@ -44,132 +45,93 @@ CHANGES changes; //!< \c global CHANGES structure * * @param chg : Structure holding all the change info (See CHANGES). */ -void FillContactList(HWND hWndDlg, CHANGES *chg) { - HWND hList = GetDlgItem(hWndDlg, IDC_LST_CONTACTS); - char *proto, *field, buff[256]; - int i; - LVITEM LvItem; - DBVARIANT dbv; - LVITEMW LvItemW; // for unicode nicks +void FillContactList(HWND hWndDlg, CHANGES *chg) +{ + HWND hList = GetDlgItem(hWndDlg, IDC_LST_CONTACTS); + TCHAR buff[256]; - SendMessage(hList,LVM_DELETEALLITEMS,0,0); + SendMessage(hList, LVM_DELETEALLITEMS, 0, 0); - ZeroMemory(&LvItem, sizeof(LvItem)); - LvItem.mask=LVIF_TEXT; // Text Style + LVITEM LvItem = { 0 }; + LvItem.mask = LVIF_TEXT; // Text Style LvItem.cchTextMax = 256; // Max size of test - ZeroMemory(&LvItemW, sizeof(LvItemW)); - LvItemW.mask=LVIF_TEXT; // Text Style - LvItemW.cchTextMax = 256; // Max size of test - - for (i = 0; i < chg->num_contacts; i++) { + for (int i = 0; i < chg->num_contacts; i++) { LvItem.iItem = i; - LvItemW.iItem = i; - - { - - char *szCDN = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)chg->hContact[i], 0); - - if (os_unicode_enabled) { - wchar_t *swzCDN = (wchar_t *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)chg->hContact[i], GCDNF_UNICODE), - *swzContactDisplayName; - - LvItemW.iSubItem = 0; // clist display name - - // detect if the clist provided unicode display name by comparing with non-unicode - if (szCDN && swzCDN && strncmp(szCDN, (char *)swzCDN, strlen(szCDN)) != 0 && wcslen(swzCDN) >= strlen(szCDN)) { - swzContactDisplayName = swzCDN; - } else { - // no? convert to unicode - if (szCDN) { - swzContactDisplayName = (wchar_t *) _alloca(sizeof(wchar_t) * (strlen(szCDN) + 1)); - MultiByteToWideChar(CP_ACP, 0, (char *) szCDN, -1, swzContactDisplayName, (int)strlen((char *)szCDN) + 1); - } else { - swzContactDisplayName = TranslateW(L"(Unknown Contact)"); - } - } - - LvItemW.pszText = swzContactDisplayName; - SendMessageW(hList, LVM_INSERTITEMW, 0, (LPARAM)&LvItemW); - } else { - LvItem.iSubItem = 0; // clist display name - LvItem.pszText = szCDN; - SendMessage(hList, LVM_INSERTITEM, 0, (LPARAM)&LvItem); - } - } - + + TCHAR *ptszCDN = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)chg->hContact[i], GCDNF_TCHAR); + if (ptszCDN == NULL) + ptszCDN = TranslateT("(Unknown Contact)"); + LvItem.iSubItem = 0; // clist display name + LvItem.pszText = ptszCDN; + ListView_InsertItem(hList, &LvItem); LvItem.iSubItem = 1; // id + char *szProto = GetContactProto(chg->hContact[i]); + if (szProto) { + char *szField = (char *)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); - proto = GetContactProto(chg->hContact[i]); - if (proto) { - field = (char *)CallProtoService(proto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0); - - db_get(chg->hContact[i],proto,field,&dbv); - switch(dbv.type) - { + DBVARIANT dbv; + if ( !db_get(chg->hContact[i], szProto, szField, &dbv)) { + switch(dbv.type) { case DBVT_ASCIIZ: - sprintf(buff,"%s",dbv.pszVal); + _tcsncpy(buff, _A2T(dbv.pszVal), SIZEOF(buff)); + break; + case DBVT_WCHAR: + _tcsncpy(buff, dbv.ptszVal, SIZEOF(buff)); break; case DBVT_BYTE: - sprintf(buff,"%d",dbv.bVal); + _itot(dbv.bVal, buff, 10); break; case DBVT_WORD: - sprintf(buff,"%d",dbv.wVal); + _itot(dbv.wVal, buff, 10); break; case DBVT_DWORD: - sprintf(buff,"%d",(int)dbv.dVal); + _itot(dbv.dVal, buff, 10); break; default: - //sprintf(buff,""); buff[0] = 0; + } + db_free(&dbv); } - db_free(&dbv); + else buff[0] = 0; LvItem.pszText = buff; SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem); // Enter text to SubItems LvItem.iSubItem = 2; // protocol - LvItem.pszText = proto; - SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem); // Enter text to SubItems - } else { - LvItem.pszText = "Unknown"; - SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem); // Enter text to SubItems + _tcsncpy(buff, _A2T(szProto), SIZEOF(buff)); + ListView_SetItem(hList, &LvItem); + } + else { + LvItem.pszText = _T("Unknown"); + ListView_SetItem(hList, &LvItem); LvItem.iSubItem = 2; // protocol - LvItem.pszText = "Unknown"; - SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem); // Enter text to SubItems + ListView_SetItem(hList, &LvItem); } LvItem.iSubItem = 3; // Default (Yes/No) - LvItem.pszText = (chg->hContact[i] == chg->hDefaultContact ? Translate("Yes") : Translate("No")); - SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem); // Enter text to SubItems + LvItem.pszText = (chg->hContact[i] == chg->hDefaultContact ? TranslateT("Yes") : TranslateT("No")); + ListView_SetItem(hList, &LvItem); LvItem.iSubItem = 4; // Offline (Yes/No) - LvItem.pszText = (chg->hContact[i] == chg->hOfflineContact ? Translate("Yes") : Translate("No")); - SendMessage(hList,LVM_SETITEM,0,(LPARAM)&LvItem); // Enter text to SubItems + LvItem.pszText = (chg->hContact[i] == chg->hOfflineContact ? TranslateT("Yes") : TranslateT("No")); + ListView_SetItem(hList, &LvItem); } } - -void SetListSelection(HWND hList, int sel) { - LVITEM LvItem; - - ZeroMemory(&LvItem, sizeof(LvItem)); - LvItem.iItem = sel; - LvItem.mask = LVIF_STATE; - LvItem.stateMask = LVIS_SELECTED|LVIS_FOCUSED; - LvItem.state = LVIS_SELECTED|LVIS_FOCUSED; - - SendMessage(hList, LVM_SETITEMSTATE, (WPARAM)sel, (LPARAM)&LvItem); - +void SetListSelection(HWND hList, int sel) +{ + ListView_SetItemState(hList, sel, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED); } /** Scans the \c CHANGES and call the appropriate function for each change. * * @param chg : Structure holding all the change info (See CHANGES). */ + void ApplyChanges(CHANGES *chg) { HANDLE most_online; @@ -223,7 +185,7 @@ void ApplyChanges(CHANGES *chg) _tcscpy(AI.filename, _T("X")); if ((int)CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS) - DBWriteContactSettingTString(chg->hMeta, "ContactPhoto", "File",AI.filename); + db_set_ts(chg->hMeta, "ContactPhoto", "File",AI.filename); } if (MetaAPI_GetForceState((WPARAM)chg->hMeta, 0) != chg->force_default) @@ -233,33 +195,19 @@ void ApplyChanges(CHANGES *chg) LRESULT ProcessCustomDraw (LPARAM lParam) { LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam; - - switch(lplvcd->nmcd.dwDrawStage) - { - case CDDS_PREPAINT : //Before the paint cycle begins - //request notifications for individual listview items - return CDRF_NOTIFYITEMDRAW; - - case CDDS_ITEMPREPAINT: //Before an item is drawn - /* - if (((int)lplvcd->nmcd.dwItemSpec%2)==0) - { - //customize item appearance - //lplvcd->clrText = RGB(255,0,0); - lplvcd->clrTextBk = RGB(200,200,200); - } - else{ - //lplvcd->clrText = RGB(0,0,255); - lplvcd->clrTextBk = RGB(255,255,255); - } - */ - if (changes.hContact[(int)lplvcd->nmcd.dwItemSpec] == changes.hDefaultContact) { - lplvcd->clrText = RGB(255, 0, 0); - } - return CDRF_NEWFONT; - } - - return 0; + switch(lplvcd->nmcd.dwDrawStage) { + case CDDS_PREPAINT : //Before the paint cycle begins + //request notifications for individual listview items + return CDRF_NOTIFYITEMDRAW; + + case CDDS_ITEMPREPAINT: //Before an item is drawn + if (changes.hContact[(int)lplvcd->nmcd.dwItemSpec] == changes.hDefaultContact) { + lplvcd->clrText = RGB(255, 0, 0); + } + return CDRF_NEWFONT; + } + + return 0; } /** Callback function for the 'Edit' Dialog. @@ -273,73 +221,59 @@ LRESULT ProcessCustomDraw (LPARAM lParam) * * @return \c TRUE if the dialog processed the message, \c FALSE if it did not. */ + #define WMU_SETTITLE (WM_USER + 1) INT_PTR CALLBACK Meta_EditDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { HWND hwnd; - char *str; int sel, i; - switch(msg) - { - case WM_INITDIALOG: + switch(msg) { + case WM_INITDIALOG: + TranslateDialogDefault( hwndDlg ); + SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx(I_EDIT)); { - // Font necessary for all controls created with CreateWindowsEx - //HFONT hfDefault = GetStockObject(DEFAULT_GUI_FONT); - //HWND combo = GetDlgItem(hwndDlg,IDC_DEFAULT); - int nb_contacts, default_contact_number, offline_contact_number; - LVCOLUMN LvCol; - - TranslateDialogDefault( hwndDlg ); - - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx(I_EDIT)); - // Disable the 'Apply' button. EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),FALSE); - // (from http://www.codeproject.com/listctrl/listview.asp) - // initialize list hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS); - SendMessage(hwnd,LVM_SETEXTENDEDLISTVIEWSTYLE, 0,LVS_EX_FULLROWSELECT); // Set style + ListView_SetExtendedListViewStyle(hwnd, LVS_EX_FULLROWSELECT); // Create list columns - ZeroMemory(&LvCol, sizeof(LvCol)); - LvCol.mask=LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM; // Type of mask - - // Inserting Couloms as much as we want - LvCol.pszText=Translate("Contact"); // First Header Text - LvCol.cx=100; // width of column - SendMessage(hwnd,LVM_INSERTCOLUMN,0,(LPARAM)&LvCol); // Insert/Show the coloum - - LvCol.pszText=Translate("Id"); // Next coloum - LvCol.cx=130; // width of column - SendMessage(hwnd,LVM_INSERTCOLUMN,1,(LPARAM)&LvCol); // ... - LvCol.pszText=Translate("Protocol"); // - LvCol.cx=100; // width of column - SendMessage(hwnd,LVM_INSERTCOLUMN,2,(LPARAM)&LvCol); // - LvCol.pszText=Translate("Default"); // - LvCol.cx=60; // width of column - SendMessage(hwnd,LVM_INSERTCOLUMN,3,(LPARAM)&LvCol); // - LvCol.pszText=Translate("Send Offline"); // - LvCol.cx=85; // width of column - SendMessage(hwnd,LVM_INSERTCOLUMN,4,(LPARAM)&LvCol); // - + LVCOLUMN LvCol = { 0 }; + LvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; + + LvCol.pszText = TranslateT("Contact"); + LvCol.cx = 100; + ListView_InsertColumn(hwnd, 0, &LvCol); + + LvCol.pszText = TranslateT("Id"); + LvCol.cx = 130; + ListView_InsertColumn(hwnd, 1, &LvCol); + + LvCol.pszText = TranslateT("Protocol"); + LvCol.cx = 100; + ListView_InsertColumn(hwnd, 2, &LvCol); + + LvCol.pszText = TranslateT("Default"); + LvCol.cx = 60; + ListView_InsertColumn(hwnd, 3, &LvCol); + + LvCol.pszText = TranslateT("Send Offline"); + LvCol.cx = 85; + ListView_InsertColumn(hwnd, 4, &LvCol); + // disable buttons until a selection is made in the list - hwnd = GetDlgItem(hwndDlg, IDC_BTN_REM); - EnableWindow(hwnd, FALSE); - hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT); - EnableWindow(hwnd, FALSE); - hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE); - EnableWindow(hwnd, FALSE); - hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP); - EnableWindow(hwnd, FALSE); - hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN); - EnableWindow(hwnd, FALSE); - - nb_contacts = db_get_dw((HANDLE)lParam, META_PROTO, "NumContacts", 0); - default_contact_number = db_get_dw((HANDLE)lParam, META_PROTO, "Default", (DWORD)-1); - offline_contact_number = db_get_dw((HANDLE)lParam, META_PROTO, "OfflineSend", (DWORD)-1); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_REM), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UP), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DOWN), FALSE); + + int nb_contacts = db_get_dw((HANDLE)lParam, META_PROTO, "NumContacts", 0); + int default_contact_number = db_get_dw((HANDLE)lParam, META_PROTO, "Default", (DWORD)-1); + int offline_contact_number = db_get_dw((HANDLE)lParam, META_PROTO, "OfflineSend", (DWORD)-1); changes.hMeta = (HANDLE)lParam; changes.num_contacts = nb_contacts; @@ -355,230 +289,178 @@ INT_PTR CALLBACK Meta_EditDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR CheckDlgButton(hwndDlg, IDC_CHK_FORCEDEFAULT, changes.force_default); FillContactList(hwndDlg, &changes); - return TRUE; } - case WMU_SETTITLE: - { - - char *szCDN = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)lParam, 0); - if (os_unicode_enabled) { - wchar_t *swzCDN = (wchar_t *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)lParam, GCDNF_UNICODE), - *swzContactDisplayName; - - // detect if the clist provided unicode display name by comparing with non-unicode - if (szCDN && swzCDN && strncmp(szCDN, (char *)swzCDN, strlen(szCDN)) != 0 && wcslen(swzCDN) >= strlen(szCDN)) { - swzContactDisplayName = swzCDN; - } else { - // no? convert to unicode - if (szCDN) { - swzContactDisplayName = (wchar_t *) _alloca(sizeof(wchar_t) * (strlen(szCDN) + 1)); - MultiByteToWideChar(CP_ACP, 0, (char *) szCDN, -1, swzContactDisplayName, (int)strlen((char *)szCDN) + 1); - } else { - swzContactDisplayName = TranslateW(L"(Unknown Contact)"); - } - } + return TRUE; + + case WMU_SETTITLE: + { + TCHAR *ptszCDN = (TCHAR*) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)lParam, GCDNF_UNICODE); + if (ptszCDN == NULL) + ptszCDN = TranslateT("(Unknown Contact)"); - SetWindowTextW(GetDlgItem(hwndDlg,IDC_ED_NAME), swzContactDisplayName); - } else { - SetWindowText(GetDlgItem(hwndDlg,IDC_ED_NAME), szCDN); + SetWindowText(GetDlgItem(hwndDlg, IDC_ED_NAME), ptszCDN); + } + return TRUE; + + case WM_NOTIFY: // the message that is being sent always + switch(LOWORD(wParam)) { // hit control + case IDC_LST_CONTACTS: // did we hit our ListView contorl? + if (((LPNMHDR)lParam)->code == NM_CLICK) { + sel = ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_LST_CONTACTS), -1, LVNI_FOCUSED|LVNI_SELECTED); // return item selected + + // enable buttons + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_REM), sel != -1); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT), sel != -1 && changes.hContact[sel] != changes.hDefaultContact); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE), sel != -1 && changes.hContact[sel] != changes.hOfflineContact); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UP), sel > 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DOWN), (sel != -1 && sel < changes.num_contacts - 1)); + } + } + break; + + case WM_COMMAND: + switch(HIWORD(wParam)) { + case BN_CLICKED: // A button ('Remove', 'Ok', 'Cancel' or 'Apply', normally) has been clicked + switch(LOWORD(wParam)) { + case IDC_VALIDATE: // Apply changes, if there is still one contact attached to the metacontact. + if (changes.num_contacts == 0) { // Otherwise, delete the metacontact. + if (IDYES == MessageBox(hwndDlg, TranslateT(szDelMsg), TranslateT("Delete MetaContact?"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1)) { + Meta_Delete((WPARAM)changes.hMeta, 0); + DestroyWindow(hwndDlg); + } + return TRUE; } - } - return TRUE; - case WM_NOTIFY: // the message that is being sent always - switch(LOWORD(wParam)) // hit control - { - case IDC_LST_CONTACTS: // did we hit our ListView contorl? - if (((LPNMHDR)lParam)->code == NM_CLICK) { - hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS); - sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected - // enable buttons - hwnd = GetDlgItem(hwndDlg, IDC_BTN_REM); - EnableWindow(hwnd, sel!=-1); - hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT); - EnableWindow(hwnd, sel!=-1 && changes.hContact[sel] != changes.hDefaultContact); - hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE); - EnableWindow(hwnd, sel!=-1 && changes.hContact[sel] != changes.hOfflineContact); - hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP); - EnableWindow(hwnd, (sel > 0)); - hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN); - EnableWindow(hwnd, (sel != -1) && (sel < changes.num_contacts - 1)); -/* - // custom draw stuff - change colour of listview things - doesn't affect selection :( - } else if (((LPNMHDR)lParam)->code == NM_CUSTOMDRAW) { - SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, (LONG)ProcessCustomDraw(lParam)); - return TRUE; -*/ - } - break; - } - break; - case WM_COMMAND: - switch(HIWORD(wParam)) - { - case BN_CLICKED: // A button ('Remove', 'Ok', 'Cancel' or 'Apply', normally) has been clicked - switch(LOWORD(wParam)) - { - case IDC_VALIDATE: // Apply changes, if there is still one contact attached to the metacontact. - if (changes.num_contacts == 0) // Otherwise, delete the metacontact. - { - if (MessageBox(hwndDlg,Translate("You are going to remove all the contacts associated with this MetaContact.\nThis will delete the MetaContact.\n\nProceed Anyway?"), - Translate("Delete MetaContact?"),MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON1)!=IDYES) - return TRUE; - else - { - Meta_Delete((WPARAM)changes.hMeta,0); - DestroyWindow(hwndDlg); - return TRUE; - } - } - ApplyChanges(&changes); - - // Disable the 'Apply' button. - EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),FALSE); - break; - case IDOK: - if (IsWindowEnabled(GetDlgItem(hwndDlg,IDC_VALIDATE))) - { // If there are changes that could be made, - if (changes.num_contacts == 0) // do the work that would have be done if - { // the button 'Apply' has been clicked. - if (MessageBox(hwndDlg,Translate("You are going to remove all the contacts associated with this MetaContact.\nThis will delete the MetaContact.\n\nProceed Anyway?"), - Translate("Delete MetaContact?"),MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON1)!=IDYES) - { - return TRUE; - } else { - Meta_Delete((WPARAM)changes.hMeta,0); - DestroyWindow(hwndDlg); - return TRUE; - } - } - ApplyChanges(&changes); - } - EndDialog(hwndDlg, IDOK); - return TRUE; - case IDCANCEL: // Simply close the dialog - EndDialog(hwndDlg, IDCANCEL); - return TRUE; - case IDC_BTN_SETDEFAULT: - hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS); - sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected - InvalidateRect(hwnd, 0, TRUE); - changes.hDefaultContact = changes.hContact[sel]; - SendMessage(hwndDlg, WMU_SETTITLE, 0, (LPARAM)changes.hContact[sel]); - - FillContactList(hwndDlg, &changes); - SetListSelection(hwnd, sel); - // Disable set default button - EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_SETDEFAULT),FALSE); - // Enable the 'Apply' button. - EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE); - - // repaint list - return TRUE; - case IDC_BTN_SETOFFLINE: - hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS); - sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected - InvalidateRect(hwnd, 0, TRUE); - changes.hOfflineContact = changes.hContact[sel]; - - FillContactList(hwndDlg, &changes); - SetListSelection(hwnd, sel); - // Disable set offline button - EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_SETOFFLINE),FALSE); - // Enable the 'Apply' button. - EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE); - - // repaint list - return TRUE; - case IDC_BTN_REM: - hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS); - sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected - changes.num_contacts--; - changes.hDeletedContacts[changes.num_deleted++] = changes.hContact[sel]; - if (changes.hDefaultContact == changes.hContact[sel]) { - if (changes.num_contacts > 0) { - changes.hDefaultContact = changes.hContact[0]; - str = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)changes.hDefaultContact, 0); - SetWindowText(GetDlgItem(hwndDlg,IDC_ED_DEFAULT),str); - } else { - changes.hDefaultContact = 0; - SetWindowText(GetDlgItem(hwndDlg,IDC_ED_DEFAULT),"None"); - } - - } - - for (i = sel; i < changes.num_contacts; i++) - changes.hContact[i] = changes.hContact[i + 1]; - FillContactList(hwndDlg, &changes); - // disable buttons - hwnd = GetDlgItem(hwndDlg, IDC_BTN_REM); - EnableWindow(hwnd, FALSE); - hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT); - EnableWindow(hwnd, FALSE); - hwnd = GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE); - EnableWindow(hwnd, FALSE); - hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP); - EnableWindow(hwnd, FALSE); - hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN); - EnableWindow(hwnd, FALSE); - // Enable the 'Apply' button. - EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE); - return TRUE; - case IDC_BTN_UP: - hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS); - sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected - - { - HANDLE temp = changes.hContact[sel]; - changes.hContact[sel] = changes.hContact[sel - 1]; - changes.hContact[sel - 1] = temp; - } - FillContactList(hwndDlg, &changes); - sel--; - SetListSelection(hwnd, sel); - - hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP); - EnableWindow(hwnd, (sel > 0)); - hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN); - EnableWindow(hwnd, (sel < changes.num_contacts - 1)); - // Enable the 'Apply' button. - EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE); - return TRUE; - case IDC_BTN_DOWN: - hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS); - sel=SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_FOCUSED|LVNI_SELECTED); // return item selected - - { - HANDLE temp = changes.hContact[sel]; - changes.hContact[sel] = changes.hContact[sel + 1]; - changes.hContact[sel + 1] = temp; - } - FillContactList(hwndDlg, &changes); - sel++; - SetListSelection(hwnd, sel); - - hwnd = GetDlgItem(hwndDlg, IDC_BTN_UP); - EnableWindow(hwnd, (sel > 0)); - hwnd = GetDlgItem(hwndDlg, IDC_BTN_DOWN); - EnableWindow(hwnd, (sel < changes.num_contacts - 1)); - // Enable the 'Apply' button. - EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE); - return TRUE; - case IDC_CHK_FORCEDEFAULT: - changes.force_default = IsDlgButtonChecked(hwndDlg, IDC_CHK_FORCEDEFAULT); - // Enable the 'Apply' button. - EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE); - return TRUE; + ApplyChanges(&changes); + + // Disable the 'Apply' button. + EnableWindow(GetDlgItem(hwndDlg, IDC_VALIDATE), FALSE); + break; + + case IDOK: + if ( IsWindowEnabled(GetDlgItem(hwndDlg, IDC_VALIDATE))) { // If there are changes that could be made, + if (changes.num_contacts == 0) { // do the work that would have be done if the 'Apply' button was clicked. + if (IDYES == MessageBox(hwndDlg, TranslateT(szDelMsg), TranslateT("Delete MetaContact?"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1)) { + Meta_Delete((WPARAM)changes.hMeta,0); + DestroyWindow(hwndDlg); + } + return TRUE; + } + ApplyChanges(&changes); + } + EndDialog(hwndDlg, IDOK); + return TRUE; + + case IDCANCEL: // Simply close the dialog + EndDialog(hwndDlg, IDCANCEL); + return TRUE; + + case IDC_BTN_SETDEFAULT: + hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS); + sel = ListView_GetNextItem(hwnd, -1, LVNI_FOCUSED | LVNI_SELECTED); + InvalidateRect(hwnd, 0, TRUE); + changes.hDefaultContact = changes.hContact[sel]; + SendMessage(hwndDlg, WMU_SETTITLE, 0, (LPARAM)changes.hContact[sel]); + + FillContactList(hwndDlg, &changes); + SetListSelection(hwnd, sel); + EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_SETDEFAULT),FALSE); + EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE); + return TRUE; + + case IDC_BTN_SETOFFLINE: + hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS); + sel = ListView_GetNextItem(hwnd, -1, LVNI_FOCUSED | LVNI_SELECTED); + InvalidateRect(hwnd, 0, TRUE); + changes.hOfflineContact = changes.hContact[sel]; + + FillContactList(hwndDlg, &changes); + SetListSelection(hwnd, sel); + EnableWindow(GetDlgItem(hwndDlg,IDC_BTN_SETOFFLINE),FALSE); + EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE); + return TRUE; + + case IDC_BTN_REM: + hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS); + sel = ListView_GetNextItem(hwnd, -1, LVNI_FOCUSED | LVNI_SELECTED); + changes.num_contacts--; + changes.hDeletedContacts[changes.num_deleted++] = changes.hContact[sel]; + if (changes.hDefaultContact == changes.hContact[sel]) { + if (changes.num_contacts > 0) { + changes.hDefaultContact = changes.hContact[0]; + TCHAR *str = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)changes.hDefaultContact, GCDNF_TCHAR); + SetWindowText(GetDlgItem(hwndDlg,IDC_ED_DEFAULT),str); } + else { + changes.hDefaultContact = 0; + SetWindowText(GetDlgItem(hwndDlg,IDC_ED_DEFAULT), _T("None")); + } + } + + for (i = sel; i < changes.num_contacts; i++) + changes.hContact[i] = changes.hContact[i + 1]; + FillContactList(hwndDlg, &changes); + + // disable buttons + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_REM), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_SETDEFAULT), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_SETOFFLINE), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UP), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DOWN), FALSE); + + // Enable the 'Apply' button. + EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE); + return TRUE; + + case IDC_BTN_UP: + hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS); + sel = ListView_GetNextItem(hwnd, -1, LVNI_FOCUSED | LVNI_SELECTED); + { + HANDLE temp = changes.hContact[sel]; + changes.hContact[sel] = changes.hContact[sel - 1]; + changes.hContact[sel - 1] = temp; + } + FillContactList(hwndDlg, &changes); + sel--; + SetListSelection(hwnd, sel); + + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UP), (sel > 0)); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DOWN), (sel < changes.num_contacts - 1)); + EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE); + return TRUE; + + case IDC_BTN_DOWN: + hwnd = GetDlgItem(hwndDlg, IDC_LST_CONTACTS); + sel = ListView_GetNextItem(hwnd, -1, LVNI_FOCUSED | LVNI_SELECTED); + { + HANDLE temp = changes.hContact[sel]; + changes.hContact[sel] = changes.hContact[sel + 1]; + changes.hContact[sel + 1] = temp; + } + FillContactList(hwndDlg, &changes); + sel++; + SetListSelection(hwnd, sel); + + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_UP), (sel > 0)); + EnableWindow(GetDlgItem(hwndDlg, IDC_BTN_DOWN), (sel < changes.num_contacts - 1)); + EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE); + return TRUE; + + case IDC_CHK_FORCEDEFAULT: + changes.force_default = IsDlgButtonChecked(hwndDlg, IDC_CHK_FORCEDEFAULT); + EnableWindow(GetDlgItem(hwndDlg,IDC_VALIDATE),TRUE); + return TRUE; } - break; - case WM_CLOSE: - DestroyWindow(hwndDlg); - return TRUE; - - case WM_DESTROY: - ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); - EndDialog(hwndDlg, IDCANCEL); - break; + } + break; + + case WM_CLOSE: + DestroyWindow(hwndDlg); + return TRUE; + + case WM_DESTROY: + ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); + EndDialog(hwndDlg, IDCANCEL); + break; } return FALSE; diff --git a/plugins/MetaContacts/src/icons.cpp b/plugins/MetaContacts/src/icons.cpp index 54f56e2a84..e56aab6195 100644 --- a/plugins/MetaContacts/src/icons.cpp +++ b/plugins/MetaContacts/src/icons.cpp @@ -65,10 +65,10 @@ void InitIcons(void) TCHAR path[MAX_PATH]; GetModuleFileName(hInstance, path, SIZEOF(path)); - SKINICONDESC sid = {0}; - sid.cbSize = sizeof(SKINICONDESC); + SKINICONDESC sid = { sizeof(sid) }; + sid.flags = SIDF_PATH_TCHAR; sid.pszSection = META_PROTO; - sid.pszDefaultFile = path; + sid.ptszDefaultFile = path; for (int i=0; i < SIZEOF(iconList); ++i) { sid.pszDescription = iconList[i].szDescr; diff --git a/plugins/MetaContacts/src/meta_main.cpp b/plugins/MetaContacts/src/meta_main.cpp index 5ff2d14878..cf98970716 100644 --- a/plugins/MetaContacts/src/meta_main.cpp +++ b/plugins/MetaContacts/src/meta_main.cpp @@ -164,7 +164,7 @@ extern "C" __declspec(dllexport) int Load(void) HANDLE hContact = db_find_first(); while (hContact != NULL) { char *proto = GetContactProto(hContact); - if (proto && !lstrcmp( META_PROTO, proto)) { + if (proto && !lstrcmpA( META_PROTO, proto)) { db_set_w(hContact, META_PROTO, "Status", ID_STATUS_OFFLINE); db_set_dw(hContact, META_PROTO, "IdleTS", 0); db_set_b(hContact, META_PROTO, "ContactCountCheck", 0); @@ -189,7 +189,7 @@ extern "C" __declspec(dllexport) int Load(void) if (Meta_SetHandles()) { // error - db corruption if ( !db_get_b(0, META_PROTO, "DisabledMessageShown", 0)) { - MessageBox(0, Translate("Error - Database corruption.\nPlugin disabled."), Translate("MetaContacts"), MB_OK | MB_ICONERROR); + MessageBox(0, TranslateT("Error - Database corruption.\nPlugin disabled."), TranslateT("MetaContacts"), MB_OK | MB_ICONERROR); db_set_b(0, META_PROTO, "DisabledMessageShown", 1); } //Meta_HideMetaContacts(TRUE); diff --git a/plugins/MetaContacts/src/meta_menu.cpp b/plugins/MetaContacts/src/meta_menu.cpp index 0d7d82d7a7..18f446b0cc 100644 --- a/plugins/MetaContacts/src/meta_menu.cpp +++ b/plugins/MetaContacts/src/meta_menu.cpp @@ -35,43 +35,34 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * @param wParam : \c HANDLE to the contact that has been chosen. * @param lParam : Allways set to 0. */ -INT_PTR Meta_Convert(WPARAM wParam,LPARAM lParam) + +INT_PTR Meta_Convert(WPARAM wParam, LPARAM lParam) { - HANDLE hMetaContact; DBVARIANT dbv; - char *group = 0;//, *proto; + char *group = 0; // Get some information about the selected contact. -// proto = GetContactProto(wParam,0); - if ( !DBGetContactSettingStringUtf((HANDLE)wParam,"CList","Group",&dbv)) { + if ( !db_get_utf((HANDLE)wParam, "CList", "Group", &dbv)) { group = _strdup(dbv.pszVal); db_free(&dbv); } // Create a new metacontact - hMetaContact = (HANDLE)CallService(MS_DB_CONTACT_ADD,0,0); - - // Add the info for the metacontact - if (hMetaContact) - { - + HANDLE hMetaContact = (HANDLE)CallService(MS_DB_CONTACT_ADD,0,0); + if (hMetaContact) { db_set_dw(hMetaContact, META_PROTO, META_ID,nextMetaID); db_set_dw(hMetaContact, META_PROTO, "NumContacts",0); - db_set_dw(NULL, META_PROTO, "NextMetaID",++nextMetaID); + db_set_dw(NULL, META_PROTO, "NextMetaID", ++nextMetaID); // Add the MetaContact protocol to the new meta contact - CallService( MS_PROTO_ADDTOCONTACT, ( WPARAM )hMetaContact, ( LPARAM )META_PROTO ); + CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hMetaContact, (LPARAM)META_PROTO); - if (group) { - if (ServiceExists(MS_DB_CONTACT_GETSETTING_STR)) - DBWriteContactSettingStringUtf(hMetaContact,"CList","Group",group); - else - db_set_s(hMetaContact,"CList","Group",group); - } + if (group) + db_set_utf(hMetaContact, "CList", "Group", group); // Assign the contact to the MetaContact just created (and make default). - if ( !Meta_Assign((HANDLE)wParam,hMetaContact,TRUE)) { - MessageBox(0,Translate("There was a problem in assigning the contact to the MetaContact"),Translate("Error"),MB_ICONEXCLAMATION); + if ( !Meta_Assign((HANDLE)wParam, hMetaContact, TRUE)) { + MessageBox(0, TranslateT("There was a problem in assigning the contact to the MetaContact"), TranslateT("Error"), MB_ICONEXCLAMATION); CallService(MS_DB_CONTACT_DELETE, (WPARAM)hMetaContact, 0); return 0; } @@ -79,14 +70,13 @@ INT_PTR Meta_Convert(WPARAM wParam,LPARAM lParam) // hide the contact if clist groups disabled (shouldn't create one anyway since menus disabled) if ( !Meta_IsEnabled()) db_set_b(hMetaContact, "CList", "Hidden", 1); - } // Update the graphics - CallService(MS_CLUI_SORTLIST,0,0); + CallService(MS_CLUI_SORTLIST, 0, 0); free(group); - return (int)hMetaContact; + return (INT_PTR)hMetaContact; } /** Display the 'Add to' Dialog @@ -97,10 +87,11 @@ INT_PTR Meta_Convert(WPARAM wParam,LPARAM lParam) * @param wParam : \c HANDLE to the contact that has been chosen. * @param lParam : Allways set to 0. */ + INT_PTR Meta_AddTo(WPARAM wParam, LPARAM lParam) { - HWND clui = (HWND)CallService(MS_CLUI_GETHWND,0,0); - DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_METASELECT),clui,&Meta_SelectDialogProc,(LPARAM)wParam); + HWND clui = (HWND)CallService(MS_CLUI_GETHWND, 0, 0); + DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_METASELECT), clui, &Meta_SelectDialogProc, (LPARAM)wParam); return 0; } @@ -113,8 +104,8 @@ INT_PTR Meta_AddTo(WPARAM wParam, LPARAM lParam) */ INT_PTR Meta_Edit(WPARAM wParam,LPARAM lParam) { - HWND clui = (HWND)CallService(MS_CLUI_GETHWND,0,0); - DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_METAEDIT),clui, Meta_EditDialogProc,(LPARAM)wParam); + HWND clui = (HWND)CallService(MS_CLUI_GETHWND, 0, 0); + DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_METAEDIT), clui, Meta_EditDialogProc, (LPARAM)wParam); return 0; } @@ -141,99 +132,88 @@ Triggers a db/contact/settingchanged event just before it returns. void Meta_RemoveContactNumber(HANDLE hMeta, int number) { - int i, num_contacts, default_contact; - HANDLE hContact;//, handle; - - char buffer[512], buffer2[512]; - - num_contacts = db_get_dw(hMeta, META_PROTO, "NumContacts", 0); - default_contact = db_get_dw(hMeta, META_PROTO, "Default", -1); - if (number >= 0 && number < num_contacts) { - - // get the handle - hContact = Meta_GetContactHandle(hMeta, number); - - // make sure this contact thinks it's part of this metacontact - if ((HANDLE)db_get_dw(hContact, META_PROTO, "Handle", 0) == hMeta) { + int num_contacts = db_get_dw(hMeta, META_PROTO, "NumContacts", 0); + int default_contact = db_get_dw(hMeta, META_PROTO, "Default", -1); + if (number < 0 && number >= num_contacts) + return; + + // get the handle + HANDLE hContact = Meta_GetContactHandle(hMeta, number); + + // make sure this contact thinks it's part of this metacontact + if ((HANDLE)db_get_dw(hContact, META_PROTO, "Handle", 0) == hMeta) { + // remove link to meta contact + db_unset(hContact, META_PROTO, "IsSubcontact"); + db_unset(hContact, META_PROTO, META_LINK); + db_unset(hContact, META_PROTO, "Handle"); + db_unset(hContact, META_PROTO, "ContactNumber"); + // unhide - must be done after removing link (see meta_services.c:Meta_ChangeStatus) + Meta_RestoreGroup(hContact); + db_unset(hContact, META_PROTO, "OldCListGroup"); + + // stop ignoring, if we were + if (options.suppress_status) + CallService(MS_IGNORE_UNIGNORE, (WPARAM)hContact, (WPARAM)IGNOREEVENT_USERONLINE); + } - // remove link to meta contact - db_unset(hContact, META_PROTO, "IsSubcontact"); - db_unset(hContact, META_PROTO, META_LINK); - db_unset(hContact, META_PROTO, "Handle"); - db_unset(hContact, META_PROTO, "ContactNumber"); - // unhide - must be done after removing link (see meta_services.c:Meta_ChangeStatus) - Meta_RestoreGroup(hContact); - db_unset(hContact, META_PROTO, "OldCListGroup"); + // each contact from 'number' upwards will be moved down one + // and the last one will be deleted + for (int i = number + 1; i < num_contacts; i++) + Meta_SwapContacts(hMeta, i, i-1); - // stop ignoring, if we were - if (options.suppress_status) - CallService(MS_IGNORE_UNIGNORE, (WPARAM)hContact, (WPARAM)IGNOREEVENT_USERONLINE); - } + // remove the last one + char buffer[512], idStr[20]; + _itoa(num_contacts-1, idStr, 10); + strcpy(buffer, "Protocol"); strcat(buffer, idStr); + db_unset(hMeta, META_PROTO, buffer); - // remove history from metacontact - //Meta_RemoveHistory(hMeta, hContact); + strcpy(buffer, "Status"); strcat(buffer, idStr); + db_unset(hMeta, META_PROTO, buffer); - // each contact from 'number' upwards will be moved down one - // and the last one will be deleted - for (i = number + 1; i < num_contacts; i++) { - Meta_SwapContacts(hMeta, i, i-1); - } + strcpy(buffer, "Handle"); strcat(buffer, idStr); + db_unset(hMeta, META_PROTO, buffer); - // remove the last one - strcpy(buffer, "Protocol"); - strcat(buffer, _itoa((num_contacts - 1), buffer2, 10)); - db_unset(hMeta, META_PROTO, buffer); - strcpy(buffer, "Status"); - strcat(buffer, _itoa((num_contacts - 1), buffer2, 10)); - db_unset(hMeta, META_PROTO, buffer); - strcpy(buffer, "Handle"); - strcat(buffer, _itoa((num_contacts - 1), buffer2, 10)); - db_unset(hMeta, META_PROTO, buffer); - strcpy(buffer, "StatusString"); - strcat(buffer, _itoa((num_contacts - 1), buffer2, 10)); - db_unset(hMeta, META_PROTO, buffer); - strcpy(buffer, "Login"); - strcat(buffer, _itoa((num_contacts - 1), buffer2, 10)); - db_unset(hMeta, META_PROTO, buffer); - strcpy(buffer, "Nick"); - strcat(buffer, _itoa((num_contacts - 1), buffer2, 10)); - db_unset(hMeta, META_PROTO, buffer); - strcpy(buffer, "CListName"); - strcat(buffer, _itoa((num_contacts - 1), buffer2, 10)); - db_unset(hMeta, META_PROTO, buffer); - - // if the default contact was equal to or greater than 'number', decrement it (and deal with ends) - if (default_contact >= number) { - default_contact--; - if (default_contact < 0) - default_contact = 0; - - db_set_dw(hMeta, META_PROTO, "Default", (DWORD)default_contact); - NotifyEventHooks(hEventDefaultChanged, (WPARAM)hMeta, (LPARAM)Meta_GetContactHandle(hMeta, default_contact)); - } - num_contacts--; - db_set_dw(hMeta, META_PROTO, "NumContacts", (DWORD)num_contacts); + strcpy(buffer, "StatusString"); strcat(buffer, idStr); + db_unset(hMeta, META_PROTO, buffer); - // fix nick - hContact = Meta_GetMostOnline(hMeta); - Meta_CopyContactNick(hMeta, hContact); + strcpy(buffer, "Login"); strcat(buffer, idStr); + db_unset(hMeta, META_PROTO, buffer); - // fix status - Meta_FixStatus(hMeta); + strcpy(buffer, "Nick"); strcat(buffer, idStr); + db_unset(hMeta, META_PROTO, buffer); - // fix avatar - hContact = Meta_GetMostOnlineSupporting(hMeta, PFLAGNUM_4, PF4_AVATARS); - if (hContact) { - PROTO_AVATAR_INFORMATIONT AI; + strcpy(buffer, "CListName"); strcat(buffer, idStr); + db_unset(hMeta, META_PROTO, buffer); - AI.cbSize = sizeof(AI); - AI.hContact = hMeta; - AI.format = PA_FORMAT_UNKNOWN; - _tcscpy(AI.filename, _T("X")); + // if the default contact was equal to or greater than 'number', decrement it (and deal with ends) + if (default_contact >= number) { + default_contact--; + if (default_contact < 0) + default_contact = 0; - if ((int)CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS) - DBWriteContactSettingTString(hMeta, "ContactPhoto", "File",AI.filename); - } + db_set_dw(hMeta, META_PROTO, "Default", (DWORD)default_contact); + NotifyEventHooks(hEventDefaultChanged, (WPARAM)hMeta, (LPARAM)Meta_GetContactHandle(hMeta, default_contact)); + } + num_contacts--; + db_set_dw(hMeta, META_PROTO, "NumContacts", (DWORD)num_contacts); + + // fix nick + hContact = Meta_GetMostOnline(hMeta); + Meta_CopyContactNick(hMeta, hContact); + + // fix status + Meta_FixStatus(hMeta); + + // fix avatar + hContact = Meta_GetMostOnlineSupporting(hMeta, PFLAGNUM_4, PF4_AVATARS); + if (hContact) { + PROTO_AVATAR_INFORMATIONT AI = { sizeof(AI) }; + AI.hContact = hMeta; + AI.format = PA_FORMAT_UNKNOWN; + _tcscpy(AI.filename, _T("X")); + + if ((int)CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS) + db_set_ts(hMeta, "ContactPhoto", "File",AI.filename); } } @@ -245,30 +225,29 @@ void Meta_RemoveContactNumber(HANDLE hMeta, int number) * @param wParam : \c HANDLE to the MetaContact to be deleted, or to the subcontact to be removed from the MetaContact * @param lParam : \c BOOL flag indicating whether to ask 'are you sure' when deleting a MetaContact */ + INT_PTR Meta_Delete(WPARAM wParam,LPARAM lParam) { DWORD metaID; - HANDLE hContact; - if ((metaID=db_get_dw((HANDLE)wParam, META_PROTO, META_ID,(DWORD)-1))!=(DWORD)-1) - {// The wParam is a metacontact + // The wParam is a metacontact + if ((metaID = db_get_dw((HANDLE)wParam, META_PROTO, META_ID, (DWORD)-1)) != (DWORD)-1) { if ( !lParam) { // check from recursion - see second half of this function - if (MessageBox((HWND)CallService(MS_CLUI_GETHWND,0,0),Translate("This will remove the MetaContact permanently.\n\nProceed Anyway?"), - Translate("Are you sure?"),MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2)!=IDYES) - { + if ( MessageBox((HWND)CallService(MS_CLUI_GETHWND,0,0), + TranslateT("This will remove the MetaContact permanently.\n\nProceed Anyway?"), + TranslateT("Are you sure?"),MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) != IDYES) return 0; - } } - hContact = db_find_first(); - while(hContact) - { // Scans the database to get all the contacts that have been previously linked to this MetaContact - if (db_get_dw(hContact, META_PROTO, META_LINK,(DWORD)-1)==metaID) - { // This contact is assigned to the MetaContact that will be deleted, clear the "MetaContacts" information + HANDLE hContact = db_find_first(); + while(hContact) { + // This contact is assigned to the MetaContact that will be deleted, clear the "MetaContacts" information + if ( db_get_dw(hContact, META_PROTO, META_LINK,(DWORD)-1) == metaID) { db_unset(hContact, META_PROTO, "IsSubcontact"); db_unset(hContact, META_PROTO, META_LINK); db_unset(hContact, META_PROTO, "Handle"); db_unset(hContact, META_PROTO, "ContactNumber"); + // unhide - must be done after removing link (see meta_services.c:Meta_ChangeStatus) Meta_RestoreGroup(hContact); db_unset(hContact, META_PROTO, "OldCListGroup"); @@ -279,35 +258,24 @@ INT_PTR Meta_Delete(WPARAM wParam,LPARAM lParam) } hContact = db_find_next(hContact); } - //db_unset((HANDLE)wParam, META_PROTO, META_ID); - //db_unset((HANDLE)wParam, META_PROTO, "NumContacts"); - //CallService(MS_PROTO_REMOVEFROMCONTACT,wParam,(LPARAM)META_PROTO); + NotifyEventHooks(hSubcontactsChanged, (WPARAM)wParam, 0); CallService(MS_DB_CONTACT_DELETE,wParam,0); } - else - {// The wParam is a simple contact - //if (lParam == 0) - // return 1; // The function has been called by the menu of a simple contact. Should not happen. - //else - {// The function has been called by the edit dialog - HANDLE hMeta = (HANDLE)db_get_dw((HANDLE)wParam, META_PROTO, "Handle", 0); - - - DWORD num_contacts = db_get_dw(hMeta, META_PROTO, "NumContacts", -1); - - if (num_contacts == 1) { - if (MessageBox(0,Translate("You are going to remove all the contacts associated with this MetaContact.\nThis will delete the MetaContact.\n\nProceed Anyway?"), - Translate("Delete MetaContact?"),MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON1)==IDYES) - { - // recurse - once - Meta_Delete((WPARAM)hMeta,(LPARAM)1); - } - return 0; - } + else { + HANDLE hMeta = (HANDLE)db_get_dw((HANDLE)wParam, META_PROTO, "Handle", 0); + + + DWORD num_contacts = db_get_dw(hMeta, META_PROTO, "NumContacts", -1); - Meta_RemoveContactNumber(hMeta, db_get_dw((HANDLE)wParam, META_PROTO, "ContactNumber", -1)); + if (num_contacts == 1) { + if (IDYES == MessageBox(0, TranslateT(szDelMsg), TranslateT("Delete MetaContact?"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON1)) + Meta_Delete((WPARAM)hMeta,(LPARAM)1); + + return 0; } + + Meta_RemoveContactNumber(hMeta, db_get_dw((HANDLE)wParam, META_PROTO, "ContactNumber", -1)); } return 0; } @@ -324,8 +292,8 @@ INT_PTR Meta_Default(WPARAM wParam,LPARAM lParam) { HANDLE hMeta; - if ((hMeta = (HANDLE)db_get_dw((HANDLE)wParam, META_PROTO, "Handle",0)) != 0) - { // the wParam is a subcontact + // the wParam is a subcontact + if ((hMeta = (HANDLE)db_get_dw((HANDLE)wParam, META_PROTO, "Handle",0)) != 0) { db_set_dw(hMeta, META_PROTO, "Default", (DWORD)Meta_GetContactNumber((HANDLE)wParam)); NotifyEventHooks(hEventDefaultChanged, (WPARAM)hMeta, (LPARAM)(HANDLE)wParam); } @@ -340,50 +308,27 @@ INT_PTR Meta_Default(WPARAM wParam,LPARAM lParam) * @param lParam : \c HWND to the clist window (This means the function has been called via the contact menu). */ + INT_PTR Meta_ForceDefault(WPARAM wParam,LPARAM lParam) { - if (db_get_dw((HANDLE)wParam, META_PROTO, META_ID, (DWORD)-1) != (DWORD)-1) - { // the wParam is a MetaContact - + // the wParam is a MetaContact + if (db_get_dw((HANDLE)wParam, META_PROTO, META_ID, (DWORD)-1) != (DWORD)-1) { BOOL current = db_get_b((HANDLE)wParam, META_PROTO, "ForceDefault", 0); current = !current; db_set_b((HANDLE)wParam, META_PROTO, "ForceDefault", (BYTE)current); db_set_dw((HANDLE)wParam, META_PROTO, "ForceSend", 0); - if (current) NotifyEventHooks(hEventForceSend, wParam, (LPARAM)Meta_GetContactHandle((HANDLE)wParam, db_get_dw((HANDLE)wParam, META_PROTO, "Default", -1))); - else NotifyEventHooks(hEventUnforceSend, wParam, 0); + if (current) + NotifyEventHooks(hEventForceSend, wParam, (LPARAM)Meta_GetContactHandle((HANDLE)wParam, db_get_dw((HANDLE)wParam, META_PROTO, "Default", -1))); + else + NotifyEventHooks(hEventUnforceSend, wParam, 0); } return 0; } -INT_PTR MenuFunc0(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 0);} -INT_PTR MenuFunc1(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 1);} -INT_PTR MenuFunc2(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 2);} -INT_PTR MenuFunc3(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 3);} -INT_PTR MenuFunc4(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 4);} -INT_PTR MenuFunc5(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 5);} -INT_PTR MenuFunc6(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 6);} -INT_PTR MenuFunc7(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 7);} -INT_PTR MenuFunc8(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 8);} -INT_PTR MenuFunc9(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 9);} -INT_PTR MenuFunc10(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 10);} -INT_PTR MenuFunc11(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 11);} -INT_PTR MenuFunc12(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 12);} -INT_PTR MenuFunc13(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 13);} -INT_PTR MenuFunc14(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 14);} -INT_PTR MenuFunc15(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 15);} -INT_PTR MenuFunc16(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 16);} -INT_PTR MenuFunc17(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 17);} -INT_PTR MenuFunc18(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 18);} -INT_PTR MenuFunc19(WPARAM wParam, LPARAM lParam) {return TranslateMenuFunc((HANDLE)wParam, 19);} - HANDLE hMenuContact[MAX_CONTACTS]; -INT_PTR TranslateMenuFunc(HANDLE hMeta, int contact_number) { - return Meta_ContactMenuFunc((WPARAM)hMeta, (LPARAM) contact_number); -} - /** Called when the context-menu of a contact is about to be displayed * * This will test which of the 4 menu item should be displayed, depending @@ -392,20 +337,19 @@ INT_PTR TranslateMenuFunc(HANDLE hMeta, int contact_number) { * @param wParam : \c HANDLE to the contact that triggered the event * @param lParam : Always set to 0; */ + int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam) { DBVARIANT dbv; HANDLE hContact; - char *proto; - char buf[512], buffer2[512]; + char buf[512], idStr[512]; int i, iconIndex; WORD status; CLISTMENUITEM mi = { sizeof(mi) }; mi.flags = CMIM_FLAGS; - if (db_get_dw((HANDLE)wParam, META_PROTO, META_ID,-1) != (DWORD)-1) - { + if (db_get_dw((HANDLE)wParam, META_PROTO, META_ID,-1) != (DWORD)-1) { int num_contacts, i; // save the mouse pos in case they open a subcontact menu @@ -413,103 +357,82 @@ int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam) // This is a MetaContact, show the edit, force default, and the delete menu, and hide the others CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuEdit, (LPARAM)&mi); - //mi.flags |= CMIM_NAME; - //if (db_get_b((HANDLE)wParam, META_PROTO, "ForceDefault", 0)) - // mi.pszName = Translate("Unforce Default"); - //else - // mi.pszName = Translate("Force Default"); - //CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuForceDefault, (LPARAM)&mi); + mi.flags = CMIM_FLAGS | CMIF_HIDDEN; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuAdd, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuConvert, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDefault, (LPARAM)&mi); + mi.flags = CMIM_FLAGS | CMIM_NAME | CMIF_HIDDEN; // we don't need delete - already in contact menu mi.pszName = Translate("Delete MetaContact"); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDelete, (LPARAM)&mi); - //show subcontact menu items num_contacts = db_get_dw((HANDLE)wParam, META_PROTO, "NumContacts", 0); for (i = 0; i < MAX_CONTACTS; i++) { if (i < num_contacts) { hContact = Meta_GetContactHandle((HANDLE)wParam, i); - proto = _strdup(GetContactProto(hContact)); - - if ( !proto) + char *szProto = GetContactProto(hContact); + if ( !szProto) status = ID_STATUS_OFFLINE; else - status = db_get_w(hContact, proto, "Status", ID_STATUS_OFFLINE); + status = db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE); if (options.menu_contact_label == DNT_UID) { strcpy(buf, "Login"); - strcat(buf, _itoa(i, buffer2, 10)); - - db_get((HANDLE)wParam, META_PROTO, buf,&dbv); - switch(dbv.type) - { - case DBVT_ASCIIZ: - mir_snprintf(buf,512,"%s",dbv.pszVal); - break; - case DBVT_BYTE: - mir_snprintf(buf,512,"%d",dbv.bVal); - break; - case DBVT_WORD: - mir_snprintf(buf,512,"%d",dbv.wVal); - break; - case DBVT_DWORD: - mir_snprintf(buf,512,"%d",dbv.dVal); - break; - default: - buf[0] = 0; + strcat(buf, _itoa(i, idStr, 10)); + + db_get((HANDLE)wParam, META_PROTO, buf, &dbv); + switch(dbv.type) { + case DBVT_ASCIIZ: + mir_snprintf(buf,512,"%s",dbv.pszVal); + break; + case DBVT_BYTE: + mir_snprintf(buf,512,"%d",dbv.bVal); + break; + case DBVT_WORD: + mir_snprintf(buf,512,"%d",dbv.wVal); + break; + case DBVT_DWORD: + mir_snprintf(buf,512,"%d",dbv.dVal); + break; + default: + buf[0] = 0; } db_free(&dbv); mi.pszName = buf; mi.flags = 0; - } else { - char *name = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, 0); - char *wname = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_UNICODE); - - if (wname && strncmp(name, wname, strlen(name)) != 0) { - mi.pszName = wname; - mi.flags = CMIF_UNICODE; - } - else { - mi.pszName = name; - mi.flags = 0; - } + } + else { + mi.ptszName = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR); + mi.flags = CMIF_TCHAR; } mi.flags |= CMIM_FLAGS | CMIM_NAME | CMIM_ICON; - //mi.hIcon = LoadSkinnedProtoIcon(proto, status); iconIndex = (int)CallService(MS_CLIST_GETCONTACTICON, (WPARAM)hContact, 0); mi.hIcon = ImageList_GetIcon((HIMAGELIST)CallService(MS_CLIST_GETICONSIMAGELIST, 0, 0), iconIndex, 0);; - free(proto); - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuContact[i], (LPARAM)&mi); DestroyIcon(mi.hIcon); - } else { + } + else { mi.flags = CMIM_FLAGS | CMIF_HIDDEN; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuContact[i], (LPARAM)&mi); } } // show hide nudge menu item -#define MS_NUDGE_SHOWMENU "NudgeShowMenu" -// wParam = char *szProto -// lParam = BOOL show - { - char serviceFunc[256]; - hContact = Meta_GetMostOnline((HANDLE)wParam); - mir_snprintf(serviceFunc, 256, "%s/SendNudge", GetContactProto(hContact)); - CallService(MS_NUDGE_SHOWMENU, (WPARAM)META_PROTO, (LPARAM)ServiceExists(serviceFunc)); - } + #define MS_NUDGE_SHOWMENU "NudgeShowMenu" + // wParam = char *szProto + // lParam = BOOL show + char serviceFunc[256]; + hContact = Meta_GetMostOnline((HANDLE)wParam); + mir_snprintf(serviceFunc, 256, "%s/SendNudge", GetContactProto(hContact)); + CallService(MS_NUDGE_SHOWMENU, (WPARAM)META_PROTO, (LPARAM)ServiceExists(serviceFunc)); } - else - {// This is a simple contact - if ( !Meta_IsEnabled()) - { + else { // This is a simple contact + if ( !Meta_IsEnabled()) { // groups disabled - all meta menu options hidden mi.flags = CMIM_FLAGS | CMIF_HIDDEN; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDefault, (LPARAM)&mi); @@ -517,26 +440,19 @@ int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam) CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuAdd, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuConvert, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuEdit, (LPARAM)&mi); - for (i = 0; i < MAX_CONTACTS; i++) { - mi.flags = CMIM_FLAGS | CMIF_HIDDEN; - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuContact[i], (LPARAM)&mi); - } - - } else if (db_get_dw((HANDLE)wParam, META_PROTO, META_LINK,(DWORD)-1)!=(DWORD)-1) { + } + else if (db_get_dw((HANDLE)wParam, META_PROTO, META_LINK,(DWORD)-1)!=(DWORD)-1) { // The contact is affected to a metacontact. CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDefault, (LPARAM)&mi); - mi.flags |= CMIM_NAME; - mi.pszName = (char *)Translate("Remove from MetaContact"); + mi.flags |= CMIM_NAME | CMIF_TCHAR; + mi.ptszName = (TCHAR*)TranslateT("Remove from MetaContact"); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDelete, (LPARAM)&mi); mi.flags = CMIM_FLAGS | CMIF_HIDDEN; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuAdd, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuConvert, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuEdit, (LPARAM)&mi); - for (i = 0; i < MAX_CONTACTS; i++) { - mi.flags = CMIM_FLAGS | CMIF_HIDDEN; - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuContact[i], (LPARAM)&mi); - } - } else { + } + else { // The contact is neutral CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuAdd, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuConvert, (LPARAM)&mi); @@ -544,14 +460,12 @@ int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam) CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuEdit, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDelete, (LPARAM)&mi); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDefault, (LPARAM)&mi); - for (i = 0; i < MAX_CONTACTS; i++) { - mi.flags = CMIM_FLAGS | CMIF_HIDDEN; - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuContact[i], (LPARAM)&mi); - } + } + + for (i = 0; i < MAX_CONTACTS; i++) { + mi.flags = CMIM_FLAGS | CMIF_HIDDEN; + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuContact[i], (LPARAM)&mi); } } return 0; } - - - diff --git a/plugins/MetaContacts/src/meta_options.cpp b/plugins/MetaContacts/src/meta_options.cpp index 0db9eed1b0..b4b5ecd330 100644 --- a/plugins/MetaContacts/src/meta_options.cpp +++ b/plugins/MetaContacts/src/meta_options.cpp @@ -33,18 +33,18 @@ MetaOptions options_changes; INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { HWND hw; - char buff[512]; + TCHAR buff[40]; switch ( msg ) { - case WM_INITDIALOG: { + case WM_INITDIALOG: TranslateDialogDefault( hwndDlg ); options_changes = options; - + CheckDlgButton(hwndDlg, IDC_CHK_SETDEFAULTRECV, options_changes.set_default_on_recv ? TRUE : FALSE); hw = GetDlgItem(hwndDlg, IDC_CHK_TEMPDEFAULT); EnableWindow(hw, options_changes.set_default_on_recv); CheckDlgButton(hwndDlg, IDC_CHK_TEMPDEFAULT, options_changes.temp_default ? TRUE : FALSE); - + CheckDlgButton(hwndDlg, IDC_CHK_ALWAYSUSEDEFAULT, options_changes.always_use_default ? TRUE : FALSE); CheckDlgButton(hwndDlg, IDC_CHK_SUPPRESSSTATUS, options_changes.suppress_status ? TRUE : FALSE); CheckDlgButton(hwndDlg, IDC_CHK_SUPPRESSPROTO, options_changes.suppress_proto ? TRUE : FALSE); @@ -75,156 +75,136 @@ INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara CheckDlgButton(hwndDlg, IDC_CHK_COPYHISTORY, options_changes.copy_subcontact_history ? TRUE : FALSE); hw = GetDlgItem(hwndDlg, IDC_ED_DAYS); - _itoa(options_changes.days_history, buff, 10); + _itot(options_changes.days_history, buff, 10); SetWindowText(hw, buff); - return TRUE; - } + case WM_COMMAND: if ( HIWORD( wParam ) == BN_CLICKED ) { switch( LOWORD( wParam )) { case IDC_CHK_SETDEFAULTRECV: options_changes.set_default_on_recv = IsDlgButtonChecked(hwndDlg, IDC_CHK_SETDEFAULTRECV); - hw = GetDlgItem(hwndDlg, IDC_CHK_TEMPDEFAULT); - EnableWindow(hw, options_changes.set_default_on_recv); - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_TEMPDEFAULT), options_changes.set_default_on_recv); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_CHK_TEMPDEFAULT: - hw = GetDlgItem(hwndDlg, IDC_CHK_TEMPDEFAULT); options_changes.temp_default = IsDlgButtonChecked(hwndDlg, IDC_CHK_TEMPDEFAULT); - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_CHK_ALWAYSUSEDEFAULT: - hw = GetDlgItem(hwndDlg, IDC_CHK_ALWAYSUSEDEFAULT); options_changes.always_use_default = IsDlgButtonChecked(hwndDlg, IDC_CHK_ALWAYSUSEDEFAULT); - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_CHK_SUPPRESSSTATUS: - hw = GetDlgItem(hwndDlg, IDC_CHK_SUPPRESSSTATUS); options_changes.suppress_status = IsDlgButtonChecked(hwndDlg, IDC_CHK_SUPPRESSSTATUS); - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_CHK_SUPPRESSPROTO: - hw = GetDlgItem(hwndDlg, IDC_CHK_SUPPRESSPROTO); options_changes.suppress_proto = IsDlgButtonChecked(hwndDlg, IDC_CHK_SUPPRESSPROTO); - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_CHK_COPYHISTORY: - hw = GetDlgItem(hwndDlg, IDC_CHK_COPYHISTORY); options_changes.copy_subcontact_history = IsDlgButtonChecked(hwndDlg, IDC_CHK_COPYHISTORY); - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_CHK_METAHISTORY: - hw = GetDlgItem(hwndDlg, IDC_CHK_METAHISTORY); options_changes.metahistory = IsDlgButtonChecked(hwndDlg, IDC_CHK_METAHISTORY); - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_CHK_SUBHISTORY: - hw = GetDlgItem(hwndDlg, IDC_CHK_SUBHISTORY); options_changes.subhistory = IsDlgButtonChecked(hwndDlg, IDC_CHK_SUBHISTORY); - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_CHK_COPYDATA: - hw = GetDlgItem(hwndDlg, IDC_CHK_COPYDATA); options_changes.copydata = IsDlgButtonChecked(hwndDlg, IDC_CHK_COPYDATA); - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_RAD_UID: - hw = GetDlgItem(hwndDlg, IDC_RAD_UID); if (IsDlgButtonChecked(hwndDlg, IDC_RAD_UID)) { options_changes.menu_contact_label = DNT_UID; CheckDlgButton(hwndDlg, IDC_RAD_DID, FALSE); } - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_RAD_DID: - hw = GetDlgItem(hwndDlg, IDC_RAD_DID); if (IsDlgButtonChecked(hwndDlg, IDC_RAD_DID)) { options_changes.menu_contact_label = DNT_DID; CheckDlgButton(hwndDlg, IDC_RAD_UID, FALSE); } - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_RAD_MSG: - hw = GetDlgItem(hwndDlg, IDC_RAD_MSG); if (IsDlgButtonChecked(hwndDlg, IDC_RAD_MSG)) { options_changes.menu_function = FT_MSG; CheckDlgButton(hwndDlg, IDC_RAD_MENU, FALSE); CheckDlgButton(hwndDlg, IDC_RAD_INFO, FALSE); } - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_RAD_MENU: - hw = GetDlgItem(hwndDlg, IDC_RAD_MENU); if (IsDlgButtonChecked(hwndDlg, IDC_RAD_MENU)) { options_changes.menu_function = FT_MENU; CheckDlgButton(hwndDlg, IDC_RAD_MSG, FALSE); CheckDlgButton(hwndDlg, IDC_RAD_INFO, FALSE); } - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_RAD_INFO: - hw = GetDlgItem(hwndDlg, IDC_RAD_INFO); if (IsDlgButtonChecked(hwndDlg, IDC_RAD_INFO)) { options_changes.menu_function = FT_INFO; CheckDlgButton(hwndDlg, IDC_RAD_MSG, FALSE); CheckDlgButton(hwndDlg, IDC_RAD_MENU, FALSE); } - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_RAD_NICK: - hw = GetDlgItem(hwndDlg, IDC_RAD_NICK); if (IsDlgButtonChecked(hwndDlg, IDC_RAD_NICK)) { options_changes.clist_contact_name = CNNT_NICK; CheckDlgButton(hwndDlg, IDC_RAD_NAME, FALSE); } - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_RAD_NAME: - hw = GetDlgItem(hwndDlg, IDC_RAD_NAME); if (IsDlgButtonChecked(hwndDlg, IDC_RAD_NAME)) { options_changes.clist_contact_name = CNNT_DISPLAYNAME; CheckDlgButton(hwndDlg, IDC_RAD_NICK, FALSE); } - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; case IDC_CHK_SUBWINDOW: - hw = GetDlgItem(hwndDlg, IDC_CHK_SUBWINDOW); options_changes.subcontact_windows = IsDlgButtonChecked(hwndDlg, IDC_CHK_SUBWINDOW); if (options_changes.subcontact_windows) { - hw = GetDlgItem(hwndDlg, IDC_CHK_METAHISTORY); - EnableWindow(hw, TRUE); - hw = GetDlgItem(hwndDlg, IDC_CHK_SUBHISTORY); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_METAHISTORY), TRUE); CheckDlgButton(hwndDlg, IDC_CHK_SUBHISTORY, TRUE); - EnableWindow(hw, FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_SUBHISTORY), FALSE); options_changes.subhistory = TRUE; } else { - hw = GetDlgItem(hwndDlg, IDC_CHK_SUBHISTORY); - EnableWindow(hw, TRUE); - hw = GetDlgItem(hwndDlg, IDC_CHK_METAHISTORY); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_SUBHISTORY), TRUE); CheckDlgButton(hwndDlg, IDC_CHK_METAHISTORY, TRUE); - EnableWindow(hw, FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_METAHISTORY), FALSE); options_changes.metahistory = TRUE; } - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; + case IDC_CHK_LOCKHANDLE: options_changes.lockHandle = IsDlgButtonChecked(hwndDlg, IDC_CHK_LOCKHANDLE); - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; } - } else if ( HIWORD( wParam ) == EN_CHANGE && ( HWND )lParam == GetFocus()) { - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + } + else if ( HIWORD( wParam ) == EN_CHANGE && ( HWND )lParam == GetFocus()) { + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); } break; case WM_NOTIFY: if (((LPNMHDR)lParam)->code == PSN_APPLY ) { hw = GetDlgItem(hwndDlg, IDC_ED_DAYS); - GetWindowText(hw, buff, 512); - if (strlen(buff) > 0) - options_changes.days_history = atoi(buff); + GetWindowText(hw, buff, SIZEOF(buff)); + if (buff[0] != 0) + options_changes.days_history = _ttoi(buff); options = options_changes; Meta_WriteOptions(&options); @@ -239,7 +219,8 @@ INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara return FALSE; } -int Meta_WriteOptions(MetaOptions *opt) { +int Meta_WriteOptions(MetaOptions *opt) +{ db_set_b(NULL, META_PROTO, "SetDefaultOnRecv", (BYTE)(opt->set_default_on_recv ? 1 : 0)); db_set_b(NULL, META_PROTO, "TempDefault", (BYTE)(opt->temp_default ? 1 : 0)); db_set_b(NULL, META_PROTO, "AlwaysUseDefault", (BYTE)(opt->always_use_default ? 1 : 0)); @@ -271,7 +252,8 @@ int Meta_WriteOptions(MetaOptions *opt) { db_set_b(NULL, META_PROTO, "UseProtoRecv", (BYTE)(opt->use_proto_recv ? 1 : 0)); } -int Meta_ReadOptions(MetaOptions *opt) { +int Meta_ReadOptions(MetaOptions *opt) +{ opt->set_default_on_recv = (db_get_b(NULL, META_PROTO, "SetDefaultOnRecv", 1) == 1 ? TRUE : FALSE); opt->temp_default = (db_get_b(NULL, META_PROTO, "TempDefault", 1) == 1 ? TRUE : FALSE); opt->always_use_default = (db_get_b(NULL, META_PROTO, "AlwaysUseDefault", 1) == 1 ? TRUE : FALSE); @@ -288,7 +270,7 @@ int Meta_ReadOptions(MetaOptions *opt) { opt->lockHandle = (db_get_b(NULL, META_PROTO, "LockHandle", 0) == 1 ? TRUE : FALSE); opt->flash_meta_message_icon = (db_get_b(NULL, META_PROTO, "MetaMessageIcon", 1) == 1 ? TRUE : FALSE); opt->copy_userinfo = (db_get_b(NULL, META_PROTO, "CopyUserInfo", 1) == 1 ? TRUE : FALSE); - + if ( !opt->subcontact_windows) opt->metahistory = TRUE; else @@ -316,7 +298,8 @@ int Meta_ReadOptions(MetaOptions *opt) { #define ID_STATUS_OUTTOLUNCH 40080 ->3 */ -int GetDefaultPrio(int status) { +int GetDefaultPrio(int status) +{ switch( status ) { case ID_STATUS_OFFLINE: return 8; case ID_STATUS_AWAY: return 4; @@ -338,39 +321,37 @@ typedef struct { ProtoStatusPrio *priorities = 0; -int GetRealPriority(char *proto, int status) { +int GetRealPriority(char *proto, int status) +{ char szSetting[256]; if ( !proto) { mir_snprintf(szSetting, 256, "DefaultPrio_%d", status); return db_get_w(0, META_PROTO, szSetting, GetDefaultPrio(status)); - } else { - int prio; - mir_snprintf(szSetting, 256, "ProtoPrio_%s%d", proto, status); - prio = db_get_w(0, META_PROTO, szSetting, 0xFFFF); - if (prio == 0xFFFF) { - mir_snprintf(szSetting, 256, "DefaultPrio_%d", status); - return db_get_w(0, META_PROTO, szSetting, GetDefaultPrio(status)); - } else - return prio; } - return 0xFFFF; + + mir_snprintf(szSetting, 256, "ProtoPrio_%s%d", proto, status); + int prio = db_get_w(0, META_PROTO, szSetting, 0xFFFF); + if (prio == 0xFFFF) { + mir_snprintf(szSetting, 256, "DefaultPrio_%d", status); + return db_get_w(0, META_PROTO, szSetting, GetDefaultPrio(status)); + } + return prio; } -void ReadPriorities() { - int num_protocols; - PROTOACCOUNT **pppDesc; +void ReadPriorities() +{ char szSetting[256]; - ProtoStatusPrio * current; - int i, j; - + int num_protocols, i, j; + PROTOACCOUNT **pppDesc; ProtoEnumAccounts(&num_protocols, &pppDesc); - current = priorities = (ProtoStatusPrio *)malloc((num_protocols + 1) * sizeof(ProtoStatusPrio)); + ProtoStatusPrio *current = priorities = (ProtoStatusPrio *)malloc((num_protocols + 1) * sizeof(ProtoStatusPrio)); for (i = ID_STATUS_OFFLINE; i <= ID_STATUS_OUTTOLUNCH; i++) { mir_snprintf(szSetting, 256, "DefaultPrio_%d", i); current->def[i - ID_STATUS_OFFLINE] = TRUE; current->prio[i - ID_STATUS_OFFLINE] = db_get_w(0, META_PROTO, szSetting, GetDefaultPrio(i)); } + for (i = 0; i < num_protocols; i++) { current = priorities + (i + 1); for (j = ID_STATUS_OFFLINE; j <= ID_STATUS_OUTTOLUNCH; j++) { @@ -381,13 +362,14 @@ void ReadPriorities() { } } -void WritePriorities() { - int num_protocols; - PROTOACCOUNT **pppDesc; +void WritePriorities() +{ char szSetting[256]; - ProtoStatusPrio * current = priorities; + ProtoStatusPrio *current = priorities; int i, j; + int num_protocols; + PROTOACCOUNT **pppDesc; ProtoEnumAccounts(&num_protocols, &pppDesc); for (i = ID_STATUS_OFFLINE; i <= ID_STATUS_OUTTOLUNCH; i++) { @@ -409,54 +391,49 @@ void WritePriorities() { } } -int GetIsDefault(int proto_index, int status) { +int GetIsDefault(int proto_index, int status) +{ return (priorities + (proto_index + 1))->def[status - ID_STATUS_OFFLINE]; } -BOOL GetPriority(int proto_index, int status) { - ProtoStatusPrio * current; - if (proto_index == -1) { +BOOL GetPriority(int proto_index, int status) +{ + if (proto_index == -1) + return priorities->prio[status - ID_STATUS_OFFLINE]; + + ProtoStatusPrio *current = priorities + (proto_index + 1); + if (current->def[status - ID_STATUS_OFFLINE]) current = priorities; - return current->prio[status - ID_STATUS_OFFLINE]; - } else { - current = priorities + (proto_index + 1); - if (current->def[status - ID_STATUS_OFFLINE]) { - current = priorities; - } - return current->prio[status - ID_STATUS_OFFLINE]; - } - return 0xFFFF; + + return current->prio[status - ID_STATUS_OFFLINE]; } -void SetPriority(int proto_index, int status, BOOL def, int prio) { - ProtoStatusPrio * current; +void SetPriority(int proto_index, int status, BOOL def, int prio) +{ if (prio < 0) prio = 0; if (prio > 500) prio = 500; - if (proto_index == -1) { - current = priorities; - current->prio[status - ID_STATUS_OFFLINE] = prio; - } else { - current = priorities + (proto_index + 1); + if (proto_index == -1) + priorities->prio[status - ID_STATUS_OFFLINE] = prio; + else { + ProtoStatusPrio *current = priorities + (proto_index + 1); current->def[status - ID_STATUS_OFFLINE] = def; - if ( !def) { + if ( !def) current->prio[status - ID_STATUS_OFFLINE] = prio; - } } } -void ResetPriorities() { - int num_protocols; +void ResetPriorities() +{ + int i, j, num_protocols; PROTOACCOUNT **pppDesc; - ProtoStatusPrio * current; - int i, j; - ProtoEnumAccounts(&num_protocols, &pppDesc); - current = priorities; + ProtoStatusPrio *current = priorities; for (i = ID_STATUS_OFFLINE; i <= ID_STATUS_OUTTOLUNCH; i++) { current->def[i - ID_STATUS_OFFLINE] = TRUE; current->prio[i - ID_STATUS_OFFLINE] = GetDefaultPrio(i); } + for (i = 0; i < num_protocols; i++) { current = priorities + (i + 1); for (j = ID_STATUS_OFFLINE; j <= ID_STATUS_OUTTOLUNCH; j++) { @@ -471,6 +448,7 @@ void ResetPriorities() { INT_PTR CALLBACK DlgProcOptsPriorities(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { HWND hw; + int sel; switch ( msg ) { case WM_INITDIALOG: @@ -480,13 +458,12 @@ INT_PTR CALLBACK DlgProcOptsPriorities(HWND hwndDlg, UINT msg, WPARAM wParam, LP { int num_protocols; PROTOACCOUNT **pppDesc; - int i, index; - ProtoEnumAccounts(&num_protocols, &pppDesc); + hw = GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL); - index = SendMessage(hw, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)Translate("")); + int index = SendMessage(hw, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)Translate("")); SendMessage(hw, CB_SETITEMDATA, (WPARAM)index, -1); - for (i = 0; i < num_protocols; i++) { + for (int i = 0; i < num_protocols; i++) { if (strcmp(pppDesc[i]->szModuleName, META_PROTO) != 0) { index = SendMessage(hw, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)pppDesc[i]->szModuleName); SendMessage(hw, CB_SETITEMDATA, (WPARAM)index, i); @@ -498,105 +475,106 @@ INT_PTR CALLBACK DlgProcOptsPriorities(HWND hwndDlg, UINT msg, WPARAM wParam, LP SendMessage(hwndDlg, WMU_FILLPRIODATA, 0, 0); } return FALSE; + case WMU_FILLPRIODATA: - { - int sel = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETCURSEL, 0, 0); + sel = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETCURSEL, 0, 0); + if (sel != -1) { + int index = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETITEMDATA, (WPARAM)sel, 0); + sel = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_STATUS), CB_GETCURSEL, 0, 0); if (sel != -1) { - int index = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETITEMDATA, (WPARAM)sel, 0); - sel = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_STATUS), CB_GETCURSEL, 0, 0); - if (sel != -1) { - int status = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_STATUS), CB_GETITEMDATA, (WPARAM)sel, 0); - SetDlgItemInt(hwndDlg, IDC_ED_PRIORITY, GetPriority(index, status), FALSE); - if (index == -1) { + int status = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_STATUS), CB_GETITEMDATA, (WPARAM)sel, 0); + SetDlgItemInt(hwndDlg, IDC_ED_PRIORITY, GetPriority(index, status), FALSE); + if (index == -1) { + EnableWindow(GetDlgItem(hwndDlg, IDC_ED_PRIORITY), TRUE); + EnableWindow(GetDlgItem(hwndDlg, IDC_SP_PRIORITY), TRUE); + CheckDlgButton(hwndDlg, IDC_CHK_DEFAULT, TRUE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_DEFAULT), FALSE); + } + else { + if (GetIsDefault(index, status)) { + CheckDlgButton(hwndDlg, IDC_CHK_DEFAULT, TRUE); + EnableWindow(GetDlgItem(hwndDlg, IDC_ED_PRIORITY), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_SP_PRIORITY), FALSE); + } + else { + CheckDlgButton(hwndDlg, IDC_CHK_DEFAULT, FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_ED_PRIORITY), TRUE); EnableWindow(GetDlgItem(hwndDlg, IDC_SP_PRIORITY), TRUE); - CheckDlgButton(hwndDlg, IDC_CHK_DEFAULT, TRUE); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_DEFAULT), FALSE); - } else { - if (GetIsDefault(index, status)) { - CheckDlgButton(hwndDlg, IDC_CHK_DEFAULT, TRUE); - EnableWindow(GetDlgItem(hwndDlg, IDC_ED_PRIORITY), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_SP_PRIORITY), FALSE); - } else { - CheckDlgButton(hwndDlg, IDC_CHK_DEFAULT, FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_ED_PRIORITY), TRUE); - EnableWindow(GetDlgItem(hwndDlg, IDC_SP_PRIORITY), TRUE); - } - - EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_DEFAULT), TRUE); } + + EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_DEFAULT), TRUE); } } } return TRUE; + case WMU_FILLSTATUSCMB: - { - int sel = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETCURSEL, 0, 0); - if (sel != -1) { - int index = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETITEMDATA, (WPARAM)sel, 0); - HWND hw = GetDlgItem(hwndDlg, IDC_CMB_STATUS); - SendMessage(hw, CB_RESETCONTENT, 0, 0); - if (index == -1) { - int i; - for (i = ID_STATUS_OFFLINE; i <= ID_STATUS_OUTTOLUNCH; i++) { - index = SendMessage(hw, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)(char *)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, i, 0)); - SendMessage(hw, CB_SETITEMDATA, (WPARAM)index, i); - } - } else { - int num_protocols, caps, i; - PROTOACCOUNT **pppDesc; - ProtoEnumAccounts(&num_protocols, &pppDesc); + sel = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETCURSEL, 0, 0); + if (sel != -1) { + int index = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETITEMDATA, (WPARAM)sel, 0); + HWND hw = GetDlgItem(hwndDlg, IDC_CMB_STATUS); + SendMessage(hw, CB_RESETCONTENT, 0, 0); + if (index == -1) { + for (int i = ID_STATUS_OFFLINE; i <= ID_STATUS_OUTTOLUNCH; i++) { + index = SendMessage(hw, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)(char *)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, i, 0)); + SendMessage(hw, CB_SETITEMDATA, (WPARAM)index, i); + } + } + else { + int num_protocols; + PROTOACCOUNT **pppDesc; + ProtoEnumAccounts(&num_protocols, &pppDesc); - caps = CallProtoService(pppDesc[index]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0); + int caps = CallProtoService(pppDesc[index]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0); - for (i = ID_STATUS_OFFLINE; i <= ID_STATUS_OUTTOLUNCH; i++) { - if (caps & Proto_Status2Flag(i)) { - index = SendMessage(hw, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)(char *)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, i, 0)); - SendMessage(hw, CB_SETITEMDATA, (WPARAM)index, i); - } + for (int i = ID_STATUS_OFFLINE; i <= ID_STATUS_OUTTOLUNCH; i++) { + if (caps & Proto_Status2Flag(i)) { + index = SendMessage(hw, CB_INSERTSTRING, (WPARAM)-1, (LPARAM)(char *)CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, i, 0)); + SendMessage(hw, CB_SETITEMDATA, (WPARAM)index, i); } } - SendMessage(hw, CB_SETCURSEL, 0, 0); - SendMessage(hwndDlg, WMU_FILLPRIODATA, 0, 0); } + SendMessage(hw, CB_SETCURSEL, 0, 0); + SendMessage(hwndDlg, WMU_FILLPRIODATA, 0, 0); } return TRUE; + case WM_COMMAND: if ( HIWORD( wParam ) == BN_CLICKED ) { switch( LOWORD( wParam )) { case IDC_CHK_DEFAULT: - { - int sel = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETCURSEL, 0, 0); + sel = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETCURSEL, 0, 0); + if (sel != -1) { + int index = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETITEMDATA, (WPARAM)sel, 0); + sel = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_STATUS), CB_GETCURSEL, 0, 0); if (sel != -1) { - int index = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETITEMDATA, (WPARAM)sel, 0); - sel = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_STATUS), CB_GETCURSEL, 0, 0); - if (sel != -1) { - BOOL checked = IsDlgButtonChecked(hwndDlg, IDC_CHK_DEFAULT); - int status = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_STATUS), CB_GETITEMDATA, (WPARAM)sel, 0); - if (checked) { - SetPriority(index, status, TRUE, 0); - SetDlgItemInt(hwndDlg, IDC_ED_PRIORITY, GetPriority(index, status), FALSE); - } else { - SetPriority(index, status, FALSE, GetDlgItemInt(hwndDlg, IDC_ED_PRIORITY, 0, FALSE)); - } - EnableWindow(GetDlgItem(hwndDlg, IDC_ED_PRIORITY), !checked); - EnableWindow(GetDlgItem(hwndDlg, IDC_SP_PRIORITY), !checked); - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + BOOL checked = IsDlgButtonChecked(hwndDlg, IDC_CHK_DEFAULT); + int status = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_STATUS), CB_GETITEMDATA, (WPARAM)sel, 0); + if (checked) { + SetPriority(index, status, TRUE, 0); + SetDlgItemInt(hwndDlg, IDC_ED_PRIORITY, GetPriority(index, status), FALSE); } + else SetPriority(index, status, FALSE, GetDlgItemInt(hwndDlg, IDC_ED_PRIORITY, 0, FALSE)); + + EnableWindow(GetDlgItem(hwndDlg, IDC_ED_PRIORITY), !checked); + EnableWindow(GetDlgItem(hwndDlg, IDC_SP_PRIORITY), !checked); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); } } break; + case IDC_BTN_RESET: ResetPriorities(); SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_SETCURSEL, 0, 0); SendMessage(hwndDlg, WMU_FILLSTATUSCMB, 0, 0); SendMessage(hwndDlg, WMU_FILLPRIODATA, 0, 0); - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; } } + if ( HIWORD( wParam ) == EN_CHANGE && LOWORD(wParam) == IDC_ED_PRIORITY && ( HWND )lParam == GetFocus()) { - int sel = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETCURSEL, 0, 0); + sel = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETCURSEL, 0, 0); if (sel != -1) { int index = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_PROTOCOL), CB_GETITEMDATA, (WPARAM)sel, 0); sel = SendMessage(GetDlgItem(hwndDlg, IDC_CMB_STATUS), CB_GETCURSEL, 0, 0); @@ -606,7 +584,7 @@ INT_PTR CALLBACK DlgProcOptsPriorities(HWND hwndDlg, UINT msg, WPARAM wParam, LP SetPriority(index, status, FALSE, prio); if (prio != GetPriority(index, status)) SetDlgItemInt(hwndDlg, IDC_ED_PRIORITY, GetPriority(index, status), FALSE); - SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 ); + SendMessage( GetParent(hwndDlg), PSM_CHANGED, 0, 0); } } } @@ -621,7 +599,7 @@ INT_PTR CALLBACK DlgProcOptsPriorities(HWND hwndDlg, UINT msg, WPARAM wParam, LP } } break; - + case WM_NOTIFY: if (((LPNMHDR)lParam)->code == PSN_APPLY ) { WritePriorities(); diff --git a/plugins/MetaContacts/src/meta_services.cpp b/plugins/MetaContacts/src/meta_services.cpp index d205ff9a6e..6e8318b0af 100644 --- a/plugins/MetaContacts/src/meta_services.cpp +++ b/plugins/MetaContacts/src/meta_services.cpp @@ -571,7 +571,7 @@ int Meta_HandleACK(WPARAM wParam, LPARAM lParam) //if ( !db_get(AI.hContact, "ContactPhoto", "File", &dbv)) { if ( !db_get(ack->hContact, "ContactPhoto", "File", &dbv)) { - DBWriteContactSettingTString(hUser, "ContactPhoto", "File", dbv.ptszVal); + db_set_ts(hUser, "ContactPhoto", "File", dbv.ptszVal); db_free(&dbv); } @@ -605,11 +605,11 @@ static DWORD sttHideContacts( BOOL param ) int Meta_SettingChanged(WPARAM wParam, LPARAM lParam) { DBCONTACTWRITESETTING *dcws = (DBCONTACTWRITESETTING *)lParam; - char buffer[512], buffer2[512]; + char buffer[512], szId[40]; + TCHAR buffer2[512]; int contact_number; HANDLE hMeta, most_online; - // hide metacontacts when groups disabled if (wParam == 0 && ((strcmp(dcws->szModule, "CList") == 0 && strcmp(dcws->szSetting, "UseGroups") == 0) @@ -639,20 +639,17 @@ int Meta_SettingChanged(WPARAM wParam, LPARAM lParam) Meta_SuppressStatus(options.suppress_status); } - if (wParam == 0 - && strcmp(dcws->szModule, "CListGroups") == 0 && dcws->value.type != DBVT_DELETED && strcmp(dcws->value.pszVal, META_HIDDEN_GROUP) == 0) + if (wParam == 0 && strcmp(dcws->szModule, "CListGroups") == 0 && dcws->value.type != DBVT_DELETED && strcmp(dcws->value.pszVal, META_HIDDEN_GROUP) == 0) { // someone is creating our hidden group!! - } // from here on, we're just interested in contact settings if (wParam == 0) return 0; - if ((hMeta=(HANDLE)db_get_dw((HANDLE)wParam, META_PROTO, "Handle",0))!=0 - && CallService(MS_DB_CONTACT_IS, (WPARAM)hMeta, 0)) // just to be safe - - { // This contact is attached to a MetaContact. + if ((hMeta=(HANDLE)db_get_dw((HANDLE)wParam, META_PROTO, "Handle",0))!=0 && CallService(MS_DB_CONTACT_IS, (WPARAM)hMeta, 0)) // just to be safe + { + // This contact is attached to a MetaContact. contact_number = Meta_GetContactNumber((HANDLE)wParam); if (contact_number == -1) return 0; // exit - db corruption @@ -667,210 +664,190 @@ int Meta_SettingChanged(WPARAM wParam, LPARAM lParam) db_unset((HANDLE)wParam, META_PROTO, "OldCListGroup"); db_set_s((HANDLE)wParam, "CList", "Group", META_HIDDEN_GROUP); } - } else + } + else if ( !strcmp(dcws->szSetting, "IP")) { + if (dcws->value.type == DBVT_DWORD) + db_set_dw(hMeta, META_PROTO, "IP", dcws->value.dVal); + else + db_unset(hMeta, META_PROTO, "IP"); + } + else if ( !strcmp(dcws->szSetting, "RealIP")) { + if (dcws->value.type == DBVT_DWORD) + db_set_dw(hMeta, META_PROTO, "RealIP", dcws->value.dVal); + else + db_unset(hMeta, META_PROTO, "RealIP"); - // copy IP - if ( !strcmp(dcws->szSetting, "IP")) { - if (dcws->value.type == DBVT_DWORD) - db_set_dw(hMeta, META_PROTO, "IP", dcws->value.dVal); - else - db_unset(hMeta, META_PROTO, "IP"); - } else + } + else if ( !strcmp(dcws->szSetting, "ListeningTo")) { + switch(dcws->value.type) { + case DBVT_ASCIIZ: + db_set_s(hMeta, META_PROTO, "ListeningTo", dcws->value.pszVal); + break; + case DBVT_UTF8: + db_set_utf(hMeta, META_PROTO, "ListeningTo", dcws->value.pszVal); + break; + case DBVT_WCHAR: + DBWriteContactSettingWString(hMeta, META_PROTO, "ListeningTo", dcws->value.pwszVal); + break; + case DBVT_DELETED: + db_unset(hMeta, META_PROTO, "ListeningTo"); + break; + } + } + else if ( !strcmp(dcws->szSetting, "Nick") && !dcws->value.type == DBVT_DELETED) { + DBVARIANT dbv; + HANDLE most_online; + + // subcontact nick has changed - update metacontact + strcpy(buffer, "Nick"); + strcat(buffer, _itoa(contact_number, szId, 10)); + MyDBWriteContactSetting(hMeta, META_PROTO, buffer, &dcws->value); + + if (Mydb_get((HANDLE)wParam, "CList", "MyHandle", &dbv)) { + strcpy(buffer, "CListName"); + strcat(buffer, _itoa(contact_number, szId, 10)); + MyDBWriteContactSetting(hMeta, META_PROTO, buffer, &dcws->value); + } + else db_free(&dbv); + + // copy nick to metacontact, if it's the most online + most_online = Meta_GetMostOnline(hMeta); + Meta_CopyContactNick(hMeta, most_online); + + return 0; + } + else if ( !strcmp(dcws->szSetting, "IdleTS")) { + if (dcws->value.type == DBVT_DWORD) + db_set_dw(hMeta, META_PROTO, "IdleTS", dcws->value.dVal); + else if (dcws->value.type == DBVT_DELETED) + db_set_dw(hMeta, META_PROTO, "IdleTS", 0); + } + else if ( !strcmp(dcws->szSetting, "LogonTS")) { + if (dcws->value.type == DBVT_DWORD) + db_set_dw(hMeta, META_PROTO, "LogonTS", dcws->value.dVal); + else if (dcws->value.type == DBVT_DELETED) + db_set_dw(hMeta, META_PROTO, "LogonTS", 0); + } + else if ( !strcmp(dcws->szModule, "CList") && !strcmp(dcws->szSetting, "MyHandle")) { + HANDLE most_online; - // copy RealIP - if ( !strcmp(dcws->szSetting, "RealIP")) { - if (dcws->value.type == DBVT_DWORD) - db_set_dw(hMeta, META_PROTO, "RealIP", dcws->value.dVal); - else - db_unset(hMeta, META_PROTO, "RealIP"); - - } else - // copy ListeningTo - if ( !strcmp(dcws->szSetting, "ListeningTo")) { - switch(dcws->value.type) { - case DBVT_ASCIIZ: - db_set_s(hMeta, META_PROTO, "ListeningTo", dcws->value.pszVal); - break; - case DBVT_UTF8: - DBWriteContactSettingStringUtf(hMeta, META_PROTO, "ListeningTo", dcws->value.pszVal); - break; - case DBVT_WCHAR: - DBWriteContactSettingWString(hMeta, META_PROTO, "ListeningTo", dcws->value.pwszVal); - break; - case DBVT_DELETED: - db_unset(hMeta, META_PROTO, "ListeningTo"); - break; - } - } else - - if ( !strcmp(dcws->szSetting, "Nick") && !dcws->value.type == DBVT_DELETED) { - DBVARIANT dbv; - HANDLE most_online; - - // subcontact nick has changed - update metacontact - strcpy(buffer, "Nick"); - strcat(buffer, _itoa(contact_number, buffer2, 10)); - MyDBWriteContactSetting(hMeta, META_PROTO, buffer, &dcws->value); - - if (Mydb_get((HANDLE)wParam, "CList", "MyHandle", &dbv)) { - strcpy(buffer, "CListName"); - strcat(buffer, _itoa(contact_number, buffer2, 10)); - MyDBWriteContactSetting(hMeta, META_PROTO, buffer, &dcws->value); - } else { - db_free(&dbv); - } - - // copy nick to metacontact, if it's the most online - most_online = Meta_GetMostOnline(hMeta); - Meta_CopyContactNick(hMeta, most_online); - - return 0; - } else - - if ( !strcmp(dcws->szSetting, "IdleTS")) { - if (dcws->value.type == DBVT_DWORD) - db_set_dw(hMeta, META_PROTO, "IdleTS", dcws->value.dVal); - else if (dcws->value.type == DBVT_DELETED) - db_set_dw(hMeta, META_PROTO, "IdleTS", 0); - } else - - if ( !strcmp(dcws->szSetting, "LogonTS")) { - if (dcws->value.type == DBVT_DWORD) - db_set_dw(hMeta, META_PROTO, "LogonTS", dcws->value.dVal); - else if (dcws->value.type == DBVT_DELETED) - db_set_dw(hMeta, META_PROTO, "LogonTS", 0); - } else - - if ( !strcmp(dcws->szModule, "CList") && !strcmp(dcws->szSetting, "MyHandle")) { - HANDLE most_online; - - if (dcws->value.type == DBVT_DELETED) { - DBVARIANT dbv; - - char *proto = GetContactProto((HANDLE)wParam); - strcpy(buffer, "CListName"); - strcat(buffer, _itoa(contact_number, buffer2, 10)); - if (proto && !Mydb_get((HANDLE)wParam, proto, "Nick", &dbv)) { - MyDBWriteContactSetting(hMeta, META_PROTO, buffer, &dbv); - db_free(&dbv); - } else { - db_unset(hMeta, META_PROTO, buffer); - } - } else { - // subcontact clist displayname has changed - update metacontact - strcpy(buffer, "CListName"); - strcat(buffer, _itoa(contact_number, buffer2, 10)); - - MyDBWriteContactSetting(hMeta, META_PROTO, buffer, &dcws->value); - } - - // copy nick to metacontact, if it's the most online - most_online = Meta_GetMostOnline(hMeta); - Meta_CopyContactNick(hMeta, most_online); - - return 0; - } else - - if ( !strcmp(dcws->szSetting, "Status") && !dcws->value.type == DBVT_DELETED) { - // subcontact changing status - - // update subcontact status setting - strcpy(buffer, "Status"); - strcat(buffer, _itoa(contact_number, buffer2, 10)); - db_set_w(hMeta, META_PROTO, buffer, dcws->value.wVal); - strcpy(buffer, "StatusString"); - strcat(buffer, _itoa(contact_number, buffer2, 10)); - Meta_GetStatusString(dcws->value.wVal, buffer2, 512); - db_set_s(hMeta, META_PROTO, buffer, buffer2); - - // if the contact was forced, unforce it (which updates status) - if ((HANDLE)db_get_dw(hMeta, META_PROTO, "ForceSend", 0) == (HANDLE)wParam) { - MetaAPI_UnforceSendContact((WPARAM)hMeta, 0); - } else { - // set status to that of most online contact - most_online = Meta_GetMostOnline(hMeta); - Meta_CopyContactNick(hMeta, most_online); - - Meta_FixStatus(hMeta); - - Meta_CopyData(hMeta); - } - - // most online contact with avatar support might have changed - update avatar - most_online = Meta_GetMostOnlineSupporting(hMeta, PFLAGNUM_4, PF4_AVATARS); - if (most_online) { - PROTO_AVATAR_INFORMATIONT AI; - - AI.cbSize = sizeof(AI); - AI.hContact = hMeta; - AI.format = PA_FORMAT_UNKNOWN; - _tcscpy(AI.filename, _T("X")); - - if ((int)CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS) - DBWriteContactSettingTString(hMeta, "ContactPhoto", "File",AI.filename); - } - } else - - if (strcmp(dcws->szSetting, "XStatusId") == 0 || strcmp(dcws->szSetting, "XStatusMsg") == 0 || strcmp(dcws->szSetting, "XStatusName") == 0 || strcmp(dcws->szSetting, "StatusMsg") == 0) { - Meta_CopyData(hMeta); - } else - - if (strcmp(dcws->szSetting, "MirVer") == 0) { - Meta_CopyData(hMeta); - } else - - if ( !meta_group_hack_disabled && !strcmp(dcws->szModule, "CList") && !strcmp(dcws->szSetting, "Hidden")) { - if ((dcws->value.type == DBVT_DELETED || db_get_b((HANDLE)wParam, "CList", "Hidden", 0) == 0) - && db_get_b((HANDLE)wParam, META_PROTO, "Hidden", 0) == 1) - { - // a subcontact we hid (e.g. jabber) has been unhidden - hide it again :( - db_set_b((HANDLE)wParam, "CList", "Hidden", 1); - } - } + if (dcws->value.type == DBVT_DELETED) { + DBVARIANT dbv; + + char *proto = GetContactProto((HANDLE)wParam); + strcpy(buffer, "CListName"); + strcat(buffer, _itoa(contact_number, szId, 10)); + if (proto && !Mydb_get((HANDLE)wParam, proto, "Nick", &dbv)) { + MyDBWriteContactSetting(hMeta, META_PROTO, buffer, &dbv); + db_free(&dbv); + } else { + db_unset(hMeta, META_PROTO, buffer); + } + } else { + // subcontact clist displayname has changed - update metacontact + strcpy(buffer, "CListName"); + strcat(buffer, _itoa(contact_number, szId, 10)); + + MyDBWriteContactSetting(hMeta, META_PROTO, buffer, &dcws->value); + } + + // copy nick to metacontact, if it's the most online + most_online = Meta_GetMostOnline(hMeta); + Meta_CopyContactNick(hMeta, most_online); + + return 0; + } + else if ( !strcmp(dcws->szSetting, "Status") && !dcws->value.type == DBVT_DELETED) { + // subcontact changing status + + // update subcontact status setting + strcpy(buffer, "Status"); + strcat(buffer, _itoa(contact_number, szId, 10)); + db_set_w(hMeta, META_PROTO, buffer, dcws->value.wVal); + + strcpy(buffer, "StatusString"); + strcat(buffer, _itoa(contact_number, szId, 10)); + Meta_GetStatusString(dcws->value.wVal, buffer2, 512); + db_set_ts(hMeta, META_PROTO, buffer, buffer2); + + // if the contact was forced, unforce it (which updates status) + if ((HANDLE)db_get_dw(hMeta, META_PROTO, "ForceSend", 0) == (HANDLE)wParam) { + MetaAPI_UnforceSendContact((WPARAM)hMeta, 0); + } else { + // set status to that of most online contact + most_online = Meta_GetMostOnline(hMeta); + Meta_CopyContactNick(hMeta, most_online); + + Meta_FixStatus(hMeta); + + Meta_CopyData(hMeta); + } + + // most online contact with avatar support might have changed - update avatar + most_online = Meta_GetMostOnlineSupporting(hMeta, PFLAGNUM_4, PF4_AVATARS); + if (most_online) { + PROTO_AVATAR_INFORMATIONT AI; + + AI.cbSize = sizeof(AI); + AI.hContact = hMeta; + AI.format = PA_FORMAT_UNKNOWN; + _tcscpy(AI.filename, _T("X")); + + if ((int)CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS) + db_set_ts(hMeta, "ContactPhoto", "File",AI.filename); + } + } + else if (strcmp(dcws->szSetting, "XStatusId") == 0 || strcmp(dcws->szSetting, "XStatusMsg") == 0 || strcmp(dcws->szSetting, "XStatusName") == 0 || strcmp(dcws->szSetting, "StatusMsg") == 0) { + Meta_CopyData(hMeta); + } + else if (strcmp(dcws->szSetting, "MirVer") == 0) { + Meta_CopyData(hMeta); + } + else if ( !meta_group_hack_disabled && !strcmp(dcws->szModule, "CList") && !strcmp(dcws->szSetting, "Hidden")) { + if ((dcws->value.type == DBVT_DELETED || db_get_b((HANDLE)wParam, "CList", "Hidden", 0) == 0) + && db_get_b((HANDLE)wParam, META_PROTO, "Hidden", 0) == 1) + { + // a subcontact we hid (e.g. jabber) has been unhidden - hide it again :( + db_set_b((HANDLE)wParam, "CList", "Hidden", 1); + } + } } return 0; } -int Meta_ContactDeleted(WPARAM wParam, LPARAM lParam) { - HANDLE hMeta; - +int Meta_ContactDeleted(WPARAM wParam, LPARAM lParam) +{ // is a subcontact - update meta contact - hMeta = (HANDLE)db_get_dw((HANDLE)wParam, META_PROTO, "Handle", 0); + HANDLE hMeta = (HANDLE)db_get_dw((HANDLE)wParam, META_PROTO, "Handle", 0); if (hMeta) { Meta_RemoveContactNumber(hMeta, db_get_dw((HANDLE)wParam, META_PROTO, "ContactNumber", -1)); NotifyEventHooks(hSubcontactsChanged, (WPARAM)hMeta, 0); return 0; - } else { - // not a subcontact - is it a metacontact? - int num_contacts = db_get_dw((HANDLE)wParam, META_PROTO, "NumContacts", 0); - int i; - HANDLE hContact; - - if (num_contacts) NotifyEventHooks(hSubcontactsChanged, (WPARAM)wParam, 0); - - // remove & restore all subcontacts - for (i = 0; i < num_contacts; i++) { - hContact = Meta_GetContactHandle((HANDLE)wParam, i); - - if (hContact && (HANDLE)db_get_dw(hContact, META_PROTO, "Handle", 0) == (HANDLE)wParam) { - if (db_get_b(hContact, META_PROTO, "IsSubcontact", 0) == 1) - db_unset(hContact, META_PROTO, "IsSubcontact"); - db_unset(hContact, META_PROTO, META_LINK); - db_unset(hContact, META_PROTO, "Handle"); - db_unset(hContact, META_PROTO, "ContactNumber"); - Meta_RestoreGroup(hContact); - db_unset(hContact, META_PROTO, "OldCListGroup"); - - // stop ignoring, if we were - if (options.suppress_status) - CallService(MS_IGNORE_UNIGNORE, (WPARAM)hContact, (WPARAM)IGNOREEVENT_USERONLINE); - } - } - return 0; } - + // not a subcontact - is it a metacontact? + int num_contacts = db_get_dw((HANDLE)wParam, META_PROTO, "NumContacts", 0); + if (num_contacts) + NotifyEventHooks(hSubcontactsChanged, (WPARAM)wParam, 0); + + // remove & restore all subcontacts + for (int i = 0; i < num_contacts; i++) { + HANDLE hContact = Meta_GetContactHandle((HANDLE)wParam, i); + if (hContact && (HANDLE)db_get_dw(hContact, META_PROTO, "Handle", 0) == (HANDLE)wParam) { + if (db_get_b(hContact, META_PROTO, "IsSubcontact", 0) == 1) + db_unset(hContact, META_PROTO, "IsSubcontact"); + db_unset(hContact, META_PROTO, META_LINK); + db_unset(hContact, META_PROTO, "Handle"); + db_unset(hContact, META_PROTO, "ContactNumber"); + Meta_RestoreGroup(hContact); + db_unset(hContact, META_PROTO, "OldCListGroup"); + + // stop ignoring, if we were + if (options.suppress_status) + CallService(MS_IGNORE_UNIGNORE, (WPARAM)hContact, (WPARAM)IGNOREEVENT_USERONLINE); + } + } return 0; } @@ -881,32 +858,24 @@ int Meta_ContactDeleted(WPARAM wParam, LPARAM lParam) { */ INT_PTR Meta_UserIsTyping(WPARAM wParam, LPARAM lParam) { - char *proto; - char buff[512]; - + // This is a simple contact, let through the stack of protocols if (db_get_dw((HANDLE)wParam, META_PROTO, META_ID,(DWORD)-1) == (DWORD)-1) - { - // This is a simple contact, let through the stack of protocols return 0; - } - else - { - // forward to sending protocol, if supported - - HANDLE most_online = Meta_GetMostOnline((HANDLE)wParam); - Meta_CopyContactNick((HANDLE)wParam, most_online); - if ( !most_online) return 0; + // forward to sending protocol, if supported - proto = GetContactProto(most_online); - if (proto) { - strncpy(buff, proto, 512); - strncpy(buff + strlen(proto), PSS_USERISTYPING, 512 - strlen(proto)); + HANDLE most_online = Meta_GetMostOnline((HANDLE)wParam); + Meta_CopyContactNick((HANDLE)wParam, most_online); + if ( !most_online) + return 0; - if (ServiceExists(buff)) { - CallService(buff, (WPARAM)most_online, (LPARAM)lParam); - } - } + char *proto = GetContactProto(most_online); + if (proto) { + char buff[512]; + strncpy(buff, proto, 512); + strncpy(buff + strlen(proto), PSS_USERISTYPING, 512 - strlen(proto)); + if (ServiceExists(buff)) + CallService(buff, (WPARAM)most_online, (LPARAM)lParam); } return 0; @@ -920,19 +889,12 @@ INT_PTR Meta_UserIsTyping(WPARAM wParam, LPARAM lParam) int Meta_ContactIsTyping(WPARAM wParam, LPARAM lParam) { HANDLE hMeta; - - if ((hMeta = (HANDLE)db_get_dw((HANDLE)wParam, META_PROTO, "Handle",0)) != 0 - // check metacontacts enabled - && Meta_IsEnabled() - ) - { // This contact is attached to a MetaContact. + if ((hMeta = (HANDLE)db_get_dw((HANDLE)wParam, META_PROTO, "Handle",0)) != 0 && Meta_IsEnabled()) { + // This contact is attached to a MetaContact. if ( !options.subcontact_windows) { // we don't want clicking on the clist notification icon to open the metacontact message window - // try to remove any clist events we added for subcontact CallServiceSync(MS_CLIST_REMOVEEVENT, wParam, (LPARAM) 1); - CallService(MS_PROTO_CONTACTISTYPING, (WPARAM)hMeta, lParam); - // stop processing of event return 1; } @@ -946,6 +908,7 @@ int Meta_ContactIsTyping(WPARAM wParam, LPARAM lParam) * Returns 1 to stop event processing and opens page for metacontact default contact (returning 1 to stop it doesn't work!) * */ + int Meta_UserInfo(WPARAM wParam, LPARAM lParam) { DWORD default_contact_number = db_get_dw((HANDLE)lParam, META_PROTO, "Default", (DWORD)-1); @@ -954,7 +917,6 @@ int Meta_UserInfo(WPARAM wParam, LPARAM lParam) return 0; CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)Meta_GetContactHandle((HANDLE)lParam, default_contact_number), 0); - return 1; } @@ -994,7 +956,6 @@ int Meta_MessageWindowEvent(WPARAM wParam, LPARAM lParam) { } } } - } return 0; @@ -1003,73 +964,48 @@ int Meta_MessageWindowEvent(WPARAM wParam, LPARAM lParam) { int Meta_ClistDoubleClicked(WPARAM wParam, LPARAM lParam) { if (db_get_dw((HANDLE)wParam, META_PROTO, "Default",(WORD)-1) == (WORD)-1) - { - // This is a simple contact return 0; - } - else - { - // -1 indicates no specific capability but respect 'ForceDefault' - HANDLE most_online = Meta_GetMostOnlineSupporting((HANDLE)wParam, PFLAGNUM_1, -1); - //DBEVENTINFO dbei; - char *proto; - char buffer[512]; - int caps; - if ( !most_online) - return 0; + // -1 indicates no specific capability but respect 'ForceDefault' + HANDLE most_online = Meta_GetMostOnlineSupporting((HANDLE)wParam, PFLAGNUM_1, -1); + if ( !most_online) + return 0; - if (options.subcontact_windows) { - if (lParam) { - // contact from incoming message in lParam via (at this point) clist message event - CallService(MS_CLIST_CONTACTDOUBLECLICKED, (WPARAM)lParam, 0); - } else { - // simulate double click on most_online contact and stop event processing - CallService(MS_CLIST_CONTACTDOUBLECLICKED, (WPARAM)most_online, 0); - } - return 1; - } else { - proto = GetContactProto(most_online); - - if (proto) { - strcpy(buffer, proto); - strcat(buffer, PS_GETCAPS); - - // get the contacts messaging capabilities - caps = CallService(buffer, (WPARAM)PFLAGNUM_1, 0); - - if ((caps & PF1_IMSEND) || (caps & PF1_CHAT) || (proto && strcmp(proto, "IRC") == 0)) - // let event process normally - return 0; - else { - // simulate double click on most_online contact and stop event processing - CallService(MS_CLIST_CONTACTDOUBLECLICKED, (WPARAM)most_online, 0); - return 1; - } - } else - return 0; - } + if (options.subcontact_windows) { + if (lParam) // contact from incoming message in lParam via (at this point) clist message event + CallService(MS_CLIST_CONTACTDOUBLECLICKED, (WPARAM)lParam, 0); + else // simulate double click on most_online contact and stop event processing + CallService(MS_CLIST_CONTACTDOUBLECLICKED, (WPARAM)most_online, 0); + return 1; } - return 0; -} + char *proto = GetContactProto(most_online); + if (proto == NULL) + return 0; -INT_PTR Meta_ClistMessageEventClicked(WPARAM wParam, LPARAM lParam) { + char buffer[512]; + strcpy(buffer, proto); + strcat(buffer, PS_GETCAPS); - HANDLE hContact = ((CLISTEVENT *)lParam)->hContact; + // get the contacts messaging capabilities + int caps = CallService(buffer, (WPARAM)PFLAGNUM_1, 0); + if ((caps & PF1_IMSEND) || (caps & PF1_CHAT) || (proto && strcmp(proto, "IRC") == 0)) + // let event process normally + return 0; - // hdbevent contains the id of the subcontact - return Meta_ClistDoubleClicked((WPARAM)hContact, (LPARAM)((CLISTEVENT *)lParam)->hDbEvent); + // simulate double click on most_online contact and stop event processing + CallService(MS_CLIST_CONTACTDOUBLECLICKED, (WPARAM)most_online, 0); + return 1; } +INT_PTR Meta_ClistMessageEventClicked(WPARAM wParam, LPARAM lParam) +{ + HANDLE hContact = ((CLISTEVENT *)lParam)->hContact; + return Meta_ClistDoubleClicked((WPARAM)hContact, (LPARAM)((CLISTEVENT *)lParam)->hDbEvent); +} -int NudgeRecieved(WPARAM wParam, LPARAM lParam) { - /* - // already being forwarded by someone - HANDLE hMeta = (HANDLE)db_get_dw((HANDLE)wParam, META_PROTO, "Handle", 0); - if (hMeta) - NotifyEventHooks(hEventNudge, (WPARAM)hMeta, 0); - */ +int NudgeRecieved(WPARAM wParam, LPARAM lParam) +{ return 0; } @@ -1136,10 +1072,6 @@ int Meta_ModulesLoaded(WPARAM wParam, LPARAM lParam) mi.pszService = "MetaContacts/Delete"; hMenuDelete = Menu_AddContactMenuItem(&mi); - //mi.pszName = "Force Default"; - //mi.pszService = "MetaContacts/ForceDefault"; - //hMenuForceDefault = Menu_AddContactMenuItem(&mi); - mi.flags |= CMIF_HIDDEN; mi.pszContactOwner = META_PROTO; @@ -1159,17 +1091,14 @@ int Meta_ModulesLoaded(WPARAM wParam, LPARAM lParam) nextMetaID = db_get_dw(NULL, META_PROTO, "NextMetaID",0); - // attemp to subsume userinfo...(returning 1 does not prevent dialog - so disabled) - //hHooks[] = (HANDLE)HookEvent(ME_USERINFO_INITIALISE, Meta_UserInfo); - // loop and copy data from subcontacts if (options.copydata) { HANDLE hContact = db_find_first(); int meta_id; while ( hContact != NULL ) { - if ((meta_id = db_get_dw(hContact, META_PROTO, META_ID,(DWORD)-1))!=(DWORD)-1) { + if ((meta_id = db_get_dw(hContact, META_PROTO, META_ID,(DWORD)-1))!=(DWORD)-1) Meta_CopyData(hContact); - } + hContact = db_find_next(hContact); } } @@ -1233,9 +1162,9 @@ static VOID CALLBACK sttMenuThread( PVOID param ) DestroyMenu(hMenu); } -INT_PTR Meta_ContactMenuFunc(WPARAM wParam, LPARAM lParam) { - HANDLE hContact; - hContact = Meta_GetContactHandle((HANDLE)wParam, (int)lParam); +INT_PTR Meta_ContactMenuFunc(WPARAM wParam, LPARAM lParam) +{ + HANDLE hContact = Meta_GetContactHandle((HANDLE)wParam, (int)lParam); if (options.menu_function == FT_MSG) { // open message window if protocol supports message sending or chat, else simulate double click @@ -1325,7 +1254,8 @@ INT_PTR Meta_FileSend(WPARAM wParam, LPARAM lParam) return 0; // fail } -INT_PTR Meta_GetAwayMsg(WPARAM wParam, LPARAM lParam) { +INT_PTR Meta_GetAwayMsg(WPARAM wParam, LPARAM lParam) +{ CCSDATA *ccs = (CCSDATA *) lParam; char *proto = 0; DWORD default_contact_number; @@ -1424,7 +1354,7 @@ INT_PTR Meta_GetInfo(WPARAM wParam, LPARAM lParam) { AI.format = PA_FORMAT_UNKNOWN; _tcscpy(AI.filename, _T("X")); if ((int)CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS) - DBWriteContactSettingTString(ccs->hContact, "ContactPhoto", "File",AI.filename); + db_set_ts(ccs->hContact, "ContactPhoto", "File",AI.filename); most_online = Meta_GetMostOnline(ccs->hContact); Meta_CopyContactNick(ccs->hContact, most_online); @@ -1448,32 +1378,32 @@ INT_PTR Meta_GetInfo(WPARAM wParam, LPARAM lParam) { int Meta_OptInit(WPARAM wParam, LPARAM lParam) { - OPTIONSDIALOGPAGE odp = { 0 }; - odp.cbSize = sizeof(odp); + OPTIONSDIALOGPAGE odp = { sizeof(odp) }; odp.position = -790000000; odp.hInstance = hInstance; odp.flags = ODPF_BOLDGROUPS; - odp.pszTemplate = MAKEINTRESOURCE(IDD_OPTIONS); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS); odp.pszTitle = LPGEN("MetaContacts"); odp.pszGroup = LPGEN("Contact List"); odp.pszTab = LPGEN("General"); odp.pfnDlgProc = DlgProcOpts; Options_AddPage(wParam, &odp); - odp.pszTemplate = MAKEINTRESOURCE(IDD_PRIORITIES); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_PRIORITIES); odp.pszTab = LPGEN("Priorities"); odp.pfnDlgProc = DlgProcOptsPriorities; Options_AddPage(wParam, &odp); - odp.pszTemplate = MAKEINTRESOURCE(IDD_HISTORY); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_HISTORY); odp.pszTab = LPGEN("History"); odp.pfnDlgProc = DlgProcOpts; Options_AddPage(wParam, &odp); return 0; } -int Meta_CallMostOnline(WPARAM wParam, LPARAM lParam) { +int Meta_CallMostOnline(WPARAM wParam, LPARAM lParam) +{ HANDLE most_online_im = Meta_GetMostOnline((HANDLE)wParam); // fix nick @@ -1484,11 +1414,9 @@ int Meta_CallMostOnline(WPARAM wParam, LPARAM lParam) { // copy all other data Meta_CopyData((HANDLE) wParam); - return 0; } - INT_PTR Meta_OnOff(WPARAM wParam, LPARAM lParam) { CLISTMENUITEM mi = { sizeof(mi) }; @@ -1532,10 +1460,16 @@ int Meta_OkToExit(WPARAM wParam, LPARAM lParam) { return 0; } +INT_PTR MenuFunc(WPARAM wParam, LPARAM lParam, LPARAM param) +{ + return Meta_ContactMenuFunc(wParam, param); +} + /** Initializes all services provided by the plugin * * Creates every function and hooks the event desired. */ + void Meta_InitServices() { previousMode = mcStatus = ID_STATUS_OFFLINE; @@ -1548,26 +1482,11 @@ void Meta_InitServices() CreateServiceFunction("MetaContacts/ForceDefault", Meta_ForceDefault); // hidden contact menu items...ho hum - CreateServiceFunction("MetaContacts/MenuFunc0", MenuFunc0); - CreateServiceFunction("MetaContacts/MenuFunc1", MenuFunc1); - CreateServiceFunction("MetaContacts/MenuFunc2", MenuFunc2); - CreateServiceFunction("MetaContacts/MenuFunc3", MenuFunc3); - CreateServiceFunction("MetaContacts/MenuFunc4", MenuFunc4); - CreateServiceFunction("MetaContacts/MenuFunc5", MenuFunc5); - CreateServiceFunction("MetaContacts/MenuFunc6", MenuFunc6); - CreateServiceFunction("MetaContacts/MenuFunc7", MenuFunc7); - CreateServiceFunction("MetaContacts/MenuFunc8", MenuFunc8); - CreateServiceFunction("MetaContacts/MenuFunc9", MenuFunc9); - CreateServiceFunction("MetaContacts/MenuFunc10", MenuFunc10); - CreateServiceFunction("MetaContacts/MenuFunc11", MenuFunc11); - CreateServiceFunction("MetaContacts/MenuFunc12", MenuFunc12); - CreateServiceFunction("MetaContacts/MenuFunc13", MenuFunc13); - CreateServiceFunction("MetaContacts/MenuFunc14", MenuFunc14); - CreateServiceFunction("MetaContacts/MenuFunc15", MenuFunc15); - CreateServiceFunction("MetaContacts/MenuFunc16", MenuFunc16); - CreateServiceFunction("MetaContacts/MenuFunc17", MenuFunc17); - CreateServiceFunction("MetaContacts/MenuFunc18", MenuFunc18); - CreateServiceFunction("MetaContacts/MenuFunc19", MenuFunc19); + for (int i=0; i < MAX_CONTACTS; i++) { + char szServiceName[100]; + mir_snprintf(szServiceName, SIZEOF(szServiceName), "MetaContacts/MenuFunc%d", i); + CreateServiceFunctionParam(szServiceName, MenuFunc, i); + } CreateProtoServiceFunction(META_PROTO, PS_GETCAPS, Meta_GetCaps); CreateProtoServiceFunction(META_PROTO, PS_GETNAME, Meta_GetName); diff --git a/plugins/MetaContacts/src/meta_utils.cpp b/plugins/MetaContacts/src/meta_utils.cpp index a11f28b90b..2217834d22 100644 --- a/plugins/MetaContacts/src/meta_utils.cpp +++ b/plugins/MetaContacts/src/meta_utils.cpp @@ -179,41 +179,41 @@ HANDLE Meta_GetHandle(const char *protocol, DBVARIANT *id) * The login of the "MetaContacts" protocol will be copied from the login * of the specified protocol. * -* @param proto : The name of the protocol used to get the login that will be +* @param szProto : The name of the protocol used to get the login that will be * affected to the "MetaContacts" protocol. * * @return O on success, 1 otherwise. */ -int Meta_SetNick(char *proto) +int Meta_SetNick(char *szProto) { CONTACTINFO ci; ci.cbSize = sizeof(CONTACTINFO); ci.dwFlag = CNF_DISPLAY; ci.hContact = NULL; - ci.szProto = proto; + ci.szProto = szProto; if (CallService(MS_CONTACT_GETCONTACTINFO,0,(LPARAM)&ci)) return 1; switch(ci.type) { case CNFT_BYTE: - if ( db_set_b(NULL, META_PROTO, "Nick",ci.bVal)) + if ( db_set_b(NULL, META_PROTO, "Nick", ci.bVal)) return 1; break; case CNFT_WORD: - if ( db_set_w(NULL, META_PROTO, "Nick",ci.wVal)) + if ( db_set_w(NULL, META_PROTO, "Nick", ci.wVal)) return 1; break; case CNFT_DWORD: - if ( db_set_dw(NULL, META_PROTO, "Nick",ci.dVal)) + if ( db_set_dw(NULL, META_PROTO, "Nick", ci.dVal)) return 1; break; case CNFT_ASCIIZ: - if ( db_set_s(NULL, META_PROTO, "Nick",ci.pszVal)) + if ( db_set_ts(NULL, META_PROTO, "Nick", ci.pszVal)) return 1; mir_free(ci.pszVal); break; default: - if ( db_set_s(NULL, META_PROTO, "Nick",(char *)Translate("Sender"))) + if ( db_set_s(NULL, META_PROTO, "Nick",(char *)TranslateT("Sender"))) return 1; break; } @@ -231,67 +231,66 @@ int Meta_SetNick(char *proto) BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default) { DBCONTACTWRITESETTING cws; - DWORD metaID; - char *proto, - *field; - DWORD num_contacts; - char buffer[512], buffer2[512]; + DWORD metaID, num_contacts; + char buffer[512], szId[40]; + TCHAR buffer2[512]; WORD status; HANDLE most_online; if ((metaID=db_get_dw(dest, META_PROTO, META_ID,(DWORD)-1))==-1) { - MessageBox(0, Translate("Could not get MetaContact id"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + MessageBox(0, TranslateT("Could not get MetaContact id"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); return FALSE; } if ((num_contacts=db_get_dw(dest, META_PROTO, "NumContacts",(DWORD)-1))==-1) { - MessageBox(0, Translate("Could not retreive MetaContact contact count"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + MessageBox(0, TranslateT("Could not retreive MetaContact contact count"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); return FALSE; } - if ( !(proto = GetContactProto(src))) { - MessageBox(0, Translate("Could not retreive contact protocol"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + char *szProto = GetContactProto(src); + if (szProto == NULL) { + MessageBox(0, TranslateT("Could not retreive contact protocol"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); return FALSE; } // Get the login of the subcontact - field = (char *)CallProtoService(proto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0); - if ( db_get(src,proto,field,&cws.value)) { - MessageBox(0, Translate("Could not get unique id of contact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + char *field = (char *)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); + if ( db_get(src,szProto,field,&cws.value)) { + MessageBox(0, TranslateT("Could not get unique id of contact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); return FALSE; } // Check that is is 'on the list' if ( db_get_b(src, "CList", "NotOnList", 0) == 1) { - MessageBox(0, Translate("Contact is 'Not on List' - please add the contact to your contact list before assigning."), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + MessageBox(0, TranslateT("Contact is 'Not on List' - please add the contact to your contact list before assigning."), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); db_free(&cws.value); return FALSE; } num_contacts++; if (num_contacts >= MAX_CONTACTS) { - MessageBox(0, Translate("MetaContact is full"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + MessageBox(0, TranslateT("MetaContact is full"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); db_free(&cws.value); return FALSE; } // write the contact's protocol strcpy(buffer, "Protocol"); - strcat(buffer, _itoa((int)(num_contacts -1), buffer2, 10)); + strcat(buffer, _itoa((int)(num_contacts -1), szId, 10)); - if ( db_set_s(dest, META_PROTO, buffer, proto)) { - MessageBox(0, Translate("Could not write contact protocol to MetaContact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + if ( db_set_s(dest, META_PROTO, buffer, szProto)) { + MessageBox(0, TranslateT("Could not write contact protocol to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); db_free(&cws.value); return FALSE; } // write the login strcpy(buffer, "Login"); - strcat(buffer, _itoa((int)(num_contacts - 1), buffer2, 10)); + strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10)); - cws.szModule=META_PROTO; - cws.szSetting=buffer; + cws.szModule = META_PROTO; + cws.szSetting = buffer; if ( CallService(MS_DB_CONTACT_WRITESETTING,(WPARAM)dest,(LPARAM)&cws)) { - MessageBox(0, Translate("Could not write unique id of contact to MetaContact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + MessageBox(0, TranslateT("Could not write unique id of contact to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); db_free(&cws.value); return FALSE; } @@ -299,16 +298,16 @@ BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default) db_free(&cws.value); // If we can get the nickname of the subcontact... - if ( !db_get(src,proto,"Nick",&cws.value)) { + if ( !db_get(src,szProto,"Nick",&cws.value)) { // write the nickname strcpy(buffer, "Nick"); - strcat(buffer, _itoa((int)(num_contacts - 1), buffer2, 10)); + strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10)); cws.szModule=META_PROTO; cws.szSetting=buffer; if (CallService(MS_DB_CONTACT_WRITESETTING,(WPARAM)dest,(LPARAM)&cws)) { - MessageBox(0, Translate("Could not write nickname of contact to MetaContact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + MessageBox(0, TranslateT("Could not write nickname of contact to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); return FALSE; } @@ -322,7 +321,7 @@ BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default) // write the display name strcpy(buffer, "CListName"); - strcat(buffer, _itoa((int)(num_contacts - 1), buffer2, 10)); + strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10)); if (wname && strncmp(name, (char *)wname, strlen(name)) != 0) { DBWriteContactSettingWString(dest, META_PROTO, buffer, wname); @@ -330,58 +329,58 @@ BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default) db_set_s(dest, META_PROTO, buffer, name); // Get the status - if ( !proto) + if ( !szProto) status = ID_STATUS_OFFLINE; else - status = db_get_w(src, proto, "Status", ID_STATUS_OFFLINE); + status = db_get_w(src, szProto, "Status", ID_STATUS_OFFLINE); } // write the status strcpy(buffer, "Status"); - strcat(buffer, _itoa((int)(num_contacts - 1), buffer2, 10)); + strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10)); if (db_set_w(dest, META_PROTO, buffer, status)) { - MessageBox(0, Translate("Could not write contact status to MetaContact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + MessageBox(0, TranslateT("Could not write contact status to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); return FALSE; } // write the handle strcpy(buffer, "Handle"); - strcat(buffer, _itoa((int)(num_contacts - 1), buffer2, 10)); + strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10)); if (db_set_dw(dest, META_PROTO, buffer, (DWORD)src)) { - MessageBox(0, Translate("Could not write contact handle to MetaContact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + MessageBox(0, TranslateT("Could not write contact handle to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); return FALSE; } // write status string strcpy(buffer, "StatusString"); - strcat(buffer, _itoa((int)(num_contacts - 1), buffer2, 10)); + strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10)); Meta_GetStatusString(status, buffer2, 512); - if (db_set_s(dest, META_PROTO, buffer, buffer2)) { - MessageBox(0, Translate("Could not write contact status string to MetaContact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + if (db_set_ts(dest, META_PROTO, buffer, buffer2)) { + MessageBox(0, TranslateT("Could not write contact status string to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); return FALSE; } // Write the link in the contact if (db_set_dw(src, META_PROTO, META_LINK,metaID)) { - MessageBox(0, Translate("Could not write MetaContact id to contact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + MessageBox(0, TranslateT("Could not write MetaContact id to contact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); return FALSE; } // Write the contact number in the contact if (db_set_dw(src, META_PROTO, "ContactNumber",(DWORD)(num_contacts - 1))) { - MessageBox(0, Translate("Could not write MetaContact contact number to contact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + MessageBox(0, TranslateT("Could not write MetaContact contact number to contact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); return FALSE; } // Write the handle in the contact if (db_set_dw(src, META_PROTO, "Handle",(DWORD)dest)) { - MessageBox(0, Translate("Could not write MetaContact contact number to contact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + MessageBox(0, TranslateT("Could not write MetaContact contact number to contact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); return FALSE; } // update count of contacts if (db_set_dw(dest, META_PROTO, "NumContacts",num_contacts)) { - MessageBox(0, Translate("Could not write contact count to MetaContact"), Translate("Assignment Error"), MB_OK | MB_ICONWARNING); + MessageBox(0, TranslateT("Could not write contact count to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); return FALSE; } @@ -409,7 +408,7 @@ BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default) _tcscpy(AI.filename, _T("X")); if ((int)CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS) - DBWriteContactSettingTString(dest, "ContactPhoto", "File",AI.filename); + db_set_ts(dest, "ContactPhoto", "File",AI.filename); } // Hide the contact @@ -450,7 +449,7 @@ HANDLE Meta_GetMostOnlineSupporting(HANDLE hMeta, int pflagnum, unsigned long ca HANDLE most_online_contact = NULL, hContact; int i, status, default_contact_number, num_contacts; unsigned long caps = 0; - char *proto, *most_online_proto; + char *szProto, *most_online_proto; // you can't get more online than having the default contact ONLINE - so check that first if ((default_contact_number = db_get_dw(hMeta, META_PROTO, "Default",(DWORD)-1)) == (DWORD)-1) @@ -465,28 +464,28 @@ HANDLE Meta_GetMostOnlineSupporting(HANDLE hMeta, int pflagnum, unsigned long ca return NULL; most_online_contact = Meta_GetContactHandle(hMeta, default_contact_number); - proto = GetContactProto(most_online_contact); - caps = proto ? CallProtoService(proto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0; - if (proto && strcmp(proto, "IRC") == 0) caps |= PF1_IM; + szProto = GetContactProto(most_online_contact); + caps = szProto ? CallProtoService(szProto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0; + if (szProto && strcmp(szProto, "IRC") == 0) caps |= PF1_IM; // we are forced to do use default for sending - '-1' capability indicates no specific capability, but respect 'Force Default' - if (proto && db_get_b(hMeta, META_PROTO, "ForceDefault", 0) && capability != 0 && (capability == -1 || (caps & capability) == capability)) // capability is 0 when we're working out status + if (szProto && db_get_b(hMeta, META_PROTO, "ForceDefault", 0) && capability != 0 && (capability == -1 || (caps & capability) == capability)) // capability is 0 when we're working out status return most_online_contact; // a subcontact is being temporarily 'forced' to do sending if ((most_online_contact = (HANDLE)db_get_dw(hMeta, META_PROTO, "ForceSend", 0))) { - caps = proto ? CallProtoService(proto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0; - if (proto && strcmp(proto, "IRC") == 0) caps |= PF1_IM; - if (proto && (caps & capability) == capability && capability != 0) // capability is 0 when we're working out status + caps = szProto ? CallProtoService(szProto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0; + if (szProto && strcmp(szProto, "IRC") == 0) caps |= PF1_IM; + if (szProto && (caps & capability) == capability && capability != 0) // capability is 0 when we're working out status return most_online_contact; } most_online_contact = Meta_GetContactHandle(hMeta, default_contact_number); - proto = GetContactProto(most_online_contact); - if (proto && CallProtoService(proto, PS_GETSTATUS, 0, 0) >= ID_STATUS_ONLINE) { - caps = proto ? CallProtoService(proto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0; - if (proto && strcmp(proto, "IRC") == 0) caps |= PF1_IM; - if (proto && (capability == -1 || (caps & capability) == capability)) { - most_online_status = db_get_w(most_online_contact, proto, "Status", ID_STATUS_OFFLINE); + szProto = GetContactProto(most_online_contact); + if (szProto && CallProtoService(szProto, PS_GETSTATUS, 0, 0) >= ID_STATUS_ONLINE) { + caps = szProto ? CallProtoService(szProto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0; + if (szProto && strcmp(szProto, "IRC") == 0) caps |= PF1_IM; + if (szProto && (capability == -1 || (caps & capability) == capability)) { + most_online_status = db_get_w(most_online_contact, szProto, "Status", ID_STATUS_OFFLINE); // if our default is not offline, and option to use default is set - return default // and also if our default is online, return it @@ -498,35 +497,35 @@ HANDLE Meta_GetMostOnlineSupporting(HANDLE hMeta, int pflagnum, unsigned long ca } else most_online_status = ID_STATUS_OFFLINE; - most_online_proto = proto; + most_online_proto = szProto; // otherwise, check all the subcontacts for the one closest to the ONLINE state which supports the required capability for (i = 0; i < num_contacts; i++) { if (i == default_contact_number) // already checked that (i.e. initial value of most_online_contact and most_online_status are those of the default contact) continue; hContact = Meta_GetContactHandle(hMeta, i); - proto = GetContactProto(hContact); + szProto = GetContactProto(hContact); - if ( !proto || CallProtoService(proto, PS_GETSTATUS, 0, 0) < ID_STATUS_ONLINE) // proto offline or connecting + if ( !szProto || CallProtoService(szProto, PS_GETSTATUS, 0, 0) < ID_STATUS_ONLINE) // szProto offline or connecting continue; - caps = proto ? CallProtoService(proto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0; - if (proto && strcmp(proto, "IRC") == 0) caps |= PF1_IM; - if (proto && (capability == -1 || (caps & capability) == capability)) { + caps = szProto ? CallProtoService(szProto, PS_GETCAPS, (WPARAM)pflagnum, 0) : 0; + if (szProto && strcmp(szProto, "IRC") == 0) caps |= PF1_IM; + if (szProto && (capability == -1 || (caps & capability) == capability)) { - status = db_get_w(hContact, proto, "Status", ID_STATUS_OFFLINE); + status = db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE); if (status == ID_STATUS_ONLINE) { most_online_contact = hContact; - most_online_proto = proto; + most_online_proto = szProto; return most_online_contact; } else if (status <= ID_STATUS_OFFLINE) // status below ID_STATUS_OFFLINE is a connecting status continue; else { - if (GetRealPriority(proto, status) < GetRealPriority(most_online_proto, most_online_status)) { + if (GetRealPriority(szProto, status) < GetRealPriority(most_online_proto, most_online_status)) { most_online_status = status; most_online_contact = hContact; - most_online_proto = proto; + most_online_proto = szProto; } } } @@ -667,7 +666,7 @@ const char *MBirthdaySettings[3] = // special handling for status message // copy from first subcontact with any of these values that has the same status as the most online contact -// proto: +// szProto: // clist: "StatusMsg" void CopyStatusData(HANDLE hMeta) @@ -687,24 +686,24 @@ void CopyStatusData(HANDLE hMeta) else hContact = Meta_GetContactHandle(hMeta, i); - char *proto = GetContactProto(hContact); + char *szProto = GetContactProto(hContact); - if (proto && db_get_w(hContact, proto, "Status", ID_STATUS_OFFLINE) == status) { + if (szProto && db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE) == status) { if ( !bDoneStatus && !Mydb_get(hContact, "CList", "StatusMsg", &dbv)) { MyDBWriteContactSetting(hMeta, "CList", "StatusMsg", &dbv); db_free(&dbv); bDoneStatus = TRUE; } - if ((!bDoneXStatus) && (!Mydb_get(hContact, proto, "XStatusId", &dbv)) && dbv.type != DBVT_DELETED) { - db_set_s(hMeta, META_PROTO, "XStatusProto", proto); + if ((!bDoneXStatus) && (!Mydb_get(hContact, szProto, "XStatusId", &dbv)) && dbv.type != DBVT_DELETED) { + db_set_s(hMeta, META_PROTO, "XStatusProto", szProto); MyDBWriteContactSetting(hMeta, META_PROTO, "XStatusId", &dbv); db_free(&dbv); - if ( !Mydb_get(hContact, proto, "XStatusMsg", &dbv)) { + if ( !Mydb_get(hContact, szProto, "XStatusMsg", &dbv)) { MyDBWriteContactSetting(hMeta, META_PROTO, "XStatusMsg", &dbv); db_free(&dbv); } - if ( !Mydb_get(hContact, proto, "XStatusName", &dbv)) { + if ( !Mydb_get(hContact, szProto, "XStatusName", &dbv)) { MyDBWriteContactSetting(hMeta, META_PROTO, "XStatusName", &dbv); db_free(&dbv); } @@ -750,11 +749,12 @@ HANDLE Meta_GetContactHandle(HANDLE hMeta, int contact_number) return (HANDLE)db_get_dw(hMeta, META_PROTO, buffer, 0); } -int Meta_SetHandles(void) { +int Meta_SetHandles(void) +{ DWORD meta_id, num_contacts, contact_number; HANDLE hContact2, hContact = db_find_first(), hNextContact; - char buffer[512], buffer2[512]; - char nick_buffer[128]; + char buffer[512]; + TCHAR nick_buffer[128], buffer2[40]; BOOL found; while ( hContact != NULL ) { @@ -762,16 +762,16 @@ int Meta_SetHandles(void) { // is a subcontact // get nick for debug messages - strcpy(nick_buffer, "meta_id: "); - strcat(nick_buffer, _itoa(meta_id, buffer2, 10)); + _tcscpy(nick_buffer, _T("meta_id: ")); + _tcscat(nick_buffer, _itot(meta_id, buffer2, 10)); contact_number = db_get_dw(hContact, META_PROTO, "ContactNumber", (DWORD)-1); - strcat(nick_buffer, ", contact num: "); - strcat(nick_buffer, _itoa(contact_number, buffer2, 10)); + _tcscat(nick_buffer, _T(", contact num: ")); + _tcscat(nick_buffer, _itot(contact_number, buffer2, 10)); if (contact_number < 0) { // problem! - MessageBox(0, Translate("Subcontact contact number < 0 - deleting MetaContact"), nick_buffer, MB_OK | MB_ICONERROR); + MessageBox(0, TranslateT("Subcontact contact number < 0 - deleting MetaContact"), nick_buffer, MB_OK | MB_ICONERROR); //CallService(MS_DB_CONTACT_DELETE, (WPARMA)hContact, 0); hNextContact = db_find_next(hContact); Meta_Delete((WPARAM)hContact, (LPARAM)1); @@ -783,7 +783,6 @@ int Meta_SetHandles(void) { // ensure the window open flag is not present db_unset(hContact, META_PROTO, "WindowOpen"); - // find metacontact found = FALSE; hContact2 = db_find_first(); @@ -791,7 +790,7 @@ int Meta_SetHandles(void) { while ( hContact2 != NULL ) { if (db_get_dw(hContact2, META_PROTO, META_ID,(DWORD)-1) == meta_id) { found = TRUE; - + // set handle db_set_dw(hContact, META_PROTO, "Handle", (DWORD)hContact2); @@ -802,20 +801,21 @@ int Meta_SetHandles(void) { num_contacts = db_get_dw(hContact2, META_PROTO, "NumContacts", (DWORD)-1); if (contact_number >= 0 && contact_number < num_contacts) { // set metacontact's handle to us + char szId[40]; strcpy(buffer, "Handle"); - strcat(buffer, _itoa((int)contact_number, buffer2, 10)); + strcat(buffer, _itoa((int)contact_number, szId, 10)); db_set_dw(hContact2, META_PROTO, buffer, (DWORD)hContact); - } else { - char buff[256]; + } + else { + TCHAR buff[256]; // problem - contact number is greater than meta's number of contacts - sprintf(buff, Translate("Subcontact contact number (%d) > meta num contacts (%d) - deleting MetaContact"), (int)contact_number, (int)num_contacts); + mir_sntprintf(buff, SIZEOF(buff), TranslateT("Subcontact contact number (%d) > meta num contacts (%d) - deleting MetaContact"), contact_number, num_contacts); MessageBox(0, buff, nick_buffer, MB_OK | MB_ICONERROR); - //CallService(MS_DB_CONTACT_DELETE, (WPARMA)hContact, 0); + hNextContact = db_find_next(hContact); Meta_Delete((WPARAM)hContact, (LPARAM)1); hContact = hNextContact; continue; - //return 1; } } @@ -824,7 +824,7 @@ int Meta_SetHandles(void) { if ( !found) { // problem - subcontact's meta not found - MessageBox(0, Translate("Subcontact's MetaContact not found - deleting MetaContact data"), nick_buffer, MB_OK | MB_ICONERROR); + MessageBox(0, TranslateT("Subcontact's MetaContact not found - deleting MetaContact data"), nick_buffer, MB_OK | MB_ICONERROR); // delete meta data db_unset(hContact, META_PROTO, "IsSubcontact"); @@ -833,25 +833,25 @@ int Meta_SetHandles(void) { db_unset(hContact, META_PROTO, "ContactNumber"); Meta_RestoreGroup(hContact); db_unset(hContact, META_PROTO, "OldCListGroup"); - + // stop ignoring, if we were if (options.suppress_status) CallService(MS_IGNORE_UNIGNORE, (WPARAM)hContact, (WPARAM)IGNOREEVENT_USERONLINE); - - } else { + + } + else { if ( !db_get_b(hContact, META_PROTO, "IsSubcontact", 0)) db_set_b(hContact, META_PROTO, "IsSubcontact", 1); } - - } else - db_unset(hContact, META_PROTO, "Handle"); + } + else db_unset(hContact, META_PROTO, "Handle"); if ((meta_id = db_get_dw(hContact, META_PROTO, META_ID,(DWORD)-1))!=(DWORD)-1) { // is a metacontact // get nick for debug messages - strcpy(nick_buffer, "meta_id: "); - strcat(nick_buffer, _itoa(meta_id, buffer2, 10)); + _tcscpy(nick_buffer, _T("meta_id: ")); + _tcscat(nick_buffer, _itot(meta_id, buffer2, 10)); // ensure the window open flag is not present db_unset(hContact, META_PROTO, "WindowOpen"); @@ -862,47 +862,40 @@ int Meta_SetHandles(void) { if (num_contacts < 0) { // problem - MessageBox(0, Translate("MetaContact number of contacts < 0 - deleting MetaContact"), nick_buffer, MB_OK | MB_ICONERROR); - //CallService(MS_DB_CONTACT_DELETE, (WPARMA)hContact, 0); + MessageBox(0, TranslateT("MetaContact number of contacts < 0 - deleting MetaContact"), nick_buffer, MB_OK | MB_ICONERROR); hNextContact = db_find_next(hContact); Meta_Delete((WPARAM)hContact, (LPARAM)1); hContact = hNextContact; continue; - //return 1; } - + if (contact_number < 0 || contact_number >= num_contacts) { // problem - MessageBox(0, Translate("MetaContact default contact number out of range - deleting MetaContact"), nick_buffer, MB_OK | MB_ICONERROR); + MessageBox(0, TranslateT("MetaContact default contact number out of range - deleting MetaContact"), nick_buffer, MB_OK | MB_ICONERROR); hNextContact = db_find_next(hContact); Meta_Delete((WPARAM)hContact, (LPARAM)1); hContact = hNextContact; - //CallService(MS_DB_CONTACT_DELETE, (WPARMA)hContact, 0); continue; - //return 1; } } hContact = db_find_next(hContact); } - + // loop through one more time - check contact counts match hContact = db_find_first(); while ( hContact != NULL ) { if ((meta_id = db_get_dw(hContact, META_PROTO, META_ID,(DWORD)-1))!=(DWORD)-1) { // get nick for debug messages - strcpy(nick_buffer, Translate("MetaId: ")); - strcat(nick_buffer, _itoa(meta_id, buffer2, 10)); num_contacts = db_get_b(hContact, META_PROTO, "ContactCountCheck", -2); if (num_contacts != (DWORD)db_get_dw(hContact, META_PROTO, "NumContacts", (DWORD)-1)) { - // mismatch - //if (MessageBox(0, Translate("MetaContact corrupted - the number of subcontacts is incorrect.\nDelete MetaContact?"), nick_buffer, MB_YESNO | MB_ICONERROR) == IDYES) { - // Meta_Delete((WPARAM)hContact, (LPARAM)1); // second param prevents confirm dialog - //} else - // return 1; hNextContact = db_find_next(hContact); - MessageBox(0, Translate("MetaContact corrupted - the number of subcontacts is incorrect.\nDeleting MetaContact."), nick_buffer, MB_OK | MB_ICONERROR); + + _tcscpy(nick_buffer, TranslateT("MetaId: ")); + _tcscat(nick_buffer, _itot(meta_id, buffer2, 10)); + MessageBox(0, TranslateT("MetaContact corrupted - the number of subcontacts is incorrect.\nDeleting MetaContact."), nick_buffer, MB_OK | MB_ICONERROR); + Meta_Delete((WPARAM)hContact, (LPARAM)1); hContact = hNextContact; continue; @@ -920,12 +913,21 @@ int Meta_SetHandles(void) { * * and ensure metafilter in place */ + +#define szMsg "The 'MetaContacts Hidden Group' has been added to your contact list.\n\ +This is most likely due to server-side contact information. To fix this, so that\n\ +MetaContacts continues to function correctly, you should:\n\ + - disable MetaContacts using the 'Toggle MetaContacts Off' main menu item\n\ + - move all contacts out of this group\n\ + - synchronize your contacts with the server\n\ + - re-enable MetaContacts" + int Meta_HideLinkedContacts(void) { DBVARIANT dbv, dbv2; DWORD meta_id, num_contacts, contact_number; WORD status; char buffer[512], buffer2[512]; - char *proto, *group_name; + char *szProto, *group_name; int hGroup = 1; HANDLE hContact2, hContact = db_find_first(); @@ -937,26 +939,19 @@ int Meta_HideLinkedContacts(void) { if (group_name && !strcmp(group_name, META_HIDDEN_GROUP)) { // disabled because it shows a message box //CallService(MS_CLIST_GROUPDELETE, (WPARAM)hGroup, 0); - MessageBox(0, Translate("The 'MetaContacts Hidden Group' has been added to your contact list.\n" - "This is most likely due to server-side contact information. To fix this, so that\n" - "MetaContacts continues to function correctly, you should:\n" - " - disable MetaContacts using the 'Toggle MetaContacts Off' main menu item\n" - " - move all contacts out of this group\n" - " - synchronize your contacts with the server\n" - " - re-enable MetaContacts"), Translate("MetaContacts Warning"), MB_ICONWARNING | MB_OK); + MessageBox(0, TranslateT(szMsg), TranslateT("MetaContacts Warning"), MB_ICONWARNING | MB_OK); break; } hGroup++; } while(group_name); - while ( hContact != NULL ) { if ((meta_id = db_get_dw(hContact, META_PROTO, META_LINK,(DWORD)-1))!=(DWORD)-1) { // get contact number contact_number = db_get_dw(hContact, META_PROTO, "ContactNumber", (DWORD)-1); // prepare to update metacontact record of subcontat status - proto = GetContactProto(hContact); + szProto = GetContactProto(hContact); // save old group and move to invisible group (i.e. non-existent group) Meta_SetGroup(hContact); @@ -969,10 +964,10 @@ int Meta_HideLinkedContacts(void) { num_contacts = db_get_dw(hContact2, META_PROTO, "NumContacts", (DWORD)-1); if (contact_number >= 0 && contact_number < num_contacts) { - if ( !proto) + if ( !szProto) status = ID_STATUS_OFFLINE; else - status = db_get_w(hContact, proto, "Status", ID_STATUS_OFFLINE); + status = db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE); // update metacontact's record of status for this contact strcpy(buffer, "Status"); @@ -980,7 +975,7 @@ int Meta_HideLinkedContacts(void) { db_set_w(hContact2, META_PROTO, buffer, status); // update metacontact's record of nick for this contact - if (proto && !db_get(hContact, proto, "Nick", &dbv)) { + if (szProto && !db_get(hContact, szProto, "Nick", &dbv)) { strcpy(buffer, "Nick"); strcat(buffer, _itoa(contact_number, buffer2, 10)); MyDBWriteContactSetting(hContact2, META_PROTO, buffer, &dbv); @@ -1159,18 +1154,18 @@ void Meta_RestoreGroup(HANDLE hContact) { } void Meta_SetGroup(HANDLE hContact) { - char *proto, *uid; + char *szProto, *uid; if (meta_group_hack_disabled) return; // clist has called api function to disable group hack - yay! // the existence of this service means that clist_meta_mw is active and will do the hiding for us if (ServiceExists(MS_CLUI_METASUPPORT)) return; - proto = GetContactProto(hContact); - if (proto) - uid = (char *)CallProtoService(proto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); + szProto = GetContactProto(hContact); + if (szProto) + uid = (char *)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); - if (proto && uid && (INT_PTR)uid != CALLSERVICE_NOTFOUND && !strcmp(JABBER_UNIQUE_ID_SETTING, uid)) { + if (szProto && uid && (INT_PTR)uid != CALLSERVICE_NOTFOUND && !strcmp(JABBER_UNIQUE_ID_SETTING, uid)) { // if it's a jabber contact, hide it, and record the fact that it was us who did db_set_b(hContact, META_PROTO, "Hidden", 1); db_set_b(hContact, "CList", "Hidden", 1); @@ -1193,44 +1188,45 @@ void Meta_SetGroup(HANDLE hContact) { } } -void Meta_GetStatusString(int status, char *buf, size_t size) { +void Meta_GetStatusString(int status, TCHAR *buf, size_t size) +{ switch(status) { - case ID_STATUS_OFFLINE: - strncpy(buf, Translate("Offline"), size); - break; - case ID_STATUS_ONLINE: - strncpy(buf, Translate("Online"), size); - break; - case ID_STATUS_AWAY: - strncpy(buf, Translate("Away"), size); - break; - case ID_STATUS_DND: - strncpy(buf, Translate("DND"), size); - break; - case ID_STATUS_NA: - strncpy(buf, Translate("N/A"), size); - break; - case ID_STATUS_OCCUPIED: - strncpy(buf, Translate("Occupied"), size); - break; - case ID_STATUS_FREECHAT: - strncpy(buf, Translate("Free to Chat"), size); - break; - case ID_STATUS_INVISIBLE: - strncpy(buf, Translate("Invisible"), size); - break; - case ID_STATUS_ONTHEPHONE: - strncpy(buf, Translate("On the Phone"), size); - break; - case ID_STATUS_OUTTOLUNCH: - strncpy(buf, Translate("Out to Lunch"), size); - break; - case ID_STATUS_IDLE: - strncpy(buf, Translate("IDLE"), size); - break; - default: - strncpy(buf, Translate("Unknown"), size); - break; + case ID_STATUS_OFFLINE: + _tcsncpy(buf, TranslateT("Offline"), size); + break; + case ID_STATUS_ONLINE: + _tcsncpy(buf, TranslateT("Online"), size); + break; + case ID_STATUS_AWAY: + _tcsncpy(buf, TranslateT("Away"), size); + break; + case ID_STATUS_DND: + _tcsncpy(buf, TranslateT("DND"), size); + break; + case ID_STATUS_NA: + _tcsncpy(buf, TranslateT("N/A"), size); + break; + case ID_STATUS_OCCUPIED: + _tcsncpy(buf, TranslateT("Occupied"), size); + break; + case ID_STATUS_FREECHAT: + _tcsncpy(buf, TranslateT("Free to Chat"), size); + break; + case ID_STATUS_INVISIBLE: + _tcsncpy(buf, TranslateT("Invisible"), size); + break; + case ID_STATUS_ONTHEPHONE: + _tcsncpy(buf, TranslateT("On the Phone"), size); + break; + case ID_STATUS_OUTTOLUNCH: + _tcsncpy(buf, TranslateT("Out to Lunch"), size); + break; + case ID_STATUS_IDLE: + _tcsncpy(buf, TranslateT("IDLE"), size); + break; + default: + _tcsncpy(buf, TranslateT("Unknown"), size); + break; } } @@ -1254,7 +1250,7 @@ int Meta_SuppressStatus(BOOL suppress) { int Meta_CopyContactNick(HANDLE hMeta, HANDLE hContact) { DBVARIANT dbv, dbv_proto; - char *proto; + char *szProto; if (options.lockHandle) { hContact = Meta_GetContactHandle(hMeta, 0); @@ -1262,13 +1258,13 @@ int Meta_CopyContactNick(HANDLE hMeta, HANDLE hContact) { if ( !hContact) return 1; - //proto = GetContactProto(hContact); - // read proto direct from db, since we do this on load and other proto plugins may not be loaded yet + //szProto = GetContactProto(hContact); + // read szProto direct from db, since we do this on load and other szProto plugins may not be loaded yet if ( !db_get(hContact, "Protocol", "p", &dbv_proto)) { - proto = dbv_proto.pszVal; - if (options.clist_contact_name == CNNT_NICK && proto) { - if ( !Mydb_get(hContact, proto, "Nick", &dbv)) { + szProto = dbv_proto.pszVal; + if (options.clist_contact_name == CNNT_NICK && szProto) { + if ( !Mydb_get(hContact, szProto, "Nick", &dbv)) { MyDBWriteContactSetting(hMeta, META_PROTO, "Nick", &dbv); db_free(&dbv); //CallService(MS_CLIST_INVALIDATEDISPLAYNAME, (WPARAM)hMeta, 0); @@ -1277,20 +1273,9 @@ int Meta_CopyContactNick(HANDLE hMeta, HANDLE hContact) { return 0; } } else if (options.clist_contact_name == CNNT_DISPLAYNAME) { - char *name = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, 0); - wchar_t *wname = (wchar_t *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_UNICODE); - - if (name && strcmp(name, Translate("(Unknown Contact)")) != 0) { - if (wname && strncmp(name, (char *)wname, strlen(name)) != 0) { - DBVARIANT dbv; - dbv.pwszVal = wname; - dbv.type = DBVT_WCHAR; - - MyDBWriteContactSetting(hMeta, META_PROTO, "Nick", &dbv); - } else - db_set_s(hMeta, META_PROTO, "Nick", name); - //CallService(MS_CLIST_INVALIDATEDISPLAYNAME, (WPARAM)hMeta, 0); - //CallService(MS_CLUI_CONTACTRENAMED, (WPARAM)hMeta, 0); + TCHAR *name = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR); + if (name && _tcscmp(name, TranslateT("(Unknown Contact)")) != 0) { + db_set_ts(hMeta, META_PROTO, "Nick", name); db_free(&dbv_proto); return 0; } @@ -1535,143 +1520,21 @@ void copyHistory(HANDLE hContactFrom,HANDLE hContactTo) } dbei.szModule = META_PROTO; - //oldBlobSize = dbei.cbBlob; - //dbei.cbBlob = oldBlobSize + id_length; dbei.flags &= ~DBEF_FIRST; - //memcpy(dbei.pBlob + oldBlobSize, id, id_length); CallService(MS_DB_EVENT_ADD, (WPARAM)hContactTo, (LPARAM)&dbei); } - //CallService(MS_DB_SETSAFETYMODE, (WPARAM)TRUE, 0); DestroyWindow(progress_dialog); if (buffer) mir_free(buffer); //mir_free(id); } -/* -void Meta_RemoveHistory(HANDLE hContactRemoveFrom, HANDLE hContactSource) { - HANDLE hDbEvent; - DBEVENTINFO dbei = { 0 }; - char *id; - DWORD id_length; - BYTE *buffer = 0; - DWORD time_now = time(0), earliest_time = time_now; - HWND progress_dialog, prog; - - if ( !hContactRemoveFrom || !hContactSource) return; - - id = Meta_GetUniqueIdentifier(hContactSource, &id_length); - if ( !id) return; - - progress_dialog = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DELPROGRESS), 0, DlgProcNull); - ShowWindow(progress_dialog, SW_SHOW); - - prog = GetDlgItem(progress_dialog, IDC_PROG); - - //CallService(MS_DB_SETSAFETYMODE, (WPARAM)FALSE, 0); - hDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDFIRST,(WPARAM)hContactRemoveFrom, 0); - while (hDbEvent) - { - // get the event - ZeroMemory(&dbei, sizeof(dbei)); - dbei.cbSize = sizeof(dbei); - - if ((dbei.cbBlob = CallService(MS_DB_EVENT_GETBLOBSIZE, (WPARAM)hDbEvent, 0)) == -1) { - break; - } - - buffer = mir_realloc(buffer, dbei.cbBlob + id_length); - dbei.pBlob = buffer; - - if (CallService(MS_DB_EVENT_GET,(WPARAM)hDbEvent,(LPARAM)&dbei)) break; - - if (dbei.timestamp < earliest_time) - earliest_time = dbei.timestamp; - - if (dbei.eventType != EVENTTYPE_MESSAGE && dbei.eventType != EVENTTYPE_FILE && dbei.eventType != EVENTTYPE_URL) { - hDbEvent=(HANDLE)CallService(MS_DB_EVENT_FINDNEXT,(WPARAM)hDbEvent,0); - continue; - } - - if (dbei.cbBlob >= id_length && strncmp((char *)(dbei.pBlob + dbei.cbBlob - id_length), id, id_length - 1) == 0) { - // event is tagged with source contact id - remove - HANDLE hDbEventNext; - - if (time_now > earliest_time) { // just in case - SendMessage(prog, PBM_SETPOS, (WPARAM)(int)(100.0 * (dbei.timestamp - earliest_time) / (time_now - earliest_time)), 0); - UpdateWindow(progress_dialog); - } - - hDbEventNext = (HANDLE)CallService(MS_DB_EVENT_FINDNEXT,(WPARAM)hDbEvent,0); - CallService(MS_DB_EVENT_DELETE, (WPARAM)hContactRemoveFrom, (LPARAM)hDbEvent); - hDbEvent = hDbEventNext; - continue; - } - - hDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDNEXT,(WPARAM)hDbEvent,0); - } - //CallService(MS_DB_SETSAFETYMODE, (WPARAM)TRUE, 0); - - DestroyWindow(progress_dialog); - if (buffer) mir_free(buffer); - mir_free(id); -} - -char *Meta_GetUniqueIdentifier(HANDLE hContact, DWORD *pused) { - char *proto = GetContactProto(hContact); - char *field; - char *id; - char buff[256]; - DWORD used; - DBVARIANT dbv; - - id = (char *)mir_alloc(256); - - if ( !proto) return 0; - - strncpy(id, proto, 127); - strcat(id, "*"); // seperate proto & proto id with asterisk to make one long comparable string - - used = strlen(id); - - field = (char *)CallProtoService(proto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0); - if ( !field) return 0; - - db_get(hContact,proto,field,&dbv); - switch(dbv.type) - { - case DBVT_ASCIIZ: - sprintf(buff,"%s",dbv.pszVal); - break; - case DBVT_BYTE: - sprintf(buff,"%d",dbv.bVal); - break; - case DBVT_WORD: - sprintf(buff,"%d",dbv.wVal); - break; - case DBVT_DWORD: - sprintf(buff,"%d",dbv.dVal); - break; - default: - sprintf(buff,"bugger this"); - } - db_free(&dbv); - - strncpy(id + used, buff, 256 - used); - if (used) { - *pused = (DWORD)(used + strlen(buff) + 1); - if (*pused > 256) *pused = 256; - } - - return id; -} -*/ void Meta_FixStatus(HANDLE hMeta) { HANDLE most_online = Meta_GetMostOnlineSupporting(hMeta, PFLAGNUM_1, 0); if (most_online) { - char *proto = GetContactProto(most_online); - if (proto) { - WORD status = (WORD)db_get_w(most_online, proto, "Status", (WORD)ID_STATUS_OFFLINE); + char *szProto = GetContactProto(most_online); + if (szProto) { + WORD status = (WORD)db_get_w(most_online, szProto, "Status", (WORD)ID_STATUS_OFFLINE); db_set_w(hMeta, META_PROTO, "Status", status); } else db_set_w(hMeta, META_PROTO, "Status", (WORD)ID_STATUS_OFFLINE); diff --git a/plugins/MetaContacts/src/metacontacts.h b/plugins/MetaContacts/src/metacontacts.h index 5312bdb4ba..8a0abca59f 100644 --- a/plugins/MetaContacts/src/metacontacts.h +++ b/plugins/MetaContacts/src/metacontacts.h @@ -78,27 +78,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. INT_PTR TranslateMenuFunc(HANDLE hContact, int i); extern HANDLE hMenuContact[MAX_CONTACTS]; -INT_PTR MenuFunc0(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc1(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc2(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc3(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc4(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc5(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc6(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc7(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc8(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc9(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc10(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc11(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc12(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc13(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc14(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc15(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc16(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc17(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc18(WPARAM wParam, LPARAM lParam); -INT_PTR MenuFunc19(WPARAM wParam, LPARAM lParam); - extern HINSTANCE hInstance; extern PLUGININFOEX pluginInfo; @@ -130,7 +109,7 @@ int Meta_SetHandles(void); int Meta_UnhideLinkedContacts(void); int Meta_GetContactNumber(HANDLE hContact); HANDLE Meta_GetContactHandle(HANDLE hMeta, int contact_number); -void Meta_GetStatusString(int status, char *buf, size_t size); +void Meta_GetStatusString(int status, TCHAR *buf, size_t size); void Meta_RestoreGroup(HANDLE hContact); void Meta_SetGroup(HANDLE hContact); int Meta_HideMetaContacts(int hide); @@ -253,7 +232,8 @@ extern BOOL meta_group_hack_disabled; #ifndef MS_CLUI_GETVERSION #define MS_CLUI_GETVERSION "CLUI/GetVersion" - extern BOOL os_unicode_enabled; +#define szDelMsg "You are going to remove all the contacts associated with this MetaContact.\nThis will delete the MetaContact.\n\nProceed Anyway?" + #endif -- cgit v1.2.3