#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 */
{ 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
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
// 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;
}
"Reveal hidden category",
"Shutdown Pandora",
"Configure Minimenu",
+ "Manage custom app categories",
"Rescan for applications",
"Cache previews to SD now",
"Run a terminal/console",
"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 ) {
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;
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" );
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 );
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;
ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
}
- // redraw tabs
- render_mask |= CHANGED_CATEGORY;
}
- for ( i = 0; i < g_categorycount; i++ ) {
- free ( labels [ i ] );
- }
+ // republish categories
+ category_publish ( CFNORMAL, NULL );
+
+ // redraw tabs
+ render_mask |= CHANGED_CATEGORY;
return;
}
// write conf, so it will take next time
conf_write ( g_conf, conf_determine_location ( g_conf ) );
- // request rescan and wrap up
- rescan_apps++;
+ // 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
}
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 ) {
i++;
} // while
+ // picker
char prompt [ 101 ];
snprintf ( prompt, 100, "Pick category [%s]", a -> ref -> main_category ? a -> ref -> main_category : "NoParentCategory" );
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;
{
char *opts [ 250 ];
unsigned char optmax = 0;
- unsigned char i;
+ 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;
+ }
+ }
+
+ }
- i = 0;
+ // add FD categories
while ( 1 ) {
if ( ! freedesktop_complete [ i ].cat ) {
break;
}
- if ( freedesktop_complete [ i ].parent_cat ) {
+ if ( ( freedesktop_complete [ i ].parent_cat ) &&
+ ( strcasecmp ( freedesktop_complete [ i ].parent_cat, whichparentarewe ) == 0 )
+ )
+ {
opts [ optmax++ ] = freedesktop_complete [ i ].cat;
}
} // while
char prompt [ 101 ];
- snprintf ( prompt, 100, "Pick subcategory [%s]", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory" );
+ //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 ( mmcustom_is_ready() ) {
+ mmcustom_shutdown();
+ }
+
}
break;
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;
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"
- return ( 1 );
+ // 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;
}
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 );
+ //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 ];
if ( dot ) {
sprintf ( dot, PXML_SAMEPATH_OVERRIDE_FILEEXT );
} else {
- fprintf ( stderr, "ERROR: Bad pnd-path in disco_t! %s\n", fullpath );
+ pnd_log ( pndn_error, "ERROR: Bad pnd-path in disco_t! %s\n", fullpath );
return ( 0 );
}
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
+ ui_pick_custom_category ( 0 );
+ break;
+
+ case 1: // list custom sub
+ if ( mmcustom_count ) {
+
+ char *maincat = ui_pick_custom_category ( 2 );
+
+ 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 ( 2 );
+
+ 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;
+}
+
+// mode 0 == custom main only; 1 == custom main + FD main; 2 == custom main + FD mains-with-custom-subs
+char *ui_pick_custom_category ( unsigned char mode ) {
+ char **list;
+ int i;
+ unsigned int counter = 0;
+
+ // alloc space for list, depending on scope
+ if ( mode > 0 ) {
+ list = malloc ( (mmcustom_count+freedesktop_count()) * sizeof(char*) );
+ } else {
+ list = malloc ( mmcustom_count * sizeof(char*) );
+ }
+
+ // add custom mains
+ for ( i = 0; i < mmcustom_count; i++ ) {
+ if ( mmcustom_complete [ i ].parent_cat == NULL ) {
+ list [ counter++ ] = mmcustom_complete [ i ].cat;
+ }
+ }
+
+ // add FD if needed
+ if ( mode > 0 ) {
+ i = 3;
+
+ while ( 1 ) {
+
+ if ( ! freedesktop_complete [ i ].cat ) {
+ break;
+ }
+
+ // if FD main cat
+ if ( freedesktop_complete [ i ].parent_cat == NULL ) {
+
+ // mode 1 == include them all
+ // mode 2 == include them if they have a custom subcat
+ if ( ( mode == 1 ) ||
+ ( mmcustom_subcount ( freedesktop_complete [ i ].cat ) ) )
+ {
+ list [ counter++ ] = freedesktop_complete [ i ].cat;
+ }
+
+ } // if parent cat
+
+ i++;
+ } // while
+
+ } // if
+
+ // we actually showing anything?
+ if ( ! counter ) {
+ ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
+ return ( NULL );
+ }
+
+ // do it
+ int sel = ui_modal_single_menu ( list, counter, "Custom Categories", "Any button to exit." );
+
+ if ( sel < 0 ) {
+ free ( list );
+ return ( NULL );
+ }
+
+ char *foo = list [ sel ];
+ free ( list );
+
+ return ( foo );
+}