void CMainFrmThread::OnSaveRemoteClips() { LogSendRecieveInfo("---------Start of OnSaveRemoteClips"); CClipList *pLocalClips = new CClipList(); //Save the clips locally { ATL::CCritSecLock csLock(m_cs.m_sect); POSITION pos; CClip* pClip; pos = m_saveRemoteClips.GetHeadPosition(); while(pos) { pClip = m_saveRemoteClips.GetNext(pos); pLocalClips->AddTail(pClip); } //pLocalClips now own, the clips m_saveRemoteClips.RemoveAll(); } LogSendRecieveInfo("---------OnSaveRemoteClips - Before AddToDB"); int count = pLocalClips->AddToDB(true); LogSendRecieveInfo("---------OnSaveRemoteClips - After AddToDB"); //are we supposed to add this clip to the clipboard CClip *pLastClip = pLocalClips->GetTail(); if(pLastClip && pLastClip->m_param1 == TRUE) { LogSendRecieveInfo("---------OnSaveRemoteClips - Before Posting msg to main thread to set clipboard"); //set the clipboard on the main thread, i was having a problem with setting the clipboard on a thread //guess it needs to be set on the main thread //main window will clear this memory PostMessage(theApp.m_MainhWnd, WM_LOAD_ClIP_ON_CLIPBOARD, (LPARAM)pLastClip, 0); LogSendRecieveInfo("---------OnSaveRemoteClips - After Posting msg to main thread to set clipboard"); pLocalClips->RemoveTail(); } theApp.RefreshView(); delete pLocalClips; LogSendRecieveInfo("---------End of OnSaveRemoteClips"); }
void CMainFrmThread::OnSaveClips() { CClipList *pLocalClips = new CClipList(); //Save the clips locally { ATL::CCritSecLock csLock(m_cs.m_sect); POSITION pos; CClip* pClip; pos = m_saveClips.GetHeadPosition(); while(pos) { pClip = m_saveClips.GetNext(pos); pLocalClips->AddTail(pClip); } //pLocalClips now own, the clips m_saveClips.RemoveAll(); } Log(_T("SaveCopyClips Before AddToDb")); int count = pLocalClips->AddToDB(true); Log(StrF(_T("SaveCopyclips After AddToDb, Count: %d"), count)); if(count > 0) { int Id = pLocalClips->GetTail()->m_id; Log(StrF(_T("SaveCopyclips After AddToDb, Id: %d Before OnCopyCopyCompleted"), Id)); theApp.OnCopyCompleted(Id, count); Log(StrF(_T("SaveCopyclips After AddToDb, Id: %d After OnCopyCopyCompleted"), Id)); if(g_Opt.m_lAutoSendClientCount > 0) { m_sendToClientThread.FireSendToClient(pLocalClips); } } delete pLocalClips; }
long CCP_MainApp::SaveCopyClips() { long lID = 0; int count; CClipList* pClips = m_CopyThread.GetClips(); // we now own pClips if(!pClips) return 0; CClipList* pCopyOfClips = NULL; if(g_Opt.m_lAutoSendClientCount > 0) { //The thread will free these pCopyOfClips = new CClipList; if(pCopyOfClips != NULL) { *pCopyOfClips = *pClips; } } bool bEnteredThread = false; bool bDeletepClips = true; if(m_QuickPasteMode == ADDING_QUICK_PASTE) { //this will be added when they are done entering the quick paste text m_pQuickPasteClip = pClips; bDeletepClips = false; //go ahead and send the clips out even though it won't be added for a bit count = 1; } else { count = pClips->AddToDB(true); if(count > 0) { lID = pClips->GetTail()->m_ID; OnCopyCompleted(lID, count); if(m_CopyBuffer.Active()) { m_CopyBuffer.EndCopy(lID); } } } if(count > 0) { if(g_Opt.m_lAutoSendClientCount > 0) { AfxBeginThread(SendClientThread, pCopyOfClips); bEnteredThread = true; } } if(bEnteredThread == false) delete pCopyOfClips; if(bDeletepClips) delete pClips; return lID; }