summaryrefslogtreecommitdiff
path: root/vendor/github.com/gotk3/gotk3/glib/application.go
blob: 81ad34ec91afe84722cbf34c9a2a54ba10eb31a4 (plain)
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
package glib

// #include <gio/gio.h>
// #include <glib.h>
// #include <glib-object.h>
// #include "glib.go.h"
import "C"
import "unsafe"

// Application is a representation of GApplication.
type Application struct {
	*Object

	// Interfaces
	IActionMap
	IActionGroup
}

// native() returns a pointer to the underlying GApplication.
func (v *Application) native() *C.GApplication {
	if v == nil || v.GObject == nil {
		return nil
	}
	return C.toGApplication(unsafe.Pointer(v.GObject))
}

func (v *Application) Native() uintptr {
	return uintptr(unsafe.Pointer(v.native()))
}

func marshalApplication(p uintptr) (interface{}, error) {
	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
	return wrapApplication(wrapObject(unsafe.Pointer(c))), nil
}

func wrapApplication(obj *Object) *Application {
	am := wrapActionMap(obj)
	ag := wrapActionGroup(obj)
	return &Application{obj, am, ag}
}

// ApplicationIDIsValid is a wrapper around g_application_id_is_valid().
func ApplicationIDIsValid(id string) bool {
	cstr1 := (*C.gchar)(C.CString(id))
	defer C.free(unsafe.Pointer(cstr1))

	return gobool(C.g_application_id_is_valid(cstr1))
}

// ApplicationNew is a wrapper around g_application_new().
func ApplicationNew(appID string, flags ApplicationFlags) *Application {
	cstr1 := (*C.gchar)(C.CString(appID))
	defer C.free(unsafe.Pointer(cstr1))

	c := C.g_application_new(cstr1, C.GApplicationFlags(flags))
	if c == nil {
		return nil
	}
	return wrapApplication(wrapObject(unsafe.Pointer(c)))
}

// GetApplicationID is a wrapper around g_application_get_application_id().
func (v *Application) GetApplicationID() string {
	c := C.g_application_get_application_id(v.native())

	return C.GoString((*C.char)(c))
}

// SetApplicationID is a wrapper around g_application_set_application_id().
func (v *Application) SetApplicationID(id string) {
	cstr1 := (*C.gchar)(C.CString(id))
	defer C.free(unsafe.Pointer(cstr1))

	C.g_application_set_application_id(v.native(), cstr1)
}

// GetInactivityTimeout is a wrapper around g_application_get_inactivity_timeout().
func (v *Application) GetInactivityTimeout() uint {
	return uint(C.g_application_get_inactivity_timeout(v.native()))
}

// SetInactivityTimeout is a wrapper around g_application_set_inactivity_timeout().
func (v *Application) SetInactivityTimeout(timeout uint) {
	C.g_application_set_inactivity_timeout(v.native(), C.guint(timeout))
}

// GetFlags is a wrapper around g_application_get_flags().
func (v *Application) GetFlags() ApplicationFlags {
	return ApplicationFlags(C.g_application_get_flags(v.native()))
}

// SetFlags is a wrapper around g_application_set_flags().
func (v *Application) SetFlags(flags ApplicationFlags) {
	C.g_application_set_flags(v.native(), C.GApplicationFlags(flags))
}

// Only available in GLib 2.42+
// // GetResourceBasePath is a wrapper around g_application_get_resource_base_path().
// func (v *Application) GetResourceBasePath() string {
// 	c := C.g_application_get_resource_base_path(v.native())

// 	return C.GoString((*C.char)(c))
// }

// Only available in GLib 2.42+
// // SetResourceBasePath is a wrapper around g_application_set_resource_base_path().
// func (v *Application) SetResourceBasePath(bp string) {
// 	cstr1 := (*C.gchar)(C.CString(bp))
// 	defer C.free(unsafe.Pointer(cstr1))

// 	C.g_application_set_resource_base_path(v.native(), cstr1)
// }

// GetDbusObjectPath is a wrapper around g_application_get_dbus_object_path().
func (v *Application) GetDbusObjectPath() string {
	c := C.g_application_get_dbus_object_path(v.native())

	return C.GoString((*C.char)(c))
}

// GetIsRegistered is a wrapper around g_application_get_is_registered().
func (v *Application) GetIsRegistered() bool {
	return gobool(C.g_application_get_is_registered(v.native()))
}

// GetIsRemote is a wrapper around g_application_get_is_remote().
func (v *Application) GetIsRemote() bool {
	return gobool(C.g_application_get_is_remote(v.native()))
}

// Hold is a wrapper around g_application_hold().
func (v *Application) Hold() {
	C.g_application_hold(v.native())
}

// Release is a wrapper around g_application_release().
func (v *Application) Release() {
	C.g_application_release(v.native())
}

// Quit is a wrapper around g_application_quit().
func (v *Application) Quit() {
	C.g_application_quit(v.native())
}

// Activate is a wrapper around g_application_activate().
func (v *Application) Activate() {
	C.g_application_activate(v.native())
}

// SendNotification is a wrapper around g_application_send_notification().
func (v *Application) SendNotification(id string, notification *Notification) {
	cstr1 := (*C.gchar)(C.CString(id))
	defer C.free(unsafe.Pointer(cstr1))

	C.g_application_send_notification(v.native(), cstr1, notification.native())
}

// WithdrawNotification is a wrapper around g_application_withdraw_notification().
func (v *Application) WithdrawNotification(id string) {
	cstr1 := (*C.gchar)(C.CString(id))
	defer C.free(unsafe.Pointer(cstr1))

	C.g_application_withdraw_notification(v.native(), cstr1)
}

// SetDefault is a wrapper around g_application_set_default().
func (v *Application) SetDefault() {
	C.g_application_set_default(v.native())
}

// ApplicationGetDefault is a wrapper around g_application_get_default().
func ApplicationGetDefault() *Application {
	c := C.g_application_get_default()
	if c == nil {
		return nil
	}
	return wrapApplication(wrapObject(unsafe.Pointer(c)))
}

// MarkBusy is a wrapper around g_application_mark_busy().
func (v *Application) MarkBusy() {
	C.g_application_mark_busy(v.native())
}

// UnmarkBusy is a wrapper around g_application_unmark_busy().
func (v *Application) UnmarkBusy() {
	C.g_application_unmark_busy(v.native())
}

// Run is a wrapper around g_application_run().
func (v *Application) Run(args []string) int {
	cargs := C.make_strings(C.int(len(args)))
	defer C.destroy_strings(cargs)

	for i, arg := range args {
		cstr := C.CString(arg)
		defer C.free(unsafe.Pointer(cstr))
		C.set_string(cargs, C.int(i), (*C.char)(cstr))
	}

	return int(C.g_application_run(v.native(), C.int(len(args)), cargs))
}

// Only available in GLib 2.44+
// // GetIsBusy is a wrapper around g_application_get_is_busy().
// func (v *Application) GetIsBusy() bool {
// 	return gobool(C.g_application_get_is_busy(v.native()))
// }

// void 	g_application_bind_busy_property ()
// void 	g_application_unbind_busy_property ()
// gboolean 	g_application_register () // requires GCancellable
// void 	g_application_set_action_group () // Deprecated since 2.32
// GDBusConnection * 	g_application_get_dbus_connection () // No support for GDBusConnection
// void 	g_application_open () // Needs GFile
// void 	g_application_add_main_option_entries () //Needs GOptionEntry
// void 	g_application_add_main_option () //Needs GOptionFlags and GOptionArg
// void 	g_application_add_option_group () // Needs GOptionGroup