From 0eb323ec50e38d8728718aea1a8551fe4fdb9a44 Mon Sep 17 00:00:00 2001 From: skeezix Date: Wed, 9 Feb 2011 16:11:53 -0500 Subject: [PATCH] mmenu: can now associate custom cats/subcats to an app; special exception -- you're allowed to register subcats for standard FD cats, may Crom have mercy on my soul --- minimenu/freedesktop_cats.c | 10 +++ minimenu/freedesktop_cats.h | 1 + minimenu/mmcustom_cats.c | 6 +- minimenu/mmcustom_cats.h | 2 + minimenu/mmui.c | 147 ++++++++++++++++++++++++------------ minimenu/mmui.h | 2 +- 6 files changed, 119 insertions(+), 49 deletions(-) diff --git a/minimenu/freedesktop_cats.c b/minimenu/freedesktop_cats.c index 087a105..f4e7e78 100644 --- a/minimenu/freedesktop_cats.c +++ b/minimenu/freedesktop_cats.c @@ -203,6 +203,16 @@ freedesktop_cat_t *freedesktop_category_query ( char *name, char *parentcatname return ( NULL ); } +unsigned int freedesktop_count ( void ) { + unsigned int i = 0; + + while ( freedesktop_complete [ i ].cat ) { + i++; + } + + return ( i ); +} + #if 0 int main ( void ) { diff --git a/minimenu/freedesktop_cats.h b/minimenu/freedesktop_cats.h index 362be8a..fd4cb2e 100644 --- a/minimenu/freedesktop_cats.h +++ b/minimenu/freedesktop_cats.h @@ -12,6 +12,7 @@ extern freedesktop_cat_t freedesktop_complete[]; // return NULL on error, otherwise a category entry freedesktop_cat_t *freedesktop_category_query ( char *name, char *parentcatname ); +unsigned int freedesktop_count ( void ); #define BADCATNAME "Other" /* irony: Other is itself not a freedesktop category */ diff --git a/minimenu/mmcustom_cats.c b/minimenu/mmcustom_cats.c index 7cb341a..445a81d 100644 --- a/minimenu/mmcustom_cats.c +++ b/minimenu/mmcustom_cats.c @@ -79,7 +79,7 @@ unsigned char mmcustom_setup ( void ) { } // while - pnd_log ( pndn_rem, "Found %u custom categories.\n", mmcustom_count ); + //pnd_log ( pndn_rem, "Found %u custom categories.\n", mmcustom_count ); } // loaded already? @@ -95,6 +95,10 @@ void mmcustom_shutdown ( void ) { return; } +unsigned char mmcustom_is_ready ( void ) { + return ( loaded ); +} + unsigned char mmcustom_write ( char *fullpath /* if NULL, uses canonical location */ ) { if ( ! fullpath ) { diff --git a/minimenu/mmcustom_cats.h b/minimenu/mmcustom_cats.h index a003451..73738ef 100644 --- a/minimenu/mmcustom_cats.h +++ b/minimenu/mmcustom_cats.h @@ -19,6 +19,8 @@ extern unsigned int mmcustom_count; unsigned char mmcustom_setup ( void ); // load void mmcustom_shutdown ( void ); // unload +unsigned char mmcustom_is_ready ( void ); + unsigned char mmcustom_write ( char *fullpath /* if NULL, uses canonical location */ ); // save char *mmcustom_determine_path ( void ); diff --git a/minimenu/mmui.c b/minimenu/mmui.c index 1770897..4dde7b8 100644 --- a/minimenu/mmui.c +++ b/minimenu/mmui.c @@ -3385,6 +3385,18 @@ void ui_menu_context ( mm_appref_t *a ) { unsigned char optmax = 0; unsigned char i; + // show custom categories + if ( mmcustom_setup() ) { + + for ( i = 0; i < mmcustom_count; i++ ) { + if ( mmcustom_complete [ i ].parent_cat == NULL ) { + opts [ optmax++ ] = mmcustom_complete [ i ].cat; + } + } + + } + + // show FD categories i = 2; // skip first two - Other and NoParentCategory while ( 1 ) { @@ -3399,6 +3411,7 @@ void ui_menu_context ( mm_appref_t *a ) { i++; } // while + // picker char prompt [ 101 ]; snprintf ( prompt, 100, "Pick category [%s]", a -> ref -> main_category ? a -> ref -> main_category : "NoParentCategory" ); @@ -3417,6 +3430,10 @@ void ui_menu_context ( mm_appref_t *a ) { } + if ( mmcustom_is_ready() ) { + mmcustom_shutdown(); + } + } break; @@ -3424,24 +3441,36 @@ void ui_menu_context ( mm_appref_t *a ) { { char *opts [ 250 ]; unsigned char optmax = 0; - unsigned char i; + unsigned char i = 0; - i = 0; + char *whichparentarewe; + if ( g_categories [ ui_category ] -> parent_catname ) { + whichparentarewe = g_categories [ ui_category ] -> parent_catname; + } else { + whichparentarewe = g_categories [ ui_category ] -> catname; + } + + // add NoSubcategory magic one opts [ optmax++ ] = freedesktop_complete [ 2 ].cat; + // add custom categories + if ( mmcustom_setup() ) { + + for ( i = 0; i < mmcustom_count; i++ ) { + if ( mmcustom_complete [ i ].parent_cat && strcmp ( mmcustom_complete [ i ].parent_cat, whichparentarewe ) == 0 ) { + opts [ optmax++ ] = mmcustom_complete [ i ].cat; + } + } + + } + + // add FD categories while ( 1 ) { if ( ! freedesktop_complete [ i ].cat ) { break; } - char *whichparentarewe; - if ( g_categories [ ui_category ] -> parent_catname ) { - whichparentarewe = g_categories [ ui_category ] -> parent_catname; - } else { - whichparentarewe = g_categories [ ui_category ] -> catname; - } - if ( ( freedesktop_complete [ i ].parent_cat ) && ( strcasecmp ( freedesktop_complete [ i ].parent_cat, whichparentarewe ) == 0 ) ) @@ -3453,7 +3482,8 @@ void ui_menu_context ( mm_appref_t *a ) { } // while char prompt [ 101 ]; - snprintf ( prompt, 100, "Pick subcategory [%s]", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory" ); + //snprintf ( prompt, 100, "Currently: %s", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory" ); + snprintf ( prompt, 100, "%s [%s]", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory", whichparentarewe ); int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select subcategory"*/, "Enter to select; other to skip." ); @@ -3468,6 +3498,10 @@ void ui_menu_context ( mm_appref_t *a ) { } + if ( mmcustom_is_ready() ) { + mmcustom_shutdown(); + } + } break; @@ -3771,7 +3805,7 @@ unsigned char ui_menu_get_text_line ( char *title, char *footer, char *initialva } unsigned char ovr_replace_or_add ( mm_appref_t *a, char *keybase, char *newvalue ) { - printf ( "setting %s:%u - '%s' to '%s' - %s/%s\n", a -> ref -> title_en, a -> ref -> subapp_number, keybase, newvalue, a -> ref -> object_path, a -> ref -> object_filename ); + //printf ( "setting %s:%u - '%s' to '%s' - %s/%s\n", a -> ref -> title_en, a -> ref -> subapp_number, keybase, newvalue, a -> ref -> object_path, a -> ref -> object_filename ); char fullpath [ PATH_MAX ]; @@ -3780,7 +3814,7 @@ unsigned char ovr_replace_or_add ( mm_appref_t *a, char *keybase, char *newvalue if ( dot ) { sprintf ( dot, PXML_SAMEPATH_OVERRIDE_FILEEXT ); } else { - fprintf ( stderr, "ERROR: Bad pnd-path in disco_t! %s\n", fullpath ); + pnd_log ( pndn_error, "ERROR: Bad pnd-path in disco_t! %s\n", fullpath ); return ( 0 ); } @@ -3846,7 +3880,7 @@ void ui_manage_categories ( void ) { case 0: // list custom if ( mmcustom_count ) { - ui_pick_custom_category(); + ui_pick_custom_category ( 0 ); } else { ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." ); } @@ -3855,13 +3889,13 @@ void ui_manage_categories ( void ) { case 1: // list custom sub if ( mmcustom_count ) { - int maincat = ui_pick_custom_category(); + char *maincat = ui_pick_custom_category ( 0 ); - if ( maincat >= 0 ) { - unsigned int subcount = mmcustom_count_subcats ( mmcustom_complete [ maincat ].cat ); + if ( maincat ) { + unsigned int subcount = mmcustom_count_subcats ( maincat ); char titlebuf [ 201 ]; - snprintf ( titlebuf, 200, "Category: %s", mmcustom_complete [ maincat ].cat ); + snprintf ( titlebuf, 200, "Category: %s", maincat ); if ( subcount == 0 ) { ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." ); @@ -3872,7 +3906,7 @@ void ui_manage_categories ( void ) { unsigned int counter = 0; for ( i = 0; i < mmcustom_count; i++ ) { - if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, mmcustom_complete [ maincat ].cat ) == 0 ) { + if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) { list [ counter++ ] = mmcustom_complete [ i ].cat; } } @@ -3929,12 +3963,12 @@ void ui_manage_categories ( void ) { case 3: // register custom sub if ( mmcustom_count ) { - int maincat = ui_pick_custom_category(); + char *maincat = ui_pick_custom_category ( 1 /* include FD */ ); - if ( maincat >= 0 ) { + if ( maincat ) { char titlebuf [ 201 ]; - snprintf ( titlebuf, 200, "Subcat of: %s", mmcustom_complete [ maincat ].cat ); + snprintf ( titlebuf, 200, "Subcat of: %s", maincat ); unsigned char changed; char namebuf [ 101 ] = ""; @@ -3945,18 +3979,18 @@ void ui_manage_categories ( void ) { if ( changed ) { // and if so, is it existant already or not? - if ( mmcustom_query ( namebuf, mmcustom_complete [ maincat ].cat ) ) { + if ( mmcustom_query ( namebuf, maincat ) ) { ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a subcategory." ); - } else if ( freedesktop_category_query ( namebuf, mmcustom_complete [ maincat ].cat ) ) { + } else if ( freedesktop_category_query ( namebuf, maincat ) ) { ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard subcategory." ); } else { char confirm [ 1001 ]; - snprintf ( confirm, 1000, "Confirm: %s [%s]", namebuf, mmcustom_complete [ maincat ].cat ); + snprintf ( confirm, 1000, "Confirm: %s [%s]", namebuf, maincat ); if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) { // register, save, recycle the current list - mmcustom_register ( namebuf, mmcustom_complete [ maincat ].cat ); + mmcustom_register ( namebuf, maincat ); mmcustom_write ( NULL ); mmcustom_shutdown(); mmcustom_setup(); @@ -3975,15 +4009,15 @@ void ui_manage_categories ( void ) { case 4: // unreg custom if ( mmcustom_count ) { - int maincat = ui_pick_custom_category(); + char *maincat = ui_pick_custom_category ( 0 ); - if ( maincat >= 0 ) { + if ( maincat ) { char confirm [ 1001 ]; - snprintf ( confirm, 1000, "Confirm remove: %s", mmcustom_complete [ maincat ].cat ); + snprintf ( confirm, 1000, "Confirm remove: %s", maincat ); if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) { // register, save, recycle the current list - mmcustom_unregister ( mmcustom_complete [ maincat ].cat, NULL ); + mmcustom_unregister ( maincat, NULL ); mmcustom_write ( NULL ); mmcustom_shutdown(); mmcustom_setup(); @@ -3998,13 +4032,13 @@ void ui_manage_categories ( void ) { case 5: // unreg custom sub if ( mmcustom_count ) { - int maincat = ui_pick_custom_category(); + char *maincat = ui_pick_custom_category ( 0 ); - if ( maincat >= 0 ) { - unsigned int subcount = mmcustom_count_subcats ( mmcustom_complete [ maincat ].cat ); + if ( maincat ) { + unsigned int subcount = mmcustom_count_subcats ( maincat ); char titlebuf [ 201 ]; - snprintf ( titlebuf, 200, "Category: %s", mmcustom_complete [ maincat ].cat ); + snprintf ( titlebuf, 200, "Category: %s", maincat ); if ( subcount == 0 ) { ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." ); @@ -4015,7 +4049,7 @@ void ui_manage_categories ( void ) { unsigned int counter = 0; for ( i = 0; i < mmcustom_count; i++ ) { - if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, mmcustom_complete [ maincat ].cat ) == 0 ) { + if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) { list [ counter++ ] = mmcustom_complete [ i ].cat; } } @@ -4028,7 +4062,7 @@ void ui_manage_categories ( void ) { if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) { // register, save, recycle the current list - mmcustom_unregister ( list [ sel ], mmcustom_complete [ maincat ].cat ); + mmcustom_unregister ( list [ sel ], maincat ); mmcustom_write ( NULL ); mmcustom_shutdown(); mmcustom_setup(); @@ -4071,31 +4105,50 @@ void ui_manage_categories ( void ) { return; } -int ui_pick_custom_category ( void ) { - char **list = malloc ( mmcustom_count * sizeof(char*) ); +char *ui_pick_custom_category ( unsigned char include_fd ) { + char **list; int i; unsigned int counter = 0; + if ( include_fd ) { + list = malloc ( (mmcustom_count+freedesktop_count()) * sizeof(char*) ); + } else { + list = malloc ( mmcustom_count * sizeof(char*) ); + } + + // add custom for ( i = 0; i < mmcustom_count; i++ ) { if ( mmcustom_complete [ i ].parent_cat == NULL ) { list [ counter++ ] = mmcustom_complete [ i ].cat; } } - int sel = ui_modal_single_menu ( list, counter, "Custom Main Categories", "Any button to exit." ); + // add FD + if ( include_fd ) { + i = 3; + while ( 1 ) { - counter = 0; - for ( i = 0; i < mmcustom_count; i++ ) { - if ( mmcustom_complete [ i ].parent_cat == NULL ) { - if ( counter == sel ) { - free ( list ); - return ( i ); + if ( ! freedesktop_complete [ i ].cat ) { + break; } - counter ++; - } + + if ( freedesktop_complete [ i ].parent_cat == NULL ) { + list [ counter++ ] = freedesktop_complete [ i ].cat; + } + + i++; + } // while + } // if + + int sel = ui_modal_single_menu ( list, counter, "Custom Main Categories", "Any button to exit." ); + + if ( sel < 0 ) { + free ( list ); + return ( NULL ); } + char *foo = list [ sel ]; free ( list ); - return ( -1 ); + return ( foo ); } diff --git a/minimenu/mmui.h b/minimenu/mmui.h index 65cdb71..464c5f5 100644 --- a/minimenu/mmui.h +++ b/minimenu/mmui.h @@ -75,7 +75,7 @@ unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ); void ui_aboutscreen ( char *textpath ); void ui_revealscreen ( void ); void ui_manage_categories ( void ); -int ui_pick_custom_category ( void ); +char *ui_pick_custom_category ( unsigned char include_fd ); /* internal functions follow */ -- 2.39.2