Ejemplo n.º 1
0
func updateHostnameProperty(object dbus.BusObject, expectedValue, property, setterName string, apply bool) (checkOK bool, err error) {
	propertyObject, err := object.GetProperty("org.freedesktop.hostname1." + property)
	if err != nil {
		return false, errwrap.Wrapf(err, "failed to get org.freedesktop.hostname1.%s", property)
	}
	if propertyObject.Value() == nil {
		return false, errwrap.Errorf("Unexpected nil value received when reading property %s", property)
	}

	propertyValue, ok := propertyObject.Value().(string)
	if !ok {
		return false, fmt.Errorf("Received unexpected type as %s value, expected string got '%T'", property, propertyValue)
	}

	// expected value and actual value match => checkOk
	if propertyValue == expectedValue {
		return true, nil
	}

	// nothing to do anymore
	if !apply {
		return false, nil
	}

	// attempting to apply the changes
	log.Printf("Changing %s: %s => %s", property, propertyValue, expectedValue)
	if err := object.Call("org.freedesktop.hostname1."+setterName, 0, expectedValue, false).Err; err != nil {
		return false, errwrap.Wrapf(err, "failed to call org.freedesktop.hostname1.%s", setterName)
	}

	// all good changes should now be applied again
	return false, nil
}
Ejemplo n.º 2
0
func PrintStatus(obj dbus.BusObject) {
	title, err := obj.GetProperty(bus_interface + ".TrackTitle")
	if err != nil {
		log.Fatalf("Could not retrieve property: %s", err)
	}

	state, err := obj.GetProperty(bus_interface + ".PlaybackStatus")
	if err != nil {
		log.Fatalf("Could not retrieve property: %s", err)
	}

	metadata, err := obj.GetProperty(bus_interface + ".TrackMetadata")
	if err != nil {
		log.Fatalf("Could not retrieve property: %s", err)
	}

	length, err := obj.GetProperty(bus_interface + ".TrackLength")
	if err != nil {
		log.Fatalf("Could not retrieve property: %s", err)
	}

	var pos, percent float64
	obj.Call(bus_interface+".TrackPosition", 0).Store(&pos, &percent)

	loop, err := obj.GetProperty(bus_interface + ".LoopStatus")
	if err != nil {
		log.Fatalf("Could not retrieve property: %s", err)
	}

	log.Printf("Title: %s\n", title.Value().(string))

	log.Printf("Tags:\n")

	for key, val := range metadata.Value().(map[string]string) {
		log.Printf(" %s: %s\n", key, val)
	}

	pos_time := time.Duration(int64(pos)) * time.Second
	len_time := time.Duration(int64(length.Value().(float64))) * time.Second

	log.Printf(
		"[%s]   %s/%s   (%.f%%)\n",
		state.Value().(string), pos_time.String(), len_time.String(),
		percent,
	)

	log.Printf("loop: %s\n", loop.Value().(string))
}
Ejemplo n.º 3
0
func PrintList(obj dbus.BusObject) {
	files, err := obj.GetProperty(bus_interface + ".Tracks")
	if err != nil {
		log.Fatalf("Could not retrieve property: %s", err)
	}

	current, _ := obj.GetProperty(bus_interface + ".TrackPath")

	for i, file := range files.Value().([]string) {
		var prefix string

		if current.Value() != nil && file == current.Value().(string) {
			prefix = "*"
		} else {
			prefix = " "
		}

		log.Printf("%s %3d:%s\n", prefix, i, file)
	}
}