added 'subcats as folders' option and support, set default ON.
[pandora-libraries.git] / minimenu / mmconf.c
index 18535da..8a69ef1 100644 (file)
@@ -23,16 +23,26 @@ static unsigned char conf_render_line ( SDL_Rect *dest, unsigned int y );
 static char *conf_format_int ( int v, change_type_e c );
 
 confitem_t page_general[] = {
-  { "Default tab to show",       "On startup, Minimenu will try to switch to this tab",     NULL /* default */, "categories.default_cat",  ct_visible_tab_list },
-  { "CPU speed within Minimenu", "Set low; speed to run Minimenu at",                       NULL,               "minimenu.mm_speed",       ct_cpu_speed },
-  { "CPU speed to run apps",     "Before running app, set this speed; app may override.",   "500",              "minimenu.run_speed",      ct_cpu_speed },
-  { "Show 'All' tab",            "Whethor an All tab is shown or not",                      "1",                "categories.do_all_cat",   ct_boolean },
-  { "Start with app selected",   "Whethor selection is placed by default or not",           "0",                "minimenu.start_selected", ct_boolean },
-  { "Wrap tab change",           "Changing tab left or right, does it wrap around?",        "0",                "tabs.wraparound",         ct_boolean },
-  { "Grid stop vertical",        "Changing selection up or down, does it stop or wrap?",    "0",                "grid.wrap_vert_stop",     ct_boolean },
-  { "Force wallpaper with..",    "You can force an override over themes background",        "/pandora/appdata/mmenu/wallpaper.png", "minimenu.force_wallpaper",  ct_filename },
-  { "",                          "",                                                        NULL,               NULL,                      ct_nil },
-  { "^- Back up to main",        "Go back to top level of configuration",                   NULL,               NULL,                      ct_switch_page, NULL },
+  { "Default tab to show",           "On startup, Minimenu will try to switch to this tab",     NULL /* default */, "categories.default_cat",  ct_visible_tab_list },
+#if 0 // and also in mmenu.c -- something crashes during image caching
+  { "Set CPU speed within Minimenu", "Whether the next setting is applied or not",              "0",                "minimenu.use_mm_speed",   ct_boolean },
+  { "CPU speed within Minimenu",     "Set low; speed to run Minimenu at",                       "400",              "minimenu.mm_speed",       ct_cpu_speed },
+#endif
+  { "Show 'All' tab",                "Whethor an All tab is shown or not",                      "1",                "categories.do_all_cat",   ct_boolean },
+  { "Show directory browser tabs",   "Show a tab for each SD card?",                            "0",                "filesystem.do_browser",   ct_boolean },
+  { "Detail panel on start?",        "Show or hide the detail panel when menu starts",          "1",                "display.show_detail_pane", ct_boolean },
+  { "Sub-categories as folders?",    "If no, uses tabs instead of folders within tabs.",        "1",                "tabs.subcat_as_folders",  ct_boolean },
+  { "Start with app selected",       "Whethor selection is placed by default or not",           "0",                "minimenu.start_selected", ct_boolean },
+  { "Auto discover pnd apps?",       "If no, turn on diectory browser to manually find apps",   "1",                "filesystem.do_pnd_disco", ct_boolean },
+  { "Keep bad categories in Other?", "Lazy dev! Put broken categories into Other to keep clean", "1",               "categories.good_cats_only", ct_boolean },
+  { "Set CPU speed when leaving",    "Whether the next setting is applied or not",              "0",                "minimenu.use_run_speed",  ct_boolean },
+  { "CPU speed when leaving",        "Before running app, set this speed; app may override.",   "500",              "minimenu.run_speed",      ct_cpu_speed },
+  { "Wrap tab change",               "Changing tab left or right, does it wrap around?",        "0",                "tabs.wraparound",         ct_boolean },
+  { "Grid stop vertical",            "Changing selection up or down, does it stop or wrap?",    "0",                "grid.wrap_vert_stop",     ct_boolean },
+  { "Live (not exit) on app run?",   "Normally menu exits (to save ram) on app run",            "0",                "minimenu.live_on_run",    ct_boolean },
+  { "Force wallpaper with..",        "You can force an override over themes background",        "/pandora/appdata/mmenu/wallpaper.png", "minimenu.force_wallpaper",  ct_filename },
+  { "",                              "",                                                        NULL,               NULL,                      ct_nil },
+  { "^- Back up to main",            "Go back to top level of configuration",                   NULL,               NULL,                      ct_switch_page, NULL },
   { NULL }
 };
 
@@ -62,10 +72,6 @@ confitem_t pages[] = {
 extern pnd_conf_handle g_conf;
 extern SDL_Surface *sdl_realscreen;
 extern mm_imgcache_t g_imagecache [ IMG_TRUEMAX ];
-extern mm_category_t *g_categories;
-extern unsigned char g_categorycount;
-extern mm_category_t _categories_invis [ MAX_CATS ];
-extern unsigned char _categories_inviscount;
 extern pnd_box_handle g_active_apps;
 
 unsigned char conf_run_menu ( confitem_t *toplevel ) {
@@ -171,21 +177,21 @@ unsigned char conf_run_menu ( confitem_t *toplevel ) {
                if ( v ) {
                  unsigned char n = 0;
                  for ( n = 0; n < g_categorycount; n++ ) {
-                   if ( strcmp ( v, g_categories [ n ].catname ) == 0 ) {
+                   if ( strcmp ( v, g_categories [ n ] -> catname ) == 0 ) {
                      break;
                    }
                  }
                  if ( n < g_categorycount ) {
                    if ( left && n ) {
-                     pnd_conf_set_char ( g_conf, page [ sel ].key, g_categories [ n - 1 ].catname );
+                     pnd_conf_set_char ( g_conf, page [ sel ].key, g_categories [ n - 1 ] -> catname );
                    } else if ( ! left && n + 1 < g_categorycount ) {
-                     pnd_conf_set_char ( g_conf, page [ sel ].key, g_categories [ n + 1 ].catname );
+                     pnd_conf_set_char ( g_conf, page [ sel ].key, g_categories [ n + 1 ] -> catname );
                    }
                  } else {
-                   pnd_conf_set_char ( g_conf, page [ sel ].key, g_categories [ 0 ].catname );
+                   pnd_conf_set_char ( g_conf, page [ sel ].key, g_categories [ 0 ] -> catname );
                  }
                } else {
-                 pnd_conf_set_char ( g_conf, page [ sel ].key, g_categories [ 0 ].catname );
+                 pnd_conf_set_char ( g_conf, page [ sel ].key, g_categories [ 0 ] -> catname );
                }
              } // if category count
            }
@@ -301,6 +307,27 @@ void conf_display_page ( confitem_t *page, unsigned int selitem, unsigned int fi
   dest += conf_render_text ( g_big_font, "Minimenu Configuration", dest, 10, 10, CONF_UNSELECTED );
   dest += conf_render_line ( dest, 45 );
 
+  // scrollable hints
+  {
+
+    // up
+    if ( first_visible > 0 ) {
+      dest -> x = 10;
+      dest -> y = 65;
+      SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
+      dest++;
+    } // scroll arrow up
+
+    // down
+    if ( first_visible + max_visible < conf_determine_pagelength ( page ) ) {
+      dest -> x = 10;
+      dest -> y = 345;
+      SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
+      dest++;
+    } // scroll arrow up
+
+  } // scrollbar
+
   // items
   tx = 50; ty = 70;
   unsigned char counter = first_visible;
@@ -386,9 +413,16 @@ void conf_display_page ( confitem_t *page, unsigned int selitem, unsigned int fi
     dest += conf_render_text ( g_tab_font, "No default value", dest, 380, 420, CONF_UNSELECTED );
   }
 
+  // cursor's conf item count number - not for top level, just the sublevels
+  if ( page != pages ) {
+    char buffer [ 40 ];
+    sprintf ( buffer, "Config item %d of %d", selitem + 1, conf_determine_pagelength ( page ) );
+    /*dest += */conf_render_text ( g_tab_font, buffer, dest, 380, 440, CONF_UNSELECTED );
+  }
+
   // help
   dest += conf_render_line ( dest, 380 );
-  dest += conf_render_text ( g_tab_font, "Up and down to switch selection", dest, 10, 400, CONF_UNSELECTED );
+  dest += conf_render_text ( g_tab_font, "D-pad Up/down; Y return to index", dest, 10, 400, CONF_UNSELECTED );
   dest += conf_render_text ( g_tab_font, "Left and right to alter selected item", dest, 10, 420, CONF_UNSELECTED );
   dest += conf_render_text ( g_tab_font, "B or Enter to activate an option", dest, 10, 440, CONF_UNSELECTED );
 
@@ -528,60 +562,59 @@ unsigned char conf_prepare_page ( confitem_t *page ) {
 
       template -> text = ""; // so it won't get repopulated again later
 
-      typedef struct {
-       mm_category_t *cat;
-       unsigned char n;
-      } _foo;
-      _foo cats [ 2 ];
-      cats [ 0 ].cat = g_categories;
-      cats [ 0 ].n = g_categorycount;
-      cats [ 1 ].cat = _categories_invis;
-      cats [ 1 ].n = _categories_inviscount;
+      // switch categories being published
+      category_publish ( CFALL, NULL );
 
       // for each tab
-      unsigned int i, j;
-      for ( j = 0; j < 2; j++ ) {
-       mm_category_t *cc = cats [ j ].cat;
-       unsigned char cn = cats [ j ].n;
-       char catname [ 512 ];
-       char *actual_catname;
-
-       for ( i = 0;  i < cn; i++ ) {
-
-         // if this is an invisi-guy, it has parent-cat prepended; we want the real cat name.
-         strncpy ( catname, cc [ i ].catname, 500 );
-         if ( ( actual_catname = strchr ( catname, '.' ) ) ) {
-           actual_catname++; // skip the period
-         } else {
-           actual_catname = catname;
-         }
-         //fprintf ( stderr, "conf ui; got '%s' but showing '%s'\n", cc [ i ].catname, actual_catname );
+      unsigned int i;
+      char catname [ 512 ];
+      char *actual_catname;
+      char finalbuf [ 101 ];
 
-         if ( strncmp ( cc [ i ].catname, "All ", 4 ) == 0 ) {
-           // skip All tab, since it is generated, and managed by another config item
-           continue;
-         }
+      for ( i = 0;  i < g_categorycount; i++ ) {
 
-         p -> text = strndup ( actual_catname, 40 );
-         p -> desc = NULL;
-         p -> def = NULL;
+       // if this is an invisi-guy, it has parent-cat prepended; we want the real cat name.
+       strncpy ( catname, g_categories [ i ] -> catname, 500 );
+
+       if ( ( actual_catname = strchr ( catname, '.' ) ) ) {
+         actual_catname++; // skip the period
+       } else {
+         actual_catname = catname;
+       }
+       //fprintf ( stderr, "conf ui; got '%s' but showing '%s'\n", cc [ i ].catname, actual_catname );
 
-         sprintf ( buffer, "%s.%s", template -> key, actual_catname );
-         p -> key = strdup ( buffer );
-         p -> type = ct_boolean;
-         p -> newhead = NULL;
+       if ( strncmp ( g_categories [ i ] -> catname, "All ", 4 ) == 0 ) {
+         // skip All tab, since it is generated, and managed by another config item
+         continue;
+       }
 
-         // create to positive if not existant
-         if ( ! pnd_conf_get_as_char ( g_conf, buffer ) ) {
-           pnd_conf_set_char ( g_conf, buffer, "1" );
-         }
+       if ( g_categories [ i ] -> parent_catname ) {
+         snprintf ( finalbuf, 100, "%s [%s]", actual_catname, g_categories [ i ] -> parent_catname );
+       } else {
+         strncpy ( finalbuf, actual_catname, 100 );
+       }
 
-         //fprintf ( stderr, "Created tabshow entry '%s'\n", cc [ i ].catname );
+       p -> text = strndup ( finalbuf, 40 );
+       p -> desc = NULL;
+       p -> def = NULL;
 
-         p++;
+       sprintf ( buffer, "%s.%s", template -> key, actual_catname );
+       p -> key = strdup ( buffer );
+       p -> type = ct_boolean;
+       p -> newhead = NULL;
+
+       // create to positive if not existant
+       if ( ! pnd_conf_get_as_char ( g_conf, buffer ) ) {
+         pnd_conf_set_char ( g_conf, buffer, "1" );
        }
 
-      }
+       //fprintf ( stderr, "Created tabshow entry '%s'\n", cc [ i ].catname );
+
+       p++;
+      } // for
+
+      // switch categories being published
+      category_publish ( CFNORMAL, NULL );
 
       break;
     }
@@ -777,3 +810,10 @@ void conf_reset_to_default ( pnd_conf_handle h ) {
   return;
 }
 
+unsigned int conf_determine_pagelength ( confitem_t *page ) {
+  confitem_t *p = page;
+  while ( p -> text ) {
+    p++;
+  }
+  return ( p - page );
+}