Преглед на файлове

Merge pull request #16 from bemagri/codex/fix-book-list-display-issue

Fix stray book cover rendered at first position
Bernardo Magri преди 4 месеца
родител
ревизия
acd5173f33
променени са 2 файла, в които са добавени 38 реда и са изтрити 0 реда
  1. 13 0
      src/bookcollection.pas
  2. 25 0
      src/unitCoverWorker.pas

+ 13 - 0
src/bookcollection.pas

@@ -32,10 +32,22 @@ end;
 
 implementation
 
+uses
+  unitCoverWorker;
+
 { TBookCollection }
 
 procedure TBookCollection.Clear;
+var
+  i : Integer;
+  book : TBook;
 begin
+  CoverWorkerStop;
+  for i := mList.Count - 1 downto 0 do
+  begin
+    book := TBook(mList[i]);
+    book.Free;               // free cover controls and the book itself
+  end;
   mList.Clear;
 end;
 
@@ -73,6 +85,7 @@ destructor Tbookcollection.Destroy;
 var i:Integer;
     book:TBook;
 begin
+  CoverWorkerStop;
   for i:=0 to mList.Count-1 do
       begin
         book:= (TBook(mList.Items[i]));

+ 25 - 0
src/unitCoverWorker.pas

@@ -20,6 +20,9 @@ procedure CoverWorkerEnqueueBookIfMissing(B: TBook);
   queue is empty. Call again later to restart if you enqueue more books. }
 procedure CoverWorkerStart;
 
+{ Stops the background worker and clears any pending books }
+procedure CoverWorkerStop;
+
 implementation
 
 type
@@ -179,6 +182,28 @@ begin
   end;
 end;
 
+{ Stops the worker and clears any queued books }
+procedure CoverWorkerStop;
+var
+  l: TList;
+begin
+  if GWorker <> nil then
+  begin
+    GWorker.Terminate;
+    GWorker.WaitFor;
+    GWorker := nil;
+  end;
+  if GPdfQueue <> nil then
+  begin
+    l := GPdfQueue.LockList;
+    try
+      l.Clear;
+    finally
+      GPdfQueue.UnlockList;
+    end;
+  end;
+end;
+
 {--- worker --------------------------------------------------------------------}
 
 procedure TCoverWorker.DoApplyCover;