refactor(archive): provide archive name as a method of Archive struct
This commit is contained in:
parent
091d0e910d
commit
3eb0e59968
1
app.go
1
app.go
|
@ -54,7 +54,6 @@ type State struct {
|
||||||
Archive archive.Archive
|
Archive archive.Archive
|
||||||
ArchivePos int
|
ArchivePos int
|
||||||
ArchivePath string
|
ArchivePath string
|
||||||
ArchiveName string
|
|
||||||
PixbufL, PixbufR *gdk.Pixbuf
|
PixbufL, PixbufR *gdk.Pixbuf
|
||||||
GoToThumbPixbuf *gdk.Pixbuf
|
GoToThumbPixbuf *gdk.Pixbuf
|
||||||
Scale float64
|
Scale float64
|
||||||
|
|
|
@ -70,11 +70,6 @@ func (app *App) doLoadArchive(path string, assumeHTTPURL bool, httpReferer strin
|
||||||
app.S.ImageHashes = make(map[int]imgdiff.Hash)
|
app.S.ImageHashes = make(map[int]imgdiff.Hash)
|
||||||
|
|
||||||
app.S.ArchivePath = path
|
app.S.ArchivePath = path
|
||||||
if assumeHTTPURL {
|
|
||||||
app.S.ArchiveName = path
|
|
||||||
} else {
|
|
||||||
app.S.ArchiveName = filepath.Base(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
cache := pagecache.NewPageCache()
|
cache := pagecache.NewPageCache()
|
||||||
app.S.PageCache = &cache
|
app.S.PageCache = &cache
|
||||||
|
@ -150,7 +145,6 @@ func (app *App) archiveClose() {
|
||||||
app.S.Archive.Close()
|
app.S.Archive.Close()
|
||||||
|
|
||||||
app.S.Archive = nil
|
app.S.Archive = nil
|
||||||
app.S.ArchiveName = ""
|
|
||||||
app.S.ArchivePath = ""
|
app.S.ArchivePath = ""
|
||||||
app.S.ArchivePos = 0
|
app.S.ArchivePos = 0
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ var (
|
||||||
type Archive interface {
|
type Archive interface {
|
||||||
Load(i int, autorotate bool, nPreload int) (*gdk.Pixbuf, error)
|
Load(i int, autorotate bool, nPreload int) (*gdk.Pixbuf, error)
|
||||||
Kind() Kind
|
Kind() Kind
|
||||||
|
ArchiveName() string
|
||||||
Name(i int) (string, error)
|
Name(i int) (string, error)
|
||||||
Len() *int // nil represents unknown length
|
Len() *int // nil represents unknown length
|
||||||
Close() error
|
Close() error
|
||||||
|
|
|
@ -93,6 +93,10 @@ func (ar *Dir) Load(i int, autorotate bool, _nPreload int) (*gdk.Pixbuf, error)
|
||||||
return pixbuf.Load(f, autorotate)
|
return pixbuf.Load(f, autorotate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ar *Dir) ArchiveName() string {
|
||||||
|
return ar.name
|
||||||
|
}
|
||||||
|
|
||||||
func (ar *Dir) Name(i int) (string, error) {
|
func (ar *Dir) Name(i int) (string, error) {
|
||||||
if err := ar.checkbounds(i); err != nil {
|
if err := ar.checkbounds(i); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
|
@ -153,6 +153,10 @@ func (ar *HTTP) Kind() Kind {
|
||||||
return HTTPKind
|
return HTTPKind
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ar *HTTP) ArchiveName() string {
|
||||||
|
return ar.urlTemplate
|
||||||
|
}
|
||||||
|
|
||||||
func (ar *HTTP) Name(i int) (string, error) {
|
func (ar *HTTP) Name(i int) (string, error) {
|
||||||
return ar.urlTemplate, nil
|
return ar.urlTemplate, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,10 @@ func (ar *Zip) Kind() Kind {
|
||||||
return Packed
|
return Packed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ar *Zip) ArchiveName() string {
|
||||||
|
return ar.name
|
||||||
|
}
|
||||||
|
|
||||||
func (ar *Zip) Name(i int) (string, error) {
|
func (ar *Zip) Name(i int) (string, error) {
|
||||||
if err := ar.checkbounds(i); err != nil {
|
if err := ar.checkbounds(i); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
8
image.go
8
image.go
|
@ -90,13 +90,13 @@ func (app *App) updateStatus() {
|
||||||
leftIndex, rightIndex = rightIndex, leftIndex
|
leftIndex, rightIndex = rightIndex, leftIndex
|
||||||
leftw, rightw = rightw, leftw
|
leftw, rightw = rightw, leftw
|
||||||
}
|
}
|
||||||
msg = fmt.Sprintf("%d+%d / %s %s | %dx%d - %dx%d (%d%%) | %s | %s - %s", leftIndex, rightIndex, lenStr, markedStr, leftw, lefth, rightw, righth, zoom, s.ArchiveName, left, right)
|
msg = fmt.Sprintf("%d+%d / %s %s | %dx%d - %dx%d (%d%%) | %s | %s - %s", leftIndex, rightIndex, lenStr, markedStr, leftw, lefth, rightw, righth, zoom, s.Archive.ArchiveName(), left, right)
|
||||||
title = fmt.Sprintf("[%d+%d / %s] %s", leftIndex, rightIndex, lenStr, s.ArchiveName)
|
title = fmt.Sprintf("[%d+%d / %s] %s", leftIndex, rightIndex, lenStr, s.Archive.ArchiveName())
|
||||||
} else {
|
} else {
|
||||||
imgPath, _ := s.Archive.Name(s.ArchivePos)
|
imgPath, _ := s.Archive.Name(s.ArchivePos)
|
||||||
w, h := s.PixbufL.GetWidth(), s.PixbufL.GetHeight()
|
w, h := s.PixbufL.GetWidth(), s.PixbufL.GetHeight()
|
||||||
msg = fmt.Sprintf("%d / %s %s | %dx%d (%d%%) | %s | %s", s.ArchivePos+1, lenStr, markedStr, w, h, zoom, s.ArchiveName, imgPath)
|
msg = fmt.Sprintf("%d / %s %s | %dx%d (%d%%) | %s | %s", s.ArchivePos+1, lenStr, markedStr, w, h, zoom, s.Archive.ArchiveName(), imgPath)
|
||||||
title = fmt.Sprintf("[%d / %s] %s", s.ArchivePos+1, lenStr, s.ArchiveName)
|
title = fmt.Sprintf("[%d / %s] %s", s.ArchivePos+1, lenStr, s.Archive.ArchiveName())
|
||||||
}
|
}
|
||||||
app.setStatus(msg)
|
app.setStatus(msg)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue