Ejemplo n.º 1
0
/**
 * dbusmenu_menuitem_property_get_image:
 * @menuitem: The #DbusmenuMenuitem to look for the property on
 * @property: The name of the property to look for.
 * 
 * This function looks on the menu item for a property by the
 * name of @property.  If one exists it tries to turn it into
 * a #GdkPixbuf.  It assumes that the property is a base64 encoded
 * PNG file like the one created by #dbusmenu_menuite_property_set_image.
 * 
 * Return value: (transfer full): A pixbuf or #NULL to signal error.
 */
GdkPixbuf *
dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * property)
{
	g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), NULL);
	g_return_val_if_fail(property != NULL && property[0] != '\0', NULL);

	gsize length = 0;
	const guchar * icondata = dbusmenu_menuitem_property_get_byte_array(menuitem, property, &length);

	/* There is no icon */
	if (length == 0) {
		return NULL;
	}
	
	GInputStream * input = g_memory_input_stream_new_from_data(icondata, length, NULL);
	if (input == NULL) {
		g_warning("Cound not create input stream from icon property data");
		return NULL;
	}

	GError * error = NULL;
	GdkPixbuf * icon = gdk_pixbuf_new_from_stream(input, NULL, &error);

	if (error != NULL) {
		g_warning("Unable to build Pixbuf from icon data: %s", error->message);
		g_error_free(error);
	}

	g_object_unref(input);

	return icon;
}
Ejemplo n.º 2
0
/**
 * dbusmenu_menuitem_property_set_shortcut:
 * @menuitem: The #DbusmenuMenuitem to set the shortcut on
 * @key: The keycode of the key to send
 * @modifier: A bitmask of modifiers used to activate the item
 * 
 * Takes the modifer described by @key and @modifier and places that into
 * the format sending across Dbus for shortcuts.
 * 
 * Return value: Whether it was successful at setting the property.
 */
gboolean
dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, GdkModifierType modifier)
{
	g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE);
	g_return_val_if_fail(gtk_accelerator_valid(key, modifier), FALSE);

	const gchar * keyname = gdk_keyval_name(key);
	g_return_val_if_fail(keyname != NULL, FALSE);

	GVariantBuilder builder;
	g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);

	if (modifier & GDK_CONTROL_MASK) {
		g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_CONTROL);
	}
	if (modifier & GDK_MOD1_MASK) {
		g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_ALT);
	}
	if (modifier & GDK_SHIFT_MASK) {
		g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_SHIFT);
	}
	if (modifier & GDK_SUPER_MASK) {
		g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_SUPER);
	}

	g_variant_builder_add(&builder, "s", keyname);

	GVariant * inside = g_variant_builder_end(&builder);
	g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
	g_variant_builder_add_value(&builder, inside);
	GVariant * outsidevariant = g_variant_builder_end(&builder);

	return dbusmenu_menuitem_property_set_variant(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, outsidevariant);
}
Ejemplo n.º 3
0
/**
 * dbusmenu_menuitem_property_set_image:
 * @menuitem: The #DbusmenuMenuitem to set the property on.
 * @property: Name of the property to set.
 * @data: The image to place on the property.
 * 
 * This function takes the pixbuf that is stored in @data and
 * turns it into a base64 encoded PNG so that it can be placed
 * onto a standard #DbusmenuMenuitem property.
 * 
 * Return value: Whether the function was able to set the property
 * 	or not.
*/
gboolean
dbusmenu_menuitem_property_set_image (DbusmenuMenuitem * menuitem, const gchar * property, const GdkPixbuf * data)
{
	g_return_val_if_fail(GDK_IS_PIXBUF(data), FALSE);
	g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE);
	g_return_val_if_fail(property != NULL && property[0] != '\0', FALSE);

	GError * error = NULL;
	gchar * png_data;
	gsize png_data_len;

	if (!gdk_pixbuf_save_to_buffer((GdkPixbuf *)data, &png_data, &png_data_len, "png", &error, NULL)) {
		if (error == NULL) {
			g_warning("Unable to create pixbuf data stream: %d", (gint)png_data_len);
		} else {
			g_warning("Unable to create pixbuf data stream: %s", error->message);
			g_error_free(error);
			error = NULL;
		}

		return FALSE;
	}

	gboolean propreturn = FALSE;
	propreturn = dbusmenu_menuitem_property_set_byte_array(menuitem, property, (guchar *)png_data, png_data_len);

	g_free(png_data);

	return propreturn;
}
Ejemplo n.º 4
0
static gboolean
new_metadata_widget (DbusmenuMenuitem * newitem,
                     DbusmenuMenuitem * parent,
                     DbusmenuClient * client,
                     gpointer user_data)
{
  g_debug("indicator-sound: new_metadata_widget");

  GtkWidget* metadata = NULL;

  g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE);
  g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE);


  metadata = metadata_widget_new (newitem);

  g_debug ("%s (\"%s\")", __func__,
           dbusmenu_menuitem_property_get(newitem, DBUSMENU_METADATA_MENUITEM_PLAYER_NAME));

  GtkMenuItem *menu_metadata_widget = GTK_MENU_ITEM(metadata);

  gtk_widget_show_all(metadata);
  dbusmenu_gtkclient_newitem_base (DBUSMENU_GTKCLIENT(client),
                                   newitem,
                                   menu_metadata_widget,
                                   parent);
  return TRUE;
}
Ejemplo n.º 5
0
static gboolean
new_transport_widget (DbusmenuMenuitem * newitem,
                      DbusmenuMenuitem * parent,
                      DbusmenuClient * client,
                      gpointer user_data)
{
  g_debug("indicator-sound: new_transport_bar() called ");

  GtkWidget* bar = NULL;
  ///IndicatorObject *io = NULL;

  g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE);
  g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE);

  bar = transport_widget_new(newitem);
  /**io = g_object_get_data (G_OBJECT (client), "indicator");
  IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io));
  priv->transport_widgets_list = g_list_append ( priv->transport_widgets_list, bar );*/
	myData.transport_widgets_list = g_list_append ( myData.transport_widgets_list, bar );
  
  GtkMenuItem *menu_transport_bar = GTK_MENU_ITEM(bar);

  gtk_widget_show_all(bar);
  dbusmenu_gtkclient_newitem_base (DBUSMENU_GTKCLIENT(client),
                                   newitem,
                                   menu_transport_bar,
                                   parent);
  return TRUE;
}
Ejemplo n.º 6
0
static gboolean
new_mute_widget(DbusmenuMenuitem * newitem,
                DbusmenuMenuitem * parent,
                DbusmenuClient * client,
                gpointer user_data)
{
  ///IndicatorObject *io = NULL;

  g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE);
  g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE);

  /**io = g_object_get_data (G_OBJECT (client), "indicator");
  IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io));*/
	AppletData *priv = myDataPtr;
  
  if (priv->mute_widget != NULL){ 
    g_object_unref (priv->mute_widget);
    priv->mute_widget = NULL;
  }

  priv->mute_widget = mute_widget_new(newitem);
  GtkMenuItem *item = mute_widget_get_menu_item (priv->mute_widget);

  dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client),
                                  newitem,
                                  item,
                                  parent);

  return TRUE;
}
Ejemplo n.º 7
0
/**
 * dbusmenu_menuitem_property_get_shortcut:
 * @menuitem: The #DbusmenuMenuitem to get the shortcut off
 * @key: (out): Location to put the key value
 * @modifier: (out): Location to put the modifier mask
 * 
 * This function gets a GTK shortcut as a key and a mask
 * for use to set the accelerators.
 */
void
dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * key, GdkModifierType * modifier)
{
	guint dummykey;
	GdkModifierType dummymodifier;

	if (key == NULL) {
		key = &dummykey;
	}

	if (modifier == NULL) {
		modifier = &dummymodifier;
	}

	*key = 0;
	*modifier = 0;

	g_return_if_fail(DBUSMENU_IS_MENUITEM(menuitem));

	GVariant * wrapper = dbusmenu_menuitem_property_get_variant(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT);
	if (wrapper == NULL) {
		return;
	}

	if (g_variant_n_children(wrapper) != 1) {
		g_warning("Unable to parse shortcut, too many keys");
		return;
	}

	GVariantIter iter;
	GVariant * child = g_variant_get_child_value(wrapper, 0);
	g_variant_iter_init(&iter, child);
	gchar * string;

	while(g_variant_iter_loop(&iter, "s", &string)) {
		if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) {
			*modifier |= GDK_CONTROL_MASK;
		} else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) {
			*modifier |= GDK_MOD1_MASK;
		} else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) {
			*modifier |= GDK_SHIFT_MASK;
		} else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) {
			*modifier |= GDK_SUPER_MASK;
		} else {
			GdkModifierType tempmod;
			gtk_accelerator_parse(string, key, &tempmod);
		}
	}

	g_variant_unref(child);

	return;
}
Ejemplo n.º 8
0
static gboolean
new_volume_slider_widget(DbusmenuMenuitem * newitem,
                         DbusmenuMenuitem * parent,
                         DbusmenuClient * client,
                         gpointer user_data)
{
  g_debug("indicator-sound: new_volume_slider_widget");

  GtkWidget* volume_widget = NULL;
  ///IndicatorObject *io = NULL;

  g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE);
  g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE);

  /**io = g_object_get_data (G_OBJECT (client), "indicator");
  IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io));*/
	AppletData *priv = myDataPtr;

  if (priv->volume_widget != NULL){ 
    ///volume_widget_tidy_up (priv->volume_widget);
    gtk_widget_destroy (priv->volume_widget);
    priv->volume_widget = NULL;
  }
  volume_widget = volume_widget_new (newitem/**, io*/);
  priv->volume_widget = volume_widget;
  // Don't forget to set the accessible desc.
  /// TODO: check that it's not needed...
  update_accessible_desc (-1/**io*/);
  

  GtkWidget* ido_slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget));

  gtk_widget_show_all(ido_slider_widget);
  // register the style callback on this widget with state manager's style change
  // handler (needs to remake the blocking animation for each style).
  /**g_signal_connect (ido_slider_widget, "style-set",
                    G_CALLBACK(sound_state_manager_style_changed_cb),
                    priv->state_manager);*/

  GtkMenuItem *menu_volume_item = GTK_MENU_ITEM(ido_slider_widget);
  dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client),
                                  newitem,
                                  menu_volume_item,
                                  parent);
  return TRUE;
}
Ejemplo n.º 9
0
/**
 * dbusmenu_menuitem_property_set_shortcut_string:
 * @menuitem: The #DbusmenuMenuitem to set the shortcut on
 * @shortcut: String describing the shortcut
 * 
 * This function takes a GTK shortcut string as defined in
 * #gtk_accelerator_parse and turns that into the information
 * required to send it over DBusmenu.
 * 
 * Return value: Whether it was successful at setting the property.
 */
gboolean
dbusmenu_menuitem_property_set_shortcut_string (DbusmenuMenuitem * menuitem, const gchar * shortcut)
{
	g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE);
	g_return_val_if_fail(shortcut != NULL, FALSE);

	guint key = 0;
	GdkModifierType modifier = 0;

	gtk_accelerator_parse(shortcut, &key, &modifier);

	if (key == 0) {
		g_warning("Unable to parse shortcut string '%s'", shortcut);
		return FALSE;
	}

	return dbusmenu_menuitem_property_set_shortcut(menuitem, key, modifier);
}
Ejemplo n.º 10
0
/**
 * dbusmenu_menuitem_property_set_shortcut_menuitem:
 * @menuitem: The #DbusmenuMenuitem to set the shortcut on
 * @gmi: A menu item to steal the shortcut off of
 * 
 * Takes the shortcut that is installed on a menu item and calls
 * #dbusmenu_menuitem_property_set_shortcut with it.  It also sets
 * up listeners to watch it change.
 * 
 * Return value: Whether it was successful at setting the property.
 */
gboolean
dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, const GtkMenuItem * gmi)
{
	g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE);
	g_return_val_if_fail(GTK_IS_MENU_ITEM(gmi), FALSE);

	GClosure * closure = NULL;
        GtkWidget *label = gtk_bin_get_child(GTK_BIN (gmi));

        if (GTK_IS_ACCEL_LABEL (label))
          {
            g_object_get (label,
                          "accel-closure", &closure,
                          NULL);
          }

        if (closure == NULL) {
          /* As a fallback, check for a closure in the related menu item.  This
             actually happens with SWT menu items. */
          GList * closures = gtk_widget_list_accel_closures (GTK_WIDGET (gmi));
          if (closures == NULL)
            return FALSE;
          closure = closures->data;
          g_list_free (closures);
	}

	GtkAccelGroup * group = gtk_accel_group_from_accel_closure(closure);

	/* Apparently this is more common than I thought. */
	if (group == NULL) {
		return FALSE;
	}

	GtkAccelKey * key = gtk_accel_group_find(group, find_closure, closure);
	/* Again, not much we can do except complain loudly. */
	g_return_val_if_fail(key != NULL, FALSE);

        if (!gtk_accelerator_valid (key->accel_key, key->accel_mods))
            return FALSE;

	return dbusmenu_menuitem_property_set_shortcut(menuitem, key->accel_key, key->accel_mods);
}
Ejemplo n.º 11
0
/* Draws a triangle on the left, using fg[STATE_TYPE] color. */
static gboolean
application_triangle_draw_cb (GtkWidget *widget, cairo_t *ctx, gpointer data)
{
	int x, y, arrow_width, arrow_height;

	if (!GTK_IS_WIDGET (widget)) return FALSE;
	if (!DBUSMENU_IS_MENUITEM (data)) return FALSE;

	/* render the triangle indicator only if the application is running */
	if (! dbusmenu_menuitem_property_get_bool (DBUSMENU_MENUITEM(data), APPLICATION_MENUITEM_PROP_RUNNING))
		return FALSE;;

	arrow_width = 5; /* the pixel-based reference triangle is 5x9 */
	arrow_height = 9;
	
	/* get style + arrow position */
	double red, green, blue;
	GtkStyleContext *style = gtk_widget_get_style_context (widget);
	GdkRGBA color;
	gtk_style_context_get_color (style, gtk_widget_get_state(widget), &color);
	red = color.red;
	green = color.green;
	blue = color.blue;
	x = 0;  // the context is already translated so that (0;0) is the top-left corner of the widget.
	y = gtk_widget_get_allocated_height (widget)/2.0 - (double)arrow_height/2.0;

	cairo_set_line_width (ctx, 1.0);

	/* cairo drawing code */
	cairo_move_to (ctx, x, y);
	cairo_line_to (ctx, x, y + arrow_height);
	cairo_line_to (ctx, x + arrow_width, y + (double)arrow_height/2.0);
	cairo_close_path (ctx);
	cairo_set_source_rgb (ctx, red, green, blue);
	cairo_fill (ctx);

	return FALSE;
}
Ejemplo n.º 12
0
/**
 * new_voip_slider_widget
 * Create the voip menu item widget, must of the time this widget will be hidden.
 * @param newitem
 * @param parent
 * @param client
 * @param user_data
 * @return
 */
static gboolean
new_voip_slider_widget (DbusmenuMenuitem * newitem,
                        DbusmenuMenuitem * parent,
                        DbusmenuClient * client,
                        gpointer user_data)
{
  g_debug("indicator-sound: new_voip_slider_widget");
  GtkWidget* voip_widget = NULL;
  ///IndicatorObject *io = NULL;

  g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE);
  g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE);

  /**io = g_object_get_data (G_OBJECT (client), "indicator");
  IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io));*/
	AppletData *priv = myDataPtr;

  if (priv->voip_widget != NULL){ 
    ///voip_input_widget_tidy_up (priv->voip_widget);
    gtk_widget_destroy (priv->voip_widget);
    priv->voip_widget = NULL;
  }

  voip_widget = voip_input_widget_new (newitem);
  priv->voip_widget = voip_widget;

  GtkWidget* ido_slider_widget = voip_input_widget_get_ido_slider(VOIP_INPUT_WIDGET(voip_widget));

  gtk_widget_show_all(ido_slider_widget);

  GtkMenuItem *menu_volume_item = GTK_MENU_ITEM(ido_slider_widget);
  dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client),
                                  newitem,
                                  menu_volume_item,
                                  parent);
  return TRUE;
}