/*This file is automatically generated by pkg.deepin.io/dbus-generator. Don't edit it*/
package locale1

import "pkg.deepin.io/lib/dbus"
import "pkg.deepin.io/lib/dbus/property"
import "reflect"
import "sync"
import "runtime"
import "fmt"
import "errors"

/*prevent compile error*/
var _ = fmt.Println
var _ = runtime.SetFinalizer
var _ = sync.NewCond
var _ = reflect.TypeOf
var _ = property.BaseObserver{}

type Locale1 struct {
	Path     dbus.ObjectPath
	DestName string
	core     *dbus.Object

	signals       map[<-chan *dbus.Signal]struct{}
	signalsLocker sync.Mutex

	Locale               *dbusPropertyLocale1Locale
	X11Layout            *dbusPropertyLocale1X11Layout
	X11Model             *dbusPropertyLocale1X11Model
	X11Variant           *dbusPropertyLocale1X11Variant
	X11Options           *dbusPropertyLocale1X11Options
	VConsoleKeymap       *dbusPropertyLocale1VConsoleKeymap
	VConsoleKeymapToggle *dbusPropertyLocale1VConsoleKeymapToggle
}

func (obj *Locale1) _createSignalChan() <-chan *dbus.Signal {
	obj.signalsLocker.Lock()
	ch := getBus().Signal()
	obj.signals[ch] = struct{}{}
	obj.signalsLocker.Unlock()
	return ch
}
func (obj *Locale1) _deleteSignalChan(ch <-chan *dbus.Signal) {
	obj.signalsLocker.Lock()
	delete(obj.signals, ch)
	getBus().DetachSignal(ch)
	obj.signalsLocker.Unlock()
}
func DestroyLocale1(obj *Locale1) {
	obj.signalsLocker.Lock()
	defer obj.signalsLocker.Unlock()
	if obj.signals == nil {
		return
	}
	for ch, _ := range obj.signals {
		getBus().DetachSignal(ch)
	}
	obj.signals = nil

	runtime.SetFinalizer(obj, nil)

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.DBus.Properties',sender='" + obj.DestName + "',member='PropertiesChanged'")
	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='org.freedesktop.locale1',sender='" + obj.DestName + "',member='PropertiesChanged'")

	obj.Locale.Reset()
	obj.X11Layout.Reset()
	obj.X11Model.Reset()
	obj.X11Variant.Reset()
	obj.X11Options.Reset()
	obj.VConsoleKeymap.Reset()
	obj.VConsoleKeymapToggle.Reset()
}

func (obj *Locale1) SetLocale(arg0 []string, arg1 bool) (_err error) {
	_err = obj.core.Call("org.freedesktop.locale1.SetLocale", 0, arg0, arg1).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Locale1) SetVConsoleKeyboard(arg0 string, arg1 string, arg2 bool, arg3 bool) (_err error) {
	_err = obj.core.Call("org.freedesktop.locale1.SetVConsoleKeyboard", 0, arg0, arg1, arg2, arg3).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Locale1) SetX11Keyboard(arg0 string, arg1 string, arg2 string, arg3 string, arg4 bool, arg5 bool) (_err error) {
	_err = obj.core.Call("org.freedesktop.locale1.SetX11Keyboard", 0, arg0, arg1, arg2, arg3, arg4, arg5).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

type dbusPropertyLocale1Locale struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyLocale1Locale) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.locale1.Locale is not writable")
}

func (this *dbusPropertyLocale1Locale) Get() []string {
	v, _ := this.GetValue()
	return v.([]string)
}
func (this *dbusPropertyLocale1Locale) GetValue() (interface{} /*[]string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.locale1", "Locale").Store(&r)
	if err == nil && r.Signature().String() == "as" {
		return r.Value().([]string), nil
	}
	return *new([]string), err
}
func (this *dbusPropertyLocale1Locale) GetType() reflect.Type {
	return reflect.TypeOf((*[]string)(nil)).Elem()
}

type dbusPropertyLocale1X11Layout struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyLocale1X11Layout) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.locale1.X11Layout is not writable")
}

func (this *dbusPropertyLocale1X11Layout) Get() string {
	v, _ := this.GetValue()
	return v.(string)
}
func (this *dbusPropertyLocale1X11Layout) GetValue() (interface{} /*string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.locale1", "X11Layout").Store(&r)
	if err == nil && r.Signature().String() == "s" {
		return r.Value().(string), nil
	}
	return *new(string), err
}
func (this *dbusPropertyLocale1X11Layout) GetType() reflect.Type {
	return reflect.TypeOf((*string)(nil)).Elem()
}

type dbusPropertyLocale1X11Model struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyLocale1X11Model) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.locale1.X11Model is not writable")
}

func (this *dbusPropertyLocale1X11Model) Get() string {
	v, _ := this.GetValue()
	return v.(string)
}
func (this *dbusPropertyLocale1X11Model) GetValue() (interface{} /*string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.locale1", "X11Model").Store(&r)
	if err == nil && r.Signature().String() == "s" {
		return r.Value().(string), nil
	}
	return *new(string), err
}
func (this *dbusPropertyLocale1X11Model) GetType() reflect.Type {
	return reflect.TypeOf((*string)(nil)).Elem()
}

type dbusPropertyLocale1X11Variant struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyLocale1X11Variant) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.locale1.X11Variant is not writable")
}

func (this *dbusPropertyLocale1X11Variant) Get() string {
	v, _ := this.GetValue()
	return v.(string)
}
func (this *dbusPropertyLocale1X11Variant) GetValue() (interface{} /*string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.locale1", "X11Variant").Store(&r)
	if err == nil && r.Signature().String() == "s" {
		return r.Value().(string), nil
	}
	return *new(string), err
}
func (this *dbusPropertyLocale1X11Variant) GetType() reflect.Type {
	return reflect.TypeOf((*string)(nil)).Elem()
}

type dbusPropertyLocale1X11Options struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyLocale1X11Options) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.locale1.X11Options is not writable")
}

func (this *dbusPropertyLocale1X11Options) Get() string {
	v, _ := this.GetValue()
	return v.(string)
}
func (this *dbusPropertyLocale1X11Options) GetValue() (interface{} /*string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.locale1", "X11Options").Store(&r)
	if err == nil && r.Signature().String() == "s" {
		return r.Value().(string), nil
	}
	return *new(string), err
}
func (this *dbusPropertyLocale1X11Options) GetType() reflect.Type {
	return reflect.TypeOf((*string)(nil)).Elem()
}

type dbusPropertyLocale1VConsoleKeymap struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyLocale1VConsoleKeymap) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.locale1.VConsoleKeymap is not writable")
}

func (this *dbusPropertyLocale1VConsoleKeymap) Get() string {
	v, _ := this.GetValue()
	return v.(string)
}
func (this *dbusPropertyLocale1VConsoleKeymap) GetValue() (interface{} /*string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.locale1", "VConsoleKeymap").Store(&r)
	if err == nil && r.Signature().String() == "s" {
		return r.Value().(string), nil
	}
	return *new(string), err
}
func (this *dbusPropertyLocale1VConsoleKeymap) GetType() reflect.Type {
	return reflect.TypeOf((*string)(nil)).Elem()
}

type dbusPropertyLocale1VConsoleKeymapToggle struct {
	*property.BaseObserver
	core *dbus.Object
}

func (this *dbusPropertyLocale1VConsoleKeymapToggle) SetValue(notwritable interface{}) {
	fmt.Println("org.freedesktop.locale1.VConsoleKeymapToggle is not writable")
}

func (this *dbusPropertyLocale1VConsoleKeymapToggle) Get() string {
	v, _ := this.GetValue()
	return v.(string)
}
func (this *dbusPropertyLocale1VConsoleKeymapToggle) GetValue() (interface{} /*string*/, error) {
	var r dbus.Variant
	err := this.core.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.locale1", "VConsoleKeymapToggle").Store(&r)
	if err == nil && r.Signature().String() == "s" {
		return r.Value().(string), nil
	}
	return *new(string), err
}
func (this *dbusPropertyLocale1VConsoleKeymapToggle) GetType() reflect.Type {
	return reflect.TypeOf((*string)(nil)).Elem()
}

func NewLocale1(destName string, path dbus.ObjectPath) (*Locale1, error) {
	if !path.IsValid() {
		return nil, errors.New("The path of '" + string(path) + "' is invalid.")
	}

	core := getBus().Object(destName, path)

	obj := &Locale1{Path: path, DestName: destName, core: core, signals: make(map[<-chan *dbus.Signal]struct{})}

	obj.Locale = &dbusPropertyLocale1Locale{&property.BaseObserver{}, core}
	obj.X11Layout = &dbusPropertyLocale1X11Layout{&property.BaseObserver{}, core}
	obj.X11Model = &dbusPropertyLocale1X11Model{&property.BaseObserver{}, core}
	obj.X11Variant = &dbusPropertyLocale1X11Variant{&property.BaseObserver{}, core}
	obj.X11Options = &dbusPropertyLocale1X11Options{&property.BaseObserver{}, core}
	obj.VConsoleKeymap = &dbusPropertyLocale1VConsoleKeymap{&property.BaseObserver{}, core}
	obj.VConsoleKeymapToggle = &dbusPropertyLocale1VConsoleKeymapToggle{&property.BaseObserver{}, core}

	dbusAddMatch("type='signal',path='" + string(path) + "',interface='org.freedesktop.DBus.Properties',sender='" + destName + "',member='PropertiesChanged'")
	dbusAddMatch("type='signal',path='" + string(path) + "',interface='org.freedesktop.locale1',sender='" + destName + "',member='PropertiesChanged'")
	sigChan := obj._createSignalChan()
	go func() {
		typeString := reflect.TypeOf("")
		typeKeyValues := reflect.TypeOf(map[string]dbus.Variant{})
		typeArrayValues := reflect.TypeOf([]string{})
		for v := range sigChan {
			if v.Name == "org.freedesktop.DBus.Properties.PropertiesChanged" &&
				len(v.Body) == 3 &&
				reflect.TypeOf(v.Body[0]) == typeString &&
				reflect.TypeOf(v.Body[1]) == typeKeyValues &&
				reflect.TypeOf(v.Body[2]) == typeArrayValues &&
				v.Body[0].(string) == "org.freedesktop.locale1" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Locale" {
						obj.Locale.Notify()

					} else if key == "X11Layout" {
						obj.X11Layout.Notify()

					} else if key == "X11Model" {
						obj.X11Model.Notify()

					} else if key == "X11Variant" {
						obj.X11Variant.Notify()

					} else if key == "X11Options" {
						obj.X11Options.Notify()

					} else if key == "VConsoleKeymap" {
						obj.VConsoleKeymap.Notify()

					} else if key == "VConsoleKeymapToggle" {
						obj.VConsoleKeymapToggle.Notify()
					}
				}
			} else if v.Name == "org.freedesktop.locale1.PropertiesChanged" && len(v.Body) == 1 && reflect.TypeOf(v.Body[0]) == typeKeyValues {
				for key, _ := range v.Body[0].(map[string]dbus.Variant) {
					if false {
					} else if key == "Locale" {
						obj.Locale.Notify()

					} else if key == "X11Layout" {
						obj.X11Layout.Notify()

					} else if key == "X11Model" {
						obj.X11Model.Notify()

					} else if key == "X11Variant" {
						obj.X11Variant.Notify()

					} else if key == "X11Options" {
						obj.X11Options.Notify()

					} else if key == "VConsoleKeymap" {
						obj.VConsoleKeymap.Notify()

					} else if key == "VConsoleKeymapToggle" {
						obj.VConsoleKeymapToggle.Notify()
					}
				}
			}
		}
	}()

	runtime.SetFinalizer(obj, func(_obj *Locale1) { DestroyLocale1(_obj) })
	return obj, nil
}
