From 8956a4b69fdf9bfec0feb17b0911d549f1cdd9ee Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 10 Aug 2018 21:56:11 +0300 Subject: Msg_Export: options dialog -> UI Classes --- plugins/Msg_Export/src/FileViewer.cpp | 20 +-- plugins/Msg_Export/src/FileViewer.h | 2 +- plugins/Msg_Export/src/main.cpp | 8 +- plugins/Msg_Export/src/options.cpp | 274 ++++++++++++++-------------------- plugins/Msg_Export/src/stdafx.h | 2 + plugins/Msg_Export/src/utils.cpp | 125 ++++++---------- plugins/Msg_Export/src/utils.h | 37 ++--- 7 files changed, 193 insertions(+), 275 deletions(-) (limited to 'plugins') diff --git a/plugins/Msg_Export/src/FileViewer.cpp b/plugins/Msg_Export/src/FileViewer.cpp index 03acddac16..3cbfbdcdcd 100755 --- a/plugins/Msg_Export/src/FileViewer.cpp +++ b/plugins/Msg_Export/src/FileViewer.cpp @@ -32,7 +32,7 @@ static UINT UM_FIND_CMD = RegisterWindowMessage(FINDMSGSTRING); bool bUseIntViewer = true; // External program used to view files -tstring sFileViewerPrg; +wstring sFileViewerPrg; // handle to the RichEditDll. We need to load this dll to use a RichEdit. HMODULE hRichEditDll = nullptr; @@ -104,7 +104,7 @@ public: HWND hWnd; MCONTACT hContact; - tstring sPath; + wstring sPath; HWND hFindDlg; FINDREPLACE fr; @@ -258,7 +258,7 @@ int CLStreamRTFInfo::nLoadFileStream(LPBYTE pbBuff, LONG cb) } dwCurrent += nWriteHeader((char*)pbBuff, cb); - tstring sMyNick = ptrW(GetMyOwnNick(hContact)); + wstring sMyNick = ptrW(GetMyOwnNick(hContact)); nNickLen = WideCharToMultiByte(bUtf8File ? CP_UTF8 : CP_ACP, 0, sMyNick.c_str(), (int)sMyNick.length(), szMyNick, sizeof(szMyNick), NULL, NULL); } @@ -449,7 +449,7 @@ void UpdateFileViews(const wchar_t *pszFile) bool bOpenExternaly(MCONTACT hContact) { - tstring sPath = GetFilePathFromUser(hContact); + wstring sPath = GetFilePathFromUser(hContact); if (sFileViewerPrg.empty()) { @@ -462,7 +462,7 @@ bool bOpenExternaly(MCONTACT hContact) ShellExecuteEx(&st); return true; } - tstring sTmp = sFileViewerPrg; + wstring sTmp = sFileViewerPrg; sTmp += L" \""; sTmp += sPath; sTmp += '\"'; @@ -908,7 +908,7 @@ void SetRichEditFont(HWND hRichEdit, bool bUseSyntaxHL) ncf.dwMask = CFM_BOLD | CFM_FACE | CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE; ncf.dwEffects = db_get_dw(NULL, MODULENAME, szFileViewDB "TEffects", 0); ncf.yHeight = db_get_dw(NULL, MODULENAME, szFileViewDB "THeight", 165); - wcsncpy_s(ncf.szFaceName, _DBGetString(NULL, MODULENAME, szFileViewDB "TFace", L"Courier New").c_str(), _TRUNCATE); + wcsncpy_s(ncf.szFaceName, _DBGetStringW(NULL, MODULENAME, szFileViewDB "TFace", L"Courier New").c_str(), _TRUNCATE); if (!bUseSyntaxHL) { ncf.dwMask |= CFM_COLOR; @@ -983,7 +983,7 @@ static INT_PTR CALLBACK DlgProcFileViewer(HWND hwndDlg, UINT msg, WPARAM wParam, wchar_t szTitle[200]; if (GetWindowText(hwndDlg, szFormat, _countof(szFormat))) { const wchar_t *pszNick = Clist_GetContactDisplayName(pclDlg->hContact); - tstring sPath = pclDlg->sPath; + wstring sPath = pclDlg->sPath; string::size_type n = sPath.find_last_of('\\'); if (n != sPath.npos) sPath.erase(0, n + 1); @@ -1036,7 +1036,7 @@ static INT_PTR CALLBACK DlgProcFileViewer(HWND hwndDlg, UINT msg, WPARAM wParam, lf.lfStrikeOut = (dwEffects & CFE_STRIKEOUT) != 0; lf.lfItalic = (dwEffects & CFE_ITALIC) != 0; - wcsncpy_s(lf.lfFaceName, _DBGetString(NULL, MODULENAME, szFileViewDB "TFace", L"Courier New").c_str(), _TRUNCATE); + wcsncpy_s(lf.lfFaceName, _DBGetStringW(NULL, MODULENAME, szFileViewDB "TFace", L"Courier New").c_str(), _TRUNCATE); CHOOSEFONT cf = { 0 }; cf.lStructSize = sizeof(cf); cf.hwndOwner = hwndDlg; @@ -1101,7 +1101,7 @@ static INT_PTR CALLBACK DlgProcFileViewer(HWND hwndDlg, UINT msg, WPARAM wParam, return TRUE; } if ((wParam & 0xFFF0) == ID_FV_SAVE_AS_RTF) { - tstring sFile = pclDlg->sPath; + wstring sFile = pclDlg->sPath; sFile += L".rtf"; HANDLE hFile = CreateFile(sFile.c_str(), GENERIC_WRITE, FILE_SHARE_READ, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); @@ -1122,7 +1122,7 @@ static INT_PTR CALLBACK DlgProcFileViewer(HWND hwndDlg, UINT msg, WPARAM wParam, return TRUE; } CloseHandle(hFile); - tstring sReport = TranslateT("History was saved successfully in file\r\n"); + wstring sReport = TranslateT("History was saved successfully in file\r\n"); sReport += sFile; MessageBox(nullptr, sReport.c_str(), MSG_BOX_TITEL, MB_OK); return TRUE; diff --git a/plugins/Msg_Export/src/FileViewer.h b/plugins/Msg_Export/src/FileViewer.h index de58099d6d..4e238bdf54 100755 --- a/plugins/Msg_Export/src/FileViewer.h +++ b/plugins/Msg_Export/src/FileViewer.h @@ -27,7 +27,7 @@ bool bShowFileViewer(MCONTACT hContact); bool bUseInternalViewer(bool bNew); bool bUseInternalViewer(); -extern tstring sFileViewerPrg; +extern wstring sFileViewerPrg; #endif diff --git a/plugins/Msg_Export/src/main.cpp b/plugins/Msg_Export/src/main.cpp index 89817922df..3ce7781be1 100755 --- a/plugins/Msg_Export/src/main.cpp +++ b/plugins/Msg_Export/src/main.cpp @@ -145,12 +145,12 @@ int CMPlugin::Load() if (nMaxLineWidth > 0 && nMaxLineWidth < 5) nMaxLineWidth = 5; - sExportDir = _DBGetString(NULL, MODULENAME, "ExportDir", L"%dbpath%\\MsgExport\\"); - sDefaultFile = _DBGetString(NULL, MODULENAME, "DefaultFile", L"%nick%.txt"); + sExportDir = _DBGetStringW(NULL, MODULENAME, "ExportDir", L"%dbpath%\\MsgExport\\"); + sDefaultFile = _DBGetStringW(NULL, MODULENAME, "DefaultFile", L"%nick%.txt"); - sTimeFormat = _DBGetString(NULL, MODULENAME, "TimeFormat", L"d s"); + sTimeFormat = _DBGetStringW(NULL, MODULENAME, "TimeFormat", L"d s"); - sFileViewerPrg = _DBGetString(NULL, MODULENAME, "FileViewerPrg", L""); + sFileViewerPrg = _DBGetStringW(NULL, MODULENAME, "FileViewerPrg", L""); bUseInternalViewer(db_get_b(NULL, MODULENAME, "UseInternalViewer", bUseInternalViewer()) != 0); bReplaceHistory = db_get_b(NULL, MODULENAME, "ReplaceHistory", bReplaceHistory) != 0; diff --git a/plugins/Msg_Export/src/options.cpp b/plugins/Msg_Export/src/options.cpp index 99d6912123..a6d3dc35f3 100755 --- a/plugins/Msg_Export/src/options.cpp +++ b/plugins/Msg_Export/src/options.cpp @@ -95,16 +95,14 @@ int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) return mir_wstrcmpi(Clist_GetContactDisplayName(lParam1), Clist_GetContactDisplayName(lParam2)); if (lParamSort == 2) - return _DBGetString((MCONTACT)lParam1, "Protocol", "p", L"").compare(_DBGetString((MCONTACT)lParam2, "Protocol", "p", L"")); + return mir_strcmp(GetContactProto((MCONTACT)lParam1), GetContactProto((MCONTACT)lParam2)); if (lParamSort == 3) { - DWORD dwUin1 = db_get_dw((MCONTACT)lParam1, _DBGetStringA((MCONTACT)lParam1, "Protocol", "p", "").c_str(), "UIN", 0); - DWORD dwUin2 = db_get_dw((MCONTACT)lParam2, _DBGetStringA((MCONTACT)lParam2, "Protocol", "p", "").c_str(), "UIN", 0); + DWORD dwUin1 = db_get_dw((MCONTACT)lParam1, GetContactProto((MCONTACT)lParam1), "UIN", 0); + DWORD dwUin2 = db_get_dw((MCONTACT)lParam2, GetContactProto((MCONTACT)lParam2), "UIN", 0); if (dwUin1 == dwUin2) return 0; - if (dwUin1 > dwUin2) - return -1; - return 1; + return (dwUin1 > dwUin2) ? -1 : 1; } return 0; } @@ -154,7 +152,7 @@ void __cdecl exportContactsMessages(ExportDialogData *data) SetWindowText(hStatus, TranslateT("Reading database information (Phase 1 of 2)")); // map with list to stored all DB history before it is exported - map, less > AllEvents; + map, less > AllEvents; { // reading from the database !!! int nCur = 0; @@ -190,7 +188,7 @@ void __cdecl exportContactsMessages(ExportDialogData *data) SendMessage(hProg, PBM_SETPOS, 0, 0); // time to write to files !!! - map, less >::iterator FileIterator; + map, less >::iterator FileIterator; int nCur = 0; for (FileIterator = AllEvents.begin(); FileIterator != AllEvents.end(); ++FileIterator) { @@ -329,7 +327,7 @@ void SetToDefault(HWND hParent) if (!ListView_GetItem(hMapUser, &sItem)) continue; - tstring sFileName = szTemp; + wstring sFileName = szTemp; ReplaceDefines((MCONTACT)sItem.lParam, sFileName); ReplaceTimeVariables(sFileName); @@ -516,7 +514,7 @@ void AutoFindeFileNames(HWND hwndDlg) } if (nShortestMatch != 0xFFFF) { - tstring sFileName; + wstring sFileName; szSearch[0] = 0; ListView_GetItemText(hMapUser, nCur, 0, szSearch, _countof(szSearch)); bool bPriHasFileName = szSearch[0] != 0; @@ -622,7 +620,7 @@ static INT_PTR CALLBACK DlgProcMsgExportOpts(HWND hwndDlg, UINT msg, WPARAM wPar } { int nUser = 0; - tstring sTmp; + wstring sTmp; LVITEM sItem = { 0 }; for (auto &hContact : Contacts()) { PROTOACCOUNT *pa = Proto_GetAccount(GetContactProto(hContact)); @@ -635,7 +633,7 @@ static INT_PTR CALLBACK DlgProcMsgExportOpts(HWND hwndDlg, UINT msg, WPARAM wPar sItem.iImage = db_get_b(hContact, MODULENAME, "EnableLog", 1); sItem.lParam = hContact; - sTmp = _DBGetString(hContact, MODULENAME, "FileName", L""); + sTmp = _DBGetStringW(hContact, MODULENAME, "FileName", L""); sItem.pszText = (wchar_t*)sTmp.c_str(); ListView_InsertItem(hMapUser, &sItem); @@ -1011,57 +1009,6 @@ static INT_PTR CALLBACK DlgProcMsgExportOpts(HWND hwndDlg, UINT msg, WPARAM wPar return FALSE; } -///////////////////////////////////////////////////////////////////// -// Member Function : bApplyChanges2 -// Type : Global -// Parameters : hwndDlg - ? -// Returns : Returns true if -// Description : -// -// References : - -// Remarks : - -// Created : 050429, 29 april 2005 -// Developer : KN -///////////////////////////////////////////////////////////////////// - -BOOL bApplyChanges2(HWND hwndDlg) -{ - if (IsDlgButtonChecked(hwndDlg, IDC_FC_PROMPT) == BST_CHECKED) - enRenameAction = eDAPromptUser; - else if (IsDlgButtonChecked(hwndDlg, IDC_FC_RENAME) == BST_CHECKED) - enRenameAction = eDAAutomatic; - else if (IsDlgButtonChecked(hwndDlg, IDC_FC_NOTHING) == BST_CHECKED) - enRenameAction = eDANothing; - - if (IsDlgButtonChecked(hwndDlg, IDC_FD_PROMPT) == BST_CHECKED) - enDeleteAction = eDAPromptUser; - else if (IsDlgButtonChecked(hwndDlg, IDC_FD_DELETE) == BST_CHECKED) - enDeleteAction = eDAAutomatic; - else if (IsDlgButtonChecked(hwndDlg, IDC_FD_NOTHING) == BST_CHECKED) - enDeleteAction = eDANothing; - - char szTemp[500]; - strncpy_s(szTemp, "DisableProt_", _TRUNCATE); - - HWND hMapUser = GetDlgItem(hwndDlg, IDC_EXPORT_PROTOS); - int nCount = ListView_GetItemCount(hMapUser); - for (int nCur = 0; nCur < nCount; nCur++) { - LVITEMA sItem = { 0 }; - sItem.iItem = nCur; - sItem.mask = LVIF_TEXT | LVIF_IMAGE; - sItem.pszText = &szTemp[12]; - sItem.cchTextMax = (_countof(szTemp) - 15); - if (::SendMessage(hMapUser, LVM_GETITEMA, 0, (LPARAM)&sItem)) { - if (sItem.iImage) - db_unset(NULL, MODULENAME, szTemp); // default is Enabled !! - else - db_set_b(NULL, MODULENAME, szTemp, 0); - } - } - SaveSettings(); - return TRUE; -} - ///////////////////////////////////////////////////////////////////// // Member Function : DlgProcMsgExportOpts2 // Type : Global @@ -1078,135 +1025,137 @@ BOOL bApplyChanges2(HWND hwndDlg) // Developer : KN ///////////////////////////////////////////////////////////////////// -static INT_PTR CALLBACK DlgProcMsgExportOpts2(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +class CAdvancedOptDlg : public CDlgBase { - static BOOL bWindowTextSet = FALSE; + CCtrlButton btnDebug; + CCtrlListView listProtos; + CCtrlCheck chkFcPrompt, chkFcRename, chkFcNothing; + CCtrlCheck chkFdPrompt, chkFdDelete, chkFdNothing; - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - bWindowTextSet = FALSE; +public: + CAdvancedOptDlg() : + CDlgBase(g_plugin, IDD_OPT_MSGEXPORT2), + btnDebug(this, IDC_DEBUG_INFO), + chkFcPrompt(this, IDC_FC_PROMPT), + chkFcRename(this, IDC_FC_RENAME), + chkFcNothing(this, IDC_FC_NOTHING), + chkFdPrompt(this, IDC_FD_PROMPT), + chkFdDelete(this, IDC_FD_DELETE), + chkFdNothing(this, IDC_FD_NOTHING), + listProtos(this, IDC_EXPORT_PROTOS) + { + } + bool OnInitDialog() override + { switch (enRenameAction) { case eDAPromptUser: - CheckDlgButton(hwndDlg, IDC_FC_PROMPT, BST_CHECKED); + chkFcPrompt.SetState(true); break; case eDAAutomatic: - CheckDlgButton(hwndDlg, IDC_FC_RENAME, BST_CHECKED); + chkFcRename.SetState(true); break; case eDANothing: - CheckDlgButton(hwndDlg, IDC_FC_NOTHING, BST_CHECKED); + chkFcNothing.SetState(true); break; } + switch (enDeleteAction) { case eDAPromptUser: - CheckDlgButton(hwndDlg, IDC_FD_PROMPT, BST_CHECKED); + chkFdPrompt.SetState(true); break; case eDAAutomatic: - CheckDlgButton(hwndDlg, IDC_FD_DELETE, BST_CHECKED); + chkFdDelete.SetState(true); break; case eDANothing: - CheckDlgButton(hwndDlg, IDC_FD_NOTHING, BST_CHECKED); + chkFdNothing.SetState(true); break; } - RECT rListSize; - { - HWND hMapUser = GetDlgItem(hwndDlg, IDC_EXPORT_PROTOS); - int nColumnWidth = 100; - if (GetWindowRect(hMapUser, &rListSize)) { - nColumnWidth = (rListSize.right - rListSize.left - GetSystemMetrics(SM_CXVSCROLL) - 5); - if (nColumnWidth < 10) - nColumnWidth = 10; - } + int nColumnWidth = 100; - // header setup !! - LVCOLUMN cCol = { 0 }; - cCol.mask = LVCF_TEXT | LVCF_WIDTH; - cCol.cx = nColumnWidth; - cCol.pszText = TranslateT("Export Protocols"); - ListView_InsertColumn(hMapUser, 0, &cCol); - - HIMAGELIST hIml = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR4 | ILC_MASK, 2, 2); - ImageList_AddIcon(hIml, Skin_LoadIcon(SKINICON_OTHER_NOTICK)); - ImageList_AddIcon(hIml, Skin_LoadIcon(SKINICON_OTHER_TICK)); - ListView_SetImageList(hMapUser, hIml, LVSIL_SMALL); - - LVITEMA sItem = { 0 }; - sItem.mask = LVIF_TEXT | LVIF_IMAGE; - char szTemp[500]; - - for (auto &pa : Accounts()) { - mir_snprintf(szTemp, "DisableProt_%s", pa->szModuleName); - sItem.pszText = pa->szModuleName; - sItem.iImage = db_get_b(NULL, MODULENAME, szTemp, 1); - ::SendMessage(hMapUser, LVM_INSERTITEMA, 0, (LPARAM)&sItem); - sItem.iItem++; - } + RECT rListSize; + if (GetWindowRect(listProtos.GetHwnd(), &rListSize)) { + nColumnWidth = (rListSize.right - rListSize.left - GetSystemMetrics(SM_CXVSCROLL) - 5); + if (nColumnWidth < 10) + nColumnWidth = 10; } - bWindowTextSet = TRUE; - return TRUE; - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_FC_PROMPT: - case IDC_FC_RENAME: - case IDC_FC_NOTHING: - case IDC_FD_PROMPT: - case IDC_FD_DELETE: - case IDC_FD_NOTHING: - if (!bWindowTextSet) - return TRUE; + listProtos.SetExtendedListViewStyle(LVS_EX_CHECKBOXES); - if (HIWORD(wParam) == BN_CLICKED) { - bUnaplyedChanges = TRUE; - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } - return TRUE; - - case IDC_DEBUG_INFO: - ShowDebugInfo(); - return TRUE; - } - break; + // header setup !! + LVCOLUMN cCol = { 0 }; + cCol.mask = LVCF_TEXT | LVCF_WIDTH; + cCol.cx = nColumnWidth; + cCol.pszText = TranslateT("Export Protocols"); + listProtos.InsertColumn(0, &cCol); - case WM_NOTIFY: - NMHDR *p = ((LPNMHDR)lParam); - if (p->idFrom == IDC_EXPORT_PROTOS) { - if (p->code == NM_CLICK) { - LVHITTESTINFO hti; - hti.pt = ((NMLISTVIEW*)lParam)->ptAction; - ListView_SubItemHitTest(p->hwndFrom, &hti); - if (hti.flags != LVHT_ONITEMICON) - break; + LVITEMW sItem = { 0 }; + sItem.mask = LVIF_TEXT | LVIF_PARAM; + char szTemp[500]; - LVITEM lvi; - lvi.mask = LVIF_IMAGE; - lvi.iItem = hti.iItem; - lvi.iSubItem = 0; - ListView_GetItem(p->hwndFrom, &lvi); - lvi.iImage ^= 1; - ListView_SetItem(p->hwndFrom, &lvi); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - } - break; - } + for (auto &pa : Accounts()) { + mir_snprintf(szTemp, "DisableProt_%s", pa->szModuleName); + sItem.pszText = pa->tszAccountName; + sItem.lParam = (LPARAM)pa->szModuleName; + listProtos.InsertItem(&sItem); - switch (p->code) { - case PSN_APPLY: - bApplyChanges2(hwndDlg); - return TRUE; + listProtos.SetCheckState(sItem.iItem, db_get_b(NULL, MODULENAME, szTemp, 1)); - case HDN_ITEMCLICK: - return FALSE; + sItem.iItem++; } - break; + return true; } - return FALSE; -} + bool OnApply() override + { + if (chkFcPrompt.GetState()) + enRenameAction = eDAPromptUser; + else if (chkFcRename.GetState() == BST_CHECKED) + enRenameAction = eDAAutomatic; + else if (chkFcNothing.GetState() == BST_CHECKED) + enRenameAction = eDANothing; + + if (chkFdPrompt.GetState() == BST_CHECKED) + enDeleteAction = eDAPromptUser; + else if (chkFdDelete.GetState() == BST_CHECKED) + enDeleteAction = eDAAutomatic; + else if (chkFdNothing.GetState() == BST_CHECKED) + enDeleteAction = eDANothing; + + int nCount = listProtos.GetItemCount(); + for (int nCur = 0; nCur < nCount; nCur++) { + LVITEM sItem = { 0 }; + sItem.iItem = nCur; + sItem.mask = LVIF_PARAM; + if (listProtos.GetItem(&sItem)) { + char szTemp[200]; + mir_snprintf(szTemp, "DisableProt_%s", (char*)sItem.lParam); + if (listProtos.GetCheckState(nCur)) + db_unset(NULL, MODULENAME, szTemp); // default is Enabled !! + else + db_set_b(NULL, MODULENAME, szTemp, 0); + } + } + SaveSettings(); + return true; + } + void onClick_Debug(CCtrlButton*) + { + wstring sDebug = L"Debug information\r\nsDBPath :"; + sDebug += sDBPath; + sDebug += L"\r\nsMirandaPath :"; + sDebug += sMirandaPath; + sDebug += L"\r\nsDefaultFile :"; + sDebug += sDefaultFile; + + sDebug += L"\r\nGetFilePathFromUser(NULL) :"; + sDebug += GetFilePathFromUser(NULL); + + MessageBox(nullptr, sDebug.c_str(), MSG_BOX_TITEL, MB_OK); + } +}; ///////////////////////////////////////////////////////////////////// // Member Function : OptionsInitialize @@ -1236,10 +1185,11 @@ int OptionsInitialize(WPARAM wParam, LPARAM /*lParam*/) odp.pfnDlgProc = DlgProcMsgExportOpts; g_plugin.addOptions(wParam, &odp); + odp.pfnDlgProc = 0; + odp.pszTemplate = 0; odp.position = 100000001; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_MSGEXPORT2); odp.szTab.w = LPGENW("Additional"); - odp.pfnDlgProc = DlgProcMsgExportOpts2; + odp.pDialog = new CAdvancedOptDlg(); g_plugin.addOptions(wParam, &odp); return 0; } diff --git a/plugins/Msg_Export/src/stdafx.h b/plugins/Msg_Export/src/stdafx.h index cfe152d061..0508f1e2be 100755 --- a/plugins/Msg_Export/src/stdafx.h +++ b/plugins/Msg_Export/src/stdafx.h @@ -41,6 +41,7 @@ using namespace std; #include #include #include +#include #include "utils.h" #include "options.h" @@ -63,5 +64,6 @@ struct CMPlugin : public PLUGIN }; extern MWindowList hInternalWindowList; +extern wstring sDBPath, sMirandaPath; #endif \ No newline at end of file diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index 2dbfbdec7b..a2ae4a9a39 100755 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -26,25 +26,25 @@ const wchar_t *pszDbPathError = L"."; const wchar_t cBadCharReplace = '_'; // sTimeFormat -tstring sTimeFormat; +wstring sTimeFormat; // path from options dialog -tstring sExportDir; +wstring sExportDir; // The default filename. Used if no other file name is specifyed in DB. -tstring sDefaultFile; +wstring sDefaultFile; // path used then %dbpath% is used in export file path -tstring sDBPath = pszDbPathError; +wstring sDBPath = pszDbPathError; // path to miranda exe file used when to avoid relative paths -tstring sMirandaPath = pszDbPathError; +wstring sMirandaPath = pszDbPathError; // Used to store the width of the user name for a file. // if a file contains events from many users the one user name // may be shorter. so to make all event have the same first // column width this map contains the largest user name -map > clFileTo1ColWidth; +map > clFileTo1ColWidth; // default line width int nMaxLineWidth = 80; @@ -95,35 +95,6 @@ bool bIsUtf8Header(BYTE * pucByteOrder) return memcmp(pucByteOrder, szUtf8ByteOrderHeader, 3) == 0; } -///////////////////////////////////////////////////////////////////// -// Member Function : ShowDebugInfo -// Type : Global -// Parameters : None -// Returns : void -// Description : -// -// References : - -// Remarks : - -// Created : 021228, 28 December 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// - -void ShowDebugInfo() -{ - tstring sDebug = L"Debug information\r\nsDBPath :"; - sDebug += sDBPath; - sDebug += L"\r\nsMirandaPath :"; - sDebug += sMirandaPath; - sDebug += L"\r\nsDefaultFile :"; - sDebug += sDefaultFile; - - sDebug += L"\r\nGetFilePathFromUser(NULL) :"; - sDebug += GetFilePathFromUser(NULL); - - MessageBox(nullptr, sDebug.c_str(), MSG_BOX_TITEL, MB_OK); -} - - ///////////////////////////////////////////////////////////////////// // Member Function : nGetFormatCount // Type : Global @@ -163,7 +134,7 @@ int nGetFormatCount(const wchar_t *pszToCheck) // Developer : KN ///////////////////////////////////////////////////////////////////// -tstring sGetErrorString(DWORD dwError) +wstring sGetErrorString(DWORD dwError) { LPVOID lpMsgBuf; FormatMessage( @@ -177,7 +148,7 @@ tstring sGetErrorString(DWORD dwError) // Process any inserts in lpMsgBuf. // ... // Display the string. - tstring ret = (LPCTSTR)lpMsgBuf; + wstring ret = (LPCTSTR)lpMsgBuf; ReplaceAll(ret, L"\r", L" "); ReplaceAll(ret, L"\n", L" "); ReplaceAll(ret, L" ", L" "); @@ -187,14 +158,14 @@ tstring sGetErrorString(DWORD dwError) return ret; } -tstring sGetErrorString() +wstring sGetErrorString() { return sGetErrorString(GetLastError()); } void DisplayLastError(const wchar_t *pszError) { - tstring sError = pszError; + wstring sError = pszError; DWORD error = GetLastError(); wchar_t szTemp[50]; @@ -205,7 +176,7 @@ void DisplayLastError(const wchar_t *pszError) } ///////////////////////////////////////////////////////////////////// -// Member Function : _DBGetString +// Member Function : _DBGetStringW // Type : Global // Parameters : hContact - ? // szModule - ? @@ -220,9 +191,9 @@ void DisplayLastError(const wchar_t *pszError) // Developer : KN ///////////////////////////////////////////////////////////////////// -tstring _DBGetStringW(MCONTACT hContact, const char *szModule, const char *szSetting, const wchar_t *pszError) +wstring _DBGetStringW(MCONTACT hContact, const char *szModule, const char *szSetting, const wchar_t *pszError) { - tstring ret; + wstring ret; DBVARIANT dbv = { 0 }; if (!db_get_ws(hContact, szModule, szSetting, &dbv)) { ret = (wchar_t*)dbv.pszVal; @@ -261,7 +232,7 @@ string _DBGetStringA(MCONTACT hContact, const char *szModule, const char *szSett // Developer : KN ///////////////////////////////////////////////////////////////////// -void ReplaceAll(tstring &sSrc, const wchar_t *pszReplace, const tstring &sNew) +void ReplaceAll(wstring &sSrc, const wchar_t *pszReplace, const wstring &sNew) { string::size_type nCur = 0; while ((nCur = sSrc.find(pszReplace, nCur)) != sSrc.npos) { @@ -270,9 +241,9 @@ void ReplaceAll(tstring &sSrc, const wchar_t *pszReplace, const tstring &sNew) } } -void ReplaceAll(tstring &sSrc, const wchar_t *pszReplace, const wchar_t *pszNew) +void ReplaceAll(wstring &sSrc, const wchar_t *pszReplace, const wchar_t *pszNew) { - tstring sNew = pszNew; + wstring sNew = pszNew; ReplaceAll(sSrc, pszReplace, sNew); } @@ -289,7 +260,7 @@ void ReplaceAll(tstring &sSrc, const wchar_t *pszReplace, const wchar_t *pszNew) // Developer : KN ///////////////////////////////////////////////////////////////////// -bool bCreatePathToFile(tstring sFilePath) +bool bCreatePathToFile(wstring sFilePath) { string::size_type nPos = sFilePath.rfind('\\'); if (nPos != string::npos) { @@ -480,7 +451,7 @@ bool bReadMirandaDirAndPath() // Developer : KN ///////////////////////////////////////////////////////////////////// -void ReplaceDBPath(tstring &sRet) +void ReplaceDBPath(wstring &sRet) { ReplaceAll(sRet, L"%dbpath%", sDBPath); // Try to firure out if it is a relative path ( ..\..\MsgExport\ ) @@ -507,21 +478,21 @@ void ReplaceDBPath(tstring &sRet) // Developer : KN ///////////////////////////////////////////////////////////////////// -tstring GetFilePathFromUser(MCONTACT hContact) +wstring GetFilePathFromUser(MCONTACT hContact) { - tstring sFilePath = sExportDir + _DBGetString(hContact, MODULENAME, "FileName", sDefaultFile.c_str()); + wstring sFilePath = sExportDir + _DBGetStringW(hContact, MODULENAME, "FileName", sDefaultFile.c_str()); bool bNickUsed = sFilePath.find(L"%nick%") != string::npos; ReplaceDefines(hContact, sFilePath); - tstring sNoDBPath = sFilePath; + wstring sNoDBPath = sFilePath; ReplaceTimeVariables(sFilePath); ReplaceDBPath(sFilePath); // Previous file name check to see if it has changed !! - tstring sPrevFileName = _DBGetString(hContact, MODULENAME, "PrevFileName", L""); + wstring sPrevFileName = _DBGetStringW(hContact, MODULENAME, "PrevFileName", L""); if (sNoDBPath != sPrevFileName) { if (!sPrevFileName.empty()) { ReplaceDBPath(sPrevFileName); @@ -552,7 +523,7 @@ tstring GetFilePathFromUser(MCONTACT hContact) bool bTryRename; if (enRenameAction != eDAAutomatic) { - tstring sRemoteUser = Clist_GetContactDisplayName(hContact); + wstring sRemoteUser = Clist_GetContactDisplayName(hContact); mir_snwprintf(szTemp, TranslateT("File name for the user \"%s\" has changed!\n\nfrom:\t%s\nto:\t%s\n\nDo you wish to rename file?"), sRemoteUser.c_str(), @@ -606,9 +577,9 @@ tstring GetFilePathFromUser(MCONTACT hContact) // Developer : KN ///////////////////////////////////////////////////////////////////// -tstring FileNickFromHandle(MCONTACT hContact) +wstring FileNickFromHandle(MCONTACT hContact) { - tstring ret = Clist_GetContactDisplayName(hContact); + wstring ret = Clist_GetContactDisplayName(hContact); string::size_type nCur = 0; while ((nCur = ret.find_first_of(L":\\", nCur)) != ret.npos) ret[nCur] = cBadCharReplace; @@ -631,9 +602,9 @@ tstring FileNickFromHandle(MCONTACT hContact) // Developer : KN ///////////////////////////////////////////////////////////////////// -void ReplaceAllNoColon(tstring &sSrc, const wchar_t *pszReplace, tstring &sNew) +void ReplaceAllNoColon(wstring &sSrc, const wchar_t *pszReplace, wstring &sNew) { - tstring::size_type nCur = 0; + wstring::size_type nCur = 0; while ((nCur = sNew.find_first_of(':', nCur)) != sNew.npos) sNew[nCur] = cBadCharReplace; ReplaceAll(sSrc, pszReplace, sNew); @@ -653,7 +624,7 @@ void ReplaceAllNoColon(tstring &sSrc, const wchar_t *pszReplace, tstring &sNew) // Developer : KN ///////////////////////////////////////////////////////////////////// -void ReplaceDefines(MCONTACT hContact, tstring & sTarget) +void ReplaceDefines(MCONTACT hContact, wstring & sTarget) { if (sTarget.find(L"%nick%") != string::npos) ReplaceAll(sTarget, L"%nick%", FileNickFromHandle(hContact)); @@ -667,7 +638,7 @@ void ReplaceDefines(MCONTACT hContact, tstring & sTarget) string sProto = _DBGetStringA(hContact, "Protocol", "p", ""); if (bUINUsed || (bIdentifierUsed && sProto == "ICQ")) { DWORD dwUIN = db_get_dw(hContact, sProto.c_str(), "UIN", 0); - tstring sReplaceUin; + wstring sReplaceUin; if (dwUIN) { wchar_t sTmp[20]; mir_snwprintf(sTmp, L"%d", dwUIN); @@ -684,9 +655,9 @@ void ReplaceDefines(MCONTACT hContact, tstring & sTarget) } if (bEMailUsed || (bIdentifierUsed && sProto == "MSN")) { - tstring sEMail = _DBGetString(hContact, sProto.c_str(), "e-mail", L""); + wstring sEMail = _DBGetStringW(hContact, sProto.c_str(), "e-mail", L""); if (sEMail.empty()) { - sEMail = _DBGetString(hContact, "MSN", "e-mail", L""); + sEMail = _DBGetStringW(hContact, "MSN", "e-mail", L""); if (sEMail.empty()) { // We can't finde the E-mail address we will use the the nick sEMail = FileNickFromHandle(hContact); @@ -701,7 +672,7 @@ void ReplaceDefines(MCONTACT hContact, tstring & sTarget) } if (bIdentifierUsed && sProto == "Jabber") { - tstring sReplace = _DBGetString(hContact, "Jabber", "jid", L""); + wstring sReplace = _DBGetStringW(hContact, "Jabber", "jid", L""); if (sReplace.empty()) { sReplace = FileNickFromHandle(hContact); } @@ -710,7 +681,7 @@ void ReplaceDefines(MCONTACT hContact, tstring & sTarget) } if (bProtoUsed) { - tstring tmp = _DBGetString(hContact, "Protocol", "p", L""); + wstring tmp = _DBGetStringW(hContact, "Protocol", "p", L""); ReplaceAllNoColon(sTarget, L"%protocol%", tmp); } @@ -719,7 +690,7 @@ void ReplaceDefines(MCONTACT hContact, tstring & sTarget) } if (sTarget.find(L"%group%") != string::npos) { - tstring sGroup = _DBGetString(hContact, "CList", "Group", L""); + wstring sGroup = _DBGetStringW(hContact, "CList", "Group", L""); ReplaceAllNoColon(sTarget, L"%group%", sGroup); } @@ -743,7 +714,7 @@ void ReplaceDefines(MCONTACT hContact, tstring & sTarget) // Developer : KN ///////////////////////////////////////////////////////////////////// -void ReplaceTimeVariables(tstring &sRet) +void ReplaceTimeVariables(wstring &sRet) { if (sRet.find(L"%year%") != string::npos || sRet.find(L"%month%") != string::npos || @@ -779,7 +750,7 @@ void UpdateFileToColWidth() clFileTo1ColWidth.clear(); for (auto &hContact : Contacts()) { - tstring sNick = Clist_GetContactDisplayName(hContact); + wstring sNick = Clist_GetContactDisplayName(hContact); string::size_type &rnValue = clFileTo1ColWidth[GetFilePathFromUser(hContact)]; if (rnValue < sNick.size()) rnValue = sNick.size(); @@ -801,9 +772,9 @@ void UpdateFileToColWidth() // Developer : KN ///////////////////////////////////////////////////////////////////// -void DisplayErrorDialog(const wchar_t *pszError, tstring& sFilePath, DBEVENTINFO * dbei) +void DisplayErrorDialog(const wchar_t *pszError, wstring &sFilePath, DBEVENTINFO *dbei) { - tstring sError = TranslateW(pszError); + wstring sError = TranslateW(pszError); sError += sFilePath; sError += TranslateT("\nError: "); sError += sGetErrorString(); @@ -870,10 +841,10 @@ void DisplayErrorDialog(const wchar_t *pszError, tstring& sFilePath, DBEVENTINFO // Developer : KN ///////////////////////////////////////////////////////////////////// -bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, tstring sFilePath, DBEVENTINFO &dbei, bool bAppendOnly) +bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath, DBEVENTINFO &dbei, bool bAppendOnly) { - tstring sLocalUser; - tstring sRemoteUser; + wstring sLocalUser; + wstring sRemoteUser; string::size_type nFirstColumnWidth; if (bUseLessAndGreaterInExport) { @@ -921,7 +892,7 @@ bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, tstring sFilePath, DBEVE return false; } } - tstring output = L"------------------------------------------------\r\n" + wstring output = L"------------------------------------------------\r\n" LPGENW(" History for\r\n") LPGENW("User : %User%\r\n") LPGENW("Protocol : %Proto%\r\n") @@ -944,10 +915,10 @@ bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, tstring sFilePath, DBEVE ReplaceAll(output, L"%User%", sRemoteUser); string sProto = _DBGetStringA(hContact, "Protocol", "p", ""); - ReplaceAll(output, L"%Proto%", _DBGetString(hContact, "Protocol", "p", L"")); + ReplaceAll(output, L"%Proto%", _DBGetStringW(hContact, "Protocol", "p", L"")); for (int nCur = 0; nCur < 9; nCur++) - ReplaceAll(output, pszReplaceList[nCur], _DBGetString(hContact, sProto.c_str(), pszReplaceListA[nCur], L"")); + ReplaceAll(output, pszReplaceList[nCur], _DBGetStringW(hContact, sProto.c_str(), pszReplaceListA[nCur], L"")); ptrW id(Contact_GetInfo(CNF_UNIQUEID, hContact, sProto.c_str())); if (id != NULL) @@ -1182,7 +1153,7 @@ bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, tstring sFilePath, DBEVE // Developer : KN ///////////////////////////////////////////////////////////////////// -HANDLE openCreateFile(tstring sFilePath) +HANDLE openCreateFile(wstring sFilePath) { GetLastError();// Clear last error !! @@ -1218,7 +1189,7 @@ int nExportEvent(WPARAM hContact, LPARAM hDbEvent) return 0; // Open/create file for writing - tstring sFilePath = GetFilePathFromUser(hContact); + wstring sFilePath = GetFilePathFromUser(hContact); HANDLE hFile = openCreateFile(sFilePath); if (hFile == INVALID_HANDLE_VALUE) { DisplayErrorDialog(LPGENW("Failed to open or create file :\n"), sFilePath, nullptr); @@ -1234,7 +1205,7 @@ int nExportEvent(WPARAM hContact, LPARAM hDbEvent) return 0; } -bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, tstring sFilePath, bool bAppendOnly) +bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, wstring sFilePath, bool bAppendOnly) { DBEVENTINFO dbei = {}; int nSize = db_event_getBlobSize(hDbEvent); @@ -1383,7 +1354,7 @@ int nContactDeleted(WPARAM wparam, LPARAM /*lparam*/) if (enDeleteAction == eDANothing) return 0; - tstring sFilePath = GetFilePathFromUser(hContact); + wstring sFilePath = GetFilePathFromUser(hContact); // Test if there is another user using this file for (auto &hOtherContact : Contacts()) diff --git a/plugins/Msg_Export/src/utils.h b/plugins/Msg_Export/src/utils.h index 6835ba182b..2a725d2920 100755 --- a/plugins/Msg_Export/src/utils.h +++ b/plugins/Msg_Export/src/utils.h @@ -20,9 +20,6 @@ #ifndef MSG_EXP_UTILS_H #define MSG_EXP_UTILS_H -#define tstring wstring -#define _DBGetString _DBGetStringW - enum ENDialogAction { eDAPromptUser, @@ -34,10 +31,10 @@ extern ENDialogAction enRenameAction; extern ENDialogAction enDeleteAction; extern int nMaxLineWidth; -extern tstring sExportDir; -extern tstring sDefaultFile; -extern tstring sTimeFormat; -extern map > clFileTo1ColWidth; +extern wstring sExportDir; +extern wstring sDefaultFile; +extern wstring sTimeFormat; +extern map > clFileTo1ColWidth; extern bool bAppendNewLine; extern bool bUseUtf8InNewFiles; @@ -45,40 +42,38 @@ extern bool bUseLessAndGreaterInExport; extern bool bReplaceHistory; -tstring sGetErrorString(DWORD dwError); -tstring sGetErrorString(); +wstring sGetErrorString(DWORD dwError); +wstring sGetErrorString(); void DisplayLastError(const wchar_t *pszError); -void DisplayErrorDialog(const wchar_t *pszError, tstring& sFilePath, DBEVENTINFO *dbei); - -wchar_t *CheckedTranslate(const wchar_t *szEng, int nFormatCount = -1); +void DisplayErrorDialog(const wchar_t *pszError, wstring &sFilePath, DBEVENTINFO *dbei); void SaveSettings(); void ShowDebugInfo(); bool bIsExportEnabled(MCONTACT hContact); -HANDLE openCreateFile(tstring sFilePath); -bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, tstring sFilePath, bool bAppendOnly); +HANDLE openCreateFile(wstring sFilePath); +bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, wstring sFilePath, bool bAppendOnly); int nExportEvent(WPARAM wparam, LPARAM lparam); int nContactDeleted(WPARAM wparam, LPARAM lparam); wchar_t* GetMyOwnNick(MCONTACT hContact); -tstring __inline _DBGetStringW(MCONTACT hContact, const char *szModule, const char *szSetting, const wchar_t *pszError); +wstring __inline _DBGetStringW(MCONTACT hContact, const char *szModule, const char *szSetting, const wchar_t *pszError); string __inline _DBGetStringA(MCONTACT hContact, const char *szModule, const char *szSetting, const char *pszError); -void ReplaceAll(tstring &sSrc, const wchar_t *pszReplace, const tstring &sNew); -void ReplaceAll(tstring &sSrc, const wchar_t *pszReplace, const wchar_t *pszNew); +void ReplaceAll(wstring &sSrc, const wchar_t *pszReplace, const wstring &sNew); +void ReplaceAll(wstring &sSrc, const wchar_t *pszReplace, const wchar_t *pszNew); void UpdateFileToColWidth(); bool bReadMirandaDirAndPath(); -tstring GetFilePathFromUser(MCONTACT hContact); +wstring GetFilePathFromUser(MCONTACT hContact); -void ReplaceDefines(MCONTACT hContact, tstring & sTarget); -void ReplaceTimeVariables(tstring &sRet); +void ReplaceDefines(MCONTACT hContact, wstring & sTarget); +void ReplaceTimeVariables(wstring &sRet); -bool bCreatePathToFile(tstring sFilePath); +bool bCreatePathToFile(wstring sFilePath); bool bWriteIndentedToFile(HANDLE hFile, int nIndent, const char *pszSrc, bool bUtf8File); bool bWriteIndentedToFile(HANDLE hFile, int nIndent, const wchar_t *pszSrc, bool bUtf8File); -- cgit v1.2.3