Added category mapping support to mmenu .. lets user define what categories to have...
authorskeezix <skeezix@flotsam-vm.(none)>
Mon, 22 Mar 2010 20:38:19 +0000 (16:38 -0400)
committerskeezix <skeezix@flotsam-vm.(none)>
Mon, 22 Mar 2010 20:38:19 +0000 (16:38 -0400)
deployment/etc/pandora/conf/mmenu.conf
minimenu/mmcat.c
minimenu/mmcat.h
minimenu/mmenu.c
minimenu/mmenu.conf

index 3e67c3f..f15336b 100644 (file)
@@ -1,6 +1,9 @@
 # for the mmenu 'minimenu'
 #
 
+# Note that you can perform icon name, clockspeed setting and category overrides via an .ovr file
+# Note that the icon can be overridden for a pnd-file by making a same-name .png file, in the same location
+
 [minimenu]
 static_art_searchpath  /etc/pandora/mmenu/skins/default:./minimenu/skin/default
 font                   Vera.ttf
@@ -123,3 +126,20 @@ IMG_PREVIEW_MISSING         pandora60.png
 IMG_ARROW_UP            arrowup.png
 IMG_ARROW_DOWN          arrowdown.png
 IMG_ARROW_SCROLLBAR     arrowscroller.png
+
+[categories]
+# Normally for mmenu, an encountered category is just used as is. 5 cats exist, you get 5 tabs.
+# If map_on is >0, then category transforms will occur
+#   @NEWCAT oldcat1:oldcat2     <- means oldcat1, if found, will map to NEWCAT. "@" is discarded.
+#   NOTE: FreeDesktop rules do not allow categories with spaces in the name; if needed, I can add it with quoting.
+# If map_default_on is set (>0), then any unmapped categories will be forced into the default category bucket (map_default_cat.)
+#   If map_default_on is off (=0), then unmapped categories will become their own categories as normal.
+#   Should probably still have an @ line to create the default category, since creating the cats comes before assigning defaults
+# NOTE: Individual app overrides occur at the time of app scanning, so before this category mapping occurs and thus is effected
+map_on                 0               # if >0, will do category mapping at all; if 0, don't do any of this.
+map_default_on         0               # if >0, any unmapped category will get forced to map_default_cat; set to 0 to leave unmapped cats alone
+map_default_cat                Spam            # see map_default_on
+# NOTE: List the categories in reverse order to how you wish them in the tab list; last one shows up as first tab
+@Woogle                        Audio
+@Jimmy                 Game
+@Spam
index eb63ad5..aede3ff 100644 (file)
@@ -8,6 +8,7 @@
 #include "pnd_pxml.h"
 #include "pnd_container.h"
 #include "pnd_discovery.h"
+#include "../lib/pnd_pathiter.h"
 
 #include "mmenu.h"
 #include "mmcache.h"
 mm_category_t g_categories [ MAX_CATS ];
 unsigned char g_categorycount = 0;
 
+mm_catmap_t g_catmaps [ MAX_CATS ];
+unsigned char g_catmapcount = 0;
+
+extern pnd_conf_handle g_conf;
+
 unsigned char category_push ( char *catname, pnd_disco_t *app ) {
   mm_category_t *c;
 
@@ -39,6 +45,10 @@ unsigned char category_push ( char *catname, pnd_disco_t *app ) {
     g_categorycount++;
   }
 
+  if ( ! app ) {
+    return ( 1 ); // create cat, but skip app
+  }
+
   // alloc and populate appref
   //
   mm_appref_t *ar = malloc ( sizeof(mm_appref_t) );
@@ -157,3 +167,79 @@ void category_freeall ( void ) {
 
   return;
 }
+
+unsigned char category_map_setup ( void ) {
+
+  char *searchpath = pnd_box_get_head ( g_conf );
+
+  if ( ! searchpath ) {
+    return ( 0 );
+  }
+
+  // look through conf for useful keys
+  while ( searchpath ) {
+    char *k = pnd_box_get_key ( searchpath );
+
+    // does this key look like a category mapping key?
+    if ( strncasecmp ( k, "categories.@", 12 ) == 0 ) {
+      k += 12;
+
+      // iterate across 'words' in v, assigning catmaps to them
+      SEARCHCHUNK_PRE
+      {
+       //pnd_log ( pndn_debug, "target(%s) from(%s)\n", k, buffer );
+
+       category_push ( k, NULL );
+       g_catmaps [ g_catmapcount ].target = category_query ( k );
+       g_catmaps [ g_catmapcount ].from = strdup ( buffer );
+       g_catmapcount++;
+
+      }
+      SEARCHCHUNK_POST
+
+    } // if key looks like catmap
+
+    searchpath = pnd_box_get_next ( searchpath );
+  } // while each conf key
+
+  return ( 1 );
+}
+
+mm_category_t *category_map_query ( char *cat ) {
+  unsigned char i;
+
+  for ( i = 0; i < g_catmapcount; i++ ) {
+    if ( strcasecmp ( g_catmaps [ i ].from, cat ) == 0 ) {
+      return ( g_catmaps [ i ].target );
+    }
+  }
+
+  return ( NULL );
+}
+
+unsigned char category_meta_push ( char *catname, pnd_disco_t *app ) {
+  mm_category_t *cat;
+
+  // do we honour cat mapping at all?
+  if ( pnd_conf_get_as_int_d ( g_conf, "categories.map_on", 0 ) ) {
+
+    // is this guy mapped?
+    cat = category_map_query ( catname );
+
+    if ( cat ) {
+      return ( category_push ( cat -> catname, app ) );
+    }
+
+    // not mapped.. but default?
+    if ( pnd_conf_get_as_int_d ( g_conf, "categories.map_default_on", 0 ) ) {
+      char *def = pnd_conf_get_as_char ( g_conf, "categories.map_default_cat" );
+      if ( def ) {
+       return ( category_push ( def, app ) );
+      }
+    }
+
+  } // cat map is desired?
+
+  // not default, just do it
+  return ( category_push ( catname, app ) );
+}
index 25f8eb1..bf78b86 100644 (file)
@@ -24,4 +24,14 @@ mm_category_t *category_query ( char *catname );
 void category_dump ( void ); // sort the apprefs
 void category_freeall ( void );
 
+// category mapping hack
+typedef struct {
+  mm_category_t *target;  // mapping a category _to_ this other category
+  char *from;             // from this category
+} mm_catmap_t;
+
+unsigned char category_map_setup ( void ); // set up the mappings
+mm_category_t *category_map_query ( char *cat );
+unsigned char category_meta_push ( char *catname, pnd_disco_t *app );
+
 #endif
index d62bb63..dec0d8b 100644 (file)
@@ -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,6 +241,14 @@ int main ( int argc, char *argv[] ) {
     emit_and_quit ( MM_QUIT );
   }
 
+  // create all cat
+  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();
@@ -399,38 +408,38 @@ void applications_scan ( void ) {
 
       // 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") );
        }
       }
index 18ee313..6ca6ca6 100644 (file)
@@ -1,6 +1,9 @@
 # for the mmenu 'minimenu'
 #
 
+# Note that you can perform icon name, clockspeed setting and category overrides via an .ovr file
+# Note that the icon can be overridden for a pnd-file by making a same-name .png file, in the same location
+
 [minimenu]
 static_art_searchpath  /etc/pandora/mmenu/skins/default:./minimenu/skin/default
 font                   Vera.ttf
@@ -123,3 +126,20 @@ IMG_PREVIEW_MISSING         pandora60.png
 IMG_ARROW_UP            arrowup.png
 IMG_ARROW_DOWN          arrowdown.png
 IMG_ARROW_SCROLLBAR     arrowscroller.png
+
+[categories]
+# Normally for mmenu, an encountered category is just used as is. 5 cats exist, you get 5 tabs.
+# If map_on is >0, then category transforms will occur
+#   @NEWCAT oldcat1:oldcat2     <- means oldcat1, if found, will map to NEWCAT. "@" is discarded.
+#   NOTE: FreeDesktop rules do not allow categories with spaces in the name; if needed, I can add it with quoting.
+# If map_default_on is set (>0), then any unmapped categories will be forced into the default category bucket (map_default_cat.)
+#   If map_default_on is off (=0), then unmapped categories will become their own categories as normal.
+#   Should probably still have an @ line to create the default category, since creating the cats comes before assigning defaults
+# NOTE: Individual app overrides occur at the time of app scanning, so before this category mapping occurs and thus is effected
+map_on                 0               # if >0, will do category mapping at all; if 0, don't do any of this.
+map_default_on         0               # if >0, any unmapped category will get forced to map_default_cat; set to 0 to leave unmapped cats alone
+map_default_cat                Spam            # see map_default_on
+# NOTE: List the categories in reverse order to how you wish them in the tab list; last one shows up as first tab
+@Woogle                        Audio
+@Jimmy                 Game
+@Spam