Back to index

indicator-appmenu  12.10.0
Defines | Functions | Variables
mock-json-app.c File Reference
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gio/gio.h>
#include <libdbusmenu-glib/server.h>
#include <libdbusmenu-jsonloader/json-loader.h>
#include "../src/dbus-shared.h"

Go to the source code of this file.

Defines

#define MENU_PATH   "/mock/json/app/menu"

Functions

static void dbus_owner_change (GObject *gobject, GParamSpec *pspec, gpointer user_data)
static gboolean idle_func (gpointer user_data)
static void destroy_cb (void)
int main (int argv, char **argc)

Variables

GtkWidget * window = NULL
DbusmenuServer * server = NULL
GDBusProxy * registrar = NULL

Define Documentation

#define MENU_PATH   "/mock/json/app/menu"

Definition at line 31 of file mock-json-app.c.


Function Documentation

static void dbus_owner_change ( GObject *  gobject,
GParamSpec *  pspec,
gpointer  user_data 
) [static]

Definition at line 38 of file mock-json-app.c.

{
       GDBusProxy * proxy = G_DBUS_PROXY(gobject);

       gchar * owner = g_dbus_proxy_get_name_owner(proxy);

       if (owner == NULL || owner[0] == '\0') {
              /* We only care about folks coming on the bus.  Exit quickly otherwise. */
              g_free(owner);
              return;
       }

       if (g_strcmp0(owner, DBUS_NAME)) {
              /* We only care about this address, reject all others. */
              g_free(owner);
              return;
       }

       GError * error = NULL;
       g_dbus_proxy_call_sync(registrar, "RegisterWindow",
                              g_variant_new("(uo)",
                                            GDK_WINDOW_XID (gtk_widget_get_window (window)),
                                            MENU_PATH),
                              G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
       if (error != NULL) {
              g_warning("Unable to register: %s", error->message);
              g_error_free(error);
       }

       g_free(owner);
       return;
}

Here is the caller graph for this function:

static void destroy_cb ( void  ) [static]

Definition at line 105 of file mock-json-app.c.

{
       gtk_main_quit();
       return;
}

Here is the caller graph for this function:

static gboolean idle_func ( gpointer  user_data) [static]

Definition at line 72 of file mock-json-app.c.

{
       DbusmenuMenuitem * root = dbusmenu_json_build_from_file((const gchar *)user_data);
       g_return_val_if_fail(root != NULL, FALSE);

       DbusmenuServer * server = dbusmenu_server_new(MENU_PATH);
       dbusmenu_server_set_root(server, root);

       registrar = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
                                                 G_DBUS_PROXY_FLAGS_NONE,
                                                 NULL, DBUS_NAME,
                                                 REG_OBJECT, REG_IFACE,
                                                 NULL, NULL);
       g_return_val_if_fail(registrar != NULL, FALSE);

       GError * error = NULL;
       g_dbus_proxy_call_sync(registrar, "RegisterWindow",
                              g_variant_new("(uo)",
                                            GDK_WINDOW_XID (gtk_widget_get_window (window)),
                                            MENU_PATH),
                              G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
       if (error != NULL) {
              g_warning("Unable to register: %s", error->message);
              g_error_free(error);
       }

       g_signal_connect(registrar, "notify::g-name-owner",
                        G_CALLBACK(dbus_owner_change), NULL);

       return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argv,
char **  argc 
)

Definition at line 112 of file mock-json-app.c.

{
       if (argv != 2) {
              g_print("'%s <JSON file>' is how you should use this program.\n", argc[0]);
              return 1;
       }

       gtk_init(&argv, &argc);

       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
       g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy_cb), NULL);
       gtk_widget_show(window);

       g_idle_add(idle_func, argc[1]);

       gtk_main();

       return 0;
}

Here is the call graph for this function:


Variable Documentation

GDBusProxy* registrar = NULL

Definition at line 35 of file mock-json-app.c.

DbusmenuServer* server = NULL

Definition at line 34 of file mock-json-app.c.

GtkWidget* window = NULL

Definition at line 33 of file mock-json-app.c.