static void
shell_app_system_init (ShellAppSystem *self)
{
  ShellAppSystemPrivate *priv;

  self->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
                                                   SHELL_TYPE_APP_SYSTEM,
                                                   ShellAppSystemPrivate);

  /* The key is owned by the value */
  priv->app_id_to_info = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                NULL, (GDestroyNotify) shell_app_info_unref);

  /* Key is owned by info */
  priv->app_id_to_app = g_hash_table_new (g_str_hash, g_str_equal);

  /* For now, we want to pick up Evince, Nautilus, etc.  We'll
   * handle NODISPLAY semantics at a higher level or investigate them
   * case by case.
   */
  priv->apps_tree = gmenu_tree_lookup ("applications.menu", GMENU_TREE_FLAGS_INCLUDE_NODISPLAY);
  priv->settings_tree = gmenu_tree_lookup ("gnomecc.menu", GMENU_TREE_FLAGS_INCLUDE_NODISPLAY);

  priv->app_change_timeout_id = 0;

  gmenu_tree_add_monitor (priv->apps_tree, on_tree_changed_cb, self);
  gmenu_tree_add_monitor (priv->settings_tree, on_tree_changed_cb, self);

  reread_menus (self);
}
/*! \fn gboolean CDesktopAppChooser::m_LoadAndBuildAppsMenuTree(void)
    \brief To load the main application menu(.menu) file. 

    \param[in] NONE
    \return TRUE or FALSE
*/
gboolean CDesktopAppChooser::m_LoadAndBuildAppsMenuTree(void)
{
  GSList *directoryList = NULL;

  /*------------ THE ENTRY POINT !!! -------------*/
  /* To open the applications .menu file. */
  m_MenuTree = gmenu_tree_lookup( APPLICATIONS_MENU, GMENU_TREE_FLAGS_NONE );

  /* To store the parsed direcotry contents. */
  m_RootDir = gmenu_tree_get_root_directory( m_MenuTree );

  /* To build the top-level tree node. */
  for(directoryList = gmenu_tree_directory_get_contents( m_RootDir ); 
      directoryList; 
      directoryList = directoryList->next )
  {
     GMenuTreeDirectory *tmpDir = (GMenuTreeDirectory*)directoryList->data;

     /* To check its type. */
     if( G_UNLIKELY(gmenu_tree_item_get_type((GMenuTreeItem*)tmpDir) != GMENU_TREE_ITEM_DIRECTORY) )
       continue;

     /* To build top-level(Directory) nodes. */          
     m_AddAppsMenuTopLevelNode(tmpDir);

     /* To build child nodes(applications). */
     m_AddAppsMenuLeafNode(tmpDir);		
  }

  return true;
}
Пример #3
0
GeeArrayList* slingshot_backend_gmenu_entries_get_categories (void) {
    GeeArrayList* result = NULL;
    GMenuTree* _tmp0_ = NULL;
    GMenuTree* _tmp1_;
    GMenuTree* tree;
    GMenuTree* _tmp2_;
    GMenuTreeDirectory* _tmp3_ = NULL;
    GMenuTreeDirectory* _tmp4_;
    GMenuTreeDirectory* root;
    GeeArrayList* _tmp5_;
    GeeArrayList* main_directory_entries;
    GMenuTreeDirectory* _tmp6_;
    GSList* _tmp7_ = NULL;
    _tmp0_ = gmenu_tree_lookup ("applications.menu", GMENU_TREE_FLAGS_INCLUDE_EXCLUDED);
    _tmp1_ = _gmenu_tree_ref0 (_tmp0_);
    tree = _tmp1_;
    _tmp2_ = tree;
    _tmp3_ = gmenu_tree_get_root_directory (_tmp2_);
    _tmp4_ = _gmenu_tree_item_ref0 (_tmp3_);
    root = _tmp4_;
    _tmp5_ = gee_array_list_new (G_TYPE_POINTER, (GBoxedCopyFunc) gmenu_tree_item_ref, gmenu_tree_item_unref, NULL);
    main_directory_entries = _tmp5_;
    _tmp6_ = root;
    _tmp7_ = gmenu_tree_directory_get_contents (_tmp6_);
    {
        GSList* item_collection = NULL;
        GSList* item_it = NULL;
        item_collection = _tmp7_;
        for (item_it = item_collection; item_it != NULL; item_it = item_it->next) {
            GMenuTreeItem* _tmp8_;
            GMenuTreeItem* item = NULL;
            _tmp8_ = _gmenu_tree_item_ref0 ((GMenuTreeItem*) item_it->data);
            item = _tmp8_;
            {
                GMenuTreeItem* _tmp9_;
                GMenuTreeItemType _tmp10_ = 0;
                _tmp9_ = item;
                _tmp10_ = gmenu_tree_item_get_type (_tmp9_);
                if (_tmp10_ == GMENU_TREE_ITEM_DIRECTORY) {
                    GeeArrayList* _tmp11_;
                    GMenuTreeItem* _tmp12_;
                    _tmp11_ = main_directory_entries;
                    _tmp12_ = item;
                    gee_abstract_collection_add ((GeeAbstractCollection*) _tmp11_, (GMenuTreeDirectory*) _tmp12_);
                }
                _gmenu_tree_item_unref0 (item);
            }
        }
    }
    result = main_directory_entries;
    _gmenu_tree_item_unref0 (root);
    _gmenu_tree_unref0 (tree);
    return result;
}
Пример #4
0
void main(int argc, char *argv[])
{
  GMenuTree *tree = NULL;
  GMenuTreeDirectory *directory = NULL;
  GMenuTreeEntry *entry = NULL;
  const char *name = NULL;

  gtk_set_locale ();

  tree = gmenu_tree_lookup ("lxde-applications.menu", GMENU_TREE_FLAGS_NONE);
  directory = gmenu_tree_get_root_directory(tree);

  walk_tree(directory);
}
Пример #5
0
GSList* get_menu_data(gboolean show_search, gboolean show_run, gboolean show_places, gboolean show_logout, char* file_manager, char*logout)
{
  /*FIXME... I'm leaking a bit of memory here */

  Menu_list_item * dir_item;
  GSList*  data = NULL;
  GMenuTree *  menu_tree;
  const char * menu_file[] = {"gnomecc.menu", "preferences.menu", "settings.menu", NULL};//
  GMenuTreeDirectory *root;
  int i;

  if (!gnome_vfs_initialized())
    gnome_vfs_init();

  G_file_manager = file_manager;

  menu_tree = gmenu_tree_lookup("applications.menu", GMENU_TREE_FLAGS_NONE);

  if (menu_tree)
  {
    root = gmenu_tree_get_root_directory(menu_tree);

    if (root)
    {
      fill_er_up(root, &data);
      gmenu_tree_item_unref(root);
    }
  }


  data = g_slist_prepend(data, get_blank());

  data = g_slist_append(data, get_separator());

  menu_tree = gmenu_tree_lookup("gnomecc.menu", GMENU_TREE_FLAGS_NONE);

  if (menu_tree)
  {
    root = gmenu_tree_get_root_directory(menu_tree);

    if (root)
    {
      dir_item = g_malloc(sizeof(Menu_list_item));
      dir_item->item_type = MENU_ITEM_DIRECTORY;
      dir_item->name = g_strdup("Control Centre");
      dir_item->comment = g_strdup("Gnome Control Centre");
      dir_item->null = NULL;
      dir_item->sublist = NULL;
      dir_item->icon = g_strdup("gnome-control-center");
      data = g_slist_append(data, dir_item);

      fill_er_up(root, &dir_item->sublist);
      dir_item->sublist = g_slist_prepend(dir_item->sublist, get_blank());
      dir_item->sublist = g_slist_append(dir_item->sublist, get_blank());
      gmenu_tree_item_unref(root);
    }
  }

  menu_tree = gmenu_tree_lookup("settings.menu", GMENU_TREE_FLAGS_NONE);

  if (menu_tree)
  {
    root = gmenu_tree_get_root_directory(menu_tree);

    if (root)
    {
      dir_item = g_malloc(sizeof(Menu_list_item));
      dir_item->item_type = MENU_ITEM_DIRECTORY;
      dir_item->name = g_strdup("Settings");
      dir_item->comment = g_strdup("System Settings");
      dir_item->sublist = NULL;
      dir_item->null = NULL;
      dir_item->icon = g_strdup("gnome-settings");
      data = g_slist_append(data, dir_item);

      fill_er_up(root, &dir_item->sublist);
      dir_item->sublist = g_slist_prepend(dir_item->sublist, get_blank());
      dir_item->sublist = g_slist_append(dir_item->sublist, get_blank());
      gmenu_tree_item_unref(root);
    }
  }

  data = g_slist_append(data, get_separator());


  if (show_places)
  {
    dir_item = g_malloc(sizeof(Menu_list_item));
    dir_item->item_type = MENU_ITEM_DIRECTORY;
    dir_item->name = g_strdup("Places");
    dir_item->icon = g_strdup("bookmark");
    dir_item->comment = g_strdup("Your special places :-)");
    dir_item->sublist = NULL;
    dir_item->monitor = monitor_places;
    data = g_slist_append(data, dir_item);
    update_places(&dir_item->sublist, file_manager);
  }

  if (show_search)
  {
    dir_item = g_malloc(sizeof(Menu_list_item));
    dir_item->item_type = MENU_ITEM_SEARCH;
    dir_item->name = g_strdup("Find:");
    dir_item->icon = g_strdup("stock_search");
    dir_item->comment = g_strdup("Search");
    dir_item->sublist = NULL;
    dir_item->search_entry = NULL;
    data = g_slist_append(data, dir_item);
  }

  if (show_run)
  {
    dir_item = g_malloc(sizeof(Menu_list_item));
    dir_item->item_type = MENU_ITEM_RUN;
    dir_item->name = g_strdup("Run:");
    dir_item->icon = g_strdup("exec");
    dir_item->comment = g_strdup("Run a program");
    dir_item->sublist = NULL;
    dir_item->search_entry = NULL;
    data = g_slist_append(data, dir_item);

  }



  if (show_logout)
  {
    dir_item = g_malloc(sizeof(Menu_list_item));
    dir_item->item_type = MENU_ITEM_ENTRY;
    dir_item->name = g_strdup("Logout...");
    dir_item->icon = g_strdup("gnome-logout");
    dir_item->exec = g_strdup(logout);
    dir_item->desktop = g_strdup("");
    dir_item->comment = g_strdup("Logout and related activities.");
    dir_item->sublist = NULL;
    data = g_slist_append(data, dir_item);

  }

  data = g_slist_append(data, get_blank());

  return data;
}
Пример #6
0
/*=============================================================================
 * Main Function
 */
int main (int argc, char **argv)
{
    int i;
    char *xdgfile = NULL;
    
    for (i = 1; i < argc; i++)
    {
        if ((strcmp (argv[i], "-h") == 0) || (strcmp (argv[i], "--help") == 0))
        {
          show_help ();
          g_free (xdgfile);
          return 0;
        }
        else if ((strcmp (argv[i], "--show-amount") == 0) ||
        (strcmp (argv[i], "-a") == 0))
        {
            option_show_amount_of_entries = 1;
        }
        else if ((strcmp (argv[i], "--plain") == 0) ||
        (strcmp (argv[i], "-p") == 0))
        {
            option_do_not_use_categories = 1;
        }
        else if (argv[i][0] != '-')
        {
            if (xdgfile != NULL) {
                g_printf ("Unexpected amount of arguments.\n");
                g_free (xdgfile);
                return 1;
            }
            xdgfile = g_strdup (argv[i]);
        }
        else
        {
            g_printf ("Unknown argument: %s\n", argv[i]);
            return 1;
        }
    }
    
    if (xdgfile == NULL) {
        show_help ();
        g_free (xdgfile);
        return 1;
    }
    
    FILE * file;
    if (!(file = fopen(xdgfile, "r")))
    {
        g_printf ("Could not read file \"%s\".\n", xdgfile);
        g_free (xdgfile);
        return 2;
    }
    fclose(file);
    
    GMenuTree *menuTree = gmenu_tree_lookup (xdgfile,  GMENU_TREE_FLAGS_NONE );
    
    GMenuTreeDirectory *rootDirectory = gmenu_tree_get_root_directory(menuTree);
    
    g_printf ("<openbox_pipe_menu>\n");
    g_printf ("<separator label=\"Menu XDG\" />\n");

    process_directory(rootDirectory, 1);
    
    gmenu_tree_item_unref (rootDirectory);
    
    g_printf ("</openbox_pipe_menu>\n");
    
    g_free (xdgfile);
    return 0;
}
Пример #7
0
int main(int argc, char** argv)
{
    GOptionContext* opt_ctx;
    GError* err = NULL;
    GMenuTree* menu_tree = NULL;
    GMenuTreeDirectory* root_dir;
    GSList* l;
    FILE *of;
    int ofd;
    char *tmp;
    char *dir;
    const gchar* const * xdg_cfg_dirs;
    const gchar* const * pdir;
    const char* menu_prefix;
    char* menu_file;
    char* plus_ptr = NULL;

    setlocale (LC_ALL, "");

    opt_ctx = g_option_context_new("Generate cache for freedesktop.org compliant menus.");
    g_option_context_add_main_entries( opt_ctx, opt_entries, NULL );
    if( ! g_option_context_parse( opt_ctx, &argc, &argv, &err ) )
    {
        g_print( "%s", err->message );
        g_error_free( err );
        return 1;
    }

    if( lang )
        g_setenv( "LANGUAGE", lang, TRUE );
#if 0
    /* if the cache is already up-to-date, just leave it. */
    if( !force && is_menu_uptodate() )
    {
        g_print("upda-to-date, re-generation is not needed.");
        return 0;
    }
#endif

    /* some memory leaks happen here if g_free is not used to free the keys. */
    de_hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
    g_hash_table_insert( de_hash, (gpointer)"LXDE", (gpointer)SHOW_IN_LXDE );
    g_hash_table_insert( de_hash, (gpointer)"GNOME", (gpointer)SHOW_IN_GNOME );
    g_hash_table_insert( de_hash, (gpointer)"KDE", (gpointer)SHOW_IN_KDE );
    g_hash_table_insert( de_hash, (gpointer)"XFCE", (gpointer)SHOW_IN_XFCE );
    g_hash_table_insert( de_hash, (gpointer)"ROX", (gpointer)SHOW_IN_ROX );

    if(ifile)
        plus_ptr = strrchr(ifile, '+');

    if(plus_ptr != NULL && strcmp(plus_ptr, "+hidden") != 0)
        plus_ptr = NULL;

    if(plus_ptr)
    {
        *plus_ptr = '\0';
        menu_tree = gmenu_tree_lookup( ifile, GMENU_TREE_FLAGS_INCLUDE_NODISPLAY | GMENU_TREE_FLAGS_INCLUDE_EXCLUDED | GMENU_TREE_FLAGS_SHOW_EMPTY );
        *plus_ptr = '+';
    }
    else
        menu_tree = gmenu_tree_lookup( ifile, GMENU_TREE_FLAGS_INCLUDE_EXCLUDED );
    if( ! menu_tree )
    {
        g_print("Error loading source menu file: %s\n", ifile);
        return 1;
    }

    dir = g_path_get_dirname( ofile );
    if( !g_file_test( dir, G_FILE_TEST_EXISTS ) )
        g_mkdir_with_parents( dir, 0700 );
    g_free( dir );

    /* write the tree to cache. */
    tmp = g_malloc( strlen( ofile ) + 7 );
    strcpy( tmp, ofile );
    strcat( tmp, "XXXXXX" );
    ofd = g_mkstemp( tmp );
    if( ofd == -1 )
    {
        g_print( "Error writing output file: %s\n", g_strerror(errno) );
        return 1;
    }

    of = fdopen( ofd, "w" );
    if( ! of )
    {
        g_print( "Error writing output file: %s\n", ofile );
        return 1;
    }

    /* Version number should be added to the head of this cache file. */
    fprintf( of, "%d.%d\n", VER_MAJOR, VER_MINOR );

    /* the first line is menu name */
    fprintf( of, "%s\n", ifile );

    root_dir = gmenu_tree_get_root_directory( menu_tree );

    /* add the source menu file itself to the list of files requiring monitor */
    if(plus_ptr)
        *plus_ptr = '\0';
    if( g_path_is_absolute(ifile) )
    {
        if( ! g_slist_find_custom(all_used_files, ifile, (GCompareFunc)strcmp ) )
            all_used_files = g_slist_prepend(all_used_files, g_strdup(ifile));
    }
    else
    {
        char* file_name;
        xdg_cfg_dirs = g_get_system_config_dirs();
        menu_prefix = g_getenv("XDG_MENU_PREFIX");
        file_name = menu_prefix ? g_strconcat(menu_prefix, ifile, NULL) : ifile;
        for( pdir = xdg_cfg_dirs; *pdir; ++pdir )
        {
            menu_file = g_build_filename( *pdir, "menus", file_name, NULL );
            if( ! g_slist_find_custom(all_used_dirs, menu_file, (GCompareFunc)strcmp ) )
                all_used_files = g_slist_prepend(all_used_files, menu_file);
            else
                g_free( menu_file );
        }
        menu_file = g_build_filename( g_get_user_config_dir(), "menus", file_name, NULL );
        if( file_name != ifile )
            g_free(file_name);

        if( ! g_slist_find_custom(all_used_dirs, menu_file, (GCompareFunc)strcmp ) )
            all_used_files = g_slist_prepend(all_used_files, menu_file);
        else
            g_free(menu_file);
    }

    /* write a list of all files which need to be monitored for changes. */
    /* write number of files first */
    fprintf( of, "%d\n", g_slist_length(all_used_dirs) + g_slist_length(all_used_files) );

    /* list all files.
     * add D or F at the begin of each line to indicate whether it's a
     * file or directory. */
    for( l = all_used_dirs; l; l = l->next )
    {
        fprintf( of, "D%s\n", (char*)l->data );
    }
    for( l = all_used_files; l; l = l->next )
    {
        fprintf( of, "F%s\n", (char*)l->data );
    }

    /* write all DE names in this menu. Known DEs such as LXDE, GNOME, and KDE don't need to be listed here */
    if( g_hash_table_size(de_hash) > N_KNOWN_DESKTOPS ) /* if there are some unknown DEs added to the hash */
        g_hash_table_foreach(de_hash, (GHFunc)write_de_name, of );
    fputc('\n', of);

    /* write the whole menu tree */
    write_dir( of, root_dir );

    fclose( of );

    gmenu_tree_unref( menu_tree );

    g_hash_table_destroy(de_hash);

    if( g_rename( tmp, ofile ) == -1 )
    {
        g_print( "Error writing output file: %s\n", g_strerror( errno ) );
    }
    g_free( tmp );
    /* g_print("success!\n"); */
    return 0;
}