wlmaker
Loading...
Searching...
No Matches
Classes | Functions | Variables
menu.c File Reference
#include "menu.h"
#include <desktop-parser/desktop-parser.h>
#include <basedir.h>
#include <fts.h>
#include <libbase/libbase.h>
#include <libbase/plist.h>
#include <libgen.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include "item.h"
Include dependency graph for menu.c:

Classes

struct  _category_translation
 
struct  _wlmtool_menu_add_desktop_file_arg
 

Functions

static bool _wlmtool_menu_add_themes_path (struct wlmtool_menu *menu_ptr, const char *path_ptr)
 
static bool _wlmtool_menu_add_themes_file (const char *resolved_path_ptr, const FTSENT *ftsent_ptr, void *ud_ptr)
 
static bool _wlmtool_menu_add_desktop_path (struct wlmtool_menu *menu_ptr, const char *path_ptr, const char *locale_ptr)
 
static bool _wlmtool_menu_add_desktop_file (const char *resolved_path_ptr, const FTSENT *ftsent_ptr, void *ud_ptr)
 
static char * _wlmtool_menu_themes_name_from_plist_file (const char *path_ptr)
 
static const char * _wlmtool_menu_category_from_entry (const struct desktop_entry *desktop_entry_ptr)
 
bspl_array_t * wlmtool_menu_generate_appearance (const char *path_ptr)
 
bspl_array_t * wlmtool_menu_generate_applications (const char *path_ptr, const char *locale_ptr)
 
static void _wlmtool_menu_test_generate_themes (bs_test_t *test_ptr)
 
static void _wlmtool_menu_test_generate_applications (bs_test_t *test_ptr)
 

Variables

static const char * _wlmtool_action_load_theme_from_file = "ThemeLoadFromFile"
 
static const struct _category_translation _wlmtool_menu_category_table []
 
static const char * _wlmtool_menu_category_other_ptr = "Other"
 
static const char * _wlmtool_menu_terminal_command = "/usr/bin/foot"
 
static const bs_test_case_t _wlmtool_menu_test_cases []
 
const bs_test_set_t wlmtool_menu_test_set
 

Detailed Description

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ _wlmtool_menu_add_desktop_file()

bool _wlmtool_menu_add_desktop_file ( const char *  resolved_path_ptr,
const FTSENT *  ftsent_ptr,
void *  ud_ptr 
)
static

Adds a menu entry for a desktop file.

◆ _wlmtool_menu_add_desktop_path()

bool _wlmtool_menu_add_desktop_path ( struct wlmtool_menu menu_ptr,
const char *  path_ptr,
const char *  locale_ptr 
)
static

Convenience wrapper to add desktop files from path_ptr to menu_ptr.

◆ _wlmtool_menu_add_themes_file()

bool _wlmtool_menu_add_themes_file ( const char *  resolved_path_ptr,
const FTSENT *  ftsent_ptr,
void *  ud_ptr 
)
static

Adds a menu entry for the plist Themes file at resolved_path_ptr.

◆ _wlmtool_menu_add_themes_path()

bool _wlmtool_menu_add_themes_path ( struct wlmtool_menu menu_ptr,
const char *  path_ptr 
)
static

Convenience wrapper to add themes file from path_ptr to menu_ptr.

◆ _wlmtool_menu_category_from_entry()

const char * _wlmtool_menu_category_from_entry ( const struct desktop_entry desktop_entry_ptr)
static

Looks up the category name for a desktop's file menu entry.

◆ _wlmtool_menu_test_generate_applications()

void _wlmtool_menu_test_generate_applications ( bs_test_t *  test_ptr)
static

Tests generation of the 'Applications' menu.

◆ _wlmtool_menu_test_generate_themes()

void _wlmtool_menu_test_generate_themes ( bs_test_t *  test_ptr)
static

Verifies themes menu generation from the test files.

◆ _wlmtool_menu_themes_name_from_plist_file()

char * _wlmtool_menu_themes_name_from_plist_file ( const char *  path_ptr)
static

Returns a string holding name to show in the menu for the file action.

This will attempt to load the file as a PList, and extract a string value keyed "Name" from the toplevel dict. If path_ptr is not a plist file, or does not hold a Plist dict as toplevel object, it returns NULL. If there is no "Name" entry in the toplevel dict, the function returns the basename of path_ptr.

Parameters
path_ptr
Returns
An allocated string, or NULL on error. The allocated string must be released by calling free().

◆ wlmtool_menu_generate_appearance()

bspl_array_t * wlmtool_menu_generate_appearance ( const char *  path_ptr)

Generates a menu for the Themes files found at XDG data directories.

Parameters
path_ptrOptional: Path to read from. If NULL, use the XDG data directories.
Returns
A Plist array, or NULL on error.

◆ wlmtool_menu_generate_applications()

bspl_array_t * wlmtool_menu_generate_applications ( const char *  path_ptr,
const char *  locale_ptr 
)

Generates an Applications menu from parsed .desktop files.

Parameters
path_ptrOptional: Path to read from. If NULL, use the XDG data directories.
locale_ptrThe locale for LC_MESSAGES, or NULL.
Returns
a Plist array, or NULL on error.

Variable Documentation

◆ _wlmtool_action_load_theme_from_file

const char* _wlmtool_action_load_theme_from_file = "ThemeLoadFromFile"
static

Command to load a theme file.

◆ _wlmtool_menu_category_other_ptr

const char* _wlmtool_menu_category_other_ptr = "Other"
static

Category to use for any entry that is not categorized.

◆ _wlmtool_menu_category_table

const struct _category_translation _wlmtool_menu_category_table[]
static
Initial value:
= {
{ "AudioVideo", "Audio & Video" },
{ "Video", "Video" },
{ "Development", "Development" },
{ "Education", "Education" },
{ "Game", "Game" },
{ "Graphics", "Graphics" },
{ "Network", "Network" },
{ "Office", "Office" },
{ "Science", "Science" },
{ "Settings", "Settings" },
{ "System", "System" },
{ "Utility", "Utility" },
{ "Screensaver", "Screensaver" },
{ "TrayIcon", "Tray Icon" },
{ "Applet", "Applet" },
{ "Shell", "Shell" },
{ NULL, NULL },
}

Recognized categories.

◆ _wlmtool_menu_terminal_command

const char* _wlmtool_menu_terminal_command = "/usr/bin/foot"
static

Command to use for terminal.

◆ _wlmtool_menu_test_cases

const bs_test_case_t _wlmtool_menu_test_cases[]
static
Initial value:
= {
{ true, "generate_themes", _wlmtool_menu_test_generate_themes },
{ true, "applications", _wlmtool_menu_test_generate_applications },
BS_TEST_CASE_SENTINEL(),
}
static void _wlmtool_menu_test_generate_themes(bs_test_t *test_ptr)
Definition menu.c:462
static void _wlmtool_menu_test_generate_applications(bs_test_t *test_ptr)
Definition menu.c:496

Test cases for the menu generator.

◆ wlmtool_menu_test_set

const bs_test_set_t wlmtool_menu_test_set
Initial value:
= BS_TEST_SET(
true, "menu", _wlmtool_menu_test_cases)
static const bs_test_case_t _wlmtool_menu_test_cases[]
Definition menu.c:451

Unit tests for the menu generator.