Vala

Gee HashMap containing methods as values

隐身守侯 提交于 2019-12-07 03:22:48
问题 I'm trying to fill a Libgee HashMap where each entry has a string as key, and a function as value. Is this possible? I want this sort of thing: var keybindings = new Gee.HashMap<string, function> (); keybindings.set ("<control>h", this.show_help ()); keybindings.set ("<control>q", this.explode ()); so that I can eventually do something like this: foreach (var entry in keybindings.entries) { uint key_code; Gdk.ModifierType accelerator_mods; Gtk.accelerator_parse((string) entry.key, out key

How to concatenate two arrays?

半世苍凉 提交于 2019-12-06 16:58:44
[indent=4] init x: array of int = {1, 2, 3} y: array of int = {4, 5, 6} z: array of int = x + y The above code produces this error message: concat_arrays.gs:6.23-6.27: error: Incompatible operand z: array of int = x + y The Vala translation doesn't work any better: int main () { int[] x = {1, 2, 3}; int[] y = {4, 5, 6}; int[] z = x + y; return 0; } The error message is: concat_arrays_v.vala:4.15-4.19: error: Incompatible operand int[] z = x + y; What is the correct way to do this? Jens Mühlenhoff Using GLib.Array<T> : int main () { int[] x = {1, 2, 3}; int[] y = {4, 5, 6}; Array<int> a = new

Vala and PolicyKit

蹲街弑〆低调 提交于 2019-12-06 00:23:36
I'm creating a simple GTK+ based application in Vala, which should be able to write into system directories, so it needs root access. I realize that giving full root access is a bad idea, so I need a way to gain temporary privileges. In theory, the PolicyKit D-Bus service is the tool for the job, but I have no idea how to use it, let alone in Vala code. Any insight would be appreciated. update: I have done some further digging. My starting point was this . So basically what I need is finding out how to adapt these solutions to PolicyKit. For this, it is necessary to find the D-Bus interface of

How to include resources file in anjuta project

纵然是瞬间 提交于 2019-12-05 21:49:18
I'm trying to update a graphical project in vala, moving lot of code lines into an ui file. I want to use template (available with glib-2.38 and GTK+3.8, something like that). My project is managed with Anjuta and autoconf. In the src directory there are application.ui : <?xml version="1.0" encoding="UTF-8"?> <interface> <!-- interface-requires gtk+ 3.8 --> <template class="SpiWindow" parent="GtkApplicationWindow"> <property name="title" translatable="yes">Example Application</property> <property name="default-width">600</property> <property name="default-height">400</property> <child>

Vala different type of constructors

落爺英雄遲暮 提交于 2019-12-05 18:55:51
Why, and what does the three vala constructors ? class construct construct method with class name and more specific, why the 3rd construct is never called when using it from a Gtk.Builder file? nemequ Short answer: because that's how GObject works. The long answer is just a smidge longer: C doesn't have objects or constructors, it has structs and functions. Structs are very simple; they contain fields, and that's it. No methods, constructors, destructors, etc. They look like this: typedef struct Foo_ { int bar; char* baz; } Foo; To "instantiate" a struct, you allocate the necessary memory

How to handle errors while using Glib.Settings in Vala?

◇◆丶佛笑我妖孽 提交于 2019-12-05 17:27:00
I am using Glib.Settings in my Vala application. And I want to make sure that my program will work okay even when the schema or key is not available. So I've added a try/catch block, but if I'm using the key that doesn't exist, the program segfaults. As I understood, it doesn't even reach the catch statement. Here is the function that uses settings: GLib.Settings settings; string token = ""; try { settings = new GLib.Settings (my_scheme); token = settings.get_string("token1"); } catch (Error e) { print("error"); token = ""; } return token; And the program output is: (main:27194): GLib-GIO

Vala vapi files documentation

99封情书 提交于 2019-12-05 15:17:29
问题 I'd like to hack on an existing GLib based C project using Vala. Basically what I'm doing is, at the beginning of my build process, using valac to generate .c and .h files from my .vala files and then just compiling the generated files the way I would any .c or .h file. This is probably not the best way, but seems to be working alright for the most part. My problem is that I'm having a hard time accessing my existing C code from my Vala code. Is there an easy way to do this? I've tried

基于 Vala 和 GObject 的并行库:Gpseq

左心房为你撑大大i 提交于 2019-12-04 06:38:20
基于 Vala 和 GObject 的并行库: Gpseq 提供如下特性: Work-stealing and managed blocking task scheduling: Similar behavior to Go scheduler Functional programming for data processing with parallel execution support: An equivalent to Java’s streams Fork-join parallelism Parallel sorting Futures and promises 64-bit atomic operations Overflow safe arithmetic functions for signed integers References Valadoc.org (暂未注册) Latest Valadoc GtkDoc (C API) (TODO) pgi-docs (Python API) (TODO) gjs-docs (JavaScript API) 案例代码 using Gpseq; void main () { string[] array = {"dog", "cat", "pig", "boar", "bear"}; Seq.of_array

Vala: reducing the size of dependencies

社会主义新天地 提交于 2019-12-04 04:22:04
I am developing small command line utilities using Vala on win32. Programs compiled using vala depend on the following DLLs libgobject-2.0-0.dll libgthread-2.0-0.dll libglib-2.0-0.dll They are taking up 1500 kbyes of space. Is there a way to reduce the size of these dependencies (besides compressing them with UPX and the like)? I can't imagine a simple helloworld like app using all the features provided by glib. Thanks! If your vala source is fairly simple, you may be able to compile it in the posix profile valac --profile posix hello.vala Then your binary will not have any dependency outside

Vala vapi files documentation

久未见 提交于 2019-12-04 01:32:57
I'd like to hack on an existing GLib based C project using Vala. Basically what I'm doing is, at the beginning of my build process, using valac to generate .c and .h files from my .vala files and then just compiling the generated files the way I would any .c or .h file. This is probably not the best way, but seems to be working alright for the most part. My problem is that I'm having a hard time accessing my existing C code from my Vala code. Is there an easy way to do this? I've tried writing my own .vapi files (I didn't have any luck with the tool that came with vala), but I can't find any