diff options
author | George Hazan <ghazan@miranda.im> | 2020-03-22 14:20:52 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-03-22 14:20:52 +0300 |
commit | 93b3a77b2590443e2b1e868b96196175f99180b9 (patch) | |
tree | 70601e77b9f6f7256721967eed0be10b598ad2e4 /plugins/TabSRMM/src | |
parent | bb0498bf6aa0accd22bbc19091a12d54602a52be (diff) |
File transfers:
- fixes #2274 (StdMsg & Scriver cannot send files to offline contacts even if their protocol allows that to do);
- all copies of AddToFileList in all plugins removed;
- ProcessFileDrop() function introduced to handle all file drop operations in all SRMM plugins & contact list
Diffstat (limited to 'plugins/TabSRMM/src')
-rw-r--r-- | plugins/TabSRMM/src/msgdialog.cpp | 35 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgdlgother.cpp | 13 | ||||
-rw-r--r-- | plugins/TabSRMM/src/utils.cpp | 26 | ||||
-rw-r--r-- | plugins/TabSRMM/src/utils.h | 68 |
4 files changed, 38 insertions, 104 deletions
diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index dd7f2743f2..69f9d20f17 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -1897,7 +1897,7 @@ LRESULT CMsgDialog::WndProc_Message(UINT msg, WPARAM wParam, LPARAM lParam) return CSkin::DrawRichEditFrame(m_message.GetHwnd(), this, ID_EXTBKINPUTAREA, msg, wParam, lParam, stubMessageProc);
case WM_DROPFILES:
- SendMessage(m_hwnd, WM_DROPFILES, (WPARAM)wParam, (LPARAM)lParam);
+ SendMessage(m_hwnd, WM_DROPFILES, wParam, lParam);
return 0;
case WM_CHAR:
@@ -3113,37 +3113,8 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) return 0;
case WM_DROPFILES:
- {
- const char *szProto = m_cache->getActiveProto();
- if (szProto == nullptr)
- break;
-
- int pcaps = CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_1, 0);
- if (!(pcaps & PF1_FILESEND))
- break;
- if (m_wStatus == ID_STATUS_OFFLINE) {
- pcaps = CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0);
- if (!(pcaps & PF4_OFFLINEFILES)) {
- ActivateTooltip(IDC_SRMM_MESSAGE, TranslateT("Contact is offline and this protocol does not support sending files to offline users."));
- break;
- }
- }
-
- wchar_t szFilename[MAX_PATH];
- HDROP hDrop = (HDROP)wParam;
- int fileCount = DragQueryFile(hDrop, -1, nullptr, 0), totalCount = 0, i;
- wchar_t **ppFiles = nullptr;
- for (i = 0; i < fileCount; i++) {
- DragQueryFile(hDrop, i, szFilename, _countof(szFilename));
- Utils::AddToFileList(&ppFiles, &totalCount, szFilename);
- }
-
- CallService(MS_FILE_SENDSPECIFICFILEST, m_hContact, (LPARAM)ppFiles);
-
- for (i = 0; ppFiles[i]; i++)
- mir_free(ppFiles[i]);
- mir_free(ppFiles);
- }
+ if (!ProcessFileDrop((HDROP)wParam, m_cache->getActiveContact()))
+ ActivateTooltip(IDC_SRMM_MESSAGE, TranslateT("Contact is offline and this protocol does not support sending files to offline users."));
return 0;
case DM_CHECKQUEUEFORCLOSE:
diff --git a/plugins/TabSRMM/src/msgdlgother.cpp b/plugins/TabSRMM/src/msgdlgother.cpp index 6396916029..249863ec01 100644 --- a/plugins/TabSRMM/src/msgdlgother.cpp +++ b/plugins/TabSRMM/src/msgdlgother.cpp @@ -1410,17 +1410,10 @@ void CMsgDialog::SendHBitmapAsFile(HBITMAP hbmp) const return; } - int totalCount = 0; - wchar_t **ppFiles = nullptr; - Utils::AddToFileList(&ppFiles, &totalCount, filename); + vTempFilenames.insert(mir_wstrdup(filename)); - wchar_t *_t = mir_wstrdup(filename); - vTempFilenames.insert(_t); - - CallService(MS_FILE_SENDSPECIFICFILEST, m_cache->getActiveContact(), (LPARAM)ppFiles); - - mir_free(ppFiles[0]); - mir_free(ppFiles); + wchar_t *ppFiles[2] = { filename, nullptr }; + CallService(MS_FILE_SENDSPECIFICFILEST, m_cache->getActiveContact(), (LPARAM)&ppFiles); } // remove all temporary files created by the "send clipboard as file" feature. diff --git a/plugins/TabSRMM/src/utils.cpp b/plugins/TabSRMM/src/utils.cpp index 84436070d3..f5e97fd276 100644 --- a/plugins/TabSRMM/src/utils.cpp +++ b/plugins/TabSRMM/src/utils.cpp @@ -955,32 +955,6 @@ HWND TSAPI GetTabWindow(HWND hwndTab, int i) /////////////////////////////////////////////////////////////////////////////////////////
// file list handler
-void Utils::AddToFileList(wchar_t ***pppFiles, int *totalCount, LPCTSTR szFilename)
-{
- *pppFiles = (wchar_t**)mir_realloc(*pppFiles, (++*totalCount + 1) * sizeof(wchar_t*));
- (*pppFiles)[*totalCount] = nullptr;
- (*pppFiles)[*totalCount - 1] = mir_wstrdup(szFilename);
-
- if (GetFileAttributes(szFilename) & FILE_ATTRIBUTE_DIRECTORY) {
- WIN32_FIND_DATA fd;
- wchar_t szPath[MAX_PATH];
- mir_wstrcpy(szPath, szFilename);
- mir_wstrcat(szPath, L"\\*");
- HANDLE hFind = FindFirstFile(szPath, &fd);
- if (hFind != INVALID_HANDLE_VALUE) {
- do {
- if (!mir_wstrcmp(fd.cFileName, L".") || !mir_wstrcmp(fd.cFileName, L".."))
- continue;
- mir_wstrcpy(szPath, szFilename);
- mir_wstrcat(szPath, L"\\");
- mir_wstrcat(szPath, fd.cFileName);
- AddToFileList(pppFiles, totalCount, szPath);
- } while (FindNextFile(hFind, &fd));
- FindClose(hFind);
- }
- }
-}
-
int _DebugTraceW(const wchar_t *fmt, ...)
{
wchar_t debug[2048];
diff --git a/plugins/TabSRMM/src/utils.h b/plugins/TabSRMM/src/utils.h index e2d57779bf..0aa96e8a22 100644 --- a/plugins/TabSRMM/src/utils.h +++ b/plugins/TabSRMM/src/utils.h @@ -48,48 +48,45 @@ struct TRTFColorTable COLORREF clr;
};
-class Utils {
-
-public:
- static wchar_t* GetPreviewWithEllipsis(wchar_t *szText, size_t iMaxLen);
- static wchar_t* FilterEventMarkers(wchar_t *wszText);
- static char* FilterEventMarkers(char *szText);
- static void DoubleAmpersands(wchar_t *pszText, size_t len);
- static void RTF_CTableInit();
- static void RTF_ColorAdd(const wchar_t *tszColname);
- static int ReadContainerSettingsFromDB(const MCONTACT hContact, TContainerSettings *cs, const char *szKey = nullptr);
- static int WriteContainerSettingsToDB(const MCONTACT hContact, TContainerSettings *cs, const char *szKey = nullptr);
- static void SettingsToContainer(TContainerData *pContainer);
- static void ContainerToSettings(TContainerData *pContainer);
- static void ReadPrivateContainerSettings(TContainerData *pContainer, bool fForce = false);
- static void SaveContainerSettings(TContainerData *pContainer, const char *szSetting);
-
- static DWORD CALLBACK StreamOut(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb);
+namespace Utils
+{
+ wchar_t* GetPreviewWithEllipsis(wchar_t *szText, size_t iMaxLen);
+ wchar_t* FilterEventMarkers(wchar_t *wszText);
+ char* FilterEventMarkers(char *szText);
+ void DoubleAmpersands(wchar_t *pszText, size_t len);
+ void RTF_CTableInit();
+ void RTF_ColorAdd(const wchar_t *tszColname);
+ int ReadContainerSettingsFromDB(const MCONTACT hContact, TContainerSettings *cs, const char *szKey = nullptr);
+ int WriteContainerSettingsToDB(const MCONTACT hContact, TContainerSettings *cs, const char *szKey = nullptr);
+ void SettingsToContainer(TContainerData *pContainer);
+ void ContainerToSettings(TContainerData *pContainer);
+ void ReadPrivateContainerSettings(TContainerData *pContainer, bool fForce = false);
+ void SaveContainerSettings(TContainerData *pContainer, const char *szSetting);
- static void addMenuItem(const HMENU& m, MENUITEMINFO& mii, HICON hIcon, const wchar_t *szText, UINT uID, UINT pos);
- static void enableDlgControl(const HWND hwnd, UINT id, bool fEnable = true);
- static void showDlgControl(const HWND hwnd, UINT id, int showCmd);
- static void setAvatarContact(HWND hWnd, MCONTACT hContact);
- static void getIconSize(HICON hIcon, int& sizeX, int& sizeY);
+ DWORD CALLBACK StreamOut(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb);
- static bool extractResource(const HMODULE h, const UINT uID, const wchar_t *tszName, const wchar_t *tszPath, const wchar_t *tszFilename, bool fForceOverwrite);
- static void scaleAvatarHeightLimited(const HBITMAP hBm, double& dNewWidth, double& dNewHeight, const LONG maxHeight);
+ void addMenuItem(const HMENU& m, MENUITEMINFO& mii, HICON hIcon, const wchar_t *szText, UINT uID, UINT pos);
+ void enableDlgControl(const HWND hwnd, UINT id, bool fEnable = true);
+ void showDlgControl(const HWND hwnd, UINT id, int showCmd);
+ void setAvatarContact(HWND hWnd, MCONTACT hContact);
+ void getIconSize(HICON hIcon, int& sizeX, int& sizeY);
- static AVATARCACHEENTRY* loadAvatarFromAVS(const MCONTACT hContact);
+ bool extractResource(const HMODULE h, const UINT uID, const wchar_t *tszName, const wchar_t *tszPath, const wchar_t *tszFilename, bool fForceOverwrite);
+ void scaleAvatarHeightLimited(const HBITMAP hBm, double& dNewWidth, double& dNewHeight, const LONG maxHeight);
- static void sanitizeFilename(wchar_t *tszFilename);
- static void ensureTralingBackslash(wchar_t *szPathname);
+ AVATARCACHEENTRY* loadAvatarFromAVS(const MCONTACT hContact);
- static void sendContactMessage(MCONTACT hContact, UINT uMsg, WPARAM wParam, LPARAM lParam);
+ void sanitizeFilename(wchar_t *tszFilename);
+ void ensureTralingBackslash(wchar_t *szPathname);
- static HMODULE loadSystemLibrary(const wchar_t* szFilename);
+ void sendContactMessage(MCONTACT hContact, UINT uMsg, WPARAM wParam, LPARAM lParam);
- static LRESULT CALLBACK PopupDlgProcError(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- static LPTSTR extractURLFromRichEdit(const ENLINK* _e, const HWND hwndRich);
+ HMODULE loadSystemLibrary(const wchar_t* szFilename);
- static size_t CopyToClipBoard(const wchar_t *str, const HWND hwndOwner);
+ LRESULT CALLBACK PopupDlgProcError(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
+ LPTSTR extractURLFromRichEdit(const ENLINK* _e, const HWND hwndRich);
- static void AddToFileList(wchar_t ***pppFiles, int *totalCount, LPCTSTR szFilename);
+ size_t CopyToClipBoard(const wchar_t *str, const HWND hwndOwner);
//////////////////////////////////////////////////////////////////////////////////////
// safe mir_strlen function - do not overflow the given buffer length
@@ -98,7 +95,7 @@ public: //
// careful: maxlen must be given in element counts!!
- template<typename T> static size_t safe_strlen(const T* src, const size_t maxlen = 0)
+ template<typename T> size_t safe_strlen(const T* src, const size_t maxlen = 0)
{
size_t s = 0;
@@ -108,8 +105,7 @@ public: return (s >= maxlen && *src != 0) ? 0 : s;
}
-public:
- static OBJLIST<TRTFColorTable> rtf_clrs;
+ extern OBJLIST<TRTFColorTable> rtf_clrs;
};
__forceinline LRESULT _dlgReturn(HWND hWnd, LRESULT result)
|