forked from sarim/goibus
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcomponent.go
56 lines (47 loc) · 1.61 KB
/
component.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
package goibus
import (
"encoding/xml"
"fmt"
"io"
"github.com/godbus/dbus/v5"
)
type Component struct {
XMLName xml.Name `xml:"component" dbus:"-"`
Name string `xml:"-"`
Attachments map[string]dbus.Variant `xml:"-"`
ComponentName string `xml:"name"`
Description string `xml:"description"`
Version string `xml:"version"`
License string `xml:"license"`
Author string `xml:"author"`
Homepage string `xml:"homepage"`
Exec string `xml:"exec"`
Textdomain string `xml:"textdomain"`
ObservedPaths []dbus.Variant `xml:"-"`
EngineList []dbus.Variant `xml:"-"`
Engines []*EngineDesc `xml:"engines>engine" dbus:"-"`
}
func NewComponent(name string, desc string, version string, license string, author string, homepage string, exec string, textdomain string) *Component {
c := &Component{}
c.Name = "IBusComponent"
c.ComponentName = name
c.Description = desc
c.Version = version
c.License = license
c.Author = author
c.Homepage = homepage
c.Exec = exec
c.Textdomain = textdomain
return c
}
func (c *Component) AddEngine(e *EngineDesc) {
c.Engines = append(c.Engines, e)
c.EngineList = append(c.EngineList, dbus.MakeVariant(*e))
}
func (c *Component) OutputXML(w io.Writer) {
data, err := xml.MarshalIndent(c, "", " ")
if err != nil {
panic(err)
}
fmt.Fprintf(w, "%s%s\n\n%s\n", xml.Header, "<!-- Generated By github.com/sarim/goibus -->", string(data))
}