pndnotifyd: fix some crashes
[pandora-libraries.git] / minimenu / mmconf.c
index d0db0ba..f64675e 100644 (file)
@@ -1,7 +1,7 @@
 
+#define __USE_GNU /* for strndup */
 #include <stdio.h>
 #include <limits.h> /* for PATH_MAX */
-#define __USE_GNU /* for strndup */
 #include <string.h> /* for strdup */
 
 #include "SDL.h"
@@ -11,6 +11,8 @@
 #include "pnd_container.h"
 #include "pnd_conf.h"
 #include "pnd_discovery.h"
+#include "pnd_notify.h"
+#include "pnd_dbusnotify.h"
 
 #include "mmenu.h"
 #include "mmconf.h"
@@ -31,10 +33,13 @@ confitem_t page_general[] = {
   { "Show 'All' tab",                "Whethor an All tab is shown or not",                      "1",                "categories.do_all_cat",   ct_boolean },
   { "Show directory browser tabs",   "Show a tab for each SD card?",                            "0",                "filesystem.do_browser",   ct_boolean },
   { "Detail panel on start?",        "Show or hide the detail panel when menu starts",          "1",                "display.show_detail_pane", ct_boolean },
+  { "Default list view not icons?",  "Normally we default to icons view not list",              "0",                "display.viewmode_list",   ct_boolean },
   { "Sub-categories as folders?",    "If no, uses tabs instead of folders within tabs.",        "1",                "tabs.subcat_as_folders",  ct_boolean },
-  { "Start with app selected",       "Whethor selection is placed by default or not",           "0",                "minimenu.start_selected", ct_boolean },
+  { "Sub-category apps in their main cat?","If no, apps with subcategories are only in subcategories","1",          "tabs.subcat_to_parent",   ct_boolean },
+  { "Remember selected app",         "On return to menu select previous app; default to selected", "1",             "minimenu.start_selected", ct_boolean },
   { "Auto discover pnd apps?",       "If no, turn on diectory browser to manually find apps",   "1",                "filesystem.do_pnd_disco", ct_boolean },
-  { "Keep bad categories in Other?", "Lazy dev! Put broken categories into Other to keep clean", "1",               "categories.good_cats_only", ct_boolean },
+  // dropped option -- we now strictly enforce free desktop categories (or user defined, but no more bogus PXML categories)
+  //    { "Keep bad categories in Other?", "Lazy dev! Put broken categories into Other to keep clean", "1",               "categories.good_cats_only", ct_boolean },
   { "Set CPU speed when leaving",    "Whether the next setting is applied or not",              "0",                "minimenu.use_run_speed",  ct_boolean },
   { "CPU speed when leaving",        "Before running app, set this speed; app may override.",   "500",              "minimenu.run_speed",      ct_cpu_speed },
   { "Wrap tab change",               "Changing tab left or right, does it wrap around?",        "0",                "tabs.wraparound",         ct_boolean },
@@ -62,6 +67,8 @@ confitem_t pages[] = {
   { "General Options",           "Miscellaneous handy options",                             NULL /* default */, NULL,                      ct_switch_page, page_general },
   { "Show/Hide Applications",    "Each application can be hidden/revealed",                 NULL /* default */, NULL,                      ct_switch_page, page_appshowhide },
   { "Show/Hide/Order Tabs",      "Each tab can be hidden/revealed or re-ordered",           NULL /* default */, NULL,                      ct_switch_page, page_tabshowhide },
+  { "Manage Custom Categories",  "Can make your own categories/tabs",                       NULL /* default */, NULL,                      ct_go_manage_categories },
+  { "Select a Minimenu Skin",    "Download alternate look and feels!",                      NULL /* default */, NULL,                      ct_go_manage_skins },
   { "",                          "",                                                        NULL,               NULL,                      ct_nil },
   { "Exit configuration",        "Quit and save configuration",                             NULL /* default */, NULL,                      ct_exit },
   { "",                          "",                                                        NULL,               NULL,                      ct_nil },
@@ -220,6 +227,8 @@ unsigned char conf_run_menu ( confitem_t *toplevel ) {
            break;
 
          case ct_nil:
+         case ct_go_manage_categories:
+         case ct_go_manage_skins:
          case ct_switch_page:
          case ct_reset:
          case ct_exit:
@@ -249,6 +258,14 @@ unsigned char conf_run_menu ( confitem_t *toplevel ) {
            page = page [ sel ].newhead;
            sel = 0; // should use a stack..
            break;
+         case ct_go_manage_categories:
+           ui_manage_categories();
+           break;
+         case ct_go_manage_skins:
+           if ( ui_pick_skin() ) {
+             emit_and_quit ( MM_RESTART );
+           }
+           break;
          case ct_filename:
            break;
          case ct_nil:
@@ -369,6 +386,8 @@ void conf_display_page ( confitem_t *page, unsigned int selitem, unsigned int fi
       break;
     case ct_exit:
       break;
+    case ct_go_manage_categories:
+    case ct_go_manage_skins:
     case ct_nil:
       break;
     } // switch
@@ -405,6 +424,8 @@ void conf_display_page ( confitem_t *page, unsigned int selitem, unsigned int fi
     case ct_reset:
     case ct_exit:
     case ct_visible_tab_list:
+    case ct_go_manage_categories:
+    case ct_go_manage_skins:
       break;
     } // switch
 
@@ -509,6 +530,8 @@ char *conf_format_int ( int v, change_type_e c ) {
   case ct_switch_page:
   case ct_visible_tab_list:
   case ct_nil:
+  case ct_go_manage_categories:
+  case ct_go_manage_skins:
     break;
 
   } // switch
@@ -569,6 +592,7 @@ unsigned char conf_prepare_page ( confitem_t *page ) {
       unsigned int i;
       char catname [ 512 ];
       char *actual_catname;
+      char finalbuf [ 101 ];
 
       for ( i = 0;  i < g_categorycount; i++ ) {
 
@@ -587,7 +611,13 @@ unsigned char conf_prepare_page ( confitem_t *page ) {
          continue;
        }
 
-       p -> text = strndup ( actual_catname, 40 );
+       if ( g_categories [ i ] -> parent_catname ) {
+         snprintf ( finalbuf, 100, "%s [%s]", actual_catname, g_categories [ i ] -> parent_catname );
+       } else {
+         strncpy ( finalbuf, actual_catname, 100 );
+       }
+
+       p -> text = strndup ( finalbuf, 40 );
        p -> desc = NULL;
        p -> def = NULL;
 
@@ -653,7 +683,7 @@ unsigned char conf_write ( pnd_conf_handle h, char *fullpath ) {
     // does item begin with app or tab tag?
     char *k = pnd_box_get_key ( v );
 
-    if ( k && 
+    if ( k &&
         ( strncasecmp ( k, "appshow.", 8 ) == 0 ||
           strncasecmp ( k, "tabshow.", 8 ) == 0 )
        )
@@ -664,6 +694,22 @@ unsigned char conf_write ( pnd_conf_handle h, char *fullpath ) {
     v = pnd_box_get_next ( v );
   } // while
 
+  // really, should write out keys that are not found in the conf items..
+  // but since g_conf is merged with other conf files, that may just
+  // make for big dumps erroneously.. hmm :/
+  char *previous_unique_id = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_app_uid" );
+  char *lastcat = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_catname" );
+  char *lastparentcat = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_parentcatname" );
+  if ( previous_unique_id ) {
+    fprintf ( f, "%s\t%s\n", "minimenu.last_known_app_uid", previous_unique_id );
+  }
+  if ( lastcat ) {
+    fprintf ( f, "%s\t%s\n", "minimenu.last_known_catname", lastcat );
+  }
+  if ( lastparentcat ) {
+    fprintf ( f, "%s\t%s\n", "minimenu.last_known_parentcatname", lastparentcat );
+  }
+
   fclose ( f );
 
   return ( 1 );
@@ -789,7 +835,7 @@ void conf_reset_to_default ( pnd_conf_handle h ) {
     // does item begin with app or tab tag?
     char *k = pnd_box_get_key ( v );
 
-    if ( k && 
+    if ( k &&
         ( strncasecmp ( k, "appshow.", 8 ) == 0 ||
           strncasecmp ( k, "tabshow.", 8 ) == 0 )
        )