Ejemplo n.º 1
0
// Connect the applet manager to the Cairo-Dock core. Saves interfaces to the
// icon and subicon DBus interfaces and connects events callbacks.
//
func (cda *CdDbus) ConnectToBus() (e error) {
	cda.dbus, e = dbus.Connect(dbus.SessionBus)
	if e != nil {
		log.Info("DBus Connect", e)
		return e
	}
	if e = cda.dbus.Authenticate(); e != nil {
		log.Info("Failed Connection.Authenticate:", e.Error())
		return e
	}

	cda.dbusIcon = cda.dbus.Object(DbusObject, cda.BusPath).Interface(DbusInterfaceApplet)
	cda.dbusSub = cda.dbus.Object(DbusObject, cda.BusPath+"/sub_icons").Interface(DbusInterfaceSubapplet)
	if cda.dbusIcon == nil || cda.dbusSub == nil {
		return errors.New("No DBus interface")
	}

	// Connect defined events callbacks.
	typ := reflect.TypeOf(cda.Events)
	elem := reflect.ValueOf(&cda.Events).Elem()
	for i := 0; i < typ.NumField(); i++ { // Parsing all fields in type.
		cda.connectEvent(elem.Field(i), typ.Field(i))
	}
	return nil
}
Ejemplo n.º 2
0
func TestDockbus(t *testing.T) {
	args := os.Args
	show := len(args) > 1 && args[1] == "--"

	dockpath.DbusPathDock = "/org/cdc/Cdc"

	info := dockbus.InfoApplet(logger, "clock")
	if assert.NotNil(t, info, "InfoApplet") {
		assert.Equal(t, info.DisplayedName, "clock", "InfoApplet")
	}

	instances, e := dockbus.AppletInstances("clock")
	assert.NoError(t, e, "AppletInstances")
	assert.NotEmpty(t, instances, "AppletInstances, found no active instance of applet clock")

	test := "type=Module"
	props, e := dockbus.DockProperties(test)
	assert.NoError(t, e, "DockProperties")
	assert.NotEmpty(t, props, "DockProperties")

	applets, e := dockbus.ListKnownApplets(logger)
	if assert.NoError(t, e, "DockProperties") && assert.NotEmpty(t, applets, "ListKnownApplets") {
		app, ok := applets["clock"]
		if assert.True(t, ok, "ListKnownApplets field clock") {
			assert.Equal(t, app.DisplayedName, "clock", "ListKnownApplets name clock")
		}
	}

	icons := dockbus.ListIcons(logger)
	assert.NotEmpty(t, icons, "ListIcons")

	if show {
		log.Info("AppletInstances clock")
		fmt.Println(instances)

		log.Info("DockProperties", "found", len(props))
		if len(props) > 0 {
			fmt.Println("first:", props[0])
		}

		log.Info("ListKnownApplets", "found", len(applets))
		for _, app := range applets {
			fmt.Println("first:", app)
			break
		}

		log.Info("ListIcons: found", len(icons))
		if len(icons) > 0 {
			fmt.Println("first:", icons[0])
		}

		log.Info("InfoApplet clock")
		fmt.Println(info)
	}

	// dockbus.DockQuit()
}
Ejemplo n.º 3
0
// Event receiver, dispatch it to the configured callback.
//
func (cda *CdDbus) receivedMainEvent(msg *dbus.Message) {
	switch msg.Member {
	case "on_stop_module":
		if cda.Events.End != nil {
			cda.Events.End()
		}
		cda.Close <- true // Send closing signal.
	case "on_reload_module":
		go cda.Events.Reload(msg.Params[0].(bool))
	case "on_click":
		go cda.Events.OnClick() // should use msg.Params[0].(int32) ?
	case "on_middle_click":
		go cda.Events.OnMiddleClick()
	case "on_build_menu":
		go cda.Events.OnBuildMenu()
	case "on_menu_select":
		go cda.Events.OnMenuSelect(msg.Params[0].(int32))
	case "on_scroll":
		go cda.Events.OnScroll(msg.Params[0].(bool))
	case "on_drop_data":
		go cda.Events.OnDropData(msg.Params[0].(string))
	case "on_answer":
		go cda.Events.OnAnswer(msg.Params[0])
	case "on_answer_dialog":
		go cda.Events.OnAnswerDialog(msg.Params[0].(int32), msg.Params[1])
	case "on_shortkey":
		go cda.Events.OnShortkey(msg.Params[0].(string))
	case "on_change_focus":
		go cda.Events.OnChangeFocus(msg.Params[0].(bool))
	default:
		log.Info(msg.Member, msg.Params)
	}
}
Ejemplo n.º 4
0
// Add subicons by pack of 3 string : label, icon, id.
//
func (cda *CdDbus) AddSubIcon(fields []string) error {
	for i := 0; i < len(fields)/3; i++ {
		log.Info("icon:", fields[3*i+2])
		id := fields[3*i+2]
		cda.Icons[id] = &SubIcon{cda.dbus, cda.dbusSub, id}
	}
	return cda.launch(cda.dbusSub, "AddSubIcons", toInterface(reflect.ValueOf(fields)))
}
Ejemplo n.º 5
0
// Add subicons by pack of 3 string : label, icon, id.
//
func (cda *CdDbus) AddSubIcon(fields []string) error {
	for i := 0; i < len(fields)/3; i++ {
		log.Info("icon:", fields[3*i+2])
		id := fields[3*i+2]
		cda.Icons[id] = &SubIcon{cda.dbus, cda.dbusSub, id}
	}
	return cda.dbusAction(cda.dbusSub, "AddSubIcons", strings2interface(fields))
}
Ejemplo n.º 6
0
func onResult(t *testing.T) func(uptoshare.Links) {
	return func(links uptoshare.Links) {
		if !assert.NotEmpty(t, links, "links ") {
			return
		}
		e, ok := links["error"]
		assert.False(t, ok, "upload error:"+e)

		fmt.Println(links["link"])
		link, ok := links["link"]
		assert.True(t, ok, "links[link] missing")
		assert.NotEmpty(t, link, "links[link]")

		log.Info("links", links)
	}
}
Ejemplo n.º 7
0
// HaveMonitor gives informations about the state of the monitored application.
// Those are usefull is this option is enabled. A monitored application, if
// opened, is supposed to have its visibility state toggled by the user event.
//
//  haveApp: true if the monitored application is opened. (Xid > 0)
//  HaveFocus: true if the monitored application is the one with the focus.
//
func (cda *CDApplet) HaveMonitor() (haveApp bool, haveFocus bool) {
	Xid, e := cda.Get("Xid")
	log.Err(e, "Xid")

	log.Info("xid", Xid)

	if id, ok := Xid.(int64); ok {
		haveApp = id > 0
	}
	HasFocus, _ := cda.Get("has_focus")
	return haveApp, HasFocus.(bool)

	// d, e :=
	// cda.GetAll()
	// log.Info("all", d, e)
	// log.Err(e, "Got Monitor")
	// return d.Xid > 0, d.HasFocus
}
Ejemplo n.º 8
0
func (h *GameHub) Run() {
	log.SetPrefix("GameHub")
	log.SetDebug(true)
	log.Info("Started GameHub")

	h.createDemoRooms()

	//InitTest()
	h.TestQuiz()

	for {
		select {

		// Player entered lobby.
		case p := <-h.register:
			h.players[p.id] = p
			h.connections[p.conn] = true
			h.lobby.addPlayer(p)
			log.Debug("Added Player " + p.id)

		// Player exited website.
		case p := <-h.unregister:
			delete(h.players, p.id)
			delete(h.connections, p.conn)
			close(p.conn.send)
			log.Debug("Player " + p.id + " exited")

		// Distribute broadcast messages to all connections.
		case m := <-h.broadcast:
			if h.handleMessage(m) != true {
				for c := range h.connections {
					select {
					case c.send <- m:
					default:
						delete(h.connections, c)
						close(c.send)
						go c.ws.Close()
					}
				}
			}
		}
	}
}
Ejemplo n.º 9
0
// Mail count changed. Check if we need to warn the user.
//
func (app *AppletGmail) sendAlert(delta int) {
	if app.conf.AlertDialogEnabled {
		// TODO: need use  min
		app.mailPopup(app.conf.AlertDialogMaxNbMail, true)
	}
	if app.conf.AlertAnimName != "" {
		app.Animate(app.conf.AlertAnimName, int32(app.conf.AlertAnimDuration))
	}
	if app.conf.AlertSoundEnabled {
		sound := app.conf.AlertSoundFile
		if len(sound) == 0 {
			log.Info("No sound file configured")
			return
		}
		if !filepath.IsAbs(sound) && sound[0] != []byte("~")[0] { // Check for relative path.
			sound = app.FileLocation(sound)
		}

		log.Err(exec.Command("paplay", sound).Start(), "Play sound")
		// if e := exec.Command("paplay", sound).Start(); e != nil {
		//~ exec.Command("aplay", sound).Start()
		// }
	}
}