Back to index

libindicator  12.10.0
Defines | Functions
indicator-loader.c File Reference
#include <gtk/gtk.h>
#include <libindicator/indicator-object.h>

Go to the source code of this file.

Defines

#define ENTRY_DATA_NAME   "indicator-custom-entry-data"

Functions

static void activate_entry (GtkWidget *widget, gpointer user_data)
static void entry_added (IndicatorObject *io, IndicatorObjectEntry *entry, gpointer user_data)
static void entry_removed_cb (GtkWidget *widget, gpointer userdata)
static void entry_removed (IndicatorObject *io, IndicatorObjectEntry *entry, gpointer user_data)
static void menu_show (IndicatorObject *io, IndicatorObjectEntry *entry, guint timestamp, gpointer user_data)
static gboolean load_module (const gchar *name, GtkWidget *menu)
static void destroy (gpointer data)
int main (int argc, char **argv)

Define Documentation

#define ENTRY_DATA_NAME   "indicator-custom-entry-data"

Definition at line 28 of file indicator-loader.c.


Function Documentation

static void activate_entry ( GtkWidget *  widget,
gpointer  user_data 
) [static]

Definition at line 31 of file indicator-loader.c.

{
       g_return_if_fail(INDICATOR_IS_OBJECT(user_data));
       gpointer entry = g_object_get_data(G_OBJECT(widget), ENTRY_DATA_NAME);
       if (entry == NULL) {
              g_debug("Activation on: (null)");
       }

       indicator_object_entry_activate(INDICATOR_OBJECT(user_data), (IndicatorObjectEntry *)entry, gtk_get_current_event_time());
       return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void destroy ( gpointer  data) [static]

Definition at line 151 of file indicator-loader.c.

{
       gtk_main_quit();
       return;
}

Here is the caller graph for this function:

static void entry_added ( IndicatorObject *  io,
IndicatorObjectEntry *  entry,
gpointer  user_data 
) [static]

Definition at line 44 of file indicator-loader.c.

{
       g_debug("Signal: Entry Added");

       if (entry->parent_object == NULL) {
              g_warning("Entry '%p' does not have a parent object", entry);
       }

       GtkWidget * menuitem = gtk_menu_item_new();
#if GTK_CHECK_VERSION(3,0,0)
       GtkWidget * hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3);
#else
       GtkWidget * hbox = gtk_hbox_new(FALSE, 3);
#endif

       if (entry->image != NULL) {
              gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry->image), FALSE, FALSE, 0);
       }
       if (entry->label != NULL) {
              gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry->label), FALSE, FALSE, 0);
       }
       gtk_container_add(GTK_CONTAINER(menuitem), hbox);
       gtk_widget_show(hbox);

       if (entry->menu != NULL) {
              gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entry->menu));
       }

       g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(activate_entry), io);

       gtk_menu_shell_append(GTK_MENU_SHELL(user_data), menuitem);
       gtk_widget_show(menuitem);

       g_object_set_data(G_OBJECT(menuitem), ENTRY_DATA_NAME, entry);

       return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void entry_removed ( IndicatorObject *  io,
IndicatorObjectEntry *  entry,
gpointer  user_data 
) [static]

Definition at line 96 of file indicator-loader.c.

{
       g_debug("Signal: Entry Removed");

       gtk_container_foreach(GTK_CONTAINER(user_data), entry_removed_cb, entry);

       return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void entry_removed_cb ( GtkWidget *  widget,
gpointer  userdata 
) [static]

Definition at line 83 of file indicator-loader.c.

{
       gpointer data = g_object_get_data(G_OBJECT(widget), ENTRY_DATA_NAME);

       if (data != userdata) {
              return;
       }

       gtk_widget_destroy(widget);
       return;
}

Here is the caller graph for this function:

static gboolean load_module ( const gchar *  name,
GtkWidget *  menu 
) [static]

Definition at line 117 of file indicator-loader.c.

{
       g_debug("Looking at Module: %s", name);
       g_return_val_if_fail(name != NULL, FALSE);

       if (!g_str_has_suffix(name, G_MODULE_SUFFIX)) {
              return FALSE;
       }

       g_debug("Loading Module: %s", name);

       /* Build the object for the module */
       IndicatorObject * io = indicator_object_new_from_file(name);

       /* Connect to it's signals */
       g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED,   G_CALLBACK(entry_added),    menu);
       g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, G_CALLBACK(entry_removed),  menu);
       g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_MENU_SHOW,     G_CALLBACK(menu_show),      NULL);

       /* Work on the entries */
       GList * entries = indicator_object_get_entries(io);
       GList * entry = NULL;

       for (entry = entries; entry != NULL; entry = g_list_next(entry)) {
              IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data;
              entry_added(io, entrydata, menu);
       }

       g_list_free(entries);

       return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 158 of file indicator-loader.c.

{
       /* Make sure we don't proxy to ourselves */
       g_unsetenv("UBUNTU_MENUPROXY");

       gtk_init(&argc, &argv);

       if (argc != 2) {
              g_error("Need filename");
              return 1;
       }

       GtkWidget * menubar = gtk_menu_bar_new();
       if (!load_module(argv[1], menubar)) {
              g_error("Unable to load module");
              return 1;
       }

       GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
       g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);

       gtk_container_add(GTK_CONTAINER(window), menubar);

       gtk_widget_show(menubar);
       gtk_widget_show(window);

       gtk_main();

       return 0;
}

Here is the call graph for this function:

static void menu_show ( IndicatorObject *  io,
IndicatorObjectEntry *  entry,
guint  timestamp,
gpointer  user_data 
) [static]

Definition at line 106 of file indicator-loader.c.

{
       if (entry != NULL) {
              g_debug("Show Menu: %s", entry->label != NULL ? gtk_label_get_text(entry->label) : "No Label");
       } else {
              g_debug("Show Menu: (null)");
       }
       return;
}

Here is the caller graph for this function: