Ejemplo n.º 1
0
Archivo: update.go Proyecto: sqp/godock
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
	app := &Applet{AppBase: base}
	app.SetConfig(&app.conf, app.actions()...)
	app.Action().SetMax(1)

	// Events
	events.OnClick = app.onClick
	events.OnMiddleClick = app.onMiddleClick
	events.OnScroll = app.onScroll
	events.OnBuildMenu = app.onBuildMenu
	events.OnDropData = app.GrepTarget

	// Create a cairo-dock sources version checker.
	app.version = versions.NewVersions(app.onGotVersions)

	// The poller will check for new versions on a timer.
	poller := app.Poller().Add(app.version.Check)

	// Set "working" emblem during version check. It should be removed or changed by the check.
	poller.SetPreCheck(func() { app.SetEmblem(app.FileLocation("img", app.conf.VersionEmblemWork), EmblemVersion) })
	poller.SetPostCheck(func() {
		for _, v := range app.version.Sources() {
			v.Log = strhelp.EscapeGtk(v.Log) // Escape <>&
		}
	})

	return app
}
Ejemplo n.º 2
0
// NewApplet create a new applet instance.
//
// It will be trigered remotely by the dock when the applet icon is created.
// Only called once for each running instance.
//
// The goal is to:
//   -Create and fill the applet struct.
//   -Set the config pointer, and maybe some actions.
//   -Register (dock to) applet events (See cdtype.Events for the full list).
//   -Declare and load permanent items required during all the applet lifetime.
//    (those who do not require a config setting, unless it's in a callback).
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
	app := &Applet{AppBase: base}
	app.SetConfig(&app.conf)

	// Events.

	// Forward click events to the defined command launcher.
	events.OnClick = app.Command().Callback(cmdClickLeft)
	events.OnMiddleClick = app.Command().Callback(cmdClickMiddle)

	// For simple callbacks event, use a closure.
	events.OnDropData = func(data string) {
		app.Log().Info("dropped", data)
	}

	events.OnBuildMenu = func(menu cdtype.Menuer) { // Another closure.
		menu.AddEntry("disabled entry", "icon-name", nil)
		menu.AddSeparator()
		menu.AddEntry("my action", "system-run", func() {
			app.Log().Info("clicked")
		})
	}

	events.OnScroll = app.myonScroll // Or use another function with the same args.

	//
	// Create and set your other permanent items here...

	return app
}
Ejemplo n.º 3
0
Archivo: audio.go Proyecto: sqp/godock
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
	app := &Applet{AppBase: base}
	app.SetConfig(&app.conf)

	// Events.
	events.OnClick = app.onClick
	events.OnMiddleClick = app.onMiddleClick
	events.OnScroll = app.onScroll
	events.OnBuildMenu = app.onBuildMenu
	events.OnSubMiddleClick = app.onSubMiddleClick
	events.OnSubScroll = app.onSubScroll
	events.OnSubBuildMenu = app.onSubBuildMenu

	// Pulseaudio service.
	log = app.Log()
	var e error
	app.pulse, e = NewAppPulse(app)
	if log.Err(e, "pulseaudio dbus") {
		return nil
	}
	return app
}
Ejemplo n.º 4
0
Archivo: TVPlay.go Proyecto: sqp/godock
// NewApplet creates a new applet instance.
//
func NewApplet(base cdtype.AppBase, events *cdtype.Events) cdtype.AppInstance {
	app := &Applet{AppBase: base}
	app.SetConfig(&app.conf, app.actions()...)

	// Events.
	events.OnClick = func() { // Left click: open and manage the gui window.
		if app.Window().IsOpened() { // Window opened.
			app.Window().ToggleVisibility()
		} else {
			app.createGui(true, true)
		}
	}

	events.OnMiddleClick = func() { app.Action().Launch(app.Action().ID(app.conf.ActionClickMiddle)) }

	events.OnScroll = func(scrollUp bool) {
		var key int
		switch app.conf.ActionMouseWheel {
		case "Change volume":
			key = ternary.Int(scrollUp, int(upnptype.ActionVolumeUp), int(upnptype.ActionVolumeDown))

		case "Seek in track":
			key = ternary.Int(scrollUp, int(upnptype.ActionSeekForward), int(upnptype.ActionSeekBackward))
		}

		app.Action().Launch(key)
	}

	events.OnBuildMenu = app.Action().CallbackMenu(dockMenu)

	events.End = func() {
		if app.win != nil {
			glib.IdleAdd(app.win.Destroy)
		}
	}

	// Create the UPnP device manager.
	var e error
	app.cp, e = gupnp.New(&logger{app.Log()})
	app.Log().Err(e, "temp Dir")

	// Connect local tests.
	hook := app.cp.SubscribeHook("applet")
	hook.OnRendererFound = app.onMediaRendererFound
	hook.OnServerFound = app.onMediaServerFound
	hook.OnRendererLost = app.onMediaRendererLost
	hook.OnServerLost = app.onMediaServerLost

	// hook.OnRendererSelected = gui.SetRenderer
	// hook.OnServerSelected = gui.SetServer

	// hook.OnTransportState = func(r upnptype.Renderer, state upnptype.PlaybackState) { gui.SetPlaybackState(state) }
	// hook.OnCurrentTrackDuration = func(r upnptype.Renderer, dur int) { gui.SetDuration(mediacp.TimeToString(dur)) }
	// hook.OnCurrentTrackMetaData = func(r upnptype.Renderer, item upnptype.Item) { gui.SetTitle(item.Title) }
	// hook.OnMute = func(r upnptype.Renderer, muted bool) { gui.SetMuted(muted) }
	// hook.OnVolume = func(r upnptype.Renderer, vol uint) { gui.SetVolume(int(vol)) }
	// hook.OnCurrentTime = func(r upnptype.Renderer, secs int, f float64) { gui.SetCurrentTime(secs, f*100) }
	// hook.OnSetVolumeDelta = func(delta int) { gui.SetVolumeDelta(delta) }
	// }

	// Connect an UPnP backend to the manager.
	// mgr := backendsonos.NewManager(&logger{app.Log()})
	// mgr.SetEvents(app.cp.DefineEvents())
	// go mgr.Start(true)

	cp := backendgupnp.NewControlPoint()
	cp.SetEvents(app.cp.DefineEvents())

	return app
}