mmenu; when list custom subcats, show custom maincats and FD maincats-that-also-have...
authorskeezix <skeezix@flotsam-vm.(none)>
Sun, 20 Feb 2011 03:37:07 +0000 (22:37 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Sun, 20 Feb 2011 03:37:07 +0000 (22:37 -0500)
minimenu/mmcustom_cats.c
minimenu/mmcustom_cats.h
minimenu/mmui.c
minimenu/mmui.h

index 445a81d..4c5a8a3 100644 (file)
@@ -145,6 +145,25 @@ mmcustom_cat_t *mmcustom_query ( char *name, char *parentcatname ) {
   return ( NULL );
 }
 
   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 ) {
 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
   } // for
 
   // kill the actual cat itself
-  if ( i >= 0 ) {
+  if ( parent_index >= 0 ) {
     pnd_log ( pndn_warning, "  Removing cat: %s\n", catname );
     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;
   }
 
   return;
index 73738ef..4632576 100644 (file)
@@ -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
 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 );
 
 mmcustom_cat_t *mmcustom_register ( char *catname, char *parentcatname );
 void mmcustom_unregister ( char *catname, char *parentcatname );
index 7861dd7..0c9a5f1 100644 (file)
@@ -3941,17 +3941,13 @@ void ui_manage_categories ( void ) {
     switch ( sel ) {
 
     case 0: // list custom
     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 ) {
 
       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 );
 
        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 ) {
 
     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 );
 
        if ( maincat ) {
          unsigned int subcount = mmcustom_count_subcats ( maincat );
@@ -4167,42 +4163,62 @@ void ui_manage_categories ( void ) {
   return;
 }
 
   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;
 
   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*) );
   }
 
     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;
     }
   }
 
   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;
     i = 3;
+
     while ( 1 ) {
 
       if ( ! freedesktop_complete [ i ].cat ) {
        break;
       }
 
     while ( 1 ) {
 
       if ( ! freedesktop_complete [ i ].cat ) {
        break;
       }
 
+      // if FD main cat
       if ( freedesktop_complete [ i ].parent_cat == NULL ) {
       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
 
       i++;
     } // while
+
   } // if
 
   } // 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 );
 
   if ( sel < 0 ) {
     free ( list );
index 15cb631..ac052ed 100644 (file)
@@ -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 );
 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
  */
 
 /* internal functions follow
  */