Example #1
0
File: editui.go Project: sqp/godock
// SetField sets the current field number.
//
func (ed *Editor) SetField(id int) int {
	ed.fields.Items = make([]string, len(fields))
	for i, str := range fields {
		ed.fields.Items[i] = str
	}
	// Highlight selected.
	id = ternary.Max(1, ternary.Min(id, len(ed.fields.Items)-1))
	ed.fields.Items[id] = "[" + ed.fields.Items[id] + "](fg-white,bg-blue)"
	return id
}
Example #2
0
File: editui.go Project: sqp/godock
// SetPack sets the current package number.
//
func (ed *Editor) SetPack(appID int) int {
	appID = ternary.Max(0, ternary.Min(appID, len(ed.packs)-1))

	var names []string
	for _, pack := range ed.packs {
		names = append(names, pack.DisplayedName)
	}
	names[appID] = "[" + names[appID] + "](fg-white,bg-blue)"

	ed.applets.Items = names

	ed.showPack(appID)
	return appID
}
Example #3
0
func (ed *Editor) setInt(field, delta, def, min, max int) {
	val := -1
	old, ok := ed.edits[field]
	if ok {
		val = old.(int) + delta
		if val == def {
			delete(ed.edits, field)
			return
		}
	} else {
		val = def + delta
	}
	ed.edits[field] = ternary.Max(min, ternary.Min(val, max))
}
Example #4
0
File: editui.go Project: sqp/godock
func (ed *Editor) showPack(appID int) {
	appID = ternary.Max(0, ternary.Min(appID, len(ed.packs)-1))
	pack := ed.packs[appID]
	catstr, _ := packages.FormatCategory(pack.Category)

	ed.appinfo.BorderLabel = pack.Path
	ed.appinfo.Items = []string{
		"",
		pack.DisplayedName,
		pack.Author,
		pack.Version,
		strconv.Itoa(pack.Category) + " : " + catstr,
		formatBool(pack.ActAsLauncher),
		formatBool(pack.IsMultiInstance),
	}

	ed.locked.Text = "this\nis\ndetails"

	ed.desc.Text = strings.Replace(pack.Description, "\\n", "\n", -1)

	// Update edited fields.
	for k, v := range ed.edits {
		switch k {
		case fieldVersion:
			ed.appinfo.Items[k], _ = packages.FormatNewVersion(pack.Version, v.(int))
			switch v.(int) {
			case 2:
				ed.appinfo.Items[k] = "[" + ed.appinfo.Items[k] + "](fg-magenta)"
				continue

			case 3:
				ed.appinfo.Items[k] = "[" + ed.appinfo.Items[k] + "](fg-red)"
				continue
			}

		case fieldCategory:
			catstr, _ := packages.FormatCategory(v.(int))
			ed.appinfo.Items[k] = strconv.Itoa(v.(int)) + " : " + catstr

		case fieldActAsLauncher, fieldMultiInstance:
			ed.appinfo.Items[k] = formatBool(v.(bool))
		}

		// Add color to field to indicate it's modified.
		ed.appinfo.Items[k] = "[" + ed.appinfo.Items[k] + "](fg-green)"
	}
}
Example #5
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 *Applet) mailPopup(nb, duration int, templateFunc string) {
	// feed := app.data.Data().(*Feed)
	feed := app.data.(*Feed)

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

	// if app.conf.DialogType == dialogInternal {
	text, e := app.conf.DialogTemplate.ToString(templateFunc, feed)
	if app.Log().Err(e, "Template ListMailsNew") {
		return
	}

	e = app.PopupDialog(cdtype.DialogData{
		Message:    strings.TrimRight(text, "\n"), // Remove last EOL if any (from template range).
		TimeLength: duration,
		UseMarkup:  true,
		Buttons:    "document-open;cancel",
		Callback:   cdtype.DialogCallbackValidNoArg(app.Action().Callback(ActionOpenClient)), // Open mail client if the user press the 1st button.
	})
	app.Log().Err(e, "popup")

	// } else {
	// 	if nb == 1 {
	// 		app.Log().Err(popUp(feed.Mail[0].AuthorName, feed.Mail[0].Title, app.FileLocation("icon"), app.conf.DialogTimer*1000), "libnotify")
	// 	} else {
	// 		title, eTit := app.ExecuteTemplate(DialogTemplate, "TitleCount", feed)
	// 		app.Log().Err(eTit, "Template TitleCount")
	// 		text, eTxt := app.ExecuteTemplate(DialogTemplate, "ListMails", feed)
	// 		app.Log().Err(eTxt, "Template ListMails")
	// 		app.Log().Err(popUp(title, text, app.FileLocation("icon"), app.conf.DialogTimer*1000), "Libnotify")
	// 	}
	// }

	// app.PopUp("Gmail", text)

	return
}
Example #6
0
func (ed *Editor) setVersion(delta int) {
	var val int
	old, ok := ed.edits[fieldVersion]
	switch {
	case ok:
		val = old.(int) + delta
		if val <= 0 {
			delete(ed.edits, fieldVersion)
			return
		}

	case delta < 1:
		return

	default:
		val = delta
	}
	ed.edits[fieldVersion] = ternary.Min(val, 3)
}
Example #7
0
// Mail count changed. Check if we need to warn the user.
//
func (app *Applet) sendAlert(delta int) {
	if app.conf.AlertDialogEnabled {
		nb := ternary.Min(delta, app.conf.DialogNbMail)
		app.mailPopup(nb, app.conf.DialogTimer, "ListMailsNew")
	}
	if app.conf.AlertAnimName != "" {
		app.Animate(app.conf.AlertAnimName, app.conf.AlertAnimDuration)
	}
	if app.conf.AlertSoundEnabled {
		sound := app.conf.AlertSoundFile
		if len(sound) == 0 {
			app.Log().Info("No sound file configured")
			return
		}
		if !filepath.IsAbs(sound) && sound[0] != []byte("~")[0] { // Check for relative path.
			sound = app.FileLocation(sound)
		}

		app.Log().ExecAsync("paplay", sound)
		// if e := exec.Command("paplay", sound).Start(); e != nil {
		//~ exec.Command("aplay", sound).Start()
		// }
	}
}