Example #1
0
// TestInit inits the test builder.
//
func TestInit(source Sourcer, file string) cftype.Grouper {
	confown.Settings.SaveEditor = ""
	confown.Settings.SaveEnabled = false

	var e error
	file, e = filepath.EvalSymlinks(file)
	if e != nil {
		println("check file", e)
		os.Exit(1)
	}

	log := &log.Log{}
	log.SetName(testLogName)

	def := file
	if filepath.Base(file) == "cairo-dock.conf" {
		def = "/usr/share/cairo-dock/cairo-dock.conf" // TODO: improve (use sourcer).
	}

	build, e := cfbuild.NewFromFile(source, log, file, def, "") // default domain.
	if log.Err(e, "load builder") {
		os.Exit(1)
	}

	build.Log().Info("config file:", file)
	return build
}
Example #2
0
// Update display callback. Receives mail check result with new messages count
// and polling error status.
//
// Update checked time and, if needed, send info or error to renderer and user
// alerts.
//
func (app *AppletGmail) updateDisplay(delta int, e error) {
	eventTime := time.Now().String()[11:19]
	label := "Checked: " + eventTime
	switch {
	case e != nil:
		label = "Update Error: " + eventTime + "\n" + e.Error() // Error time is refreshed.
		log.Err(e, "Check mail")
		if app.err == nil || e.Error() != app.err.Error() { // Error buffer, dont warn twice the same information.
			app.render.Error(e)
			app.PopUp("Mail check error", e.Error())
			app.err = e
		}

	case delta > 0:
		log.Debug("  * Count changed", delta)
		app.sendAlert(delta)

	case delta == 0:
		log.Debug("", " * no change")
	}

	switch {
	case e == nil && app.err != nil: // Error disapeared. Cleaning buffer and refresh display.
		app.render.Set(app.data.Count())
		app.err = nil

	case delta != 0: // Refresh display only if changed.
		app.render.Set(app.data.Count())
	}
	app.SetLabel(label)
}
Example #3
0
// TestPathDefault returns the first command line arg or the default test path.
// returns true if the default test file is used.
//
func TestPathDefault() (string, bool) {
	if len(os.Args) > 1 {
		newpath, e := filepath.Abs(os.Args[1])
		log.Err(e, "filepath.Abs")
		return newpath, false
	}
	return PathTestConf(), true
}
Example #4
0
// Load template files. If error, it will just be be logged, so you must check
// that the template is valid. Map entry will still be created, just check it
// isn't nil. *CDapplet.ExecuteTemplate does it for you.
//
// Templates must be in a subdir called templates in applet dir. If you really
// need a way to change this, ask for a new method.
//
func (cda *CDApplet) LoadTemplate(names ...string) {
	for _, name := range names {
		fileloc := cda.FileLocation("templates", name+".tmpl")
		template, e := template.ParseFiles(fileloc)
		log.Err(e, "Template")
		cda.Templates[name] = template
	}
}
Example #5
0
// Execute a pre-loaded template with given data.
//
func (cda *CDApplet) ExecuteTemplate(name string, data interface{}) (string, error) {
	if cda.Templates[name] == nil {
		return "", fmt.Errorf("Missing template %s", name)
	}

	buff := bytes.NewBuffer([]byte(""))
	log.Err(cda.Templates[name].ExecuteTemplate(buff, name, data), "FormatDialog")
	return buff.String(), nil
}
Example #6
0
// Open a popup on the configured notification systme. Valid options are internal
// or libnotify.
//
func (app *AppletGmail) PopUp(title, msg string) {
	if app.conf.DialogType == dialogInternal {
		app.ShowDialog(msg, int32(app.conf.DialogTimer))
	} else {
		var e error
		if popUp == nil {
			e = errors.New("Applet was compiled with library support disabled")
		} else {
			e = popUp(title, msg, app.FileLocation("icon"), app.conf.DialogTimer*1000)
			//~ DEBUG("notify", e==nil, e)
		}
		log.Err(e, "libnotify")
	}
}
Example #7
0
// Show dialog with information for the given number of mails. Can display an
// additional comment about mails being new if the second param is set to true.
//
func (app *AppletGmail) mailPopup(nb int, new bool) {
	feed := app.data.Data().(*Feed)

	// Prepare data for template formater.
	feed.New = nb
	feed.Plural = feed.New > 1
	max := min(feed.New, len(feed.Mail))
	feed.MailsNew = make([]*Email, max)
	for i := 0; i < max; i++ {
		feed.MailsNew[i] = feed.Mail[i]
	}

	text, e := app.ExecuteTemplate("InternalDialog", feed)
	if !log.Err(e, "Template") {
		app.PopUp("Gmail", text)
	}
	return
}
Example #8
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
}
Example #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()
		// }
	}
}
Example #10
0
func testGetSet(t *testing.T, v extendedStorage, group string) {
	name := "name"

	getSet := func(v cftype.Storage, group, name string, i, o interface{}) {
		v.Set(group, name+"2", i)
		log.Err(v.Get(group, name+"2", o), "get")
	}

	ib := true
	ob := false

	getSet(v, group, name, ib, &ob)
	v.SetBool(group, name, ib)
	rb, e := v.Bool(group, name)
	log.Err(e, "get bool")
	assert.Equal(t, ib, ob, "get/set bool")
	assert.Equal(t, ib, rb, "get/set bool")

	ii := 42
	oi := 0

	getSet(v, group, name, ii, &oi)
	v.SetInt(group, name, ii)
	ri, e := v.Int(group, name)
	log.Err(e, "get int")
	assert.Equal(t, ii, oi, "get/set int")
	assert.Equal(t, ii, ri, "get/set int")

	ifl := float64(4.2)
	ofl := float64(0)

	getSet(v, group, name, ifl, &ofl)
	v.SetFloat(group, name, ifl)
	rfl, e := v.Float(group, name)
	log.Err(e, "get float64")
	assert.Equal(t, ifl, ofl, "get/set float64")
	assert.Equal(t, ifl, rfl, "get/set float64")

	is := "42"
	os := ""

	getSet(v, group, name, is, &os)
	v.SetString(group, name, is)
	rs, e := v.String(group, name)
	log.Err(e, "get string")
	assert.Equal(t, is, os, "get/set string")
	assert.Equal(t, is, rs, "get/set string")

	ilb := []bool{true, true}
	olb := []bool{}

	getSet(v, group, name, ilb, &olb)
	v.SetListBool(group, name, ilb)
	rlb, e := v.ListBool(group, name)
	log.Err(e, "get list bool")
	assert.Equal(t, ilb, olb, "get/set list bool")
	assert.Equal(t, ilb, rlb, "get/set list bool")

	ili := []int{42, -1}
	oli := []int{}

	getSet(v, group, name, ili, &oli)
	v.SetListInt(group, name, ili)
	rli, e := v.ListInt(group, name)
	log.Err(e, "get list int")
	assert.Equal(t, ili, oli, "get/set list int")
	assert.Equal(t, ili, rli, "get/set list int")

	ilfl := []float64{4.2, -5.9}
	olfl := []float64{}

	getSet(v, group, name, ilfl, &olfl)
	v.SetListFloat(group, name, ilfl)
	rlfl, e := v.ListFloat(group, name)
	log.Err(e, "get list float")
	assert.Equal(t, ilfl, olfl, "get/set list float")
	assert.Equal(t, ilfl, rlfl, "get/set list float")

	ils := []string{"42", "or", "!"}
	ols := []string{}

	getSet(v, group, name, ils, &ols)
	v.SetListString(group, name, ils)
	rls, e := v.ListString(group, name)
	log.Err(e, "get list string")
	assert.Equal(t, ils, ols, "get/set list string")
	assert.Equal(t, ils, rls, "get/set list string")
}
Example #11
0
func testValuerToBoth(t *testing.T, conf cftype.Storage, group string) {
	ii := 42
	ib := true
	it := float64(4.2)
	is := "42"
	ili := []int{42, -1}
	ilb := []bool{true, true}
	ilf := []float64{4.2, -5.9}
	ils := []string{"42", "or", "!"}

	vi := conf.Valuer(group, "int").(extendedValuer)
	vb := conf.Valuer(group, "bool").(extendedValuer)
	vf := conf.Valuer(group, "float").(extendedValuer)
	vs := conf.Valuer(group, "string").(extendedValuer)
	vli := conf.Valuer(group, "listint").(extendedValuer)
	vlb := conf.Valuer(group, "listbool").(extendedValuer)
	vlf := conf.Valuer(group, "listfloat").(extendedValuer)
	vls := conf.Valuer(group, "liststring").(extendedValuer)

	// Set from Valuer.

	vi.Set(ii)
	vb.Set(ib)
	vf.Set(it)
	vs.Set(is)
	vli.Set(ili)
	vlb.Set(ilb)
	vlf.Set(ilf)
	vls.Set(ils)

	// Test get from Valuer.

	assert.Equal(t, ii, vi.Int(), "get Valuer int")
	assert.Equal(t, ib, vb.Bool(), "get Valuer bool")
	assert.Equal(t, it, vf.Float(), "get Valuer float64")
	assert.Equal(t, is, vs.String(), "get Valuer string")
	assert.Equal(t, ili, vli.ListInt(), "get Valuer list int")
	assert.Equal(t, ilb, vlb.ListBool(), "get Valuer list bool")
	assert.Equal(t, ilf, vlf.ListFloat(), "get Valuer list float")
	assert.Equal(t, ils, vls.ListString(), "get Valuer list string")

	// Test get from Source with pointer.

	ob := false
	oi := 0
	ot := float64(0)
	os := ""
	olb := []bool{}
	oli := []int{}
	olf := []float64{}
	ols := []string{}

	log.Err(conf.Get(group, "int", &oi), "get int")
	log.Err(conf.Get(group, "bool", &ob), "get bool")
	log.Err(conf.Get(group, "float", &ot), "get float")
	log.Err(conf.Get(group, "string", &os), "get string")
	log.Err(conf.Get(group, "listint", &oli), "get listint")
	log.Err(conf.Get(group, "listbool", &olb), "get listbool")
	log.Err(conf.Get(group, "listfloat", &olf), "get listfloat")
	log.Err(conf.Get(group, "liststring", &ols), "get liststring")

	assert.Equal(t, ii, oi, "get Source Get int")
	assert.Equal(t, ib, ob, "get Source Get bool")
	assert.Equal(t, it, ot, "get Source Get float64")
	assert.Equal(t, is, os, "get Source Get string")
	assert.Equal(t, ilb, olb, "get Source Get list bool")
	assert.Equal(t, ili, oli, "get Source Get list int")
	assert.Equal(t, ilf, olf, "get Source Get list float")
	assert.Equal(t, ils, ols, "get Source Get list string")

	// Test get from Source directly.

	oi, _ = conf.Int(group, "int")
	ob, _ = conf.Bool(group, "bool")
	ot, _ = conf.Float(group, "float")
	os, _ = conf.String(group, "string")
	olb, _ = conf.ListBool(group, "listbool")
	oli, _ = conf.ListInt(group, "listint")
	olf, _ = conf.ListFloat(group, "listfloat")
	ols, _ = conf.ListString(group, "liststring")

	assert.Equal(t, ii, oi, "get Source fields int")
	assert.Equal(t, ib, ob, "get Source fields bool")
	assert.Equal(t, it, ot, "get Source fields float64")
	assert.Equal(t, is, os, "get Source fields string")
	assert.Equal(t, ili, oli, "get Source fields list int")
	assert.Equal(t, ilb, olb, "get Source fields list bool")
	assert.Equal(t, ilf, olf, "get Source fields list float")
	assert.Equal(t, ils, ols, "get Source fields list string")

}