1
0

Implemented library menu location (closes #72) (#75)

This commit is contained in:
Patrick Gaskin
2020-08-05 01:25:51 -04:00
committed by GitHub
parent c8ce8462a5
commit 141333c402
4 changed files with 12 additions and 2 deletions

View File

@@ -18,6 +18,7 @@
# main - the menu in the top-left corner of the home screen # main - the menu in the top-left corner of the home screen
# reader - the overflow menu in the reader # reader - the overflow menu in the reader
# browser - the menu in the bottom-right of the web browser # browser - the menu in the bottom-right of the web browser
# library - the menu in the filter bar for the "My Books" and "My Articles" library views
# <label> the label to show on the menu item (must not contain :) # <label> the label to show on the menu item (must not contain :)
# <action> the type of action to run, one of: # <action> the type of action to run, one of:
# cmd_spawn - starts a command in the background # cmd_spawn - starts a command in the background

View File

@@ -305,7 +305,7 @@ nm_config_t *nm_config_parse(nm_config_file_t *files) {
}))) RETERR("error appending default action to empty config: %s", nm_config_parse__strerror(ret)); }))) RETERR("error appending default action to empty config: %s", nm_config_parse__strerror(ret));
} }
size_t mm = 0, rm = 0, bm = 0; size_t mm = 0, rm = 0, bm = 0, lm = 0;
for (nm_config_t *cur = state.cfg_s; cur; cur = cur->next) { for (nm_config_t *cur = state.cfg_s; cur; cur = cur->next) {
switch (cur->type) { switch (cur->type) {
case NM_CONFIG_TYPE_MENU_ITEM: case NM_CONFIG_TYPE_MENU_ITEM:
@@ -316,6 +316,7 @@ nm_config_t *nm_config_parse(nm_config_file_t *files) {
case NM_MENU_LOCATION_MAIN_MENU: mm++; break; case NM_MENU_LOCATION_MAIN_MENU: mm++; break;
case NM_MENU_LOCATION_READER_MENU: rm++; break; case NM_MENU_LOCATION_READER_MENU: rm++; break;
case NM_MENU_LOCATION_BROWSER_MENU: bm++; break; case NM_MENU_LOCATION_BROWSER_MENU: bm++; break;
case NM_MENU_LOCATION_LIBRARY_MENU: lm++; break;
} }
break; break;
case NM_CONFIG_TYPE_GENERATOR: case NM_CONFIG_TYPE_GENERATOR:
@@ -330,6 +331,8 @@ nm_config_t *nm_config_parse(nm_config_file_t *files) {
RETERR("too many menu items in reader menu (> %d)", NM_CONFIG_MAX_MENU_ITEMS_PER_MENU); RETERR("too many menu items in reader menu (> %d)", NM_CONFIG_MAX_MENU_ITEMS_PER_MENU);
if (bm > NM_CONFIG_MAX_MENU_ITEMS_PER_MENU) if (bm > NM_CONFIG_MAX_MENU_ITEMS_PER_MENU)
RETERR("too many menu items in browser menu (> %d)", NM_CONFIG_MAX_MENU_ITEMS_PER_MENU); RETERR("too many menu items in browser menu (> %d)", NM_CONFIG_MAX_MENU_ITEMS_PER_MENU);
if (lm > NM_CONFIG_MAX_MENU_ITEMS_PER_MENU)
RETERR("too many menu items in library menu (> %d)", NM_CONFIG_MAX_MENU_ITEMS_PER_MENU);
return state.cfg_s; return state.cfg_s;
} }
@@ -347,6 +350,7 @@ static bool nm_config_parse__line_item(const char *type, char **line, nm_menu_it
else if (!strcmp(s_loc, "main")) it_out->loc = NM_MENU_LOCATION_MAIN_MENU; else if (!strcmp(s_loc, "main")) it_out->loc = NM_MENU_LOCATION_MAIN_MENU;
else if (!strcmp(s_loc, "reader")) it_out->loc = NM_MENU_LOCATION_READER_MENU; else if (!strcmp(s_loc, "reader")) it_out->loc = NM_MENU_LOCATION_READER_MENU;
else if (!strcmp(s_loc, "browser")) it_out->loc = NM_MENU_LOCATION_BROWSER_MENU; else if (!strcmp(s_loc, "browser")) it_out->loc = NM_MENU_LOCATION_BROWSER_MENU;
else if (!strcmp(s_loc, "library")) it_out->loc = NM_MENU_LOCATION_LIBRARY_MENU;
else NM_ERR_RET(NULL, "field 2: unknown location '%s'", s_loc); else NM_ERR_RET(NULL, "field 2: unknown location '%s'", s_loc);
char *p_lbl = strtrim(strsep(line, ":")); char *p_lbl = strtrim(strsep(line, ":"));

View File

@@ -13,6 +13,7 @@ typedef enum {
NM_MENU_LOCATION_MAIN_MENU = 1, NM_MENU_LOCATION_MAIN_MENU = 1,
NM_MENU_LOCATION_READER_MENU = 2, NM_MENU_LOCATION_READER_MENU = 2,
NM_MENU_LOCATION_BROWSER_MENU = 3, NM_MENU_LOCATION_BROWSER_MENU = 3,
NM_MENU_LOCATION_LIBRARY_MENU = 4,
} nm_menu_location_t; } nm_menu_location_t;
typedef struct nm_menu_action_t { typedef struct nm_menu_action_t {

View File

@@ -142,7 +142,8 @@ extern "C" __attribute__((visibility("default"))) MenuTextItem* _nm_menu_hook(vo
QString trmm = QCoreApplication::translate("StatusBarMenuController", "Settings"); QString trmm = QCoreApplication::translate("StatusBarMenuController", "Settings");
QString trrm = QCoreApplication::translate("DictionaryActionProxy", "Dictionary"); QString trrm = QCoreApplication::translate("DictionaryActionProxy", "Dictionary");
QString trbm = QCoreApplication::translate("N3BrowserSettingsMenuController", "Keyboard"); QString trbm = QCoreApplication::translate("N3BrowserSettingsMenuController", "Keyboard");
NM_LOG("Comparing against '%s', '%s', '%s'", qPrintable(trmm), qPrintable(trrm), qPrintable(trbm)); QString trlm = QCoreApplication::translate("LibraryViewMenuController", "Manage downloads");
NM_LOG("Comparing against '%s', '%s', '%s', '%s'", qPrintable(trmm), qPrintable(trrm), qPrintable(trbm), qPrintable(trlm));
nm_menu_location_t loc = {}; nm_menu_location_t loc = {};
if (label == trmm && !checkable) { if (label == trmm && !checkable) {
@@ -154,6 +155,9 @@ extern "C" __attribute__((visibility("default"))) MenuTextItem* _nm_menu_hook(vo
} else if (label == trbm && !checkable) { } else if (label == trbm && !checkable) {
NM_LOG("Intercepting browser menu (label=Keyboard, checkable=false)..."); NM_LOG("Intercepting browser menu (label=Keyboard, checkable=false)...");
loc = NM_MENU_LOCATION_BROWSER_MENU; loc = NM_MENU_LOCATION_BROWSER_MENU;
} else if (label == trlm && !checkable) {
NM_LOG("Intercepting library menu (label=Manage downloads, checkable=false)..."); // this is actually two menus: in "My Books", and in "My Articles"
loc = NM_MENU_LOCATION_LIBRARY_MENU;
} }
if (loc) if (loc)