Documentation
¶
Overview ¶
Package filechooser is the shell's dev.stubbe.lys.FileChooser1 host (lys-shell services/file_chooser and shell/file_chooser): the file dialog behind the portal backend's FileChooser.
Index ¶
- Constants
- func FilterLabel(f Filter) string
- func FormatTime(t time.Time) string
- func HumanSize(n int64) string
- func MatchesFilter(db *mime.Database, name string, filters []Filter, active int) bool
- func RecentFile() string
- func SortEntries(entries []Entry, key SortColumn, asc bool)
- func SortSearch(entries []Entry, root, query string)
- func SystemLocations(home string) func() []Place
- func SystemTrashDirs(home string) func() []string
- func TrashDirs(dataHome string, mounts []string, uid int) []string
- func VisibleMounts(mounts io.Reader, home, user string) []string
- func WalkSearch(ctx context.Context, root, query string, showHidden bool, emit func([]string)) int
- func WatchMounts(changed func()) (stop func())
- func WatchSystemLocations(changed func()) (stop func())
- type Chooser
- type Client
- type Crumb
- type Daemon
- func (d *Daemon) Dismiss(handle string) *dbus.Error
- func (d *Daemon) Export(conn *dbus.Conn) (func(), error)
- func (d *Daemon) OpenFile(c portalreq.Caller, r OpenRequest) ([]string, Filter, []portalreq.Selection, *dbus.Error)
- func (d *Daemon) SaveFile(c portalreq.Caller, r SaveRequest) ([]string, Filter, []portalreq.Selection, *dbus.Error)
- type Deps
- type Entry
- type Filter
- type Host
- type Mode
- type OpenRequest
- type Place
- type Result
- type Rule
- type SaveRequest
- type SortColumn
- type Window
Constants ¶
const ( ServiceName = "dev.stubbe.lys.FileChooser1" ServicePath = dbus.ObjectPath("/dev/stubbe/lys/FileChooser") )
D-Bus identity (wayle-ipc file_chooser.rs).
const ( RuleGlob uint32 = 0 RuleMIME uint32 = 1 )
Rule kinds of a Filter.
Variables ¶
This section is empty.
Functions ¶
func FilterLabel ¶
FilterLabel is a filter's name. Apps that want the patterns seen put them in the name; GTK's case-insensitive suffix globs (*.[pP][nN][gG]) would read as noise. Only a nameless filter shows its patterns, MIME types as their *.ext.
func FormatTime ¶
FormatTime is a modification time in local time, "" for none.
func MatchesFilter ¶
MatchesFilter reports whether name passes the active filter: no filters, an out-of-range index or an empty rule set pass everything; otherwise any one rule must match, a glob by pattern, a MIME rule against the type guessed from the name.
func RecentFile ¶
func RecentFile() string
RecentFile is the recently-used list GTK writes, $XDG_DATA_HOME/recently-used.xbel; "" without a data home.
func SortEntries ¶
func SortEntries(entries []Entry, key SortColumn, asc bool)
SortEntries orders directories first, then by the column.
func SortSearch ¶
SortSearch orders recursive hits by relevance, then by path so the order is stable.
func SystemLocations ¶
SystemLocations reads the mount table for OtherLocations, then the gvfs network shares.
func SystemTrashDirs ¶
SystemTrashDirs reads the data home and the mount table for TrashDirs: the home trash, then the user-visible mounts' trashes.
func TrashDirs ¶
TrashDirs are the trash directories of the freedesktop trash spec: the home trash under dataHome, then for each mount point its $topdir/.Trash/$uid when .Trash is a real, sticky directory, and its $topdir/.Trash-$uid.
func VisibleMounts ¶
VisibleMounts are the user-visible mount points in a /proc/self/mounts listing, each once, in its order; none for a nil listing.
func WalkSearch ¶
WalkSearch walks root depth first, handing every path whose name matches query to emit in batches as they are found, and returns the match count. Hidden entries (GTK's rule) are skipped, and their subtrees not entered, unless showHidden; symlinked directories are not entered, which keeps the walk out of loops. A cancelled ctx stops the walk, mid-directory too.
func WatchMounts ¶
func WatchMounts(changed func()) (stop func())
WatchMounts calls changed (off the loop) each time the mount table changes, until stop is called: the kernel flags /proc/self/mounts with POLLPRI on every mount and unmount, and reading it again rearms the flag. A table that cannot be watched watches nothing.
func WatchSystemLocations ¶
func WatchSystemLocations(changed func()) (stop func())
WatchSystemLocations calls changed (off the loop) whenever SystemLocations may have changed, until stop is called: a mount came or went (WatchMounts), or gvfs mounted or unmounted a share under $XDG_RUNTIME_DIR/gvfs, which the mount table does not show.
Types ¶
type Chooser ¶
type Chooser struct {
// contains filtered or unexported fields
}
Chooser is the dev.stubbe.lys.FileChooser1 host: one overlay showing one request; requests arriving meanwhile wait their turn, and dismissing a request answers it with nothing, showing or waiting. Open and Save may be called from any goroutine; the rest runs on the loop.
func (*Chooser) Dismiss ¶
Dismiss answers the request at handle with nothing: the dialog showing for it is taken down, a waiting one never shows. Another request's dialog stays.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client calls the shell's dialog; it waits on the user, so it is bounded only by ctx.
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon serves a Host as dev.stubbe.lys.FileChooser1.
func (*Daemon) Export ¶
Export serves the interface under its name; the returned release drops the name.
type Deps ¶
type Deps struct {
// Config is the live config (the chooser animation).
Config func() *config.Config
// Open maps the overlay; Invoke runs on the UI loop.
Open func(cfg app.LayerConfig) (Window, error)
Invoke func(func())
// Font shapes the text; Sheet styles the surface, the labels'
// and entries' ink included.
Font render.Font
Sheet *widget.Stylesheet
// MIME guesses types for filters and icons.
MIME *mime.Database
// Home is where a request without a folder starts and what the
// breadcrumbs shorten to Home.
Home string
// Places and Locations fill the sidebar for each request;
// WatchLocations calls changed (off the loop) whenever the
// locations may have changed (a mount came or went) until its stop
// is called; nil watches nothing.
Places, Locations func() []Place
WatchLocations func(changed func()) (stop func())
// ViewFile persists the sort and layout; "" keeps them in memory.
ViewFile string
// RecentFile is the recently-used list the Recent place lists
// (RecentFile()); "" offers no Recent.
RecentFile string
// TrashDirs are the trash directories the Trash place lists
// (SystemTrashDirs); nil offers no Trash.
TrashDirs func() []string
// Target is the output a dialog maps on (the focused one, else the
// first) with its logical size, which the sheet is centred on; false
// while none is known, when the compositor places it.
Target func() (output *app.Output, w, h int, ok bool)
}
Deps are the chooser's collaborators.
type Entry ¶
type Entry struct {
Path string
IsDir bool
Size int64
Modified time.Time
// Label is the name shown in place of the basename: a trashed
// file's original name; "" shows the basename.
Label string
}
Entry is one listed file or directory.
func ListDir ¶
ListDir lists dir in full. Only the mode rule applies here, because it cannot change while the listing is cached; the hidden toggle, the type filter and the search text partition the cached listing. A directory that cannot be read is an error.
func ListRecent ¶
ListRecent lists the recently used local files that still exist, the newest maxRecent of them; an unreadable list lists none.
func ListTrash ¶
ListTrash lists the files in each trash directory's files/, each named by the original basename its info/<name>.trashinfo records. A file without readable, well-formed info is left out (the spec's orphan), a trash directory that does not exist lists nothing, and one that cannot be read is an error naming it.
type Host ¶
type Host interface {
Open(portalreq.Caller, OpenRequest) Result
Save(portalreq.Caller, SaveRequest) Result
// Dismiss takes down the dialog showing for the request at handle.
Dismiss(handle string)
}
Host shows the dialogs; each blocks until the user answers.
type OpenRequest ¶
type OpenRequest struct {
Title string
Multiple, Directory bool
Filters []Filter
// CurrentFolder seeds the starting directory ("" is the default).
CurrentFolder string
// AcceptLabel names the confirm button ("" for the mode's own).
AcceptLabel string
// CurrentFilter is the index of the filter to start on (the
// first by default).
CurrentFilter int32
// Choices are extra questions shown with the dialog.
Choices []portalreq.Choice
}
OpenRequest is one open dialog.
type Place ¶
type Place struct {
Label, Path, Icon string
}
Place is a sidebar shortcut.
func Bookmarks ¶
Bookmarks are the local folders a GTK bookmarks file lists, one "<uri> [label]" a line, labelled by their label else their name; remote ones and folders that are gone are left out.
func NetworkLocations ¶
NetworkLocations are the network shares gvfs mounted, as its FUSE daemon shows them under runtimeDir/gvfs, one folder each named "<type>:<key>=<value>,...": labelled by share and server, else by user and host; none without gvfsd-fuse running.
func OtherLocations ¶
OtherLocations is Computer (/) plus the user-visible mounts in a /proc/self/mounts listing: what gio's volume monitor shows for unix mounts, those under /media, /run/media/<user> and the home directory (not hidden ones).
func UserPlaces ¶
UserPlaces is Home, the user directories that exist (where user-dirs.dirs puts them, under their localized names), then the GTK bookmarks.
type Result ¶
Result is what a dialog answers, (asa(sa(us))a(ss)) on the wire as three values: the chosen file:// URIs (none on a cancel or a dismissal), the filter active at the end (a nameless empty one for none), and what was picked for each choice.
type SaveRequest ¶
type SaveRequest struct {
Title string
CurrentName string
Filters []Filter
CurrentFolder string
AcceptLabel string
CurrentFilter int32
Choices []portalreq.Choice
}
SaveRequest is one save dialog.
type SortColumn ¶
type SortColumn uint8
SortColumn is a list view column.
const ( SortName SortColumn = iota SortSize SortModified SortKind )
The sortable columns.