summaryrefslogtreecommitdiff
path: root/vendor/github.com/gotk3/gotk3/glib/notifications.go
blob: 9f1ec6a1c3dbd4e88dff8b5fc81bca0d7170b37a (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
package glib

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

// Only available from 2.42
// // NotificationPriority is a representation of GLib's GNotificationPriority.
// type NotificationPriority int

// const (
// 	NOTIFICATION_PRIORITY_NORMAL NotificationPriority = C.G_NOTIFICATION_PRIORITY_NORMAL
// 	NOTIFICATION_PRIORITY_LOW    NotificationPriority = C.G_NOTIFICATION_PRIORITY_LOW
// 	NOTIFICATION_PRIORITY_HIGH   NotificationPriority = C.G_NOTIFICATION_PRIORITY_HIGH
// 	NOTIFICATION_PRIORITY_URGENT NotificationPriority = C.G_NOTIFICATION_PRIORITY_URGENT
// )

// Notification is a representation of GNotification.
type Notification struct {
	*Object
}

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

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

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

func wrapNotification(obj *Object) *Notification {
	return &Notification{obj}
}

// NotificationNew is a wrapper around g_notification_new().
func NotificationNew(title string) *Notification {
	cstr1 := (*C.gchar)(C.CString(title))
	defer C.free(unsafe.Pointer(cstr1))

	c := C.g_notification_new(cstr1)
	if c == nil {
		return nil
	}
	return wrapNotification(wrapObject(unsafe.Pointer(c)))
}

// SetTitle is a wrapper around g_notification_set_title().
func (v *Notification) SetTitle(title string) {
	cstr1 := (*C.gchar)(C.CString(title))
	defer C.free(unsafe.Pointer(cstr1))

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

// SetBody is a wrapper around g_notification_set_body().
func (v *Notification) SetBody(body string) {
	cstr1 := (*C.gchar)(C.CString(body))
	defer C.free(unsafe.Pointer(cstr1))

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

// Only available from 2.42
// // SetPriority is a wrapper around g_notification_set_priority().
// func (v *Notification) SetPriority(prio NotificationPriority) {
// 	C.g_notification_set_priority(v.native(), C.GNotificationPriority(prio))
// }

// SetDefaultAction is a wrapper around g_notification_set_default_action().
func (v *Notification) SetDefaultAction(detailedAction string) {
	cstr1 := (*C.gchar)(C.CString(detailedAction))
	defer C.free(unsafe.Pointer(cstr1))

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

// AddButton is a wrapper around g_notification_add_button().
func (v *Notification) AddButton(label, detailedAction string) {
	cstr1 := (*C.gchar)(C.CString(label))
	defer C.free(unsafe.Pointer(cstr1))

	cstr2 := (*C.gchar)(C.CString(detailedAction))
	defer C.free(unsafe.Pointer(cstr2))

	C.g_notification_add_button(v.native(), cstr1, cstr2)
}

// void 	g_notification_set_default_action_and_target () // requires varargs
// void 	g_notification_set_default_action_and_target_value () // requires variant
// void 	g_notification_add_button_with_target () // requires varargs
// void 	g_notification_add_button_with_target_value () //requires variant
// void 	g_notification_set_urgent () // Deprecated, so not implemented
// void 	g_notification_set_icon () // Requires support for GIcon, which we don't have yet.