Exemple #1
0
static void
setup_button (Launcher *launcher)
{
	char *comment;
	char *name;
	char *str;
	char *icon;
	char *unescaped_str;
	
	g_return_if_fail (launcher != NULL);

	name = panel_key_file_get_locale_string (launcher->key_file, "Name");
	comment = panel_key_file_get_locale_string (launcher->key_file,
						    "Comment");

	/* Setup tooltip */
	if (!PANEL_GLIB_STR_EMPTY (name) && !PANEL_GLIB_STR_EMPTY (comment))
		str = g_strdup_printf ("%s\n%s", name, comment);
	else if (!PANEL_GLIB_STR_EMPTY (name))
		str = g_strdup (name);
	else
		str = g_strdup (comment);

	g_free (name);
	g_free (comment);

	/* If we can unescape the string, then we probably have an escaped
	 * string (a location e.g.). If we can't, then it most probably means
	 * we have a % that is not here to encode a character, and we don't
	 * want to unescape in this case. See bug #170516 for details. */
	unescaped_str = g_uri_unescape_string (str, NULL);
	if (unescaped_str) {
		g_free (str);
		str = unescaped_str;
	}

	panel_util_set_tooltip_text (launcher->button, str);

	/* Setup accessible name */
	panel_a11y_set_atk_name_desc (launcher->button, str, NULL);

	g_free (str);

	/* Setup icon */
	icon = panel_key_file_get_locale_string (launcher->key_file, "Icon");
	if (icon && icon[0] == '\0') {
		g_free (icon);
		icon = NULL;
	}

	if (!icon)
		icon = guess_icon_from_exec (button_widget_get_icon_theme (BUTTON_WIDGET (launcher->button)),
					     launcher->key_file);
	if (!icon)
		icon = g_strdup (PANEL_ICON_LAUNCHER);

	button_widget_set_icon_name (BUTTON_WIDGET (launcher->button), icon);
	g_free (icon);
}
void
panel_layout_delete_object (const char *object_id)
{
        char *path;
        char *id_copy;

        if (PANEL_GLIB_STR_EMPTY (object_id))
                return;

        /* The original will be freed if removal succeeds */
        id_copy = g_strdup (object_id);

        if (!panel_gsettings_remove_all_from_strv (layout_settings,
                                                   PANEL_LAYOUT_OBJECT_ID_LIST_KEY,
                                                   id_copy)) {
                g_free (id_copy);
                return;
        }

        path = g_strdup_printf ("%s%s/",
                                PANEL_LAYOUT_OBJECT_PATH, id_copy);
        panel_dconf_recursive_reset (path, NULL);
        g_free (path);

        path = panel_layout_object_get_gconf_path (id_copy);
        panel_gconf_recursive_unset (path, NULL);
        g_free (path);

        g_free (id_copy);
}
Exemple #3
0
static void
panel_layout_load_toplevel (const char *toplevel_id)
{
        PanelToplevel *toplevel;
        char          *path;

        if (PANEL_GLIB_STR_EMPTY (toplevel_id))
                return;

        path = g_strdup_printf ("%s%s/",
                                PANEL_LAYOUT_TOPLEVEL_PATH, toplevel_id);

        toplevel = g_object_new (PANEL_TYPE_TOPLEVEL,
                                 "decorated", FALSE,
                                 "settings-path", path,
                                 "toplevel-id", toplevel_id,
                                 "type-hint", GDK_WINDOW_TYPE_HINT_DOCK,
                                 NULL);

        g_free (path);

        /* FIXME: we shouldn't have to do this manually */
        panel_setup (toplevel);

        gtk_widget_show (GTK_WIDGET (toplevel));
}
Exemple #4
0
static char *
panel_util_get_file_display_for_common_files (GFile *file)
{
    GFile *compare;

    compare = g_file_new_for_path (g_get_home_dir ());
    if (g_file_equal (file, compare)) {
        GSettings *settings = g_settings_new (GNOME_NAUTILUS_DESKTOP_SCHEMA);
        char *home_foler_name = g_settings_get_string (settings, GNOME_NAUTILUS_DESKTOP_HOME_ICON_NAME_KEY);

        g_object_unref (compare);
        g_object_unref (settings);

        if (PANEL_GLIB_STR_EMPTY (home_foler_name)) {
            g_free (home_foler_name);
            return g_strdup (_("Home Folder"));
        } else {
            return home_foler_name;
        }
    }
    g_object_unref (compare);

    compare = g_file_new_for_path ("/");
    if (g_file_equal (file, compare)) {
        g_object_unref (compare);
        /* Translators: this is the same string as the one found in
         * nautilus */
        return g_strdup (_("File System"));
    }
    g_object_unref (compare);

    return NULL;
}
Exemple #5
0
gchar *
get_applications_menu (void)
{
	const gchar *xdg_menu_prefx = g_getenv ("XDG_MENU_PREFIX");
	return g_strdup_printf ("%sapplications.menu",
	                        !PANEL_GLIB_STR_EMPTY (xdg_menu_prefx) ? xdg_menu_prefx : "gnome-");
}
char *
panel_object_type_to_iid (PanelObjectType  type,
                          const char      *detail)
{
        int i;

        if (type == PANEL_OBJECT_APPLET)
                return g_strdup (detail);

        for (i = 0; i < G_N_ELEMENTS (panel_object_iid_map); i++) {
                if (panel_object_iid_map[i].type != type)
                        continue;

                if (panel_object_iid_map[i].has_detail &&
                    PANEL_GLIB_STR_EMPTY (detail))
                        return NULL;

                if (panel_object_iid_map[i].has_detail)
                        return g_strdup_printf ("%s::%s:%s",
                                                PANEL_INTERNAL_FACTORY,
                                                panel_object_iid_map[i].id,
                                                detail);
                else
                        return g_strdup_printf ("%s::%s",
                                                PANEL_INTERNAL_FACTORY,
                                                panel_object_iid_map[i].id);
        }

        return NULL;
}
Exemple #7
0
static char *
panel_util_get_file_display_for_common_files (GFile *file)
{
	GFile *compare;

	compare = g_file_new_for_path (g_get_home_dir ());
	if (g_file_equal (file, compare)) {
		char *gconf_name;

		g_object_unref (compare);

		gconf_name = gconf_client_get_string (panel_gconf_get_client (),
						      HOME_NAME_KEY,
						      NULL);
		if (PANEL_GLIB_STR_EMPTY (gconf_name)) {
			g_free (gconf_name);
			return g_strdup (_("Home Folder"));
		} else {
			return gconf_name;
		}
	}
	g_object_unref (compare);

	compare = g_file_new_for_path ("/");
	if (g_file_equal (file, compare)) {
		g_object_unref (compare);
		/* Translators: this is the same string as the one found in
		 * nautilus */
		return g_strdup (_("File System"));
	}
	g_object_unref (compare);

	return NULL;
}
static void
panel_properties_dialog_setup_image_chooser (PanelPropertiesDialog *dialog,
					     GtkBuilder            *gui)
{
	char *image;

	dialog->image_chooser = PANEL_GTK_BUILDER_GET (gui, "image_chooser");
	panel_gtk_file_chooser_add_image_preview (GTK_FILE_CHOOSER (dialog->image_chooser));

	image = panel_profile_get_background_image (dialog->toplevel);

	if (PANEL_GLIB_STR_EMPTY (image))
		gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog->image_chooser));
	else
		gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog->image_chooser),
					       image);
	
	if (image)
		g_free (image);

	dialog->selection_emitted = 0;
	g_signal_connect_swapped (dialog->image_chooser, "selection-changed",
				  G_CALLBACK (panel_properties_dialog_image_changed),
				  dialog);

	if ( ! panel_profile_background_key_is_writable (dialog->toplevel, "image")) {
		gtk_widget_set_sensitive (dialog->image_chooser, FALSE);
		gtk_widget_show (dialog->writability_warn_background);
	}
}
Exemple #9
0
static void
panel_addto_name_change (PanelAddtoDialog *dialog,
			 const char       *name)
{
	char *title;
	char *label;

	label = NULL;

	if (!PANEL_GLIB_STR_EMPTY (name))
		label = g_strdup_printf (_("Find an _item to add to \"%s\":"),
					 name);

	if (panel_toplevel_get_is_attached (dialog->panel_widget->toplevel)) {
		title = g_strdup_printf (_("Add to Drawer"));
		if (label == NULL)
			label = g_strdup (_("Find an _item to add to the drawer:"));
	} else {
		title = g_strdup_printf (_("Add to Panel"));
		if (label == NULL)
			label = g_strdup (_("Find an _item to add to the panel:"));
	}

	gtk_window_set_title (GTK_WINDOW (dialog->addto_dialog), title);
	g_free (title);

	gtk_label_set_text_with_mnemonic (GTK_LABEL (dialog->label), label);
	g_free (label);
}
static void
panel_properties_dialog_update_background_image (PanelPropertiesDialog *dialog,
						 gchar                 *text)
{
	char       *old_text;

	old_text = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog->image_chooser));

	if (PANEL_GLIB_STR_EMPTY (text) && old_text)
		gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog->image_chooser));
	else if (!PANEL_GLIB_STR_EMPTY (text) &&
		 (!old_text || strcmp (text, old_text)))
		gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog->image_chooser),
					       text);

	if (old_text)
		g_free (old_text);
}
Exemple #11
0
static gboolean
drop_url (PanelWidget         *panel,
	  PanelObjectPackType  pack_type,
	  int                  pack_index,
	  const char          *url)
{
	enum {
		NETSCAPE_URL_URL,
		NETSCAPE_URL_NAME
	};
	char **netscape_url;
	char  *name;
	char  *comment;

	g_return_val_if_fail (url != NULL, FALSE);

	if (!panel_layout_is_writable ())
		return FALSE;

	netscape_url = g_strsplit (url, "\n", 2);
	if (!netscape_url ||
	    PANEL_GLIB_STR_EMPTY (netscape_url[NETSCAPE_URL_URL])) {
		g_strfreev (netscape_url);
		return FALSE;
	}
	
	comment = g_strdup_printf (_("Open URL: %s"),
				   netscape_url[NETSCAPE_URL_URL]);

	if (PANEL_GLIB_STR_EMPTY (netscape_url[NETSCAPE_URL_NAME]))
		name = netscape_url[NETSCAPE_URL_URL];
	else
		name = netscape_url[NETSCAPE_URL_NAME];

	panel_launcher_create_from_info (panel->toplevel, pack_type, pack_index,
					 FALSE,
					 netscape_url[NETSCAPE_URL_URL],
					 name, comment, PANEL_ICON_REMOTE);

	g_free (comment);
	g_strfreev (netscape_url);

	return TRUE;
}
void
panel_layout_delete_toplevel (const char *toplevel_id)
{
        char  *path;
        char  *id_copy;
        char **objects;
        int    i;

        if (PANEL_GLIB_STR_EMPTY (toplevel_id))
                return;

        /* The original will be freed if removal succeeds */
        id_copy = g_strdup (toplevel_id);

        if (!panel_gsettings_remove_all_from_strv (layout_settings,
                                                   PANEL_LAYOUT_TOPLEVEL_ID_LIST_KEY,
                                                   id_copy)) {
                g_free (id_copy);
                return;
        }

        path = g_strdup_printf ("%s%s/",
                                PANEL_LAYOUT_TOPLEVEL_PATH, id_copy);
        panel_dconf_recursive_reset (path, NULL);

        /* remove all applets that were on this toplevel */

        objects = g_settings_get_strv (layout_settings,
                                       PANEL_LAYOUT_OBJECT_ID_LIST_KEY);

        for (i = 0; objects[i] != NULL; i++) {
                GSettings *settings;
                char       *object_toplevel_id;

                path = g_strdup_printf ("%s%s/",
                                        PANEL_LAYOUT_OBJECT_PATH, objects[i]);

                settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA, path);
                object_toplevel_id = g_settings_get_string (settings,
                                                            PANEL_OBJECT_TOPLEVEL_ID_KEY);

                g_object_unref (settings);
                g_free (path);

                if (g_strcmp0 (id_copy, object_toplevel_id) == 0)
                        panel_layout_delete_object (objects[i]);

                g_free (object_toplevel_id);
        }

        g_strfreev (objects);

        g_free (id_copy);
}
static void
panel_layout_load_object (const char *object_id)
{
        char *path;

        if (PANEL_GLIB_STR_EMPTY (object_id))
                return;

        path = g_strdup_printf ("%s%s/",
                                PANEL_LAYOUT_OBJECT_PATH, object_id);

        panel_object_loader_queue (object_id, path);

        g_free (path);
}
static void
panel_properties_dialog_background_image_update (PanelPropertiesDialog *dialog)
{
	char *uri;

	uri = g_settings_get_string (dialog->settings_background,
				     PANEL_BACKGROUND_IMAGE_URI_KEY);

	if (PANEL_GLIB_STR_EMPTY (uri))
		gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog->image_chooser));
	else
		gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog->image_chooser),
					  uri);

	g_free (uri);
}
Exemple #15
0
char *
panel_util_get_user_name (void)
{
	char *name;

	name = g_locale_to_utf8 (g_get_real_name (), -1, NULL, NULL, NULL);

	if (PANEL_GLIB_STR_EMPTY (name) || g_strcmp0 (name, "Unknown") == 0) {
		g_free (name);
		name = g_locale_to_utf8 (g_get_user_name (), -1 , NULL, NULL, NULL);
	}

	if (!name)
		name = g_strdup (g_get_user_name ());

	return name;
}
Exemple #16
0
void
launcher_load (PanelWidget *panel_widget,
	       const char  *id,
	       GSettings   *settings)
{
	GSettings *settings_instance;
	Launcher  *launcher;
	char      *launcher_location;

	g_return_if_fail (panel_widget != NULL);
	g_return_if_fail (id != NULL);

	settings_instance = panel_layout_get_instance_settings (settings,
								PANEL_LAUNCHER_SCHEMA);

	launcher_location = g_settings_get_string (settings_instance,
						   PANEL_LOCATION_KEY);

	if (PANEL_GLIB_STR_EMPTY (launcher_location)) {
		g_printerr (_("Launcher location is not set, cannot load launcher\n"));
		g_free (launcher_location);
		g_object_unref (settings_instance);
		return;
	}

	launcher = load_launcher_applet (launcher_location,
					 panel_widget,
					 id, settings);

	if (launcher) {
		if (!g_settings_is_writable (settings_instance,
					     PANEL_LOCATION_KEY)) {
			AppletUserMenu *menu;

			menu = panel_applet_get_callback (launcher->info->user_menu,
							  "properties");
			if (menu != NULL)
				menu->sensitive = FALSE;
		}
	}

	g_free (launcher_location);
	g_object_unref (settings_instance);
}
Exemple #17
0
static char *
panel_addto_make_text (const char *name,
		       const char *desc)
{
	const char *real_name;
	char       *result;

	real_name = name ? name : _("(empty)");

	if (!PANEL_GLIB_STR_EMPTY (desc)) {
		result = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>\n%s",
						  real_name, desc);
	} else {
		result = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
						  real_name);
	}

	return result;
}
Exemple #18
0
void
panel_util_set_tooltip_text (GtkWidget  *widget,
			     const char *text)
{
        g_signal_handlers_disconnect_matched (widget,
					      G_SIGNAL_MATCH_FUNC,
					      0, 0, NULL,
					      panel_util_query_tooltip_cb,
					      NULL);

	if (PANEL_GLIB_STR_EMPTY (text)) {
		g_object_set (widget, "has-tooltip", FALSE, NULL);
		return;
	}

	g_object_set (widget, "has-tooltip", TRUE, NULL);
	g_signal_connect_data (widget, "query-tooltip",
			       G_CALLBACK (panel_util_query_tooltip_cb),
			       g_strdup (text), (GClosureNotify) g_free, 0);
}
gchar *
panel_compatibility_get_applet_iid (GSettings   *settings,
				    const gchar *id)
{
	PanelAppletInfo *info;
	gchar *object_iid;
	gboolean needs_migration;
	const char *iid;

	needs_migration = FALSE;

	object_iid = g_settings_get_string (settings, PANEL_OBJECT_IID_KEY);
	if (PANEL_GLIB_STR_EMPTY (object_iid)) {
		g_free (object_iid);
		return NULL;
	}

	info = panel_applets_manager_get_applet_info_from_old_id (object_iid);
	if (!info)
		info = panel_applets_manager_get_applet_info (object_iid);

	if (!info) {
		g_free (object_iid);
		return NULL;
	}

	iid = panel_applet_info_get_iid (info);

	/* migrate if the iid in the configuration is different than the real
	 * iid that will get used */
	if (!g_str_equal (iid, object_iid))
		needs_migration = TRUE;

	g_free (object_iid);

	if (needs_migration)
		g_settings_set_string (settings, PANEL_OBJECT_IID_KEY, iid);

	return g_strdup (iid);
}
void
panel_object_loader_queue (const char *id,
                           const char *settings_path)
{
        PanelObjectToLoad *object;
        GSettings         *settings;
        char              *toplevel_id;

        if (panel_object_loader_is_queued (id))
                return;

        settings = g_settings_new_with_path (PANEL_OBJECT_SCHEMA,
                                             settings_path);
        toplevel_id = g_settings_get_string (settings,
                                             PANEL_OBJECT_TOPLEVEL_ID_KEY);

        if (PANEL_GLIB_STR_EMPTY (toplevel_id)) {
                g_warning ("No toplevel on which to load object '%s'\n", id);
                g_free (toplevel_id);
                g_object_unref (settings);
                return;
        }

        object = g_new0 (PanelObjectToLoad, 1);

        object->id            = g_strdup (id);
        object->settings_path = g_strdup (settings_path);
        object->settings      = g_object_ref (settings);
        object->toplevel_id   = toplevel_id;
        object->pack_type     = g_settings_get_enum (settings,
                                                     PANEL_OBJECT_PACK_TYPE_KEY);
        object->pack_index    = g_settings_get_int (settings,
                                                    PANEL_OBJECT_PACK_INDEX_KEY);

        panel_objects_to_load = g_slist_prepend (panel_objects_to_load, object);

        g_object_unref (settings);
}
Exemple #21
0
static char *
panel_util_get_file_display_for_common_files (GFile *file)
{
	GFile *compare;

	compare = g_file_new_for_path (g_get_home_dir ());
	if (g_file_equal (file, compare)) {
		GSettings *caja_desktop_settings;
		char *caja_home_icon_name = NULL;

		g_object_unref (compare);

		if (mate_gsettings_schema_exists (CAJA_DESKTOP_SCHEMA)) {
			caja_desktop_settings = g_settings_new (CAJA_DESKTOP_SCHEMA);
			caja_home_icon_name = g_settings_get_string (caja_desktop_settings,
														 CAJA_DESKTOP_HOME_ICON_NAME_KEY);
			g_object_unref (caja_desktop_settings);
		}
		if (PANEL_GLIB_STR_EMPTY (caja_home_icon_name)) {
			g_free (caja_home_icon_name);
			return g_strdup (_("Home Folder"));
		} else {
			return caja_home_icon_name;
		}
	}
	g_object_unref (compare);

	compare = g_file_new_for_path ("/");
	if (g_file_equal (file, compare)) {
		g_object_unref (compare);
		/* Translators: this is the same string as the one found in
		 * caja */
		return g_strdup (_("File System"));
	}
	g_object_unref (compare);

	return NULL;
}
static void
panel_layout_load_toplevel (const char *toplevel_id)
{
        PanelToplevel *toplevel;
        char          *path;
        GSettings     *settings;
        int            screen;

        if (PANEL_GLIB_STR_EMPTY (toplevel_id))
                return;

        path = g_strdup_printf ("%s%s/",
                                PANEL_LAYOUT_TOPLEVEL_PATH, toplevel_id);

        /* Check that the screen is valid */
        settings = g_settings_new_with_path (PANEL_TOPLEVEL_SCHEMA, path);
        screen = g_settings_get_int (settings, PANEL_TOPLEVEL_SCREEN_KEY);
        g_object_unref (settings);

        if (screen < 0 || screen >= panel_multiscreen_screens ()) {
                g_free (path);
                return;
        }

        toplevel = g_object_new (PANEL_TYPE_TOPLEVEL,
                                 "toplevel-id", toplevel_id,
                                 "settings-path", path,
                                 NULL);

        g_free (path);

        /* FIXME: we shouldn't have to do this manually */
        panel_setup (toplevel);

        gtk_widget_show (GTK_WIDGET (toplevel));
}
Exemple #23
0
static GtkWidget *
panel_place_menu_item_create_menu (PanelPlaceMenuItem *place_item)
{
	GtkWidget *places_menu;
	GtkWidget *item;
	char      *gsettings_name = NULL;
	char      *name;
	char      *uri;
	GFile     *file;

	places_menu = panel_create_menu ();

	file = g_file_new_for_path (g_get_home_dir ());
	uri = g_file_get_uri (file);
	name = panel_util_get_label_for_uri (uri);
	g_object_unref (file);

	panel_menu_items_append_place_item (PANEL_ICON_HOME, NULL,
					    name,
					    _("Open your personal folder"),
					    places_menu,
					    G_CALLBACK (activate_home_uri),
					    uri);
	g_free (name);
	g_free (uri);

	if (!place_item->priv->caja_prefs_settings ||
		!g_settings_get_boolean (place_item->priv->caja_prefs_settings,
				     CAJA_PREFS_DESKTOP_IS_HOME_DIR_KEY)) {
		file = g_file_new_for_path (g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP));
		uri = g_file_get_uri (file);
		g_object_unref (file);

		panel_menu_items_append_place_item (
				PANEL_ICON_DESKTOP, NULL,
				/* Translators: Desktop is used here as in
				 * "Desktop Folder" (this is not the Desktop
				 * environment). */
				C_("Desktop Folder", "Desktop"),
				_("Open the contents of your desktop in a folder"),
				places_menu,
				G_CALLBACK (activate_desktop_uri),
				/* FIXME: if the dir changes, we'd need to update the drag data since the uri is not the same */
				uri);
		g_free (uri);
	}

	panel_place_menu_item_append_gtk_bookmarks (places_menu, g_settings_get_uint (place_item->priv->menubar_settings, PANEL_MENU_BAR_MAX_ITEMS_OR_SUBMENU));
	add_menu_separator (places_menu);

	if (place_item->priv->caja_desktop_settings != NULL)
		gsettings_name = g_settings_get_string (place_item->priv->caja_desktop_settings,
								CAJA_DESKTOP_COMPUTER_ICON_NAME_KEY);

	if (PANEL_GLIB_STR_EMPTY (gsettings_name))
		gsettings_name = g_strdup (_("Computer"));

	panel_menu_items_append_place_item (
			PANEL_ICON_COMPUTER, NULL,
			gsettings_name,
			_("Browse all local and remote disks and folders accessible from this computer"),
			places_menu,
			G_CALLBACK (activate_uri),
			"computer://");

	if (gsettings_name)
		g_free (gsettings_name);

	panel_place_menu_item_append_local_gio (place_item, places_menu);
	add_menu_separator (places_menu);

	panel_menu_items_append_place_item (
			PANEL_ICON_NETWORK, NULL,
			_("Network"),
			_("Browse bookmarked and local network locations"),
			places_menu,
			G_CALLBACK (activate_uri),
			"network://");
	panel_place_menu_item_append_remote_gio (place_item, places_menu);

	if (panel_is_program_in_path ("caja-connect-server") ||
	    panel_is_program_in_path ("nautilus-connect-server") ||
	    panel_is_program_in_path ("nemo-connect-server")) {
		item = panel_menu_items_create_action_item (PANEL_ACTION_CONNECT_SERVER);
		if (item != NULL)
			gtk_menu_shell_append (GTK_MENU_SHELL (places_menu),
					       item);
	}

	add_menu_separator (places_menu);

	if (panel_is_program_in_path ("mate-search-tool"))
		panel_menu_items_append_from_desktop (places_menu,
						      "mate-search-tool.desktop",
						      NULL,
						      FALSE);
	else
		panel_menu_items_append_from_desktop (places_menu,
						      "gnome-search-tool.desktop",
						      NULL,
						      FALSE);

	panel_recent_append_documents_menu (places_menu,
					    place_item->priv->recent_manager);
/* Fix any failures of compiz/other wm's to communicate with gtk for transparency */
	GtkWidget *toplevel = gtk_widget_get_toplevel (places_menu);
	GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(toplevel));
	GdkVisual *visual = gdk_screen_get_rgba_visual(screen);
	gtk_widget_set_visual(GTK_WIDGET(toplevel), visual); 

	return places_menu;
}
Exemple #24
0
static void
panel_menu_items_append_from_desktop (GtkWidget *menu,
				      char      *path,
				      char      *force_name,
                                      gboolean   use_icon)
{
	GKeyFile  *key_file;
	gboolean   loaded;
	GtkWidget *item;
	char      *path_freeme;
	char      *full_path;
	char      *uri;
	char      *type;
	gboolean   is_application;
	char      *tryexec;
	char      *icon;
	char      *name;
	char      *comment;

	path_freeme = NULL;

	key_file = g_key_file_new ();

	if (g_path_is_absolute (path)) {
		loaded = g_key_file_load_from_file (key_file, path,
						    G_KEY_FILE_NONE, NULL);
		full_path = path;
	} else {
		char *lookup_file;
		char *desktop_path;

		if (!g_str_has_suffix (path, ".desktop")) {
			desktop_path = g_strconcat (path, ".desktop", NULL);
		} else {
			desktop_path = path;
		}

		lookup_file = g_strconcat ("applications", G_DIR_SEPARATOR_S,
					   desktop_path, NULL);
		loaded = g_key_file_load_from_data_dirs (key_file, lookup_file,
							 &path_freeme,
							 G_KEY_FILE_NONE,
							 NULL);
		full_path = path_freeme;
		g_free (lookup_file);

		if (desktop_path != path)
			g_free (desktop_path);
	}

	if (!loaded) {
		g_key_file_free (key_file);
		if (path_freeme)
			g_free (path_freeme);
		return;
	}

	/* For Application desktop files, respect TryExec */
	type = panel_key_file_get_string (key_file, "Type");
	if (!type) {
		g_key_file_free (key_file);
		if (path_freeme)
			g_free (path_freeme);
		return;
	}
	is_application = (strcmp (type, "Application") == 0);
	g_free (type);

	if (is_application) {
		tryexec = panel_key_file_get_string (key_file, "TryExec");
		if (tryexec) {
			char *prog;

			prog = g_find_program_in_path (tryexec);
			g_free (tryexec);

			if (!prog) {
				/* FIXME: we could add some file monitor magic,
				 * so that the menu items appears when the
				 * program appears, but that's really complex
				 * for not a huge benefit */
				g_key_file_free (key_file);
				if (path_freeme)
					g_free (path_freeme);
				return;
			}

			g_free (prog);
		}
	}

	/* Now, simply build the menu item */
	icon    = panel_key_file_get_locale_string (key_file, "Icon");
	comment = panel_key_file_get_locale_string (key_file, "Comment");

	if (PANEL_GLIB_STR_EMPTY (force_name))
		name = panel_key_file_get_locale_string (key_file, "Name");
	else
		name = g_strdup (force_name);

	if (use_icon) {
		item = panel_image_menu_item_new ();
        } else {
		item = gtk_image_menu_item_new ();
	}

	setup_menu_item_with_icon (item, panel_menu_icon_get_size (),
				   icon, NULL, NULL, name);

	panel_util_set_tooltip_text (item, comment);

	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
	g_signal_connect_data (item, "activate",
			       G_CALLBACK (panel_menu_item_activate_desktop_file),
			       g_strdup (full_path),
			       (GClosureNotify) g_free, 0);
	g_signal_connect (G_OBJECT (item), "button_press_event",
			  G_CALLBACK (menu_dummy_button_press_event), NULL);

	uri = g_filename_to_uri (full_path, NULL, NULL);

	setup_uri_drag (item, uri, icon, GDK_ACTION_COPY);
	g_free (uri);

	g_key_file_free (key_file);

	if (icon)
		g_free (icon);

	if (name)
		g_free (name);

	if (comment)
		g_free (comment);

	if (path_freeme)
		g_free (path_freeme);
}