[sword-svn] r101 - trunk/src/gui

dtrotzjr at www.crosswire.org dtrotzjr at www.crosswire.org
Mon Mar 17 19:03:39 MST 2008


Author: dtrotzjr
Date: 2008-03-17 19:03:38 -0700 (Mon, 17 Mar 2008)
New Revision: 101

Modified:
   trunk/src/gui/NavFind.cpp
   trunk/src/gui/NavFind.h
   trunk/src/gui/SwordIndex.cpp
   trunk/src/gui/SwordIndex.h
Log:
Fixed searching memory leak and added better searching progress bar support.

Modified: trunk/src/gui/NavFind.cpp
===================================================================
--- trunk/src/gui/NavFind.cpp	2008-03-17 03:20:07 UTC (rev 100)
+++ trunk/src/gui/NavFind.cpp	2008-03-18 02:03:38 UTC (rev 101)
@@ -259,4 +259,5 @@
 	clearResults();
 	setProgress(5);
 	navigator->position.search(query,rangeMode,methodMode,this);
-}
\ No newline at end of file
+}
+

Modified: trunk/src/gui/NavFind.h
===================================================================
--- trunk/src/gui/NavFind.h	2008-03-17 03:20:07 UTC (rev 100)
+++ trunk/src/gui/NavFind.h	2008-03-18 02:03:38 UTC (rev 101)
@@ -42,5 +42,4 @@
 	int rangeMode;
 	int methodMode;
 };
-
 #endif 

Modified: trunk/src/gui/SwordIndex.cpp
===================================================================
--- trunk/src/gui/SwordIndex.cpp	2008-03-17 03:20:07 UTC (rev 100)
+++ trunk/src/gui/SwordIndex.cpp	2008-03-18 02:03:38 UTC (rev 101)
@@ -196,46 +196,52 @@
 	bible->setKey(verse);
 }
 
+
 void SwordIndex::search(const WCString &text, int range, int method, Searcher* searcher) {
-	searcher->setProgress(10);
-	Verse from=verse->clone();
-	Verse to=verse->clone();
-	if (range==RANGEBIBLE) from.Testament(1);
-	if ((range==RANGETESTAMENT)||(range==RANGEBIBLE)) from.Book(1);
+	//searcher->setProgress(10);
+    // Clone is a bit dangerous, it creates a new SWKey which has to be deleted
+    // thus you cannot simply pass the cloned object to the constructor of
+    // a VerseKey object.
+    SWKey *tmp = verse->clone();
+    Verse from(tmp);
+	Verse to(tmp);
+    delete tmp;
+
+    if (range == RANGEBIBLE) 
+        from.Testament(1);
+	if ((range == RANGETESTAMENT)||(range == RANGEBIBLE)) 
+        from.Book(1);
+
 	from.Chapter(1);
 	from.Verse(1);
-	if (range==RANGEBIBLE) to.Testament(2);
-	if ((range==RANGETESTAMENT)||(range==RANGEBIBLE)) to.Book((to.Testament()==2)?bookCount()-otBookCount():otBookCount());
+	if (range == RANGEBIBLE) 
+        to.Testament(2);
+	if ((range == RANGETESTAMENT)||(range == RANGEBIBLE)) 
+        to.Book((to.Testament()==2) ? 
+            bookCount() - otBookCount() :
+            otBookCount());
+
 	to.Chapter(to.books[to.Testament()-1][to.Book()-1].chapmax);
 	to.Verse(to.books[to.Testament()-1][to.Book()-1].versemax[to.Chapter()-1]);
-/*	FOR DEBUGGING
-	searcher->addResult(verseToString(&from));
-	searcher->addResult(verseToString(&to));
-*/
 
 	Verse verses(from,to);
 	sword::ListKey results;
-	searcher->setProgress(20);
-// this next code block carries out the search - the call is to SWModule::search
-	results=bible->search(
-		text.c_str(), 
-		(method==METHODMULTIWORD)?-2:-1, 
-		2 /* case insensitive */, 
-		&verses
-	);
-// end of search - returns a SWModule::ListKey variable (results)
-	searcher->setProgress(90);
+	//searcher->setProgress(20);
 
-// the 'for' loop copies the results into the display window
+	results=bible->search(text.c_str(), (method==METHODMULTIWORD)?-2:-1, 2, &verses, 0, setPercentCB, (void*)searcher);
+
+	//searcher->setProgress(90);
+
 	for (results = TOP; !results.Error(); results++) {
-//		searcher->addResult(toUString(String(results.getText())));
 		searcher->addResult(results.getText());
-		}
-// thanks to Troy for the above
+	}
 
-// below was the original code from Johan Gorter
-//	for (int i=0;i<results.Count();i++) {
-//		searcher->addResult(toUString(String(results.getElement(i)->getText())));
-//	}
-	searcher->setProgress(100);
+	//searcher->setProgress(100);
 }
+
+void setPercentCB(char percent, void *userData)
+{
+    Searcher *caller = static_cast<Searcher*>(userData);
+    if(caller)
+        caller->setProgress((int)percent);
+}
\ No newline at end of file

Modified: trunk/src/gui/SwordIndex.h
===================================================================
--- trunk/src/gui/SwordIndex.h	2008-03-17 03:20:07 UTC (rev 100)
+++ trunk/src/gui/SwordIndex.h	2008-03-18 02:03:38 UTC (rev 101)
@@ -115,4 +115,5 @@
 	void operator-=(int count) {verse->decrement(count);};
 };
 
+void setPercentCB(char percent, void *userData);
 #endif




More information about the sword-cvs mailing list