mmenu: Fixing bug in custom category management
[pandora-libraries.git] / minimenu / mmui.c
index 31a3e88..7a31c83 100644 (file)
@@ -371,6 +371,12 @@ void ui_render ( void ) {
 
   ui_context_t *c = &ui_display_context; // for convenience and shorthand
 
+  // on demand icon loading
+  static int load_visible = -1;
+  if ( load_visible == -1 ) {
+    load_visible = pnd_conf_get_as_int_d ( g_conf, "minimenu.load_visible_icons", 0 );
+  }
+
   // how many total rows do we need?
   if ( g_categorycount ) {
     icon_rows = g_categories [ ui_category ] -> refcount / c -> col_max;
@@ -745,6 +751,44 @@ void ui_render ( void ) {
            // show icon
            mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
            SDL_Surface *iconsurface;
+
+           // if icon not in cache, and its a pnd-file source, perhaps try to load it right now..
+           if ( ( ! ic ) &&
+                ( load_visible ) &&
+                ( ! ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) )
+              )
+           {
+             // try to load any icons that..
+             // - are not yet loaded
+             // - did not fail a previous load attempt
+             // this way user can upfront load all icons, or defer all icons, or even defer all icons
+             // and still try to load visible ones 'just before needed'; so not at mmenu load time, but
+             // as needed (only the ones needed.)
+
+             if ( ( appiter -> ref -> pnd_icon_pos ) ||
+                  ( appiter -> ref -> icon && appiter -> ref -> object_flags & PND_DISCO_LIBPND_DD )
+                )
+             {
+  
+               // try to cache it?
+               if ( ! cache_icon ( appiter -> ref, ui_display_context.icon_max_width, ui_display_context.icon_max_width ) ) {
+                 // erm..
+               }
+
+               // avoid churn
+               appiter -> ref -> pnd_icon_pos = 0;
+               if ( appiter -> ref -> icon ) {
+                 free ( appiter -> ref -> icon );
+                 appiter -> ref -> icon = NULL;
+               }
+
+               // pick up as if nothing happened..
+               ic = cache_query_icon ( appiter -> ref -> unique_id );
+
+             }
+
+           } // load icon during rendering?
+
            if ( ic ) {
              iconsurface = ic -> i;
            } else {
@@ -1419,6 +1463,8 @@ void ui_process_input ( pnd_dbusnotify_handle dbh, pnd_notify_handle nh ) {
          // do nothing
          ui_revealscreen();
        } else if ( sel == 1 ) {
+         // store conf on exit, so that last app/cat can be cached.. for ED :)
+         conf_write ( g_conf, conf_determine_location ( g_conf ) );
          // shutdown
          sprintf ( buffer, "sudo poweroff" );
          system ( buffer );
@@ -2844,7 +2890,7 @@ void ui_post_scan ( void ) {
   } // default cat
 
   // if we're sent right to a dirbrowser tab, restock it now (normally we restock on entry)
-  if ( g_categories [ ui_category ] -> fspath ) {
+  if ( g_categories [ ui_category ] && g_categories [ ui_category ] -> fspath ) {
     printf ( "Restock on start: '%s'\n", g_categories [ ui_category ] -> fspath );
     category_fs_restock ( g_categories [ ui_category ] );
   }
@@ -2873,7 +2919,7 @@ unsigned char ui_threaded_defered_icon ( void *p ) {
 
   // work at it in order within current category
 
-  mm_appref_t *refiter = g_categories [ ui_category ] -> refs;
+  mm_appref_t *refiter = g_categories [ ui_category ] ? g_categories [ ui_category ] -> refs : NULL;
   while ( refiter && ! g_icon_thread_stop ) {
     iter = refiter -> ref;
 
@@ -4112,6 +4158,14 @@ void ui_manage_categories ( void ) {
        // did the user enter something?
        if ( changed ) {
 
+         // for now, force use of '*' into something else as we use * internally :/ (FIXME)
+         {
+           char *fixme;
+           while ( fixme = strchr ( namebuf, '*' ) ) {
+             *fixme = '_';
+           }
+         }
+
          // and if so, is it existant already or not?
          if ( mmcustom_query ( namebuf, NULL ) ) {
            ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a registered category." );
@@ -4155,6 +4209,14 @@ void ui_manage_categories ( void ) {
          // did the user enter something?
          if ( changed ) {
 
+           // for now, force use of '*' into something else as we use * internally :/ (FIXME)
+           {
+             char *fixme;
+             while ( fixme = strchr ( namebuf, '*' ) ) {
+               *fixme = '_';
+             }
+           }
+
            // and if so, is it existant already or not?
            if ( mmcustom_query ( namebuf, maincat ) ) {
              ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a subcategory." );
@@ -4351,7 +4413,8 @@ char *ui_pick_custom_category ( unsigned char mode ) {
 }
 
 void ui_start_defered_icon_thread ( void ) {
-  if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 0 ) {
+
+  if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) != 1 ) {
     return;
   }