void
panel_menu_button_set_menu_path (PanelMenuButton *button,
				 const char      *menu_uri)
{
	const char *menu_path;
	char       *scheme;

	g_return_if_fail (PANEL_IS_MENU_BUTTON (button));

	scheme    = NULL;
	menu_path = split_menu_uri (menu_uri, &scheme);

	if (!scheme)
		return;

	button->priv->path_root = panel_menu_scheme_to_path_root (scheme);
	g_free (scheme);

	if (!button->priv->menu_path && (!menu_path || !menu_path [0]))
		return;

	if (button->priv->menu_path && menu_path &&
	    !strcmp (button->priv->menu_path, menu_path))
		return;

	g_free (button->priv->menu_path);
	button->priv->menu_path = NULL;

	button->priv->menu_path = g_strdup (menu_path);

	if (button->priv->menu)
		gtk_menu_detach (GTK_MENU (button->priv->menu));
	button->priv->menu = NULL;

	panel_menu_button_set_icon (button);
}
Exemplo n.º 2
0
static void
update_menu (GpMenuButtonApplet *menu_button)
{
  GpMenuButtonAppletPrivate *priv;
  gchar *menu_path;
  gchar *scheme;
  gchar *path;

  priv = gp_menu_button_applet_get_instance_private (menu_button);

  g_clear_object (&priv->menu);
  g_clear_object (&priv->lock_logout);

  menu_path = g_settings_get_string (priv->settings, "menu-path");

  scheme = NULL;
  path = split_menu_uri (menu_path, &scheme);
  g_free (menu_path);

  if (path != NULL)
    {
      gchar *menu_file;

      menu_file = NULL;
      if (validate_scheme (scheme, &menu_file))
        {
          priv->menu = gp_menu_new (menu_file, TRUE);
          gp_menu_set_path (GP_MENU (priv->menu), path);

          priv->custom_menu = TRUE;

          g_signal_connect_swapped (priv->menu, "loaded",
                                    G_CALLBACK (update_icon), menu_button);
        }

      g_free (menu_file);
      g_free (scheme);
      g_free (path);
    }

  if (priv->menu == NULL)
    {
      gchar *menu_file;

      menu_file = gp_menu_utils_get_applications_menu ();
      priv->menu = gp_menu_new (menu_file, TRUE);
      g_free (menu_file);

      g_assert (priv->lock_logout == NULL);
      priv->lock_logout = gp_lock_logout_new ();

      g_object_bind_property (menu_button, "enable-tooltips",
                              priv->lock_logout, "enable-tooltips",
                              G_BINDING_DEFAULT |
                              G_BINDING_SYNC_CREATE);

      g_object_bind_property (menu_button, "locked-down",
                              priv->lock_logout, "locked-down",
                              G_BINDING_DEFAULT |
                              G_BINDING_SYNC_CREATE);

      g_object_bind_property (menu_button, "menu-icon-size",
                              priv->lock_logout, "menu-icon-size",
                              G_BINDING_DEFAULT |
                              G_BINDING_SYNC_CREATE);

      g_signal_connect_swapped (priv->lock_logout, "changed",
                                G_CALLBACK (gp_menu_reload), priv->menu);

      gp_menu_set_append_func (GP_MENU (priv->menu),
                               (GpAppendMenuItemsFunc) append_menu_items_cb,
                               menu_button);

      priv->custom_menu = FALSE;
    }

  g_object_bind_property (menu_button, "enable-tooltips",
                          priv->menu, "enable-tooltips",
                          G_BINDING_DEFAULT |
                          G_BINDING_SYNC_CREATE);

  g_object_bind_property (menu_button, "locked-down",
                          priv->menu, "locked-down",
                          G_BINDING_DEFAULT |
                          G_BINDING_SYNC_CREATE);

  g_object_bind_property (menu_button, "menu-icon-size",
                          priv->menu, "menu-icon-size",
                          G_BINDING_DEFAULT |
                          G_BINDING_SYNC_CREATE);

  g_object_ref_sink (priv->menu);
}