FileView: Do not forget to kill the preview background task is some cases.

[GB.FORM]
* NEW: FileView: EPub preview generator is more clever.
* BUG: FileView: Do not forget to kill the preview background task is some cases.
* BUG: FileView: Fix the refresh logic.
This commit is contained in:
Benoît Minisini 2023-01-05 11:35:19 +01:00
parent 78841b379e
commit d9a5b8feaf
2 changed files with 65 additions and 53 deletions

View file

@ -102,7 +102,7 @@ Private Sub PrintIcon(hImage As Image, sThumb As String, Optional bVideo As Bool
Dim iSizeBinding As Integer
If nPage < 0 Then
iSizeBinding = 4
iSizeBinding = $iSize \ 16
Else If nPage > 1 Then
iSizeBinding = Min(Min($iSize / 8, Max(1, nPage / 512 * $iSize)), (nPage - 1))
Endif
@ -319,24 +319,40 @@ Private Sub PrintEPub(sPath As String, sThumb As String) As Rect
Dim sData As String
Dim hImage As Image
Dim sCover As String
Dim sDir As String
Dim iPos As Integer
Dim iPos2 As Integer
Dim sContent As String
If Not $sUnzip Then Return
For Each sDir In ["", "OEBPS", "Ops"]
Exec [$sUnzip, "-p", "-C", sPath, sDir &/ "content.opf"] To sData
Try sCover = Scan(sData, "*<meta name=\"cover\" content=\"*\"*")[1]
If sCover Then Break
Next
Exec [$sUnzip, "-p", "-C", sPath, "META-INF/container.xml"] To sData
Try sContent = Scan(sData, "*full-path=\"*\"*")[1]
If Not sContent Then Return
Exec [$sUnzip, "-p", "-C", sPath, sContent] To sData
If Not sData Then Return
Try sCover = Scan(sData, "*<meta name=\"cover\" content=\"*\"*")[1]
If Not sCover Then
iPos = InStr(sData, "media-type=\"image/")
If iPos = 0 Then Return
iPos = RInStr(sData, "<item", iPos)
If iPos = 0 Then Return
iPos2 = InStr(sData, "/>", iPos)
If iPos2 = 0 Then Return
Try sCover = Scan(Mid$(sData, iPos, iPos2 - iPos), "*id=\"*\"*")[1]
If Not sCover Then Return
Endif
If sCover Then
iPos = InStr(sData, "id=\"" & sCover & "\"")
If iPos Then
iPos2 = InStr(sData, "/>", iPos)
iPos = RInStr(sData, "<item ", iPos - 1)
Try sCover = sDir &/ Scan(Mid$(sData, iPos, iPos2 - iPos), "*href=\"*\"*")[1]
Try sCover = File.Dir(sContent) &/ Scan(Mid$(sData, iPos, iPos2 - iPos), "*href=\"*\"*")[1]
If Not Error Then
sCover = Main.UrlUnquote(sCover)
Else

View file

@ -103,7 +103,6 @@ Private $iPreviewCount As Integer
Private $hEnsureVisible As Timer
Private $hWatch As Watch
Private $bWatch As Boolean
Private $bRefreshIcon As Boolean
Private $bRefreshAll As Boolean
Private $hWatcher As Watcher
Private $bVisible As Boolean
@ -122,9 +121,10 @@ Private $hHighlightPicture As Picture
Private $hBorder As Panel
Private $hProgress As ProgressBar
Private $bRefreshPreview As Boolean
Private $sLastPreview As String
Private $bIgnorePreviewCache As Boolean
Private $bPreviewDone As Boolean
Private $bRefreshView As Boolean
Static Public Sub _init()
@ -384,6 +384,8 @@ Private Sub RefreshView()
Inc Application.Busy
$bRefreshTriggered = False
$bRefreshView = False
bFilter = Object.CanRaise(Me, "Filter")
$nFile = 0
@ -495,10 +497,8 @@ Private Sub RefreshView()
GoSub ADD_PREVIEW
Else
$hColumnView[sKey].Editable = Access(sDir, gb.Write)
If $bRefreshIcon Then
$hColumnView[sKey].Picture = hPict
GoSub ADD_PREVIEW
Endif
$hColumnView[sKey].Picture = hPict
GoSub ADD_PREVIEW
Endif
With $hColumnView[sKey]
@ -513,10 +513,8 @@ Private Sub RefreshView()
GoSub ADD_PREVIEW
Else
$hIconView[sKey].Editable = Access(sDir, gb.Write)
If $bRefreshIcon Then
$hIconView[sKey].Picture = hPict
GoSub ADD_PREVIEW
Endif
$hIconView[sKey].Picture = hPict
GoSub ADD_PREVIEW
Endif
If sRichText Then $hIconView[sKey].RichText = sRichText
Endif
@ -533,7 +531,6 @@ Private Sub RefreshView()
Finally
$bRefreshIcon = False
$bRefreshAll = False
If $hColumnView.Visible Then
$hColumnView._End
@ -580,7 +577,10 @@ End
Private Sub StopPreview()
If $hPreview Then $hPreview.Stop
If $hPreview Then
$hPreview.Stop
'Debug Me.Name
Endif
$hProgress.Hide
$sLastPreview = ""
@ -590,6 +590,9 @@ Private Sub StartPreview(aPreview As String[])
Dim sDir As String
If Not $bVisible Then Return
If Not $bShowPreview Then Return
StopPreview
Component.Load("gb.hash")
$hProgress.Show
@ -603,6 +606,7 @@ Private Sub StartPreview(aPreview As String[])
' Endif
$hPreview = New CTaskPreview(GetCurrentDir(), GetIconSize(), $iMaxPreviewSize, aPreview, sDir, $bIgnorePreviewCache) As "TaskPreview"
'Debug Me.Name;; System.Backtrace.Join(" ")
End
@ -644,6 +648,7 @@ Public Sub TaskPreview_Read(Data As String)
For Each sLine In Split(Data, "\n", "", True)
If sLine = "." Then
$bPreviewDone = True
Try StopPreview
Return
Endif
@ -705,31 +710,27 @@ End
Private Sub RefreshViewLater(Optional bClear As Boolean)
UpdateIconView
$bRefreshView = True
If bClear Then $bRefreshAll = True
If Not $bVisible Then Return
If $bRefreshTriggered Then
If bClear Then $bRefreshAll = True
Return
Endif
If $bRefreshTriggered Then Return
If $hRefresh.Enabled Then $hRefresh.Stop
$bRefreshAll = bClear
$bRefreshTriggered = True
UpdateIconView
$hRefresh.Trigger
End
Public Sub _RefreshViewAfter()
If $bRefreshTriggered Then Return
If $hRefresh.Enabled Then Return
$hRefresh.Delay = 100
$hRefresh.Start
End
' Public Sub _RefreshViewAfter()
'
' If $bRefreshTriggered Then Return
' If $hRefresh.Enabled Then Return
'
' $hRefresh.Delay = 100
' $hRefresh.Start
'
' End
Public Sub Refresh_Timer()
@ -1140,8 +1141,7 @@ Private Sub Settings_Write(Value As Variant[])
End Select
$bRefreshIcon = True
RefreshViewLater
'RefreshViewLater(True)
Else
@ -1193,8 +1193,7 @@ Private Sub IconSize_Write(Value As Integer)
If $aIconSize[iView] = Value Then Return
$aIconSize[iView] = Value
$bRefreshIcon = True
RefreshViewLater
RefreshViewLater(True)
End
@ -1250,7 +1249,6 @@ Private Sub ShowPreview_Write(Value As Boolean)
If $bShowPreview = Value Then Return
$bShowPreview = Value
StopPreview
$bRefreshIcon = True
RefreshViewLater
End
@ -1361,21 +1359,20 @@ End
Public Sub Watcher_Hide()
'Debug Me.Name
If $hPreview Then
StopPreview
$bRefreshPreview = True
Endif
$hWatch = Null
$bVisible = False
$hWatch = Null
If $hPreview Then
StopPreview
RefreshViewLater
Endif
End
Public Sub Watcher_Show()
'Debug Me.Name;; $bRefreshView
$bVisible = True
RefreshViewLater($bRefreshPreview)
$bRefreshPreview = False
If $bRefreshView Then RefreshViewLater()
End
@ -1652,8 +1649,7 @@ Private Sub View_Write(Value As Integer)
Endif
UpdateIconView
If iIconSize <> GetIconSize() Then
$bRefreshIcon = True
RefreshView
RefreshViewLater(True)
Endif
Endif