Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -I option to make icons optional #25

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ static bool no_footer;
static bool no_header;
static bool pipemenu;
static bool show_desktop_filename;
static bool show_icons;
static char *terminal_prefix;

static const struct option long_options[] = {
{"bare", no_argument, NULL, 'b'},
{"desktop", no_argument, NULL, 'd'},
{"help", no_argument, NULL, 'h'},
{"ignore", required_argument, NULL, 'i'},
{"icons", no_argument, NULL, 'I'},
{"no-duplicates", no_argument, NULL, 'n'},
{"pipemenu", no_argument, NULL, 'p'},
{"terminal-prefix", required_argument, NULL, 't'},
Expand All @@ -40,6 +42,7 @@ static const char labwc_menu_generator_usage[] =
" -d, --desktop Add .desktop filename as a comment in the XML output\n"
" -h, --help Show help message and quit\n"
" -i, --ignore <file> Specify file listing .desktop files to ignore\n"
" -I, --icons Add icon=\"\" attribute\n"
" -n, --no-duplicates Limit desktop entries to one directory only\n"
" -p, --pipemenu Output in pipemenu format\n"
" -t, --terminal-prefix Specify prefix for Terminal=true entries\n";
Expand Down Expand Up @@ -86,9 +89,14 @@ print_app_to_buffer(struct app *app, GString *submenu)
exit(EXIT_FAILURE);
}

g_string_append_printf(submenu,
" <item label=\"%s\" icon=\"%s\">\n",
app->name_localized ? app->name_localized : app->name, app->icon);
g_string_append_printf(submenu, " <item label=\"%s\"",
app->name_localized ? app->name_localized : app->name);
if (show_icons) {
g_string_append_printf(submenu, " icon=\"%s\"", app->icon);
}
g_string_append_printf(submenu, ">\n");


g_string_append_printf(submenu,
" <action name=\"Execute\"><command>%s</command></action>\n",
command);
Expand Down Expand Up @@ -197,8 +205,13 @@ print_menu(GList *dirs, GList *apps)
if (!submenu->len) {
continue;
}
printf(" <menu id=\"%s\" label=\"%s\" icon=\"%s\">\n",
dir->name, dir->name_localized ? : dir->name, dir->icon);

printf(" <menu id=\"%s\" label=\"%s\"", dir->name, dir->name_localized ? : dir->name);
if (show_icons) {
printf(" icon=\"%s\"", dir->icon);
}
printf(">\n");

printf("%s", submenu->str);
printf(" </menu> <!-- %s -->\n", dir->name);
}
Expand Down Expand Up @@ -312,7 +325,7 @@ main(int argc, char **argv)
int c;
while (1) {
int index = 0;
c = getopt_long(argc, argv, "bdhi:npt:", long_options, &index);
c = getopt_long(argc, argv, "bdhi:Inpt:", long_options, &index);
if (c == -1) {
break;
}
Expand All @@ -327,6 +340,9 @@ main(int argc, char **argv)
case 'i':
ignore_init(optarg);
break;
case 'I':
show_icons = true;
break;
case 'n':
no_duplicates = true;
break;
Expand Down
2 changes: 1 addition & 1 deletion t/t1000.t.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int main(void)
setenv("LABWC_MENU_GENERATOR_DEBUG_FIRST_DIR_ONLY", "1", 1);
setenv("LANG", "C", 1);
char command[1000];
snprintf(command, sizeof(command), "./labwc-menu-generator >%s", actual);
snprintf(command, sizeof(command), "./labwc-menu-generator -I >%s", actual);
system(command);
bool pass = test_cmp_files(actual, expect);
if (pass) {
Expand Down
2 changes: 1 addition & 1 deletion t/t1001.t.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int main(void)
setenv("LABWC_MENU_GENERATOR_DEBUG_FIRST_DIR_ONLY", "1", 1);
setenv("LANG", "sv_SE.utf8", 1);
char command[1000];
snprintf(command, sizeof(command), "./labwc-menu-generator >%s", actual);
snprintf(command, sizeof(command), "./labwc-menu-generator -I >%s", actual);
system(command);
bool pass = test_cmp_files(actual, expect);
if (pass) {
Expand Down