コード例 #1
0
ファイル: welcome.go プロジェクト: sqp/godock
// New creates a welcome widget with informations about the program.
//
func New(source cftype.Source, log cdtype.Logger) cftype.Grouper {
	const group = "Welcome"
	title := tran.Slate("Welcome to cairo-dock-rework")
	header := tran.Slate(`This is a reworked version of cairo-dock, with all the user interface rewritten in Go.
It's still under development, but should now be very close to the original version.`)
	warningSave := `Warning, save configuration is disabled by default.
As it shares its files with the original dock, it requires more tests to ensure nothing will be broken.
It's better to save your current theme, and check nothing wrong will be changed in your files.
Then, you can enable the save option under the "GUI Settings" config tab, at your own risks.`

	keys := []*cftype.Key{
		newkey.TextLabel(group, "title", common.Bold(common.Big(title))),
		newkey.TextLabel(group, "header", header),
		newkey.Separator(group, "sep_title"),
		newkey.TextLabel(group, "warningSave", warningSave),
		newkey.Separator(group, "sep_warning"),
		newkey.Link(group, "URLwebsite", "Project website", "github", URLwebsite),
		newkey.Link(group, "URLdocumentation", "Documentation", "godoc", URLdocumentation),
		newkey.Link(group, "URLdockInfo", "Cairo-Dock forum related thread", "glx-dock forum", URLdockInfo),
	}
	for _, link := range links {
		str := common.Big(common.Bold(common.URI(link.URL, link.Title)))
		keys = append(keys,
			// newkey.Frame(group, "F_"+title, str, link.Icon),
			newkey.Separator(group, "sep_"+link.Title),
			newkey.TextLabel(group, "T_"+link.Title, str),
			newkey.TextLabel(group, "L_"+link.Title, link.Text),
		)
	}

	build := cfbuild.NewVirtual(source, log, "", "", "")
	return build.BuildSingle(group, cfbuild.TweakAddGroup(group, keys...))
}
コード例 #2
0
ファイル: conficons.go プロジェクト: sqp/godock
// addBoxItem adds an item to the list.
//
func (widget *List) addBoxItem(icon datatype.Iconer, indent int, bold bool) *gtk.ListBoxRow {
	row := newgtk.ListBoxRow()
	box := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 0)
	row.Add(box)

	name, img := icon.DefaultNameIcon()

	box.Set("margin-start", 15*indent)
	if bold {
		name = common.Bold(name)
	}
	if img != "" {
		if pix, e := common.ImageNewFromFile(img, iconSize); !widget.log.Err(e, "Load icon") {
			box.PackStart(pix, false, false, 0)
		}
	}
	lbl := newgtk.Label(name)
	lbl.SetUseMarkup(true)
	box.PackStart(lbl, false, false, 0)

	widget.list.Add(row)
	widget.index[row] = icon

	return row
}
コード例 #3
0
ファイル: devpage.go プロジェクト: sqp/godock
// New creates a welcome widget with informations about the program.
//
func New(source cftype.Source, log cdtype.Logger, switcher *pageswitch.Switcher) cftype.Grouper {
	const group = "Dev"
	title := tran.Slate("hi")

	// all packages in the application gopath.
	pathGoTest := strings.Join(append(cdglobal.AppBuildPath, "..."), "/")

	pathTestConfCmd := cdglobal.AppBuildPathFull("test", "confcmd", "confcmd.go")
	pathTestConfGUI := cdglobal.AppBuildPathFull("test", "confgui", "confgui.go")
	pathTestConfCmd, _ = filepath.EvalSymlinks(pathTestConfCmd)
	pathTestConfGUI, _ = filepath.EvalSymlinks(pathTestConfGUI)

	printConfig := func(showAll bool) {
		path := source.MainConfigFile()
		def := source.MainConfigDefault()

		otherSw := pageswitch.New()
		defer otherSw.Destroy()
		build, e := cfbuild.NewFromFile(source, log, path, def, "")
		if !log.Err(e, "load current dock config file") {
			// build.BuildSingle("TaskBar")
			build.BuildAll(otherSw)
			println("conf", path, def)
			cfprint.Default(build, showAll)
			build.Destroy()
		}
	}

	buildInfo := cfbuild.TweakAddGroup(group,
		newkey.TextLabel(group, "txt_title", common.Bold(common.Big(title))),
		newkey.Separator(group, "sep_title"),
		newkey.TextLabel(group, "txt_dev_page", "Test page, with useful tools for the developer."),
		newkey.CustomButtonLabel(group, "printConfig", "Print configuration", "show mainconf edited", func() { printConfig(false) }),
		newkey.CustomButtonLabel(group, "printConfig", "Print configuration", "show mainconf all", func() { printConfig(true) }),
		newkey.Separator(group, "sep_go_area"),
		newkey.TextLabel(group, "txt_go_area", "<b>Those commands requires the application sources in their Go environment</b>."),
		newkey.Separator(group, "sep_tests_gui"),
		newkey.LaunchCommand(group, "testConfGUI", "Launch config GUI test", "go run "+pathTestConfGUI),
		newkey.Separator(group, "sep_tests_cmd"),
		newkey.LaunchCommand(group, "testConfGUI", "Launch config console test", "go run "+pathTestConfCmd),
		newkey.LaunchCommand(group, "testConfGUI", "Launch config console mainconf diff", "go run "+pathTestConfCmd+" "+source.MainConfigFile()),
		newkey.Separator(group, "sep_tests_go"),
		newkey.LaunchCommand(group, "gotest", "Launch go tests", "go test "+pathGoTest),
		newkey.LaunchCommand(group, "golint", "Launch go lint", "golint "+pathGoTest),
		newkey.LaunchCommand(group, "govet", "Launch go vet", "go vet "+pathGoTest),
	)

	build := cfbuild.NewVirtual(source, log, "", "", "").BuildAll(switcher, buildInfo)

	build.ShowAll()
	return build
}
コード例 #4
0
ファイル: desktopclass.go プロジェクト: sqp/godock
func desktopFileText(apps []string, dir, selected string) string {
	text := ""
	for _, v := range apps {
		// Remove suffix for name and highlight the active one (with link if possible).
		name := strings.TrimSuffix(v, ".desktop")
		isCurrent := name == selected

		if fileExists(filepath.Join(dir, v)) {
			name = common.URI("file://"+filepath.Join(dir, v), name)
		}

		if isCurrent {
			name = common.Bold(name)
		}
		text = strhelp.Separator(text, ", ", name)
	}
	return text
}
コード例 #5
0
ファイル: appletpreview.go プロジェクト: sqp/godock
// Load loads an applet or theme in the preview. Handbooker and Appleter can be used.
//
func (widget *Preview) Load(pack Previewer) {
	widget.title.SetMarkup(common.Big(common.Bold(pack.GetTitle())))
	author := pack.GetAuthor()
	if author != "" {
		author = fmt.Sprintf(tran.Slate("by %s"), author)
	}
	widget.author.SetMarkup(common.Small(common.Mono(author)))

	apl, ok := pack.(Appleter)
	if ok {
		widget.stateText.SetMarkup(apl.FormatState())
		widget.size.SetMarkup(common.Small(apl.FormatSize()))

		if icon := apl.IconState(); icon != "" {
			if pixbuf, e := common.PixbufAtSize(icon, 24, 24); !widget.log.Err(e, "Load image pixbuf") {
				widget.stateIcon.SetFromPixbuf(pixbuf)
				widget.stateIcon.Show()
			}
		}
	}

	// widget.RemoveTmpFile()

	widget.previewFrame.Hide() // Hide the preview frame until we have an image.

	// Async calls for description and image. They can have to be downloaded and be slow at it.

	chDesc := make(chan (string))
	go func() { // Go routines to get data.
		chDesc <- pack.GetDescription()
	}()
	go func() {
		imageLocation := pack.GetPreviewFilePath()
		// imageLocation, isTemp := pack.GetPreview(widget.TmpFile) // reuse the same tmp location if needed.

		desc := <-chDesc
		glib.IdleAdd(func() { // glib Idle to show the result.
			widget.description.SetMarkup(desc)
			widget.setImage(imageLocation)
		})
	}()

}
コード例 #6
0
ファイル: desktopclass.go プロジェクト: sqp/godock
// Widget creates a desktop class informations widget.
//
func Widget(source datatype.Source, selected datatype.DesktopClasser, origins string) gtk.IWidget {
	apps := strings.Split(origins, ";")
	if len(apps) == 0 {
		return nil
	}

	// Remove the path from the first item.
	dir := filepath.Dir(apps[0])
	apps[0] = filepath.Base(apps[0])

	// Try force select the first one (can be inactive if "do not bind appli").
	if selected.String() == "" {
		selected = source.DesktopClasser(strings.TrimSuffix(apps[0], ".desktop"))
	}

	command := selected.Command()
	desktopFile := desktopFileText(apps, dir, selected.String())

	wName := boxLabel(selected.Name())
	wIcon := boxLabel(selected.Icon())
	wCommand := boxButton(command, func() { println("need to launch", command) })
	wDesktopFiles := boxLabel(desktopFile)

	grid := newgtk.Grid()
	grid.Attach(boxLabel("Name"), 0, 0, 1, 1)
	grid.Attach(boxLabel("Icon"), 0, 1, 1, 1)
	grid.Attach(boxLabel("Command"), 0, 2, 1, 1)
	grid.Attach(boxLabel("Desktop file"), 0, 3, 1, 1)
	grid.Attach(wName, 1, 0, 1, 1)
	grid.Attach(wIcon, 1, 1, 1, 1)
	grid.Attach(wCommand, 1, 2, 1, 1)
	grid.Attach(wDesktopFiles, 1, 3, 1, 1)

	frame := newgtk.Frame("")
	label := newgtk.Label(common.Bold("Launcher origin"))
	label.SetUseMarkup(true)
	frame.SetLabelWidget(label)
	frame.Add(grid)
	frame.ShowAll()
	return frame
}
コード例 #7
0
ファイル: handbook.go プロジェクト: sqp/godock
// SetPackage fills the handbook data with a package.
//
func (widget *Handbook) SetPackage(book datatype.Handbooker) {
	title := common.Bold(common.Big(book.GetTitle()))
	if widget.ShowVersion {
		title += " v" + book.GetModuleVersion()
	}
	widget.title.SetMarkup(title)

	author := book.GetAuthor()
	if author != "" {
		author = fmt.Sprintf("by %s", author)
		widget.author.SetMarkup(common.Small(common.Mono(author)))
	}
	widget.author.SetVisible(author != "")

	widget.description.SetMarkup("<span rise='8000'>" + book.GetDescription() + "</span>")

	previewFound := false
	defer func() { widget.previewFrame.SetVisible(previewFound) }()

	file := book.GetPreviewFilePath()
	if file == "" {
		return
	}
	_, w, h := gdk.PixbufGetFileInfo(file)

	var pixbuf *gdk.Pixbuf
	var e error
	if w > PreviewSizeMax || h > PreviewSizeMax {
		pixbuf, e = gdk.PixbufNewFromFileAtScale(file, PreviewSizeMax, PreviewSizeMax, true)
	} else {
		pixbuf, e = gdk.PixbufNewFromFile(file)
	}

	if e == nil && pixbuf != nil {
		previewFound = true
		widget.previewImage.SetFromPixbuf(pixbuf)
	}
}
コード例 #8
0
ファイル: widgets.go プロジェクト: sqp/godock
// Frame adds a simple or expanded frame widget.
//
func Frame(key *cftype.Key) {
	if len(key.AuthorizedValues) == 0 {
		key.SetFrame(nil)
		key.SetFrameBox(nil)
		return
	}

	value, img := "", ""
	if key.AuthorizedValues[0] == "" {
		key.Log().Info("WidgetFrame, need value case 1")
		// value = g_key_file_get_string(pKeyFile, cGroupName, cKeyName, NULL) // utile ?
	} else {
		value = key.AuthorizedValues[0]
		if len(key.AuthorizedValues) > 1 {
			img = key.AuthorizedValues[1]
		}
	}

	// Create the frame label with the optional icon.
	label := newgtk.Label("")
	// key.SetLabel(label)
	label.SetMarkup(" " + common.Bold(key.Translate(value)) + " ")

	var labelContainer gtk.IWidget
	if img == "" {
		labelContainer = label
	} else {
		box := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, cftype.MarginIcon/2)
		if icon, e := common.ImageNewFromFile(img, iconSizeFrame); !key.Log().Err(e, "Frame icon") { // TODO: fix size : int(gtk.ICON_SIZE_MENU)
			box.Add(icon)
		}
		box.Add(label)
		labelContainer = box
	}

	// Create the box that will contain next widgets (inside the frame).
	box := newgtk.Box(gtk.ORIENTATION_VERTICAL, cftype.MarginGUI)
	key.SetFrameBox(box)

	frame := newgtk.Frame("")
	key.SetFrame(frame)
	frame.SetBorderWidth(cftype.MarginGUI)
	frame.SetShadowType(gtk.SHADOW_OUT)
	frame.Add(box)

	// Set label and create the expander around the frame if needed.
	switch key.Type {
	case cftype.KeyFrame:
		frame.SetLabelWidget(labelContainer)
		key.BoxPage().PackStart(frame, false, false, 0)

	case cftype.KeyExpander:
		expand := newgtk.Expander("")
		expand.SetExpanded(false)
		expand.SetLabelWidget(labelContainer)

		expand.Add(frame)
		key.BoxPage().PackStart(expand, false, false, 0)
	}

	// SAME AS IN builder.go

	// 	if (pControlWidgets != NULL)
	// 	{
	// 		cd_debug ("ctrl\n");
	// 		CDControlWidget *cw = pControlWidgets->data;
	// 		if (cw->pControlContainer == key.Box)
	// 		{
	// 			cd_debug ("ctrl (NbControlled:%d, iFirstSensitiveWidget:%d, iNbSensitiveWidgets:%d)", cw->NbControlled, cw->iFirstSensitiveWidget, cw->iNbSensitiveWidgets);
	// 			cw->NbControlled --;
	// 			if (cw->iFirstSensitiveWidget > 0)
	// 				cw->iFirstSensitiveWidget --;
	// 			cw->iNonSensitiveWidget --;

	// 			GtkWidget *w = pExternFrame;
	// 			if (cw->iFirstSensitiveWidget == 0 && cw->iNbSensitiveWidgets > 0 && cw->iNonSensitiveWidget != 0)
	// 			{
	// 				cd_debug (" => sensitive\n");
	// 				cw->iNbSensitiveWidgets --;
	// 				if (GTK_IS_EXPANDER (w))
	// 					gtk_expander_set_expanded (GTK_EXPANDER (w), TRUE);
	// 			}
	// 			else
	// 			{
	// 				cd_debug (" => unsensitive\n");
	// 				if (!GTK_IS_EXPANDER (w))
	// 					gtk_widget_set_sensitive (w, FALSE);
	// 			}
	// 			if (cw->iFirstSensitiveWidget == 0 && cw->NbControlled == 0)
	// 			{
	// 				pControlWidgets = g_list_delete_link (pControlWidgets, pControlWidgets);
	// 				g_free (cw);
	// 			}
	// 		}
	// 	}
}