diff options
author | George Hazan <george.hazan@gmail.com> | 2015-05-21 16:11:58 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-05-21 16:11:58 +0000 |
commit | 48266e479d1fcf5153b29c612866845990fccad8 (patch) | |
tree | c8cbc908cd3c5f08731e5e8d7eaac6b568007d09 /plugins/TabSRMM | |
parent | ebdb556f152734035846f120eb8112f88ef91281 (diff) |
war against atavisms continues
- everything that goes to PSS_MESSAGE should be sent as utf8 string;
- thus PREF_UNICODE & PREF_UTF support discontinued, these constants are removed;
- support for PREF_UNICODE & PREF_UTF in protocols also removed;
- PREF_UNICODE used in file transfers (PROTOFILERECVT) replaced with PRFF_UNICODE / PRFF_TCHAR
git-svn-id: http://svn.miranda-ng.org/main/trunk@13734 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/TabSRMM')
-rw-r--r-- | plugins/TabSRMM/src/functions.h | 1 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgdialog.cpp | 37 | ||||
-rw-r--r-- | plugins/TabSRMM/src/sendlater.cpp | 7 | ||||
-rw-r--r-- | plugins/TabSRMM/src/sendqueue.cpp | 156 |
4 files changed, 27 insertions, 174 deletions
diff --git a/plugins/TabSRMM/src/functions.h b/plugins/TabSRMM/src/functions.h index f5fa1e308f..83c7f532ee 100644 --- a/plugins/TabSRMM/src/functions.h +++ b/plugins/TabSRMM/src/functions.h @@ -70,7 +70,6 @@ void TSAPI HandleMenuEntryFromhContact(MCONTACT iSelection); * gneric msgwindow functions(creation, container management etc.)
*/
-BOOL TSAPI IsUtfSendAvailable(MCONTACT hContact);
HWND TSAPI CreateNewTabForContact(TContainerData *pContainer, MCONTACT hContact, int isSend,
const char *pszInitialText, BOOL bActivateTAb, BOOL bPopupContainer, BOOL bWantPopup, MEVENT hdbEvent);
int TSAPI ActivateTabFromHWND(HWND hwndTab, HWND hwnd);
diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index 2367fc9d6c..81ae18d9a8 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -72,15 +72,6 @@ static void _clrMsgFilter(LPARAM lParam) m->wParam = 0;
}
-BOOL TSAPI IsUtfSendAvailable(MCONTACT hContact)
-{
- char *szProto = GetContactProto(hContact);
- if (szProto == NULL)
- return FALSE;
-
- return (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDUTF) ? TRUE : FALSE;
-}
-
/////////////////////////////////////////////////////////////////////////////////////////
// show a modified context menu for the richedit control(s)
// @param dat message window data
@@ -2422,8 +2413,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP if (job->hSendId == 0 && job->hContact == 0)
break;
- job->hSendId = (HANDLE)CallContactService(job->hContact, PSS_MESSAGE,
- (dat->sendMode & SMODE_FORCEANSI) ? (job->dwFlags & ~PREF_UNICODE) : job->dwFlags, (LPARAM)job->szSendBuffer);
+ job->hSendId = (HANDLE)CallContactService(job->hContact, PSS_MESSAGE, job->dwFlags, (LPARAM)job->szSendBuffer);
resent++;
}
@@ -2671,23 +2661,14 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP if (decoded.IsEmpty())
break;
- char *utfResult = NULL;
if (final_sendformat)
DoRtfToTags(dat, decoded, SIZEOF(rtfDefColors), rtfDefColors);
decoded.TrimRight();
int bufSize = WideCharToMultiByte(dat->codePage, 0, decoded, -1, dat->sendBuffer, 0, 0, 0);
- size_t memRequired = 0;
int flags = 0;
- if (!IsUtfSendAvailable(dat->hContact)) {
- flags |= PREF_UNICODE;
- memRequired = bufSize + (mir_wstrlen(decoded) + 1) * sizeof(WCHAR);
- }
- else {
- flags |= PREF_UTF;
- utfResult = mir_utf8encodeT(decoded);
- memRequired = strlen(utfResult) + 1;
- }
+ char *utfResult = mir_utf8encodeT(decoded);
+ size_t memRequired = strlen(utfResult) + 1;
// try to detect RTL
HWND hwndEdit = GetDlgItem(hwndDlg, IDC_MESSAGE);
@@ -2711,15 +2692,9 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP dat->sendBuffer = (char *)mir_realloc(dat->sendBuffer, memRequired);
dat->iSendBufferSize = memRequired;
}
- if (utfResult) {
- memcpy(dat->sendBuffer, utfResult, memRequired);
- mir_free(utfResult);
- }
- else {
- WideCharToMultiByte(dat->codePage, 0, decoded, -1, dat->sendBuffer, bufSize, 0, 0);
- if (flags & PREF_UNICODE)
- memcpy(&dat->sendBuffer[bufSize], decoded, (mir_wstrlen(decoded) + 1) * sizeof(WCHAR));
- }
+
+ memcpy(dat->sendBuffer, utfResult, memRequired);
+ mir_free(utfResult);
if (memRequired == 0 || dat->sendBuffer[0] == 0)
break;
diff --git a/plugins/TabSRMM/src/sendlater.cpp b/plugins/TabSRMM/src/sendlater.cpp index fddb95208a..f373ca98fa 100644 --- a/plugins/TabSRMM/src/sendlater.cpp +++ b/plugins/TabSRMM/src/sendlater.cpp @@ -417,12 +417,7 @@ int CSendLater::sendIt(CSendLaterJob *job) job->iSendCount++;
job->hTargetContact = hContact;
job->bCode = CSendLaterJob::JOB_WAITACK;
-
- DWORD dwFlags = IsUtfSendAvailable(hContact) ? PREF_UTF : PREF_UNICODE;
- if (dwFlags & PREF_UTF)
- job->hProcess = (HANDLE)CallContactService(hContact, PSS_MESSAGE, dwFlags, (LPARAM)job->sendBuffer);
- else
- job->hProcess = (HANDLE)CallContactService(hContact, PSS_MESSAGE, dwFlags, (LPARAM)job->pBuf);
+ job->hProcess = (HANDLE)CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)job->sendBuffer);
return 0;
}
diff --git a/plugins/TabSRMM/src/sendqueue.cpp b/plugins/TabSRMM/src/sendqueue.cpp index 98b9932f7f..4e9471f662 100644 --- a/plugins/TabSRMM/src/sendqueue.cpp +++ b/plugins/TabSRMM/src/sendqueue.cpp @@ -137,75 +137,6 @@ static int SendChunkA(char *chunk, MCONTACT hContact, char *szSvc, DWORD dwFlags return(CallContactService(hContact, szSvc, dwFlags, (LPARAM)chunk)); } -static void DoSplitSendW(LPVOID param) -{ - SendJob *job = sendQueue->getJobByIndex((int)param); - BOOL fFirstSend = FALSE; - WCHAR *wszSaved, savedChar; - size_t iCur = 0, iSavedCur = 0, i; - BOOL fSplitting = TRUE; - MCONTACT hContact = job->hContact; - DWORD dwFlags = job->dwFlags; - size_t chunkSize = job->chunkSize / 2; - - size_t iLen = mir_strlen(job->szSendBuffer); - WCHAR *wszBegin = (WCHAR*)& job->szSendBuffer[iLen + 1]; - WCHAR *wszTemp = (WCHAR*)mir_alloc(sizeof(WCHAR) * (mir_wstrlen(wszBegin) + 1)); - memcpy(wszTemp, wszBegin, sizeof(WCHAR) * (mir_wstrlen(wszBegin) + 1)); - wszBegin = wszTemp; - - do { - iCur += chunkSize; - if (iCur > iLen) - fSplitting = FALSE; - - // try to "word wrap" the chunks - split on word boundaries (space characters), if possible. - // SPLIT_WORD_CUTOFF = max length of unbreakable words, longer words may be split. - if (fSplitting) { - i = 0; - wszSaved = &wszBegin[iCur]; - iSavedCur = iCur; - while (iCur) { - if (wszBegin[iCur] == (TCHAR)' ') { - wszSaved = &wszBegin[iCur]; - break; - } - if (i == SPLIT_WORD_CUTOFF) { // no space found backwards, restore old split position - iCur = iSavedCur; - wszSaved = &wszBegin[iCur]; - break; - } - i++; - iCur--; - } - savedChar = *wszSaved; - *wszSaved = 0; - int id = SendChunkW(wszTemp, hContact, dwFlags); - if (!fFirstSend) { - job->hSendId = (HANDLE)id; - fFirstSend = TRUE; - PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_SPLITSENDACK, (WPARAM)param, 0); - } - *wszSaved = savedChar; - wszTemp = wszSaved; - if (savedChar == (TCHAR)' ') { - wszTemp++; - iCur++; - } - } - else { - int id = SendChunkW(wszTemp, hContact, dwFlags); - if (!fFirstSend) { - job->hSendId = (HANDLE)id; - fFirstSend = TRUE; - PostMessage(PluginConfig.g_hwndHotkeyHandler, DM_SPLITSENDACK, (WPARAM)param, 0); - } - } - Sleep(500L); - } while (fSplitting); - mir_free(wszBegin); -} - static void DoSplitSendA(LPVOID param) { SendJob *job = sendQueue->getJobByIndex((int)param); @@ -279,14 +210,7 @@ static void DoSplitSendA(LPVOID param) size_t SendQueue::getSendLength(const int iEntry, int sendMode) { SendJob &p = m_jobs[iEntry]; - if (p.dwFlags & PREF_UNICODE && !(sendMode & SMODE_FORCEANSI)) { - size_t iLen = mir_strlen(p.szSendBuffer); - WCHAR *wszBuf = (WCHAR*)&p.szSendBuffer[iLen + 1]; - char *utf8 = mir_utf8encodeT(wszBuf); - p.iSendLength = mir_strlen(utf8); - mir_free(utf8); - } - else p.iSendLength = mir_strlen(p.szSendBuffer); + p.iSendLength = mir_strlen(p.szSendBuffer); return p.iSendLength; } @@ -365,13 +289,7 @@ int SendQueue::sendQueued(TWindowData *dat, const int iEntry) m_jobs[iEntry].chunkSize = dat->nMax; DWORD dwOldFlags = m_jobs[iEntry].dwFlags; - if (dat->sendMode & SMODE_FORCEANSI) - m_jobs[iEntry].dwFlags &= ~PREF_UNICODE; - - if (!(m_jobs[iEntry].dwFlags & PREF_UNICODE) || dat->sendMode & SMODE_FORCEANSI) - mir_forkthread(DoSplitSendA, (LPVOID)iEntry); - else - mir_forkthread(DoSplitSendW, (LPVOID)iEntry); + mir_forkthread(DoSplitSendA, (LPVOID)iEntry); m_jobs[iEntry].dwFlags = dwOldFlags; } else { @@ -394,8 +312,7 @@ int SendQueue::sendQueued(TWindowData *dat, const int iEntry) clearJob(iEntry); return 0; } - m_jobs[iEntry].hSendId = (HANDLE)CallContactService(dat->hContact, PSS_MESSAGE, - (dat->sendMode & SMODE_FORCEANSI) ? (m_jobs[iEntry].dwFlags & ~PREF_UNICODE) : m_jobs[iEntry].dwFlags, (LPARAM)m_jobs[iEntry].szSendBuffer); + m_jobs[iEntry].hSendId = (HANDLE)CallContactService(dat->hContact, PSS_MESSAGE, m_jobs[iEntry].dwFlags, (LPARAM)m_jobs[iEntry].szSendBuffer); if (dat->sendMode & SMODE_NOACK) { // fake the ack if we are not interested in receiving real acks ACKDATA ack = { 0 }; @@ -472,13 +389,8 @@ void SendQueue::logError(const TWindowData *dat, int iSendJobIndex, const TCHAR iMsgLen = 0; dbei.pBlob = NULL; } - if (m_jobs[iSendJobIndex].dwFlags & PREF_UTF) - dbei.flags = DBEF_UTF; - if (iSendJobIndex >= 0) { - if (m_jobs[iSendJobIndex].dwFlags & PREF_UNICODE) { - iMsgLen *= 3; - } - } + + dbei.flags = DBEF_UTF; dbei.cbBlob = (int)iMsgLen; dbei.timestamp = time(NULL); dbei.szModule = (char *)szErrMsg; @@ -545,13 +457,8 @@ void SendQueue::recallFailed(const TWindowData *dat, int iEntry) const return; // message area is empty, so we can recall the failed message... - SETTEXTEX stx = { ST_DEFAULT, 1200 }; - if (m_jobs[iEntry].dwFlags & PREF_UNICODE) - SendDlgItemMessage(dat->hwnd, IDC_MESSAGE, EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)&m_jobs[iEntry].szSendBuffer[mir_strlen(m_jobs[iEntry].szSendBuffer) + 1]); - else { - stx.codepage = (m_jobs[iEntry].dwFlags & PREF_UTF) ? CP_UTF8 : CP_ACP; - SendDlgItemMessage(dat->hwnd, IDC_MESSAGE, EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)m_jobs[iEntry].szSendBuffer); - } + SETTEXTEX stx = { ST_DEFAULT, CP_UTF8 }; + SendDlgItemMessage(dat->hwnd, IDC_MESSAGE, EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)m_jobs[iEntry].szSendBuffer); UpdateSaveAndSendButton(const_cast<TWindowData *>(dat)); SendDlgItemMessage(dat->hwnd, IDC_MESSAGE, EM_SETSEL, (WPARAM)-1, (LPARAM)-1); } @@ -698,12 +605,9 @@ int SendQueue::ackMessage(TWindowData *dat, WPARAM wParam, LPARAM lParam) cc->updateStats(TSessionStats::BYTES_SENT, dbei.cbBlob - 1); } - if (job.dwFlags & PREF_UNICODE) - dbei.cbBlob *= sizeof(TCHAR) + 1; if (job.dwFlags & PREF_RTL) dbei.flags |= DBEF_RTL; - if (job.dwFlags & PREF_UTF) - dbei.flags |= DBEF_UTF; + dbei.flags |= DBEF_UTF; dbei.pBlob = (PBYTE)job.szSendBuffer; MessageWindowEvent evt = { sizeof(evt), (int)job.hSendId, job.hContact, &dbei }; @@ -816,41 +720,21 @@ int SendQueue::doSendLater(int iJobIndex, TWindowData *dat, MCONTACT hContact, b } else mir_sntprintf(tszHeader, SIZEOF(tszHeader), _T("M%d|"), time(0)); - if (job->dwFlags & PREF_UTF || !(job->dwFlags & PREF_UNICODE)) { - char *utf_header = mir_utf8encodeT(tszHeader); - size_t required = mir_strlen(utf_header) + mir_strlen(job->szSendBuffer) + 10; - char *tszMsg = reinterpret_cast<char *>(mir_alloc(required)); + char *utf_header = mir_utf8encodeT(tszHeader); + size_t required = mir_strlen(utf_header) + mir_strlen(job->szSendBuffer) + 10; + char *tszMsg = reinterpret_cast<char *>(mir_alloc(required)); - if (fIsSendLater) { - mir_snprintf(tszMsg, required, "%s%s", job->szSendBuffer, utf_header); - db_set_s(hContact ? hContact : job->hContact, "SendLater", szKeyName, tszMsg); - } - else { - mir_snprintf(tszMsg, required, "%s%s", utf_header, job->szSendBuffer); - sendLater->addJob(tszMsg, hContact); - } - mir_free(utf_header); - mir_free(tszMsg); + if (fIsSendLater) { + mir_snprintf(tszMsg, required, "%s%s", job->szSendBuffer, utf_header); + db_set_s(hContact ? hContact : job->hContact, "SendLater", szKeyName, tszMsg); } - else if (job->dwFlags & PREF_UNICODE) { - size_t iLen = mir_strlen(job->szSendBuffer); - wchar_t *wszMsg = (wchar_t *)&job->szSendBuffer[iLen + 1]; - - size_t required = sizeof(TCHAR) * (mir_tstrlen(tszHeader) + mir_wstrlen(wszMsg) + 10); - - TCHAR *tszMsg = reinterpret_cast<TCHAR *>(mir_alloc(required)); - if (fIsSendLater) - mir_sntprintf(tszMsg, required, _T("%s%s"), wszMsg, tszHeader); - else - mir_sntprintf(tszMsg, required, _T("%s%s"), tszHeader, wszMsg); - char *utf = mir_utf8encodeT(tszMsg); - if (fIsSendLater) - db_set_s(hContact ? hContact : job->hContact, "SendLater", szKeyName, utf); - else - sendLater->addJob(utf, hContact); - mir_free(utf); - mir_free(tszMsg); + else { + mir_snprintf(tszMsg, required, "%s%s", utf_header, job->szSendBuffer); + sendLater->addJob(tszMsg, hContact); } + mir_free(utf_header); + mir_free(tszMsg); + if (fIsSendLater) { int iCount = db_get_dw(hContact ? hContact : job->hContact, "SendLater", "count", 0); iCount++; |