/* * add a message to the sending queue. * iLen = required size of the memory block to hold the message */ int SendQueue::addTo(TWindowData *dat, const int iLen, int dwFlags) { int iLength = 0, i; int iFound = NR_SENDJOBS; if (m_currentIndex >= NR_SENDJOBS) { _DebugPopup(dat->hContact, _T("Send queue full")); return 0; } /* * find a free entry in the send queue... */ for (i = 0; i < NR_SENDJOBS; i++) { if (m_jobs[i].hOwner != 0 || m_jobs[i].iStatus != 0) { // this entry is used, check if it's orphaned and can be removed... if (m_jobs[i].hwndOwner && IsWindow(m_jobs[i].hwndOwner)) // window exists, do not reuse it continue; if (time(NULL) - m_jobs[i].dwTime < 120) // non-acked entry, but not old enough, don't re-use it continue; clearJob(i); iFound = i; goto entry_found; } iFound = i; break; } entry_found: if (iFound == NR_SENDJOBS) { _DebugPopup(dat->hContact, _T("Send queue full")); return 0; } iLength = iLen; if (iLength > 0) { if (m_jobs[iFound].sendBuffer == NULL) { if (iLength < HISTORY_INITIAL_ALLOCSIZE) iLength = HISTORY_INITIAL_ALLOCSIZE; m_jobs[iFound].sendBuffer = (char *)malloc(iLength); m_jobs[iFound].dwLen = iLength; } else { if (iLength > m_jobs[iFound].dwLen) { m_jobs[iFound].sendBuffer = (char *)realloc(m_jobs[iFound].sendBuffer, iLength); m_jobs[iFound].dwLen = iLength; } } CopyMemory(m_jobs[iFound].sendBuffer, dat->sendBuffer, iLen); } m_jobs[iFound].dwFlags = dwFlags; m_jobs[iFound].dwTime = time(NULL); HWND hwndDlg = dat->hwnd; dat->cache->saveHistory(0, 0); ::SetDlgItemText(hwndDlg, IDC_MESSAGE, _T("")); ::SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE)); UpdateSaveAndSendButton(dat); sendQueued(dat, iFound); return 0; }
int SendQueue::addTo(TWindowData *dat, size_t iLen, int dwFlags) { int i; int iFound = NR_SENDJOBS; if (m_currentIndex >= NR_SENDJOBS) { _DebugPopup(dat->hContact, _T("Send queue full")); return 0; } // find a mir_free entry in the send queue... for (i = 0; i < NR_SENDJOBS; i++) { if (m_jobs[i].hContact != 0 || m_jobs[i].iStatus != 0) { // this entry is used, check if it's orphaned and can be removed... if (m_jobs[i].hOwnerWnd && IsWindow(m_jobs[i].hOwnerWnd)) // window exists, do not reuse it continue; if (time(NULL) - m_jobs[i].dwTime < 120) // non-acked entry, but not old enough, don't re-use it continue; clearJob(i); iFound = i; goto entry_found; } iFound = i; break; } entry_found: if (iFound == NR_SENDJOBS) { _DebugPopup(dat->hContact, _T("Send queue full")); return 0; } SendJob &job = m_jobs[iFound]; job.szSendBuffer = (char*)mir_alloc(iLen); memcpy(job.szSendBuffer, dat->sendBuffer, iLen); job.dwFlags = dwFlags; job.dwTime = time(NULL); HWND hwndDlg = dat->hwnd; dat->cache->saveHistory(0, 0); ::SetDlgItemText(hwndDlg, IDC_MESSAGE, _T("")); ::SetFocus(GetDlgItem(hwndDlg, IDC_MESSAGE)); UpdateSaveAndSendButton(dat); sendQueued(dat, iFound); return 0; }
void SendQueue::recallFailed(const TWindowData *dat, int iEntry) const { if (dat == NULL) return; int iLen = GetWindowTextLength(GetDlgItem(dat->hwnd, IDC_MESSAGE)); NotifyDeliveryFailure(dat); if (iLen != 0) return; // message area is empty, so we can recall the failed message... 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); }
void SendQueue::recallFailed(const TWindowData *dat, int iEntry) const { int iLen = GetWindowTextLengthA(GetDlgItem(dat->hwnd, IDC_MESSAGE)); if(dat) { NotifyDeliveryFailure(dat); if (iLen == 0) { // 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].sendBuffer[lstrlenA(m_jobs[iEntry].sendBuffer) + 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].sendBuffer); } UpdateSaveAndSendButton(const_cast<TWindowData *>(dat)); SendDlgItemMessage(dat->hwnd, IDC_MESSAGE, EM_SETSEL, (WPARAM) - 1, (LPARAM) - 1); } } }