Browse Source

changed write of clip time on paste to a thread. On U3 devices the write is very slow

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@353 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 19 years ago
parent
commit
d0f7156a18
5 changed files with 73 additions and 39 deletions
  1. 0 37
      Misc.cpp
  2. 0 1
      Misc.h
  3. 68 1
      ProcessPaste.cpp
  4. 1 0
      ProcessPaste.h
  5. 4 0
      QPasteWnd.cpp

+ 0 - 37
Misc.cpp

@@ -1318,43 +1318,6 @@ void CPopup::Hide()
 ID based Globals
 \*------------------------------------------------------------------*/
 
-BOOL MarkClipAsPasted(long lID)
-{
-	CGetSetOptions::SetTripPasteCount(-1);
-	CGetSetOptions::SetTotalPasteCount(-1);
-	
-	if( !g_Opt.m_bUpdateTimeOnPaste )
-		return FALSE;
-	
-	try
-	{	
-		//Update the time it was copied so that it appears at the top of the 
-		//paste list.  Items are sorted by this time.
-
-		CTime now = CTime::GetCurrentTime();
-		try
-		{
-			CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT lDate FROM Main ORDER BY lDate DESC LIMIT 1"));			
-			if(q.eof() == false)
-			{
-				long lLatestDate = q.getIntField(_T("lDate"));
-				if(now.GetTime() <= lLatestDate)
-				{
-					now = lLatestDate + 1;
-				}
-			}
-		}
-		CATCH_SQLITE_EXCEPTION
-
-		theApp.m_db.execDMLEx(_T("UPDATE Main SET lDate = %d where lID = %d;"), (long)now.GetTime(), lID);
-		
-		return TRUE;
-	}
-	CATCH_SQLITE_EXCEPTION
-	
-	return FALSE;
-}
-
 long NewGroupID(long lParentID, CString text)
 {
 	long lID=0;

+ 0 - 1
Misc.h

@@ -322,7 +322,6 @@ public:
 /*------------------------------------------------------------------*\
 	ID based Globals
 \*------------------------------------------------------------------*/
-BOOL MarkClipAsPasted(long lID);
 long NewGroupID(long lParentID = 0, CString text = "");
 BOOL DeleteID(long lID);
 BOOL DeleteAllIDs();

+ 68 - 1
ProcessPaste.cpp

@@ -91,8 +91,75 @@ BOOL CProcessPaste::DoDrag()
 
 void CProcessPaste::MarkAsPasted()
 {
+	Log(_T("start of MarkAsPasted"));
+
 	CClipIDs& clips = GetClipIDs();
 	if(clips.GetSize() == 1)
-		MarkClipAsPasted(clips.ElementAt(0));
+	{
+		CGetSetOptions::SetTripPasteCount(-1);
+		CGetSetOptions::SetTotalPasteCount(-1);
+
+		if(!g_Opt.m_bUpdateTimeOnPaste)
+			return;
+
+		long lID = (long)clips.ElementAt(0);
+		//Moved to a thread because when running from from U3 devices the write is time consuming
+		AfxBeginThread(CProcessPaste::MarkAsPastedThread, (LPVOID)lID, THREAD_PRIORITY_LOWEST);
+	}
+
+	Log(_T("End of MarkAsPasted"));
 }
 
+UINT CProcessPaste::MarkAsPastedThread(LPVOID pParam)
+{
+	static CEvent UpdateTimeEvent(TRUE, TRUE, _T("Ditto_Update_Clip_Time"), NULL);
+	UpdateTimeEvent.ResetEvent();
+
+	Log(_T("Start of MarkAsPastedThread"));
+
+	//If running from a U3 device then wait a little before updating the db
+	//updating the db can take a second or two and it delays the act of pasting
+	if(g_Opt.m_bU3)
+	{
+		Sleep(350);
+	}
+
+	long lID = (long)pParam;
+	BOOL bRet = FALSE;
+
+	try
+	{
+		CppSQLite3DB Local_db;
+		Local_db.open(CGetSetOptions::GetDBPath());
+
+		//Update the time it was copied so that it appears at the top of the
+		//paste list. Items are sorted by this time.
+		CTime now = CTime::GetCurrentTime();
+		try
+		{
+			CppSQLite3Query q = Local_db.execQuery(_T("SELECT lDate FROM Main ORDER BY lDate DESC LIMIT 1"));
+
+			if(q.eof() == false)
+			{
+				long lLatestDate = q.getIntField(_T("lDate"));
+				if(now.GetTime() <= lLatestDate)
+				{
+					now = lLatestDate + 1;
+				}
+			}
+		}
+
+		CATCH_SQLITE_EXCEPTION
+
+		Local_db.execDMLEx(_T("UPDATE Main SET lDate = %d where lID = %d;"), (long)now.GetTime(), lID);
+		Local_db.close();
+		bRet = TRUE;
+	}
+
+	CATCH_SQLITE_EXCEPTION
+
+	Log(_T("End of MarkAsPastedThread"));
+
+	UpdateTimeEvent.SetEvent();
+	return bRet;
+}

+ 1 - 0
ProcessPaste.h

@@ -36,6 +36,7 @@ public:
 	BOOL DoDrag();
 
 	void MarkAsPasted();
+	static UINT MarkAsPastedThread(LPVOID pParam);
 };
 
 #endif // !defined(AFX_PROCESSPASTE_H__185CBB6F_4B63_4397_8FF9_E18D777DA506__INCLUDED_)

+ 4 - 0
QPasteWnd.cpp

@@ -2693,6 +2693,7 @@ void CQPasteWnd::RunThread()
 {
 	try
 	{
+		CEvent UpdateTimeEvent(TRUE, TRUE, _T("Ditto_Update_Clip_Time"), NULL);
 		CppSQLite3DB db;
 
 		CString csDbPath = CGetSetOptions::GetDBPath();
@@ -2775,6 +2776,9 @@ void CQPasteWnd::RunThread()
 				{
 					ResetEvent(m_SearchingEvent);
 
+					//If we pasted then wait for the time on the pasted event to be updated before we query the db
+					DWORD dRet = WaitForSingleObject(UpdateTimeEvent, 2000);
+
 					long lTick = GetTickCount();
 					BOOL bRefreshedRows = false;