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

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 Entry struct {
	Path     dbus.ObjectPath
	DestName string
	core     *dbus.Object

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

	Id   *dbusPropertyEntryId
	Type *dbusPropertyEntryType
	Data *dbusPropertyEntryData
}

func (obj *Entry) _createSignalChan() <-chan *dbus.Signal {
	obj.signalsLocker.Lock()
	ch := getBus().Signal()
	obj.signals[ch] = struct{}{}
	obj.signalsLocker.Unlock()
	return ch
}
func (obj *Entry) _deleteSignalChan(ch <-chan *dbus.Signal) {
	obj.signalsLocker.Lock()
	delete(obj.signals, ch)
	getBus().DetachSignal(ch)
	obj.signalsLocker.Unlock()
}
func DestroyEntry(obj *Entry) {
	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='dde.dock.Entry',sender='" + obj.DestName + "',member='PropertiesChanged'")

	dbusRemoveMatch("type='signal',path='" + string(obj.Path) + "',interface='dde.dock.Entry',sender='" + obj.DestName + "',member='DataChanged'")

	obj.Id.Reset()
	obj.Type.Reset()
	obj.Data.Reset()
}

func (obj *Entry) ShowQuickWindow() (_err error) {
	_err = obj.core.Call("dde.dock.Entry.ShowQuickWindow", 0).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Entry) Activate(x int32, y int32) (_err error) {
	_err = obj.core.Call("dde.dock.Entry.Activate", 0, x, y).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Entry) SecondaryActivate(x int32, y int32) (_err error) {
	_err = obj.core.Call("dde.dock.Entry.SecondaryActivate", 0, x, y).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Entry) ContextMenu(x int32, y int32) (_err error) {
	_err = obj.core.Call("dde.dock.Entry.ContextMenu", 0, x, y).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Entry) HandleMenuItem(id string) (_err error) {
	_err = obj.core.Call("dde.dock.Entry.HandleMenuItem", 0, id).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Entry) HandleDragDrop(x int32, y int32, data string) (_err error) {
	_err = obj.core.Call("dde.dock.Entry.HandleDragDrop", 0, x, y, data).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Entry) HandleDragEnter(x int32, y int32, data string) (_err error) {
	_err = obj.core.Call("dde.dock.Entry.HandleDragEnter", 0, x, y, data).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Entry) HandleDragLeave(x int32, y int32, data string) (_err error) {
	_err = obj.core.Call("dde.dock.Entry.HandleDragLeave", 0, x, y, data).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Entry) HandleDragOver(x int32, y int32, data string) (_err error) {
	_err = obj.core.Call("dde.dock.Entry.HandleDragOver", 0, x, y, data).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Entry) HandleMouseWheel(x int32, y int32, angleDelta int32) (_err error) {
	_err = obj.core.Call("dde.dock.Entry.HandleMouseWheel", 0, x, y, angleDelta).Store()
	if _err != nil {
		fmt.Println(_err)
	}
	return
}

func (obj *Entry) ConnectDataChanged(callback func(arg0 string, arg1 string)) func() {
	sigChan := obj._createSignalChan()
	go func() {
		for v := range sigChan {
			if v.Path != obj.Path || v.Name != "dde.dock.Entry.DataChanged" || 2 != len(v.Body) {
				continue
			}
			if reflect.TypeOf(v.Body[0]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}
			if reflect.TypeOf(v.Body[1]) != reflect.TypeOf((*string)(nil)).Elem() {
				continue
			}

			callback(v.Body[0].(string), v.Body[1].(string))
		}
	}()
	return func() {
		obj._deleteSignalChan(sigChan)
	}
}

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

func (this *dbusPropertyEntryId) SetValue(notwritable interface{}) {
	fmt.Println("dde.dock.Entry.Id is not writable")
}

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

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

func (this *dbusPropertyEntryType) SetValue(notwritable interface{}) {
	fmt.Println("dde.dock.Entry.Type is not writable")
}

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

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

func (this *dbusPropertyEntryData) SetValue(notwritable interface{}) {
	fmt.Println("dde.dock.Entry.Data is not writable")
}

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

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

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

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

	obj.Id = &dbusPropertyEntryId{&property.BaseObserver{}, core}
	obj.Type = &dbusPropertyEntryType{&property.BaseObserver{}, core}
	obj.Data = &dbusPropertyEntryData{&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='dde.dock.Entry',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) == "dde.dock.Entry" {
				props := v.Body[1].(map[string]dbus.Variant)
				for key, _ := range props {
					if false {
					} else if key == "Id" {
						obj.Id.Notify()

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

					} else if key == "Data" {
						obj.Data.Notify()
					}
				}
			} else if v.Name == "dde.dock.Entry.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 == "Id" {
						obj.Id.Notify()

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

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

	dbusAddMatch("type='signal',path='" + string(obj.Path) + "',interface='dde.dock.Entry',sender='" + obj.DestName + "',member='DataChanged'")

	runtime.SetFinalizer(obj, func(_obj *Entry) { DestroyEntry(_obj) })
	return obj, nil
}
