Vala and Policykit

Vala and PolicyKit

The polkit Reference Manual contains some good information, including a high-level overview on writing polkit applications.

Instead of using the D-Bus interface directly, you should probably consider using the libpolkit-gobject-1 library. You can use the GIR directly, or generate a VAPI (which I would recommend) with vapigen. Here is one I just generated. I'm not really familiar with the API, but it is very easy to use a C API reference as a reference to figure out the Vala API.

How to use a Qt GUI with Vala?

As others have mentioned, Qt and Vala don't work hand-in-hand, but that doesn't mean it's impossible to get them to cooperate. It's mostly about understanding what's going on beneath the covers.

Vala generates C code which is then fed to gcc (or another installed compiler) to produce a binary. Note that one of the Vala designers' chief goals was for Vala to produce C-based libraries. These can then be used by other languages that accept C-based bindings -- Python, Ruby, Java, and so on.

So, you could use Vala to code a C-based library that your Qt C++ GUI application calls into. The Vala compiler produces a .h file that your Qt app merely #includes.

The problem with this is that Qt and Vala use different object systems: QObject for Qt, GObject for Vala. (Vala does allow for other backends, and there's even some thought about Vala producing Qt C++ instead of GObject-based C, but that's far in the future.) QObject and GObject are not compatible, and so for your QObjects to talk with GObjects, you need to do a lot of manual C-based work. (Writing GObject in C is quite verbose, hence the allure of Vala to hide all of it.)

But it can be done. Note that Qt will even use GLib's event loop rather than its own, allowing for the code to commingle in an event-driven application.

I can't heartily recommend the above, but in theory it's possible, mostly because C++ code can easily call C code.

Another possibility worth considering is make Vala code a DBus server and your Qt code a DBus client. DBus is a fancy IPC, and so this is not suitable for all applications, but it might be for yours. It's attractive because Vala can easily produce DBus clients and servers (they look like ordinary objects). Tools to produce Qt DBus bindings are available as well. Note that this means your Vala code runs as a separate process and is not an in-process library. See http://live.gnome.org/Vala/DBusServerSample and http://live.gnome.org/Vala/DBusClientSamples

Vala Gtk Folder selection

Set the action property.

filechooser.action = FileChooserAction.SELECT_FOLDER;

undefined symbol: polkit_unix_process_new on i386 platform

Okay the error was a simple cmake error but not necessarily easy to spot when you are maintaining an application.

It seems that amd64 is generous enough to let the build error slide but not i386

The issue was in the cmake file where the library polkit-gobject-1 was missing in the pkg_check_modules clause and the include file was added manually but not the link to the shared library.

Erroneous cmake snippet:

pkg_check_modules (DEPS REQUIRED gthread-2.0 gtk+-3.0 switchboard-2.0 granite gconf-2.0 gee-0.8 glib-2.0)

add_definitions (${DEPS_CFLAGS} -I/usr/include/polkit-1)
add_definitions (${DEPS_CFLAGS})
link_libraries (${DEPS_LIBRARIES})
link_directories (${DEPS_LIBRARY_DIRS})

Correct cmake snippet:

pkg_check_modules (DEPS REQUIRED gthread-2.0 gtk+-3.0 switchboard-2.0 granite gconf-2.0 gee-0.8 polkit-gobject-1 glib-2.0)

add_definitions (${DEPS_CFLAGS})
link_libraries (${DEPS_LIBRARIES})
link_directories (${DEPS_LIBRARY_DIRS})

Access another user's D-Bus session

First, you need DBUS_SESSION_BUS_ADDRESS environment variable to be preserved when invoking application with su or sudo. Unfortunately, this is not enough, because DBus always checks (as a security measure) whether UIDs of the calling process and the session daemon are the same. The only workaround is to call seteuid from this application before connecting to the session bus. You can regain your privileges then with seteuid(0).



Related Topics



Leave a reply



Submit