From: skeezix Date: Sun, 20 Feb 2011 03:37:07 +0000 (-0500) Subject: mmenu; when list custom subcats, show custom maincats and FD maincats-that-also-have... X-Git-Tag: sz_beta3~66 X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73fff7a0e01fca8d360301bf4d77958e4c9c26e9;p=pandora-libraries.git mmenu; when list custom subcats, show custom maincats and FD maincats-that-also-have-custom-subcats; when unregister subcats, same change --- diff --git a/minimenu/mmcustom_cats.c b/minimenu/mmcustom_cats.c index 445a81d..4c5a8a3 100644 --- a/minimenu/mmcustom_cats.c +++ b/minimenu/mmcustom_cats.c @@ -145,6 +145,25 @@ mmcustom_cat_t *mmcustom_query ( char *name, char *parentcatname ) { return ( NULL ); } +unsigned int mmcustom_subcount ( char *parentcatname ) { + unsigned int counter = 0; + + int i; + + // search for the cat/parent combination + for ( i = 0; i < mmcustom_count; i++ ) { + + if ( mmcustom_complete [ i ].parent_cat && + strcmp ( mmcustom_complete [ i ].parent_cat, parentcatname ) == 0 ) + { + counter++; + } + + } // for + + return ( counter ); +} + mmcustom_cat_t *mmcustom_register ( char *catname, char *parentcatname ) { mmcustom_complete [ mmcustom_count ].cat = strdup ( catname ); if ( parentcatname ) { @@ -219,10 +238,10 @@ void mmcustom_unregister ( char *catname, char *parentcatname ) { } // for // kill the actual cat itself - if ( i >= 0 ) { + if ( parent_index >= 0 ) { pnd_log ( pndn_warning, " Removing cat: %s\n", catname ); - free ( mmcustom_complete [ i ].cat ); - mmcustom_complete [ i ].cat = NULL; + free ( mmcustom_complete [ parent_index ].cat ); + mmcustom_complete [ parent_index ].cat = NULL; } return; diff --git a/minimenu/mmcustom_cats.h b/minimenu/mmcustom_cats.h index 73738ef..4632576 100644 --- a/minimenu/mmcustom_cats.h +++ b/minimenu/mmcustom_cats.h @@ -25,6 +25,7 @@ unsigned char mmcustom_write ( char *fullpath /* if NULL, uses canonical locatio char *mmcustom_determine_path ( void ); mmcustom_cat_t *mmcustom_query ( char *catname, char *parentcatname ); // parentcatname NULL for parents +unsigned int mmcustom_subcount ( char *parentcatname ); // how many custom subcats of the named cat (FD or custom) mmcustom_cat_t *mmcustom_register ( char *catname, char *parentcatname ); void mmcustom_unregister ( char *catname, char *parentcatname ); diff --git a/minimenu/mmui.c b/minimenu/mmui.c index 7861dd7..0c9a5f1 100644 --- a/minimenu/mmui.c +++ b/minimenu/mmui.c @@ -3941,17 +3941,13 @@ void ui_manage_categories ( void ) { switch ( sel ) { case 0: // list custom - if ( mmcustom_count ) { - ui_pick_custom_category ( 0 ); - } else { - ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." ); - } + ui_pick_custom_category ( 0 ); break; case 1: // list custom sub if ( mmcustom_count ) { - char *maincat = ui_pick_custom_category ( 0 ); + char *maincat = ui_pick_custom_category ( 2 ); if ( maincat ) { unsigned int subcount = mmcustom_count_subcats ( maincat ); @@ -4094,7 +4090,7 @@ void ui_manage_categories ( void ) { case 5: // unreg custom sub if ( mmcustom_count ) { - char *maincat = ui_pick_custom_category ( 0 ); + char *maincat = ui_pick_custom_category ( 2 ); if ( maincat ) { unsigned int subcount = mmcustom_count_subcats ( maincat ); @@ -4167,42 +4163,62 @@ void ui_manage_categories ( void ) { return; } -char *ui_pick_custom_category ( unsigned char include_fd ) { +// mode 0 == custom main only; 1 == custom main + FD main; 2 == custom main + FD mains-with-custom-subs +char *ui_pick_custom_category ( unsigned char mode ) { char **list; int i; unsigned int counter = 0; - if ( include_fd ) { + // alloc space for list, depending on scope + if ( mode > 0 ) { list = malloc ( (mmcustom_count+freedesktop_count()) * sizeof(char*) ); } else { list = malloc ( mmcustom_count * sizeof(char*) ); } - // add custom + // add custom mains for ( i = 0; i < mmcustom_count; i++ ) { if ( mmcustom_complete [ i ].parent_cat == NULL ) { list [ counter++ ] = mmcustom_complete [ i ].cat; } } - // add FD - if ( include_fd ) { + // add FD if needed + if ( mode > 0 ) { i = 3; + while ( 1 ) { if ( ! freedesktop_complete [ i ].cat ) { break; } + // if FD main cat if ( freedesktop_complete [ i ].parent_cat == NULL ) { - list [ counter++ ] = freedesktop_complete [ i ].cat; - } + + // mode 1 == include them all + // mode 2 == include them if they have a custom subcat + if ( ( mode == 1 ) || + ( mmcustom_subcount ( freedesktop_complete [ i ].cat ) ) ) + { + list [ counter++ ] = freedesktop_complete [ i ].cat; + } + + } // if parent cat i++; } // while + } // if - int sel = ui_modal_single_menu ( list, counter, "Custom Main Categories", "Any button to exit." ); + // we actually showing anything? + if ( ! counter ) { + ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." ); + return ( NULL ); + } + + // do it + int sel = ui_modal_single_menu ( list, counter, "Custom Categories", "Any button to exit." ); if ( sel < 0 ) { free ( list ); diff --git a/minimenu/mmui.h b/minimenu/mmui.h index 15cb631..ac052ed 100644 --- a/minimenu/mmui.h +++ b/minimenu/mmui.h @@ -78,7 +78,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 ); -char *ui_pick_custom_category ( unsigned char include_fd ); +char *ui_pick_custom_category ( unsigned char mode ); // mode 0 == custom main only; 1 == custom main + FD main; 2 == custom main + FD mains-with-custom-subs /* internal functions follow */