From 7969931ecab74a0d251de7613a8427f2a9a5c86c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 26 Dec 2013 12:38:05 +0000 Subject: various code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@7382 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/UserInfoEx/src/commonheaders.h | 1 + plugins/UserInfoEx/src/dlg_msgbox.cpp | 2 +- plugins/UserInfoEx/src/dlg_msgbox.h | 22 +- plugins/UserInfoEx/src/dlg_propsheet.cpp | 1397 ++++++++++++++---------------- plugins/UserInfoEx/src/mir_db.cpp | 881 +++++++++---------- plugins/UserInfoEx/src/mir_db.h | 128 +-- 6 files changed, 1140 insertions(+), 1291 deletions(-) (limited to 'plugins/UserInfoEx') diff --git a/plugins/UserInfoEx/src/commonheaders.h b/plugins/UserInfoEx/src/commonheaders.h index d5e67ba2f5..8d02bf2cac 100644 --- a/plugins/UserInfoEx/src/commonheaders.h +++ b/plugins/UserInfoEx/src/commonheaders.h @@ -78,6 +78,7 @@ using namespace std; #include #include #include +#include #include /*********************************************************************************************************** diff --git a/plugins/UserInfoEx/src/dlg_msgbox.cpp b/plugins/UserInfoEx/src/dlg_msgbox.cpp index 8dfd6ca3dc..06a470f67d 100644 --- a/plugins/UserInfoEx/src/dlg_msgbox.cpp +++ b/plugins/UserInfoEx/src/dlg_msgbox.cpp @@ -645,7 +645,7 @@ INT_PTR MsgBoxService(WPARAM wParam, LPARAM lParam) * param: **/ -INT_PTR CALLBACK MsgBox(HWND hParent, UINT uType, LPTSTR pszTitle, LPTSTR pszInfo, LPTSTR pszFormat, ...) +INT_PTR CALLBACK MsgBox(HWND hParent, UINT uType, LPCTSTR pszTitle, LPCTSTR pszInfo, LPCTSTR pszFormat, ...) { TCHAR tszMsg[MAX_SECONDLINE]; diff --git a/plugins/UserInfoEx/src/dlg_msgbox.h b/plugins/UserInfoEx/src/dlg_msgbox.h index be104546dc..5e4651bc93 100644 --- a/plugins/UserInfoEx/src/dlg_msgbox.h +++ b/plugins/UserInfoEx/src/dlg_msgbox.h @@ -72,20 +72,20 @@ flags typedef struct _MSGBOX { - UINT cbSize; // size of this structure - UINT uType; // parameters - HICON hiLogo; // right upper icon of the info bar - HICON hiMsg; // icon left next to the message text - LPTSTR ptszTitle; - LPTSTR ptszInfoText; - LPTSTR ptszMsg; - HWND hParent; // parent window for the messagebox - COLORREF colorBack; // valid if MB_CUSTOMCOLOR is set - COLORREF colorText; // valid if MB_CUSTOMCOLOR is set + UINT cbSize; // size of this structure + UINT uType; // parameters + HICON hiLogo; // right upper icon of the info bar + HICON hiMsg; // icon left next to the message text + LPTSTR ptszTitle; + LPTSTR ptszInfoText; + LPTSTR ptszMsg; + HWND hParent; // parent window for the messagebox + COLORREF colorBack; // valid if MB_CUSTOMCOLOR is set + COLORREF colorText; // valid if MB_CUSTOMCOLOR is set } MSGBOX, *LPMSGBOX; -INT_PTR CALLBACK MsgBox(HWND hParent, UINT uType, LPTSTR pszTitle, LPTSTR pszInfo, LPTSTR pszFormat, ...); +INT_PTR CALLBACK MsgBox(HWND hParent, UINT uType, LPCTSTR pszTitle, LPCTSTR pszInfo, LPCTSTR pszFormat, ...); INT_PTR CALLBACK MsgErr(HWND hParent, LPCTSTR pszFormat, ...); INT_PTR MsgBoxService(WPARAM wParam, LPARAM lParam); diff --git a/plugins/UserInfoEx/src/dlg_propsheet.cpp b/plugins/UserInfoEx/src/dlg_propsheet.cpp index 5b42e8fccc..0892a74f24 100644 --- a/plugins/UserInfoEx/src/dlg_propsheet.cpp +++ b/plugins/UserInfoEx/src/dlg_propsheet.cpp @@ -20,8 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** - * System & local includes: - **/ +* System & local includes: +**/ #include "commonheaders.h" #include "dlg_propsheet.h" #include "psp_base.h" @@ -55,8 +55,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define INIT_ICONS_ALL (INIT_ICONS_OWNER|INIT_ICONS_CONTACT) /*********************************************************************************************************** - * internal variables - ***********************************************************************************************************/ +* internal variables +***********************************************************************************************************/ static BYTE bInitIcons = INIT_ICONS_NONE; static HANDLE ghWindowList = NULL; @@ -96,8 +96,8 @@ void CPsHdr::Free_pPages() } /*********************************************************************************************************** - * class CPsUpload - ***********************************************************************************************************/ +* class CPsUpload +***********************************************************************************************************/ class CPsUpload { public: @@ -115,36 +115,29 @@ private: LPPS _pPs; /** - * @class Upload - * @class CPsUpload - * @desc start upload process for the current protocol - * @param none - * @return 0 on success - * @return 1 otherwise - **/ + * @class Upload + * @class CPsUpload + * @desc start upload process for the current protocol + * @param none + * @return 0 on success + * @return 1 otherwise + **/ int Upload() { - CPsTreeItem *pti; - // check if icq is online - if (!IsProtoOnline((*_pPd)->szModuleName)) { - LPTSTR ptszProto = mir_a2t((*_pPd)->szModuleName); - - TCHAR szMsg[MAX_PATH]; - mir_sntprintf(szMsg, SIZEOF(szMsg), TranslateT("Protocol '%s' is offline"), ptszProto); - mir_free(ptszProto); - - MsgBox(_pPs->hDlg, MB_ICON_WARNING, TranslateT("Upload Details"), szMsg, + if (!IsProtoOnline((*_pPd)->szModuleName)) + MsgBox(_pPs->hDlg, MB_ICON_WARNING, TranslateT("Upload Details"), + CMString().Format(TranslateT("Protocol '%s' is offline"), _A2T((*_pPd)->szModuleName)), TranslateT("You are not currently connected to the ICQ network.\nYou must be online in order to update your information on the server.\n\nYour changes will be saved to database only.")); - } + // start uploading process else { _hUploading = (HANDLE)CallProtoService((*_pPd)->szModuleName, PS_CHANGEINFOEX, CIXT_FULL, NULL); if (_hUploading && _hUploading != (HANDLE)CALLSERVICE_NOTFOUND) { EnableWindow(_pPs->pTree->Window(), FALSE); - if (pti = _pPs->pTree->CurrentItem()) { + if (CPsTreeItem *pti = _pPs->pTree->CurrentItem()) EnableWindow(pti->Wnd(), FALSE); - } + EnableWindow(GetDlgItem(_pPs->hDlg, IDOK), FALSE); EnableWindow(GetDlgItem(_pPs->hDlg, IDAPPLY), FALSE); mir_snprintf(_pPs->szUpdating, SIZEOF(_pPs->szUpdating), "%s (%s)", Translate("Uploading"), (*_pPd)->szModuleName); @@ -158,13 +151,13 @@ private: public: /** - * @name CPsUpload - * @class CPsUpload - * @desc retrieves the list of installed protocols and initializes the class - * @param pPs - the owning propertysheet - * @param bExitAfter - whether the dialog is to close after upload or not - * @return nothing - **/ + * @name CPsUpload + * @class CPsUpload + * @desc retrieves the list of installed protocols and initializes the class + * @param pPs - the owning propertysheet + * @param bExitAfter - whether the dialog is to close after upload or not + * @return nothing + **/ CPsUpload(LPPS pPs, BYTE bExitAfter) { _pPs = pPs; @@ -174,7 +167,8 @@ public: _bExitAfterUploading = bExitAfter; } - int UploadFirst() { + int UploadFirst() + { // create a list of all protocols which support uploading contact information if ( ProtoEnumAccounts(&_numProto, &_pPd)) return _bExitAfterUploading ? UPLOAD_FINISH_CLOSE : UPLOAD_FINISH; @@ -183,34 +177,34 @@ public: } /** - * @name ~CPsUpload - * @class CPsUpload - * @desc clear pointer to the upload object - * @param none - * @return nothing - **/ + * @name ~CPsUpload + * @class CPsUpload + * @desc clear pointer to the upload object + * @param none + * @return nothing + **/ ~CPsUpload() { _pPs->pUpload = NULL; } /** - * @name Handle - * @class CPsUpload - * @desc returns the handle of the current upload process - * @param none - * @return handle of the current upload process - **/ + * @name Handle + * @class CPsUpload + * @desc returns the handle of the current upload process + * @param none + * @return handle of the current upload process + **/ __inline HANDLE Handle() const { return _hUploading; }; /** - * @name UploadNext - * @class CPsUpload - * @desc Search the next protocol which supports uploading contact information - * and start uploading. Delete the object if ready - * @param none - * @return nothing - **/ - int UploadNext() + * @name UploadNext + * @class CPsUpload + * @desc Search the next protocol which supports uploading contact information + * and start uploading. Delete the object if ready + * @param none + * @return nothing + **/ + int UploadNext() { CHAR str[MAXMODULELABELLENGTH]; while (_pPd && *_pPd && _numProto-- > 0) { @@ -227,15 +221,16 @@ public: }; /*********************************************************************************************************** - * propertysheet - ***********************************************************************************************************/ +* propertysheet +***********************************************************************************************************/ /** - * @name SortProc() - * @desc used for sorting the tab pages - * - * @return -1 or 0 or 1 - **/ +* @name SortProc() +* @desc used for sorting the tab pages +* +* @return -1 or 0 or 1 +**/ + static int SortProc(CPsTreeItem** item1, CPsTreeItem** item2) { if (*item1 && *item2) { @@ -246,119 +241,115 @@ static int SortProc(CPsTreeItem** item1, CPsTreeItem** item2) } /** - * This service routine creates the DetailsDialog - * @param wParam - handle to contact - * @param lParam - not used - * - * @retval 0 on success - * @retval 1 on failure - **/ +* This service routine creates the DetailsDialog +* @param wParam - handle to contact +* @param lParam - not used +* +* @retval 0 on success +* @retval 1 on failure +**/ + static INT_PTR ShowDialog(WPARAM wParam, LPARAM lParam) { - HWND hWnd; - // update some cached settings myGlobals.ShowPropsheetColours = db_get_b(NULL, MODNAME, SET_PROPSHEET_SHOWCOLOURS, TRUE); myGlobals.WantAeroAdaption = db_get_b(NULL, MODNAME, SET_PROPSHEET_AEROADAPTION, TRUE); // allow only one dialog per user - if (hWnd = WindowList_Find(ghWindowList, (HANDLE)wParam)) { + if (HWND hWnd = WindowList_Find(ghWindowList, (HANDLE)wParam)) { SetForegroundWindow(hWnd); SetFocus(hWnd); + return 0; } - else { - CPsHdr psh; - POINT metrics; - BYTE bScanMetaSubContacts = FALSE; - HICON hDefIcon; - - // init the treeview options - if (db_get_b(NULL, MODNAME, SET_PROPSHEET_SORTITEMS, FALSE)) - psh._dwFlags |= PSTVF_SORTTREE; - if (db_get_b(NULL, MODNAME, SET_PROPSHEET_GROUPS, TRUE)) - psh._dwFlags |= PSTVF_GROUPS; - // create imagelist - metrics.x = GetSystemMetrics(SM_CXSMICON); - metrics.y = GetSystemMetrics(SM_CYSMICON); - if ((psh._hImages = ImageList_Create(metrics.x, metrics.y, ILC_COLOR32 | ILC_MASK, 0, 1)) == NULL) { - MsgErr(NULL, LPGENT("Creating the imagelist failed!")); - return 1; - } - hDefIcon = Skin_GetIcon(ICO_TREE_DEFAULT); - if (!hDefIcon) - hDefIcon = (HICON) LoadImage(ghInst, MAKEINTRESOURCE(IDI_DEFAULT), IMAGE_ICON, metrics.x, metrics.y, 0); + CPsHdr psh; + POINT metrics; + bool bScanMetaSubContacts = false; + + // init the treeview options + if (db_get_b(NULL, MODNAME, SET_PROPSHEET_SORTITEMS, FALSE)) + psh._dwFlags |= PSTVF_SORTTREE; + if (db_get_b(NULL, MODNAME, SET_PROPSHEET_GROUPS, TRUE)) + psh._dwFlags |= PSTVF_GROUPS; + + // create imagelist + metrics.x = GetSystemMetrics(SM_CXSMICON); + metrics.y = GetSystemMetrics(SM_CYSMICON); + if ((psh._hImages = ImageList_Create(metrics.x, metrics.y, ILC_COLOR32 | ILC_MASK, 0, 1)) == NULL) { + MsgErr(NULL, LPGENT("Creating the imagelist failed!")); + return 1; + } - // add the default icon to imagelist - ImageList_AddIcon(psh._hImages, hDefIcon); + HICON hDefIcon = Skin_GetIcon(ICO_TREE_DEFAULT); + if (!hDefIcon) + hDefIcon = (HICON) LoadImage(ghInst, MAKEINTRESOURCE(IDI_DEFAULT), IMAGE_ICON, metrics.x, metrics.y, 0); - // init contact - psh._hContact = (HANDLE)wParam; - if (psh._hContact == NULL) { - // mark owner icons as initiated - bInitIcons |= INIT_ICONS_OWNER; - psh._pszProto = NULL; - psh._pszPrefix = NULL; - } - else { - // get contact's protocol - psh._pszPrefix = psh._pszProto = DB::Contact::Proto((HANDLE)wParam); - if (psh._pszProto == NULL) { - MsgErr(NULL, LPGENT("Could not find contact's protocol. Maybe it is not active!")); - return 1; - } - // prepare scanning for metacontact's subcontact's pages - if (bScanMetaSubContacts = DB::Module::IsMetaAndScan(psh._pszProto)) - psh._dwFlags |= PSF_PROTOPAGESONLY_INIT; - } - // add the pages - NotifyEventHooks(ghDetailsInitEvent, (WPARAM)&psh, wParam); - if (!psh._pPages || !psh._numPages) { - MsgErr(NULL, LPGENT("No pages have been added. Canceling dialog creation!")); + // add the default icon to imagelist + ImageList_AddIcon(psh._hImages, hDefIcon); + + // init contact + psh._hContact = (HANDLE)wParam; + if (psh._hContact == NULL) { + // mark owner icons as initiated + bInitIcons |= INIT_ICONS_OWNER; + psh._pszProto = NULL; + psh._pszPrefix = NULL; + } + else { + // get contact's protocol + psh._pszPrefix = psh._pszProto = DB::Contact::Proto((HANDLE)wParam); + if (psh._pszProto == NULL) { + MsgErr(NULL, LPGENT("Could not find contact's protocol. Maybe it is not active!")); return 1; } - // metacontacts sub pages - if (bScanMetaSubContacts) - { - int numSubs = DB::MetaContact::SubCount((HANDLE)wParam); + // prepare scanning for metacontact's subcontact's pages + if (bScanMetaSubContacts = DB::Module::IsMetaAndScan(psh._pszProto)) + psh._dwFlags |= PSF_PROTOPAGESONLY_INIT; + } - psh._dwFlags &= ~PSF_PROTOPAGESONLY_INIT; - psh._dwFlags |= PSF_PROTOPAGESONLY; - for (int i = 0; i < numSubs; i++) - { - psh._hContact = DB::MetaContact::Sub((HANDLE)wParam, i); - psh._nSubContact = i; - if (psh._hContact) - { - psh._pszProto = DB::Contact::Proto(psh._hContact); - if ((INT_PTR)psh._pszProto != CALLSERVICE_NOTFOUND) - NotifyEventHooks(ghDetailsInitEvent, (WPARAM)&psh, (LPARAM)psh._hContact); - } - } - psh._hContact = (HANDLE)wParam; - } + // add the pages + NotifyEventHooks(ghDetailsInitEvent, (WPARAM)&psh, wParam); + if (!psh._pPages || !psh._numPages) { + MsgErr(NULL, LPGENT("No pages have been added. Canceling dialog creation!")); + return 1; + } - // sort the pages by the position read from database - if (!(psh._dwFlags & PSTVF_SORTTREE)) { - qsort(psh._pPages, psh._numPages, sizeof(CPsTreeItem*), - (int (*)(const void*, const void*))SortProc); + // metacontacts sub pages + if (bScanMetaSubContacts) { + int numSubs = DB::MetaContact::SubCount((HANDLE)wParam); + + psh._dwFlags &= ~PSF_PROTOPAGESONLY_INIT; + psh._dwFlags |= PSF_PROTOPAGESONLY; + for (int i = 0; i < numSubs; i++) { + psh._hContact = DB::MetaContact::Sub((HANDLE)wParam, i); + psh._nSubContact = i; + if (psh._hContact) { + psh._pszProto = DB::Contact::Proto(psh._hContact); + if ((INT_PTR)psh._pszProto != CALLSERVICE_NOTFOUND) + NotifyEventHooks(ghDetailsInitEvent, (WPARAM)&psh, (LPARAM)psh._hContact); + } } - // create the dialog itself - hWnd = CreateDialogParam(ghInst, MAKEINTRESOURCE(IDD_DETAILS), NULL, DlgProc, (LPARAM)&psh); - if (!hWnd) - MsgErr(NULL, LPGENT("Details dialog failed to be created. Returning error is %d."), GetLastError()); + psh._hContact = (HANDLE)wParam; } + + // sort the pages by the position read from database + if (!(psh._dwFlags & PSTVF_SORTTREE)) + qsort(psh._pPages, psh._numPages, sizeof(CPsTreeItem*), (int(*)(const void*, const void*))SortProc); + + // create the dialog itself + if (!CreateDialogParam(ghInst, MAKEINTRESOURCE(IDD_DETAILS), NULL, DlgProc, (LPARAM)&psh)) + MsgErr(NULL, LPGENT("Details dialog failed to be created. Returning error is %d."), GetLastError()); return 0; } /** - * @name AddPage() - * @desc this adds a new pages - * @param wParam - The List of pages we want to add the new one to - * @param lParam - it's the page to add - * - * @return 0 - **/ +* @name AddPage() +* @desc this adds a new pages +* @param wParam - The List of pages we want to add the new one to +* @param lParam - it's the page to add +* +* @return 0 +**/ static INT_PTR AddPage(WPARAM wParam, LPARAM lParam) { CPsHdr *pPsh = (CPsHdr*)wParam; @@ -414,11 +405,11 @@ static INT_PTR AddPage(WPARAM wParam, LPARAM lParam) } /** - * @name OnDeleteContact() - * @desc a user was deleted, so need to close its details dialog, if one open - * - * @return 0 - **/ +* @name OnDeleteContact() +* @desc a user was deleted, so need to close its details dialog, if one open +* +* @return 0 +**/ static int OnDeleteContact(WPARAM wParam, LPARAM lParam) { HWND hWnd = WindowList_Find(ghWindowList, (HANDLE)wParam); @@ -428,11 +419,11 @@ static int OnDeleteContact(WPARAM wParam, LPARAM lParam) } /** - * @name OnShutdown() - * @desc we need to emptify the windowlist - * - * @return 0 - **/ +* @name OnShutdown() +* @desc we need to emptify the windowlist +* +* @return 0 +**/ static int OnShutdown(WPARAM wParam, LPARAM lParam) { WindowList_BroadcastAsync(ghWindowList, WM_DESTROY, 0, 0); @@ -440,14 +431,14 @@ static int OnShutdown(WPARAM wParam, LPARAM lParam) } /** - * @name AddProtocolPages() - * @desc is called by Miranda if user selects to display the userinfo dialog - * @param odp - optiondialogpage structure to use - * @param wParam - the propertysheet init structure to pass - * @param pszProto - the protocol name to prepend as item name (can be NULL) - * - * @return 0 - **/ +* @name AddProtocolPages() +* @desc is called by Miranda if user selects to display the userinfo dialog +* @param odp - optiondialogpage structure to use +* @param wParam - the propertysheet init structure to pass +* @param pszProto - the protocol name to prepend as item name (can be NULL) +* +* @return 0 +**/ static int AddProtocolPages(OPTIONSDIALOGPAGE& odp, WPARAM wParam, LPSTR pszProto = NULL) { TCHAR szTitle[MAX_PATH]; @@ -514,13 +505,13 @@ static int AddProtocolPages(OPTIONSDIALOGPAGE& odp, WPARAM wParam, LPSTR pszProt } /** - * @name InitDetails - * @desc is called by Miranda if user selects to display the userinfo dialog - * @param wParam - the propertysheet init structure to pass - * @param lParam - handle to contact whose information are read - * - * @return 0 - **/ +* @name InitDetails +* @desc is called by Miranda if user selects to display the userinfo dialog +* @param wParam - the propertysheet init structure to pass +* @param lParam - handle to contact whose information are read +* +* @return 0 +**/ static int InitDetails(WPARAM wParam, LPARAM lParam) { CPsHdr* pPsh = (CPsHdr*)wParam; @@ -552,12 +543,12 @@ static int InitDetails(WPARAM wParam, LPARAM lParam) } /** - * @name InitTreeIcons() - * @desc initalize all treeview icons - * @param none - * - * @return nothing - **/ +* @name InitTreeIcons() +* @desc initalize all treeview icons +* @param none +* +* @return nothing +**/ void DlgContactInfoInitTreeIcons() { // make sure this is run only once @@ -624,22 +615,22 @@ void DlgContactInfoInitTreeIcons() } /** - * @name UnLoadModule() - * @desc unload the UserInfo Module - * - * @return nothing - **/ +* @name UnLoadModule() +* @desc unload the UserInfo Module +* +* @return nothing +**/ void DlgContactInfoUnLoadModule() { DestroyHookableEvent(ghDetailsInitEvent); } /** - * @name LoadModule() - * @desc load the UserInfo Module - * - * @return nothing - **/ +* @name LoadModule() +* @desc load the UserInfo Module +* +* @return nothing +**/ void DlgContactInfoLoadModule() { ghDetailsInitEvent = CreateHookableEvent(ME_USERINFO_INITIALISE); @@ -674,27 +665,24 @@ void DlgContactInfoLoadModule() static void ResetUpdateInfo(LPPS pPs) { - int i; - // free the array of accomblished acks - for (i = 0; i < (int)pPs->nSubContacts; i++) + for (int i = 0; i < (int)pPs->nSubContacts; i++) MIR_FREE(pPs->infosUpdated[i].acks); MIR_FREE(pPs->infosUpdated); pPs->nSubContacts = 0; } -/* -============================================================================================ +/*============================================================================================ PropertySheet's Dialog Procedures -============================================================================================ -*/ + ============================================================================================*/ /** - * @name DlgProc() - * @desc dialog procedure for the main propertysheet dialog box - * - * @return 0 or 1 - **/ +* @name DlgProc() +* @desc dialog procedure for the main propertysheet dialog box +* +* @return 0 or 1 +**/ + static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { LPPS pPs = (LPPS)GetUserData(hDlg); @@ -703,16 +691,16 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar if (!PtrIsValid(pPs) && uMsg != WM_INITDIALOG) return FALSE; - switch (uMsg) - { + switch (uMsg) { /** - * @class WM_INITDIALOG - * @desc initiates all dialog controls - * @param wParam - not used - * lParam - pointer to a PSHDR structure, which contains all information to create the dialog - * - * @return TRUE if everything is ok, FALSE if dialog creation should fail - **/ + * @class WM_INITDIALOG + * @desc initiates all dialog controls + * @param wParam - not used + * lParam - pointer to a PSHDR structure, which contains all information to create the dialog + * + * @return TRUE if everything is ok, FALSE if dialog creation should fail + **/ + case WM_INITDIALOG: { CPsHdr* pPsh = (CPsHdr*)lParam; @@ -729,13 +717,14 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar // if (!(pPs = (LPPS)mir_alloc(sizeof(PS)))) return FALSE; - ZeroMemory(pPs, sizeof(PS)); + ZeroMemory(pPs, sizeof(PS)); if (!(pPs->pTree = new CPsTree(pPs))) return FALSE; - if (!(pPs->pTree->Create(GetDlgItem(hDlg, STATIC_TREE), pPsh))) { + + if (!(pPs->pTree->Create(GetDlgItem(hDlg, STATIC_TREE), pPsh))) return FALSE; - } + SetUserData(hDlg, pPs); pPs->hDlg = hDlg; pPs->dwFlags |= PSF_LOCKED; @@ -750,45 +739,42 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar // // set icons // - SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIcon(ICO_COMMON_MAIN, TRUE)); + SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIcon(ICO_COMMON_MAIN)); DlgProc(hDlg, HM_RELOADICONS, NULL, NULL); // // load basic protocol for current contact (for faster load later on and better handling for owner protocol) // - if (pPs->hContact) mir_strncpy(pPs->pszProto, pPsh->_pszPrefix, MAXMODULELABELLENGTH); + if (pPs->hContact) + mir_strncpy(pPs->pszProto, pPsh->_pszPrefix, MAXMODULELABELLENGTH); // set the windowtitle DlgProc(hDlg, HM_SETWINDOWTITLE, NULL, NULL); // translate Userinfo buttons - { - SendDlgItemMessage(hDlg, BTN_UPDATE, BUTTONTRANSLATE, NULL, NULL); - SendDlgItemMessage(hDlg, IDOK, BUTTONTRANSLATE, NULL, NULL); - SendDlgItemMessage(hDlg, IDCANCEL, BUTTONTRANSLATE, NULL, NULL); - SendDlgItemMessage(hDlg, IDAPPLY, BUTTONTRANSLATE, NULL, NULL); - SendDlgItemMessage(hDlg, BTN_EXPORT, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Export to file"), MBBF_TCHAR); - SendDlgItemMessage(hDlg, BTN_IMPORT, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Import from file"), MBBF_TCHAR); - } + SendDlgItemMessage(hDlg, BTN_UPDATE, BUTTONTRANSLATE, NULL, NULL); + SendDlgItemMessage(hDlg, IDOK, BUTTONTRANSLATE, NULL, NULL); + SendDlgItemMessage(hDlg, IDCANCEL, BUTTONTRANSLATE, NULL, NULL); + SendDlgItemMessage(hDlg, IDAPPLY, BUTTONTRANSLATE, NULL, NULL); + SendDlgItemMessage(hDlg, BTN_EXPORT, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Export to file"), MBBF_TCHAR); + SendDlgItemMessage(hDlg, BTN_IMPORT, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Import from file"), MBBF_TCHAR); // // set bold font for name in description area // - { - LOGFONT lf; - HFONT hNormalFont = (HFONT)SendMessage(hDlg, WM_GETFONT, 0, 0); - - GetObject(hNormalFont, sizeof(lf), &lf); - lf.lfHeight = 22; - mir_tcscpy(lf.lfFaceName, _T("Segoe UI")); - pPs->hCaptionFont = CreateFontIndirect(&lf); - SendDlgItemMessage(hDlg, IDC_PAGETITLE, WM_SETFONT, (WPARAM)pPs->hCaptionFont, 0); - - GetObject(hNormalFont, sizeof(lf), &lf); - lf.lfWeight = FW_BOLD; - pPs->hBoldFont = CreateFontIndirect(&lf); - } - + LOGFONT lf; + HFONT hNormalFont = (HFONT)SendMessage(hDlg, WM_GETFONT, 0, 0); + + GetObject(hNormalFont, sizeof(lf), &lf); + lf.lfHeight = 22; + mir_tcscpy(lf.lfFaceName, _T("Segoe UI")); + pPs->hCaptionFont = CreateFontIndirect(&lf); + SendDlgItemMessage(hDlg, IDC_PAGETITLE, WM_SETFONT, (WPARAM)pPs->hCaptionFont, 0); + + GetObject(hNormalFont, sizeof(lf), &lf); + lf.lfWeight = FW_BOLD; + pPs->hBoldFont = CreateFontIndirect(&lf); + // // initialize the optionpages and tree control // @@ -799,7 +785,6 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar // move and resize dialog and its controls // { - HWND hCtrl; RECT rcTree; POINT pt = { 0, 0 }; int addWidth = 0; @@ -840,19 +825,19 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar // move and resize the rest of the controls if (addWidth > 0) { - const WORD idResize[] = { IDC_HEADERBAR, STATIC_LINE2 }; - const WORD idMove[] = { IDC_PAGETITLE, IDC_PAGETITLEBG, IDC_PAGETITLEBG2, IDOK, IDCANCEL, IDAPPLY }; - WORD i; + static const WORD idResize[] = { IDC_HEADERBAR, STATIC_LINE2 }; + static const WORD idMove[] = { IDC_PAGETITLE, IDC_PAGETITLEBG, IDC_PAGETITLEBG2, IDOK, IDCANCEL, IDAPPLY }; + HWND hCtrl; - for (i = 0; i < SIZEOF(idResize); i++) { + for (int i = 0; i < SIZEOF(idResize); i++) { if (hCtrl = GetDlgItem(hDlg, idResize[i])) { GetWindowRect(hCtrl, &rc); OffsetRect(&rc, -pt.x, -pt.y); MoveWindow(hCtrl, rc.left, rc.top, rc.right - rc.left + addWidth, rc.bottom - rc.top, FALSE); } } - for (i = 0; i < SIZEOF(idMove); i++) { - if (hCtrl = GetDlgItem(hDlg, idMove[i])) { + for (int k = 0; k < SIZEOF(idMove); k++) { + if (hCtrl = GetDlgItem(hDlg, idMove[k])) { GetWindowRect(hCtrl, &rc); OffsetRect(&rc, -pt.x, -pt.y); MoveWindow(hCtrl, rc.left + addWidth, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE); @@ -873,85 +858,66 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar pPs->dwFlags &= ~PSF_LOCKED; pPs->dwFlags |= PSF_INITIALIZED; - // // initialize the "updating" button and statustext and check for online status // pPs->updateAnimFrame = 0; - if (pPs->hContact && *pPs->pszProto) - { + if (pPs->hContact && *pPs->pszProto) { GetDlgItemTextA(hDlg, TXT_UPDATING, pPs->szUpdating, SIZEOF(pPs->szUpdating)); ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_HIDE); if (DlgProc(hDlg, M_CHECKONLINE, NULL, NULL)) - { DlgProc(hDlg, WM_COMMAND, MAKEWPARAM(BTN_UPDATE, BN_CLICKED), (LPARAM)GetDlgItem(hDlg, BTN_UPDATE)); - } } - - { - int nPage = pPs->pTree->CurrentItemIndex(); - if (!pPs->pTree->IsIndexValid(nPage)) - nPage = 0; - TreeView_Select(pPs->pTree->Window(), NULL, TVGN_CARET); - TreeView_Select(pPs->pTree->Window(), pPs->pTree->TreeItemHandle(nPage), TVGN_CARET); - ShowWindow(hDlg, SW_SHOW); - } + int nPage = pPs->pTree->CurrentItemIndex(); + if (!pPs->pTree->IsIndexValid(nPage)) + nPage = 0; + TreeView_Select(pPs->pTree->Window(), NULL, TVGN_CARET); + TreeView_Select(pPs->pTree->Window(), pPs->pTree->TreeItemHandle(nPage), TVGN_CARET); + ShowWindow(hDlg, SW_SHOW); } return TRUE; /** - * @class WM_TIMER - * @desc is called to display the "updating" text in the status area - * @param wParam - not used - * lParam - not used - * - * @return always FALSE - **/ + * @class WM_TIMER + * @desc is called to display the "updating" text in the status area + * @param wParam - not used + * lParam - not used + * + * @return always FALSE + **/ case WM_TIMER: - switch (wParam) - { + switch (wParam) { case TIMERID_UPDATING: - { - CHAR str[84]; - - mir_snprintf(str, SIZEOF(str), "%.*s%s%.*s", pPs->updateAnimFrame%10, ".........", pPs->szUpdating, pPs->updateAnimFrame%10, "........."); - SetDlgItemTextA(hDlg, TXT_UPDATING, str); - if (++pPs->updateAnimFrame == UPDATEANIMFRAMES) - pPs->updateAnimFrame = 0; - return FALSE; - } + SetDlgItemTextA(hDlg, TXT_UPDATING, CMStringA().Format("%.*s%s%.*s", pPs->updateAnimFrame % 10, ".........", pPs->szUpdating, pPs->updateAnimFrame % 10, ".........")); + if (++pPs->updateAnimFrame == UPDATEANIMFRAMES) + pPs->updateAnimFrame = 0; + return FALSE; } break; case 0x031E: /*WM_DWMCOMPOSITIONCHANGED:*/ - { - ShowWindow(GetDlgItem(hDlg, IDC_PAGETITLEBG),IsAeroMode()); - InvalidateRect(hDlg, NULL, TRUE); - } + ShowWindow(GetDlgItem(hDlg, IDC_PAGETITLEBG), IsAeroMode()); + InvalidateRect(hDlg, NULL, TRUE); break; /** - * @class WM_CTLCOLORSTATIC - * @desc sets the colour of some of the dialog's static controls - * @param wParam - HWND of the contrls - * lParam - HDC for drawing - * - * @return StockObject - **/ + * @class WM_CTLCOLORSTATIC + * @desc sets the colour of some of the dialog's static controls + * @param wParam - HWND of the contrls + * lParam - HDC for drawing + * + * @return StockObject + **/ case WM_CTLCOLORSTATIC: - switch (GetWindowLongPtr((HWND)lParam, GWLP_ID)) - { + switch (GetWindowLongPtr((HWND)lParam, GWLP_ID)) { case TXT_UPDATING: { - COLORREF textCol, bgCol, newCol; - int ratio; - - textCol = GetSysColor(COLOR_BTNTEXT); - bgCol = GetSysColor(COLOR_3DFACE); - ratio = abs(UPDATEANIMFRAMES/2 - pPs->updateAnimFrame) * 510 / UPDATEANIMFRAMES; - newCol = RGB(GetRValue(bgCol) + (GetRValue(textCol) - GetRValue(bgCol)) * ratio / 256, + COLORREF textCol = GetSysColor(COLOR_BTNTEXT); + COLORREF bgCol = GetSysColor(COLOR_3DFACE); + int ratio = abs(UPDATEANIMFRAMES/2 - pPs->updateAnimFrame) * 510 / UPDATEANIMFRAMES; + COLORREF newCol = RGB(GetRValue(bgCol) + (GetRValue(textCol) - GetRValue(bgCol)) * ratio / 256, GetGValue(bgCol) + (GetGValue(textCol) - GetGValue(bgCol)) * ratio / 256, GetBValue(bgCol) + (GetBValue(textCol) - GetBValue(bgCol)) * ratio / 256); SetTextColor((HDC)wParam, newCol); @@ -960,34 +926,28 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar return (INT_PTR)GetSysColorBrush(COLOR_3DFACE); case IDC_PAGETITLE: case IDC_PAGETITLEBG: - { - if (IsAeroMode()) - { - SetTextColor((HDC)wParam, RGB(0,90,180)); - SetBkColor((HDC)wParam, RGB(255, 255, 255)); - return (INT_PTR)GetStockObject(WHITE_BRUSH); - } - else - { - SetBkColor((HDC)wParam, GetSysColor(COLOR_3DFACE)); - return (INT_PTR)GetSysColorBrush(COLOR_3DFACE); - } + if (IsAeroMode()) { + SetTextColor((HDC)wParam, RGB(0, 90, 180)); + SetBkColor((HDC)wParam, RGB(255, 255, 255)); + return (INT_PTR)GetStockObject(WHITE_BRUSH); } + + SetBkColor((HDC)wParam, GetSysColor(COLOR_3DFACE)); + return (INT_PTR)GetSysColorBrush(COLOR_3DFACE); } SetBkMode((HDC)wParam, TRANSPARENT); return (INT_PTR)GetStockObject(NULL_BRUSH); /** - * @class PSM_CHANGED - * @desc indicates the propertysheet and the current selected page as changed - * @param wParam - not used - * lParam - not used - * - * @return TRUE if successful FALSE if the dialog is locked at the moment - **/ + * @class PSM_CHANGED + * @desc indicates the propertysheet and the current selected page as changed + * @param wParam - not used + * lParam - not used + * + * @return TRUE if successful FALSE if the dialog is locked at the moment + **/ case PSM_CHANGED: - if (!(pPs->dwFlags & PSF_LOCKED)) - { + if (!(pPs->dwFlags & PSF_LOCKED)) { pPs->dwFlags |= PSF_CHANGED; pPs->pTree->CurrentItem()->AddFlags(PSPF_CHANGED); EnableWindow(GetDlgItem(hDlg, IDAPPLY), TRUE); @@ -996,16 +956,15 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar break; /** - * @class PSM_GETBOLDFONT - * @desc returns the bold font - * @param wParam - not used - * lParam - pointer to a HFONT, which takes the boldfont - * - * @return TRUE if successful, FALSE otherwise - **/ + * @class PSM_GETBOLDFONT + * @desc returns the bold font + * @param wParam - not used + * lParam - pointer to a HFONT, which takes the boldfont + * + * @return TRUE if successful, FALSE otherwise + **/ case PSM_GETBOLDFONT: - if (pPs->hBoldFont && lParam) - { + if (pPs->hBoldFont && lParam) { *(HFONT*)lParam = pPs->hBoldFont; SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LONG_PTR)pPs->hBoldFont); return TRUE; @@ -1015,17 +974,16 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar break; /** - * @class PSM_GETCONTACT - * @desc returns the handle to the contact, associated with this propertysheet - * @param wParam - index or -1 for current item - * lParam - pointer to a HANDLE, which takes the contact handle - * - * @return TRUE if successful, FALSE otherwise - **/ + * @class PSM_GETCONTACT + * @desc returns the handle to the contact, associated with this propertysheet + * @param wParam - index or -1 for current item + * lParam - pointer to a HANDLE, which takes the contact handle + * + * @return TRUE if successful, FALSE otherwise + **/ case PSM_GETCONTACT: - if (lParam) - { - CPsTreeItem *pti = ((int)wParam != -1) + if (lParam) { + CPsTreeItem *pti = ((int)wParam != -1) ? pPs->pTree->TreeItem((int)wParam) : pPs->pTree->CurrentItem(); @@ -1035,7 +993,7 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LONG_PTR)pti->hContact()); return TRUE; } - + // return contact who owns the details dialog if (pPs->hContact != INVALID_HANDLE_VALUE) { *(HANDLE*)lParam = pPs->hContact; @@ -1048,19 +1006,19 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar break; /** - * @class PSM_GETBASEPROTO - * @desc returns the basic protocol module for the associated contact - * @param wParam - index or -1 for current item - * lParam - pointer to a LPCSTR which takes the protocol string pointer - * - * @return TRUE if successful, FALSE otherwise - **/ + * @class PSM_GETBASEPROTO + * @desc returns the basic protocol module for the associated contact + * @param wParam - index or -1 for current item + * lParam - pointer to a LPCSTR which takes the protocol string pointer + * + * @return TRUE if successful, FALSE otherwise + **/ case PSM_GETBASEPROTO: if (lParam) { - CPsTreeItem *pti = ((int)wParam != -1) + CPsTreeItem *pti = ((int)wParam != -1) ? pPs->pTree->TreeItem((int)wParam) : pPs->pTree->CurrentItem(); - + if (pti && pti->Proto()) { // return custom protocol for the current page *(LPCSTR*)lParam = pti->Proto(); @@ -1080,31 +1038,30 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar break; /** - * @class PSM_ISLOCKED - * @desc returns the lock state of the propertysheetpage - * @param wParam - not used - * lParam - not used - * - * @return TRUE if propertysheet is locked, FALSE if not - **/ + * @class PSM_ISLOCKED + * @desc returns the lock state of the propertysheetpage + * @param wParam - not used + * lParam - not used + * + * @return TRUE if propertysheet is locked, FALSE if not + **/ case PSM_ISLOCKED: - { - BYTE bLocked = (pPs->dwFlags & PSF_LOCKED) == PSF_LOCKED; - - SetWindowLongPtr(hDlg, DWLP_MSGRESULT, bLocked); - return bLocked; - } + { + BYTE bLocked = (pPs->dwFlags & PSF_LOCKED) == PSF_LOCKED; + SetWindowLongPtr(hDlg, DWLP_MSGRESULT, bLocked); + return bLocked; + } /** - * @class PSM_FORCECHANGED - * @desc force all propertysheetpages to update their controls with new values from the database - * @param wParam - whether to replace changed settings too or not + * @class PSM_FORCECHANGED + * @desc force all propertysheetpages to update their controls with new values from the database + * @param wParam - whether to replace changed settings too or not * lParam - not used - * - * @return always FALSE - **/ + * + * @return always FALSE + **/ case PSM_FORCECHANGED: - if (!(pPs->dwFlags & PSF_LOCKED)) { + if (!(pPs->dwFlags & PSF_LOCKED)) { BYTE bChanged; pPs->dwFlags |= PSF_LOCKED; @@ -1118,42 +1075,39 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar break; /** - * @class PSM_DLGMESSAGE - * @desc Sends a message to a specified propertysheetpage - * @param wParam - not used - * lParam - LPDLGCOMMAND structure, which contains information about the message to forward - * - * @return E_FAIL if the page was not found - **/ + * @class PSM_DLGMESSAGE + * @desc Sends a message to a specified propertysheetpage + * @param wParam - not used + * lParam - LPDLGCOMMAND structure, which contains information about the message to forward + * + * @return E_FAIL if the page was not found + **/ case PSM_DLGMESSAGE: - { - LPDLGCOMMAND pCmd = (LPDLGCOMMAND)lParam; - CPsTreeItem *pti; + { + LPDLGCOMMAND pCmd = (LPDLGCOMMAND)lParam; + CPsTreeItem *pti; - if (pCmd && (pti = pPs->pTree->FindItemByResource(pCmd->hInst, pCmd->idDlg)) && pti->Wnd()) { - if (!pCmd->idDlgItem) - return SendMessage(pti->Wnd(), pCmd->uMsg, pCmd->wParam, pCmd->lParam); - else - return SendDlgItemMessage(pti->Wnd(), pCmd->idDlgItem, pCmd->uMsg, pCmd->wParam, pCmd->lParam); + if (pCmd && (pti = pPs->pTree->FindItemByResource(pCmd->hInst, pCmd->idDlg)) && pti->Wnd()) { + if (!pCmd->idDlgItem) + return SendMessage(pti->Wnd(), pCmd->uMsg, pCmd->wParam, pCmd->lParam); + else + return SendDlgItemMessage(pti->Wnd(), pCmd->idDlgItem, pCmd->uMsg, pCmd->wParam, pCmd->lParam); + } } return E_FAIL; - } /** - * @class PSM_GETPAGEHWND - * @desc get the window handle for a specified propertysheetpage - * @param wParam - recource id of the dialog recource - * lParam - hinstance of the plugin, which created the dialog box - * - * @return TRUE if handle was found and dialog was created before, false otherwise - **/ + * @class PSM_GETPAGEHWND + * @desc get the window handle for a specified propertysheetpage + * @param wParam - recource id of the dialog recource + * lParam - hinstance of the plugin, which created the dialog box + * + * @return TRUE if handle was found and dialog was created before, false otherwise + **/ case PSM_GETPAGEHWND: - { - CPsTreeItem *pti; - if (pti = pPs->pTree->FindItemByResource((HINSTANCE)lParam, wParam)) { - SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LONG_PTR)pti->Wnd()); - return (pti->Wnd() != NULL); - } + if (CPsTreeItem *pti = pPs->pTree->FindItemByResource((HINSTANCE)lParam, wParam)) { + SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LONG_PTR)pti->Wnd()); + return (pti->Wnd() != NULL); } return FALSE; @@ -1161,45 +1115,39 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar { BYTE bIsAeroMode = IsAeroMode(); if (lParam) - { *(BYTE*)lParam = bIsAeroMode; - } return (INT_PTR)bIsAeroMode; } /** - * @class HM_SETWINDOWTITLE - * @desc set the window title and text of the infobar - * @param wParam - not used - * lParam - DBCONTACTWRITESETTING structure if called by HM_SETTING_CHANGED message handler - * - * @return FALSE - **/ + * @class HM_SETWINDOWTITLE + * @desc set the window title and text of the infobar + * @param wParam - not used + * lParam - DBCONTACTWRITESETTING structure if called by HM_SETTING_CHANGED message handler + * + * @return FALSE + **/ case HM_SETWINDOWTITLE: { - LPCTSTR pszName = NULL; - TCHAR newTitle[MAX_PATH]; - RECT rc; - POINT pt = { 0, 0 }; - HWND hName = GetDlgItem(hDlg, TXT_NAME); DBCONTACTWRITESETTING* pdbcws = (DBCONTACTWRITESETTING*)lParam; + LPCTSTR pszName; if (!pPs->hContact) pszName = TranslateT("Owner"); - else - if (pdbcws && pdbcws->value.type == DBVT_TCHAR) + else if (pdbcws && pdbcws->value.type == DBVT_TCHAR) pszName = pdbcws->value.ptszVal; else pszName = DB::Contact::DisplayName(pPs->hContact); + HWND hName = GetDlgItem(hDlg, TXT_NAME); SetWindowText(hName, pszName); - mir_sntprintf(newTitle, MAX_PATH, _T("%s - %s"), pszName, TranslateT("Edit Contact Information")); - SetWindowText(hDlg, newTitle); - mir_sntprintf(newTitle, MAX_PATH, _T("%s\n%s"), TranslateT("Edit Contact Information"), pszName); - SetDlgItemText(hDlg, IDC_HEADERBAR, newTitle); + SetWindowText(hDlg, CMString().Format(_T("%s - %s"), pszName, TranslateT("Edit Contact Information"))); + SetDlgItemText(hDlg, IDC_HEADERBAR, CMString().Format(_T("%s\n%s"), TranslateT("Edit Contact Information"), pszName)); // redraw the name control + POINT pt = { 0, 0 }; ScreenToClient(hDlg, &pt); + RECT rc; GetWindowRect(hName, &rc); OffsetRect(&rc, pt.x, pt.y); InvalidateRect(hDlg, &rc, TRUE); @@ -1207,18 +1155,18 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar } /** - * @class HM_RELOADICONS - * @desc handles the changed icon event from the icolib plugin and reloads all icons - * @param wParam - not used - * lParam - not used - * - * @return FALSE - **/ + * @class HM_RELOADICONS + * @desc handles the changed icon event from the icolib plugin and reloads all icons + * @param wParam - not used + * lParam - not used + * + * @return FALSE + **/ case HM_RELOADICONS: { HWND hCtrl; HICON hIcon; - const ICONCTRL idIcon[] = { + static const ICONCTRL idIcon[] = { { ICO_DLG_DETAILS, STM_SETIMAGE, ICO_DLGLOGO }, { ICO_BTN_UPDATE, BM_SETIMAGE, BTN_UPDATE }, { ICO_BTN_OK, BM_SETIMAGE, IDOK }, @@ -1247,13 +1195,13 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar } /** - * @class M_CHECKONLINE - * @desc determines whether miranda is online or not - * @param wParam - not used - * lParam - not used - * - * @return TRUE if online, FALSE if offline - **/ + * @class M_CHECKONLINE + * @desc determines whether miranda is online or not + * @param wParam - not used + * lParam - not used + * + * @return TRUE if online, FALSE if offline + **/ case M_CHECKONLINE: { if (IsProtoOnline(pPs->pszProto)) @@ -1268,161 +1216,150 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar } /** - * @class HM_PROTOACK - * @desc handles all acks from the protocol plugin - * @param wParam - not used - * lParam - pointer to a ACKDATA structure - * - * @return FALSE - **/ + * @class HM_PROTOACK + * @desc handles all acks from the protocol plugin + * @param wParam - not used + * lParam - pointer to a ACKDATA structure + * + * @return FALSE + **/ case HM_PROTOACK: { ACKDATA *ack = (ACKDATA*)lParam; int i, iSubContact; - CPsTreeItem *pti; if (!ack->hContact && ack->type == ACKTYPE_STATUS) return DlgProc(hDlg, M_CHECKONLINE, NULL, NULL); switch (ack->type) { - - case ACKTYPE_SETINFO: - { - if (ack->hContact != pPs->hContact || !pPs->pUpload || pPs->pUpload->Handle() != ack->hProcess) + case ACKTYPE_SETINFO: + if (ack->hContact != pPs->hContact || !pPs->pUpload || pPs->pUpload->Handle() != ack->hProcess) + break; + if (ack->result == ACKRESULT_SUCCESS) { + ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_HIDE); + KillTimer(hDlg, TIMERID_UPDATING); + // upload next protocols contact information + switch (pPs->pUpload->UploadNext()) { + case CPsUpload::UPLOAD_FINISH_CLOSE: + MIR_DELETE(pPs->pUpload); + DestroyWindow(hDlg); + case CPsUpload::UPLOAD_CONTINUE: + return FALSE; + case CPsUpload::UPLOAD_FINISH: + MIR_DELETE(pPs->pUpload); break; - if (ack->result == ACKRESULT_SUCCESS) { - ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_HIDE); - KillTimer(hDlg, TIMERID_UPDATING); - // upload next protocols contact information - switch (pPs->pUpload->UploadNext()) { - case CPsUpload::UPLOAD_FINISH_CLOSE: - MIR_DELETE(pPs->pUpload); - DestroyWindow(hDlg); - case CPsUpload::UPLOAD_CONTINUE: - return FALSE; - case CPsUpload::UPLOAD_FINISH: - MIR_DELETE(pPs->pUpload); - break; - } - DlgProc(hDlg, M_CHECKONLINE, NULL, NULL); - EnableWindow(pPs->pTree->Window(), TRUE); - if (pti = pPs->pTree->CurrentItem()) { - EnableWindow(pti->Wnd(), TRUE); - } - EnableWindow(GetDlgItem(hDlg, IDOK), TRUE); - pPs->dwFlags &= ~PSF_LOCKED; } - else - if (ack->result == ACKRESULT_FAILED) { - MsgBox(hDlg, MB_ICON_WARNING, - LPGENT("Upload ICQ Details"), - LPGENT("Upload failed"), - LPGENT("Your details were not uploaded successfully.\nThey were written to database only.")); - KillTimer(hDlg, TIMERID_UPDATING); - ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_HIDE); - DlgProc(hDlg, M_CHECKONLINE, NULL, NULL); - - // upload next protocols contact information - switch (pPs->pUpload->UploadNext()) { - case CPsUpload::UPLOAD_FINISH_CLOSE: - MIR_DELETE(pPs->pUpload); - DestroyWindow(hDlg); - case CPsUpload::UPLOAD_CONTINUE: - return 0; - case CPsUpload::UPLOAD_FINISH: - MIR_DELETE(pPs->pUpload); - break; - } - if (pti = pPs->pTree->CurrentItem()) { - EnableWindow(pti->Wnd(), TRUE); - } - // activate all controls again - EnableWindow(pPs->pTree->Window(), TRUE); - EnableWindow(GetDlgItem(hDlg, IDOK), TRUE); - pPs->dwFlags &= ~PSF_LOCKED; + DlgProc(hDlg, M_CHECKONLINE, NULL, NULL); + EnableWindow(pPs->pTree->Window(), TRUE); + if (CPsTreeItem *pti = pPs->pTree->CurrentItem()) + EnableWindow(pti->Wnd(), TRUE); + EnableWindow(GetDlgItem(hDlg, IDOK), TRUE); + pPs->dwFlags &= ~PSF_LOCKED; + } + else if (ack->result == ACKRESULT_FAILED) { + MsgBox(hDlg, MB_ICON_WARNING, + LPGENT("Upload ICQ Details"), + LPGENT("Upload failed"), + LPGENT("Your details were not uploaded successfully.\nThey were written to database only.")); + KillTimer(hDlg, TIMERID_UPDATING); + ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_HIDE); + DlgProc(hDlg, M_CHECKONLINE, NULL, NULL); + + // upload next protocols contact information + switch (pPs->pUpload->UploadNext()) { + case CPsUpload::UPLOAD_FINISH_CLOSE: + MIR_DELETE(pPs->pUpload); + DestroyWindow(hDlg); + case CPsUpload::UPLOAD_CONTINUE: + return 0; + case CPsUpload::UPLOAD_FINISH: + MIR_DELETE(pPs->pUpload); + break; } - break; + if (CPsTreeItem *pti = pPs->pTree->CurrentItem()) + EnableWindow(pti->Wnd(), TRUE); + + // activate all controls again + EnableWindow(pPs->pTree->Window(), TRUE); + EnableWindow(GetDlgItem(hDlg, IDOK), TRUE); + pPs->dwFlags &= ~PSF_LOCKED; } + break; - case ACKTYPE_GETINFO: + case ACKTYPE_GETINFO: + // is contact the owner of the dialog or any metasubcontact of the owner? skip handling otherwise! + if (ack->hContact != pPs->hContact) { + if (!myGlobals.szMetaProto) + break; - // is contact the owner of the dialog or any metasubcontact of the owner? skip handling otherwise! - if (ack->hContact != pPs->hContact) { - - if (!myGlobals.szMetaProto) - break; - - if (!db_get_b(NULL, MODNAME, SET_META_SCAN, TRUE)) + if (!db_get_b(NULL, MODNAME, SET_META_SCAN, TRUE)) + break; + + for (i = 0; i < pPs->nSubContacts; i++) { + if (pPs->infosUpdated[i].hContact == ack->hContact) { + iSubContact = i; break; - - for (i = 0; i < pPs->nSubContacts; i++) { - if (pPs->infosUpdated[i].hContact == ack->hContact) { - iSubContact = i; - break; - } } - if (i == pPs->nSubContacts) - break; } - else { - iSubContact = 0; - } - - // if they're not gonna send any more ACK's don't let that mean we should crash - if (!pPs->infosUpdated || (!ack->hProcess && !ack->lParam)) { - ResetUpdateInfo(pPs); - - ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_HIDE); - KillTimer(hDlg, TIMERID_UPDATING); - DlgProc(hDlg, M_CHECKONLINE, NULL, NULL); + if (i == pPs->nSubContacts) break; - } + } + else iSubContact = 0; - if (iSubContact < pPs->nSubContacts) { + // if they're not gonna send any more ACK's don't let that mean we should crash + if (!pPs->infosUpdated || (!ack->hProcess && !ack->lParam)) { + ResetUpdateInfo(pPs); - // init the acks structure for a sub contact - if (pPs->infosUpdated[iSubContact].acks == NULL) { - pPs->infosUpdated[iSubContact].acks = (LPINT)mir_calloc(sizeof(int) * (int)(INT_PTR)ack->hProcess); - pPs->infosUpdated[iSubContact].count = (int)(INT_PTR)ack->hProcess; - } + ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_HIDE); + KillTimer(hDlg, TIMERID_UPDATING); + DlgProc(hDlg, M_CHECKONLINE, NULL, NULL); + break; + } - if (ack->result == ACKRESULT_SUCCESS || ack->result == ACKRESULT_FAILED) - pPs->infosUpdated[iSubContact].acks[ack->lParam] = 1; + if (iSubContact < pPs->nSubContacts) { + // init the acks structure for a sub contact + if (pPs->infosUpdated[iSubContact].acks == NULL) { + pPs->infosUpdated[iSubContact].acks = (LPINT)mir_calloc(sizeof(int)* (int)(INT_PTR)ack->hProcess); + pPs->infosUpdated[iSubContact].count = (int)(INT_PTR)ack->hProcess; + } - // check for pending tasks - for (iSubContact = 0; iSubContact < pPs->nSubContacts; iSubContact++) { - for (i = 0; i < pPs->infosUpdated[iSubContact].count; i++) { - if (pPs->infosUpdated[iSubContact].acks[i] == 0) - break; - } - if (i < pPs->infosUpdated[iSubContact].count) + if (ack->result == ACKRESULT_SUCCESS || ack->result == ACKRESULT_FAILED) + pPs->infosUpdated[iSubContact].acks[ack->lParam] = 1; + + // check for pending tasks + for (iSubContact = 0; iSubContact < pPs->nSubContacts; iSubContact++) { + for (i = 0; i < pPs->infosUpdated[iSubContact].count; i++) + if (pPs->infosUpdated[iSubContact].acks[i] == 0) break; - } - } - // all acks are done, finish updating - if (iSubContact >= pPs->nSubContacts) { - ResetUpdateInfo(pPs); - ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_HIDE); - KillTimer(hDlg, TIMERID_UPDATING); - DlgProc(hDlg, M_CHECKONLINE, NULL, NULL); + if (i < pPs->infosUpdated[iSubContact].count) + break; } + } + + // all acks are done, finish updating + if (iSubContact >= pPs->nSubContacts) { + ResetUpdateInfo(pPs); + ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_HIDE); + KillTimer(hDlg, TIMERID_UPDATING); + DlgProc(hDlg, M_CHECKONLINE, NULL, NULL); + } } break; } /** - * @class HM_SETTING_CHANGED - * @desc This message is called by the ME_DB_CONTACT_SETTINGCHANGED event and forces all - * unedited settings in the propertysheetpages to be updated - * @param wParam - handle to the contact whose settings are to be changed - * lParam - DBCONTACTWRITESETTING structure that identifies the changed setting - * @return FALSE - **/ + * @class HM_SETTING_CHANGED + * @desc This message is called by the ME_DB_CONTACT_SETTINGCHANGED event and forces all + * unedited settings in the propertysheetpages to be updated + * @param wParam - handle to the contact whose settings are to be changed + * lParam - DBCONTACTWRITESETTING structure that identifies the changed setting + * @return FALSE + **/ case HM_SETTING_CHANGED: if (!(pPs->dwFlags & PSF_LOCKED)) { HANDLE hContact = (HANDLE)wParam; - DBCONTACTWRITESETTING* pdbcws = (DBCONTACTWRITESETTING*)lParam; + DBCONTACTWRITESETTING *pdbcws = (DBCONTACTWRITESETTING*)lParam; if (hContact != pPs->hContact) { if (!myGlobals.szMetaProto) @@ -1454,70 +1391,64 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar // case STATIC_TREE: switch (((LPNMHDR)lParam)->code) { - case TVN_SELCHANGING: - { + case TVN_SELCHANGING: + pPs->dwFlags |= PSF_LOCKED; + pPs->pTree->OnSelChanging(); + pPs->dwFlags &= ~PSF_LOCKED; + break; + + case TVN_SELCHANGED: + if (pPs->dwFlags & PSF_INITIALIZED) { pPs->dwFlags |= PSF_LOCKED; - pPs->pTree->OnSelChanging(); + pPs->pTree->OnSelChanged((LPNMTREEVIEW)lParam); + if (pPs->pTree->CurrentItem()) { + RECT rc; + POINT pt = { 0, 0 }; + + GetWindowRect(GetDlgItem(hDlg, IDC_PAGETITLE), &rc); + ScreenToClient(hDlg, &pt); + OffsetRect(&rc, pt.x, pt.y); + SetDlgItemText(hDlg, IDC_PAGETITLE, pPs->pTree->CurrentItem()->Label()); + InvalidateRect(GetDlgItem(hDlg, IDC_PAGETITLEBG), &rc, TRUE); + InvalidateRect(hDlg, &rc, TRUE); + } pPs->dwFlags &= ~PSF_LOCKED; - break; } + break; - case TVN_SELCHANGED: - if (pPs->dwFlags & PSF_INITIALIZED) { - pPs->dwFlags |= PSF_LOCKED; - pPs->pTree->OnSelChanged((LPNMTREEVIEW)lParam); - if (pPs->pTree->CurrentItem()) - { - RECT rc; - POINT pt = { 0, 0 }; - - GetWindowRect(GetDlgItem(hDlg, IDC_PAGETITLE), &rc); - ScreenToClient(hDlg, &pt); - OffsetRect(&rc, pt.x, pt.y); - SetDlgItemText(hDlg, IDC_PAGETITLE, pPs->pTree->CurrentItem()->Label()); - InvalidateRect(GetDlgItem(hDlg, IDC_PAGETITLEBG), &rc, TRUE); - InvalidateRect(hDlg, &rc, TRUE); - } - pPs->dwFlags &= ~PSF_LOCKED; - } - break; - - case TVN_BEGINDRAG: + case TVN_BEGINDRAG: { LPNMTREEVIEW nmtv = (LPNMTREEVIEW)lParam; - if (nmtv->itemNew.hItem == TreeView_GetSelection(nmtv->hdr.hwndFrom)) { SetCapture(hDlg); pPs->pTree->BeginDrag(nmtv->itemNew.hItem); } TreeView_SelectItem(nmtv->hdr.hwndFrom, nmtv->itemNew.hItem); - break; } + break; - case TVN_ITEMEXPANDED: - pPs->pTree->AddFlags(PSTVF_STATE_CHANGED); - break; + case TVN_ITEMEXPANDED: + pPs->pTree->AddFlags(PSTVF_STATE_CHANGED); + break; - case NM_KILLFOCUS: - KillTimer(hDlg, TIMERID_RENAME); - break; + case NM_KILLFOCUS: + KillTimer(hDlg, TIMERID_RENAME); + break; - case NM_CLICK: + case NM_CLICK: { TVHITTESTINFO hti; - GetCursorPos(&hti.pt); ScreenToClient(pPs->pTree->Window(), &hti.pt); TreeView_HitTest(pPs->pTree->Window(), &hti); - if ((hti.flags & (TVHT_ONITEM|TVHT_ONITEMRIGHT)) && hti.hItem == TreeView_GetSelection(pPs->pTree->Window())) + if ((hti.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT)) && hti.hItem == TreeView_GetSelection(pPs->pTree->Window())) SetTimer(hDlg, TIMERID_RENAME, 500, NULL); - break; } + break; - case NM_RCLICK: - pPs->pTree->PopupMenu(); - return 0; - + case NM_RCLICK: + pPs->pTree->PopupMenu(); + return 0; } break; } @@ -1533,12 +1464,10 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar TreeView_HitTest(pPs->pTree->Window(), &hti); if (hti.flags & (TVHT_ONITEM|TVHT_ONITEMRIGHT)) { - RECT rc; - BYTE height; - // check where over the item, the pointer is + RECT rc; if (TreeView_GetItemRect(pPs->pTree->Window(), hti.hItem, &rc, FALSE)) { - height = (BYTE)(rc.bottom - rc.top); + BYTE height = (BYTE)(rc.bottom - rc.top); if (hti.pt.y - (height / 3) < rc.top) { SetCursor(LoadCursor(NULL, IDC_ARROW)); @@ -1564,18 +1493,16 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar break; case WM_LBUTTONUP: - // drop item if (pPs->pTree->IsDragging()) { - TVHITTESTINFO hti; RECT rc; - BYTE height; - BYTE bAsChild = FALSE; + bool bAsChild = false; TreeView_SetInsertMark(pPs->pTree->Window(), NULL, 0); ReleaseCapture(); SetCursor(LoadCursor(NULL, IDC_ARROW)); + TVHITTESTINFO hti; hti.pt.x = (SHORT)LOWORD(lParam); hti.pt.y = (SHORT)HIWORD(lParam); MapWindowPoints(hDlg, pPs->pTree->Window(), &hti.pt, 1); @@ -1586,21 +1513,17 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar break; } - if (hti.flags & TVHT_ABOVE) { + if (hti.flags & TVHT_ABOVE) hti.hItem = TVI_FIRST; - } - else - if (hti.flags & (TVHT_NOWHERE|TVHT_BELOW)) { + else if (hti.flags & (TVHT_NOWHERE|TVHT_BELOW)) hti.hItem = TVI_LAST; - } - else - if (hti.flags & (TVHT_ONITEM|TVHT_ONITEMRIGHT)) { + else if (hti.flags & (TVHT_ONITEM|TVHT_ONITEMRIGHT)) { // check where over the item, the pointer is if (!TreeView_GetItemRect(pPs->pTree->Window(), hti.hItem, &rc, FALSE)) { pPs->pTree->EndDrag(); break; } - height = (BYTE)(rc.bottom - rc.top); + BYTE height = (BYTE)(rc.bottom - rc.top); if (hti.pt.y - (height / 3) < rc.top) { HTREEITEM hItem = hti.hItem; @@ -1609,140 +1532,118 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar if (!(hti.hItem = TreeView_GetParent(pPs->pTree->Window(), hItem))) hti.hItem = TVI_FIRST; else - bAsChild = TRUE; + bAsChild = true; } } - else - if (hti.pt.y + (height / 3) <= rc.bottom) { - bAsChild = TRUE; - } + else if (hti.pt.y + (height / 3) <= rc.bottom) + bAsChild = true; } pPs->pTree->MoveItem(pPs->pTree->DragItem(), hti.hItem, bAsChild); pPs->pTree->EndDrag(); - } break; case WM_COMMAND: switch (LOWORD(wParam)) { - case IDCANCEL: - { - pPs->pTree->OnCancel(); - DestroyWindow(hDlg); - break; - } + case IDCANCEL: + pPs->pTree->OnCancel(); + DestroyWindow(hDlg); + break; + + /** + * name: IDOK / IDAPPLY + * desc: user clicked on apply or ok button in order to save changes + **/ + case IDOK: + case IDAPPLY: + if (pPs->dwFlags & PSF_CHANGED) { + // kill focus from children to make sure all data can be saved (ComboboxEx) + SetFocus(hDlg); + + pPs->dwFlags |= PSF_LOCKED; + if (pPs->pTree->OnApply()) { + pPs->dwFlags &= ~(PSF_LOCKED | PSF_CHANGED); + break; + } - /** - * name: IDOK / IDAPPLY - * desc: user clicked on apply or ok button in order to save changes - **/ - case IDOK: - case IDAPPLY: - if (pPs->dwFlags & PSF_CHANGED) { - // kill focus from children to make sure all data can be saved (ComboboxEx) - SetFocus(hDlg); + pPs->dwFlags &= ~PSF_CHANGED; + EnableWindow(GetDlgItem(hDlg, IDAPPLY), FALSE); + CallService(MS_CLIST_INVALIDATEDISPLAYNAME, (WPARAM)pPs->hContact, NULL); - pPs->dwFlags |= PSF_LOCKED; - if (pPs->pTree->OnApply()) { - pPs->dwFlags &= ~(PSF_LOCKED|PSF_CHANGED); - break; + // need to upload owners settings + if (!pPs->hContact && myGlobals.CanChangeDetails && db_get_b(NULL, MODNAME, SET_PROPSHEET_CHANGEMYDETAILS, FALSE)) { + if (pPs->pUpload = new CPsUpload(pPs, LOWORD(wParam) == IDOK)) { + if (pPs->pUpload->UploadFirst() == CPsUpload::UPLOAD_CONTINUE) + break; + MIR_DELETE(pPs->pUpload); } - - pPs->dwFlags &= ~PSF_CHANGED; - EnableWindow(GetDlgItem(hDlg, IDAPPLY), FALSE); - CallService(MS_CLIST_INVALIDATEDISPLAYNAME, (WPARAM)pPs->hContact, NULL); - - // need to upload owners settings - if (!pPs->hContact && myGlobals.CanChangeDetails && db_get_b(NULL, MODNAME, SET_PROPSHEET_CHANGEMYDETAILS, FALSE)) { - if (pPs->pUpload = new CPsUpload(pPs, LOWORD(wParam) == IDOK)) { - if (pPs->pUpload->UploadFirst() == CPsUpload::UPLOAD_CONTINUE) - break; - MIR_DELETE(pPs->pUpload); + } + pPs->dwFlags &= ~PSF_LOCKED; + } + if (LOWORD(wParam) == IDOK) + DestroyWindow(hDlg); + break; + + case BTN_UPDATE: + if (pPs->hContact != NULL) { + ResetUpdateInfo(pPs); + + mir_snprintf(pPs->szUpdating, SIZEOF(pPs->szUpdating), "%s (%s)", Translate("Updating"), pPs->pszProto); + + // need meta contact's subcontact information + if (DB::Module::IsMetaAndScan(pPs->pszProto)) { + // count valid subcontacts whose protocol supports the PSS_GETINFO service to update the information + int numSubs = DB::MetaContact::SubCount(pPs->hContact); + for (int i = 0; i < numSubs; i++) { + HANDLE hSubContact = DB::MetaContact::Sub(pPs->hContact, i); + if (hSubContact != NULL) { + if (ProtoServiceExists(DB::Contact::Proto(hSubContact), PSS_GETINFO)) { + pPs->infosUpdated = (TAckInfo*)mir_realloc(pPs->infosUpdated, sizeof(TAckInfo)* (pPs->nSubContacts + 1)); + pPs->infosUpdated[pPs->nSubContacts].hContact = hSubContact; + pPs->infosUpdated[pPs->nSubContacts].acks = NULL; + pPs->infosUpdated[pPs->nSubContacts].count = 0; + pPs->nSubContacts++; + } } } - pPs->dwFlags &= ~PSF_LOCKED; - } - if (LOWORD(wParam) == IDOK) - DestroyWindow(hDlg); - break; - case BTN_UPDATE: - { - if (pPs->hContact != NULL) - { - ResetUpdateInfo(pPs); - - mir_snprintf(pPs->szUpdating, SIZEOF(pPs->szUpdating), "%s (%s)", Translate("Updating"), pPs->pszProto); - - // need meta contact's subcontact information - if (DB::Module::IsMetaAndScan(pPs->pszProto)) - { - HANDLE hSubContact; - int i, numSubs; - - numSubs = DB::MetaContact::SubCount(pPs->hContact); - - // count valid subcontacts whose protocol supports the PSS_GETINFO service to update the information - for (i = 0; i < numSubs; i++) - { - hSubContact = DB::MetaContact::Sub(pPs->hContact, i); - if (hSubContact != NULL) - { - if ( ProtoServiceExists(DB::Contact::Proto(hSubContact), PSS_GETINFO)) - { - pPs->infosUpdated = (TAckInfo*)mir_realloc(pPs->infosUpdated, sizeof(TAckInfo) * (pPs->nSubContacts + 1)); - pPs->infosUpdated[pPs->nSubContacts].hContact = hSubContact; - pPs->infosUpdated[pPs->nSubContacts].acks = NULL; - pPs->infosUpdated[pPs->nSubContacts].count = 0; - pPs->nSubContacts++; - } - } - } + if (pPs->nSubContacts != 0) { + BYTE bDo = FALSE; - if (pPs->nSubContacts != 0) - { - BYTE bDo = FALSE; - - // call the services - for (i = 0; i < pPs->nSubContacts; i++) - { - if (!CallContactService(pPs->infosUpdated[pPs->nSubContacts].hContact, PSS_GETINFO, NULL, NULL)) - { - bDo = TRUE; - } - } - if (bDo) - { - EnableWindow(GetDlgItem(hDlg, BTN_UPDATE), FALSE); - ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_SHOW); - SetTimer(hDlg, TIMERID_UPDATING, 100, NULL); - } - } - } - else if (!CallContactService(pPs->hContact, PSS_GETINFO, NULL, NULL)) - { - pPs->infosUpdated = (TAckInfo*)mir_calloc(sizeof(TAckInfo)); - pPs->infosUpdated[0].hContact = pPs->hContact; - pPs->nSubContacts = 1; + // call the services + for (int i = 0; i < pPs->nSubContacts; i++) + if (!CallContactService(pPs->infosUpdated[pPs->nSubContacts].hContact, PSS_GETINFO, NULL, NULL)) + bDo = TRUE; + if (bDo) { EnableWindow(GetDlgItem(hDlg, BTN_UPDATE), FALSE); ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_SHOW); SetTimer(hDlg, TIMERID_UPDATING, 100, NULL); } } } - break; - - case BTN_IMPORT: - svcExIm_ContactImport_Service((WPARAM) pPs->hContact, 0); - break; - - case BTN_EXPORT: - // save changes before exporting data - DlgProc(hDlg, WM_COMMAND, MAKEWPARAM(IDAPPLY, BN_CLICKED), (LPARAM)GetDlgItem(hDlg, IDAPPLY)); - // do the exporting stuff - svcExIm_ContactExport_Service((WPARAM) pPs->hContact, 0); - break; + else if (!CallContactService(pPs->hContact, PSS_GETINFO, NULL, NULL)) { + pPs->infosUpdated = (TAckInfo*)mir_calloc(sizeof(TAckInfo)); + pPs->infosUpdated[0].hContact = pPs->hContact; + pPs->nSubContacts = 1; + + EnableWindow(GetDlgItem(hDlg, BTN_UPDATE), FALSE); + ShowWindow(GetDlgItem(hDlg, TXT_UPDATING), SW_SHOW); + SetTimer(hDlg, TIMERID_UPDATING, 100, NULL); + } + } + break; + + case BTN_IMPORT: + svcExIm_ContactImport_Service((WPARAM)pPs->hContact, 0); + break; + + case BTN_EXPORT: + // save changes before exporting data + DlgProc(hDlg, WM_COMMAND, MAKEWPARAM(IDAPPLY, BN_CLICKED), (LPARAM)GetDlgItem(hDlg, IDAPPLY)); + // do the exporting stuff + svcExIm_ContactExport_Service((WPARAM)pPs->hContact, 0); + break; } break; @@ -1751,39 +1652,35 @@ static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPar break; case WM_DESTROY: - { - int i = 0; - - // hide before destroy - ShowWindow(hDlg, SW_HIDE); + // hide before destroy + ShowWindow(hDlg, SW_HIDE); - ResetUpdateInfo(pPs); + ResetUpdateInfo(pPs); - // avoid any further message processing for this dialog page - WindowList_Remove(ghWindowList, hDlg); - SetUserData(hDlg, NULL); + // avoid any further message processing for this dialog page + WindowList_Remove(ghWindowList, hDlg); + SetUserData(hDlg, NULL); - // unhook events and stop timers - KillTimer(hDlg, TIMERID_RENAME); - UnhookEvent(pPs->hProtoAckEvent); - UnhookEvent(pPs->hSettingChanged); - UnhookEvent(pPs->hIconsChanged); + // unhook events and stop timers + KillTimer(hDlg, TIMERID_RENAME); + UnhookEvent(pPs->hProtoAckEvent); + UnhookEvent(pPs->hSettingChanged); + UnhookEvent(pPs->hIconsChanged); - // save my window position - Utils_SaveWindowPosition(hDlg, NULL, MODNAME, "DetailsDlg"); - - // save current tree and destroy it - if (pPs->pTree != NULL) { - // save tree's current look - pPs->pTree->SaveState(); - delete pPs->pTree; - pPs->pTree = NULL; - } - - DeleteObject(pPs->hCaptionFont); - DeleteObject(pPs->hBoldFont); - mir_free(pPs); pPs = NULL; + // save my window position + Utils_SaveWindowPosition(hDlg, NULL, MODNAME, "DetailsDlg"); + + // save current tree and destroy it + if (pPs->pTree != NULL) { + // save tree's current look + pPs->pTree->SaveState(); + delete pPs->pTree; + pPs->pTree = NULL; } + + DeleteObject(pPs->hCaptionFont); + DeleteObject(pPs->hBoldFont); + mir_free(pPs); pPs = NULL; } return FALSE; } diff --git a/plugins/UserInfoEx/src/mir_db.cpp b/plugins/UserInfoEx/src/mir_db.cpp index fcd347e373..9b8a8a2798 100644 --- a/plugins/UserInfoEx/src/mir_db.cpp +++ b/plugins/UserInfoEx/src/mir_db.cpp @@ -25,31 +25,19 @@ namespace DB { namespace MetaContact { -/** - * - * - **/ -INT_PTR SubCount(HANDLE hMetaContact) +INT_PTR SubCount(HANDLE hMetaContact) { INT_PTR result = CallService(MS_MC_GETNUMCONTACTS, (WPARAM) hMetaContact, 0); return (result == CALLSERVICE_NOTFOUND) ? -1 : result; } -/** - * - * - **/ -INT_PTR SubDefNum(HANDLE hMetaContact) +INT_PTR SubDefNum(HANDLE hMetaContact) { INT_PTR result = CallService(MS_MC_GETDEFAULTCONTACTNUM, (WPARAM) hMetaContact, 0); return (result == CALLSERVICE_NOTFOUND) ? -1 : result; } -/** - * - * - **/ -HANDLE Sub(HANDLE hMetaContact, int idx) +HANDLE Sub(HANDLE hMetaContact, int idx) { if (idx != -1) { INT_PTR result = CallService(MS_MC_GETSUBCONTACT, (WPARAM) hMetaContact, (LPARAM) idx); @@ -58,34 +46,20 @@ HANDLE Sub(HANDLE hMetaContact, int idx) return NULL; } -/** - * - * - **/ -BYTE IsSub(HANDLE hContact) +bool IsSub(HANDLE hContact) { return myGlobals.szMetaProto && db_get_b(NULL, myGlobals.szMetaProto, "Enabled", TRUE) && db_get_b(hContact, myGlobals.szMetaProto, "IsSubcontact", FALSE); } -/** - * - * - **/ -HANDLE GetMeta(HANDLE hContact) +HANDLE GetMeta(HANDLE hContact) { - HANDLE result; - if (myGlobals.szMetaProto){ - result = (HANDLE)CallService(MS_MC_GETMETACONTACT, (WPARAM) hContact, 0); - if (result == (HANDLE)CALLSERVICE_NOTFOUND) { - result = NULL; - } - } - else { - result = NULL; - } - return (HANDLE) result; + if (!myGlobals.szMetaProto) + return NULL; + + HANDLE result = (HANDLE)CallService(MS_MC_GETMETACONTACT, (WPARAM) hContact, 0); + return (result == (HANDLE)CALLSERVICE_NOTFOUND) ? NULL : result; } } /* namespace MetaContact */ @@ -93,23 +67,26 @@ HANDLE GetMeta(HANDLE hContact) /** * This namespace contains all functions used to access or modify contacts in the database. **/ + namespace Contact { /** - * This function retrieves the display name for a contact. - * @param hContact - handle to the contact - * @return Returns the display name of a contact. - **/ -LPTSTR DisplayName(HANDLE hContact) +* This function retrieves the display name for a contact. +* @param hContact - handle to the contact +* @return Returns the display name of a contact. +**/ + +LPTSTR DisplayName(HANDLE hContact) { - return (LPTSTR) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM) hContact, GCDNF_TCHAR); + return pcli->pfnGetContactDisplayName(hContact, 0); } /** - * This function is used to retrieve a contact's basic protocol - * @param hContact - handle to the contact - * @return This function returns the basic protocol of a contact. - **/ +* This function is used to retrieve a contact's basic protocol +* @param hContact - handle to the contact +* @return This function returns the basic protocol of a contact. +**/ + LPSTR Proto(HANDLE hContact) { if (hContact) { @@ -126,7 +103,7 @@ LPSTR Proto(HANDLE hContact) * @return Returns the number of contacts. They can be retrieved using * contact/findfirst and contact/findnext **/ -INT_PTR GetCount() +INT_PTR GetCount() { return CallService(MS_DB_CONTACT_GETCOUNT, 0, 0); } @@ -135,7 +112,7 @@ INT_PTR GetCount() * Simply adds a new contact without setting up any protocol or something else * @return HANDLE The function returns the HANDLE of the new contact **/ -HANDLE Add() +HANDLE Add() { return (HANDLE) CallService(MS_DB_CONTACT_ADD, 0, 0); } @@ -144,7 +121,7 @@ HANDLE Add() * This function deletes a contact from the database. * @param hContact - handle to the contact **/ -BYTE Delete(HANDLE hContact) +BYTE Delete(HANDLE hContact) { return CallService(MS_DB_CONTACT_DELETE, (WPARAM) hContact, 0) != 0; } @@ -154,22 +131,17 @@ BYTE Delete(HANDLE hContact) **/ DWORD WhenAdded(DWORD dwUIN, LPCSTR pszProto) { - DBEVENTINFO dbei; - HANDLE edbe; - DWORD dwEvtUIN; - - ZeroMemory(&dbei, sizeof(dbei)); - dbei.cbSize = sizeof(dbei); - for (edbe = db_event_first(NULL); edbe != NULL; edbe = db_event_next(edbe)) { + DBEVENTINFO dbei = { sizeof(dbei) }; + for (HANDLE edbe = db_event_first(NULL); edbe != NULL; edbe = db_event_next(edbe)) { // get eventtype and compare if (!DB::Event::GetInfo(edbe, &dbei) && dbei.eventType == EVENTTYPE_ADDED) { if (!DB::Event::GetInfoWithData(edbe, &dbei)) { // extract UIN and compare with given one + DWORD dwEvtUIN; CopyMemory(&dwEvtUIN, dbei.pBlob, sizeof(DWORD)); MIR_FREE(dbei.pBlob); - if (dwEvtUIN == dwUIN) { + if (dwEvtUIN == dwUIN) return dbei.timestamp; - } } } } @@ -181,54 +153,56 @@ DWORD WhenAdded(DWORD dwUIN, LPCSTR pszProto) namespace Module { /** - * Deletes all settings in the module. - * @param hContact - handle to the contact - * @param pszModule - the module to delete the setting from (e.g. USERINFO) - * return: nothing - **/ +* Deletes all settings in the module. +* @param hContact - handle to the contact +* @param pszModule - the module to delete the setting from (e.g. USERINFO) +* return: nothing +**/ + void Delete(HANDLE hContact, LPCSTR pszModule) { - CEnumList Settings; + CEnumList Settings; if (!Settings.EnumSettings(hContact, pszModule)) for (int i = 0; i < Settings.getCount(); i++) db_unset(hContact, pszModule, Settings[i]); } /** - * Enum Proc for DBModule_IsEmpty - * @param pszSetting - the setting - * @param lParam - DBCONTACTENUMSETTINGS - (LPARAM)&dbces - * @retval TRUE - always true - **/ -static int IsEmptyEnumProc(LPCSTR pszSetting, LPARAM lParam) +* Enum Proc for DBModule_IsEmpty +* @param pszSetting - the setting +* @param lParam - DBCONTACTENUMSETTINGS - (LPARAM)&dbces +* @retval TRUE - always true +**/ + +static int IsEmptyEnumProc(LPCSTR pszSetting, LPARAM lParam) { return 1; } /** - * This function tests, whether a module is empty for the given contact or not - * @param hContact - handle to the contact - * @param pszModule - the module to read the setting from (e.g. USERINFO) - * @retval TRUE - the module is empty - * @retval FALSE - the module contains settings - **/ -BYTE IsEmpty(HANDLE hContact, LPCSTR pszModule) +* This function tests, whether a module is empty for the given contact or not +* @param hContact - handle to the contact +* @param pszModule - the module to read the setting from (e.g. USERINFO) +* @retval TRUE - the module is empty +* @retval FALSE - the module contains settings +**/ + +bool IsEmpty(HANDLE hContact, LPCSTR pszModule) { - DBCONTACTENUMSETTINGS dbces; - dbces.pfnEnumProc = IsEmptyEnumProc; - dbces.szModule = pszModule; - dbces.ofsSettings = 0; - dbces.lParam = 0; + DBCONTACTENUMSETTINGS dbces = { 0 }; + dbces.pfnEnumProc = IsEmptyEnumProc; + dbces.szModule = pszModule; return (0 > CallService(MS_DB_CONTACT_ENUMSETTINGS, (WPARAM)hContact, (LPARAM)&dbces)); } /** - * This function tests, whether a module belongs to a metacontact protocol - * @param pszModule - the module to read the setting from (e.g. USERINFO) - * @retval TRUE - the module belongs to a metacontact protocol - * @retval FALSE - the module belongs to a other protocol - **/ -BYTE IsMeta(LPCSTR pszModule) +* This function tests, whether a module belongs to a metacontact protocol +* @param pszModule - the module to read the setting from (e.g. USERINFO) +* @retval TRUE - the module belongs to a metacontact protocol +* @retval FALSE - the module belongs to a other protocol +**/ + +bool IsMeta(LPCSTR pszModule) { if (myGlobals.szMetaProto) return !mir_strcmp(pszModule, myGlobals.szMetaProto); @@ -236,14 +210,15 @@ BYTE IsMeta(LPCSTR pszModule) } /** - * This function tests, whether a module is a meta contact, and user wants to scan it for settings - * @param pszModule - the module to read the setting from (e.g. USERINFO) - * @retval TRUE - the module is empty - * @retval FALSE - the module contains settings - **/ -BYTE IsMetaAndScan(LPCSTR pszModule) +* This function tests, whether a module is a meta contact, and user wants to scan it for settings +* @param pszModule - the module to read the setting from (e.g. USERINFO) +* @retval TRUE - the module is empty +* @retval FALSE - the module contains settings +**/ + +bool IsMetaAndScan(LPCSTR pszModule) { - return db_get_b(NULL, MODNAME, SET_META_SCAN, TRUE) && IsMeta(pszModule); + return 0 != db_get_b(NULL, MODNAME, SET_META_SCAN, TRUE) && IsMeta(pszModule); } } /* namespace Module */ @@ -251,83 +226,85 @@ BYTE IsMetaAndScan(LPCSTR pszModule) namespace Setting { /** - * This function calls MS_DB_CONTACT_GETSETTING_STR service to get database values. - * @param hContact - handle to the contact - * @param pszModule - the module to read the setting from (e.g. USERINFO) - * @param pszSetting - the setting to read - * @param destType - desired string type (DBVT_ASCIIZ, DBVT_WCHAR, DBVT_UTF8) - * - * @retval 0 - success - * @retval 1 - error - **/ -BYTE Get(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE destType) +* This function calls MS_DB_CONTACT_GETSETTING_STR service to get database values. +* @param hContact - handle to the contact +* @param pszModule - the module to read the setting from (e.g. USERINFO) +* @param pszSetting - the setting to read +* @param destType - desired string type (DBVT_ASCIIZ, DBVT_WCHAR, DBVT_UTF8) +* +* @retval 0 - success +* @retval 1 - error +**/ + +BYTE Get(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE destType) { // read value without translation to specific type BYTE result = db_get_s(hContact, pszModule, pszSetting, dbv, 0) != 0; // Is value read successfully and destination type set? - if (!result && destType) { + if (!result && destType) result = DB::Variant::ConvertString(dbv, destType); - } return result; } /** - * This function reads a value from the database and returns it as an ansi encoded string. - * @param hContact - handle to the contact - * @param pszModule - the module to read the setting from (e.g. USERINFO) - * @param pszSetting - the setting to read - * - * @return string value - **/ +* This function reads a value from the database and returns it as an ansi encoded string. +* @param hContact - handle to the contact +* @param pszModule - the module to read the setting from (e.g. USERINFO) +* @param pszSetting - the setting to read +* +* @return string value +**/ + LPSTR GetAString(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting) { DBVARIANT dbv; if (GetAString(hContact, pszModule, pszSetting, &dbv) == 0){ - if (DB::Variant::dbv2String(&dbv, DBVT_WCHAR) == 0) { + if (DB::Variant::dbv2String(&dbv, DBVT_WCHAR) == 0) return dbv.pszVal; - } + db_free(&dbv); } return NULL; } /** - * This function reads a value from the database and returns it as an unicode encoded string. - * @param hContact - handle to the contact - * @param pszModule - the module to read the setting from (e.g. USERINFO) - * @param pszSetting - the setting to read - * - * @return string value - **/ -LPWSTR GetWString(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting) +* This function reads a value from the database and returns it as an unicode encoded string. +* @param hContact - handle to the contact +* @param pszModule - the module to read the setting from (e.g. USERINFO) +* @param pszSetting - the setting to read +* +* @return string value +**/ + +LPWSTR GetWString(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting) { DBVARIANT dbv; if (GetWString(hContact, pszModule, pszSetting, &dbv) == 0) { - if (DB::Variant::dbv2String(&dbv, DBVT_WCHAR) == 0) { + if (DB::Variant::dbv2String(&dbv, DBVT_WCHAR) == 0) return dbv.pwszVal; - } + db_free(&dbv); } return NULL; } /** - * This function calls MS_DB_CONTACT_GETSETTING_STR service to get database values. - * It searches in pszModule first and if the setting does not exist there it tries proto to retrieve it. - * @param hContact - handle to the contact - * @param pszModule - the module to read the setting from (e.g. USERINFO) - * @param szProto - the contact's protocol to read the setting from (e.g. ICQ) - * @param szSetting - the setting to read - * @param destType - desired string type (DBVT_ASCIIZ, DBVT_WCHAR, DBVT_UTF8) - * - * @retval 0 - success - * @retval 1 - error - **/ -BYTE GetEx(HANDLE hContact, LPCSTR pszModule, LPCSTR pszProto, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE destType) +* This function calls MS_DB_CONTACT_GETSETTING_STR service to get database values. +* It searches in pszModule first and if the setting does not exist there it tries proto to retrieve it. +* @param hContact - handle to the contact +* @param pszModule - the module to read the setting from (e.g. USERINFO) +* @param szProto - the contact's protocol to read the setting from (e.g. ICQ) +* @param szSetting - the setting to read +* @param destType - desired string type (DBVT_ASCIIZ, DBVT_WCHAR, DBVT_UTF8) +* +* @retval 0 - success +* @retval 1 - error +**/ + +BYTE GetEx(HANDLE hContact, LPCSTR pszModule, LPCSTR pszProto, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE destType) { - BYTE result; - result = !pszModule || Get(hContact, pszModule, pszSetting, dbv, destType); + BYTE result = !pszModule || Get(hContact, pszModule, pszSetting, dbv, destType); // try to read setting from the contact's protocol module if (result && pszProto) { result = Get(hContact, pszProto, pszSetting, dbv, destType) != 0; @@ -350,42 +327,43 @@ BYTE GetEx(HANDLE hContact, LPCSTR pszModule, LPCSTR pszProto, LPCSTR pszSetting for (i = 0; result && i < cnt; i++) { if (i != def) { hSubContact = DB::MetaContact::Sub(hContact, i); - if (hSubContact != NULL) { + if (hSubContact != NULL) result = DB::Setting::GetEx(hSubContact, pszModule, DB::Contact::Proto(hSubContact), pszSetting, dbv, destType) != 0; - } } } } } } } + } } } } } } + return result; } /** - * This function is used by the controls of the details dialog and calls MS_DB_CONTACT_GETSETTING_STR service - * to get database values. It searches in pszModule first and if the setting does not exist there it tries proto - * to retrieve it. - * @param hContact - handle to the contact - * @param pszModule - the module to read the setting from (e.g. USERINFO) - * @param pszSubModule - the module to read the setting from a meta subcontract (e.g. USERINFO) - * @param pszProto - the contact's protocol to read the setting from (e.g. ICQ) - * @param pszSetting - the setting to read - * @param destType - desired string type (DBVT_ASCIIZ, DBVT_WCHAR, DBVT_UTF8) - * - * @return This function returns the WORD which contains the source of information. - **/ -WORD GetCtrl(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSubModule, LPCSTR pszProto, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE destType) +* This function is used by the controls of the details dialog and calls MS_DB_CONTACT_GETSETTING_STR service +* to get database values. It searches in pszModule first and if the setting does not exist there it tries proto +* to retrieve it. +* @param hContact - handle to the contact +* @param pszModule - the module to read the setting from (e.g. USERINFO) +* @param pszSubModule - the module to read the setting from a meta subcontract (e.g. USERINFO) +* @param pszProto - the contact's protocol to read the setting from (e.g. ICQ) +* @param pszSetting - the setting to read +* @param destType - desired string type (DBVT_ASCIIZ, DBVT_WCHAR, DBVT_UTF8) +* +* @return This function returns the WORD which contains the source of information. +**/ + +WORD GetCtrl(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSubModule, LPCSTR pszProto, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE destType) { WORD wFlags = 0; // read setting from given module if (hContact && pszModule && *pszModule && !Get(hContact, pszModule, pszSetting, dbv, destType)) { wFlags |= CTRLF_HASCUSTOM; - if (Exists(hContact, pszProto, pszSetting)) { + if (Exists(hContact, pszProto, pszSetting)) wFlags |= CTRLF_HASPROTO; - } } // read setting from contact's basic protocol else if (pszProto && *pszProto) { // try to read the setting from the basic protocol - if (!Get(hContact, pszProto, pszSetting, dbv, destType)) { + if (!Get(hContact, pszProto, pszSetting, dbv, destType)) wFlags |= CTRLF_HASPROTO; - } + // try to read the setting from the sub contacts' modules else if (DB::Module::IsMetaAndScan(pszProto)) { const INT_PTR def = DB::MetaContact::SubDefNum(hContact); @@ -415,39 +393,41 @@ WORD GetCtrl(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSubModule, LPCSTR pszP wFlags |= CTRLF_HASMETA; break; } } } } } } } - if (wFlags == 0) { + + if (wFlags == 0) dbv->type = DBVT_DELETED; - } + return wFlags; } /** - * This function reads a setting from database into a predefined portion of memory - * and convert numbers into a string, too. - * @param hContact - handle to the contact - * @param pszModule - the module to read the setting from (e.g. USERINFO) - * @param pszSetting - the setting to read - * @param pszValue - buffer, that retrieves the value - * @param cchValue - number of characters the buffer can take - * - * @retval 0 - success - * @retval 1 - error - **/ -BYTE GetStatic(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, LPSTR pszValue, int cchValue) +* This function reads a setting from database into a predefined portion of memory +* and convert numbers into a string, too. +* @param hContact - handle to the contact +* @param pszModule - the module to read the setting from (e.g. USERINFO) +* @param pszSetting - the setting to read +* @param pszValue - buffer, that retrieves the value +* @param cchValue - number of characters the buffer can take +* +* @retval 0 - success +* @retval 1 - error +**/ + +BYTE GetStatic(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, LPSTR pszValue, int cchValue) { DBVARIANT dbv; DBCONTACTGETSETTING sVal; if (pszValue && cchValue) { - pszValue[0] = 0; - dbv.pszVal = pszValue; - dbv.cchVal = cchValue; - dbv.type = DBVT_ASCIIZ; - - sVal.pValue = &dbv; - sVal.szModule = pszModule; - sVal.szSetting = pszSetting; - + pszValue[0] = 0; + dbv.pszVal = pszValue; + dbv.cchVal = cchValue; + dbv.type = DBVT_ASCIIZ; + + sVal.pValue = &dbv; + sVal.szModule = pszModule; + sVal.szSetting = pszSetting; + if (!CallService(MS_DB_CONTACT_GETSETTINGSTATIC, (WPARAM)hContact, (LPARAM)&sVal)) { switch (dbv.type) { case DBVT_BYTE: @@ -466,50 +446,51 @@ BYTE GetStatic(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, LPSTR pszVa } /** - * This function checks for the existence of the given setting in the database - * @param hContact - handle to the contact - * @param pszModule - the module to read the setting from (e.g. USERINFO) - * @param pszSetting - the setting to check - * - * @retval TRUE - setting exists - * @retval FALSE - setting does not exist - **/ -BYTE Exists(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting) +* This function checks for the existence of the given setting in the database +* @param hContact - handle to the contact +* @param pszModule - the module to read the setting from (e.g. USERINFO) +* @param pszSetting - the setting to check +* +* @retval TRUE - setting exists +* @retval FALSE - setting does not exist +**/ + +BYTE Exists(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting) { if (pszModule && pszSetting) { - DBCONTACTGETSETTING cgs; - DBVARIANT dbv; CHAR szDummy[1]; + DBVARIANT dbv; + dbv.pszVal = szDummy; + dbv.cchVal = sizeof(szDummy); + dbv.type = 0; - dbv.pszVal = szDummy; - dbv.cchVal = sizeof(szDummy); - dbv.type = 0; - cgs.pValue = &dbv; - cgs.szModule = pszModule; - cgs.szSetting = pszSetting; - if (!CallService(MS_DB_CONTACT_GETSETTINGSTATIC, (WPARAM) hContact, (LPARAM) &cgs)) { + DBCONTACTGETSETTING cgs; + cgs.pValue = &dbv; + cgs.szModule = pszModule; + cgs.szSetting = pszSetting; + if (!CallService(MS_DB_CONTACT_GETSETTINGSTATIC, (WPARAM) hContact, (LPARAM) &cgs)) return (dbv.type > DBVT_DELETED); - } } return FALSE; } /** - * This function deletes all reluctant settings of an setting array such as My-phoneXX. - * @param hContact - handle to the contact - * @param pszModule - the module to read the setting from (e.g. USERINFO) - * @param pszFormat - the format, telling what a array of settings is ment - * @param iStart - the first index of the setting to delete - * - * @return nothing - **/ -void DeleteArray(HANDLE hContact, LPCSTR pszModule, LPCSTR pszFormat, int iStart) +* This function deletes all reluctant settings of an setting array such as My-phoneXX. +* @param hContact - handle to the contact +* @param pszModule - the module to read the setting from (e.g. USERINFO) +* @param pszFormat - the format, telling what a array of settings is ment +* @param iStart - the first index of the setting to delete +* +* @return nothing +**/ + +void DeleteArray(HANDLE hContact, LPCSTR pszModule, LPCSTR pszFormat, int iStart) { CHAR pszSetting[MAXSETTING]; do { mir_snprintf(pszSetting, MAXSETTING, pszFormat, iStart++); } - while (!db_unset(hContact, pszModule, pszSetting)); + while (!db_unset(hContact, pszModule, pszSetting)); } } /* namespace Setting */ @@ -517,177 +498,155 @@ void DeleteArray(HANDLE hContact, LPCSTR pszModule, LPCSTR pszFormat, int iStart namespace Variant { /** - * This function converts a string value of the DBVARIANT to the destination type - * but keeps all other values as is. - * @param dbv - pointer to DBVARIANT structure which is to manipulate - * @param destType - one of (DBVT_ASCIIZ, DBVT_UTF8 or DBVT_WCHAR) - * - * @retval 0 - success - * @retval 1 - error - **/ -BYTE ConvertString(DBVARIANT* dbv, const BYTE destType) +* This function converts a string value of the DBVARIANT to the destination type +* but keeps all other values as is. +* @param dbv - pointer to DBVARIANT structure which is to manipulate +* @param destType - one of (DBVT_ASCIIZ, DBVT_UTF8 or DBVT_WCHAR) +* +* @retval 0 - success +* @retval 1 - error +**/ + +BYTE ConvertString(DBVARIANT* dbv, const BYTE destType) { - if (dbv) { - switch (dbv->type) { - // source value is of type "ascii" - case DBVT_ASCIIZ: - { - switch (destType) { - // destination type is "utf8" - case DBVT_UTF8: - { - LPSTR tmpBuf = mir_utf8encode(dbv->pszVal); - mir_free(dbv->pszVal); - dbv->pszVal = tmpBuf; - dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED; - } break; - // destination type is "wchar" - case DBVT_WCHAR: - { - LPWSTR tmpBuf = mir_a2u(dbv->pszVal); - mir_free(dbv->pszVal); - dbv->pwszVal = tmpBuf; - dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED; - } - } - } break; - // source value is of type "utf8" + if (dbv == NULL) + return 1; + + LPSTR tmpBuf; + switch (dbv->type) { + // source value is of type "ascii" + case DBVT_ASCIIZ: + switch (destType) { + // destination type is "utf8" case DBVT_UTF8: - { - switch (destType) { - // destination type is "ascii" - case DBVT_ASCIIZ: - { - mir_utf8decode(dbv->pszVal, NULL); - dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED; - } break; - // destination type is "wchar" - case DBVT_WCHAR: - { - LPSTR savePtr = dbv->pszVal; - dbv->pszVal = NULL; - mir_utf8decode(savePtr, &dbv->pwszVal); - mir_free(savePtr); - dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED; - } - } - } break; - // source value is of type "wchar" + tmpBuf = mir_utf8encode(dbv->pszVal); + mir_free(dbv->pszVal); + dbv->pszVal = tmpBuf; + dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED; + break; + // destination type is "wchar" case DBVT_WCHAR: - { - switch (destType) { - // destination type is "ascii" - case DBVT_ASCIIZ: - { - LPSTR tmpBuf = mir_u2a(dbv->pwszVal); - mir_free(dbv->pwszVal); - dbv->pszVal = tmpBuf; - dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED; - } break; - // destination type is "utf8" - case DBVT_UTF8: - { - LPSTR tmpBuf = mir_utf8encodeW(dbv->pwszVal); - mir_free(dbv->pwszVal); - dbv->pszVal = tmpBuf; - dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED; - } - } - } + LPWSTR tmpBuf = mir_a2u(dbv->pszVal); + mir_free(dbv->pszVal); + dbv->pwszVal = tmpBuf; + dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED; + } + break; + // source value is of type "utf8" + case DBVT_UTF8: + switch (destType) { + // destination type is "ascii" + case DBVT_ASCIIZ: + mir_utf8decode(dbv->pszVal, NULL); + dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED; + break; + // destination type is "wchar" + case DBVT_WCHAR: + LPSTR savePtr = dbv->pszVal; + dbv->pszVal = NULL; + mir_utf8decode(savePtr, &dbv->pwszVal); + mir_free(savePtr); + dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED; + } + break; + // source value is of type "wchar" + case DBVT_WCHAR: + switch (destType) { + // destination type is "ascii" + case DBVT_ASCIIZ: + tmpBuf = mir_u2a(dbv->pwszVal); + mir_free(dbv->pwszVal); + dbv->pszVal = tmpBuf; + dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED; + break; + // destination type is "utf8" + case DBVT_UTF8: + tmpBuf = mir_utf8encodeW(dbv->pwszVal); + mir_free(dbv->pwszVal); + dbv->pszVal = tmpBuf; + dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED; } - return dbv->type == DBVT_DELETED; } - return 1; + return dbv->type == DBVT_DELETED; } /** - * This function completely converts a DBVARIANT to the destination string type. - * It includes BYTE, WORD, DWORD and all string types - * @param dbv - pointer to DBVARIANT structure which is to manipulate - * @param destType - one of (DBVT_ASCIIZ, DBVT_UTF8 or DBVT_WCHAR) - * - * @retval 0 - success - * @retval 1 - error - **/ +* This function completely converts a DBVARIANT to the destination string type. +* It includes BYTE, WORD, DWORD and all string types +* @param dbv - pointer to DBVARIANT structure which is to manipulate +* @param destType - one of (DBVT_ASCIIZ, DBVT_UTF8 or DBVT_WCHAR) +* +* @retval 0 - success +* @retval 1 - error +**/ + BYTE dbv2String(DBVARIANT* dbv, const BYTE destType) { - if (dbv) { - switch (destType) { - // destination type is "utf8" or "ascii" + if (dbv == NULL) + return 1; + + switch (destType) { + CHAR buf[32]; + // destination type is "utf8" or "ascii" + case DBVT_ASCIIZ: + case DBVT_UTF8: + switch (dbv->type) { + // source value is of type "byte" + case DBVT_BYTE: + _ultoa(dbv->bVal, buf, 10); + dbv->pszVal = mir_strdup(buf); + dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED; + break; + // source value is of type "word" + case DBVT_WORD: + _ultoa(dbv->wVal, buf, 10); + dbv->pszVal = mir_strdup(buf); + dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED; + break; + // source value is of type "dword" + case DBVT_DWORD: + _ultoa(dbv->dVal, buf, 10); + dbv->pszVal = mir_strdup(buf); + dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED; + break; + // source value is of any string type case DBVT_ASCIIZ: + case DBVT_WCHAR: case DBVT_UTF8: - { - CHAR buf[32]; - switch (dbv->type) { - // source value is of type "byte" - case DBVT_BYTE: - { - _ultoa(dbv->bVal, buf, 10); - dbv->pszVal = mir_strdup(buf); - dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED; - } break; - // source value is of type "word" - case DBVT_WORD: - { - _ultoa(dbv->wVal, buf, 10); - dbv->pszVal = mir_strdup(buf); - dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED; - } break; - // source value is of type "dword" - case DBVT_DWORD: - { - _ultoa(dbv->dVal, buf, 10); - dbv->pszVal = mir_strdup(buf); - dbv->type = (dbv->pszVal) ? destType : DBVT_DELETED; - } break; - // source value is of any string type - case DBVT_ASCIIZ: - case DBVT_WCHAR: - case DBVT_UTF8: - { - return ConvertString(dbv, destType); - } - } - } break; - // destination type is "wchar" + return ConvertString(dbv, destType); + } + break; + + // destination type is "wchar" + case DBVT_WCHAR: + switch (dbv->type) { + WCHAR buf[32]; + // source value is of type "byte" + case DBVT_BYTE: + _ultow(dbv->bVal, buf, 10); + dbv->pwszVal = mir_wcsdup(buf); + dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED; + break; + // source value is of type "word" + case DBVT_WORD: + _ultow(dbv->wVal, buf, 10); + dbv->pwszVal = mir_wcsdup(buf); + dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED; + break; + // source value is of type "dword" + case DBVT_DWORD: + _ultow(dbv->dVal, buf, 10); + dbv->pwszVal = mir_wcsdup(buf); + dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED; + break; + // source value is of any string type + case DBVT_ASCIIZ: case DBVT_WCHAR: - { - WCHAR buf[32]; - switch (dbv->type) { - // source value is of type "byte" - case DBVT_BYTE: - { - _ultow(dbv->bVal, buf, 10); - dbv->pwszVal = mir_wcsdup(buf); - dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED; - } break; - // source value is of type "word" - case DBVT_WORD: - { - _ultow(dbv->wVal, buf, 10); - dbv->pwszVal = mir_wcsdup(buf); - dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED; - } break; - // source value is of type "dword" - case DBVT_DWORD: - { - _ultow(dbv->dVal, buf, 10); - dbv->pwszVal = mir_wcsdup(buf); - dbv->type = (dbv->pwszVal) ? destType : DBVT_DELETED; - } break; - // source value is of any string type - case DBVT_ASCIIZ: - case DBVT_WCHAR: - case DBVT_UTF8: - { - return ConvertString(dbv, destType); - } - } - } + case DBVT_UTF8: + return ConvertString(dbv, destType); } - return dbv->type != destType; } - return 1; + return dbv->type != destType; } } /* namespace Variant */ @@ -695,15 +654,16 @@ BYTE dbv2String(DBVARIANT* dbv, const BYTE destType) namespace Event { /** - * This function initializes the DBEVENTINFO structure and calls - * db_event_get() to retrieve information about an event. - * @param hEvent - the handle of the event to get information for - * @param dbei - the pointer to a DBEVENTINFO structure, which retrieves all information. - * - * @retval 0 - success - * @retval nonezero - failure - **/ -BYTE GetInfo(HANDLE hEvent, DBEVENTINFO *dbei) +* This function initializes the DBEVENTINFO structure and calls +* db_event_get() to retrieve information about an event. +* @param hEvent - the handle of the event to get information for +* @param dbei - the pointer to a DBEVENTINFO structure, which retrieves all information. +* +* @retval 0 - success +* @retval nonezero - failure +**/ + +bool GetInfo(HANDLE hEvent, DBEVENTINFO *dbei) { dbei->cbSize = sizeof(DBEVENTINFO); dbei->cbBlob = 0; @@ -712,15 +672,16 @@ BYTE GetInfo(HANDLE hEvent, DBEVENTINFO *dbei) } /** - * This function initializes the DBEVENTINFO structure and calls - * db_event_get() to retrieve information about an event. - * @param hEvent - the handle of the event to get information for - * @param dbei - the pointer to a DBEVENTINFO structure, which retrieves all information. - * - * @retval 0 - success - * @retval 1 - failure - **/ -BYTE GetInfoWithData(HANDLE hEvent, DBEVENTINFO *dbei) +* This function initializes the DBEVENTINFO structure and calls +* db_event_get() to retrieve information about an event. +* @param hEvent - the handle of the event to get information for +* @param dbei - the pointer to a DBEVENTINFO structure, which retrieves all information. +* +* @retval 0 - success +* @retval 1 - failure +**/ + +bool GetInfoWithData(HANDLE hEvent, DBEVENTINFO *dbei) { dbei->cbSize = sizeof(DBEVENTINFO); if (!dbei->cbBlob) { @@ -729,13 +690,12 @@ BYTE GetInfoWithData(HANDLE hEvent, DBEVENTINFO *dbei) } if (dbei->cbBlob) { dbei->pBlob = (PBYTE) mir_alloc(dbei->cbBlob); - if (dbei->pBlob == NULL) { + if (dbei->pBlob == NULL) dbei->cbBlob = 0; - } } else dbei->pBlob = NULL; - BYTE result = db_event_get(hEvent, dbei) != 0; + bool result = db_event_get(hEvent, dbei) != 0; if (result && dbei->pBlob) { mir_free(dbei->pBlob); dbei->pBlob = NULL; @@ -744,86 +704,83 @@ BYTE GetInfoWithData(HANDLE hEvent, DBEVENTINFO *dbei) } /** - * This function returns the timestamp for the given event. - * @param hEvent - the handle of the event to get the timestamp for - * - * @retval 0 if no timestamp is available - * @retval timestamp - **/ +* This function returns the timestamp for the given event. +* @param hEvent - the handle of the event to get the timestamp for +* +* @retval 0 if no timestamp is available +* @retval timestamp +**/ + DWORD TimeOf(HANDLE hEvent) { DBEVENTINFO dbei; - if (!GetInfo(hEvent, &dbei)) { + if (!GetInfo(hEvent, &dbei)) return dbei.timestamp; - } + return 0; } /** - * This function compares two DBEVENTINFO structures against each other. - * It compares the timestamp, eventType and module names. - * @param d1 - pointer to the first DBEVENTINFO structure - * @param d2 - pointer to the second DBEVENTINFO structure - * @param Data - default false, if true compare also blob data +* This function compares two DBEVENTINFO structures against each other. +* It compares the timestamp, eventType and module names. +* @param d1 - pointer to the first DBEVENTINFO structure +* @param d2 - pointer to the second DBEVENTINFO structure +* @param Data - default false, if true compare also blob data .* - * @retval TRUE - The structures describe the same event. - * @retval FALSE - The two structure's events differ from each other. - **/ -static FORCEINLINE -BYTE IsEqual(const DBEVENTINFO *d1, const DBEVENTINFO *d2, bool Data) +* @retval TRUE - The structures describe the same event. +* @retval FALSE - The two structure's events differ from each other. +**/ + +static FORCEINLINE bool IsEqual(const DBEVENTINFO *d1, const DBEVENTINFO *d2, bool Data) { - BYTE res = d1 && d2 && + bool res = d1 && d2 && (d1->timestamp == d2->timestamp) && (d1->eventType == d2->eventType) && (d1->cbBlob == d2->cbBlob) && - (!d1->szModule || !d2->szModule || !_stricmp(d1->szModule, d2->szModule)) - ; - if (Data) { - return res && - (!d1->pBlob || !d2->pBlob || !memcmp(d1->pBlob,d2->pBlob,d1->cbBlob)) - ; - } + (!d1->szModule || !d2->szModule || !_stricmp(d1->szModule, d2->szModule)); + if (Data) + return res && (!d1->pBlob || !d2->pBlob || !memcmp(d1->pBlob,d2->pBlob,d1->cbBlob)); + return res; } /** - * This functions searches for an existing event in the database, which matches - * the information provided by 'dbei'. In order to fasten up the search e.g. - * while checking many events, this function stars searching from the last - * found event. - * @param hContact - the handle of the contact to search events for - * @param hDbExistingEvent - an existing database event to start the search from. - * @param dbei - the pointer to a DBEVENTINFO structure - * - * @retval TRUE - the event identified by its information in @c dbei exists. - * @retval FALSE - no event with the information of @c dbei exists. - * - **/ -BYTE Exists(HANDLE hContact, HANDLE& hDbExistingEvent, DBEVENTINFO *dbei) +* This functions searches for an existing event in the database, which matches +* the information provided by 'dbei'. In order to fasten up the search e.g. +* while checking many events, this function stars searching from the last +* found event. +* @param hContact - the handle of the contact to search events for +* @param hDbExistingEvent - an existing database event to start the search from. +* @param dbei - the pointer to a DBEVENTINFO structure +* +* @retval TRUE - the event identified by its information in @c dbei exists. +* @retval FALSE - no event with the information of @c dbei exists. +* +**/ + +bool Exists(HANDLE hContact, HANDLE& hDbExistingEvent, DBEVENTINFO *dbei) { - BYTE result = FALSE; + bool result = false; DBEVENTINFO edbei; - HANDLE sdbe, - edbe; if (!hDbExistingEvent) { hDbExistingEvent = db_event_first(hContact); if (hDbExistingEvent) { if (!GetInfo(hDbExistingEvent, &edbei)) { - if ((dbei->timestamp < edbei.timestamp)) { - return FALSE; - } + if ((dbei->timestamp < edbei.timestamp)) + return false; + if (IsEqual(dbei, &edbei, false)) { if (!GetInfoWithData(hDbExistingEvent, &edbei)) { if (IsEqual(dbei, &edbei, true)) { mir_free(edbei.pBlob); - return TRUE; + return true; } mir_free(edbei.pBlob); } } } - edbe = db_event_last(hContact); + HANDLE edbe = db_event_last(hContact); if (edbe == hDbExistingEvent) return FALSE; @@ -831,37 +788,35 @@ BYTE Exists(HANDLE hContact, HANDLE& hDbExistingEvent, DBEVENTINFO *dbei) } } if (hDbExistingEvent) { - sdbe = hDbExistingEvent; - for ( edbe = sdbe; - edbe && !GetInfo(edbe, &edbei) && (dbei->timestamp <= edbei.timestamp); - edbe = db_event_prev(edbe)) { + HANDLE sdbe = hDbExistingEvent; + for (HANDLE edbe = sdbe; edbe && !GetInfo(edbe, &edbei) && (dbei->timestamp <= edbei.timestamp); edbe = db_event_prev(edbe)) { hDbExistingEvent = edbe; //compare without data (faster) if ( result = IsEqual(dbei, &edbei, false)) { - if (NULL == (result = !GetInfoWithData(edbe, &edbei))) continue; + if (NULL == (result = !GetInfoWithData(edbe, &edbei))) + continue; + //compare with data result = IsEqual(dbei, &edbei, true); mir_free(edbei.pBlob); - if (result) { + if (result) break; - } } } /*end for*/ if (!result) { - for ( edbe = db_event_next(sdbe); - edbe && !GetInfo(edbe, &edbei) && (dbei->timestamp >= edbei.timestamp); - edbe = db_event_next(edbe)) { + for (HANDLE edbe = db_event_next(sdbe); edbe && !GetInfo(edbe, &edbei) && (dbei->timestamp >= edbei.timestamp); edbe = db_event_next(edbe)) { hDbExistingEvent = edbe; //compare without data (faster) - if ( result = IsEqual(dbei, &edbei, false)) { - if (NULL == (result = !GetInfoWithData(edbe, &edbei))) continue; + if (result = IsEqual(dbei, &edbei, false)) { + if (NULL == (result = !GetInfoWithData(edbe, &edbei))) + continue; + //compare with data result = IsEqual(dbei, &edbei, true); mir_free(edbei.pBlob); - if (result) { + if (result) break; - } } } } @@ -873,9 +828,8 @@ BYTE Exists(HANDLE hContact, HANDLE& hDbExistingEvent, DBEVENTINFO *dbei) int CEnumList::EnumProc(LPCSTR pszName, DWORD ofsModuleName, LPARAM lParam) { - if (pszName) { + if (pszName) ((CEnumList*)lParam)->Insert(pszName); - } return 0; } @@ -887,9 +841,9 @@ int CEnumList::EnumSettingsProc(LPCSTR pszName, LPARAM lParam) int CEnumList::CompareProc(LPCSTR p1, LPCSTR p2) { if (p1) { - if (p2) { + if (p2) return strcmp(p1, p2); - } + return 1; } return 0; @@ -901,14 +855,10 @@ CEnumList::CEnumList() : LIST(50, (FTSortFunc)CEnumList::CompareProc) CEnumList::~CEnumList() { - int i, cnt; - LPSTR p; - - for (i = 0, cnt = getCount(); i < cnt; i++) { - p = (*this)[i]; - if (p) { + for (int i = 0, cnt = getCount(); i < cnt; i++) { + LPSTR p = (*this)[i]; + if (p) mir_free(p); - } } destroy(); } @@ -929,17 +879,16 @@ INT_PTR CEnumList::EnumModules() } /** - * @retval -1 - no settings to enumerate - * @retval 0 - success - **/ +* @retval -1 - no settings to enumerate +* @retval 0 - success +**/ + INT_PTR CEnumList::EnumSettings(HANDLE hContact, LPCSTR pszModule) { - DBCONTACTENUMSETTINGS dbces; - + DBCONTACTENUMSETTINGS dbces = { 0 }; dbces.pfnEnumProc = (DBSETTINGENUMPROC)CEnumList::EnumSettingsProc; dbces.szModule = pszModule; dbces.lParam = (LPARAM)this; - dbces.ofsSettings = 0; return CallService(MS_DB_CONTACT_ENUMSETTINGS, (WPARAM)hContact, (LPARAM)&dbces); } diff --git a/plugins/UserInfoEx/src/mir_db.h b/plugins/UserInfoEx/src/mir_db.h index ed60f07b90..471d0db5d4 100644 --- a/plugins/UserInfoEx/src/mir_db.h +++ b/plugins/UserInfoEx/src/mir_db.h @@ -24,13 +24,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. namespace DB { namespace MetaContact{ - INT_PTR SubCount (HANDLE hMetaContact); - INT_PTR SubDefNum (HANDLE hMetaContact); - HANDLE Sub (HANDLE hMetaContact, int idx); - - BYTE IsSub (HANDLE hContact); - HANDLE GetMeta (HANDLE hContact); + INT_PTR SubCount(HANDLE hMetaContact); + INT_PTR SubDefNum(HANDLE hMetaContact); + HANDLE Sub(HANDLE hMetaContact, int idx); + bool IsSub(HANDLE hContact); + HANDLE GetMeta(HANDLE hContact); } /* namespace MetaContact */ /** @@ -38,23 +37,23 @@ namespace MetaContact{ * or modify contacts in the database. **/ namespace Contact { - LPTSTR DisplayName (HANDLE hContact); - LPSTR Proto (HANDLE hContact); + LPTSTR DisplayName(HANDLE hContact); + LPSTR Proto(HANDLE hContact); - INT_PTR GetCount (); + INT_PTR GetCount(); - HANDLE Add(); - BYTE Delete (HANDLE hContact); + HANDLE Add(); + BYTE Delete(HANDLE hContact); - DWORD WhenAdded (DWORD dwUIN, LPCSTR szBaseProto); + DWORD WhenAdded(DWORD dwUIN, LPCSTR szBaseProto); } /* namespace Contact */ namespace Module { - void Delete (HANDLE hContact, LPCSTR pszModule); - BYTE IsEmpty (HANDLE hContact, LPCSTR pszModule); - BYTE IsMeta (LPCSTR pszModule); - BYTE IsMetaAndScan (LPCSTR pszModule); + void Delete(HANDLE hContact, LPCSTR pszModule); + bool IsEmpty(HANDLE hContact, LPCSTR pszModule); + bool IsMeta(LPCSTR pszModule); + bool IsMetaAndScan(LPCSTR pszModule); } /* namespace Module */ @@ -63,69 +62,72 @@ namespace Module { **/ namespace Setting { - BYTE Get (HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE nType); - static FORCEINLINE - BYTE GetAsIs (HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv) {return Get(hContact, pszModule, pszSetting, dbv, 0); } - static FORCEINLINE - BYTE GetAString (HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv) {return Get(hContact, pszModule, pszSetting, dbv, DBVT_ASCIIZ); } - LPSTR GetAString (HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting); - static FORCEINLINE - BYTE GetWString (HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv) {return Get(hContact, pszModule, pszSetting, dbv, DBVT_WCHAR); } - LPWSTR GetWString (HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting); - static FORCEINLINE - BYTE GetUString (HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv) {return Get(hContact, pszModule, pszSetting, dbv, DBVT_UTF8); } - - BYTE GetEx (HANDLE hContact, LPCSTR pszModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE nType); - static FORCEINLINE - BYTE GetAsIsEx (HANDLE hContact, LPCSTR pszModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv) { return GetEx(hContact, pszModule, szProto, pszSetting, dbv, 0); } - static FORCEINLINE - LPSTR GetAStringEx (HANDLE hContact, LPCSTR pszModule, LPCSTR szProto, LPCSTR pszSetting) { DBVARIANT dbv; return (!GetEx(hContact, pszModule, szProto, pszSetting, &dbv, DBVT_ASCIIZ) && dbv.type == DBVT_ASCIIZ) ? dbv.pszVal : NULL; } - static FORCEINLINE - LPWSTR GetWStringEx (HANDLE hContact, LPCSTR pszModule, LPCSTR szProto, LPCSTR pszSetting) { DBVARIANT dbv; return (!GetEx(hContact, pszModule, szProto, pszSetting, &dbv, DBVT_WCHAR) && dbv.type == DBVT_WCHAR) ? dbv.pwszVal : NULL; } - static FORCEINLINE - LPSTR GetUStringEx (HANDLE hContact, LPCSTR pszModule, LPCSTR szProto, LPCSTR pszSetting) { DBVARIANT dbv; return (!GetEx(hContact, pszModule, szProto, pszSetting, &dbv, DBVT_UTF8) && dbv.type == DBVT_UTF8) ? dbv.pszVal : NULL; } - - WORD GetCtrl (HANDLE hContact, LPCSTR pszModule, LPCSTR szSubModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE nType); - static FORCEINLINE - WORD GetAsIsCtrl (HANDLE hContact, LPCSTR pszModule, LPCSTR szSubModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv) { return GetCtrl(hContact, pszModule, szSubModule, szProto, pszSetting, dbv, 0); } - static FORCEINLINE - WORD GetAStringCtrl(HANDLE hContact, LPCSTR pszModule, LPCSTR szSubModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv) { return GetCtrl(hContact, pszModule, szSubModule, szProto, pszSetting, dbv, DBVT_ASCIIZ); } - static FORCEINLINE - WORD GetWStringCtrl(HANDLE hContact, LPCSTR pszModule, LPCSTR szSubModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv) { return GetCtrl(hContact, pszModule, szSubModule, szProto, pszSetting, dbv, DBVT_WCHAR); } - static FORCEINLINE - WORD GetUStringCtrl(HANDLE hContact, LPCSTR pszModule, LPCSTR szSubModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv) { return GetCtrl(hContact, pszModule, szSubModule, szProto, pszSetting, dbv, DBVT_UTF8); } - - BYTE GetStatic (HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, LPSTR szValue, int cchValue); - - #define GetTString GetWString - #define GetTStringEx GetWStringEx - #define GetTStringCtrl GetWStringCtrl - #define WriteTString WriteWString + BYTE Get(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE nType); + static FORCEINLINE BYTE GetAsIs(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv) + { return Get(hContact, pszModule, pszSetting, dbv, 0); } + static FORCEINLINE BYTE GetAString(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv) + { return Get(hContact, pszModule, pszSetting, dbv, DBVT_ASCIIZ); } + + LPSTR GetAString(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting); + static FORCEINLINE BYTE GetWString(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv) + { return Get(hContact, pszModule, pszSetting, dbv, DBVT_WCHAR); } + + LPWSTR GetWString(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting); + static FORCEINLINE BYTE GetUString(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, DBVARIANT *dbv) + { return Get(hContact, pszModule, pszSetting, dbv, DBVT_UTF8); } + + BYTE GetEx(HANDLE hContact, LPCSTR pszModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE nType); + static FORCEINLINE BYTE GetAsIsEx(HANDLE hContact, LPCSTR pszModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv) + { return GetEx(hContact, pszModule, szProto, pszSetting, dbv, 0); } + static FORCEINLINE LPSTR GetAStringEx(HANDLE hContact, LPCSTR pszModule, LPCSTR szProto, LPCSTR pszSetting) + { DBVARIANT dbv; return (!GetEx(hContact, pszModule, szProto, pszSetting, &dbv, DBVT_ASCIIZ) && dbv.type == DBVT_ASCIIZ) ? dbv.pszVal : NULL; } + static FORCEINLINE LPWSTR GetWStringEx(HANDLE hContact, LPCSTR pszModule, LPCSTR szProto, LPCSTR pszSetting) + { DBVARIANT dbv; return (!GetEx(hContact, pszModule, szProto, pszSetting, &dbv, DBVT_WCHAR) && dbv.type == DBVT_WCHAR) ? dbv.pwszVal : NULL; } + static FORCEINLINE LPSTR GetUStringEx(HANDLE hContact, LPCSTR pszModule, LPCSTR szProto, LPCSTR pszSetting) + { DBVARIANT dbv; return (!GetEx(hContact, pszModule, szProto, pszSetting, &dbv, DBVT_UTF8) && dbv.type == DBVT_UTF8) ? dbv.pszVal : NULL; } + + WORD GetCtrl(HANDLE hContact, LPCSTR pszModule, LPCSTR szSubModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv, const BYTE nType); + static FORCEINLINE WORD GetAsIsCtrl(HANDLE hContact, LPCSTR pszModule, LPCSTR szSubModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv) + { return GetCtrl(hContact, pszModule, szSubModule, szProto, pszSetting, dbv, 0); } + static FORCEINLINE WORD GetAStringCtrl(HANDLE hContact, LPCSTR pszModule, LPCSTR szSubModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv) + { return GetCtrl(hContact, pszModule, szSubModule, szProto, pszSetting, dbv, DBVT_ASCIIZ); } + static FORCEINLINE WORD GetWStringCtrl(HANDLE hContact, LPCSTR pszModule, LPCSTR szSubModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv) + { return GetCtrl(hContact, pszModule, szSubModule, szProto, pszSetting, dbv, DBVT_WCHAR); } + static FORCEINLINE WORD GetUStringCtrl(HANDLE hContact, LPCSTR pszModule, LPCSTR szSubModule, LPCSTR szProto, LPCSTR pszSetting, DBVARIANT *dbv) + { return GetCtrl(hContact, pszModule, szSubModule, szProto, pszSetting, dbv, DBVT_UTF8); } + + BYTE GetStatic(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting, LPSTR szValue, int cchValue); + + #define GetTString GetWString + #define GetTStringEx GetWStringEx + #define GetTStringCtrl GetWStringCtrl + #define WriteTString WriteWString /** * misc operations **/ - BYTE Exists (HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting); - void DeleteArray (HANDLE hContact, LPCSTR pszModule, LPCSTR pszFormat, int iStart); + BYTE Exists(HANDLE hContact, LPCSTR pszModule, LPCSTR pszSetting); + void DeleteArray(HANDLE hContact, LPCSTR pszModule, LPCSTR pszFormat, int iStart); } /* namespace Setting */ namespace Variant { - BYTE ConvertString (DBVARIANT* dbv, const BYTE destType); - BYTE dbv2String (DBVARIANT* dbv, const BYTE destType); + BYTE ConvertString(DBVARIANT* dbv, const BYTE destType); + BYTE dbv2String(DBVARIANT* dbv, const BYTE destType); } /* namespace Variant */ namespace Event { - HANDLE FindLast (HANDLE hContact); - BYTE GetInfo (HANDLE hEvent, DBEVENTINFO *dbei); - BYTE GetInfoWithData(HANDLE hEvent, DBEVENTINFO *dbei); - DWORD GetTime (HANDLE hEvent); - BYTE Exists (HANDLE hContact, HANDLE& hDbExistingEvent, DBEVENTINFO *dbei); + HANDLE FindLast(HANDLE hContact); + bool GetInfo(HANDLE hEvent, DBEVENTINFO *dbei); + bool GetInfoWithData(HANDLE hEvent, DBEVENTINFO *dbei); + DWORD GetTime(HANDLE hEvent); + bool Exists(HANDLE hContact, HANDLE& hDbExistingEvent, DBEVENTINFO *dbei); } /* namespace Events */ /** * enumerating **/ + class CEnumList : public ::LIST { static int EnumProc (LPCSTR pszName, DWORD ofsModuleName, LPARAM lParam); -- cgit v1.2.3