Exemplo n.º 1
0
// PopupDialog open a dialog box . See cdtype.AppIcon.
//
func (cda *CDDbus) PopupDialog(data cdtype.DialogData) error {
	dialog := map[string]interface{}{
		"message":     data.Message,
		"icon":        data.Icon,
		"time-length": int32(data.TimeLength),
		"force-above": data.ForceAbove,
		"use-markup":  data.UseMarkup,
		"buttons":     data.Buttons,
	}

	var widget map[string]interface{}
	switch dw := data.Widget.(type) {

	case cdtype.DialogWidgetText:
		widget = map[string]interface{}{
			"widget-type":   "text-entry",
			"multi-lines":   dw.MultiLines,
			"editable":      !dw.Locked,
			"visible":       !dw.Hidden,
			"nb-chars":      int32(dw.NbChars),
			"initial-value": dw.InitialValue,
		}

	case cdtype.DialogWidgetScale:
		widget = map[string]interface{}{
			"widget-type":   "scale",
			"min-value":     dw.MinValue,
			"max-value":     dw.MaxValue,
			"nb-digit":      int32(dw.NbDigit),
			"initial-value": dw.InitialValue,
			"min-label":     dw.MinLabel,
			"max-label":     dw.MaxLabel,
		}

	case cdtype.DialogWidgetList:
		widget = map[string]interface{}{
			"widget-type": "list",
			"editable":    dw.Editable,
			"values":      strings.Join(dw.Values, ";"),
		}

		// Recast interface to real type so it won't crash in ToMapVariant.
		switch v := dw.InitialValue.(type) {
		case int32, string:
			widget["initial-value"] = v
			// case int:
			// 	widget["initial-value"] = int32(v)
		}

	default:
		widget = make(map[string]interface{})
	}
	cda.dialogCall = data.Callback

	return cda.dbusIcon.Call("PopupDialog", dbuscommon.ToMapVariant(dialog), dbuscommon.ToMapVariant(widget))
}
Exemplo n.º 2
0
// AddMenuItems adds a list of items to the menu triggered by OnBuildMenu.
//
func (cda *CDDbus) AddMenuItems(items ...map[string]interface{}) error {
	var data []map[string]dbus.Variant
	for _, interf := range items {
		data = append(data, dbuscommon.ToMapVariant(interf))
	}

	return cda.dbusIcon.Call("AddMenuItems", data)
}
Exemplo n.º 3
0
func dockAdd(args map[string]interface{}) func(*Client) error {
	return func(client *Client) error { return client.Call("Add", dbuscommon.ToMapVariant(args)) }
}