Added default auto-rescan to minimenu on SD insert; disable via conf file.
[pandora-libraries.git] / minimenu / mmui.c
index aeafcd6..0601a0e 100644 (file)
@@ -1218,14 +1218,13 @@ void ui_process_input ( unsigned char block_p ) {
          "Shutdown Pandora",
          "Rescan for applications",
          "Cache previews to SD now",
-         "Run xfce4 from Minimenu",
          "Run a terminal/console",
-         "Switch preferred GUI",
+         "Run another GUI (xfce, etc)",
          "Quit (<- beware)",
          "Select a Minimenu skin",
          "About Minimenu"
        };
-       int sel = ui_modal_single_menu ( opts, 10, "Minimenu", "Enter to select; other to return." );
+       int sel = ui_modal_single_menu ( opts, 9, "Minimenu", "Enter to select; other to return." );
 
        char buffer [ 100 ];
        if ( sel == 0 ) {
@@ -1241,12 +1240,6 @@ void ui_process_input ( unsigned char block_p ) {
          applications_free();
          pnd_log ( pndn_debug, "Rescanning applications\n" );
          applications_scan();
-         // reset view
-         ui_selected = NULL;
-         ui_rows_scrolled_down = 0;
-         // set back to first tab, to be safe
-         ui_category = 0;
-         ui_catshift = 0;
        } else if ( sel == 3 ) {
          // cache preview to SD now
          extern pnd_box_handle g_active_apps;
@@ -1271,11 +1264,6 @@ void ui_process_input ( unsigned char block_p ) {
          } // while
 
        } else if ( sel == 4 ) {
-         // run xfce
-         char buffer [ PATH_MAX ];
-         sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/bin/startxfce4" );
-         emit_and_quit ( buffer );
-       } else if ( sel == 5 ) {
          // run terminal
          char *argv[5];
          argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
@@ -1285,18 +1273,18 @@ void ui_process_input ( unsigned char block_p ) {
            ui_forkexec ( argv );
          }
 
-       } else if ( sel == 6 ) {
+       } else if ( sel == 5 ) {
          char buffer [ PATH_MAX ];
          sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
          emit_and_quit ( buffer );
-       } else if ( sel == 7 ) {
+       } else if ( sel == 6 ) {
          emit_and_quit ( MM_QUIT );
-       } else if ( sel == 8 ) {
+       } else if ( sel == 7 ) {
          // select skin
          if ( ui_pick_skin() ) {
            emit_and_quit ( MM_RESTART );
          }
-       } else if ( sel == 9 ) {
+       } else if ( sel == 8 ) {
          // about
          char buffer [ PATH_MAX ];
          sprintf ( buffer, "%s/about.txt", g_skinpath );
@@ -2342,6 +2330,42 @@ void ui_post_scan ( void ) {
 
   } // deferred icon load
 
+  // reset view
+  ui_selected = NULL;
+  ui_rows_scrolled_down = 0;
+  // set back to first tab, to be safe
+  ui_category = 0;
+  ui_catshift = 0;
+
+  // do we have a preferred category to jump to?
+  char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
+  if ( dc ) {
+
+    // attempt to find default cat; if we do find it, select it; otherwise
+    // default behaviour will pick first cat (ie: usually All)
+    unsigned int i;
+    for ( i = 0; i < g_categorycount; i++ ) {
+      if ( strcasecmp ( g_categories [ i ].catname, dc ) == 0 ) {
+       ui_category = i;
+       // ensure visibility
+       unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
+       unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
+       if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
+         ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
+       }
+       break;
+      }
+    }
+
+    if ( i == g_categorycount ) {
+      pnd_log ( pndn_warning, "  User defined default category '%s' but not found, so using default behaviour\n", dc );
+    }
+
+  } // default cat
+
+  // redraw all
+  render_mask |= CHANGED_EVERYTHING;
+
   return;
 }
 
@@ -2700,6 +2724,10 @@ void ui_revealscreen ( void ) {
   unsigned int labelmax = 0;
   unsigned int i;
 
+  if ( ! _categories_inviscount ) {
+    return; // nothing to do
+  }
+
   for ( i = 0; i < _categories_inviscount; i++ ) {
     labels [ labelmax++ ] = _categories_invis [ i ].catname;
   }
@@ -2714,18 +2742,31 @@ void ui_revealscreen ( void ) {
       return;
     }
 
+    // fix up category name, if its been hacked
+    if ( strchr ( _categories_invis [ sel ].catname, '.' ) ) {
+      char *t = _categories_invis [ sel ].catname;
+      _categories_invis [ sel ].catname = strdup ( strchr ( _categories_invis [ sel ].catname, '.' ) + 1 );
+      free ( t );
+    }
+    // copy invisi-cat into live-cat
     memmove ( &(g_categories [ g_categorycount ]), &(_categories_invis [ sel ]), sizeof(mm_category_t) );
     g_categorycount++;
+    // move subsequent invisi-cats up, so the selected invisi-cat is nolonger existing in invisi-list at
+    // all (avoid double-free() later)
+    memmove ( &(_categories_invis [ sel ]), &(_categories_invis [ sel + 1 ]), sizeof(mm_category_t) * ( _categories_inviscount - sel - 1 ) );
+    _categories_inviscount--;
 
+    // switch to the new category
     ui_category = g_categorycount - 1;
 
+    // ensure visibility
     unsigned int screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
     unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
     if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
-      //ui_catshift++;
       ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
     }
 
+    // redraw tabs
     render_mask |= CHANGED_CATEGORY;
   }