application-window: Move desktop file handling code to separate function

https://bugzilla.gnome.org/show_bug.cgi?id=674118
This commit is contained in:
Kalev Lember 2012-04-14 21:30:26 +03:00
parent ba81a3a14c
commit 234c7fcf28

View File

@ -257,6 +257,32 @@ gtk_application_window_update_menubar (GtkApplicationWindow *window)
} }
} }
static gchar *
gtk_application_window_get_app_desktop_name ()
{
gchar *retval = NULL;
#ifdef HAVE_GIO_UNIX
GDesktopAppInfo *app_info;
const gchar *app_name = NULL;
gchar *desktop_file;
desktop_file = g_strconcat (g_get_prgname (), ".desktop", NULL);
app_info = g_desktop_app_info_new (desktop_file);
g_free (desktop_file);
if (app_info != NULL)
app_name = g_app_info_get_name (G_APP_INFO (app_info));
if (app_name != NULL)
retval = g_strdup (app_name);
g_clear_object (&app_info);
#endif /* HAVE_GIO_UNIX */
return retval;
}
static void static void
gtk_application_window_update_shell_shows_app_menu (GtkApplicationWindow *window, gtk_application_window_update_shell_shows_app_menu (GtkApplicationWindow *window,
GtkSettings *settings) GtkSettings *settings)
@ -282,33 +308,25 @@ gtk_application_window_update_shell_shows_app_menu (GtkApplicationWindow *window
if (app_menu != NULL) if (app_menu != NULL)
{ {
const gchar *name; const gchar *app_name;
GDesktopAppInfo *app_info = NULL; gchar *name;
name = g_get_application_name (); app_name = g_get_application_name ();
if (name == g_get_prgname ()) if (app_name != g_get_prgname ())
{ {
const gchar *app_name = NULL; /* the app has set its application name, use it */
name = g_strdup (app_name);
#ifdef HAVE_GIO_UNIX
gchar *desktop_name;
desktop_name = g_strconcat (name, ".desktop", NULL);
app_info = g_desktop_app_info_new (desktop_name);
if (app_info != NULL)
app_name = g_app_info_get_name (G_APP_INFO (app_info));
g_free (desktop_name);
#endif /* HAVE_GIO_UNIX */
if (app_name != NULL &&
g_strcmp0 (app_name, name) != 0)
name = app_name;
else
name = _("Application");
} }
else
{
/* get the name from .desktop file */
name = gtk_application_window_get_app_desktop_name ();
if (name == NULL)
name = g_strdup (_("Application"));
}
g_menu_append_submenu (window->priv->app_menu_section, name, app_menu); g_menu_append_submenu (window->priv->app_menu_section, name, app_menu);
g_clear_object (&app_info); g_free (name);
} }
} }
} }