mmenu -- minor buglet when trying to create custom subcats for FD cats
[pandora-libraries.git] / minimenu / mmui.c
index 2b34fa5..7861dd7 100644 (file)
@@ -9,6 +9,8 @@
 #include <string.h> /* for making ftw.h happy */
 #include <time.h>
 #include <ftw.h>
+#include <ctype.h>
+
 #include "SDL.h"
 #include "SDL_audio.h"
 #include "SDL_image.h"
@@ -28,6 +30,8 @@
 #include "../lib/pnd_pathiter.h"
 #include "pnd_utility.h"
 #include "pnd_pndfiles.h"
+#include "pnd_notify.h"
+#include "pnd_dbusnotify.h"
 
 #include "mmenu.h"
 #include "mmcat.h"
@@ -36,6 +40,8 @@
 #include "mmwrapcmd.h"
 #include "mmconf.h"
 #include "mmui_context.h"
+#include "freedesktop_cats.h"
+#include "mmcustom_cats.h"
 
 #define CHANGED_NOTHING     (0)
 #define CHANGED_CATEGORY    (1<<0)  /* changed to different category */
@@ -52,10 +58,12 @@ unsigned int render_mask = CHANGED_EVERYTHING;
 SDL_Surface *sdl_realscreen = NULL;
 unsigned int sdl_ticks = 0;
 SDL_Thread *g_preview_thread = NULL;
+SDL_Thread *g_timer_thread = NULL;
 
 enum { sdl_user_ticker = 0,
        sdl_user_finishedpreview = 1,
        sdl_user_finishedicon = 2,
+       sdl_user_checksd = 3,
 };
 
 /* app state
@@ -146,7 +154,7 @@ unsigned char ui_setup ( void ) {
 #endif
 
   // key repeat
-  SDL_EnableKeyRepeat ( 500, 150 );
+  SDL_EnableKeyRepeat ( 500, 125 /* 150 */ );
 
   // images
   //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
@@ -232,12 +240,15 @@ mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
   { IMG_HOURGLASS,            "graphics.IMG_HOURGLASS", },
   { IMG_FOLDER,               "graphics.IMG_FOLDER", },
   { IMG_EXECBIN,              "graphics.IMG_EXECBIN", },
+  { IMG_SUBCATFOLDER,         "graphics.IMG_SUBCATFOLDER", "graphics.IMG_FOLDER", },
+  { IMG_DOTDOTFOLDER,         "graphics.IMG_DOTDOTFOLDER", "graphics.IMG_FOLDER", },
   { IMG_MAX,                  NULL },
 };
 
 unsigned char ui_imagecache ( char *basepath ) {
   unsigned int i;
   char fullpath [ PATH_MAX ];
+  unsigned char try;
 
   // loaded
 
@@ -248,23 +259,39 @@ unsigned char ui_imagecache ( char *basepath ) {
       exit ( -1 );
     }
 
-    char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
+    for ( try = 0; try < 2; try++ ) {
 
-    if ( ! filename ) {
-      pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
-      return ( 0 );
-    }
+      char *filename;
 
-    if ( filename [ 0 ] == '/' ) {
-      strncpy ( fullpath, filename, PATH_MAX );
-    } else {
-      sprintf ( fullpath, "%s/%s", basepath, filename );
-    }
+      if ( try == 0 ) {
+       filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
+      } else {
+       if ( g_imagecache [ i ].alt_confname ) {
+         filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].alt_confname );
+       } else {
+         return ( 0 );
+       }
+      }
 
-    if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
-      pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
-      return ( 0 );
-    }
+      if ( ! filename ) {
+       pnd_log ( pndn_error, "ERROR: (Try %u) Missing filename in conf for key: %s\n", try + 1, g_imagecache [ i ].confname );
+       if ( try == 0 ) { continue; } else { return ( 0 ); }
+      }
+
+      if ( filename [ 0 ] == '/' ) {
+       strncpy ( fullpath, filename, PATH_MAX );
+      } else {
+       sprintf ( fullpath, "%s/%s", basepath, filename );
+      }
+
+      if ( ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
+       break; // no retry needed
+      } else {
+       pnd_log ( pndn_error, "ERROR: (Try %u) Couldn't load static cache image: %s\n", try + 1, fullpath );
+       if ( try == 0 ) { continue; } else { return ( 0 ); }
+      }
+
+    } // try twice
 
   } // for
 
@@ -363,17 +390,25 @@ void ui_render ( void ) {
   // ensure selection is visible
   if ( ui_selected ) {
 
-    int index = ui_selected_index();
-    int topleft = c -> col_max * ui_rows_scrolled_down;
-    int botright = ( c -> col_max * ( ui_rows_scrolled_down + c -> row_max ) - 1 );
+    unsigned char autoscrolled = 1;
+    while ( autoscrolled ) {
+      autoscrolled = 0;
+
+      int index = ui_selected_index();
+      int topleft = c -> col_max * ui_rows_scrolled_down;
+      int botright = ( c -> col_max * ( ui_rows_scrolled_down + c -> row_max ) - 1 );
+
+      if ( index < topleft ) {
+       ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
+       render_jobs_b |= R_ALL;
+       autoscrolled = 1;
+      } else if ( index > botright ) {
+       ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
+       render_jobs_b |= R_ALL;
+       autoscrolled = 1;
+      }
 
-    if ( index < topleft ) {
-      ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
-      render_jobs_b |= R_ALL;
-    } else if ( index > botright ) {
-      ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
-      render_jobs_b |= R_ALL;
-    }
+    } // while autoscrolling
 
     if ( ui_rows_scrolled_down < 0 ) {
       ui_rows_scrolled_down = 0;
@@ -688,7 +723,17 @@ void ui_render ( void ) {
              // filesystem (file or directory icon)
              if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
                if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
-                 iconsurface = g_imagecache [ IMG_FOLDER ].i;
+
+                 // is this a subcat, a .., or a filesystem folder?
+                 //iconsurface = g_imagecache [ IMG_FOLDER ].i;
+                 if ( g_categories [ ui_category ] -> fspath ) {
+                   iconsurface = g_imagecache [ IMG_FOLDER ].i;
+                 } else if ( strcmp ( appiter -> ref -> title_en, ".." ) == 0 ) {
+                   iconsurface = g_imagecache [ IMG_DOTDOTFOLDER ].i;
+                 } else {
+                   iconsurface = g_imagecache [ IMG_SUBCATFOLDER ].i;
+                 }
+
                } else {
                  iconsurface = g_imagecache [ IMG_EXECBIN ].i;
                }
@@ -936,6 +981,30 @@ void ui_render ( void ) {
 
       desty += src.h;
 
+      rtext = TTF_RenderText_Blended ( g_detailtext_font, "START or B to run app", c -> fontcolor );
+      dest -> x = cell_offset_x;
+      dest -> y = desty;
+      SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
+      SDL_FreeSurface ( rtext );
+      dest++;
+      desty += src.h;
+
+      rtext = TTF_RenderText_Blended ( g_detailtext_font, "SPACE for app menu", c -> fontcolor );
+      dest -> x = cell_offset_x;
+      dest -> y = desty;
+      SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
+      SDL_FreeSurface ( rtext );
+      dest++;
+      desty += src.h;
+
+      rtext = TTF_RenderText_Blended ( g_detailtext_font, "A to toggle details", c -> fontcolor );
+      dest -> x = cell_offset_x;
+      dest -> y = desty;
+      SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
+      SDL_FreeSurface ( rtext );
+      dest++;
+      desty += src.h;
+
     } // r_detail && selected?
 
   } // r_detail
@@ -1029,14 +1098,14 @@ void ui_render ( void ) {
 
 } // ui_render
 
-void ui_process_input ( unsigned char block_p ) {
+void ui_process_input ( pnd_dbusnotify_handle dbh, pnd_notify_handle nh ) {
   SDL_Event event;
 
   unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
   //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
 
-  while ( ! ui_event &&
-         block_p ? SDL_WaitEvent ( &event ) : SDL_PollEvent ( &event ) )
+  while ( ( ! ui_event ) &&
+         /*block_p ?*/ SDL_WaitEvent ( &event ) /*: SDL_PollEvent ( &event )*/ )
   {
 
     switch ( event.type ) {
@@ -1044,8 +1113,16 @@ void ui_process_input ( unsigned char block_p ) {
     case SDL_USEREVENT:
       // update something
 
+      // the user-defined SDL events are all for threaded/delayed previews (and icons, which
+      // generally are not used); if we're in wide mode, we can skip previews
+      // to avoid slowing things down when they're not shown.
+
       if ( event.user.code == sdl_user_ticker ) {
 
+       if ( ui_detail_hidden ) {
+         break; // skip building previews when not showing them
+       }
+
        // timer went off, time to load something
        if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
 
@@ -1097,7 +1174,29 @@ void ui_process_input ( unsigned char block_p ) {
        // redraw, so we can show the newly loaded icon
        ui_event++;
 
-      }
+      } else if ( event.user.code == sdl_user_checksd ) {
+       // check if any inotify-type events occured, forcing us to rescan/re-disco the SDs
+
+       unsigned char watch_dbus = 0;
+       unsigned char watch_inotify = 0;
+
+       if ( dbh ) {
+         watch_dbus = pnd_dbusnotify_rediscover_p ( dbh );
+       }
+
+       if ( nh ) {
+         watch_inotify = pnd_notify_rediscover_p ( nh );
+       }
+
+       if ( watch_dbus || watch_inotify ) {
+         pnd_log ( pndn_debug, "dbusnotify detected SD event\n" );
+         applications_free();
+         applications_scan();
+
+         ui_event++;
+       }
+
+      } // SDL user event
 
       render_mask |= CHANGED_EVERYTHING;
 
@@ -1217,9 +1316,17 @@ void ui_process_input ( unsigned char block_p ) {
       } else if ( event.key.keysym.sym == SDLK_DOWN ) {
        ui_push_down();
        ui_event++;
-      } else if ( event.key.keysym.sym == SDLK_SPACE || event.key.keysym.sym == SDLK_END ) { // space or B
+      } else if ( event.key.keysym.sym == SDLK_END ) { // B
        ui_push_exec();
        ui_event++;
+      } else if ( event.key.keysym.sym == SDLK_SPACE ) { // space
+       if ( ui_selected ) {
+         ui_menu_context ( ui_selected );
+       } else {
+         // TBD: post an error?
+       }
+       render_mask |= CHANGED_EVERYTHING;
+       ui_event++;
       } else if ( event.key.keysym.sym == SDLK_TAB || event.key.keysym.sym == SDLK_HOME ) { // tab or A
        // if detail panel is togglable, then toggle it
        // if not, make sure its ruddy well shown!
@@ -1235,12 +1342,26 @@ void ui_process_input ( unsigned char block_p ) {
       } else if ( event.key.keysym.sym == SDLK_RCTRL || event.key.keysym.sym == SDLK_PERIOD ) { // right trigger or period
        ui_push_rtrigger();
        ui_event++;
+
       } else if ( event.key.keysym.sym == SDLK_PAGEUP ) { // Y
        // info
        if ( ui_selected ) {
          ui_show_info ( pnd_run_script, ui_selected -> ref );
          ui_event++;
        }
+      } else if ( event.key.keysym.sym == SDLK_PAGEDOWN ) { // X
+       ui_push_backup();
+
+       // forget the selection, nolonger applies
+       ui_selected = NULL;
+       ui_set_selected ( ui_selected );
+       // rescan the dir
+       if ( g_categories [ ui_category ] -> fspath ) {
+         category_fs_restock ( g_categories [ ui_category ] );
+       }
+       // redraw the grid
+       render_mask |= CHANGED_EVERYTHING;
+       ui_event++;
 
       } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
        ui_push_exec();
@@ -1251,6 +1372,7 @@ void ui_process_input ( unsigned char block_p ) {
          "Reveal hidden category",
          "Shutdown Pandora",
          "Configure Minimenu",
+         "Manage custom app categories",
          "Rescan for applications",
          "Cache previews to SD now",
          "Run a terminal/console",
@@ -1259,7 +1381,7 @@ void ui_process_input ( unsigned char block_p ) {
          "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, 11, "Minimenu", "Enter to select; other to return." );
 
        char buffer [ 100 ];
        if ( sel == 0 ) {
@@ -1277,12 +1399,15 @@ void ui_process_input ( unsigned char block_p ) {
            emit_and_quit ( MM_RESTART );
          }
        } else if ( sel == 3 ) {
+         // manage custom categories
+         ui_manage_categories();
+       } else if ( sel == 4 ) {
          // rescan apps
          pnd_log ( pndn_debug, "Freeing up applications\n" );
          applications_free();
          pnd_log ( pndn_debug, "Rescanning applications\n" );
          applications_scan();
-       } else if ( sel == 4 ) {
+       } else if ( sel == 5 ) {
          // cache preview to SD now
          extern pnd_box_handle g_active_apps;
          pnd_box_handle h = g_active_apps;
@@ -1305,7 +1430,7 @@ void ui_process_input ( unsigned char block_p ) {
            iter = pnd_box_get_next ( iter );
          } // while
 
-       } else if ( sel == 5 ) {
+       } else if ( sel == 6 ) {
          // run terminal
          char *argv[5];
          argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
@@ -1315,18 +1440,18 @@ void ui_process_input ( unsigned char block_p ) {
            ui_forkexec ( argv );
          }
 
-       } else if ( sel == 6 ) {
+       } else if ( sel == 7 ) {
          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 ) {
-         emit_and_quit ( MM_QUIT );
        } else if ( sel == 8 ) {
+         emit_and_quit ( MM_QUIT );
+       } else if ( sel == 9 ) {
          // select skin
          if ( ui_pick_skin() ) {
            emit_and_quit ( MM_RESTART );
          }
-       } else if ( sel == 9 ) {
+       } else if ( sel == 10 ) {
          // about
          char buffer [ PATH_MAX ];
          sprintf ( buffer, "%s/about.txt", g_skinpath );
@@ -1348,7 +1473,7 @@ void ui_process_input ( unsigned char block_p ) {
          //fprintf ( stderr, "sel %s next %s\n", ui_selected -> ref -> title_en, ui_selected -> next -> ref -> title_en );
 
          // are we already matching the same char? and next item is also same char?
-         if ( app && ui_selected &&
+         if ( app && ui_selected && ui_selected -> next &&
               ui_selected -> ref -> title_en && ui_selected -> next -> ref -> title_en &&
               toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( ui_selected -> next -> ref -> title_en [ 0 ] ) &&
               toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym )
@@ -1373,12 +1498,10 @@ void ui_process_input ( unsigned char block_p ) {
            // looks like we found a potential match; try switching it to visible selection
            ui_selected = app;
            ui_set_selected ( ui_selected );
+           ui_event++;
          }
 
 
-
-
-
        } // SDLK_alphanumeric?
 
       } // SDLK_....
@@ -1606,6 +1729,60 @@ void ui_push_down ( void ) {
   return;
 }
 
+// 'backup' is currently 'X', for going back up in a folder/subcat without having to hit exec on the '..' entry
+void ui_push_backup ( void ) {
+
+  // a subcat-as-dir, or a dir browser?
+  if ( g_categories [ ui_category] -> fspath ) {
+    // dir browser, just climb our way back up
+
+    // go up
+    char *c;
+
+    // lop off last word; if the thing ends with /, lop that one, then the next word.
+    while ( ( c = strrchr ( g_categories [ ui_category] -> fspath, '/' ) ) ) {
+      *c = '\0'; // lop off the last hunk
+      if ( *(c+1) != '\0' ) {
+       break;
+      }
+    } // while
+
+    // nothing left?
+    if ( g_categories [ ui_category] -> fspath [ 0 ] == '\0' ) {
+      free ( g_categories [ ui_category] -> fspath );
+      g_categories [ ui_category] -> fspath = strdup ( "/" );
+    }
+
+  } else {
+    // a pnd subcat .. are we in one, or at the 'top'?
+    char *pcatname = g_categories [ ui_category ] -> parent_catname;
+
+    if ( ! pcatname ) {
+      return; // we're at the 'top' already
+    }
+
+    // set to first cat!
+    ui_category = 0;
+
+    // republish cats .. shoudl just be the one
+    category_publish ( CFNORMAL, NULL );
+
+    if ( pcatname ) {
+      ui_category = category_index ( pcatname );
+
+      // ensure tab visible?
+      unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
+      if ( ui_category > ui_catshift + ( ui_display_context.screen_width / tab_width ) - 1 ) {
+       ui_catshift = ui_category - ( ui_display_context.screen_width / tab_width ) + 1;
+      }
+
+    }
+
+  } // dir or subcat?
+
+  return;
+}
+
 void ui_push_exec ( void ) {
 
   if ( ! ui_selected ) {
@@ -1625,27 +1802,18 @@ void ui_push_exec ( void ) {
       if ( ! g_categories [ ui_category] -> fspath ) {
        // pnd subcat as dir
 
-       static char *ui_category_stack = NULL;
-
        // are we already in a subcat? if so, go back to parent; there is no grandparenting or deeper
        if ( g_categories [ ui_category ] -> parent_catname ) {
          // go back up
-
-         // set to first cat!
-         ui_category = 0;
-         // republish cats .. shoudl just be the one
-         category_publish ( CFNORMAL, NULL );
-
-         if ( ui_category_stack ) {
-           ui_category = category_index ( ui_category_stack );
-         }
+         ui_push_backup();
 
        } else {
          // delve into subcat
 
          // set to first cat!
-         ui_category_stack = g_categories [ ui_category ] -> catname;
          ui_category = 0;
+         ui_catshift = 0;
+
          // republish cats .. shoudl just be the one
          category_publish ( CFBYNAME, ui_selected -> ref -> object_path );
 
@@ -1661,22 +1829,7 @@ void ui_push_exec ( void ) {
 
        // delve up/down the dir tree
        if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
-         // go up
-         char *c;
-
-         // lop off last word; if the thing ends with /, lop that one, then the next word.
-         while ( ( c = strrchr ( g_categories [ ui_category] -> fspath, '/' ) ) ) {
-           *c = '\0'; // lop off the last hunk
-           if ( *(c+1) != '\0' ) {
-             break;
-           }
-         } // while
-
-         // nothing left?
-         if ( g_categories [ ui_category] -> fspath [ 0 ] == '\0' ) {
-           free ( g_categories [ ui_category] -> fspath );
-           g_categories [ ui_category] -> fspath = strdup ( "/" );
-         }
+         ui_push_backup();
 
        } else {
          // go down
@@ -2150,14 +2303,7 @@ int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *f
 
   unsigned int sel = 0;
 
-  unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
-  unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
-  unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
-  unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
-
-  SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
-
-  SDL_Color selfontcolor = { 0/*font_rgba_r*/, font_rgba_g, font_rgba_b, font_rgba_a };
+  SDL_Color selfontcolor = { 0/*font_rgba_r*/, ui_display_context.font_rgba_g, ui_display_context.font_rgba_b, ui_display_context.font_rgba_a };
 
   unsigned int i;
   SDL_Event event;
@@ -2198,7 +2344,7 @@ int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *f
 
     // show header
     if ( title ) {
-      rtext = TTF_RenderText_Blended ( g_tab_font, title, tmpfontcolor );
+      rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
       dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
       dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
       SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
@@ -2208,7 +2354,7 @@ int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *f
 
     // show footer
     if ( footer ) {
-      rtext = TTF_RenderText_Blended ( g_tab_font, footer, tmpfontcolor );
+      rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
       dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
       dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
        ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
@@ -2225,7 +2371,7 @@ int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *f
       if ( sel == i ) {
        rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
       } else {
-       rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], tmpfontcolor );
+       rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], ui_display_context.fontcolor );
       }
       dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
       dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 - first_visible ) );
@@ -2503,6 +2649,44 @@ unsigned char ui_forkexec ( char *argv[] ) {
   return ( 1 );
 }
 
+unsigned char ui_threaded_timer_create ( void ) {
+
+  g_timer_thread = SDL_CreateThread ( (void*)ui_threaded_timer, NULL );
+
+  if ( ! g_timer_thread ) {
+    pnd_log ( pndn_error, "ERROR: Couldn't create timer thread\n" );
+    return ( 0 );
+  }
+
+  return ( 1 );
+}
+
+int ui_threaded_timer ( pnd_disco_t *p ) {
+
+  // this timer's job is to ..
+  // - do nothing for quite awhile
+  // - on wake, post event to SDL event queue, so that main thread will check if SD insert/eject occurred
+  // - goto 10
+
+  unsigned int delay_s = 2; // seconds
+
+  while ( 1 ) {
+
+    // pause...
+    sleep ( delay_s );
+
+    // .. trigger SD check
+    SDL_Event e;
+    bzero ( &e, sizeof(SDL_Event) );
+    e.type = SDL_USEREVENT;
+    e.user.code = sdl_user_checksd;
+    SDL_PushEvent ( &e );
+
+  } // while
+
+  return ( 0 );
+}
+
 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
 
   if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
@@ -2937,6 +3121,7 @@ void ui_revealscreen ( void ) {
   char *labels [ 500 ];
   unsigned int labelmax = 0;
   unsigned int i;
+  char fulllabel [ 200 ];
 
   if ( ! category_count ( CFHIDDEN ) ) {
     return; // nothing to do
@@ -2947,7 +3132,14 @@ void ui_revealscreen ( void ) {
 
   // build up labels to show in menu
   for ( i = 0; i < g_categorycount; i++ ) {
-    labels [ labelmax++ ] = g_categories [ i ] -> catname;
+
+    if ( g_categories [ i ] -> parent_catname ) {
+      sprintf ( fulllabel, "%s [%s]", g_categories [ i ] -> catname, g_categories [ i ] -> parent_catname );
+    } else {
+      sprintf ( fulllabel, "%s", g_categories [ i ] -> catname );
+    }
+
+    labels [ labelmax++ ] = strdup ( fulllabel );
   }
 
   // show menu
@@ -2958,11 +3150,13 @@ void ui_revealscreen ( void ) {
   if ( sel >= 0 ) {
 
     // fix up category name, if its been hacked
+#if 0 // prepending and .. wtf crap is this
     if ( strchr ( g_categories [ sel ] -> catname, '.' ) ) {
       char *t = g_categories [ sel ] -> catname;
       g_categories [ sel ] -> catname = strdup ( strchr ( g_categories [ sel ] -> catname, '.' ) + 1 );
       free ( t );
     }
+#endif
 
     // reflag this guy to be visible
     g_categories [ sel ] -> catflags = CFNORMAL;
@@ -2983,10 +3177,14 @@ void ui_revealscreen ( void ) {
       ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
     }
 
-    // redraw tabs
-    render_mask |= CHANGED_CATEGORY;
   }
 
+  // republish categories
+  category_publish ( CFNORMAL, NULL );
+
+  // redraw tabs
+  render_mask |= CHANGED_CATEGORY;
+
   return;
 }
 
@@ -3095,3 +3293,924 @@ void ui_toggle_detail_pane ( void ) {
 
   return;
 }
+
+void ui_menu_context ( mm_appref_t *a ) {
+
+  unsigned char rescan_apps = 0;
+  unsigned char context_alive = 1;
+
+  enum {
+    context_done = 0,
+    context_file_info,
+    context_file_delete,
+    context_app_info,
+    context_app_hide,
+    context_app_recategorize,
+    context_app_recategorize_sub,
+    context_app_rename,
+    context_app_cpuspeed,
+    context_app_run,
+    context_app_notes1,
+    context_app_notes2,
+    context_app_notes3,
+    context_menu_max
+  };
+
+  char *verbiage[] = {
+    "Done (return to grid)",      // context_done
+    "Get info about file/dir",    // context_file_info
+    "Delete file/dir",            // context_file_delete
+    "Get info",                   // context_app_info
+    "Hide application",           //             hide
+    "Recategorize",               //             recategorize
+    "Recategorize subcategory",   //             recategorize
+    "Change displayed title",     //             rename
+    "Set CPU speed for launch",   //             cpuspeed
+    "Run application",            //             run
+    "Edit notes line 1",          //             notes1
+    "Edit notes line 2",          //             notes2
+    "Edit notes line 3",          //             notes3
+  };
+
+  unsigned short int menu [ context_menu_max ];
+  char *menustring [ context_menu_max ];
+  unsigned char menumax = 0;
+
+  // ++ done
+  menu [ menumax ] = context_done; menustring [ menumax++ ] = verbiage [ context_done ];
+
+  // hook up appropriate menu options based on tab-type and object-type
+  if ( g_categories [ ui_category ] -> fspath ) {
+    return; // TBD
+    menu [ menumax ] = context_file_info; menustring [ menumax++ ] = verbiage [ context_file_info ];
+    menu [ menumax ] = context_file_delete; menustring [ menumax++ ] = verbiage [ context_file_delete ];
+  } else {
+
+    if ( a -> ref -> object_type == pnd_object_type_directory ) {
+      return; // don't do anything if the guy is a subcat-as-folder
+    }
+
+    //menu [ menumax ] = context_app_info; menustring [ menumax++ ] = verbiage [ context_app_info ];
+    menu [ menumax ] = context_app_run; menustring [ menumax++ ] = verbiage [ context_app_run ];
+    menu [ menumax ] = context_app_hide; menustring [ menumax++ ] = verbiage [ context_app_hide ];
+    menu [ menumax ] = context_app_recategorize; menustring [ menumax++ ] = verbiage [ context_app_recategorize ];
+    menu [ menumax ] = context_app_recategorize_sub; menustring [ menumax++ ] = verbiage [ context_app_recategorize_sub ];
+    menu [ menumax ] = context_app_rename; menustring [ menumax++ ] = verbiage [ context_app_rename ];
+    menu [ menumax ] = context_app_cpuspeed; menustring [ menumax++ ] = verbiage [ context_app_cpuspeed ];
+    menu [ menumax ] = context_app_notes1; menustring [ menumax++ ] = verbiage [ context_app_notes1 ];
+    menu [ menumax ] = context_app_notes2; menustring [ menumax++ ] = verbiage [ context_app_notes2 ];
+    menu [ menumax ] = context_app_notes3; menustring [ menumax++ ] = verbiage [ context_app_notes3 ];
+  }
+
+  // operate the menu
+  while ( context_alive ) {
+
+    int sel = ui_modal_single_menu ( menustring, menumax, a -> ref -> title_en ? a -> ref -> title_en : "Quickpick Menu" /* title */, "B or Enter; other to cancel." /* footer */ );
+
+    if ( sel < 0 ) {
+      context_alive = 0;
+
+    } else {
+
+      switch ( menu [ sel ] ) {
+
+      case context_done:
+       context_alive = 0;
+       break;
+
+      case context_file_info:
+       break;
+
+      case context_file_delete:
+       //ui_menu_twoby ( "Delete - Are you sure?", "B/enter; other to cancel", "Delete", "Do not delete" );
+       break;
+
+      case context_app_info:
+       break;
+
+      case context_app_hide:
+       {
+         // determine key
+         char confkey [ 1000 ];
+         snprintf ( confkey, 999, "%s.%s", "appshow", a -> ref -> unique_id );
+
+         // turn app 'off'
+         pnd_conf_set_char ( g_conf, confkey, "0" );
+
+         // write conf, so it will take next time
+         conf_write ( g_conf, conf_determine_location ( g_conf ) );
+
+         // can we just 'hide' this guy without reloading all apps? (this is for you, EvilDragon)
+         if ( 0 ) {
+           //
+           // DOESN'T WORK YET; other parts of app are still hanging onto some values and blow up
+           //
+           char *uid = strdup ( a -> ref -> unique_id );
+           unsigned int i;
+           for ( i = 0; i < g_categorycount; i++ ) {
+             mm_appref_t *p = g_categories [ i ] -> refs;
+             mm_appref_t *n;
+             while ( p ) {
+               n = p -> next;
+
+               if ( strcmp ( p -> ref -> unique_id, uid ) == 0 ) {
+                 free ( p );
+                 if ( g_categories [ i ] -> refcount ) {
+                   g_categories [ i ] -> refcount--;
+                 }
+               }
+
+               p = n;
+             } // while for each appref
+           } // for each cat/tab
+
+           free ( uid );
+
+         } else {
+           // request rescan and wrap up
+           rescan_apps++;
+         }
+
+         context_alive = 0; // nolonger visible, so lets just get out
+
+       }
+    
+       break;
+
+      case context_app_recategorize:
+       {
+         char *opts [ 250 ];
+         unsigned char optmax = 0;
+         unsigned char i;
+
+         // show custom categories
+         if ( mmcustom_setup() ) {
+
+           for ( i = 0; i < mmcustom_count; i++ ) {
+             if ( mmcustom_complete [ i ].parent_cat == NULL ) {
+               opts [ optmax++ ] = mmcustom_complete [ i ].cat;
+             }
+           }
+
+         }
+
+         // show FD categories
+         i = 2; // skip first two - Other and NoParentCategory
+         while ( 1 ) {
+
+           if ( ! freedesktop_complete [ i ].cat ) {
+             break;
+           }
+
+           if ( ! freedesktop_complete [ i ].parent_cat ) {
+             opts [ optmax++ ] = freedesktop_complete [ i ].cat;
+           }
+
+           i++;
+         } // while
+
+         // picker
+         char prompt [ 101 ];
+         snprintf ( prompt, 100, "Pick category [%s]", a -> ref -> main_category ? a -> ref -> main_category : "NoParentCategory" );
+
+         int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select parent category"*/, "Enter to select; other to skip." );
+
+         if ( sel >= 0 ) {
+           char confirm [ 1001 ];
+           snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
+
+           if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm categorization", "Do not set category" ) == 1 ) {
+             ovr_replace_or_add ( a, "maincategory", opts [ sel ] );
+             rescan_apps++;
+             // when changing main cat, reset subcat, otherwise you go from Game/Emu to Network/Emu and get sent to Other right away
+             ovr_replace_or_add ( a, "maincategorysub1", freedesktop_complete [ 2 ].cat );
+           }
+
+         }
+
+         if ( mmcustom_is_ready() ) {
+           mmcustom_shutdown();
+         }
+
+       }
+       break;
+
+      case context_app_recategorize_sub:
+       {
+         char *opts [ 250 ];
+         unsigned char optmax = 0;
+         unsigned char i = 0;
+
+         char *whichparentarewe;
+         if ( g_categories [ ui_category ] -> parent_catname ) {
+           whichparentarewe = g_categories [ ui_category ] -> parent_catname;
+         } else {
+           whichparentarewe = g_categories [ ui_category ] -> catname;
+         }
+
+         // add NoSubcategory magic one
+         opts [ optmax++ ] = freedesktop_complete [ 2 ].cat;
+
+         // add custom categories
+         if ( mmcustom_setup() ) {
+
+           for ( i = 0; i < mmcustom_count; i++ ) {
+             if ( mmcustom_complete [ i ].parent_cat && strcmp ( mmcustom_complete [ i ].parent_cat, whichparentarewe ) == 0  ) {
+               opts [ optmax++ ] = mmcustom_complete [ i ].cat;
+             }
+           }
+
+         }
+
+         // add FD categories
+         while ( 1 ) {
+
+           if ( ! freedesktop_complete [ i ].cat ) {
+             break;
+           }
+
+           if ( ( freedesktop_complete [ i ].parent_cat ) &&
+                ( strcasecmp ( freedesktop_complete [ i ].parent_cat, whichparentarewe ) == 0 )
+              )
+           {
+             opts [ optmax++ ] = freedesktop_complete [ i ].cat;
+           }
+
+           i++;
+         } // while
+
+         char prompt [ 101 ];
+         //snprintf ( prompt, 100, "Currently: %s", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory" );
+         snprintf ( prompt, 100, "%s [%s]", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory", whichparentarewe );
+
+         int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select subcategory"*/, "Enter to select; other to skip." );
+
+         if ( sel >= 0 ) {
+           char confirm [ 1001 ];
+           snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
+
+           if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm sub-categorization", "Do not set sub-category" ) == 1 ) {
+             ovr_replace_or_add ( a, "maincategorysub1", opts [ sel ] );
+             rescan_apps++;
+           }
+
+         }
+
+         if ( mmcustom_is_ready() ) {
+           mmcustom_shutdown();
+         }
+
+       }
+       break;
+
+      case context_app_rename:
+       {
+         char namebuf [ 101 ];
+         unsigned char changed;
+
+         changed = ui_menu_get_text_line ( "Rename application", "Use keyboard; Enter when done.",
+                                           a -> ref -> title_en ? a -> ref -> title_en : "blank", namebuf, 30, 0 /* alphanumeric */ );
+
+         if ( changed ) {
+           char confirm [ 1001 ];
+           snprintf ( confirm, 1000, "Confirm: %s", namebuf );
+
+           if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm rename", "Do not rename" ) == 1 ) {
+             ovr_replace_or_add ( a, "title", namebuf );
+             rescan_apps++;
+           }
+
+         }
+
+       }
+
+       break;
+
+      case context_app_cpuspeed:
+       {
+         char namebuf [ 101 ];
+         unsigned char changed;
+
+         changed = ui_menu_get_text_line ( "Specify runspeed", "Use keyboard; Enter when done.",
+                                           a -> ref -> clockspeed ? a -> ref -> clockspeed : "500", namebuf, 6, 1 /* numeric */ );
+
+         if ( changed ) {
+           char confirm [ 1001 ];
+           snprintf ( confirm, 1000, "Confirm: %s", namebuf );
+
+           if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm clockspeed", "Do not set" ) == 1 ) {
+             ovr_replace_or_add ( a, "clockspeed", namebuf );
+             rescan_apps++;
+           }
+
+         }
+
+       }
+
+       break;
+
+      case context_app_run:
+       ui_push_exec();
+       break;
+
+      case context_app_notes1:
+      case context_app_notes2:
+      case context_app_notes3:
+       {
+         char namebuf [ 101 ] = "";
+
+         char key [ 501 ];
+         unsigned char notenum;
+
+         // which note line?
+         if ( menu [ sel ] == context_app_notes1 ) {
+           notenum = 1;
+         } else if ( menu [ sel ] == context_app_notes2 ) {
+           notenum = 2;
+         } else if ( menu [ sel ] == context_app_notes3 ) {
+           notenum = 3;
+         }
+
+         // figure out key for looking up existing, and for storing replacement
+         snprintf ( key, 500, "Application-%u.note-%u", a -> ref -> subapp_number, notenum );
+
+         // do we have existing value?
+         if ( a -> ovrh ) {
+           char *existing = pnd_conf_get_as_char ( a -> ovrh, key );
+           if ( existing ) {
+             strncpy ( namebuf, existing, 100 );
+           }
+         }
+
+         unsigned char changed;
+
+         changed = ui_menu_get_text_line ( "Enter replacement note", "Use keyboard; Enter when done.",
+                                           namebuf, namebuf, 30, 0 /* not-numeric-forced */ );
+
+         if ( changed ) {
+           ovr_replace_or_add ( a, strchr ( key, '.' ) + 1, namebuf );
+           rescan_apps++;
+         }
+
+       }
+       break;
+
+      default:
+       return;
+
+      } // switch
+
+    } // if useful return
+
+  } // menu is alive?
+
+  // rescan apps?
+  if ( rescan_apps ) {
+    applications_free();
+    applications_scan();
+  }
+
+  return;
+}
+
+unsigned char ui_menu_oneby ( char *title, char *footer, char *one ) {
+  char *opts [ 2 ];
+  opts [ 0 ] = one;
+  int sel = ui_modal_single_menu ( opts, 1, title, footer );
+  if ( sel < 0 ) {
+    return ( 0 );
+  }
+  return ( sel + 1 );
+}
+
+unsigned char ui_menu_twoby ( char *title, char *footer, char *one, char *two ) {
+  char *opts [ 3 ];
+  opts [ 0 ] = one;
+  opts [ 1 ] = two;
+  int sel = ui_modal_single_menu ( opts, 2, title, footer );
+  if ( sel < 0 ) {
+    return ( 0 );
+  }
+  return ( sel + 1 );
+}
+
+unsigned char ui_menu_get_text_line ( char *title, char *footer, char *initialvalue,
+                                     char *r_buffer, unsigned char maxlen, unsigned char numbersonlyp )
+{
+  SDL_Rect rects [ 40 ];
+  SDL_Rect *dest = rects;
+  SDL_Rect src;
+  SDL_Surface *rtext;
+
+  char hacktext [ 1024 ];
+  unsigned char shifted = 0;
+
+  bzero ( rects, sizeof(SDL_Rect) * 40 );
+
+  if ( initialvalue ) {
+    if ( initialvalue == r_buffer ) {
+      // already good to go
+    } else {
+      strncpy ( r_buffer, initialvalue, maxlen );
+    }
+  } else {
+    bzero ( r_buffer, maxlen );
+  }
+
+  while ( 1 ) {
+
+    // clear
+    dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
+    dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
+    dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
+    dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
+    SDL_FillRect( sdl_realscreen, dest, 0 );
+
+    // show dialog background
+    if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
+      src.x = 0;
+      src.y = 0;
+      src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
+      src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
+      dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
+      dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
+      SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
+      dest++;
+    }
+
+    // show dialog frame
+    if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
+      dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
+      dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
+      SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
+      dest++;
+    }
+
+    // show header
+    if ( title ) {
+      rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
+      dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
+      dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
+      SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
+      SDL_FreeSurface ( rtext );
+      dest++;
+    }
+
+    // show footer
+    if ( footer ) {
+      rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
+      dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
+      dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
+       ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
+       - 60;
+      SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
+      SDL_FreeSurface ( rtext );
+      dest++;
+    }
+
+    // show text line - and embed cursor
+    dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
+    dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( 0/*i*/ + 1 - 0/*first_visible*/ ) );
+
+    strncpy ( hacktext, r_buffer, 1000 );
+    strncat ( hacktext, "\n", 1000 ); // add [] in most fonts
+
+    rtext = TTF_RenderText_Blended ( g_tab_font, hacktext, ui_display_context.fontcolor );
+    SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
+    SDL_FreeSurface ( rtext );
+    dest++;
+
+    // update all the rects and send it all to sdl
+    SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
+    dest = rects;
+
+    // check for input
+    SDL_Event event;
+    while ( SDL_WaitEvent ( &event ) ) {
+
+      switch ( event.type ) {
+
+      case SDL_KEYUP:
+       if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
+         shifted = 0;
+       }
+       break;
+
+      case SDL_KEYDOWN:
+
+       if ( event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_BACKSPACE ) {
+         if ( strlen ( r_buffer ) > 0 ) {
+           char *eol = strchr ( r_buffer, '\0' );
+           *( eol - 1 ) = '\0';
+         }
+
+       } else if ( event.key.keysym.sym == SDLK_UP ) {
+         r_buffer [ 0 ] = '\0'; // truncate!
+
+       } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
+         // on Enter/Return or B, if the buffer has 1 or more chars, we return it as valid.. otherwise, invalid.
+         if ( strlen ( r_buffer ) > 0 ) {
+           return ( 1 );
+         }
+         return ( 0 );
+
+       } else if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
+         shifted = 1;
+
+       } else if ( event.key.keysym.sym == SDLK_ESCAPE ||
+                   event.key.keysym.sym == SDLK_PAGEUP ||
+                   event.key.keysym.sym == SDLK_PAGEDOWN ||
+                   event.key.keysym.sym == SDLK_HOME
+                 )
+       {
+         return ( 0 );
+
+       } else {
+
+         if ( isprint(event.key.keysym.sym) ) {
+
+           unsigned char good = 1;
+
+           if ( numbersonlyp && ( ! isdigit(event.key.keysym.sym) ) ) {
+             good = 0;
+           }
+
+           if ( maxlen && strlen(r_buffer) >= maxlen ) {
+             good = 0;
+           }
+
+           if ( good ) {
+             char b [ 2 ] = { '\0', '\0' };
+             if ( shifted ) {
+               b [ 0 ] = toupper ( event.key.keysym.sym );
+             } else {
+               b [ 0 ] = event.key.keysym.sym;
+             }
+             strncat ( r_buffer, b, maxlen );
+           } // good?
+
+         } // printable?
+
+       }
+
+       break;
+
+      } // switch
+
+      break;
+
+    } // while waiting for input
+
+  } // while
+  
+  return ( 0 );
+}
+
+unsigned char ovr_replace_or_add ( mm_appref_t *a, char *keybase, char *newvalue ) {
+  //printf ( "setting %s:%u - '%s' to '%s' - %s/%s\n", a -> ref -> title_en, a -> ref -> subapp_number, keybase, newvalue, a -> ref -> object_path, a -> ref -> object_filename );
+
+  char fullpath [ PATH_MAX ];
+
+  sprintf ( fullpath, "%s/%s", a -> ref -> object_path, a -> ref -> object_filename );
+  char *dot = strrchr ( fullpath, '.' );
+  if ( dot ) {
+    sprintf ( dot, PXML_SAMEPATH_OVERRIDE_FILEEXT );
+  } else {
+    pnd_log ( pndn_error, "ERROR: Bad pnd-path in disco_t! %s\n", fullpath );
+    return ( 0 );
+  }
+
+  struct stat statbuf;
+
+  if ( stat ( fullpath, &statbuf ) == 0 ) {
+    // file exists
+    pnd_conf_handle h;
+
+    h = pnd_conf_fetch_by_path ( fullpath );
+
+    if ( ! h ) {
+      return ( 0 ); // fail!
+    }
+
+    char key [ 101 ];
+    snprintf ( key, 100, "Application-%u.%s", a -> ref -> subapp_number, keybase );
+
+    pnd_conf_set_char ( h, key, newvalue );
+
+    return ( pnd_conf_write ( h, fullpath ) );
+
+  } else {
+    // file needs to be created - easy!
+
+    FILE *f = fopen ( fullpath, "w" );
+
+    if ( f ) {
+      fprintf ( f, "Application-%u.%s\t%s\n", a -> ref -> subapp_number, keybase, newvalue );
+      fclose ( f );
+
+    } else {
+      return ( 0 ); // fail!
+    }
+
+  } // new or used?
+
+  return ( 1 );
+}
+
+void ui_manage_categories ( void ) {
+  unsigned char require_app_scan = 0;
+
+  if ( ! mmcustom_setup() ) {
+    return; // error
+  }
+
+  char *opts [ 20 ] = {
+    "List custom categories",
+    "List custom subcategories",
+    "Register custom category",
+    "Register custom subcategory",
+    "Unregister custom category",
+    "Unregister custom subcategory",
+    "Done"
+  };
+
+  while ( 1 ) {
+
+    int sel = ui_modal_single_menu ( opts, 7, "Custom Categories", "B to select; other to cancel." );
+
+    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." );
+      }
+      break;
+
+    case 1: // list custom sub
+      if ( mmcustom_count ) {
+
+       char *maincat = ui_pick_custom_category ( 0 );
+
+       if ( maincat ) {
+         unsigned int subcount = mmcustom_count_subcats ( maincat );
+         char titlebuf [ 201 ];
+
+         snprintf ( titlebuf, 200, "Category: %s", maincat );
+
+         if ( subcount == 0 ) {
+           ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
+         } else {
+
+           char **list = malloc ( subcount * sizeof(char*) );
+           int i;
+           unsigned int counter = 0;
+
+           for ( i = 0; i < mmcustom_count; i++ ) {
+             if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
+               list [ counter++ ] = mmcustom_complete [ i ].cat;
+             }
+           }
+
+           ui_modal_single_menu ( list, counter, titlebuf, "Any button to exit." );
+
+           free ( list );
+
+         } // more than 0 subcats?
+
+       } // user picked a main cat?
+
+      } else {
+       ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
+      }
+      break;
+
+    case 2: // register custom
+      {
+       unsigned char changed;
+       char namebuf [ 101 ] = "";
+
+       changed = ui_menu_get_text_line ( "Enter unique category name", "Use keyboard; Enter when done.",
+                                         "Pandora", namebuf, 30, 0 /* alphanumeric */ );
+
+       // did the user enter something?
+       if ( changed ) {
+
+         // 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." );
+         } else if ( freedesktop_category_query ( namebuf, NULL ) ) {
+           ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard category." );
+         } else {
+
+           char confirm [ 1001 ];
+           snprintf ( confirm, 1000, "Confirm: %s", namebuf );
+
+           if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
+             // register, save, recycle the current list
+             mmcustom_register ( namebuf, NULL );
+             mmcustom_write ( NULL );
+             mmcustom_shutdown();
+             mmcustom_setup();
+           }
+
+         } // dupe?
+
+       } // entered something?
+
+      }
+      break;
+
+    case 3: // register custom sub
+      if ( 1 /*mmcustom_count -- we allow FD cats now, so this isn't applicable error */ ) {
+
+       char *maincat = ui_pick_custom_category ( 1 /* include FD */ );
+
+       if ( maincat ) {
+         char titlebuf [ 201 ];
+
+         snprintf ( titlebuf, 200, "Subcat of: %s", maincat );
+
+         unsigned char changed;
+         char namebuf [ 101 ] = "";
+
+         changed = ui_menu_get_text_line ( titlebuf, "Use keyboard; Enter when done.", "Submarine", namebuf, 30, 0 /* alphanumeric */ );
+
+         // did the user enter something?
+         if ( changed ) {
+
+           // 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." );
+           } else if ( freedesktop_category_query ( namebuf, maincat ) ) {
+             ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard subcategory." );
+           } else {
+
+             char confirm [ 1001 ];
+             snprintf ( confirm, 1000, "Confirm: %s [%s]", namebuf, maincat );
+
+             if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
+               // register, save, recycle the current list
+               mmcustom_register ( namebuf, maincat );
+               mmcustom_write ( NULL );
+               mmcustom_shutdown();
+               mmcustom_setup();
+             }
+
+           } // dupe?
+
+         } // entered something?
+
+       } // selected parent cat?
+
+      } else {
+       ui_menu_oneby ( "Warning", "B/Enter to accept", "No categories registered." );
+      }
+      break;
+
+    case 4: // unreg custom
+      if ( mmcustom_count ) {
+       char *maincat = ui_pick_custom_category ( 0 );
+
+       if ( maincat ) {
+         char confirm [ 1001 ];
+         snprintf ( confirm, 1000, "Confirm remove: %s", maincat );
+
+         if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
+           // register, save, recycle the current list
+           mmcustom_unregister ( maincat, NULL );
+           mmcustom_write ( NULL );
+           mmcustom_shutdown();
+           mmcustom_setup();
+         }
+
+       } // picked?
+
+      } else {
+       ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
+      }
+      break;
+
+    case 5: // unreg custom sub
+      if ( mmcustom_count ) {
+       char *maincat = ui_pick_custom_category ( 0 );
+
+       if ( maincat ) {
+         unsigned int subcount = mmcustom_count_subcats ( maincat );
+         char titlebuf [ 201 ];
+
+         snprintf ( titlebuf, 200, "Category: %s", maincat );
+
+         if ( subcount == 0 ) {
+           ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
+         } else {
+
+           char **list = malloc ( subcount * sizeof(char*) );
+           int i;
+           unsigned int counter = 0;
+
+           for ( i = 0; i < mmcustom_count; i++ ) {
+             if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
+               list [ counter++ ] = mmcustom_complete [ i ].cat;
+             }
+           }
+
+           int sel = ui_modal_single_menu ( list, counter, titlebuf, "B to selct; other to exit." );
+
+           if ( sel >= 0 ) {
+             char confirm [ 1001 ];
+             snprintf ( confirm, 1000, "Confirm remove: %s", list [ sel ] );
+
+             if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
+               // register, save, recycle the current list
+               mmcustom_unregister ( list [ sel ], maincat );
+               mmcustom_write ( NULL );
+               mmcustom_shutdown();
+               mmcustom_setup();
+             }
+
+           } // confirm kill?
+
+           free ( list );
+
+         } // more than 0 subcats?
+
+       } // user picked a main cat?
+
+      } else {
+       ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
+      }
+      break;
+
+    } // switch
+
+    // exeunt
+    if ( sel < 0 || sel > 5 ) {
+      break;
+    }
+
+  } // while running the menu
+
+  // shut down custom cats
+  mmcustom_shutdown();
+
+  // reload apps?
+  if ( require_app_scan ) {
+    applications_free();
+    applications_scan();
+  }
+
+  // redraw
+  render_mask |= CHANGED_EVERYTHING;
+
+  return;
+}
+
+char *ui_pick_custom_category ( unsigned char include_fd ) {
+  char **list;
+  int i;
+  unsigned int counter = 0;
+
+  if ( include_fd ) {
+    list = malloc ( (mmcustom_count+freedesktop_count()) * sizeof(char*) );
+  } else {
+    list = malloc ( mmcustom_count * sizeof(char*) );
+  }
+
+  // add custom
+  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 ) {
+    i = 3;
+    while ( 1 ) {
+
+      if ( ! freedesktop_complete [ i ].cat ) {
+       break;
+      }
+
+      if ( freedesktop_complete [ i ].parent_cat == NULL ) {
+       list [ counter++ ] = freedesktop_complete [ i ].cat;
+      }
+
+      i++;
+    } // while
+  } // if
+
+  int sel = ui_modal_single_menu ( list, counter, "Custom Main Categories", "Any button to exit." );
+
+  if ( sel < 0 ) {
+    free ( list );
+    return ( NULL );
+  }
+
+  char *foo = list [ sel ];
+  free ( list );
+
+  return ( foo );
+}