├── .gitignore ├── .travis.yml ├── GAction.go ├── GActionMap.go ├── GApplication.go ├── GApplicationFlags.go ├── GCancellable.go ├── GDBusConnection.go ├── GFile.go ├── GMenu.go ├── GMenuModel.go ├── GNotification.go ├── GSimpleAction.go ├── GTypeModule.go ├── README.md ├── gio.go └── gio.go.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.4 5 | - 1.5 6 | - 1.6 7 | - tip 8 | 9 | env: 10 | - GOARCH=amd64 11 | 12 | sudo: required 13 | dist: trusty 14 | 15 | before_install: 16 | - sudo apt-get update -qq 17 | - sudo apt-get install -qq -y gtk+3.0 libgtk-3-dev 18 | - sudo apt-get install -qq -y xvfb 19 | - "export DISPLAY=:99.0" 20 | - sudo /usr/bin/Xvfb $DISPLAY 2>1 > /dev/null & 21 | - "export GTK_VERSION=$(pkg-config --modversion gtk+-3.0 | tr . _| cut -d '_' -f 1-2)" 22 | - "export Glib_VERSION=$(pkg-config --modversion glib-2.0)" 23 | - "export Cairo_VERSION=$(pkg-config --modversion cairo)" 24 | - "export Pango_VERSION=$(pkg-config --modversion pango)" 25 | - echo "GTK version ${GTK_VERSION} (Glib ${Glib_VERSION}, Cairo ${Cairo_VERSION}, Pango ${Pango_VERSION})" 26 | 27 | install: 28 | - go get -t -tags "gtk_${GTK_VERSION}" github.com/gotk3/gotk3/... 29 | - go get -t -tags "gio_${GTK_VERSION}" github.com/gotk3/gio/... 30 | 31 | script: 32 | - go test -tags "gtk_${GTK_VERSION}" ./... -------------------------------------------------------------------------------- /GAction.go: -------------------------------------------------------------------------------- 1 | //GAction 2 | package gio 3 | 4 | // #cgo pkg-config: gio-2.0 glib-2.0 5 | // #include 6 | // #include "gio.go.h" 7 | import "C" 8 | 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/gotk3/gotk3/glib" 13 | ) 14 | 15 | /* 16 | * GAction 17 | */ 18 | 19 | // Action is a representation of GIO's GAction. 20 | type Action struct { 21 | *glib.Object 22 | } 23 | 24 | // native returns a pointer to the underlying GAction. 25 | func (v *Action) native() *C.GAction { 26 | if v == nil || v.GObject == nil { 27 | return nil 28 | } 29 | p := unsafe.Pointer(v.GObject) 30 | return C.toGAction(p) 31 | } 32 | 33 | func marshalAction(p uintptr) (interface{}, error) { 34 | c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p))) 35 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 36 | return wrapAction(obj), nil 37 | } 38 | 39 | func wrapAction(obj *glib.Object) *Action { 40 | return &Action{obj} 41 | } 42 | 43 | func (v *Action) toAction() *C.GAction { 44 | if v == nil { 45 | return nil 46 | } 47 | return C.toGAction(unsafe.Pointer(v.GObject)) 48 | } 49 | 50 | func convertToAction(c *C.GAction) *Action { 51 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 52 | return wrapAction(obj) 53 | } 54 | 55 | //gboolean 56 | //g_action_name_is_valid (const gchar *action_name); 57 | //Checks if action_name is valid. 58 | //action_name is valid if it consists only of alphanumeric characters, plus '-' and '.'. The empty string is not a valid action name. 59 | //It is an error to call this function with a non-utf8 action_name . action_name must not be NULL. 60 | func ActionNameIsValid(action_name string) bool { 61 | cstr := C.CString(action_name) 62 | defer C.free(unsafe.Pointer(cstr)) 63 | c := C.g_action_name_is_valid((*C.gchar)(cstr)) 64 | return gobool(c) 65 | } 66 | 67 | //const gchar * 68 | //g_action_get_name (GAction *action); 69 | //Queries the name of action . 70 | func (v *Action) GetName() string { 71 | c := (*C.char)(C.g_action_get_name(v.native())) 72 | return C.GoString(c) 73 | } 74 | 75 | //const GVariantType * 76 | //g_action_get_parameter_type (GAction *action); 77 | //Queries the type of the parameter that must be given when activating action . 78 | //When activating the action using g_action_activate(), the GVariant given to that function must be of the type returned by this function. 79 | //In the case that this function returns NULL, you must not give any GVariant, but NULL instead. 80 | func (v *Action) GetParameterType() *glib.VariantType { 81 | c := (C.g_action_get_parameter_type(v.native())) 82 | p := unsafe.Pointer(c) 83 | return glib.VariantTypeFromUnsafePointer(p) 84 | } 85 | 86 | //const GVariantType * 87 | //g_action_get_state_type (GAction *action); 88 | //Queries the type of the state of action . 89 | //If the action is stateful (e.g. created with g_simple_action_new_stateful()) then this function returns the GVariantType of the state. This is the type of the initial value given as the state. All calls to g_action_change_state() must give a GVariant of this type and g_action_get_state() will return a GVariant of the same type. 90 | //If the action is not stateful (e.g. created with g_simple_action_new()) then this function will return NULL. In that case, g_action_get_state() will return NULL and you must not call g_action_change_state(). 91 | func (v *Action) GetStateType() *glib.VariantType { 92 | c := (C.g_action_get_state_type(v.native())) 93 | p := unsafe.Pointer(c) 94 | return glib.VariantTypeFromUnsafePointer(p) 95 | } 96 | 97 | //GVariant * 98 | //g_action_get_state_hint (GAction *action); 99 | //Requests a hint about the valid range of values for the state of action . 100 | //If NULL is returned it either means that the action is not stateful or that there is no hint about the valid range of values for the state of the action. 101 | //If a GVariant array is returned then each item in the array is a possible value for the state. If a GVariant pair (ie: two-tuple) is returned then the tuple specifies the inclusive lower and upper bound of valid values for the state. 102 | //In any case, the information is merely a hint. It may be possible to have a state value outside of the hinted range and setting a value within the range may fail. 103 | //The return value (if non-NULL) should be freed with g_variant_unref() when it is no longer required. 104 | func (v *Action) GetStateHint() *glib.Variant { 105 | c := (C.g_action_get_state_hint(v.native())) 106 | p := unsafe.Pointer(c) 107 | return glib.VariantFromUnsafePointer(p) 108 | } 109 | 110 | //gboolean 111 | //g_action_get_enabled (GAction *action); 112 | //Checks if action is currently enabled. 113 | //An action must be enabled in order to be activated or in order to have its state changed from outside callers. 114 | func (v *Action) GetEnabled() bool { 115 | c := C.g_action_get_enabled(v.native()) 116 | return gobool(c) 117 | } 118 | 119 | //GVariant * 120 | //g_action_get_state (GAction *action); 121 | //Queries the current state of action . 122 | //If the action is not stateful then NULL will be returned. If the action is stateful then the type of the return value is the type given by g_action_get_state_type(). 123 | //The return value (if non-NULL) should be freed with g_variant_unref() when it is no longer required. 124 | func (v *Action) GetState() *glib.Variant { 125 | c := (C.g_action_get_state(v.native())) 126 | p := unsafe.Pointer(c) 127 | return glib.VariantFromUnsafePointer(p) 128 | } 129 | 130 | //void 131 | //g_action_change_state (GAction *action, 132 | // GVariant *value); 133 | //Request for the state of action to be changed to value . 134 | //The action must be stateful and value must be of the correct type. See g_action_get_state_type(). 135 | //This call merely requests a change. The action may refuse to change its state or may change its state to something other than value . See g_action_get_state_hint(). 136 | //If the value GVariant is floating, it is consumed. 137 | func (v *Action) ChangeState(value *glib.Variant) { 138 | C.g_action_change_state(v.native(), (*C.GVariant)(value.ToGVariant())) 139 | } 140 | 141 | //void 142 | //g_action_activate (GAction *action, 143 | // GVariant *parameter); 144 | //Activates the action. 145 | //parameter must be the correct type of parameter for the action (ie: the parameter type given at construction time). If the parameter type was NULL then parameter must also be NULL. 146 | //If the parameter GVariant is floating, it is consumed. 147 | func (v *Action) Activate(parameter *glib.Variant) { 148 | C.g_action_activate(v.native(), (*C.GVariant)(parameter.ToGVariant())) 149 | } 150 | 151 | //gboolean 152 | //g_action_parse_detailed_name (const gchar *detailed_name, 153 | // gchar **action_name, 154 | // GVariant **target_value, 155 | // GError **error); 156 | //Parses a detailed action name into its separate name and target components. 157 | //Detailed action names can have three formats. 158 | //The first format is used to represent an action name with no target value and consists of just an action name containing no whitespace nor the characters ':', '(' or ')'. For example: "app.action". 159 | //The second format is used to represent an action with a target value that is a non-empty string consisting only of alphanumerics, plus '-' and '.'. In that case, the action name and target value are separated by a double colon ("::"). For example: "app.action::target". 160 | //The third format is used to represent an action with any type of target value, including strings. The target value follows the action name, surrounded in parens. For example: "app.action(42)". The target value is parsed using g_variant_parse(). If a tuple-typed value is desired, it must be specified in the same way, resulting in two sets of parens, for example: "app.action((1,2,3))". A string target can be specified this way as well: "app.action('target')". For strings, this third format must be used if * target value is empty or contains characters other than alphanumerics, '-' and '.'. 161 | 162 | //gchar * 163 | //g_action_print_detailed_name (const gchar *action_name, 164 | // GVariant *target_value); 165 | //Formats a detailed action name from action_name and target_value . 166 | //It is an error to call this function with an invalid action name. 167 | //This function is the opposite of g_action_parse_detailed_action_name(). It will produce a string that can be parsed back to the action_name and target_value by that function. 168 | //See that function for the types of strings that will be printed by this function. 169 | func (v *Action) ActionPrintDetailedName(action_name string, target_value *glib.Variant) string { 170 | cstr := C.CString(action_name) 171 | defer C.free(unsafe.Pointer(cstr)) 172 | cstrRes := (*C.char)(C.g_action_print_detailed_name((*C.gchar)(cstr), (*C.GVariant)(target_value.ToGVariant()))) 173 | return C.GoString(cstrRes) 174 | } 175 | -------------------------------------------------------------------------------- /GActionMap.go: -------------------------------------------------------------------------------- 1 | //GActionMap — Interface for Action containers 2 | 3 | // +build 4 | package gio_2_32 5 | 6 | // #cgo pkg-config: gio-2.0 glib-2.0 7 | // #include 8 | // #include "gio.go.h" 9 | import "C" 10 | 11 | import ( 12 | "log" 13 | "unsafe" 14 | 15 | "github.com/gotk3/gotk3/glib" 16 | ) 17 | 18 | func init() { 19 | tm := []glib.TypeMarshaler{ 20 | // Enums 21 | 22 | // Objects/Interfaces 23 | 24 | {glib.Type(C.g_action_map_get_type()), marshalActionMap}, 25 | 26 | // Boxed 27 | 28 | } 29 | glib.RegisterGValueMarshalers(tm) 30 | } 31 | 32 | /* 33 | * GActionMap 34 | */ 35 | 36 | // ActionMap is a representation of GIO's GActionMap. 37 | type ActionMap struct { 38 | *glib.Object 39 | } 40 | 41 | // native returns a pointer to the underlying GActionMap. 42 | func (v *ActionMap) native() *C.GActionMap { 43 | if v == nil || v.GObject == nil { 44 | return nil 45 | } 46 | p := unsafe.Pointer(v.GObject) 47 | return C.toGActionMap(p) 48 | } 49 | 50 | func marshalActionMap(p uintptr) (interface{}, error) { 51 | c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p))) 52 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 53 | return wrapActionMap(obj), nil 54 | } 55 | 56 | func wrapActionMap(obj *glib.Object) *ActionMap { 57 | return &ActionMap{obj} 58 | } 59 | 60 | func (v *ActionMap) toActionMap() *C.GActionMap { 61 | if v == nil { 62 | return nil 63 | } 64 | return C.toGActionMap(unsafe.Pointer(v.GObject)) 65 | } 66 | 67 | func convertToActionMap(c *C.GActionMap) *ActionMap { 68 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 69 | return wrapActionMap(obj) 70 | } 71 | 72 | //GAction * 73 | //g_action_map_lookup_action (GActionMap *action_map, 74 | // const gchar *action_name); 75 | //Looks up the action with the name action_name in action_map . 76 | //If no such action exists, returns NULL. 77 | func (v *ActionMap) LookAction(action_name string) *Action { 78 | cstr := C.CString(action_name) 79 | defer C.free(unsafe.Pointer(cstr)) 80 | c := C.g_action_map_lookup_action(v.native(), (*C.gchar)(cstr)) 81 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 82 | return wrapAction(obj) 83 | } 84 | 85 | //g_action_map_add_action_entries () 86 | //void 87 | //g_action_map_add_action_entries (GActionMap *action_map, 88 | // const GActionEntry *entries, 89 | // gint n_entries, 90 | // gpointer user_data); 91 | //A convenience function for creating multiple GSimpleAction instances and adding them to a GActionMap. 92 | //Each action is constructed as per one GActionEntry. 93 | func (v *ActionMap) AddActionEntries(entries []ActionEntry, user_data interface{}) { 94 | gEntries := make([]C.GActionEntry, len(entries)) 95 | for i := 0; i < len(entries); i++ { 96 | gEntries[i].name = (*C.gchar)(C.CString(entries[i].Name)) 97 | defer C.free(unsafe.Pointer(gEntries[i].name)) 98 | if len(entries[i].ParameterType) == 0 { 99 | gEntries[i].parameter_type = nil 100 | } else { 101 | gEntries[i].parameter_type = (*C.gchar)(C.CString(entries[i].ParameterType)) 102 | defer C.free(unsafe.Pointer(gEntries[i].parameter_type)) 103 | } 104 | if len(entries[i].State) == 0 { 105 | gEntries[i].state = nil 106 | } else { 107 | gEntries[i].state = (*C.gchar)(C.CString(entries[i].State)) 108 | defer C.free(unsafe.Pointer(gEntries[i].state)) 109 | } 110 | gEntries[i].activate = nil /*func (a *C.GSimpleAction, p *C.GVariant, u C.gpointer){ 111 | entries[i].Activate(nil,nil,nil) 112 | } //entries[i].Activate //FIXME*/ 113 | gEntries[i].change_state = nil //entries[i].ChangeState //FIXME 114 | 115 | defer C.free(unsafe.Pointer(gEntries[i].state)) 116 | } 117 | //FIXME copy entries into gEntries 118 | C.g_action_map_add_action_entries(v.native(), (*C.GActionEntry)(unsafe.Pointer(&gEntries[0])), (C.gint)(len(entries)), (C.gpointer)(unsafe.Pointer(&user_data))) 119 | 120 | for i := 0; i < len(entries); i++ { 121 | action := v.LookAction(entries[i].Name) 122 | if action == nil { 123 | log.Println(entries[i].Name, " not an action -> not connected") 124 | } else { 125 | if entries[i].Activate != nil { 126 | _, err := action.Connect("activate", entries[i].Activate, nil) 127 | if err != nil { 128 | log.Println(entries[i].Name, " connect to activate signal error ", err.Error()) 129 | } 130 | } 131 | if entries[i].ChangeState != nil { 132 | _, err := action.Connect("change_state", entries[i].ChangeState, nil) 133 | if err != nil { 134 | log.Println(entries[i].Name, " connect to change_state signal error ", err.Error()) 135 | } 136 | } 137 | } 138 | } 139 | 140 | } 141 | 142 | //void 143 | //g_action_map_add_action (GActionMap *action_map, 144 | // GAction *action); 145 | //Adds an action to the action_map . 146 | //If the action map already contains an action with the same name as action then the old action is dropped from the action map. 147 | //The action map takes its own reference on action . 148 | func (v *ActionMap) AddAction(action *Action) { 149 | C.g_action_map_add_action(v.native(), action.native()) 150 | } 151 | 152 | //void 153 | //g_action_map_remove_action (GActionMap *action_map, 154 | // const gchar *action_name); 155 | //Removes the named action from the action map. 156 | //If no action of this name is in the map then nothing happens. 157 | func (v *ActionMap) RemoveAction(action_name string) { 158 | cstr := C.CString(action_name) 159 | defer C.free(unsafe.Pointer(cstr)) 160 | C.g_action_map_remove_action(v.native(), (*C.gchar)(cstr)) 161 | } 162 | 163 | /* 164 | * GActionEntry 165 | */ 166 | 167 | type ActionEntry struct { 168 | Name string //the name of the action 169 | Activate func(action *SimpleAction, parameter *glib.Variant) //the callback to connect to the "activate" signal of the action. Since GLib 2.40, this can be NULL for stateful actions, in which case the default handler is used. For boolean-stated actions with no parameter, this is a toggle. For other state types (and parameter type equal to the state type) this will be a function that just calls change_state (which you should provide). 170 | ParameterType string //the type of the parameter that must be passed to the activate function for this action, given as a single GVariant type string (or NULL for no parameter) 171 | State string //the initial state for this action, given in GVariant text format. The state is parsed with no extra type information, so type tags must be added to the string if they are necessary. Stateless actions should give NULL here. 172 | ChangeState func(action *SimpleAction, parameter *glib.Variant) //the callback to connect to the "change-state" signal of the action. All stateful actions should provide a handler here; stateless actions should not. 173 | } 174 | -------------------------------------------------------------------------------- /GApplication.go: -------------------------------------------------------------------------------- 1 | //GApplication — Core application class 2 | package gio 3 | 4 | // #cgo pkg-config: gio-2.0 glib-2.0 5 | // #include 6 | // #include "gio.go.h" 7 | import "C" 8 | 9 | import ( 10 | "runtime" 11 | "unsafe" 12 | 13 | "github.com/gotk3/gotk3/glib" 14 | ) 15 | 16 | /* 17 | * GApplication 18 | */ 19 | 20 | // Handler type without params 21 | type OnNoParamHandler func() 22 | 23 | // Handler type with files and hint for open signal 24 | type OnApplicationOpenFileHandler func([]*File, string) 25 | 26 | // IWidget is an interface type implemented by all structs 27 | // embedding a Widget. It is meant to be used as an argument type 28 | // for wrapper functions that wrap around a C GTK function taking a 29 | // GtkWidget. 30 | //type IApplication interface { 31 | // toGApplication() *C.GApplication 32 | //} 33 | 34 | // Application is a representation of GIO's GApplication. 35 | type Application struct { 36 | *glib.Object 37 | 38 | activateHandlers []OnNoParamHandler //Slice of handlers to call when activate signal appends 39 | shutdownHandlers []OnNoParamHandler //Slice of handlers to call when shutdown signal appends 40 | startupHandlers []OnNoParamHandler //Slice of handlers to call when startup signal appends 41 | openHandlers []OnApplicationOpenFileHandler //Slice of handlers to call when open signal appends 42 | } 43 | 44 | // native returns a pointer to the underlying GApplication. 45 | func (v *Application) native() *C.GApplication { 46 | if v == nil || v.GObject == nil { 47 | return nil 48 | } 49 | p := unsafe.Pointer(v.GObject) 50 | return C.toGApplication(p) 51 | } 52 | 53 | func marshalApplication(p uintptr) (interface{}, error) { 54 | c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p))) 55 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 56 | return wrapApplication(obj), nil 57 | } 58 | 59 | func wrapApplication(obj *glib.Object) *Application { 60 | return &Application{Object: obj} 61 | } 62 | 63 | func (v *Application) ToGApplication() *C.GApplication { 64 | if v == nil { 65 | return nil 66 | } 67 | return C.toGApplication(unsafe.Pointer(v.GObject)) 68 | } 69 | 70 | //gboolean 71 | //g_application_id_is_valid (const gchar *application_id); 72 | 73 | //Checks if application_id is a valid application identifier. 74 | //A valid ID is required for calls to g_application_new() and g_application_set_application_id(). 75 | //For convenience, the restrictions on application identifiers are reproduced here: 76 | //*Application identifiers must contain only the ASCII characters "A-Z[0-9]_-." and must not begin with a digit. 77 | //*Application identifiers must contain at least one '.' (period) character (and thus at least three elements). 78 | //*Application identifiers must not begin or end with a '.' (period) character. 79 | //*Application identifiers must not contain consecutive '.' (period) characters. 80 | //*Application identifiers must not exceed 255 characters. 81 | func ApplicationIdIsValid(application_id string) bool { 82 | cstr := C.CString(application_id) 83 | defer C.free(unsafe.Pointer(cstr)) 84 | c := C.g_application_id_is_valid((*C.gchar)(cstr)) 85 | 86 | return gobool(c) 87 | } 88 | 89 | //GApplication * 90 | //g_application_new (const gchar *application_id, 91 | // GApplicationFlags flags); 92 | 93 | //Creates a new GApplication instance. 94 | //If non-NULL, the application id must be valid. See g_application_id_is_valid(). 95 | //If no application ID is given then some features of GApplication (most notably application uniqueness) will be disabled. 96 | func ApplicationNew(application_id string, flags ApplicationFlags) (*Application, error) { 97 | cstr := C.CString(application_id) 98 | defer C.free(unsafe.Pointer(cstr)) 99 | c := C.g_application_new((*C.gchar)(cstr), C.GApplicationFlags(flags)) 100 | if c == nil { 101 | return nil, nilPtrErr 102 | } 103 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 104 | app := wrapApplication(obj) 105 | obj.Ref() 106 | runtime.SetFinalizer(obj, (*glib.Object).Unref) 107 | return app, nil 108 | } 109 | 110 | //const gchar * 111 | //g_application_get_application_id (GApplication *application); 112 | 113 | //Gets the unique identifier for application . 114 | func (v *Application) GetApplicationId() string { 115 | cstr := (*C.char)(C.g_application_get_application_id(v.native())) 116 | defer C.free(unsafe.Pointer(cstr)) 117 | return C.GoString(cstr) 118 | } 119 | 120 | //void 121 | //g_application_set_application_id (GApplication *application, 122 | // const gchar *application_id); 123 | 124 | //Sets the unique identifier for application . 125 | //The application id can only be modified if application has not yet been registered. 126 | //If non-NULL, the application id must be valid. See g_application_id_is_valid(). 127 | func (v *Application) SetApplicationId(application_id string) { 128 | cstr := C.CString(application_id) 129 | defer C.free(unsafe.Pointer(cstr)) 130 | C.g_application_set_application_id(v.native(), (*C.gchar)(cstr)) 131 | } 132 | 133 | //guint 134 | //g_application_get_inactivity_timeout (GApplication *application); 135 | 136 | //Gets the current inactivity timeout for the application. 137 | //This is the amount of time (in milliseconds) after the last call to g_application_release() before the application stops running. 138 | func (v *Application) GetInactivityTimeout() uint { 139 | c := C.g_application_get_inactivity_timeout(v.native()) 140 | return uint(c) 141 | } 142 | 143 | //void 144 | //g_application_set_inactivity_timeout (GApplication *application, 145 | // guint inactivity_timeout); 146 | 147 | //Sets the current inactivity timeout for the application. 148 | //This is the amount of time (in milliseconds) after the last call to g_application_release() before the application stops running. 149 | //This call has no side effects of its own. The value set here is only used for next time g_application_release() drops the use count to zero. Any timeouts currently in progress are not impacted. 150 | func (v *Application) SetInactivityTimeout(inactivity_timeout uint) { 151 | C.g_application_set_inactivity_timeout(v.native(), (C.guint)(inactivity_timeout)) 152 | } 153 | 154 | //GApplicationFlags 155 | //g_application_get_flags (GApplication *application); 156 | 157 | //Gets the flags for application . 158 | //See GApplicationFlags. 159 | func (v *Application) GetFlags() ApplicationFlags { 160 | c := C.g_application_get_flags(v.native()) 161 | return (ApplicationFlags)(c) 162 | } 163 | 164 | //void 165 | //g_application_set_flags (GApplication *application, 166 | // GApplicationFlags flags); 167 | 168 | //Sets the flags for application . 169 | //The flags can only be modified if application has not yet been registered. 170 | //See GApplicationFlags. 171 | func (v *Application) SetFlags(flags ApplicationFlags) { 172 | C.g_application_set_flags(v.native(), C.GApplicationFlags(flags)) 173 | } 174 | 175 | //const gchar * 176 | //g_application_get_resource_base_path (GApplication *application); 177 | 178 | //Gets the resource base path of application . 179 | //See g_application_set_resource_base_path() for more information. 180 | func (v *Application) GetResourceBasePath() string { 181 | cstr := (*C.char)(C.g_application_get_resource_base_path(v.native())) 182 | defer C.free(unsafe.Pointer(cstr)) 183 | return C.GoString(cstr) 184 | } 185 | 186 | //void 187 | //g_application_set_resource_base_path (GApplication *application, 188 | // const gchar *resource_path); 189 | 190 | //Sets (or unsets) the base resource path of application . 191 | //The path is used to automatically load various application resources such as menu layouts and File descriptions. The various types of resources will be found at fixed names relative to the given base path. 192 | //By default, the resource base path is determined from the application ID by prefixing '/' and replacing each '.' with '/'. This is done at the time that the GApplication object is constructed. Changes to the application ID after that point will not have an impact on the resource base path. 193 | //As an example, if the application has an ID of "org.example.app" then the default resource base path will be "/org/example/app". If this is a GtkApplication (and you have not manually changed the path) then Gtk will then search for the menus of the application at "/org/example/app/gtk/menus.ui". 194 | //See GResource for more information about adding resources to your application. 195 | //You can disable automatic resource loading functionality by setting the path to NULL. 196 | //Changing the resource base path once the application is running is not recommended. The point at which the resource path is consulted for forming paths for various purposes is unspecified. 197 | func (v *Application) SetResourceBasePath(resource_path string) { 198 | cstr := C.CString(resource_path) 199 | defer C.free(unsafe.Pointer(cstr)) 200 | C.g_application_set_resource_base_path(v.native(), (*C.gchar)(cstr)) 201 | } 202 | 203 | //GDBusConnection * 204 | //g_application_get_dbus_connection (GApplication *application); 205 | 206 | //Gets the GDBusConnection being used by the application, or NULL. 207 | //If GApplication is using its D-Bus backend then this function will return the GDBusConnection being used for uniqueness and communication with the desktop environment and other instances of the application. 208 | //If GApplication is not using D-Bus then this function will return NULL. This includes the situation where the D-Bus backend would normally be in use but we were unable to connect to the bus. 209 | //This function must not be called before the application has been registered. See g_application_get_is_registered(). 210 | func (v *Application) GetDBusConnection() *DBusConnection { 211 | c := C.g_application_get_dbus_connection(v.native()) 212 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 213 | return wrapDBusConnection(obj) 214 | } 215 | 216 | //const gchar * 217 | //g_application_get_dbus_object_path (GApplication *application); 218 | 219 | //Gets the D-Bus object path being used by the application, or NULL. 220 | //If GApplication is using its D-Bus backend then this function will return the D-Bus object path that GApplication is using. If the application is the primary instance then there is an object published at this path. If the application is not the primary instance then the result of this function is undefined. 221 | //If GApplication is not using D-Bus then this function will return NULL. This includes the situation where the D-Bus backend would normally be in use but we were unable to connect to the bus. 222 | //This function must not be called before the application has been registered. See g_application_get_is_registered(). 223 | func (v *Application) GetDBusObjectPath() string { 224 | cstr := (*C.char)(C.g_application_get_dbus_object_path(v.native())) 225 | defer C.free(unsafe.Pointer(cstr)) 226 | return C.GoString(cstr) 227 | } 228 | 229 | //DEPRECATED void g_application_set_File_group () 230 | 231 | //gboolean 232 | //g_application_get_is_registered (GApplication *application); 233 | 234 | //Checks if application is registered. 235 | //An application is registered if g_application_register() has been successfully called. 236 | func (v *Application) GetIsRegistered() bool { 237 | c := C.g_application_get_is_registered(v.native()) 238 | return gobool(c) 239 | } 240 | 241 | //gboolean 242 | //g_application_get_is_remote (GApplication *application); 243 | 244 | //Checks if application is remote. 245 | //If application is remote then it means that another instance of application already exists (the 'primary' instance). Calls to perform Files on application will result in the Files being performed by the primary instance. 246 | //The value of this property cannot be accessed before g_application_register() has been called. See g_application_get_is_registered(). 247 | func (v *Application) GetIsRemote() bool { 248 | c := C.g_application_get_is_remote(v.native()) 249 | return gobool(c) 250 | } 251 | 252 | //gboolean 253 | //g_application_register (GApplication *application, 254 | // GCancellable *cancellable, 255 | // GError **error); 256 | 257 | //Attempts registration of the application. 258 | //This is the point at which the application discovers if it is the primary instance or merely acting as a remote for an already-existing primary instance. This is implemented by attempting to acquire the application identifier as a unique bus name on the session bus using GDBus. 259 | //If there is no application ID or if G_APPLICATION_NON_UNIQUE was given, then this process will always become the primary instance. 260 | //Due to the internal architecture of GDBus, method calls can be dispatched at any time (even if a main loop is not running). For this reason, you must ensure that any object paths that you wish to register are registered before calling this function. 261 | //If the application has already been registered then TRUE is returned with no work performed. 262 | //The “startup” signal is emitted if registration succeeds and application is the primary instance (including the non-unique case). 263 | //In the event of an error (such as cancellable being cancelled, or a failure to connect to the session bus), FALSE is returned and error is set appropriately. 264 | //Note: the return value of this function is not an indicator that this instance is or is not the primary instance of the application. See g_application_get_is_remote() for that. 265 | func (v *Application) Register(cancellable *Cancellable) bool { 266 | var gerror **C.GError 267 | c := C.g_application_register(v.native(), cancellable.native(), gerror) 268 | return gobool(c) 269 | } 270 | 271 | //void 272 | //g_application_hold (GApplication *application); 273 | 274 | //Increases the use count of application . 275 | //Use this function to indicate that the application has a reason to continue to run. For example, g_application_hold() is called by GTK+ when a toplevel window is on the screen. 276 | //To cancel the hold, call g_application_release(). 277 | func (v *Application) Hold() { 278 | C.g_application_hold(v.native()) 279 | } 280 | 281 | //void 282 | //g_application_release (GApplication *application); 283 | 284 | //Decrease the use count of application . 285 | //When the use count reaches zero, the application will stop running. 286 | //Never call this function except to cancel the effect of a previous call to g_application_hold(). 287 | func (v *Application) Release() { 288 | C.g_application_release(v.native()) 289 | } 290 | 291 | //void 292 | //g_application_quit (GApplication *application); 293 | 294 | //Immediately quits the application. 295 | //Upon return to the mainloop, g_application_run() will return, calling only the 'shutdown' function before doing so. 296 | //The hold count is ignored. 297 | //The result of calling g_application_run() again after it returns is unspecified. 298 | func (v *Application) Quit() { 299 | C.g_application_quit(v.native()) 300 | } 301 | 302 | //void 303 | //g_application_activate (GApplication *application); 304 | 305 | //Activates the application. 306 | //In essence, this results in the “activate” signal being emitted in the primary instance. 307 | //The application must be registered before calling this function. 308 | func (v *Application) Activate() { 309 | C.g_application_activate(v.native()) 310 | } 311 | 312 | //void 313 | //g_application_open (GApplication *application, 314 | // GFile **files, 315 | // gint n_files, 316 | // const gchar *hint); 317 | 318 | //Opens the given files. 319 | //In essence, this results in the “open” signal being emitted in the primary instance. 320 | //n_files must be greater than zero. 321 | //hint is simply passed through to the ::open signal. It is intended to be used by applications that have multiple modes for opening files (eg: "view" vs "edit", etc). Unless you have a need for this functionality, you should use "". 322 | //The application must be registered before calling this function and it must have the G_APPLICATION_HANDLES_OPEN flag set. 323 | func (v *Application) Open(files []*File, hint string) { 324 | gfiles := C.alloc_files(C.int(len(files))) 325 | for n, val := range files { 326 | C.set_file(gfiles, C.int(n), val.native()) 327 | } 328 | defer C.g_free(C.gpointer(gfiles)) 329 | cstr_hint := C.CString(hint) 330 | defer C.free(unsafe.Pointer(cstr_hint)) 331 | C.g_application_open(v.native(), gfiles, C.gint(len(files)), (*C.gchar)(cstr_hint)) 332 | } 333 | 334 | //void 335 | //g_application_send_notification (GApplication *application, 336 | // const gchar *id, 337 | // GNotification *notification); 338 | 339 | //Sends a notification on behalf of application to the desktop shell. There is no guarantee that the notification is displayed immediately, or even at all. 340 | //Notifications may persist after the application exits. It will be D-Bus-activated when the notification or one of its Files is activated. 341 | //Modifying notification after this call has no effect. However, the object can be reused for a later call to this function. 342 | //id may be any string that uniquely identifies the event for the application. It does not need to be in any special format. For example, "new-message" might be appropriate for a notification about new messages. 343 | //If a previous notification was sent with the same id , it will be replaced with notification and shown again as if it was a new notification. This works even for notifications sent from a previous execution of the application, as long as id is the same string. 344 | //id may be NULL, but it is impossible to replace or withdraw notifications without an id. 345 | //If notification is no longer relevant, it can be withdrawn with g_application_withdraw_notification(). 346 | func (v *Application) SendNotification(id string, notification *Notification) { 347 | cstr := C.CString(id) 348 | defer C.free(unsafe.Pointer(cstr)) 349 | C.g_application_send_notification(v.native(), (*C.gchar)(cstr), notification.native()) 350 | } 351 | 352 | //void 353 | //g_application_withdraw_notification (GApplication *application, 354 | // const gchar *id); 355 | 356 | //Withdraws a notification that was sent with g_application_send_notification(). 357 | //This call does nothing if a notification with id doesn't exist or the notification was never sent. 358 | //This function works even for notifications sent in previous executions of this application, as long id is the same as it was for the sent notification. 359 | //Note that notifications are dismissed when the user clicks on one of the buttons in a notification or triggers its default File, so there is no need to explicitly withdraw the notification in that case. 360 | func (v *Application) WithdrawNotification(id string) { 361 | cstr := C.CString(id) 362 | defer C.free(unsafe.Pointer(cstr)) 363 | C.g_application_withdraw_notification(v.native(), (*C.gchar)(cstr)) 364 | } 365 | 366 | //int 367 | //g_application_run (GApplication *application, 368 | // int argc, 369 | // char **argv); 370 | 371 | //Runs the application. 372 | //This function is intended to be run from main() and its return value is intended to be returned by main(). Although you are expected to pass the argc , argv parameters from main() to this function, it is possible to pass NULL if argv is not available or commandline handling is not required. Note that on Windows, argc and argv are ignored, and g_win32_get_command_line() is called internally (for proper support of Unicode commandline arguments). 373 | //GApplication will attempt to parse the commandline arguments. You can add commandline flags to the list of recognised options by way of g_application_add_main_option_entries(). After this, the “handle-local-options” signal is emitted, from which the application can inspect the values of its GOptionEntrys. 374 | //“handle-local-options” is a good place to handle options such as --version, where an immediate reply from the local process is desired (instead of communicating with an already-running instance). A “handle-local-options” handler can stop further processing by returning a non-negative value, which then becomes the exit status of the process. 375 | //What happens next depends on the flags: if G_APPLICATION_HANDLES_COMMAND_LINE was specified then the remaining commandline arguments are sent to the primary instance, where a “command-line” signal is emitted. Otherwise, the remaining commandline arguments are assumed to be a list of files. If there are no files listed, the application is activated via the “activate” signal. If there are one or more files, and G_APPLICATION_HANDLES_OPEN was specified then the files are opened via the “open” signal. 376 | //If you are interested in doing more complicated local handling of the commandline then you should implement your own GApplication subclass and override local_command_line(). In this case, you most likely want to return TRUE from your local_command_line() implementation to suppress the default handling. See gapplication-example-cmdline2.c for an example. 377 | //If, after the above is done, the use count of the application is zero then the exit status is returned immediately. If the use count is non-zero then the default main context is iterated until the use count falls to zero, at which point 0 is returned. 378 | //If the G_APPLICATION_IS_SERVICE flag is set, then the service will run for as much as 10 seconds with a use count of zero while waiting for the message that caused the activation to arrive. After that, if the use count falls to zero the application will exit immediately, except in the case that g_application_set_inactivity_timeout() is in use. 379 | //This function sets the prgname (g_set_prgname()), if not already set, to the basename of argv[0]. 380 | //Since 2.40, applications that are not explicitly flagged as services or launchers (ie: neither G_APPLICATION_IS_SERVICE or G_APPLICATION_IS_LAUNCHER are given as flags) will check (from the default handler for local_command_line) if "--gapplication-service" was given in the command line. If this flag is present then normal commandline processing is interrupted and the G_APPLICATION_IS_SERVICE flag is set. This provides a "compromise" solution whereby running an application directly from the commandline will invoke it in the normal way (which can be useful for debugging) while still allowing applications to be D-Bus activated in service mode. The D-Bus service file should invoke the executable with "--gapplication-service" as the sole commandline argument. This approach is suitable for use by most graphical applications but should not be used from applications like editors that need precise control over when processes invoked via the commandline will exit and what their exit status will be. 381 | func (v *Application) Run(args []string) (ret int) { 382 | if args != nil { 383 | argc := C.int(len(args)) 384 | argv := make([](*C.char), argc) 385 | for i, arg := range args { 386 | argv[i] = C.CString(arg) 387 | defer C.free(unsafe.Pointer(argv[i])) 388 | } 389 | ret = int(C.g_application_run(v.native(), argc, (**C.char)(unsafe.Pointer(&argv[0])))) 390 | } else { 391 | ret = int(C.g_application_run(v.native(), 0, nil)) 392 | } 393 | return 394 | } 395 | 396 | //void g_application_add_main_option_entries () 397 | //void g_application_add_main_option () 398 | //void g_application_add_option_group () 399 | //void g_application_set_default () 400 | //GApplication * g_application_get_default () 401 | //void g_application_mark_busy () 402 | //void g_application_unmark_busy () 403 | //gboolean g_application_get_is_busy () 404 | //void g_application_bind_busy_property () 405 | //void g_application_unbind_busy_property () 406 | 407 | //---- EVENTS ----// 408 | 409 | //The ::activate signal is emitted on the primary instance when an activation occurs. See g_application_activate(). 410 | func (v *Application) OnActivateAdd(handler OnNoParamHandler) { 411 | if len(v.activateHandlers) <= 0 { 412 | v.Connect("activate", func(app *Application) { 413 | for _, h := range v.activateHandlers { 414 | h() 415 | } 416 | }) 417 | } 418 | v.activateHandlers = append(v.activateHandlers, handler) 419 | } 420 | 421 | //The ::shutdown signal is emitted only on the registered primary instance immediately after the main loop terminates. 422 | func (v *Application) OnShutdownAdd(handler OnNoParamHandler) { 423 | if len(v.shutdownHandlers) <= 0 { 424 | v.Connect("activate", func(app *Application) { 425 | for _, h := range v.shutdownHandlers { 426 | h() 427 | } 428 | }) 429 | } 430 | v.shutdownHandlers = append(v.shutdownHandlers, handler) 431 | } 432 | 433 | //The ::startup signal is emitted on the primary instance immediately after registration. See g_application_register(). 434 | func (v *Application) OnStartupAdd(handler OnNoParamHandler) { 435 | if len(v.startupHandlers) <= 0 { 436 | v.Connect("activate", func(app *Application) { 437 | for _, h := range v.startupHandlers { 438 | h() 439 | } 440 | }) 441 | } 442 | v.startupHandlers = append(v.startupHandlers, handler) 443 | } 444 | 445 | //The ::open signal is emitted on the primary instance when there are files to open. See g_application_open() for more information. 446 | func (v *Application) OnOpenAdd(handler OnApplicationOpenFileHandler) { 447 | if len(v.openHandlers) <= 0 { 448 | v.Connect("open", func(app *Application, gfiles unsafe.Pointer, nfiles int, hint string) { 449 | files := make([]*File, nfiles) 450 | for i := 0; i < nfiles; i++ { 451 | files[i] = convertToFile(C.get_file(gfiles, (C.int)(i))) 452 | } 453 | for _, h := range v.openHandlers { 454 | h(files, hint) 455 | } 456 | }) 457 | } 458 | v.openHandlers = append(v.openHandlers, handler) 459 | } 460 | -------------------------------------------------------------------------------- /GApplicationFlags.go: -------------------------------------------------------------------------------- 1 | package gio 2 | 3 | // #cgo pkg-config: gio-2.0 glib-2.0 4 | // #include 5 | // #include "gio.go.h" 6 | import "C" 7 | import "unsafe" 8 | 9 | 10 | /* 11 | * GApplicationFlags 12 | * Flags used to define the behaviour of a GApplication. 13 | */ 14 | type ApplicationFlags int 15 | 16 | const ( 17 | APPLICATION_FLAGS_NONE ApplicationFlags = C.G_APPLICATION_FLAGS_NONE //Default 18 | APPLICATION_IS_SERVICE ApplicationFlags = C.G_APPLICATION_IS_SERVICE //Run as a service. In this mode, registration fails if the service is already running, and the application will initially wait up to 10 seconds for an initial activation message to arrive. 19 | APPLICATION_IS_LAUNCHER ApplicationFlags = C.G_APPLICATION_IS_LAUNCHER //Don't try to become the primary instance. 20 | APPLICATION_HANDLES_OPEN ApplicationFlags = C.G_APPLICATION_HANDLES_OPEN //This application handles opening files (in the primary instance). Note that this flag only affects the default implementation of local_command_line(), and has no effect if G_APPLICATION_HANDLES_COMMAND_LINE is given. See g_application_run() for details. 21 | APPLICATION_HANDLES_COMMAND_LINE ApplicationFlags = C.G_APPLICATION_HANDLES_COMMAND_LINE //This application handles command line arguments (in the primary instance). Note that this flag only affect the default implementation of local_command_line(). See g_application_run() for details. 22 | APPLICATION_SEND_ENVIRONMENT ApplicationFlags = C.G_APPLICATION_SEND_ENVIRONMENT //Send the environment of the launching process to the primary instance. Set this flag if your application is expected to behave differently depending on certain environment variables. For instance, an editor might be expected to use the GIT_COMMITTER_NAME environment variable when editing a git commit message. The environment is available to the “command-line” signal handler, via g_application_command_line_getenv(). 23 | APPLICATION_NON_UNIQUE ApplicationFlags = C.G_APPLICATION_NON_UNIQUE //Make no attempts to do any of the typical single-instance application negotiation, even if the application ID is given. The application neither attempts to become the owner of the application ID nor does it check if an existing owner already exists. Everything occurs in the local process. Since: 2.30. 24 | ) 25 | 26 | func marshalApplicationFlags(p uintptr) (interface{}, error) { 27 | c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p))) 28 | return ApplicationFlags(c), nil 29 | } 30 | -------------------------------------------------------------------------------- /GCancellable.go: -------------------------------------------------------------------------------- 1 | //GCancellable 2 | package gio 3 | 4 | // #cgo pkg-config: gio-2.0 glib-2.0 5 | // #include 6 | // #include "gio.go.h" 7 | import "C" 8 | 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/gotk3/gotk3/glib" 13 | ) 14 | 15 | /* 16 | * GCancellable 17 | */ 18 | 19 | // Cancellable is a representation of GIO's GCancellable. 20 | type Cancellable struct { 21 | *glib.Object 22 | } 23 | 24 | // native returns a pointer to the underlying GCancellable. 25 | func (v *Cancellable) native() *C.GCancellable { 26 | if v == nil || v.GObject == nil { 27 | return nil 28 | } 29 | p := unsafe.Pointer(v.GObject) 30 | return C.toGCancellable(p) 31 | } 32 | 33 | func marshalCancellable(p uintptr) (interface{}, error) { 34 | c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p))) 35 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 36 | return wrapCancellable(obj), nil 37 | } 38 | 39 | func wrapCancellable(obj *glib.Object) *Cancellable { 40 | return &Cancellable{obj} 41 | } 42 | 43 | func (v *Cancellable) toCancellable() *C.GCancellable { 44 | if v == nil { 45 | return nil 46 | } 47 | return C.toGCancellable(unsafe.Pointer(v.GObject)) 48 | } 49 | -------------------------------------------------------------------------------- /GDBusConnection.go: -------------------------------------------------------------------------------- 1 | //GDBusConnection 2 | package gio 3 | 4 | // #cgo pkg-config: gio-2.0 glib-2.0 5 | // #include 6 | // #include "gio.go.h" 7 | import "C" 8 | 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/gotk3/gotk3/glib" 13 | ) 14 | 15 | /* 16 | * GDBusConnection 17 | */ 18 | 19 | // DBusConnection is a representation of GIO's GDBusConnection. 20 | type DBusConnection struct { 21 | *glib.Object 22 | } 23 | 24 | // native returns a pointer to the underlying GDBusConnection. 25 | func (v *DBusConnection) native() *C.GDBusConnection { 26 | if v == nil || v.GObject == nil { 27 | return nil 28 | } 29 | p := unsafe.Pointer(v.GObject) 30 | return C.toGDBusConnection(p) 31 | } 32 | 33 | func marshalDBusConnection(p uintptr) (interface{}, error) { 34 | c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p))) 35 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 36 | return wrapDBusConnection(obj), nil 37 | } 38 | 39 | func wrapDBusConnection(obj *glib.Object) *DBusConnection { 40 | return &DBusConnection{obj} 41 | } 42 | 43 | func (v *DBusConnection) toDBusConnection() *C.GDBusConnection { 44 | if v == nil { 45 | return nil 46 | } 47 | return C.toGDBusConnection(unsafe.Pointer(v.GObject)) 48 | } 49 | -------------------------------------------------------------------------------- /GFile.go: -------------------------------------------------------------------------------- 1 | //GFile 2 | package gio 3 | 4 | // #cgo pkg-config: gio-2.0 glib-2.0 5 | // #include 6 | // #include "gio.go.h" 7 | import "C" 8 | 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/gotk3/gotk3/glib" 13 | ) 14 | 15 | /* 16 | * GFile 17 | */ 18 | 19 | // File is a representation of GIO's GFile. 20 | type File struct { 21 | *glib.Object 22 | } 23 | 24 | // native returns a pointer to the underlying GFile. 25 | func (v *File) native() *C.GFile { 26 | if v == nil || v.GObject == nil { 27 | return nil 28 | } 29 | p := unsafe.Pointer(v.GObject) 30 | return C.toGFile(p) 31 | } 32 | 33 | func marshalFile(p uintptr) (interface{}, error) { 34 | c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p))) 35 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 36 | return wrapFile(obj), nil 37 | } 38 | 39 | func wrapFile(obj *glib.Object) *File { 40 | return &File{obj} 41 | } 42 | 43 | func (v *File) toFile() *C.GFile { 44 | if v == nil { 45 | return nil 46 | } 47 | return C.toGFile(unsafe.Pointer(v.GObject)) 48 | } 49 | 50 | func convertToFile(c *C.GFile) *File { 51 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 52 | return wrapFile(obj) 53 | } 54 | 55 | //void (*GFileProgressCallback) () 56 | //gboolean (*GFileReadMoreCallback) () 57 | //void (*GFileMeasureProgressCallback) () 58 | //GFile * g_file_new_for_path () 59 | //GFile * g_file_new_for_uri () 60 | //GFile * g_file_new_for_commandline_arg () 61 | //GFile * g_file_new_for_commandline_arg_and_cwd () 62 | //GFile * g_file_new_tmp () 63 | //GFile * g_file_parse_name () 64 | //GFile * g_file_dup () 65 | //guint g_file_hash () 66 | //gboolean g_file_equal () 67 | 68 | //char * 69 | //g_file_get_basename (GFile *file); 70 | //Gets the base name (the last component of the path) for a given GFile. 71 | //If called for the top level of a system (such as the filesystem root or a uri like sftp://host/) it will return a single directory separator (and on Windows, possibly a drive letter). 72 | //The base name is a byte string (not UTF-8). It has no defined encoding or rules other than it may not contain zero bytes. If you want to use filenames in a user interface you should use the display name that you can get by requesting the G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME attribute with g_file_query_info(). 73 | //This call does no blocking I/O. 74 | func (v *File) GetBasename() string { 75 | if v == nil { 76 | return "" 77 | } 78 | cstr := (*C.char)(C.g_file_get_basename(v.native())) 79 | return C.GoString(cstr) 80 | } 81 | 82 | //char * 83 | //g_file_get_path (GFile *file); 84 | //Gets the local pathname for GFile, if one exists. If non-NULL, this is guaranteed to be an absolute, canonical path. It might contain symlinks. 85 | //This call does no blocking I/O. 86 | func (v *File) GetPath() string { 87 | if v == nil { 88 | return "" 89 | } 90 | cstr := (*C.char)(C.g_file_get_path(v.native())) 91 | return C.GoString(cstr) 92 | } 93 | 94 | //char * 95 | //g_file_get_uri (GFile *file); 96 | //Gets the URI for the file . 97 | //This call does no blocking I/O. 98 | func (v *File) GetUri() string { 99 | if v == nil { 100 | return "" 101 | } 102 | cstr := (*C.char)(C.g_file_get_uri(v.native())) 103 | return C.GoString(cstr) 104 | } 105 | 106 | //char * 107 | //g_file_get_parse_name (GFile *file); 108 | //Gets the parse name of the file . A parse name is a UTF-8 string that describes the file such that one can get the GFile back using g_file_parse_name(). 109 | //This is generally used to show the GFile as a nice full-pathname kind of string in a user interface, like in a location entry. 110 | //For local files with names that can safely be converted to UTF-8 the pathname is used, otherwise the IRI is used (a form of URI that allows UTF-8 characters unescaped). 111 | //This call does no blocking I/O. 112 | func (v *File) GetParseName() string { 113 | if v == nil { 114 | return "" 115 | } 116 | cstr := (*C.char)(C.g_file_get_parse_name(v.native())) 117 | return C.GoString(cstr) 118 | } 119 | 120 | //GFile * g_file_get_parent () 121 | //gboolean g_file_has_parent () 122 | //GFile * g_file_get_child () 123 | //GFile * g_file_get_child_for_display_name () 124 | //gboolean g_file_has_prefix () 125 | //char * g_file_get_relative_path () 126 | //GFile * g_file_resolve_relative_path () 127 | //gboolean g_file_is_native () 128 | //gboolean g_file_has_uri_scheme () 129 | //char * g_file_get_uri_scheme () 130 | //GFileInputStream * g_file_read () 131 | //void g_file_read_async () 132 | //GFileInputStream * g_file_read_finish () 133 | //GFileOutputStream * g_file_append_to () 134 | //GFileOutputStream * g_file_create () 135 | //GFileOutputStream * g_file_replace () 136 | //void g_file_append_to_async () 137 | //GFileOutputStream * g_file_append_to_finish () 138 | //void g_file_create_async () 139 | //GFileOutputStream * g_file_create_finish () 140 | //void g_file_replace_async () 141 | //GFileOutputStream * g_file_replace_finish () 142 | //GFileInfo * g_file_query_info () 143 | //void g_file_query_info_async () 144 | //GFileInfo * g_file_query_info_finish () 145 | //gboolean g_file_query_exists () 146 | //GFileType g_file_query_file_type () 147 | //GFileInfo * g_file_query_filesystem_info () 148 | //void g_file_query_filesystem_info_async () 149 | //GFileInfo * g_file_query_filesystem_info_finish () 150 | //GAppInfo * g_file_query_default_handler () 151 | //gboolean g_file_measure_disk_usage () 152 | //void g_file_measure_disk_usage_async () 153 | //gboolean g_file_measure_disk_usage_finish () 154 | //GMount * g_file_find_enclosing_mount () 155 | //void g_file_find_enclosing_mount_async () 156 | //GMount * g_file_find_enclosing_mount_finish () 157 | //GFileEnumerator * g_file_enumerate_children () 158 | //void g_file_enumerate_children_async () 159 | //GFileEnumerator * g_file_enumerate_children_finish () 160 | //GFile * g_file_set_display_name () 161 | //void g_file_set_display_name_async () 162 | //GFile * g_file_set_display_name_finish () 163 | //gboolean g_file_delete () 164 | //void g_file_delete_async () 165 | //gboolean g_file_delete_finish () 166 | //gboolean g_file_trash () 167 | //void g_file_trash_async () 168 | //gboolean g_file_trash_finish () 169 | //gboolean g_file_copy () 170 | //void g_file_copy_async () 171 | //gboolean g_file_copy_finish () 172 | //gboolean g_file_move () 173 | //gboolean g_file_make_directory () 174 | //void g_file_make_directory_async () 175 | //gboolean g_file_make_directory_finish () 176 | //gboolean g_file_make_directory_with_parents () 177 | //gboolean g_file_make_symbolic_link () 178 | //GFileAttributeInfoList * g_file_query_settable_attributes () 179 | //GFileAttributeInfoList * g_file_query_writable_namespaces () 180 | //gboolean g_file_set_attribute () 181 | //gboolean g_file_set_attributes_from_info () 182 | //void g_file_set_attributes_async () 183 | //gboolean g_file_set_attributes_finish () 184 | //gboolean g_file_set_attribute_string () 185 | //gboolean g_file_set_attribute_byte_string () 186 | //gboolean g_file_set_attribute_uint32 () 187 | //gboolean g_file_set_attribute_int32 () 188 | //gboolean g_file_set_attribute_uint64 () 189 | //gboolean g_file_set_attribute_int64 () 190 | //void g_file_mount_mountable () 191 | //GFile * g_file_mount_mountable_finish () 192 | //void g_file_unmount_mountable () 193 | //gboolean g_file_unmount_mountable_finish () 194 | //void g_file_unmount_mountable_with_operation () 195 | //gboolean g_file_unmount_mountable_with_operation_finish () 196 | //void g_file_eject_mountable () 197 | //gboolean g_file_eject_mountable_finish () 198 | //void g_file_eject_mountable_with_operation () 199 | //gboolean g_file_eject_mountable_with_operation_finish () 200 | //void g_file_start_mountable () 201 | //gboolean g_file_start_mountable_finish () 202 | //void g_file_stop_mountable () 203 | //gboolean g_file_stop_mountable_finish () 204 | //void g_file_poll_mountable () 205 | //gboolean g_file_poll_mountable_finish () 206 | //void g_file_mount_enclosing_volume () 207 | //gboolean g_file_mount_enclosing_volume_finish () 208 | //GFileMonitor * g_file_monitor_directory () 209 | //GFileMonitor * g_file_monitor_file () 210 | //GFileMonitor * g_file_monitor () 211 | 212 | //gboolean 213 | //g_file_load_contents (GFile *file, 214 | // GCancellable *cancellable, 215 | // char **contents, 216 | // gsize *length, 217 | // char **etag_out, 218 | // GError **error); 219 | 220 | //Loads the content of the file into memory. The data is always zero-terminated, but this is not included in the resultant length . The returned content should be freed with g_free() when no longer needed. 221 | //If cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error G_IO_ERROR_CANCELLED will be returned. 222 | func (v *File) LoadContents(cancellable *Cancellable) (text string, ok bool) { 223 | contents := new(*C.char) 224 | length := new(C.gsize) 225 | c := C.g_file_load_contents(v.native(), cancellable.native(), contents, length, nil, nil) 226 | 227 | ok = gobool(c) 228 | text = C.GoStringN((*C.char)(*contents), (C.int)(*length)) 229 | C.g_free((C.gpointer)(contents)) 230 | return 231 | } 232 | 233 | //void g_file_load_contents_async () 234 | //gboolean g_file_load_contents_finish () 235 | //void g_file_load_partial_contents_async () 236 | //gboolean g_file_load_partial_contents_finish () 237 | //gboolean g_file_replace_contents () 238 | //void g_file_replace_contents_async () 239 | //void g_file_replace_contents_bytes_async () 240 | //gboolean g_file_replace_contents_finish () 241 | //gboolean g_file_copy_attributes () 242 | //GFileIOStream * g_file_create_readwrite () 243 | //void g_file_create_readwrite_async () 244 | //GFileIOStream * g_file_create_readwrite_finish () 245 | //GFileIOStream * g_file_open_readwrite () 246 | //void g_file_open_readwrite_async () 247 | //GFileIOStream * g_file_open_readwrite_finish () 248 | //GFileIOStream * g_file_replace_readwrite () 249 | //void g_file_replace_readwrite_async () 250 | //GFileIOStream * g_file_replace_readwrite_finish () 251 | //gboolean g_file_supports_thread_contexts () 252 | -------------------------------------------------------------------------------- /GMenu.go: -------------------------------------------------------------------------------- 1 | //GMenu : GMenu — A simple implementation of GMenuModel 2 | package gio 3 | 4 | // #cgo pkg-config: gio-2.0 glib-2.0 5 | // #include 6 | // #include "gio.go.h" 7 | import "C" 8 | 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/gotk3/gotk3/glib" 13 | ) 14 | 15 | func init() { 16 | tm := []glib.TypeMarshaler{ 17 | // Enums 18 | 19 | // Objects/Interfaces 20 | 21 | {glib.Type(C.g_menu_get_type()), marshalMenu}, 22 | 23 | // Boxed 24 | 25 | } 26 | glib.RegisterGValueMarshalers(tm) 27 | } 28 | 29 | /* 30 | * GMenu 31 | */ 32 | 33 | // Menu is a representation of GIO's GMenu. 34 | type Menu struct { 35 | MenuModel 36 | } 37 | 38 | // native returns a pointer to the underlying GMenu. 39 | func (v *Menu) native() *C.GMenu { 40 | if v == nil || v.GObject == nil { 41 | return nil 42 | } 43 | p := unsafe.Pointer(v.GObject) 44 | return C.toGMenu(p) 45 | } 46 | 47 | func marshalMenu(p uintptr) (interface{}, error) { 48 | c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p))) 49 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 50 | return wrapMenu(obj), nil 51 | } 52 | 53 | func wrapMenu(obj *glib.Object) *Menu { 54 | return &Menu{MenuModel{obj}} 55 | } 56 | 57 | func (v *Menu) toMenu() *C.GMenu { 58 | if v == nil { 59 | return nil 60 | } 61 | return C.toGMenu(unsafe.Pointer(v.GObject)) 62 | } 63 | 64 | func convertToMenu(c *C.GMenu) *Menu { 65 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 66 | return wrapMenu(obj) 67 | } 68 | 69 | //GMenu * g_menu_new () 70 | //void g_menu_freeze () 71 | //void g_menu_insert () 72 | //void g_menu_prepend () 73 | //void g_menu_append () 74 | //void g_menu_insert_item () 75 | //void g_menu_append_item () 76 | //void g_menu_prepend_item () 77 | //void g_menu_insert_section () 78 | //void g_menu_prepend_section () 79 | //void g_menu_append_section () 80 | //void g_menu_append_submenu () 81 | //void g_menu_insert_submenu () 82 | //void g_menu_prepend_submenu () 83 | //void g_menu_remove () 84 | //void g_menu_remove_all () 85 | //GMenuItem * g_menu_item_new () 86 | //GMenuItem * g_menu_item_new_section () 87 | //GMenuItem * g_menu_item_new_submenu () 88 | //GMenuItem * g_menu_item_new_from_model () 89 | //void g_menu_item_set_label () 90 | //void g_menu_item_set_icon () 91 | //void g_menu_item_set_action_and_target_value () 92 | //void g_menu_item_set_action_and_target () 93 | //void g_menu_item_set_detailed_action () 94 | //void g_menu_item_set_section () 95 | //void g_menu_item_set_submenu () 96 | //GVariant * g_menu_item_get_attribute_value () 97 | //gboolean g_menu_item_get_attribute () 98 | //GMenuModel * g_menu_item_get_link () 99 | //void g_menu_item_set_attribute_value () 100 | //void g_menu_item_set_attribute () 101 | //void g_menu_item_set_link () 102 | -------------------------------------------------------------------------------- /GMenuModel.go: -------------------------------------------------------------------------------- 1 | //GMenuModel : GMenuModel — An abstract class representing the contents of a menu 2 | package gio 3 | 4 | // #cgo pkg-config: gio-2.0 glib-2.0 5 | // #include 6 | // #include "gio.go.h" 7 | import "C" 8 | 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/gotk3/gotk3/glib" 13 | ) 14 | 15 | func init() { 16 | tm := []glib.TypeMarshaler{ 17 | // Enums 18 | 19 | // Objects/Interfaces 20 | 21 | {glib.Type(C.g_menu_model_get_type()), marshalMenuModel}, 22 | {glib.Type(C.g_menu_link_iter_get_type()), marshalMenuLinkIter}, 23 | {glib.Type(C.g_menu_attribute_iter_get_type()), marshalMenuAttributeIter}, 24 | 25 | // Boxed 26 | 27 | } 28 | glib.RegisterGValueMarshalers(tm) 29 | } 30 | 31 | /* 32 | * GMenuModel 33 | */ 34 | 35 | type MenuModel struct { 36 | *glib.Object 37 | } 38 | 39 | // native returns a pointer to the underlying GMenuModel. 40 | func (v *MenuModel) native() *C.GMenuModel { 41 | if v == nil || v.GObject == nil { 42 | return nil 43 | } 44 | p := unsafe.Pointer(v.GObject) 45 | return C.toGMenuModel(p) 46 | } 47 | 48 | func marshalMenuModel(p uintptr) (interface{}, error) { 49 | c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p))) 50 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 51 | return wrapMenuModel(obj), nil 52 | } 53 | 54 | func wrapMenuModel(obj *glib.Object) *MenuModel { 55 | return &MenuModel{obj} 56 | } 57 | 58 | func (v *MenuModel) ToGMenuModel() *C.GMenuModel { 59 | return v.native() 60 | } 61 | 62 | // IsMutable is a wrapper around g_menu_model_is_mutable(). 63 | /* 64 | Queries if model is mutable. 65 | An immutable GMenuModel will never emit the “items-changed” signal. Consumers of the model may make optimisations accordingly. 66 | */ 67 | func (v *MenuModel) IsMutable() bool { 68 | c := C.g_menu_model_is_mutable(v.native()) 69 | return gobool(c) 70 | } 71 | 72 | // GetNItems is a wrapper around g_menu_model_get_n_items(). 73 | /* 74 | Query the number of items in model . 75 | */ 76 | func (v *MenuModel) GetNItems() int { 77 | c := C.g_menu_model_get_n_items(v.native()) 78 | return int(c) 79 | } 80 | 81 | // GetItemAttributeValue is a wrapper around g_menu_model_get_item_attribute_value(). 82 | /* 83 | Queries the item at position item_index in model for the attribute specified by attribute . 84 | If expected_type is non-NULL then it specifies the expected type of the attribute. If it is NULL then any type will be accepted. 85 | If the attribute exists and matches expected_type (or if the expected type is unspecified) then the value is returned. 86 | If the attribute does not exist, or does not match the expected type then NULL is returned. 87 | */ 88 | /* 89 | func (v *MenuModel) GetItemAttributeValue(item_index int, attribute string, expected_type interface{}) interface{} { //FIXME Variant 90 | cstrattribute := C.CString(attribute) 91 | defer C.free(unsafe.Pointer(cstrattribute)) 92 | c := C.g_menu_model_get_item_attribute_value(v.native(), (C.gint)(item_index), (*C.gchar)(cstrattribute), expected_type.native()) 93 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 94 | return wrapVariant(obj) 95 | } 96 | */ 97 | 98 | // GetItemAttribute is a wrapper around g_menu_model_get_item_attribute(). 99 | /* 100 | Queries item at position item_index in model for the attribute specified by attribute . 101 | If the attribute exists and matches the GVariantType corresponding to format_string then format_string is used to deconstruct the value into the positional parameters and TRUE is returned. 102 | If the attribute does not exist, or it does exist but has the wrong type, then the positional parameters are ignored and FALSE is returned. 103 | This function is a mix of g_menu_model_get_item_attribute_value() and g_variant_get(), followed by a g_variant_unref(). As such, format_string must make a complete copy of the data (since the GVariant may go away after the call to g_variant_unref()). In particular, no '&' characters are allowed in format_string . 104 | */ 105 | /* 106 | func (v *MenuModel) GetItemAttribute(item_index int, attribute, format string ,a ...interface{}) bool { //FIXME ... vargs 107 | cstrattribute := C.CString(attribute) 108 | defer C.free(unsafe.Pointer(cstrattribute)) 109 | cstrformat := C.CString(format) 110 | defer C.free(unsafe.Pointer(cstrformat)) 111 | s := fmt.Sprintf(format, a...) 112 | cstr := C.CString(s) 113 | defer C.free(unsafe.Pointer(cstr)) 114 | c := C.g_menu_model_get_item_attribute(v.native(), (C.gint)(item_index), (*C.gchar)(cstrattribute), (*C.gchar)(cstrformat) ,cstr) 115 | return gobool(c) 116 | } 117 | */ 118 | 119 | // GetItemLink is a wrapper around g_menu_model_get_item_link(). 120 | /* 121 | Queries the item at position item_index in model for the link specified by link . 122 | If the link exists, the linked GMenuModel is returned. If the link does not exist, NULL is returned. 123 | */ 124 | func (v *MenuModel) GetItemLink(item_index int, link string) *MenuModel { 125 | cstrlink := C.CString(link) 126 | defer C.free(unsafe.Pointer(cstrlink)) 127 | c := C.g_menu_model_get_item_link(v.native(), (C.gint)(item_index), (*C.gchar)(cstrlink)) 128 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 129 | return wrapMenuModel(obj) 130 | } 131 | 132 | // IterateItemAttributes is a wrapper around g_menu_model_iterate_item_attributes(). 133 | /* 134 | Creates a GMenuAttributeIter to iterate over the attributes of the item at position item_index in model . 135 | You must free the iterator with g_object_unref() when you are done. 136 | */ 137 | func (v *MenuModel) IterateItemAttributes(item_index int) *MenuAttributeIter { 138 | c := C.g_menu_model_iterate_item_attributes(v.native(), (C.gint)(item_index)) 139 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 140 | return wrapMenuAttributeIter(obj) 141 | } 142 | 143 | // IterateItemLinks is a wrapper around g_menu_model_iterate_item_links(). 144 | /* 145 | Creates a GMenuLinkIter to iterate over the links of the item at position item_index in model . 146 | You must free the iterator with g_object_unref() when you are done. 147 | */ 148 | func (v *MenuModel) IterateItemLinks(item_index int) *MenuLinkIter { 149 | c := C.g_menu_model_iterate_item_links(v.native(), (C.gint)(item_index)) 150 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 151 | return wrapMenuLinkIter(obj) 152 | } 153 | 154 | // ItemsChanged is a wrapper around g_menu_model_items_changed(). 155 | /* 156 | Requests emission of the “items-changed” signal on model . 157 | This function should never be called except by GMenuModel subclasses. Any other calls to this function will very likely lead to a violation of the interface of the model. 158 | The implementation should update its internal representation of the menu before emitting the signal. The implementation should further expect to receive queries about the new state of the menu (and particularly added menu items) while signal handlers are running. 159 | The implementation must dispatch this call directly from a mainloop entry and not in response to calls -- particularly those from the GMenuModel API. Said another way: the menu must not change while user code is running without returning to the mainloop. 160 | */ 161 | func (v *MenuModel) ItemsChanged(position, removed, added int) { 162 | C.g_menu_model_items_changed(v.native(), (C.gint)(position), (C.gint)(removed), (C.gint)(added)) 163 | } 164 | 165 | /* 166 | * GMenuAttributeIter 167 | */ 168 | 169 | type MenuAttributeIter struct { 170 | *glib.Object 171 | } 172 | 173 | // native returns a pointer to the underlying GMenuModel. 174 | func (v *MenuAttributeIter) native() *C.GMenuAttributeIter { 175 | if v == nil || v.GObject == nil { 176 | return nil 177 | } 178 | p := unsafe.Pointer(v.GObject) 179 | return C.toGMenuAttributeIter(p) 180 | } 181 | 182 | func marshalMenuAttributeIter(p uintptr) (interface{}, error) { 183 | c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p))) 184 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 185 | return wrapMenuAttributeIter(obj), nil 186 | } 187 | 188 | func wrapMenuAttributeIter(obj *glib.Object) *MenuAttributeIter { 189 | return &MenuAttributeIter{obj} 190 | } 191 | 192 | func (v *MenuAttributeIter) toMenuAttributeIter() *C.GMenuAttributeIter { 193 | if v == nil { 194 | return nil 195 | } 196 | return C.toGMenuAttributeIter(unsafe.Pointer(v.GObject)) 197 | } 198 | 199 | // GetNext is a wrapper around g_menu_attribute_iter_get_next(). 200 | /* 201 | This function combines g_menu_attribute_iter_next() with g_menu_attribute_iter_get_name() and g_menu_attribute_iter_get_value(). 202 | First the iterator is advanced to the next (possibly first) attribute. If that fails, then FALSE is returned and there are no other effects. 203 | If successful, name and value are set to the name and value of the attribute that has just been advanced to. At this point, g_menu_attribute_iter_get_name() and g_menu_attribute_iter_get_value() will return the same values again. 204 | The value returned in name remains valid for as long as the iterator remains at the current position. The value returned in value must be unreffed using g_variant_unref() when it is no longer in use. 205 | */ 206 | /* 207 | func (v *MenuAttributeIter) GetNext() ([]string, []interface{}, bool) { //FIXME Variant 208 | c := C.g_menu_attribute_iter_get_next(v.native(), out_name, value) 209 | return out_name, value, gobool(c) 210 | } 211 | */ 212 | // GetName is a wrapper around g_menu_attribute_iter_get_name(). 213 | /* 214 | Gets the name of the attribute at the current iterator position, as a string. 215 | The iterator is not advanced. 216 | */ 217 | func (v *MenuAttributeIter) GetName() string { 218 | cstr := (*C.char)(C.g_menu_attribute_iter_get_name(v.native())) 219 | defer C.free(unsafe.Pointer(cstr)) 220 | return C.GoString(cstr) 221 | } 222 | 223 | // GetValue is a wrapper around g_menu_attribute_iter_get_value(). 224 | /* 225 | Gets the value of the attribute at the current iterator position. 226 | The iterator is not advanced. 227 | */ 228 | /* 229 | func (v *MenuAttributeIter) GetValue() interface{} { //FIXME Variant 230 | c := C.g_menu_attribute_iter_get_value(v.native()) 231 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 232 | return wrapVariant(obj) 233 | } 234 | */ 235 | 236 | // IterNext is a wrapper around g_menu_attribute_iter_next(). 237 | /* 238 | Attempts to advance the iterator to the next (possibly first) attribute. 239 | TRUE is returned on success, or FALSE if there are no more attributes. 240 | You must call this function when you first acquire the iterator to advance it to the first attribute (and determine if the first attribute exists at all). 241 | */ 242 | func (v *MenuAttributeIter) IterNext() bool { 243 | c := C.g_menu_attribute_iter_next(v.native()) 244 | return gobool(c) 245 | } 246 | 247 | /* 248 | * GMenuLinkIterMenuAttributeIter 249 | */ 250 | 251 | type MenuLinkIter struct { 252 | *glib.Object 253 | } 254 | 255 | // native returns a pointer to the underlying GMenuModel. 256 | func (v *MenuLinkIter) native() *C.GMenuLinkIter { 257 | if v == nil || v.GObject == nil { 258 | return nil 259 | } 260 | p := unsafe.Pointer(v.GObject) 261 | return C.toGMenuLinkIter(p) 262 | } 263 | 264 | func marshalMenuLinkIter(p uintptr) (interface{}, error) { 265 | c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p))) 266 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 267 | return wrapMenuLinkIter(obj), nil 268 | } 269 | 270 | func wrapMenuLinkIter(obj *glib.Object) *MenuLinkIter { 271 | return &MenuLinkIter{obj} 272 | } 273 | 274 | func (v *MenuLinkIter) toMenuLinkIter() *C.GMenuLinkIter { 275 | if v == nil { 276 | return nil 277 | } 278 | return C.toGMenuLinkIter(unsafe.Pointer(v.GObject)) 279 | } 280 | 281 | // GetNext is a wrapper around g_menu_link_iter_get_next(). 282 | /* 283 | This function combines g_menu_link_iter_next() with g_menu_link_iter_get_name() and g_menu_link_iter_get_value(). 284 | First the iterator is advanced to the next (possibly first) link. If that fails, then FALSE is returned and there are no other effects. 285 | If successful, out_link and value are set to the name and GMenuModel of the link that has just been advanced to. At this point, g_menu_link_iter_get_name() and g_menu_link_iter_get_value() will return the same values again. 286 | The value returned in out_link remains valid for as long as the iterator remains at the current position. The value returned in value must be unreffed using g_object_unref() when it is no longer in use. 287 | */ 288 | /* 289 | func (v *MenuLinkIter) GetNext() ([]string, []interface{}, bool) { //FIXME Variant 290 | c := C.g_menu_link_iter_get_next(v.native(), out_name, value) 291 | return out_name, value, gobool(c) 292 | } 293 | */ 294 | // GetName is a wrapper around g_menu_link_iter_get_name(). 295 | /* 296 | Gets the name of the link at the current iterator position. 297 | The iterator is not advanced. 298 | */ 299 | func (v *MenuLinkIter) GetName() string { 300 | cstr := (*C.char)(C.g_menu_link_iter_get_name(v.native())) 301 | defer C.free(unsafe.Pointer(cstr)) 302 | return C.GoString(cstr) 303 | } 304 | 305 | // GetValue is a wrapper around g_menu_link_iter_get_value(). 306 | /* 307 | Gets the linked GMenuModel at the current iterator position. 308 | The iterator is not advanced. 309 | */ 310 | /* 311 | func (v *MenuLinkIter) GetValue() interface{} { //FIXME Variant 312 | c := C.g_menu_link_iter_get_value(v.native()) 313 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 314 | return wrapVariant(obj) 315 | } 316 | */ 317 | 318 | // IterNext is a wrapper around g_menu_link_iter_next(). 319 | /* 320 | Attempts to advance the iterator to the next (possibly first) link. 321 | TRUE is returned on success, or FALSE if there are no more links. 322 | You must call this function when you first acquire the iterator to advance it to the first link (and determine if the first link exists at all). 323 | */ 324 | func (v *MenuLinkIter) IterNext() bool { 325 | c := C.g_menu_link_iter_next(v.native()) 326 | return gobool(c) 327 | } 328 | -------------------------------------------------------------------------------- /GNotification.go: -------------------------------------------------------------------------------- 1 | //GNotification 2 | package gio 3 | 4 | // #cgo pkg-config: gio-2.0 glib-2.0 5 | // #include 6 | // #include "gio.go.h" 7 | import "C" 8 | 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/gotk3/gotk3/glib" 13 | ) 14 | 15 | /* 16 | * GNotification 17 | */ 18 | 19 | // Notification is a representation of GIO's GNotification. 20 | type Notification struct { 21 | *glib.Object 22 | } 23 | 24 | // native returns a pointer to the underlying GNotification. 25 | func (v *Notification) native() *C.GNotification { 26 | if v == nil || v.GObject == nil { 27 | return nil 28 | } 29 | p := unsafe.Pointer(v.GObject) 30 | return C.toGNotification(p) 31 | } 32 | 33 | func marshalNotification(p uintptr) (interface{}, error) { 34 | c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p))) 35 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 36 | return wrapNotification(obj), nil 37 | } 38 | 39 | func wrapNotification(obj *glib.Object) *Notification { 40 | return &Notification{obj} 41 | } 42 | 43 | func (v *Notification) toNotification() *C.GNotification { 44 | if v == nil { 45 | return nil 46 | } 47 | return C.toGNotification(unsafe.Pointer(v.GObject)) 48 | } 49 | -------------------------------------------------------------------------------- /GSimpleAction.go: -------------------------------------------------------------------------------- 1 | //GSimpleAction — Interface for Action containers 2 | package gio 3 | 4 | // #cgo pkg-config: gio-2.0 glib-2.0 5 | // #include 6 | // #include "gio.go.h" 7 | import "C" 8 | 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/gotk3/gotk3/glib" 13 | ) 14 | 15 | func init() { 16 | tm := []glib.TypeMarshaler{ 17 | // Enums 18 | 19 | // Objects/Interfaces 20 | 21 | {glib.Type(C.g_simple_action_get_type()), marshalSimpleAction}, 22 | 23 | // Boxed 24 | 25 | } 26 | glib.RegisterGValueMarshalers(tm) 27 | } 28 | 29 | /* 30 | * GSimpleAction 31 | */ 32 | 33 | // SimpleAction is a representation of GIO's GSimpleAction. 34 | type SimpleAction struct { 35 | *glib.Object 36 | } 37 | 38 | // native returns a pointer to the underlying GSimpleAction. 39 | func (v *SimpleAction) native() *C.GSimpleAction { 40 | if v == nil || v.GObject == nil { 41 | return nil 42 | } 43 | p := unsafe.Pointer(v.GObject) 44 | return C.toGSimpleAction(p) 45 | } 46 | 47 | func marshalSimpleAction(p uintptr) (interface{}, error) { 48 | c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p))) 49 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 50 | return wrapSimpleAction(obj), nil 51 | } 52 | 53 | func wrapSimpleAction(obj *glib.Object) *SimpleAction { 54 | return &SimpleAction{obj} 55 | } 56 | 57 | func (v *SimpleAction) toSimpleAction() *C.GSimpleAction { 58 | if v == nil { 59 | return nil 60 | } 61 | return C.toGSimpleAction(unsafe.Pointer(v.GObject)) 62 | } 63 | 64 | func convertToSimpleAction(c *C.GSimpleAction) *SimpleAction { 65 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 66 | return wrapSimpleAction(obj) 67 | } 68 | 69 | //GSimpleAction * 70 | //g_simple_action_new (const gchar *name, 71 | // const GVariantType *parameter_type); 72 | //Creates a new action. 73 | //The created action is stateless. See g_simple_action_new_stateful(). 74 | func SimpleActionNew(name string, parameter_type *glib.VariantType) *SimpleAction { 75 | cstr := C.CString(name) 76 | defer C.free(unsafe.Pointer(cstr)) 77 | c := C.g_simple_action_new((*C.gchar)(cstr), (*C.GVariantType)(parameter_type.GVariantType)) 78 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 79 | return wrapSimpleAction(obj) 80 | } 81 | 82 | //g_simple_action_new_stateful () 83 | //GSimpleAction * 84 | //g_simple_action_new_stateful (const gchar *name, 85 | // const GVariantType *parameter_type, 86 | // GVariant *state); 87 | //Creates a new stateful action. 88 | //state is the initial state of the action. All future state values must have the same GVariantType as the initial state. 89 | //If the state GVariant is floating, it is consumed. 90 | func SimpleActionNewStateful(name string, parameter_type *glib.VariantType, state *glib.Variant) *SimpleAction { 91 | cstr := C.CString(name) 92 | defer C.free(unsafe.Pointer(cstr)) 93 | c := C.g_simple_action_new_stateful((*C.gchar)(cstr), (*C.GVariantType)(parameter_type.GVariantType), (*C.GVariant)(state.GVariant)) 94 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 95 | return wrapSimpleAction(obj) 96 | } 97 | 98 | //void 99 | //g_simple_action_set_enabled (GSimpleAction *simple, 100 | // gboolean enabled); 101 | //Sets the action as enabled or not. 102 | //An action must be enabled in order to be activated or in order to have its state changed from outside callers. 103 | //This should only be called by the implementor of the action. Users of the action should not attempt to modify its enabled flag. 104 | func (v *SimpleAction) SetEnabled(enabled bool) { 105 | b := gbool(enabled) 106 | C.g_simple_action_set_enabled(v.native(), b) 107 | } 108 | 109 | //void 110 | //g_simple_action_set_state (GSimpleAction *simple, 111 | // GVariant *value); 112 | //Sets the state of the action. 113 | //This directly updates the 'state' property to the given value. 114 | //This should only be called by the implementor of the action. Users of the action should not attempt to directly modify the 'state' property. Instead, they should call g_action_change_state() to request the change. 115 | //If the value GVariant is floating, it is consumed. 116 | func (v *SimpleAction) SetState(value *glib.Variant) { 117 | C.g_simple_action_set_state(v.native(), (*C.GVariant)(value.GVariant)) 118 | } 119 | 120 | //void 121 | //g_simple_action_set_state_hint (GSimpleAction *simple, 122 | // GVariant *state_hint); 123 | //Sets the state hint for the action. 124 | //See g_action_get_state_hint() for more information about action state hints. 125 | func (v *SimpleAction) SetStateHint(value *glib.Variant) { 126 | C.g_simple_action_set_state_hint(v.native(), (*C.GVariant)(value.GVariant)) 127 | } 128 | -------------------------------------------------------------------------------- /GTypeModule.go: -------------------------------------------------------------------------------- 1 | //GTypeModule 2 | package gio 3 | 4 | // #cgo pkg-config: gio-2.0 glib-2.0 5 | // #include 6 | // #include "gio.go.h" 7 | import "C" 8 | 9 | import ( 10 | "unsafe" 11 | 12 | "github.com/gotk3/gotk3/glib" 13 | ) 14 | 15 | /* 16 | * GTypeModule 17 | */ 18 | 19 | // TypeModule is a representation of GIO's GTypeModule. 20 | type TypeModule struct { 21 | *glib.Object 22 | } 23 | 24 | // native returns a pointer to the underlying GTypeModule. 25 | func (v *TypeModule) native() *C.GTypeModule { 26 | if v == nil || v.GObject == nil { 27 | return nil 28 | } 29 | p := unsafe.Pointer(v.GObject) 30 | return C.toGTypeModule(p) 31 | } 32 | 33 | func marshalTypeModule(p uintptr) (interface{}, error) { 34 | c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p))) 35 | obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))} 36 | return wrapTypeModule(obj), nil 37 | } 38 | 39 | func wrapTypeModule(obj *glib.Object) *TypeModule { 40 | return &TypeModule{obj} 41 | } 42 | 43 | func (v *TypeModule) toTypeModule() *C.GTypeModule { 44 | if v == nil { 45 | return nil 46 | } 47 | return C.toGTypeModule(unsafe.Pointer(v.GObject)) 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gio [![GoDoc](https://godoc.org/github.com/gotk3/gio?status.svg)](https://godoc.org/github.com/gotk3/gio) 2 | ===== 3 | 4 | [![Build Status](https://travis-ci.org/gotk3/gio.png?branch=master)](https://travis-ci.org/gotk3/gio) 5 | 6 | this is the go binding for gtk gio (virtual file system) 7 | 8 | see: https://developer.gnome.org/gio/stable/ -------------------------------------------------------------------------------- /gio.go: -------------------------------------------------------------------------------- 1 | package gio 2 | 3 | // #cgo pkg-config: gio-2.0 glib-2.0 4 | // #include 5 | // #include "gio.go.h" 6 | import "C" 7 | import ( 8 | "errors" 9 | "github.com/gotk3/gotk3/glib" 10 | ) 11 | 12 | func init() { 13 | tm := []glib.TypeMarshaler{ 14 | // Enums 15 | {glib.Type(C.g_application_flags_get_type()), marshalApplicationFlags}, 16 | 17 | // Objects/Interfaces 18 | {glib.Type(C.g_application_get_type()), marshalApplication}, 19 | {glib.Type(C.g_cancellable_get_type()), marshalCancellable}, 20 | {glib.Type(C.g_dbus_connection_get_type()), marshalDBusConnection}, 21 | {glib.Type(C.g_file_get_type()), marshalFile}, 22 | {glib.Type(C.g_notification_get_type()), marshalNotification}, 23 | {glib.Type(C.g_type_module_get_type()), marshalTypeModule}, 24 | 25 | // Boxed 26 | } 27 | glib.RegisterGValueMarshalers(tm) 28 | } 29 | 30 | /* 31 | * Type conversions 32 | */ 33 | 34 | func gbool(b bool) C.gboolean { 35 | if b { 36 | return C.gboolean(1) 37 | } 38 | return C.gboolean(0) 39 | } 40 | func gobool(b C.gboolean) bool { 41 | if b != 0 { 42 | return true 43 | } 44 | return false 45 | } 46 | 47 | /* 48 | * Unexported vars 49 | */ 50 | 51 | var nilPtrErr = errors.New("cgo returned unexpected nil pointer") 52 | -------------------------------------------------------------------------------- /gio.go.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | //static int callGApplicationRun(GApplication *app, int argc, char **argv){ 8 | // int i, res; 9 | // printf ("-- Tableau de %d éléments : --\n",argc); 10 | // for (i=0;i