Back to index

indicator-session  12.10.0
Classes | Defines | Typedefs | Functions | Variables
user-widget.c File Reference
#include <gtk/gtk.h>
#include <libindicator/indicator-image-helper.h>
#include "shared-names.h"
#include "user-widget.h"

Go to the source code of this file.

Classes

struct  _UserWidgetPrivate

Defines

#define USER_WIDGET_GET_PRIVATE(o)   (G_TYPE_INSTANCE_GET_PRIVATE ((o), USER_WIDGET_TYPE, UserWidgetPrivate))

Typedefs

typedef struct _UserWidgetPrivate

Functions

static void user_widget_class_init (UserWidgetClass *klass)
static void user_widget_init (UserWidget *self)
static void user_widget_dispose (GObject *object)
static void user_widget_finalize (GObject *object)
static void user_widget_set_twin_item (UserWidget *self, DbusmenuMenuitem *twin_item)
static gboolean user_widget_primitive_draw_cb_gtk_3 (GtkWidget *image, cairo_t *cr, gpointer user_data)
 G_DEFINE_TYPE (UserWidget, user_widget, GTK_TYPE_MENU_ITEM)
static void update_icon (UserWidget *self, DbusmenuMenuitem *mi)
static void update_logged_in (UserWidget *self, DbusmenuMenuitem *mi)
static void update_name (UserWidget *self, DbusmenuMenuitem *mi)
static void user_widget_property_update (DbusmenuMenuitem *mi, const gchar *property, GVariant *value, UserWidget *self)
GtkWidget * user_widget_new (DbusmenuMenuitem *item)
 user_widget_new:

Variables

static const int ICON_SIZE = 24

Class Documentation

struct _UserWidgetPrivate

Definition at line 36 of file user-widget.c.

Class Members
GtkWidget * container
gboolean logged_in
gboolean sessions_active
GtkWidget * tick_icon
DbusmenuMenuitem * twin_item
GtkWidget * user_image
GtkWidget * user_name

Define Documentation

#define USER_WIDGET_GET_PRIVATE (   o)    (G_TYPE_INSTANCE_GET_PRIVATE ((o), USER_WIDGET_TYPE, UserWidgetPrivate))

Definition at line 47 of file user-widget.c.


Typedef Documentation

typedef struct _UserWidgetPrivate

Definition at line 34 of file user-widget.c.


Function Documentation

G_DEFINE_TYPE ( UserWidget  ,
user_widget  ,
GTK_TYPE_MENU_ITEM   
)
static void update_icon ( UserWidget *  self,
DbusmenuMenuitem *  mi 
) [static]

Definition at line 186 of file user-widget.c.

{
  GdkPixbuf * pixbuf = NULL;

  /* first, try the menuitem's icon property */
  const gchar * icon_name = dbusmenu_menuitem_property_get (mi, USER_ITEM_PROP_ICON);
  if (icon_name)
    {
      GError* error = NULL;
      pixbuf = gdk_pixbuf_new_from_file_at_size (icon_name, ICON_SIZE, ICON_SIZE, &error);
      if (error != NULL)
        {
          g_warning ("Couldn't load the image \"%s\": %s", icon_name, error->message);
          g_clear_error (&error);
        }
    }

  /* as a fallback, try to use the default user icon */
  if (pixbuf == NULL)
    {
      pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
                                         USER_ITEM_ICON_DEFAULT,
                                         ICON_SIZE,
                                         GTK_ICON_LOOKUP_FORCE_SIZE,
                                         NULL);
    }

  if (pixbuf != NULL)
    {
      gtk_image_set_from_pixbuf (GTK_IMAGE(self->priv->user_image), pixbuf);
      g_object_unref (pixbuf);
    }
}

Here is the caller graph for this function:

static void update_logged_in ( UserWidget *  self,
DbusmenuMenuitem *  mi 
) [static]

Definition at line 221 of file user-widget.c.

{
  const gboolean b = dbusmenu_menuitem_property_get_bool (mi, USER_ITEM_PROP_LOGGED_IN);

  g_debug ("User \"%s\" %s active sessions",
           dbusmenu_menuitem_property_get (mi, USER_ITEM_PROP_NAME),
           b ? "has" : "doesn't have");

  gtk_widget_set_visible (self->priv->tick_icon, b);
}

Here is the caller graph for this function:

static void update_name ( UserWidget *  self,
DbusmenuMenuitem *  mi 
) [static]

Definition at line 233 of file user-widget.c.

{
  gtk_label_set_label (GTK_LABEL(self->priv->user_name),
                       dbusmenu_menuitem_property_get (mi, USER_ITEM_PROP_NAME));
}

Here is the caller graph for this function:

static void user_widget_class_init ( UserWidgetClass *  klass) [static]

Definition at line 65 of file user-widget.c.

{
  GObjectClass * gobject_class = G_OBJECT_CLASS (klass);

  g_type_class_add_private (klass, sizeof (UserWidgetPrivate));

  gobject_class->dispose = user_widget_dispose;
  gobject_class->finalize = user_widget_finalize;
}

Here is the call graph for this function:

static void user_widget_dispose ( GObject *  object) [static]

Definition at line 132 of file user-widget.c.

{
  G_OBJECT_CLASS (user_widget_parent_class)->dispose (object);
}

Here is the caller graph for this function:

static void user_widget_finalize ( GObject *  object) [static]

Definition at line 139 of file user-widget.c.

{
  G_OBJECT_CLASS (user_widget_parent_class)->finalize (object);
}

Here is the caller graph for this function:

static void user_widget_init ( UserWidget *  self) [static]

Definition at line 76 of file user-widget.c.

{
  self->priv = USER_WIDGET_GET_PRIVATE(self);

  UserWidgetPrivate * priv = self->priv;

  priv->user_image = NULL;
  priv->user_name  = NULL;
  priv->logged_in = FALSE;
  priv->sessions_active = FALSE;
  priv->container = NULL;
  priv->tick_icon = NULL;

  // Create the UI elements.
  priv->user_image = gtk_image_new ();
  gtk_misc_set_alignment(GTK_MISC(priv->user_image), 0.0, 0.0);
  gtk_misc_set_padding (GTK_MISC(priv->user_image),0, 4.0);

  priv->user_name = gtk_label_new ("");

  priv->container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);

  priv->tick_icon = gtk_image_new_from_icon_name ("account-logged-in",
                                                   GTK_ICON_SIZE_MENU);
  gtk_misc_set_alignment(GTK_MISC(priv->tick_icon), 1.0, 0.5);

  // Pack it together
  gtk_box_pack_start (GTK_BOX (priv->container),
                      priv->user_image,
                      FALSE,
                      FALSE,
                      0);
  gtk_box_pack_start (GTK_BOX (priv->container),
                      priv->user_name,
                      FALSE,
                      FALSE,
                      3);
  gtk_box_pack_end (GTK_BOX(priv->container),
                    priv->tick_icon,
                    FALSE,
                    FALSE, 5);

  gtk_widget_show_all (priv->container);
  gtk_container_add (GTK_CONTAINER (self), priv->container);
  gtk_widget_show_all (priv->tick_icon);
  gtk_widget_set_no_show_all (priv->tick_icon, TRUE);
  gtk_widget_hide (priv->tick_icon);


  // Fetch the drawing context.
  g_signal_connect_after (GTK_WIDGET(self), "draw",
                          G_CALLBACK(user_widget_primitive_draw_cb_gtk_3),
                          GTK_WIDGET(self));
}

Here is the call graph for this function:

GtkWidget* user_widget_new ( DbusmenuMenuitem *  item)

user_widget_new:

Returns:
: a new #UserWidget.

Definition at line 283 of file user-widget.c.

{
  GtkWidget* widget =  g_object_new(USER_WIDGET_TYPE, NULL);
  user_widget_set_twin_item ( USER_WIDGET(widget), item );
  return widget;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean user_widget_primitive_draw_cb_gtk_3 ( GtkWidget *  image,
cairo_t *  cr,
gpointer  user_data 
) [static]

Definition at line 149 of file user-widget.c.

{
  g_return_val_if_fail(IS_USER_WIDGET(user_data), FALSE);
  UserWidget* meta = USER_WIDGET(user_data);
  UserWidgetPrivate * priv = USER_WIDGET_GET_PRIVATE(meta);

  // Draw dot only when user is the current user.
  if (dbusmenu_menuitem_property_get_bool (priv->twin_item, USER_ITEM_PROP_IS_CURRENT_USER))
    {
      gdouble x, y;
      GtkStyle * style = gtk_widget_get_style (widget);

      GtkAllocation allocation;
      gtk_widget_get_allocation (widget, &allocation);
      x = allocation.x + 13;
      y = allocation.height / 2;

      cairo_arc (cr, x, y, 3.0, 0.0, 2 * G_PI);

      cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0,
                                style->fg[gtk_widget_get_state(widget)].green/65535.0,
                                style->fg[gtk_widget_get_state(widget)].blue/65535.0);
      cairo_fill (cr);
    }

  return FALSE;
}

Here is the caller graph for this function:

static void user_widget_property_update ( DbusmenuMenuitem *  mi,
const gchar *  property,
GVariant *  value,
UserWidget *  self 
) [static]

Definition at line 240 of file user-widget.c.

{
  g_return_if_fail (IS_USER_WIDGET (self));

  if (!g_strcmp0 (property, USER_ITEM_PROP_LOGGED_IN))
    {
      update_logged_in (self, mi);
    }
  else if (!g_strcmp0 (property, USER_ITEM_PROP_ICON))
    {
      update_icon (self, mi);
    }
  else if (!g_strcmp0 (property, USER_ITEM_PROP_NAME))
    {
      update_name (self, mi);
    }
  else
    {
      g_debug ("%s FIXME: unhandled property change %s", G_STRFUNC, property);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void user_widget_set_twin_item ( UserWidget *  self,
DbusmenuMenuitem *  twin_item 
) [static]

Definition at line 266 of file user-widget.c.

{
  self->priv->twin_item = mi;

  update_icon      (self, mi);
  update_name      (self, mi);
  update_logged_in (self, mi);

  g_signal_connect (G_OBJECT(mi), "property-changed",
                    G_CALLBACK(user_widget_property_update), self);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const int ICON_SIZE = 24 [static]

Definition at line 183 of file user-widget.c.