-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathalbum.go
108 lines (89 loc) · 2.77 KB
/
album.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (C) 2020 David Vogel
//
// This file is part of Galago.
//
// Galago is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// Galago is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Galago. If not, see <http://www.gnu.org/licenses/>.
package main
import "fmt"
// Album can contain other elements
type Album struct {
name, urlName string
parent Element
index int
children []Element
}
// Compile time check if Album implements Element.
var _ Element = (*Album)(nil)
// Clone returns a clone with the given parent and index set
func (a *Album) Clone(parent Element, index int) Element {
clone := *a
clone.parent = parent
clone.index = index
return &clone
}
// Parent returns the parent element, duh.
func (a *Album) Parent() Element {
return a.parent
}
// Index returns the index of the element in its parent children list.
func (a *Album) Index() int {
return a.index
}
// Children returns the content of the album.
func (a *Album) Children() ([]Element, error) {
return a.children, nil
}
// Path returns the absolute path of the element, but not the filesystem path.
// For details see ElementPath.
func (a *Album) Path() string {
return ElementPath(a)
}
// IsContainer returns whether an element can contain other elements or not.
func (a *Album) IsContainer() bool {
return true
}
// IsHidden returns whether this element can be listed as child or not.
func (a *Album) IsHidden() bool {
return false
}
// IsHome returns whether an element should be linked by the home button or not.
func (a *Album) IsHome() bool {
return false
}
// Name returns the name that is shown to the user.
func (a *Album) Name() string {
return a.name
}
// URLName returns the name/identifier that is used in URLs.
func (a *Album) URLName() string {
return a.urlName
}
// Traverse the element's children with the given path.
func (a *Album) Traverse(path string) (Element, error) {
return TraverseElements(a, path)
}
func (a *Album) String() string {
return fmt.Sprintf("{Album %q: %v children}", a.Path(), len(a.children))
}
// FilterAlbums takes a list of elements, and returns only the albums.
// The content of the albums stays untouched.
func FilterAlbums(ee []Element) []*Album {
result := []*Album{}
for _, element := range ee {
if album, ok := element.(*Album); ok {
result = append(result, album)
}
}
return result
}