Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SetStrv to glib.settings #225

Merged
merged 2 commits into from Dec 27, 2017
Merged

Added SetStrv to glib.settings #225

merged 2 commits into from Dec 27, 2017

Conversation

okelet
Copy link
Contributor

@okelet okelet commented Dec 22, 2017

Implement SetStrv, but doesn't compile. Please help fix. The documentation of the function is here https://developer.gnome.org/gio/stable/GSettings.html#g-settings-set-strv. I have opened a question in StackOverflow (https://stackoverflow.com/questions/47907238/convert-glib-c-method-with-string-array-as-parameter-to-go), but nobody answered. I don't have enough knowledge of C to do this.

@tommyshem
Copy link

Looking at the code in gtk.go from line 6550 they have used this code to create a C string array.
I have have changed your code with the way it is done in gtk.go above.
Not tested as I do not program in cgo, and I do not use this function.
You could try and see if it helps.

// SetStrv is a wrapper around g_settings_set_strv().
func (v *Settings) SetStrv(name string, values []string) bool {
	cstr1 := (*C.gchar)(C.CString(name))
	defer C.free(unsafe.Pointer(cstr1))

	// cvalues := C.make_strings(C.int(len(values) + 1))
	cvalues := make([]*C.gchar, len(values))

	for i, accel := range values {
		cvalues[i] = (*C.gchar)(C.CString(accel))
		defer C.free(unsafe.Pointer(cvalues[i]))
	}
	cvalues = append(cvalues, nil)

	// C.set_string(cvalues, C.int(len(values)), nil)
	return gobool(C.g_settings_set_strv(v.native(), cstr1, &cvalues[0]))

@okelet
Copy link
Contributor Author

okelet commented Dec 26, 2017

Thanks @tommyshem! Now it compiles, and I have done some tests, and it seems to work. I have commited my forked repo, and the travis build has been relaunched with successful results. The pull is request is now ready and working.

@tommyshem
Copy link

@okelet Glad it worked.

@andre-hub andre-hub merged commit 7e09a04 into gotk3:master Dec 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants