Esempio n. 1
0
const char *
cinnamon_app_get_id (CinnamonApp *app)
{
  if (app->entry)
    return gmenu_tree_entry_get_desktop_file_id (app->entry);
  return app->window_id_string;
}
Esempio n. 2
0
/**
 * shell_app_system_lookup_app_by_tree_entry:
 * @system: a #ShellAppSystem
 * @entry: a #GMenuTreeEntry
 *
 * Find a #ShellApp corresponding to a #GMenuTreeEntry.
 *
 * Return value: (transfer none): The #ShellApp for @entry, or %NULL if none
 */
ShellApp *
shell_app_system_lookup_app_by_tree_entry (ShellAppSystem  *self,
                                           GMenuTreeEntry  *entry)
{
  /* If we looked up directly in ->entry_to_app, we'd lose the
   * override of running apps.  Thus, indirect through the id.
   */
  return shell_app_system_lookup_app (self, gmenu_tree_entry_get_desktop_file_id (entry));
}
Esempio n. 3
0
static GList *
xde_entry(MenuContext *ctx, GMenuTreeEntry *ent)
{
	GDesktopAppInfo *info;
	GList *text = NULL, *acts;
	const char *name;
	char *esc1, *esc2, *cmd, *p;
	char *s, *icon = NULL;
	GIcon *gicon = NULL;
	char *appid;

	if (!(info = gmenu_tree_entry_get_app_info(ent)) || g_desktop_app_info_get_is_hidden(info)
	    || g_desktop_app_info_get_nodisplay(info) || !g_desktop_app_info_get_show_in(info, NULL)
	    || !g_app_info_should_show(G_APP_INFO(info)))
		return (text);
	name = g_app_info_get_name(G_APP_INFO(info));
	esc1 = xde_character_escape(name, ')');

	if ((appid = strdup(gmenu_tree_entry_get_desktop_file_id(ent)))
	    && (p = strstr(appid, ".desktop")))
		*p = '\0';

	if (ctx->stack)
		gicon = gmenu_tree_directory_get_icon(ctx->stack->data);
	icon = xde_get_app_icon(ctx, info, gicon, "exec", "unknown",
				GET_ENTRY_ICON_FLAG_XPM | GET_ENTRY_ICON_FLAG_PNG |
				GET_ENTRY_ICON_FLAG_JPG | GET_ENTRY_ICON_FLAG_SVG);

	if (options.launch) {
		cmd = g_strdup_printf("xdg-launch --pointer %s", appid);
	} else {
		cmd = xde_get_command(info, appid, icon);
	}
	esc2 = xde_character_escape(cmd, '}');
	icon = ctx->wmm.wrap(ctx, icon);
	if (options.actions && (acts = ctx->wmm.ops.actions(ctx, ent, info))) {
		xde_increase_indent(ctx);
		s = g_strdup_printf("%s[exec] (%s) {%s}%s\n", ctx->indent, esc1, esc2, icon);
		xde_decrease_indent(ctx);
		acts = g_list_prepend(acts, s);
		s = g_strdup_printf("%s[submenu] (%s) {%s}%s\n", ctx->indent, esc1, esc1, icon);
		acts = g_list_prepend(acts, s);
		s = g_strdup_printf("%s[end]\n", ctx->indent);
		acts = g_list_append(acts, s);
		text = g_list_concat(text, acts);
	} else {
		s = g_strdup_printf("%s[exec] (%s) {%s}%s\n", ctx->indent, esc1, esc2, icon);
		text = g_list_append(text, s);
	}
	free(icon);
	free(appid);
	free(esc1);
	free(esc2);
	free(cmd);
	return (text);
}
Esempio n. 4
0
static void
add_entry(GMenuTreeEntry *entry,
          const char     *path, GSList**p)
{
  GSList*  data = *p;
  char *utf8_path;
  char *utf8_file_id;
  Menu_list_item * item;
  gchar * file_name;

  utf8_path = g_filename_to_utf8(gmenu_tree_entry_get_desktop_file_path(entry),
                                 -1, NULL, NULL, NULL);

  utf8_file_id = g_filename_to_utf8(gmenu_tree_entry_get_desktop_file_id(entry),
                                    -1, NULL, NULL, NULL);
  file_name = utf8_path ? utf8_path : _("[Invalid Filename]");
  item = g_malloc(sizeof(Menu_list_item));
  item->item_type = MENU_ITEM_ENTRY;
  item->name = gmenu_tree_entry_get_name(entry);
  item->icon = gmenu_tree_entry_get_icon(entry);
  item->exec = gmenu_tree_entry_get_exec(entry);
  char *str = item->exec;

  while (*str)
  {
    if (*str == '%')
    {
      *str = ' ';

      if (*(str + 1))
      {
        str++;
        *str = ' ';
      }
    }

    str++;
  }

  item->comment = gmenu_tree_entry_get_comment(entry);

  item->launch_in_terminal = gmenu_tree_entry_get_launch_in_terminal(entry);
  item->desktop = g_strdup(file_name);
  data = g_slist_append(data, item);
  *p = data;

  g_free(utf8_file_id);
  g_free(utf8_path);
}
const char *
shell_app_info_get_id (ShellAppInfo *info)
{
  switch (info->type)
  {
    case SHELL_APP_INFO_TYPE_ENTRY:
      return gmenu_tree_entry_get_desktop_file_id ((GMenuTreeEntry*)info->entry);
    case SHELL_APP_INFO_TYPE_DESKTOP_FILE:
      return info->keyfile_path;
    case SHELL_APP_INFO_TYPE_WINDOW:
      return info->window_id;
  }
  g_assert_not_reached ();
  return NULL;
}
Esempio n. 6
0
static GList *
xde_entry(MenuContext *ctx, GMenuTreeEntry *ent)
{
	GDesktopAppInfo *info;
	GList *text = NULL;
	const char *name;
	char *esc1, *qname, *esc2, *cmd, *p;
	char *s, *icon = NULL;
	GIcon *gicon = NULL;
	char *appid;

	if (!(info = gmenu_tree_entry_get_app_info(ent)) || g_desktop_app_info_get_is_hidden(info)
	    || g_desktop_app_info_get_nodisplay(info) || !g_desktop_app_info_get_show_in(info, NULL)
	    || !g_app_info_should_show(G_APP_INFO(info)))
		return (text);
	name = g_app_info_get_name(G_APP_INFO(info));
	esc1 = xde_character_escape(name, '"');
	qname = g_strdup_printf("\"%s\"", esc1);

	if ((appid = strdup(gmenu_tree_entry_get_desktop_file_id(ent)))
	    && (p = strstr(appid, ".desktop")))
		*p = '\0';
	if (ctx->stack)
		gicon = gmenu_tree_directory_get_icon(ctx->stack->data);
	icon = xde_get_app_icon(ctx, info, gicon, "exec", "unknown",
				GET_ENTRY_ICON_FLAG_XPM | GET_ENTRY_ICON_FLAG_PNG |
				GET_ENTRY_ICON_FLAG_JPG | GET_ENTRY_ICON_FLAG_SVG);
	if (options.launch) {
		cmd = g_strdup_printf("xdg-launch --pointer %s", appid);
	} else {
		cmd = xde_get_command(info, appid, icon);
	}
	esc2 = xde_character_escape(cmd, '"');

	s = g_strdup_printf("    %-32s  f.exec \"exec %s &\"\n", qname, esc2);
	text = g_list_append(text, s);

	free(icon);
	free(appid);
	g_free(qname);
	free(esc1);
	free(esc2);
	free(cmd);
	return (text);
}
Esempio n. 7
0
static GList *
xde_action(MenuContext *ctx, GMenuTreeEntry *ent, GDesktopAppInfo *info, const char *action)
{
	GList *text = NULL;
	const char *name, *path;
	char *esc1, *esc2, *cmd, *p;
	char *s, *icon = NULL;
	GIcon *gicon = NULL;
	char *appid;

	name = g_desktop_app_info_get_action_name(info, action);
	esc1 = xde_character_escape(name, ')');

	if ((appid = strdup(gmenu_tree_entry_get_desktop_file_id(ent)))
			&& (p = strstr(appid, ".desktop")))
		*p = '\0';
	if (ctx->stack)
		gicon = gmenu_tree_directory_get_icon(ctx->stack->data);
	if ((path = gmenu_tree_entry_get_desktop_file_path(ent))) {
		GKeyFile *file = g_key_file_new();

		g_key_file_load_from_file(file, path, G_KEY_FILE_NONE, NULL);
		icon = xde_get_action_icon(ctx, file, action, gicon, "exec", "unknown",
				GET_ENTRY_ICON_FLAG_XPM | GET_ENTRY_ICON_FLAG_PNG |
				GET_ENTRY_ICON_FLAG_JPG | GET_ENTRY_ICON_FLAG_SVG);
		g_key_file_unref(file);
	} else
		icon = xde_get_icon2(ctx, "exec", "unknown");
	gicon = g_app_info_get_icon(G_APP_INFO(info));
	if (options.launch)
		cmd = g_strdup_printf("xdg-launch --pointer --action='%s' %s", action, appid);
	else
		cmd = xde_get_action(info, appid, icon, action);
	esc2 = xde_character_escape(cmd, '}');
	icon = ctx->wmm.wrap(ctx, icon);
	s = g_strdup_printf("%s[exec] (%s) {%s}%s\n", ctx->indent, esc1, esc2, icon);
	text = g_list_append(text, s);
	free(icon);
	free(appid);
	free(esc1);
	free(esc2);
	free(cmd);
	return (text);
}
Esempio n. 8
0
static void
print_entry(GMenuTreeEntry *entry,
            const char     *path)
{
  char *utf8_path;
  char *utf8_file_id;

  utf8_path = g_filename_to_utf8(gmenu_tree_entry_get_desktop_file_path(entry),
                                 -1, NULL, NULL, NULL);

  utf8_file_id = g_filename_to_utf8(gmenu_tree_entry_get_desktop_file_id(entry),
                                    -1, NULL, NULL, NULL);

  g_print("%s\t%s\t%s%s\n",
          path,
          utf8_file_id ? utf8_file_id : _("Invalid desktop file ID"),
          utf8_path ? utf8_path : _("[Invalid Filename]"),
          gmenu_tree_entry_get_is_excluded(entry) ? _(" <excluded>") : "");

  g_free(utf8_file_id);
  g_free(utf8_path);
}
Esempio n. 9
0
static void
get_flattened_entries_recurse (GMenuTreeDirectory *dir,
                               GHashTable         *entry_set)
{
  GMenuTreeIter *iter = gmenu_tree_directory_iter (dir);
  GMenuTreeItemType next_type;

  while ((next_type = gmenu_tree_iter_next (iter)) != GMENU_TREE_ITEM_INVALID)
    {
      gpointer item = NULL;

      switch (next_type)
        {
        case GMENU_TREE_ITEM_ENTRY:
          {
            GMenuTreeEntry *entry;
            item = entry = gmenu_tree_iter_get_entry (iter);
            /* Key is owned by entry */
            g_hash_table_replace (entry_set,
                                  (char*)gmenu_tree_entry_get_desktop_file_id (entry),
                                  gmenu_tree_item_ref (entry));
          }
          break;
        case GMENU_TREE_ITEM_DIRECTORY:
          {
            item = gmenu_tree_iter_get_directory (iter);
            get_flattened_entries_recurse ((GMenuTreeDirectory*)item, entry_set);
          }
          break;
        default:
          break;
        }
      if (item != NULL)
        gmenu_tree_item_unref (item);
    }

  gmenu_tree_iter_unref (iter);
}
Esempio n. 10
0
static char *
get_prefix_for_entry (GMenuTreeEntry *entry)
{
  char *prefix = NULL, *file_prefix = NULL;
  const char *id;
  GFile *file;
  char *name;
  int i = 0;

  id = gmenu_tree_entry_get_desktop_file_id (entry);
  file = g_file_new_for_path (gmenu_tree_entry_get_desktop_file_path (entry));
  name = g_file_get_basename (file);

  if (!name)
    {
      g_object_unref (file);
      return NULL;
    }
  for (i = 0; vendor_prefixes[i]; i++)
    {
      if (g_str_has_prefix (name, vendor_prefixes[i]))
        {
          file_prefix = g_strdup (vendor_prefixes[i]);
          break;
        }
    }

  while (strcmp (name, id) != 0)
    {
      char *t;
      char *pname;
      GFile *parent = g_file_get_parent (file);

      if (!parent)
        {
          g_warn_if_reached ();
          break;
        }

      pname = g_file_get_basename (parent);
      if (!pname)
        {
          g_object_unref (parent);
          break;
        }
      if (!g_strstr_len (id, -1, pname))
        {
          /* handle <LegacyDir prefix="..."> */
          char *t;
          size_t name_len = strlen (name);
          size_t id_len = strlen (id);
          char *t_id = g_strdup (id);

          t_id[id_len - name_len] = '\0';
          t = g_strdup(t_id);
          g_free (prefix);
          g_free (t_id);
          g_free (name);
          name = g_strdup (id);
          prefix = t;

          g_object_unref (file);
          file = parent;
          g_free (pname);
          g_free (file_prefix);
          file_prefix = NULL;
          break;
        }

      t = g_strconcat (pname, "-", name, NULL);
      g_free (name);
      name = t;

      t = g_strconcat (pname, "-", prefix, NULL);
      g_free (prefix);
      prefix = t;

      g_object_unref (file);
      file = parent;
      g_free (pname);
    }

  if (file)
    g_object_unref (file);

  if (strcmp (name, id) == 0)
    {
      g_free (name);
      if (file_prefix && !prefix)
        return file_prefix;
      if (file_prefix)
        {
          char *t = g_strconcat (prefix, "-", file_prefix, NULL);
          g_free (prefix);
          g_free (file_prefix);
          prefix = t;
        }
      return prefix;
    }

  g_free (name);
  g_free (prefix);
  g_free (file_prefix);
  g_return_val_if_reached (NULL);
}
Esempio n. 11
0
static GList *
xde_entry(MenuContext *ctx, GMenuTreeEntry *ent)
{
	GDesktopAppInfo *info;
	GList *text = NULL;
	const char *name;
	char *esc1, *esc2, *cmd, *p;
	char *icon = NULL, *wrap, *s;
	GIcon *gicon = NULL;
	gboolean notify;
	char *wmclass, *appid;

	if (!(info = gmenu_tree_entry_get_app_info(ent)) || g_desktop_app_info_get_is_hidden(info)
	    || g_desktop_app_info_get_nodisplay(info) || !g_desktop_app_info_get_show_in(info, NULL)
	    || !g_app_info_should_show(G_APP_INFO(info)))
		return (text);
	name = g_app_info_get_name(G_APP_INFO(info));

	esc1 = g_markup_escape_text(name, -1);

	if (ctx->stack)
		gicon = gmenu_tree_directory_get_icon(ctx->stack->data);
	icon = xde_get_app_icon(ctx, info, gicon, "exec", "unknown",
				GET_ENTRY_ICON_FLAG_XPM | GET_ENTRY_ICON_FLAG_PNG |
				GET_ENTRY_ICON_FLAG_JPG | GET_ENTRY_ICON_FLAG_SVG);
	wrap = ctx->wmm.wrap(ctx, strdup(icon));

	notify = g_desktop_app_info_get_boolean(info, G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY);
	wmclass = g_desktop_app_info_get_string(info, G_KEY_FILE_DESKTOP_KEY_STARTUP_WM_CLASS);

	if ((appid = strdup(gmenu_tree_entry_get_desktop_file_id(ent)))
	    && (p = strstr(appid, ".desktop")))
		*p = '\0';

	if (options.launch) {
		cmd = g_strdup_printf("xdg-launch --pointer %s", appid);
	} else {
		cmd = xde_get_command(info, appid, icon);
	}

	esc2 = g_markup_escape_text(cmd, -1);

	s = g_strdup_printf("%s<item label=\"%s\"%s>\n", ctx->indent, esc1, wrap);
	text = g_list_append(text, s);
	s = g_strdup_printf("%s  <action name=\"Execute\">\n", ctx->indent);
	text = g_list_append(text, s);
	s = g_strdup_printf("%s    <command>%s</command>\n", ctx->indent, esc2);
	text = g_list_append(text, s);

	if (!options.launch && (notify || wmclass)) {
		/* don't put launch specifics if we are launching with xdg-launch */
		s = g_strdup_printf("%s    <startupnotify>\n", ctx->indent);
		text = g_list_append(text, s);
		if (notify) {
			s = g_strdup_printf("%s      <enabled>yes</enabled>\n", ctx->indent);
			text = g_list_append(text, s);
		}
		if (wmclass) {
			s = g_strdup_printf("%s      <wmclass>%s</wmclass>\n", ctx->indent,
					    wmclass);
			text = g_list_append(text, s);
		}
		s = g_strdup_printf("%s      <name>%s</name>\n", ctx->indent, esc1);
		text = g_list_append(text, s);
		if (icon) {
			s = g_strdup_printf("%s      <icon>%s</icon>\n", ctx->indent, icon);
			text = g_list_append(text, s);
		}
		s = g_strdup_printf("%s    </startupnotify>\n", ctx->indent);
		text = g_list_append(text, s);
	}

	s = g_strdup_printf("%s  </action>\n", ctx->indent);
	text = g_list_append(text, s);
	s = g_strdup_printf("%s</item>\n", ctx->indent);
	text = g_list_append(text, s);

	free(wrap);
	free(icon);
	g_free(wmclass);
	free(appid);
	g_free(esc1);
	g_free(esc2);
	free(cmd);
	return (text);
}
/*! \fn gboolean CDesktopAppChooser::m_AddAppsMenuLeafNode(GMenuTreeDirectory *appsDir)
    \brief To create leaf nodes(applications).

    \param[in] appsDir
    \return TRUE or FALSE
*/
gboolean CDesktopAppChooser::m_AddAppsMenuLeafNode(GMenuTreeDirectory *appsDir)
{
  GSList *itemList = NULL;

  if( G_UNLIKELY(!appsDir) )
    return false;

  for( itemList = gmenu_tree_directory_get_contents(appsDir);
       itemList;
       itemList = itemList->next )
  {
     GMenuTreeItem  *item = (GMenuTreeItem*)itemList->data;
     GMenuTreeItemType type = gmenu_tree_item_get_type(item);

     if( type == GMENU_TREE_ITEM_DIRECTORY )
     {
        /* To pars sub-directory items and add it to the menu tree.
           Here using recursive parse. */
        m_AddAppsMenuLeafNode( (GMenuTreeDirectory*)item );
     }
     else if( type == GMENU_TREE_ITEM_ENTRY )
     {
        GdkPixbuf *pixbuf = NULL;
        const gchar *icon_name = gmenu_tree_entry_get_icon( (GMenuTreeEntry*)item );
        APP_ITEM_INFO *appInfo = NULL;
				
        /* To determine if the current item need not to be shown. If it is, continue. */
        if(gmenu_tree_entry_get_is_nodisplay( (GMenuTreeEntry*)item ) || 
           gmenu_tree_entry_get_is_excluded( (GMenuTreeEntry*)item ) )
          continue;
					
        /* To create the icon for the currently read node. */
        if(icon_name)
          pixbuf = m_LoadIcon(icon_name, IMG_SIZE, TRUE );
        else
          pixbuf = m_LoadIcon(DEFAULT_APP__MIME_ICON, IMG_SIZE, TRUE );  // If there has no icon name in .desktop file, using the system default icon for application.

        /* To create a object containing information about current leaf node. */
        appInfo = new APP_ITEM_INFO ;

        /* Zero out the new allocated memory. */
        memset(appInfo, 0x00, sizeof(APP_ITEM_INFO));

        if(appInfo)
        {
           gchar *name = (gchar*)gmenu_tree_entry_get_name( (GMenuTreeEntry*)item ) ;
           gchar *exec = (gchar*)gmenu_tree_entry_get_exec( (GMenuTreeEntry*)item );
           gchar *comment = (gchar*)gmenu_tree_entry_get_comment( (GMenuTreeEntry*)item );

           #if 1
           gchar *desktopfile = (gchar*)gmenu_tree_entry_get_desktop_file_path( (GMenuTreeEntry*)item );
           #else
           gchar *desktopfile = (gchar*)gmenu_tree_entry_get_desktop_file_id( (GMenuTreeEntry*)item );
           #endif

           if(name)
             appInfo->name = (gchar*)g_strdup(name);

           if(icon_name)
             appInfo->icon = (gchar*)g_strdup(icon_name);

           if(exec)
             appInfo->exec = (gchar*)g_strdup(exec);

           if(comment)
             appInfo->comment = (gchar*)g_strdup(comment);

           if(desktopfile)
             appInfo->desktopfile = (gchar*)g_strdup(desktopfile);
        }

        /* Add a tree leaf. */
        gtk_tree_store_append(m_TreeStore, &m_ChildNodeIter, &m_TopLevelNodeIter);
        gtk_tree_store_set(m_TreeStore, &m_ChildNodeIter,
                           COLUMN_ICON, pixbuf,
                           COLUMN_TEXT, gmenu_tree_entry_get_name( (GMenuTreeEntry*)item ),
                           COLUMN_NODEDATA, appInfo,
                           -1);					
				
        /* pixbuf has a referece count of "1" now, as the tree store has added its own reference. 
           So to decrease the reference count of pixbuf. */
        g_object_unref(pixbuf);
    }
  } // The end of for() 

  return true;
}
Esempio n. 13
0
static void write_entry( FILE* of, GMenuTreeEntry* item )
{
    const char* cstr;
    char* str;
    int flags = 0;

//    if( gmenu_tree_entry_get_is_nodisplay(item) /* || gmenu_tree_entry_get_is_excluded(item) */ )
//        return;

    /* dekstop id, not necessarily the same as file basename */
    fprintf( of, "-%s\n", gmenu_tree_entry_get_desktop_file_id( item ) );

    /* Name */
    fprintf( of, "%s\n", gmenu_tree_entry_get_name( item ) );

    /* Comment */
    cstr = gmenu_tree_entry_get_comment( item );
    fprintf( of, "%s\n", cstr ? cstr : "" );

    /* Icon */
    cstr = gmenu_tree_entry_get_icon( item );
    fprintf( of, "%s\n", cstr ? cstr : "" );

    /* file dir/basename */
    if( gmenu_tree_entry_get_desktop_file_path( item ) )
    {
        /* file basenames are the same as desktop ids, except that sometimes
         * the '/' in paths are replaced with '-'.
         * for ex, /usr/share/applications/foo/bar.desktop has the app dir
         * /usr/share/applications, the filename foo/bar.desltop, and the
         * desktop id: foo-bar.desktop
         */

        /* filename */
        str = g_path_get_basename( gmenu_tree_entry_get_desktop_file_path( item ) );
        if( strcmp(str, gmenu_tree_entry_get_desktop_file_id(item) ) )
            fprintf( of, "%s\n", str );
        else
            fprintf( of, "\n" );
        g_free( str );

        /* dirname */
        str = g_path_get_dirname( gmenu_tree_entry_get_desktop_file_path( item ) );
        fprintf( of, "%d\n", dirname_index( str) );
        g_free( str );
    }
    else
    {
        fprintf( of, "\n-1\n" );
    }

    /* DisplayName */
    cstr = gmenu_tree_entry_get_display_name( item );
    fprintf( of, "%s\n", cstr ? cstr : "" );

    /* Exec */
    fprintf( of, "%s\n", gmenu_tree_entry_get_exec( item ) );

    /* Terminal/StartupNotify flags */
    if( gmenu_tree_entry_get_launch_in_terminal( item ) )
        flags |= FLAG_USE_TERMINAL;
    if( gmenu_tree_entry_get_use_startup_notify( item ) )
        flags |= FLAG_USE_SN;
    if( gmenu_tree_entry_get_is_nodisplay( item ) )
        flags |= FLAG_IS_NODISPLAY;
    fprintf( of, "%u\n", flags );

    /* ShowIn info */
    fprintf( of, "%d\n", gmenu_tree_entry_get_show_in_flags(item) );
/*
    if( gmenu_tree_entry_get_desktop_file_path( item ) )
        write_item_ex_info(of, gmenu_tree_entry_get_desktop_file_path( item ));
    fputs( "\n", of );
*/

}