gnometimed

package
v0.0.0-...-389cf96 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2024 License: BSD-3-Clause Imports: 16 Imported by: 0

README

gnometimed

Package for dealing with GNOME Timed Wallpaper XML files

Version: 2.0.1

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultEventLoopDelay = 30 * time.Second

Functions

func CommonPrefix

func CommonPrefix(sl []string) string

CommonPrefix will find the longest common prefix in a slice of strings

func CommonSuffix

func CommonSuffix(sl []string) string

CommonSuffix will find the longest common suffix in a slice of strings

func GnomeFileToSimpleString

func GnomeFileToSimpleString(filename string) (string, error)

GnomeFileToSimpleString reads and parses an XML file, then returns a string representing the contents of a Simple Timed Wallpaper file.

func GnomeToSimple

func GnomeToSimple(gtw *Wallpaper) (*simpletimed.Wallpaper, error)

GnomeToSimple converts a Gnome Timed Wallpaper to a Simple Timed Wallpaper

func GnomeToSimpleString

func GnomeToSimpleString(gtw *Wallpaper) (string, error)

GnomeToSimpleString converts a Gnome Timed Wallpaper to a string representing a Simple Timed Wallpaper. The Path field in the given struct is not included in the output string.

func Meat

func Meat(s, prefix, suffix string) string

Meat returns the meat of the string: the part that is after the prefix and before the suffix. Will return the given string if it is too short to contain the prefix and suffix.

Types

type GBackground

type GBackground struct {
	XMLName     xml.Name      `xml:"background"`
	StartTime   GStartTime    `xml:"starttime"`
	Statics     []GStatic     `xml:"static"`
	Transitions []GTransition `xml:"transition"`
	// contains filtered or unexported fields
}

func (*GBackground) Get

func (gb *GBackground) Get(i int) (interface{}, error)

Get either a GStatic or a GTransition, given a total position. Will return nil and an error if nothing is found.

func (*GBackground) StaticOrder

func (gb *GBackground) StaticOrder(i int) (int, error)

StaticOrder finds the total position of a given GStatic position

func (*GBackground) String

func (gb *GBackground) String() string

func (*GBackground) TransitionOrder

func (gb *GBackground) TransitionOrder(i int) (int, error)

TransitionOrder finds the total position of a given GTransition position

type GStartTime

type GStartTime struct {
	XMLName xml.Name `xml:"starttime"`
	Year    int      `xml:"year"`
	Month   int      `xml:"month"`
	Day     int      `xml:"day"`
	Hour    int      `xml:"hour"`
	Minute  int      `xml:"minute"`
	Second  int      `xml:"second"`
}

type GStatic

type GStatic struct {
	XMLName  xml.Name `xml:"static"`
	Seconds  float64  `xml:"duration"`
	Filename string   `xml:"file"`
}

func (*GStatic) Duration

func (s *GStatic) Duration() time.Duration

Duration returns how long a static wallpaper should last

type GTransition

type GTransition struct {
	XMLName      xml.Name `xml:"transition"`
	Type         string   `xml:"type,attr,omitempty"`
	Seconds      float64  `xml:"duration"`
	FromFilename string   `xml:"from"`
	ToFilename   string   `xml:"to"`
}

func (*GTransition) Duration

func (t *GTransition) Duration() time.Duration

Duration returns how long a transition should last

type StaticMap

type StaticMap map[int]int

type TransitionMap

type TransitionMap map[int]int

type Wallpaper

type Wallpaper struct {
	// The name of this timed wallpaper
	Name string

	// Path is the full path to the XML file
	Path string

	// Config contains the parsed XML. See: gnomexml.go
	Config *GBackground

	// LoopWait is for how long the event loop should sleep at every iteration
	LoopWait time.Duration
}

func NewWallpaper

func NewWallpaper(name string, path string, config *GBackground) *Wallpaper

func ParseXML

func ParseXML(filename string) (*Wallpaper, error)

ParseXML will try to parse a Gnome XML file into a Wallpaper struct

Example
gtw, err := ParseXML("testdata/example1.xml")
if err != nil {
	panic(err)
}
fmt.Println(gtw.Config.StartTime.Year)
fmt.Println(gtw.Config.Transitions[0].ToFilename)

gtw, err = ParseXML("testdata/example2.xml")
if err != nil {
	panic(err)
}
fmt.Println(gtw.Config.StartTime.Year)

gtw, err = ParseXML("testdata/adwaita-timed.xml")
if err != nil {
	panic(err)
}
fmt.Println(gtw.Config.StartTime.Year)

gtw, err = ParseXML("testdata/generated.xml")
if err != nil {
	panic(err)
}
fmt.Println(gtw.Config.StartTime.Year)
Output:

2009
/usr/share/backgrounds/cosmos/comet.jpg
0
2011
2018

func (*Wallpaper) EventLoop

func (gtw *Wallpaper) EventLoop(verbose bool, setWallpaperFunc func(string) error, tempImageFilename string) error

EventLoop will start the event loop for this GNOME Timed Wallpaper

func (*Wallpaper) Images

func (gtw *Wallpaper) Images() []string

func (*Wallpaper) StartTime

func (gtw *Wallpaper) StartTime() time.Time

StartTime returns the timed wallpaper start time, as a time.Time

func (*Wallpaper) String

func (gtw *Wallpaper) String() string

String builds a string with various information about this GNOME timed wallpaper

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL