File: app_chooser.go

package info (click to toggle)
golang-github-gotk3-gotk3 0.6.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,392 kB
  • sloc: ansic: 914; makefile: 4
file content (408 lines) | stat: -rw-r--r-- 12,575 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
package gtk

// #include <gtk/gtk.h>
// #include "gtk.go.h"
import "C"
import (
	"unsafe"

	"github.com/gotk3/gotk3/glib"
)

func init() {
	tm := []glib.TypeMarshaler{
		{glib.Type(C.gtk_app_chooser_get_type()), marshalAppChooser},
		{glib.Type(C.gtk_app_chooser_button_get_type()), marshalAppChooserButton},
		{glib.Type(C.gtk_app_chooser_widget_get_type()), marshalAppChooserWidget},
		{glib.Type(C.gtk_app_chooser_dialog_get_type()), marshalAppChooserDialog},
	}

	glib.RegisterGValueMarshalers(tm)

	WrapMap["GtkAppChooser"] = wrapAppChooser
	WrapMap["GtkAppChooserButton"] = wrapAppChooserButton
	WrapMap["GtkAppChooserWidget"] = wrapAppChooserWidget
	WrapMap["GtkAppChooserDialog"] = wrapAppChooserDialog
}

/*
 * GtkAppChooser
 */

// AppChooser is a representation of GTK's GtkAppChooser GInterface.
type AppChooser struct {
	*glib.Object
}

// IAppChooser is an interface type implemented by all structs
// embedding an AppChooser. It is meant to be used as an argument type
// for wrapper functions that wrap around a C GTK function taking a
// GtkAppChooser.
type IAppChooser interface {
	toAppChooser() *C.GtkAppChooser
}

// native returns a pointer to the underlying GtkAppChooser.
func (v *AppChooser) native() *C.GtkAppChooser {
	if v == nil || v.GObject == nil {
		return nil
	}
	p := unsafe.Pointer(v.GObject)
	return C.toGtkAppChooser(p)
}

func marshalAppChooser(p uintptr) (interface{}, error) {
	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
	obj := glib.Take(unsafe.Pointer(c))
	return wrapAppChooser(obj), nil
}

func wrapAppChooser(obj *glib.Object) *AppChooser {
	if obj == nil {
		return nil
	}

	return &AppChooser{obj}
}

func (v *AppChooser) toAppChooser() *C.GtkAppChooser {
	if v == nil {
		return nil
	}
	return v.native()
}

// TODO: Needs gio/GAppInfo implementation first
// gtk_app_chooser_get_app_info ()

// GetContentType is a wrapper around gtk_app_chooser_get_content_type().
func (v *AppChooser) GetContentType() string {
	cstr := C.gtk_app_chooser_get_content_type(v.native())
	defer C.free(unsafe.Pointer(cstr))
	return C.GoString((*C.char)(cstr))
}

// Refresh is a wrapper around gtk_app_chooser_refresh().
func (v *AppChooser) Refresh() {
	C.gtk_app_chooser_refresh(v.native())
}

/*
 * GtkAppChooserButton
 */

// AppChooserButton is a representation of GTK's GtkAppChooserButton.
type AppChooserButton struct {
	ComboBox

	// Interfaces
	AppChooser
}

// native returns a pointer to the underlying GtkAppChooserButton.
func (v *AppChooserButton) native() *C.GtkAppChooserButton {
	if v == nil || v.GObject == nil {
		return nil
	}

	p := unsafe.Pointer(v.GObject)
	return C.toGtkAppChooserButton(p)
}

func marshalAppChooserButton(p uintptr) (interface{}, error) {
	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
	return wrapAppChooserButton(glib.Take(unsafe.Pointer(c))), nil
}

func wrapAppChooserButton(obj *glib.Object) *AppChooserButton {
	if obj == nil {
		return nil
	}

	cl := wrapCellLayout(obj)
	ce := wrapCellEditable(obj)
	ac := wrapAppChooser(obj)
	return &AppChooserButton{ComboBox{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}, *cl, *ce}, *ac}
}

// AppChooserButtonNew() is a wrapper around gtk_app_chooser_button_new().
func AppChooserButtonNew(content_type string) (*AppChooserButton, error) {
	cstr := C.CString(content_type)
	defer C.free(unsafe.Pointer(cstr))
	c := C.gtk_app_chooser_button_new((*C.gchar)(cstr))
	if c == nil {
		return nil, nilPtrErr
	}
	return wrapAppChooserButton(glib.Take(unsafe.Pointer(c))), nil
}

// TODO: Needs gio/GIcon implemented first
// gtk_app_chooser_button_append_custom_item ()

// AppendSeparator() is a wrapper around gtk_app_chooser_button_append_separator().
func (v *AppChooserButton) AppendSeparator() {
	C.gtk_app_chooser_button_append_separator(v.native())
}

// SetActiveCustomItem() is a wrapper around gtk_app_chooser_button_set_active_custom_item().
func (v *AppChooserButton) SetActiveCustomItem(name string) {
	cstr := C.CString(name)
	defer C.free(unsafe.Pointer(cstr))
	C.gtk_app_chooser_button_set_active_custom_item(v.native(), (*C.gchar)(cstr))
}

// GetShowDefaultItem() is a wrapper around gtk_app_chooser_button_get_show_default_item().
func (v *AppChooserButton) GetShowDefaultItem() bool {
	return gobool(C.gtk_app_chooser_button_get_show_default_item(v.native()))
}

// SetShowDefaultItem() is a wrapper around gtk_app_chooser_button_set_show_default_item().
func (v *AppChooserButton) SetShowDefaultItem(setting bool) {
	C.gtk_app_chooser_button_set_show_default_item(v.native(), gbool(setting))
}

// GetShowDialogItem() is a wrapper around gtk_app_chooser_button_get_show_dialog_item().
func (v *AppChooserButton) GetShowDialogItem() bool {
	return gobool(C.gtk_app_chooser_button_get_show_dialog_item(v.native()))
}

// SetShowDialogItem() is a wrapper around gtk_app_chooser_button_set_show_dialog_item().
func (v *AppChooserButton) SetShowDialogItem(setting bool) {
	C.gtk_app_chooser_button_set_show_dialog_item(v.native(), gbool(setting))
}

// GetHeading() is a wrapper around gtk_app_chooser_button_get_heading().
// In case when gtk_app_chooser_button_get_heading() returns a nil string,
// GetHeading() returns a non-nil error.
func (v *AppChooserButton) GetHeading() (string, error) {
	cstr := C.gtk_app_chooser_button_get_heading(v.native())
	if cstr == nil {
		return "", nilPtrErr
	}
	defer C.free(unsafe.Pointer(cstr))
	return C.GoString((*C.char)(cstr)), nil
}

// SetHeading() is a wrapper around gtk_app_chooser_button_set_heading().
func (v *AppChooserButton) SetHeading(heading string) {
	cstr := C.CString(heading)
	defer C.free(unsafe.Pointer(cstr))
	C.gtk_app_chooser_button_set_heading(v.native(), (*C.gchar)(cstr))
}

/*
 * GtkAppChooserWidget
 */

// AppChooserWidget is a representation of GTK's GtkAppChooserWidget.
type AppChooserWidget struct {
	Box

	// Interfaces
	AppChooser
}

// native returns a pointer to the underlying GtkAppChooserWidget.
func (v *AppChooserWidget) native() *C.GtkAppChooserWidget {
	if v == nil || v.GObject == nil {
		return nil
	}

	p := unsafe.Pointer(v.GObject)
	return C.toGtkAppChooserWidget(p)
}

func marshalAppChooserWidget(p uintptr) (interface{}, error) {
	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
	return wrapAppChooserWidget(glib.Take(unsafe.Pointer(c))), nil
}

func wrapAppChooserWidget(obj *glib.Object) *AppChooserWidget {
	if obj == nil {
		return nil
	}

	box := wrapBox(obj)
	ac := wrapAppChooser(obj)
	return &AppChooserWidget{*box, *ac}
}

// AppChooserWidgetNew() is a wrapper around gtk_app_chooser_widget_new().
func AppChooserWidgetNew(content_type string) (*AppChooserWidget, error) {
	cstr := C.CString(content_type)
	defer C.free(unsafe.Pointer(cstr))
	c := C.gtk_app_chooser_widget_new((*C.gchar)(cstr))
	if c == nil {
		return nil, nilPtrErr
	}
	return wrapAppChooserWidget(glib.Take(unsafe.Pointer(c))), nil
}

// GetShowDefault() is a wrapper around gtk_app_chooser_widget_get_show_default().
func (v *AppChooserWidget) GetShowDefault() bool {
	return gobool(C.gtk_app_chooser_widget_get_show_default(v.native()))
}

// SetShowDefault() is a wrapper around gtk_app_chooser_widget_set_show_default().
func (v *AppChooserWidget) SetShowDefault(setting bool) {
	C.gtk_app_chooser_widget_set_show_default(v.native(), gbool(setting))
}

// GetShowRecommended() is a wrapper around gtk_app_chooser_widget_get_show_recommended().
func (v *AppChooserWidget) GetShowRecommended() bool {
	return gobool(C.gtk_app_chooser_widget_get_show_recommended(v.native()))
}

// SetShowRecommended() is a wrapper around gtk_app_chooser_widget_set_show_recommended().
func (v *AppChooserWidget) SetShowRecommended(setting bool) {
	C.gtk_app_chooser_widget_set_show_recommended(v.native(), gbool(setting))
}

// GetShowFallback() is a wrapper around gtk_app_chooser_widget_get_show_fallback().
func (v *AppChooserWidget) GetShowFallback() bool {
	return gobool(C.gtk_app_chooser_widget_get_show_fallback(v.native()))
}

// SetShowFallback() is a wrapper around gtk_app_chooser_widget_set_show_fallback().
func (v *AppChooserWidget) SetShowFallback(setting bool) {
	C.gtk_app_chooser_widget_set_show_fallback(v.native(), gbool(setting))
}

// GetShowOther() is a wrapper around gtk_app_chooser_widget_get_show_other().
func (v *AppChooserWidget) GetShowOther() bool {
	return gobool(C.gtk_app_chooser_widget_get_show_other(v.native()))
}

// SetShowOther() is a wrapper around gtk_app_chooser_widget_set_show_other().
func (v *AppChooserWidget) SetShowOther(setting bool) {
	C.gtk_app_chooser_widget_set_show_other(v.native(), gbool(setting))
}

// GetShowAll() is a wrapper around gtk_app_chooser_widget_get_show_all().
func (v *AppChooserWidget) GetShowAll() bool {
	return gobool(C.gtk_app_chooser_widget_get_show_all(v.native()))
}

// SetShowAll() is a wrapper around gtk_app_chooser_widget_set_show_all().
func (v *AppChooserWidget) SetShowAll(setting bool) {
	C.gtk_app_chooser_widget_set_show_all(v.native(), gbool(setting))
}

// GetDefaultText() is a wrapper around gtk_app_chooser_widget_get_default_text().
// In case when gtk_app_chooser_widget_get_default_text() returns a nil string,
// GetDefaultText() returns a non-nil error.
func (v *AppChooserWidget) GetDefaultText() (string, error) {
	cstr := C.gtk_app_chooser_widget_get_default_text(v.native())
	if cstr == nil {
		return "", nilPtrErr
	}
	defer C.free(unsafe.Pointer(cstr))
	return C.GoString((*C.char)(cstr)), nil
}

// SetDefaultText() is a wrapper around gtk_app_chooser_widget_set_default_text().
func (v *AppChooserWidget) SetDefaultText(text string) {
	cstr := C.CString(text)
	defer C.free(unsafe.Pointer(cstr))
	C.gtk_app_chooser_widget_set_default_text(v.native(), (*C.gchar)(cstr))
}

/*
 * GtkAppChooserDialog
 */

// AppChooserDialog is a representation of GTK's GtkAppChooserDialog.
type AppChooserDialog struct {
	Dialog

	// Interfaces
	AppChooser
}

// native returns a pointer to the underlying GtkAppChooserButton.
func (v *AppChooserDialog) native() *C.GtkAppChooserDialog {
	if v == nil || v.GObject == nil {
		return nil
	}

	p := unsafe.Pointer(v.GObject)
	return C.toGtkAppChooserDialog(p)
}

func marshalAppChooserDialog(p uintptr) (interface{}, error) {
	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
	return wrapAppChooserDialog(glib.Take(unsafe.Pointer(c))), nil
}

func wrapAppChooserDialog(obj *glib.Object) *AppChooserDialog {
	if obj == nil {
		return nil
	}

	dialog := wrapDialog(obj)
	ac := wrapAppChooser(obj)
	return &AppChooserDialog{*dialog, *ac}
}

// AppChooserDialogNew is a wrapper around gtk_app_chooser_dialog_new().
func AppChooserDialogNew(parent IWindow, flags DialogFlags, file *glib.File) (*AppChooserDialog, error) {

	var gfile *C.GFile
	if file != nil {
		gfile = (*C.GFile)(unsafe.Pointer(file.Native()))
	}

	var pw *C.GtkWindow = nil
	if parent != nil {
		pw = parent.toWindow()
	}

	c := C.gtk_app_chooser_dialog_new(pw, C.GtkDialogFlags(flags), gfile)
	if c == nil {
		return nil, nilPtrErr
	}
	return wrapAppChooserDialog(glib.Take(unsafe.Pointer(c))), nil
}

// AppChooserDialogNewForContentType() is a wrapper around gtk_app_chooser_dialog_new_for_content_type().
func AppChooserDialogNewForContentType(parent IWindow, flags DialogFlags, content_type string) (*AppChooserDialog, error) {

	cstr := C.CString(content_type)
	defer C.free(unsafe.Pointer(cstr))

	var pw *C.GtkWindow = nil
	if parent != nil {
		pw = parent.toWindow()
	}

	c := C.gtk_app_chooser_dialog_new_for_content_type(pw, C.GtkDialogFlags(flags), (*C.gchar)(cstr))
	if c == nil {
		return nil, nilPtrErr
	}
	return wrapAppChooserDialog(glib.Take(unsafe.Pointer(c))), nil
}

// GetWidget() is a wrapper around gtk_app_chooser_dialog_get_widget().
func (v *AppChooserDialog) GetWidget() *AppChooserWidget {
	c := C.gtk_app_chooser_dialog_get_widget(v.native())
	return wrapAppChooserWidget(glib.Take(unsafe.Pointer(c)))
}

// GetHeading() is a wrapper around gtk_app_chooser_dialog_get_heading().
// In case when gtk_app_chooser_dialog_get_heading() returns a nil string,
// GetHeading() returns a non-nil error.
func (v *AppChooserDialog) GetHeading() (string, error) {
	cstr := C.gtk_app_chooser_dialog_get_heading(v.native())
	if cstr == nil {
		return "", nilPtrErr
	}
	defer C.free(unsafe.Pointer(cstr))
	return C.GoString((*C.char)(cstr)), nil
}

// SetHeading() is a wrapper around gtk_app_chooser_dialog_set_heading().
func (v *AppChooserDialog) SetHeading(heading string) {
	cstr := C.CString(heading)
	defer C.free(unsafe.Pointer(cstr))
	C.gtk_app_chooser_dialog_set_heading(v.native(), (*C.gchar)(cstr))
}