mininmenu fix -- tablineR will always be used on far right, not 'just right of select...
[pandora-libraries.git] / minimenu / mmenu.c
index 4a649c0..23dfeb8 100644 (file)
@@ -50,7 +50,7 @@
 #include "mmcat.h"
 #include "mmui.h"
 
-pnd_box_handle *g_active_apps = NULL;
+pnd_box_handle g_active_apps = NULL;
 unsigned int g_active_appcount = 0;
 char g_username [ 128 ]; // since we have to wait for login (!!), store username here
 pnd_conf_handle g_conf = 0;
@@ -59,6 +59,7 @@ pnd_conf_handle g_desktopconf = 0;
 char *pnd_run_script = NULL;
 char *g_skinpath = NULL;
 unsigned char g_x11_present = 1; // >0 if X is present
+unsigned char g_catmap = 0; // if 1, we're doing category mapping
 
 int main ( int argc, char *argv[] ) {
   int logall = -1; // -1 means normal logging rules; >=0 means log all!
@@ -240,15 +241,120 @@ int main ( int argc, char *argv[] ) {
     emit_and_quit ( MM_QUIT );
   }
 
+  // create all cat
+  if ( pnd_conf_get_as_int_d ( g_conf, "categories.do_all_cat", 1 ) ) {
+    category_push ( g_x11_present ? CATEGORY_ALL "    (X11)" : CATEGORY_ALL "   (No X11)", NULL );
+  }
+
+  // set up category mappings
+  if ( pnd_conf_get_as_int_d ( g_conf, "categories.map_on", 0 ) ) {
+    g_catmap = category_map_setup();
+  }
+
   /* inhale applications, icons, categories, etc
    */
+  applications_scan();
+
+  /* actual work now
+   */
+
+  while ( 1 ) { // forever!
+
+    // show the menu, or changes thereof
+    ui_render ( CHANGED_NOTHING );
+
+    // wait for input or time-based events (like animations)
+    // deal with inputs
+    ui_process_input ( 1 /* block */ );
+
+    // sleep? block?
+    usleep ( 5000 );
+
+  } // while
+
+  return ( 0 );
+}
+
+void emit_and_quit ( char *s ) {
+  printf ( "%s\n", s );
+  exit ( 0 );
+}
+
+void applications_free ( void ) {
+
+  // free up all our category apprefs, but keep the preview and icon cache's..
+  category_freeall();
+
+  // free up old disco_t
+  if ( g_active_apps ) {
+    pnd_disco_t *p = pnd_box_get_head ( g_active_apps );
+    pnd_disco_t *n;
+    while ( p ) {
+      n = pnd_box_get_next ( p );
+      pnd_disco_destroy ( p );
+      p = n;
+    }
+    pnd_box_delete ( g_active_apps );
+  }
+
+  return;
+}
+
+void applications_scan ( void ) {
 
   // show disco screen
   ui_discoverscreen ( 1 /* clear screen */ );
 
   // determine current app list, cache icons
-  pnd_log ( pndn_debug, "Looking for pnd applications here: %s\n", pnd_conf_get_as_char ( g_desktopconf, "desktop.searchpath" ) );
-  g_active_apps = pnd_disco_search ( pnd_conf_get_as_char ( g_desktopconf, "desktop.searchpath" ), NULL ); // ignore overrides for now
+  // - ignore overrides for now
+
+  g_active_apps = 0;
+  pnd_box_handle merge_apps = 0;
+
+  // desktop apps?
+  if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.desktop_apps", 1 ) ) {
+    pnd_log ( pndn_debug, "Looking for pnd applications here: %s\n",
+             pnd_conf_get_as_char ( g_desktopconf, "desktop.searchpath" ) );
+    g_active_apps = pnd_disco_search ( pnd_conf_get_as_char ( g_desktopconf, "desktop.searchpath" ), NULL );
+  }
+
+  // menu apps?
+  if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.menu_apps", 1 ) ) {
+    pnd_log ( pndn_debug, "Looking for pnd applications here: %s\n",
+             pnd_conf_get_as_char ( g_desktopconf, "menu.searchpath" ) );
+    merge_apps = pnd_disco_search ( pnd_conf_get_as_char ( g_desktopconf, "menu.searchpath" ), NULL );
+  }
+
+  // merge lists
+  if ( merge_apps ) {
+    if ( g_active_apps ) {
+      // got menu apps, and got desktop apps, merge
+      pnd_box_append ( g_active_apps, merge_apps );
+    } else {
+      // got menu apps, had no desktop apps, so just assign
+      g_active_apps = merge_apps;
+    }
+  }
+
+  // aux apps?
+  char *aux_apps = NULL;
+  merge_apps = 0;
+  aux_apps = pnd_conf_get_as_char ( g_conf, "minimenu.aux_searchpath" );
+  if ( aux_apps && aux_apps [ 0 ] ) {
+    pnd_log ( pndn_debug, "Looking for pnd applications here: %s\n", aux_apps );
+    merge_apps = pnd_disco_search ( aux_apps, NULL );
+  }
+
+  // merge aux apps
+  if ( merge_apps ) {
+    if ( g_active_apps ) {
+      pnd_box_append ( g_active_apps, merge_apps );
+    } else {
+      g_active_apps = merge_apps;
+    }
+  }
+
+  // do it
   g_active_appcount = pnd_box_get_size ( g_active_apps );
 
   unsigned char maxwidth, maxheight;
@@ -260,17 +366,23 @@ int main ( int argc, char *argv[] ) {
 
   pnd_log ( pndn_debug, "Found pnd applications, and caching icons:\n" );
   pnd_disco_t *iter = pnd_box_get_head ( g_active_apps );
+  unsigned int itercount = 0;
   while ( iter ) {
     //pnd_log ( pndn_debug, "  App: '%s'\n", IFNULL(iter->title_en,"No Name") );
 
     // update cachescreen
-    ui_cachescreen ( 1 /* clear screen */, IFNULL(iter->title_en,"No Name") );
+    // ... every 5 filenames, just to avoid slowing it too much
+    if ( itercount % 5 == 0 ) {
+      ui_cachescreen ( 0 /* clear screen */, IFNULL(iter->title_en,"No Name") );
+    }
 
-    // cache the icon
-    if ( iter -> pnd_icon_pos &&
-        ! cache_icon ( iter, maxwidth, maxheight ) )
-    {
-      pnd_log ( pndn_warning, "  Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
+    // cache the icon, unless deferred
+    if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 0 ) {
+      if ( iter -> pnd_icon_pos &&
+          ! cache_icon ( iter, maxwidth, maxheight ) )
+      {
+       pnd_log ( pndn_warning, "  Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
+      }
     }
 
     // cache the preview --> SHOULD DEFER
@@ -292,44 +404,46 @@ int main ( int argc, char *argv[] ) {
 
       // push to All category
       // we do this first, so first category is always All
-      if ( ! category_push ( g_x11_present ? CATEGORY_ALL "    (X11)" : CATEGORY_ALL "   (No X11)", iter ) ) {
-       pnd_log ( pndn_warning, "  Couldn't categorize to All: '%s'\n", IFNULL(iter -> title_en, "No Name") );
-      }
+      if ( pnd_conf_get_as_int_d ( g_conf, "categories.do_all_cat", 1 ) ) {
+       if ( ! category_push ( g_x11_present ? CATEGORY_ALL "    (X11)" : CATEGORY_ALL "   (No X11)", iter ) ) {
+         pnd_log ( pndn_warning, "  Couldn't categorize to All: '%s'\n", IFNULL(iter -> title_en, "No Name") );
+       }
+      } // all?
 
       // main categories
       if ( iter -> main_category && pnd_conf_get_as_int_d ( g_conf, "tabs.top_maincat", 1 ) ) {
-       if ( ! category_push ( iter -> main_category, iter ) ) {
+       if ( ! category_meta_push ( iter -> main_category, iter ) ) {
          pnd_log ( pndn_warning, "  Couldn't categorize to %s: '%s'\n", iter -> main_category, IFNULL(iter -> title_en, "No Name") );
        }
       }
 
       if ( iter -> main_category1 && pnd_conf_get_as_int_d ( g_conf, "tabs.top_maincat1", 0 ) ) {
-       if ( ! category_push ( iter -> main_category1, iter ) ) {
+       if ( ! category_meta_push ( iter -> main_category1, iter ) ) {
          pnd_log ( pndn_warning, "  Couldn't categorize to %s: '%s'\n", iter -> main_category1, IFNULL(iter -> title_en, "No Name") );
        }
       }
 
       if ( iter -> main_category2 && pnd_conf_get_as_int_d ( g_conf, "tabs.top_maincat2", 0 ) ) {
-       if ( ! category_push ( iter -> main_category2, iter ) ) {
+       if ( ! category_meta_push ( iter -> main_category2, iter ) ) {
          pnd_log ( pndn_warning, "  Couldn't categorize to %s: '%s'\n", iter -> main_category2, IFNULL(iter -> title_en, "No Name") );
        }
       }
 
       // alt categories
       if ( iter -> alt_category && pnd_conf_get_as_int_d ( g_conf, "tabs.top_altcat", 0 ) ) {
-       if ( ! category_push ( iter -> alt_category, iter ) ) {
+       if ( ! category_meta_push ( iter -> alt_category, iter ) ) {
          pnd_log ( pndn_warning, "  Couldn't categorize to %s: '%s'\n", iter -> alt_category, IFNULL(iter -> title_en, "No Name") );
        }
       }
 
       if ( iter -> alt_category1 && pnd_conf_get_as_int_d ( g_conf, "tabs.top_altcat1", 0 ) ) {
-       if ( ! category_push ( iter -> alt_category1, iter ) ) {
+       if ( ! category_meta_push ( iter -> alt_category1, iter ) ) {
          pnd_log ( pndn_warning, "  Couldn't categorize to %s: '%s'\n", iter -> alt_category1, IFNULL(iter -> title_en, "No Name") );
        }
       }
 
       if ( iter -> alt_category2 && pnd_conf_get_as_int_d ( g_conf, "tabs.top_altcat2", 0 ) ) {
-       if ( ! category_push ( iter -> alt_category2, iter ) ) {
+       if ( ! category_meta_push ( iter -> alt_category2, iter ) ) {
          pnd_log ( pndn_warning, "  Couldn't categorize to %s: '%s'\n", iter -> alt_category2, IFNULL(iter -> title_en, "No Name") );
        }
       }
@@ -338,32 +452,14 @@ int main ( int argc, char *argv[] ) {
 
     // next
     iter = pnd_box_get_next ( iter );
+    itercount++;
   } // while
 
   // dump categories
   //category_dump();
 
-  /* actual work now
-   */
-
-  while ( 1 ) { // forever!
-
-    // show the menu, or changes thereof
-    ui_render ( CHANGED_NOTHING );
-
-    // wait for input or time-based events (like animations)
-    // deal with inputs
-    ui_process_input ( 1 /* block */ );
-
-    // sleep? block?
-    usleep ( 5000 );
-
-  } // while
-
-  return ( 0 );
-}
+  // let deferred icon cache go now
+  ui_post_scan();
 
-void emit_and_quit ( char *s ) {
-  printf ( "%s\n", s );
-  exit ( 0 );
+  return;
 }