2 #include <stdio.h> /* for FILE etc */
3 #include <stdlib.h> /* for malloc */
4 #include <unistd.h> /* for unlink */
5 #include <limits.h> /* for PATH_MAX */
8 #define __USE_GNU /* for strcasestr */
9 #include <string.h> /* for making ftw.h happy */
15 #include "SDL_audio.h"
16 #include "SDL_image.h"
18 #include "SDL_gfxPrimitives.h"
19 #include "SDL_rotozoom.h"
20 #include "SDL_thread.h"
24 #include "pnd_logger.h"
26 #include "pnd_container.h"
27 #include "pnd_discovery.h"
29 #include "pnd_device.h"
30 #include "../lib/pnd_pathiter.h"
31 #include "pnd_utility.h"
32 #include "pnd_pndfiles.h"
33 #include "pnd_notify.h"
34 #include "pnd_dbusnotify.h"
40 #include "mmwrapcmd.h"
42 #include "mmui_context.h"
43 #include "freedesktop_cats.h"
44 #include "mmcustom_cats.h"
46 #define CHANGED_NOTHING (0)
47 #define CHANGED_CATEGORY (1<<0) /* changed to different category */
48 #define CHANGED_SELECTION (1<<1) /* changed app selection */
49 #define CHANGED_DATAUPDATE (1<<2) /* deferred preview pic or icon came in */
50 #define CHANGED_APPRELOAD (1<<3) /* new set of applications entirely */
51 #define CHANGED_EVERYTHING (1<<4) /* redraw it all! */
52 unsigned int render_mask = CHANGED_EVERYTHING;
54 #define MIMETYPE_EXE "/usr/bin/file" /* check for file type prior to invocation */
58 SDL_Surface *sdl_realscreen = NULL;
59 unsigned int sdl_ticks = 0;
60 SDL_Thread *g_preview_thread = NULL;
61 SDL_Thread *g_timer_thread = NULL;
63 enum { sdl_user_ticker = 0,
64 sdl_user_finishedpreview = 1,
65 sdl_user_finishedicon = 2,
71 unsigned short int g_scale = 1; // 1 == noscale
73 SDL_Surface *g_imgcache [ IMG_MAX ];
75 TTF_Font *g_big_font = NULL;
76 TTF_Font *g_grid_font = NULL;
77 TTF_Font *g_detailtext_font = NULL;
78 TTF_Font *g_tab_font = NULL;
80 extern pnd_conf_handle g_conf;
82 /* current display state
84 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
85 mm_appref_t *ui_selected = NULL;
86 unsigned char ui_category = 0; // current category
87 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
88 ui_context_t ui_display_context; // display paramaters: see mmui_context.h
89 unsigned char ui_detail_hidden = 0; // if >0, detail panel is hidden
90 // FUTURE: If multiple panels can be shown/hidden, convert ui_detail_hidden to a bitmask
92 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
93 static int ui_selected_index ( void );
95 unsigned char ui_setup ( void ) {
100 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
102 SDL_JoystickOpen ( 0 ); // turn on joy-0
104 SDL_WM_SetCaption ( "mmenu", "mmenu" );
106 // hide the mouse cursor if we can
107 if ( SDL_ShowCursor ( -1 ) == 1 ) {
108 SDL_ShowCursor ( 0 );
114 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
115 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
116 svm |= SDL_FULLSCREEN;
120 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
122 if ( ! sdl_realscreen ) {
123 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
127 pnd_log ( pndn_debug, "Pixel format:" );
128 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
129 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
130 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
131 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
132 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
138 /* Set 16-bit stereo audio at 22Khz */
139 fmt.freq = 44100; //22050;
140 fmt.format = AUDIO_S16; //AUDIO_S16;
142 fmt.samples = 2048; /* A good value for games */
143 fmt.callback = mixaudio;
146 /* Open the audio device and start playing sound! */
147 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
148 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
152 SDL_PauseAudio ( 0 );
157 SDL_EnableKeyRepeat ( 500, 125 /* 150 */ );
160 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
166 if ( TTF_Init() == -1 ) {
167 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
168 return ( 0 ); // couldn't set up SDL TTF
171 char fullpath [ PATH_MAX ];
173 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
174 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
175 if ( ! g_big_font ) {
176 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
177 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
178 return ( 0 ); // couldn't set up SDL TTF
182 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "grid.font" ) );
183 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
184 if ( ! g_grid_font ) {
185 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
186 pnd_conf_get_as_char ( g_conf, "grid.font" ), pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
187 return ( 0 ); // couldn't set up SDL TTF
191 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
192 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
193 if ( ! g_detailtext_font ) {
194 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
195 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
196 return ( 0 ); // couldn't set up SDL TTF
200 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
201 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
202 if ( ! g_tab_font ) {
203 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
204 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
205 return ( 0 ); // couldn't set up SDL TTF
208 // determine display context
209 if ( pnd_conf_get_as_int_d ( g_conf, "display.show_detail_pane", 1 ) > 0 ) {
210 ui_detail_hidden = 0;
212 ui_detail_hidden = 1;
214 ui_recache_context ( &ui_display_context );
219 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
220 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
221 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
222 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
223 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
224 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
225 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
226 { IMG_TAB_SEL_L, "graphics.IMG_TAB_SEL_L" },
227 { IMG_TAB_SEL_R, "graphics.IMG_TAB_SEL_R" },
228 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
229 { IMG_TAB_UNSEL_L, "graphics.IMG_TAB_UNSEL_L" },
230 { IMG_TAB_UNSEL_R, "graphics.IMG_TAB_UNSEL_R" },
231 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
232 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
233 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
234 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
235 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
236 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
237 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
238 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
239 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
240 { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
241 { IMG_FOLDER, "graphics.IMG_FOLDER", },
242 { IMG_EXECBIN, "graphics.IMG_EXECBIN", },
246 unsigned char ui_imagecache ( char *basepath ) {
248 char fullpath [ PATH_MAX ];
252 for ( i = 0; i < IMG_MAX; i++ ) {
254 if ( g_imagecache [ i ].id != i ) {
255 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
259 char *filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
262 pnd_log ( pndn_error, "ERROR: Missing filename in conf for key: %s\n", g_imagecache [ i ].confname );
266 if ( filename [ 0 ] == '/' ) {
267 strncpy ( fullpath, filename, PATH_MAX );
269 sprintf ( fullpath, "%s/%s", basepath, filename );
272 if ( ! ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
273 pnd_log ( pndn_error, "ERROR: Couldn't load static cache image: %s\n", fullpath );
280 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
281 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
287 g_imagecache [ IMG_ICON_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_ICON_MISSING ].i, pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 ), -1 );
288 // scale text hilight
289 g_imagecache [ IMG_SELECTED_HILITE ].i = ui_scale_image ( g_imagecache [ IMG_SELECTED_HILITE ].i, pnd_conf_get_as_int_d ( g_conf, "grid.text_width", 50 ), -1 );
290 // scale preview no-pic
291 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
292 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
293 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
295 // set alpha on detail panel
296 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
301 void ui_render ( void ) {
304 // divide width: 550 / 250
305 // divide left side: 5 columns == 110px width
306 // 20px buffer either side == 70px wide icon + 20 + 20?
308 // what jobs to do during render?
312 #define R_TABS (1<<1)
313 #define R_DETAIL (1<<2)
314 #define R_GRID (1<<3)
316 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
318 unsigned int render_jobs_b = 0;
320 if ( render_mask & CHANGED_EVERYTHING ) {
321 render_jobs_b |= R_ALL;
324 if ( render_mask & CHANGED_SELECTION ) {
325 render_jobs_b |= R_GRID;
326 render_jobs_b |= R_DETAIL;
329 if ( render_mask & CHANGED_CATEGORY ) {
330 render_jobs_b |= R_ALL;
333 render_mask = CHANGED_NOTHING;
337 unsigned int icon_rows;
340 SDL_Rect rects [ MAXRECTS ], src;
341 SDL_Rect *dest = rects;
342 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
344 unsigned int row, displayrow, col;
345 mm_appref_t *appiter;
347 ui_context_t *c = &ui_display_context; // for convenience and shorthand
349 // how many total rows do we need?
350 if ( g_categorycount ) {
351 icon_rows = g_categories [ ui_category ] -> refcount / c -> col_max;
352 if ( g_categories [ ui_category ] -> refcount % c -> col_max > 0 ) {
360 // if no selected app yet, select the first one
361 if ( ! ui_selected && pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) ) {
362 ui_selected = g_categories [ ui_category ] -> refs;
366 // reset touchscreen regions
367 if ( render_jobs_b ) {
371 // ensure selection is visible
374 unsigned char autoscrolled = 1;
375 while ( autoscrolled ) {
378 int index = ui_selected_index();
379 int topleft = c -> col_max * ui_rows_scrolled_down;
380 int botright = ( c -> col_max * ( ui_rows_scrolled_down + c -> row_max ) - 1 );
382 if ( index < topleft ) {
383 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
384 render_jobs_b |= R_ALL;
386 } else if ( index > botright ) {
387 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
388 render_jobs_b |= R_ALL;
392 } // while autoscrolling
394 if ( ui_rows_scrolled_down < 0 ) {
395 ui_rows_scrolled_down = 0;
396 } else if ( ui_rows_scrolled_down > icon_rows ) {
397 ui_rows_scrolled_down = icon_rows;
403 if ( render_jobs_b & R_BG ) {
405 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
408 dest -> w = sdl_realscreen -> w;
409 dest -> h = sdl_realscreen -> h;
410 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
415 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
418 dest -> w = sdl_realscreen -> w;
419 dest -> h = sdl_realscreen -> h;
420 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
427 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
428 static unsigned int tab_width;
429 static unsigned int tab_height;
430 static unsigned int tab_offset_x;
431 static unsigned int tab_offset_y;
432 static unsigned int text_offset_x;
433 static unsigned int text_offset_y;
434 static unsigned int text_width;
436 static unsigned char tab_first_run = 1;
437 if ( tab_first_run ) {
439 tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
440 tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
441 tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
442 tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
443 text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
444 text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
445 text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
448 unsigned int maxtab = ( c -> screen_width / tab_width ) < g_categorycount ? ( c -> screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
449 unsigned int maxtabspot = ( c -> screen_width / tab_width );
451 if ( g_categorycount > 0 ) {
453 // draw tabs with categories
454 for ( col = ui_catshift;
461 // if this is the first (leftmost) tab, we use different artwork
462 // than if the other tabs (so skinner can link lines up nicely.)
463 if ( col == ui_catshift ) {
464 // leftmost tab, special case
466 if ( col == ui_category ) {
467 s = g_imagecache [ IMG_TAB_SEL_L ].i;
469 s = g_imagecache [ IMG_TAB_UNSEL_L ].i;
472 } else if ( col == maxtab - 1 ) {
473 // rightmost tab, special case
475 if ( col == ui_category ) {
476 s = g_imagecache [ IMG_TAB_SEL_R ].i;
478 s = g_imagecache [ IMG_TAB_UNSEL_R ].i;
482 // normal (not leftmost) tab
484 if ( col == ui_category ) {
485 s = g_imagecache [ IMG_TAB_SEL ].i;
487 s = g_imagecache [ IMG_TAB_UNSEL ].i;
490 } // first col, or not first col?
497 if ( col == ui_category ) {
498 src.h = tab_selheight;
506 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
507 dest -> y = tab_offset_y;
510 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
512 if ( render_jobs_b & R_TABS ) {
513 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
514 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
518 if ( col == ui_category ) {
519 // no line for selected tab
521 if ( col - ui_catshift == 0 ) {
522 s = g_imagecache [ IMG_TAB_LINEL ].i;
523 } else if ( col - ui_catshift == maxtabspot - 1 ) {
524 s = g_imagecache [ IMG_TAB_LINER ].i;
526 s = g_imagecache [ IMG_TAB_LINE ].i;
528 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
529 dest -> y = tab_offset_y + tab_height;
530 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
536 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ] -> catname, c -> fontcolor );
539 src.w = rtext -> w < text_width ? rtext -> w : text_width;
541 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
542 dest -> y = tab_offset_y + text_offset_y;
543 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
544 SDL_FreeSurface ( rtext );
551 } // if we got categories
553 if ( render_jobs_b & R_TABS ) {
555 // draw tab lines under where tabs would be if we had categories
556 for ( /* foo */; col < maxtabspot; col++ ) {
559 if ( col - ui_catshift == 0 ) {
560 s = g_imagecache [ IMG_TAB_LINEL ].i;
561 } else if ( col - ui_catshift == maxtabspot - 1 ) {
562 s = g_imagecache [ IMG_TAB_LINER ].i;
564 s = g_imagecache [ IMG_TAB_LINE ].i;
566 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
567 dest -> y = tab_offset_y + tab_height;
568 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
577 // scroll bars and arrows
578 if ( render_jobs_b & R_BG ) {
579 unsigned char show_bar = 0;
582 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
583 dest -> x = c -> arrow_up_x;
584 dest -> y = c -> arrow_up_y;
585 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
592 if ( ui_rows_scrolled_down + c -> row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
593 dest -> x = c -> arrow_down_x;
594 dest -> y = c -> arrow_down_y;
595 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
602 // show scrollbar as well
605 src.w = c -> arrow_bar_clip_w;
606 src.h = c -> arrow_bar_clip_h;
607 dest -> x = c -> arrow_bar_x;
608 dest -> y = c -> arrow_bar_y;
609 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
613 } // r_bg, scroll bars
615 // render detail pane bg
616 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
618 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
621 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
622 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
623 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
624 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
625 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
626 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
627 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
628 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
632 // render detail pane
633 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
634 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
635 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
636 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
640 } // detailpane frame/bg
644 // anything to render?
645 if ( render_jobs_b & R_GRID && g_categorycount ) {
647 // if just rendering grid, and nothing else, better clear it first
648 if ( ! ( render_jobs_b & R_BG ) ) {
649 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
650 src.x = c -> grid_offset_x;
651 src.y = c -> grid_offset_y + c -> sel_icon_offset_y;
652 src.w = c -> col_max * c -> cell_width;
653 src.h = c -> row_max * c -> cell_height;
655 dest -> x = c -> grid_offset_x;
656 dest -> y = c -> grid_offset_y + c -> sel_icon_offset_y;
658 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
664 if ( g_categories [ ui_category ] -> refs ) {
666 appiter = g_categories [ ui_category ] -> refs;
670 // until we run out of apps, or run out of space
671 while ( appiter != NULL ) {
673 for ( col = 0; col < c -> col_max && appiter != NULL; col++ ) {
675 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
676 if ( row >= ui_rows_scrolled_down ) {
678 // selected? show hilights
679 if ( appiter == ui_selected ) {
680 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
682 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
683 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + c -> sel_icon_offset_x;
684 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
685 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + c -> sel_icon_offset_y;
686 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
689 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
690 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_hilite_offset_y;
691 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
696 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
697 SDL_Surface *iconsurface;
699 iconsurface = ic -> i;
701 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
703 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
704 // filesystem (file or directory icon)
705 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
706 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
707 iconsurface = g_imagecache [ IMG_FOLDER ].i;
709 iconsurface = g_imagecache [ IMG_EXECBIN ].i;
712 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
717 // got an icon I hope?
719 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
725 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + (( c -> icon_max_width - iconsurface -> w ) / 2);
726 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + (( c -> icon_max_height - iconsurface -> h ) / 2);
728 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
731 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
738 if ( appiter -> ref -> title_en ) {
740 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, c -> fontcolor );
743 src.w = c -> text_width < rtext -> w ? c -> text_width : rtext -> w;
745 if ( rtext -> w > c -> text_width ) {
746 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
748 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_offset_x - ( rtext -> w / 2 );
750 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_offset_y;
751 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
752 SDL_FreeSurface ( rtext );
756 } // display now? or scrolled away..
759 appiter = appiter -> next;
761 } // for column 1...X
763 if ( row >= ui_rows_scrolled_down ) {
769 // are we done displaying rows?
770 if ( displayrow >= c -> row_max ) {
777 // no apps to render?
778 pnd_log ( pndn_rem, "No applications to render?\n" );
783 // detail panel - show app details or blank-message
784 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
786 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
787 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
788 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
790 unsigned int desty = cell_offset_y;
797 if ( ui_selected -> ref -> title_en ) {
799 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, c -> fontcolor );
802 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
804 dest -> x = cell_offset_x;
806 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
807 SDL_FreeSurface ( rtext );
814 if ( ui_selected -> ref -> main_category ) {
816 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
819 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
822 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
824 dest -> x = cell_offset_x;
826 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
827 SDL_FreeSurface ( rtext );
834 if ( ui_selected -> ref -> clockspeed ) {
836 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
839 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
842 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
844 dest -> x = cell_offset_x;
846 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
847 SDL_FreeSurface ( rtext );
852 // show sub-app# on right side of cpu clock?
853 //if ( ui_selected -> ref -> subapp_number )
855 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
858 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
859 dest -> x = cell_offset_x + cell_width - rtext -> w;
860 dest -> y = desty - src.h;
861 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
862 SDL_FreeSurface ( rtext );
867 #if 0 // merged into hint-line
868 if ( ui_selected -> ref -> info_filename ) {
870 sprintf ( buffer, "Documentation - hit Y" );
873 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
876 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
878 dest -> x = cell_offset_x;
880 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
881 SDL_FreeSurface ( rtext );
888 if ( ui_selected -> ovrh ) {
893 desty += 5; // a touch of spacing can't hurt
895 for ( i = 1; i < 4; i++ ) {
896 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
897 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
901 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, c -> fontcolor );
904 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
906 dest -> x = cell_offset_x;
908 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
909 SDL_FreeSurface ( rtext );
915 } // r_detail -> notes
918 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
919 SDL_Surface *previewpic;
922 previewpic = ic -> i;
924 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
928 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
929 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
930 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
931 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
937 char *empty_message = "Press SELECT for menu";
941 rtext = TTF_RenderText_Blended ( g_detailtext_font, empty_message, c -> fontcolor );
945 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
947 dest -> x = cell_offset_x;
949 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
950 SDL_FreeSurface ( rtext );
955 rtext = TTF_RenderText_Blended ( g_detailtext_font, "START or B to run app", c -> fontcolor );
956 dest -> x = cell_offset_x;
958 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
959 SDL_FreeSurface ( rtext );
963 rtext = TTF_RenderText_Blended ( g_detailtext_font, "SPACE for app menu", c -> fontcolor );
964 dest -> x = cell_offset_x;
966 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
967 SDL_FreeSurface ( rtext );
971 rtext = TTF_RenderText_Blended ( g_detailtext_font, "A to toggle details", c -> fontcolor );
972 dest -> x = cell_offset_x;
974 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
975 SDL_FreeSurface ( rtext );
979 } // r_detail && selected?
987 if ( render_jobs_b & R_BG ) {
988 static int last_battlevel = 0;
989 static unsigned char batterylevel = 0;
992 if ( time ( NULL ) - last_battlevel > 60 ) {
993 batterylevel = pnd_device_get_battery_gauge_perc();
994 last_battlevel = time ( NULL );
997 sprintf ( buffer, "Battery: %u%%", batterylevel );
1000 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1001 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
1002 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
1003 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1004 SDL_FreeSurface ( rtext );
1009 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
1011 unsigned int hintx, hinty;
1012 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
1013 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
1014 static unsigned int lastwidth = 3000;
1016 if ( ui_selected && ui_selected -> ref -> info_filename ) {
1017 buffer = "Documentation - hit Y";
1019 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
1023 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1026 if ( ! ( render_jobs_b & R_BG ) ) {
1033 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
1035 lastwidth = rtext -> w;
1041 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1042 SDL_FreeSurface ( rtext );
1047 if ( render_jobs_b & R_BG &&
1048 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
1052 time_t t = time ( NULL );
1053 struct tm *tm = localtime ( &t );
1054 strftime ( buffer, 50, "%a %H:%M %F", tm );
1057 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1058 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
1059 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
1060 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1061 SDL_FreeSurface ( rtext );
1065 // update all the rects and send it all to sdl
1066 // - at this point, we could probably just do 1 rect, of the
1067 // whole screen, and be faster :/
1068 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1072 void ui_process_input ( pnd_dbusnotify_handle dbh, pnd_notify_handle nh ) {
1075 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
1076 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
1078 while ( ( ! ui_event ) &&
1079 /*block_p ?*/ SDL_WaitEvent ( &event ) /*: SDL_PollEvent ( &event )*/ )
1082 switch ( event.type ) {
1087 // the user-defined SDL events are all for threaded/delayed previews (and icons, which
1088 // generally are not used); if we're in wide mode, we can skip previews
1089 // to avoid slowing things down when they're not shown.
1091 if ( event.user.code == sdl_user_ticker ) {
1093 if ( ui_detail_hidden ) {
1094 break; // skip building previews when not showing them
1097 // timer went off, time to load something
1098 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1100 if ( ! ui_selected ) {
1104 // load the preview pics now!
1105 pnd_disco_t *iter = ui_selected -> ref;
1107 if ( iter -> preview_pic1 ) {
1109 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
1110 // load in bg thread, make user experience chuggy
1112 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
1114 if ( ! g_preview_thread ) {
1115 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
1119 // load it now, make user wait
1121 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1122 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1125 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
1126 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1131 } // got a preview at all?
1136 } else if ( event.user.code == sdl_user_finishedpreview ) {
1138 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1139 // we finished another, no big woop
1140 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1144 } else if ( event.user.code == sdl_user_finishedicon ) {
1145 // redraw, so we can show the newly loaded icon
1148 } else if ( event.user.code == sdl_user_checksd ) {
1149 // check if any inotify-type events occured, forcing us to rescan/re-disco the SDs
1151 unsigned char watch_dbus = 0;
1152 unsigned char watch_inotify = 0;
1155 watch_dbus = pnd_dbusnotify_rediscover_p ( dbh );
1159 watch_inotify = pnd_notify_rediscover_p ( nh );
1162 if ( watch_dbus || watch_inotify ) {
1163 pnd_log ( pndn_debug, "dbusnotify detected SD event\n" );
1164 applications_free();
1165 applications_scan();
1172 render_mask |= CHANGED_EVERYTHING;
1176 #if 0 // joystick motion
1177 case SDL_JOYAXISMOTION:
1179 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1181 if ( event.jaxis.axis == 0 ) {
1183 if ( event.jaxis.value < 0 ) {
1185 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1186 } else if ( event.jaxis.value > 0 ) {
1187 ui_push_right ( 0 );
1188 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1190 } else if ( event.jaxis.axis == 1 ) {
1192 if ( event.jaxis.value < 0 ) {
1194 } else if ( event.jaxis.value > 0 ) {
1204 #if 0 // joystick buttons
1205 case SDL_JOYBUTTONDOWN:
1207 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1209 if ( event.jbutton.button == 0 ) { // B
1211 } else if ( event.jbutton.button == 1 ) { // Y
1213 } else if ( event.jbutton.button == 2 ) { // X
1215 } else if ( event.jbutton.button == 3 ) { // A
1218 } else if ( event.jbutton.button == 4 ) { // Select
1219 ui_mask |= uisb_select;
1220 } else if ( event.jbutton.button == 5 ) { // Start
1221 ui_mask |= uisb_start;
1223 } else if ( event.jbutton.button == 7 ) { // L
1225 } else if ( event.jbutton.button == 8 ) { // R
1234 case SDL_JOYBUTTONUP:
1236 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1238 if ( event.jbutton.button == 0 ) { // B
1241 } else if ( event.jbutton.button == 1 ) { // Y
1243 } else if ( event.jbutton.button == 2 ) { // X
1245 } else if ( event.jbutton.button == 3 ) { // A
1248 } else if ( event.jbutton.button == 4 ) { // Select
1249 ui_mask &= ~uisb_select;
1250 } else if ( event.jbutton.button == 5 ) { // Start
1251 ui_mask &= ~uisb_start;
1253 } else if ( event.jbutton.button == 7 ) { // L
1256 } else if ( event.jbutton.button == 8 ) { // R
1267 #if 1 // keyboard events
1271 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1273 // SDLK_LALT -> Start
1274 // page up/down for y/x
1275 // home/end for a and b
1278 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1279 ui_push_right ( 0 );
1281 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1284 } else if ( event.key.keysym.sym == SDLK_UP ) {
1287 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1290 } else if ( event.key.keysym.sym == SDLK_END ) { // B
1293 } else if ( event.key.keysym.sym == SDLK_SPACE ) { // space
1294 if ( ui_selected ) {
1295 ui_menu_context ( ui_selected );
1297 // TBD: post an error?
1299 render_mask |= CHANGED_EVERYTHING;
1301 } else if ( event.key.keysym.sym == SDLK_TAB || event.key.keysym.sym == SDLK_HOME ) { // tab or A
1302 // if detail panel is togglable, then toggle it
1303 // if not, make sure its ruddy well shown!
1304 if ( ui_is_detail_hideable() ) {
1305 ui_toggle_detail_pane();
1307 ui_detail_hidden = 0;
1310 } else if ( event.key.keysym.sym == SDLK_RSHIFT || event.key.keysym.sym == SDLK_COMMA ) { // left trigger or comma
1313 } else if ( event.key.keysym.sym == SDLK_RCTRL || event.key.keysym.sym == SDLK_PERIOD ) { // right trigger or period
1317 } else if ( event.key.keysym.sym == SDLK_PAGEUP ) { // Y
1319 if ( ui_selected ) {
1320 ui_show_info ( pnd_run_script, ui_selected -> ref );
1323 } else if ( event.key.keysym.sym == SDLK_PAGEDOWN ) { // X
1326 // forget the selection, nolonger applies
1328 ui_set_selected ( ui_selected );
1330 if ( g_categories [ ui_category ] -> fspath ) {
1331 category_fs_restock ( g_categories [ ui_category ] );
1334 render_mask |= CHANGED_EVERYTHING;
1337 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1341 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1342 char *opts [ 20 ] = {
1343 "Reveal hidden category",
1345 "Configure Minimenu",
1346 "Manage custom app categories",
1347 "Rescan for applications",
1348 "Cache previews to SD now",
1349 "Run a terminal/console",
1350 "Run another GUI (xfce, etc)",
1352 "Select a Minimenu skin",
1355 int sel = ui_modal_single_menu ( opts, 11, "Minimenu", "Enter to select; other to return." );
1357 char buffer [ 100 ];
1361 } else if ( sel == 1 ) {
1363 sprintf ( buffer, "sudo poweroff" );
1365 } else if ( sel == 2 ) {
1367 unsigned char restart = conf_run_menu ( NULL );
1368 conf_write ( g_conf, conf_determine_location ( g_conf ) );
1370 emit_and_quit ( MM_RESTART );
1372 } else if ( sel == 3 ) {
1373 // manage custom categories
1374 ui_manage_categories();
1375 } else if ( sel == 4 ) {
1377 pnd_log ( pndn_debug, "Freeing up applications\n" );
1378 applications_free();
1379 pnd_log ( pndn_debug, "Rescanning applications\n" );
1380 applications_scan();
1381 } else if ( sel == 5 ) {
1382 // cache preview to SD now
1383 extern pnd_box_handle g_active_apps;
1384 pnd_box_handle h = g_active_apps;
1386 unsigned int maxwidth, maxheight;
1387 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1388 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1390 pnd_disco_t *iter = pnd_box_get_head ( h );
1395 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1396 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1397 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1401 iter = pnd_box_get_next ( iter );
1404 } else if ( sel == 6 ) {
1407 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1411 ui_forkexec ( argv );
1414 } else if ( sel == 7 ) {
1415 char buffer [ PATH_MAX ];
1416 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
1417 emit_and_quit ( buffer );
1418 } else if ( sel == 8 ) {
1419 emit_and_quit ( MM_QUIT );
1420 } else if ( sel == 9 ) {
1422 if ( ui_pick_skin() ) {
1423 emit_and_quit ( MM_RESTART );
1425 } else if ( sel == 10 ) {
1427 char buffer [ PATH_MAX ];
1428 sprintf ( buffer, "%s/about.txt", g_skinpath );
1429 ui_aboutscreen ( buffer );
1433 render_mask |= CHANGED_EVERYTHING;
1436 // unknown SDLK_ keycode?
1438 // many SDLK_keycodes map to ASCII ("a" is ascii(a)), so try to jump to a filename of that name, in this category?
1439 // and if already there, try to jump to next, maybe?
1440 // future: look for sequence typing? ie: user types 'm' then 'a', look for 'ma*' instead of 'm' then 'a' matching
1441 if ( isalpha ( event.key.keysym.sym ) && g_categories [ ui_category ] -> refcount > 0 ) {
1442 mm_appref_t *app = g_categories [ ui_category ] -> refs;
1444 //fprintf ( stderr, "sel %s next %s\n", ui_selected -> ref -> title_en, ui_selected -> next -> ref -> title_en );
1446 // are we already matching the same char? and next item is also same char?
1447 if ( app && ui_selected && ui_selected -> next &&
1448 ui_selected -> ref -> title_en && ui_selected -> next -> ref -> title_en &&
1449 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( ui_selected -> next -> ref -> title_en [ 0 ] ) &&
1450 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym )
1453 // just skip down one
1454 app = ui_selected -> next;
1457 // walk the category, looking for a first-char match
1459 if ( app -> ref -> title_en && toupper ( app -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym ) ) {
1465 } // same start letter, or new run?
1467 // found something, or no?
1469 // looks like we found a potential match; try switching it to visible selection
1471 ui_set_selected ( ui_selected );
1476 } // SDLK_alphanumeric?
1482 if ( event.key.keysym.sym == SDLK_ESCAPE ) {
1483 emit_and_quit ( MM_QUIT );
1490 #if 1 // mouse / touchscreen
1492 case SDL_MOUSEBUTTONDOWN:
1493 if ( event.button.button == SDL_BUTTON_LEFT ) {
1494 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1500 case SDL_MOUSEBUTTONUP:
1501 if ( event.button.button == SDL_BUTTON_LEFT ) {
1502 ui_touch_act ( event.button.x, event.button.y );
1515 } // switch event type
1522 void ui_push_left ( unsigned char forcecoil ) {
1524 if ( ! ui_selected ) {
1525 ui_push_right ( 0 );
1529 // what column we in?
1530 unsigned int col = ui_determine_screen_col ( ui_selected );
1532 // are we already at first item?
1533 if ( forcecoil == 0 &&
1534 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1537 unsigned int i = ui_display_context.col_max - 1;
1538 while ( i && ui_selected -> next ) {
1539 ui_push_right ( 0 );
1543 } else if ( g_categories [ ui_category ] -> refs == ui_selected ) {
1544 // can't go any more left, we're at the head
1547 // figure out the previous item; yay for singly linked list :/
1548 mm_appref_t *i = g_categories [ ui_category ] -> refs;
1550 if ( i -> next == ui_selected ) {
1558 ui_set_selected ( ui_selected );
1563 void ui_push_right ( unsigned char forcecoil ) {
1565 if ( ui_selected ) {
1567 // what column we in?
1568 unsigned int col = ui_determine_screen_col ( ui_selected );
1571 if ( forcecoil == 0 &&
1572 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1573 // and selected is far-right, or last icon in category (might not be far right)
1574 ( ( col == ui_display_context.col_max - 1 ) ||
1575 ( ui_selected -> next == NULL ) )
1579 //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1580 while ( col /*i*/ ) {
1586 // just go to the next
1588 if ( ui_selected -> next ) {
1589 ui_selected = ui_selected -> next;
1595 ui_selected = g_categories [ ui_category ] -> refs;
1598 ui_set_selected ( ui_selected );
1603 void ui_push_up ( void ) {
1604 unsigned char col_max = ui_display_context.col_max;
1606 if ( ! ui_selected ) {
1611 unsigned int row = ui_determine_row ( ui_selected );
1614 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1616 // wrap around instead
1618 unsigned int col = ui_determine_screen_col ( ui_selected );
1621 ui_selected = g_categories [ ui_category ] -> refs;
1622 while ( ui_selected -> next ) {
1623 ui_selected = ui_selected -> next;
1626 // try to move to same column
1627 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1628 if ( newcol > col ) {
1636 // scroll down to show it
1637 int r = ui_determine_row ( ui_selected ) - 1;
1638 if ( r - ui_display_context.row_max > 0 ) {
1639 ui_rows_scrolled_down = (unsigned int) r;
1643 // stop at top/bottom
1655 void ui_push_down ( void ) {
1656 unsigned char col_max = ui_display_context.col_max;
1658 if ( ui_selected ) {
1661 unsigned int row = ui_determine_row ( ui_selected );
1664 unsigned int icon_rows = g_categories [ ui_category ] -> refcount / col_max;
1665 if ( g_categories [ ui_category ] -> refcount % col_max > 0 ) {
1670 if ( row == ( icon_rows - 1 ) &&
1671 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1674 unsigned char col = ui_determine_screen_col ( ui_selected );
1676 ui_selected = g_categories [ ui_category ] -> refs;
1679 ui_selected = ui_selected -> next;
1683 ui_rows_scrolled_down = 0;
1685 render_mask |= CHANGED_EVERYTHING;
1690 ui_push_right ( 1 );
1697 ui_push_right ( 0 );
1703 // 'backup' is currently 'X', for going back up in a folder/subcat without having to hit exec on the '..' entry
1704 void ui_push_backup ( void ) {
1706 // a subcat-as-dir, or a dir browser?
1707 if ( g_categories [ ui_category] -> fspath ) {
1708 // dir browser, just climb our way back up
1713 // lop off last word; if the thing ends with /, lop that one, then the next word.
1714 while ( ( c = strrchr ( g_categories [ ui_category] -> fspath, '/' ) ) ) {
1715 *c = '\0'; // lop off the last hunk
1716 if ( *(c+1) != '\0' ) {
1722 if ( g_categories [ ui_category] -> fspath [ 0 ] == '\0' ) {
1723 free ( g_categories [ ui_category] -> fspath );
1724 g_categories [ ui_category] -> fspath = strdup ( "/" );
1728 // a pnd subcat .. are we in one, or at the 'top'?
1729 char *pcatname = g_categories [ ui_category ] -> parent_catname;
1732 return; // we're at the 'top' already
1735 // set to first cat!
1738 // republish cats .. shoudl just be the one
1739 category_publish ( CFNORMAL, NULL );
1742 ui_category = category_index ( pcatname );
1744 // ensure tab visible?
1745 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1746 if ( ui_category > ui_catshift + ( ui_display_context.screen_width / tab_width ) - 1 ) {
1747 ui_catshift = ui_category - ( ui_display_context.screen_width / tab_width ) + 1;
1757 void ui_push_exec ( void ) {
1759 if ( ! ui_selected ) {
1763 // was this icon generated from filesystem, or from pnd-file?
1764 if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
1766 if ( ! ui_selected -> ref -> title_en ) {
1767 return; // no filename
1770 if ( ui_selected -> ref -> object_type == pnd_object_type_directory ) {
1772 // check if this guy is a dir-browser tab, or is a directory on a pnd tab
1773 if ( ! g_categories [ ui_category] -> fspath ) {
1774 // pnd subcat as dir
1776 // are we already in a subcat? if so, go back to parent; there is no grandparenting or deeper
1777 if ( g_categories [ ui_category ] -> parent_catname ) {
1782 // delve into subcat
1784 // set to first cat!
1788 // republish cats .. shoudl just be the one
1789 category_publish ( CFBYNAME, ui_selected -> ref -> object_path );
1793 // forget the selection, nolonger applies
1795 ui_set_selected ( ui_selected );
1797 render_mask |= CHANGED_EVERYTHING;
1801 // delve up/down the dir tree
1802 if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
1807 char *temp = malloc ( strlen ( g_categories [ ui_category] -> fspath ) + strlen ( ui_selected -> ref -> title_en ) + 1 + 1 );
1808 sprintf ( temp, "%s/%s", g_categories [ ui_category] -> fspath, ui_selected -> ref -> title_en );
1809 free ( g_categories [ ui_category] -> fspath );
1810 g_categories [ ui_category] -> fspath = temp;
1813 pnd_log ( pndn_debug, "Cat %s is now in path %s\n", g_categories [ ui_category ] -> catname, g_categories [ ui_category ]-> fspath );
1815 // forget the selection, nolonger applies
1817 ui_set_selected ( ui_selected );
1819 category_fs_restock ( g_categories [ ui_category ] );
1821 render_mask |= CHANGED_SELECTION;
1823 } // directory browser or pnd subcat?
1826 // just run it arbitrarily?
1828 // if this a pnd-file, or just some executable?
1829 if ( strcasestr ( ui_selected -> ref -> object_filename, PND_PACKAGE_FILEEXT ) ) {
1830 // looks like a pnd, now what do we do..
1831 pnd_box_handle h = pnd_disco_file ( ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1834 pnd_disco_t *d = pnd_box_get_head ( h );
1835 pnd_apps_exec_disco ( pnd_run_script, d, PND_EXEC_OPTION_NORUN, NULL );
1836 char buffer [ PATH_MAX ];
1837 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1838 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1839 emit_and_quit ( buffer );
1841 emit_and_run ( buffer );
1848 // is it even executable? if we don't have handlers for non-executables yet (Jan 2011 we don't),
1849 // then don't even try to run things not-flagged as executable.. but wait most people are on
1850 // FAT filesystems, what a drag, we can't tell at the fs level.
1851 // ... but we can still invoke 'file' and grep out the good bits, at least.
1853 // open a stream reading 'file /path/to/file' and check output for 'executable'
1854 // -- not checking for "ARM" so it can pick up x86 (or whatever native) executables in build environment
1855 unsigned char is_executable = 0;
1859 char popenbuf [ FILENAME_MAX ];
1860 snprintf ( popenbuf, FILENAME_MAX, "%s %s/%s", MIMETYPE_EXE, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1863 if ( ! ( marceau = popen ( popenbuf, "r" ) ) ) {
1864 return; // error, we need some useful error handling and dialog boxes here
1867 if ( fgets ( popenbuf, FILENAME_MAX, marceau ) ) {
1868 //printf ( "File test returns: %s\n", popenbuf );
1869 if ( strstr ( popenbuf, "executable" ) != NULL ) {
1878 if ( ! is_executable ) {
1879 fprintf ( stderr, "ERROR: File to invoke is not executable, skipping. (%s)\n", ui_selected -> ref -> title_en );
1880 return; // need some error handling here
1883 #if 0 // eat up any pending SDL events and toss 'em?
1887 while ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_ALLEVENTS ) > 0 ) {
1897 // get CWD so we can restore it on return
1898 char cwd [ PATH_MAX ];
1899 getcwd ( cwd, PATH_MAX );
1901 // full path to executable so we don't rely on implicit "./"
1902 char execbuf [ FILENAME_MAX ];
1903 snprintf ( execbuf, FILENAME_MAX, "%s/%s", g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1906 chdir ( g_categories [ ui_category ] -> fspath );
1907 exec_raw_binary ( execbuf /*ui_selected -> ref -> title_en*/ );
1910 // DEPRECATED / NOT TESTED
1911 // get mmwrapper to run it
1912 char buffer [ PATH_MAX ];
1913 sprintf ( buffer, "%s %s/%s\n", MM_RUN, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1914 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1915 emit_and_quit ( buffer );
1917 emit_and_run ( buffer );
1926 // set app-run speed
1927 int use_run_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.use_run_speed", 0 );
1928 if ( use_run_speed > 0 ) {
1929 int mm_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.run_speed", -1 );
1930 if ( mm_speed > -1 ) {
1931 char buffer [ 512 ];
1932 snprintf ( buffer, 500, "sudo /usr/pandora/scripts/op_cpuspeed.sh %d", mm_speed );
1935 } // do speed change?
1937 // request app to run and quit mmenu
1938 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
1939 char buffer [ PATH_MAX ];
1940 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1941 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1942 emit_and_quit ( buffer );
1944 emit_and_run ( buffer );
1951 void ui_push_ltrigger ( void ) {
1952 unsigned char oldcat = ui_category;
1953 unsigned int screen_width = ui_display_context.screen_width;
1954 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1956 if ( g_categorycount == 0 ) {
1960 if ( ui_category > 0 ) {
1962 category_fs_restock ( g_categories [ ui_category ] );
1964 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1965 ui_category = g_categorycount - 1;
1967 if ( ui_category >= ( screen_width / tab_width ) ) {
1968 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
1970 category_fs_restock ( g_categories [ ui_category ] );
1974 if ( oldcat != ui_category ) {
1976 ui_set_selected ( ui_selected );
1979 // make tab visible?
1980 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
1985 ui_rows_scrolled_down = 0;
1987 render_mask |= CHANGED_CATEGORY;
1992 void ui_push_rtrigger ( void ) {
1993 unsigned char oldcat = ui_category;
1995 if ( g_categorycount == 0 ) {
1999 unsigned int screen_width = ui_display_context.screen_width;
2000 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2002 if ( ui_category < ( g_categorycount - 1 ) ) {
2004 category_fs_restock ( g_categories [ ui_category ] );
2006 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
2009 category_fs_restock ( g_categories [ ui_category ] );
2013 if ( oldcat != ui_category ) {
2015 ui_set_selected ( ui_selected );
2018 // make tab visible?
2019 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2024 ui_rows_scrolled_down = 0;
2026 render_mask |= CHANGED_CATEGORY;
2031 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
2032 double scale = 1000000.0;
2033 double scalex = 1000000.0;
2034 double scaley = 1000000.0;
2035 SDL_Surface *scaled;
2037 scalex = (double)maxwidth / (double)s -> w;
2039 if ( maxheight == -1 ) {
2042 scaley = (double)maxheight / (double)s -> h;
2044 if ( scaley < scalex ) {
2052 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
2053 SDL_FreeSurface ( s );
2059 void ui_loadscreen ( void ) {
2064 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2068 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", ui_display_context.fontcolor );
2071 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2072 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2073 SDL_FreeSurface ( rtext );
2078 void ui_discoverscreen ( unsigned char clearscreen ) {
2083 if ( clearscreen ) {
2084 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2086 // render background
2087 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2090 dest.w = sdl_realscreen -> w;
2091 dest.h = sdl_realscreen -> h;
2092 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2093 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2100 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", ui_display_context.fontcolor );
2101 if ( clearscreen ) {
2108 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2109 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2110 SDL_FreeSurface ( rtext );
2113 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2114 dest.x = rtext -> w + 30;
2116 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
2117 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2123 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
2125 SDL_Rect rects [ 4 ];
2126 SDL_Rect *dest = rects;
2128 bzero ( dest, sizeof(SDL_Rect)* 4 );
2130 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2131 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2132 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
2133 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
2135 static unsigned int stepx = 0;
2138 if ( clearscreen ) {
2139 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2141 // render background
2142 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2145 dest -> w = sdl_realscreen -> w;
2146 dest -> h = sdl_realscreen -> h;
2147 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2153 // render background
2154 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2157 src.w = sdl_realscreen -> w;
2161 dest -> w = sdl_realscreen -> w;
2162 dest -> h = sdl_realscreen -> h;
2163 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
2171 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
2172 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
2175 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2176 SDL_FreeSurface ( rtext );
2180 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2181 dest -> x = rtext -> w + 30 + stepx;
2183 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
2189 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
2192 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2193 SDL_FreeSurface ( rtext );
2200 if ( stepx > 350 ) {
2204 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2209 int ui_selected_index ( void ) {
2211 if ( ! ui_selected ) {
2212 return ( -1 ); // no index
2215 mm_appref_t *r = g_categories [ ui_category ] -> refs;
2218 if ( r == ui_selected ) {
2228 static mm_appref_t *timer_ref = NULL;
2229 void ui_set_selected ( mm_appref_t *r ) {
2231 render_mask |= CHANGED_SELECTION;
2233 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
2234 return; // no desire to defer anything
2239 SDL_SetTimer ( 0, NULL );
2244 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
2250 unsigned int ui_callback_f ( unsigned int t ) {
2252 if ( ui_selected != timer_ref ) {
2253 return ( 0 ); // user has moved it, who cares
2257 bzero ( &e, sizeof(SDL_Event) );
2258 e.type = SDL_USEREVENT;
2259 e.user.code = sdl_user_ticker;
2260 SDL_PushEvent ( &e );
2265 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
2266 SDL_Rect rects [ 40 ];
2267 SDL_Rect *dest = rects;
2270 unsigned char max_visible = pnd_conf_get_as_int_d ( g_conf, "detailtext.max_visible" , 11 );
2271 unsigned char first_visible = 0;
2273 bzero ( rects, sizeof(SDL_Rect) * 40 );
2275 unsigned int sel = 0;
2277 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 };
2285 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2286 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2287 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
2288 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
2289 SDL_FillRect( sdl_realscreen, dest, 0 );
2291 // show dialog background
2292 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
2295 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
2296 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
2297 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2298 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2299 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2300 // repeat for darken?
2301 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2302 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2303 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2307 // show dialog frame
2308 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
2309 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2310 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2311 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
2312 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2318 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
2319 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2320 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
2321 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2322 SDL_FreeSurface ( rtext );
2328 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
2329 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2330 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
2331 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
2333 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2334 SDL_FreeSurface ( rtext );
2339 for ( i = first_visible; i < first_visible + max_visible && i < argc; i++ ) {
2343 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
2345 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], ui_display_context.fontcolor );
2347 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2348 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 - first_visible ) );
2349 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2350 SDL_FreeSurface ( rtext );
2355 // update all the rects and send it all to sdl
2356 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2360 while ( SDL_WaitEvent ( &event ) ) {
2362 switch ( event.type ) {
2367 if ( event.key.keysym.sym == SDLK_UP ) {
2371 if ( sel < first_visible ) {
2376 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
2378 if ( sel < argc - 1 ) {
2381 // ensure visibility
2382 if ( sel >= first_visible + max_visible ) {
2388 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
2392 } else if ( event.key.keysym.sym == SDLK_q ) {
2397 return ( -1 ); // nada
2412 unsigned char ui_determine_row ( mm_appref_t *a ) {
2413 unsigned int row = 0;
2415 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2420 row /= ui_display_context.col_max;
2425 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
2426 return ( ui_determine_row ( a ) % ui_display_context.row_max );
2429 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
2430 unsigned int col = 0;
2432 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2437 col %= ui_display_context.col_max;
2442 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
2443 char *viewer, *searchpath;
2444 pnd_conf_handle desktoph;
2447 searchpath = pnd_conf_query_searchpath();
2449 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
2455 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
2458 return ( 0 ); // no way to view the file
2462 if ( ! p -> unique_id ) {
2466 if ( ! p -> info_filename ) {
2470 if ( ! p -> info_name ) {
2481 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
2482 snprintf ( pargs, 1001, "%s %s",
2483 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
2488 char pndfile [ 1024 ];
2489 if ( p -> object_type == pnd_object_type_directory ) {
2490 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
2491 strncpy ( pndfile, p -> object_path, 1000 );
2492 } else if ( p -> object_type == pnd_object_type_pnd ) {
2493 // pnd_run.sh wants the full path and filename for the .pnd file
2494 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2497 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2498 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2503 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2507 if ( ( x = fork() ) < 0 ) {
2508 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2513 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2514 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2526 #define MAXTOUCH 100
2527 ui_touch_t ui_touchrects [ MAXTOUCH ];
2528 unsigned char ui_touchrect_count = 0;
2530 void ui_register_reset ( void ) {
2531 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2532 ui_touchrect_count = 0;
2536 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2538 if ( ui_touchrect_count == MAXTOUCH ) {
2542 ui_touchrects [ ui_touchrect_count ].r.x = x;
2543 ui_touchrects [ ui_touchrect_count ].r.y = y;
2544 ui_touchrects [ ui_touchrect_count ].r.w = w;
2545 ui_touchrects [ ui_touchrect_count ].r.h = h;
2546 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2547 ui_touchrect_count++;
2552 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2554 if ( ui_touchrect_count == MAXTOUCH ) {
2558 ui_touchrects [ ui_touchrect_count ].r.x = x;
2559 ui_touchrects [ ui_touchrect_count ].r.y = y;
2560 ui_touchrects [ ui_touchrect_count ].r.w = w;
2561 ui_touchrects [ ui_touchrect_count ].r.h = h;
2562 ui_touchrects [ ui_touchrect_count ].ref = app;
2563 ui_touchrect_count++;
2568 void ui_touch_act ( unsigned int x, unsigned int y ) {
2573 for ( i = 0; i < ui_touchrect_count; i++ ) {
2574 t = &(ui_touchrects [ i ]);
2576 if ( x >= t -> r.x &&
2577 x <= t -> r.x + t -> r.w &&
2579 y <= t -> r.y + t -> r.h
2584 ui_selected = t -> ref;
2587 if ( ui_category != t -> catnum ) {
2590 ui_category = t -> catnum;
2591 render_mask |= CHANGED_CATEGORY;
2593 category_fs_restock ( g_categories [ ui_category ] );
2604 unsigned char ui_forkexec ( char *argv[] ) {
2605 char *fooby = argv[0];
2608 if ( ( x = fork() ) < 0 ) {
2609 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2613 if ( x == 0 ) { // child
2614 execv ( fooby, argv );
2615 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2623 unsigned char ui_threaded_timer_create ( void ) {
2625 g_timer_thread = SDL_CreateThread ( (void*)ui_threaded_timer, NULL );
2627 if ( ! g_timer_thread ) {
2628 pnd_log ( pndn_error, "ERROR: Couldn't create timer thread\n" );
2635 int ui_threaded_timer ( pnd_disco_t *p ) {
2637 // this timer's job is to ..
2638 // - do nothing for quite awhile
2639 // - on wake, post event to SDL event queue, so that main thread will check if SD insert/eject occurred
2642 unsigned int delay_s = 2; // seconds
2649 // .. trigger SD check
2651 bzero ( &e, sizeof(SDL_Event) );
2652 e.type = SDL_USEREVENT;
2653 e.user.code = sdl_user_checksd;
2654 SDL_PushEvent ( &e );
2661 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
2663 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
2664 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
2667 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
2668 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
2671 // trigger that we completed
2673 bzero ( &e, sizeof(SDL_Event) );
2674 e.type = SDL_USEREVENT;
2675 e.user.code = sdl_user_finishedpreview;
2677 SDL_PushEvent ( &e );
2682 SDL_Thread *g_icon_thread = NULL;
2683 void ui_post_scan ( void ) {
2685 // if deferred icon load, kick off the thread now
2686 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2688 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
2690 if ( ! g_icon_thread ) {
2691 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
2694 } // deferred icon load
2698 ui_rows_scrolled_down = 0;
2699 // set back to first tab, to be safe
2703 // do we have a preferred category to jump to?
2704 char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
2707 // attempt to find default cat; if we do find it, select it; otherwise
2708 // default behaviour will pick first cat (ie: usually All)
2710 for ( i = 0; i < g_categorycount; i++ ) {
2711 if ( strcasecmp ( g_categories [ i ] -> catname, dc ) == 0 ) {
2713 // ensure visibility
2714 unsigned int screen_width = ui_display_context.screen_width;
2715 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2716 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2717 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2723 if ( i == g_categorycount ) {
2724 pnd_log ( pndn_warning, " User defined default category '%s' but not found, so using default behaviour\n", dc );
2729 // if we're sent right to a dirbrowser tab, restock it now (normally we restock on entry)
2730 if ( g_categories [ ui_category ] -> fspath ) {
2731 printf ( "Restock on start: '%s'\n", g_categories [ ui_category ] -> fspath );
2732 category_fs_restock ( g_categories [ ui_category ] );
2736 render_mask |= CHANGED_EVERYTHING;
2741 unsigned char ui_threaded_defered_icon ( void *p ) {
2742 extern pnd_box_handle g_active_apps;
2743 pnd_box_handle h = g_active_apps;
2745 unsigned char maxwidth, maxheight;
2746 maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
2747 maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
2749 pnd_disco_t *iter = pnd_box_get_head ( h );
2754 if ( iter -> pnd_icon_pos &&
2755 ! cache_icon ( iter, maxwidth, maxheight ) )
2757 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2760 // trigger that we completed
2762 bzero ( &e, sizeof(SDL_Event) );
2763 e.type = SDL_USEREVENT;
2764 e.user.code = sdl_user_finishedicon;
2765 SDL_PushEvent ( &e );
2767 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2768 usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2773 iter = pnd_box_get_next ( iter );
2779 void ui_show_hourglass ( unsigned char updaterect ) {
2782 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2784 dest.x = ( 800 - s -> w ) / 2;
2785 dest.y = ( 480 - s -> h ) / 2;
2787 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2790 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2796 unsigned char ui_pick_skin ( void ) {
2798 char *skins [ MAXSKINS ];
2801 char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
2802 char tempname [ 100 ];
2806 skins [ iter++ ] = "No skin change";
2810 DIR *d = opendir ( buffer );
2815 while ( ( dd = readdir ( d ) ) ) {
2817 if ( dd -> d_name [ 0 ] == '.' ) {
2819 } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
2822 snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
2823 skins [ iter++ ] = strdup ( tempname );
2834 int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
2836 // did they pick one?
2840 char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
2841 s = pnd_expand_tilde ( s );
2843 f = fopen ( s, "w" );
2848 fprintf ( f, "%s\n", skins [ sel ] + 6 );
2858 void ui_aboutscreen ( char *textpath ) {
2865 #define ROWS SCRH / ( PIXELH + MARGINH )
2866 #define COLS SCRW / ( PIXELW + MARGINW )
2868 unsigned char pixelboard [ ROWS * COLS ]; // pixel heat
2869 bzero ( pixelboard, ROWS * COLS );
2874 SDL_Color rtextc = { 200, 200, 200, 100 };
2877 char *textloop [ 500 ];
2878 unsigned int textmax = 0;
2879 bzero ( textloop, 500 * sizeof(char*) );
2882 char cbuffer [ 50000 ];
2883 bzero ( cbuffer, 50000 );
2884 unsigned int crevealed = 0;
2886 FILE *f = fopen ( textpath, "r" );
2889 pnd_log ( pndn_error, "ERROR: Couldn't open about text: %s\n", textpath );
2893 char textbuf [ 100 ];
2894 while ( fgets ( textbuf, 100, f ) ) {
2896 // add to full buffer
2897 strncat ( cbuffer, textbuf, 50000 );
2900 if ( strchr ( textbuf, '\n' ) ) {
2901 * strchr ( textbuf, '\n' ) = '\0';
2904 // add to pixel loop
2905 if ( 1||textbuf [ 0 ] ) {
2906 textloop [ textmax ] = strdup ( textbuf );
2914 unsigned int textiter = 0;
2915 while ( textiter < textmax ) {
2916 char *text = textloop [ textiter ];
2920 // render to surface
2921 rtext = TTF_RenderText_Blended ( g_grid_font, text, rtextc );
2923 // render font to pixelboard
2924 unsigned int px, py;
2926 unsigned int *pixels = rtext -> pixels;
2927 unsigned char cr, cg, cb, ca;
2928 for ( py = 0; py < rtext -> h; py ++ ) {
2929 for ( px = 0; px < ( rtext -> w > COLS ? COLS : rtext -> w ); px++ ) {
2931 SDL_GetRGBA ( pixels [ ( py * rtext -> pitch / 4 ) + px ],
2932 rtext -> format, &cr, &cg, &cb, &ca );
2936 ph = pixelboard + ( /*y offset */ 30 * COLS ) + ( py * COLS ) + px /* / 2 */;
2943 if ( *ph + ca < 250 ) {
2954 unsigned int runcount = 10;
2955 while ( runcount-- ) {
2958 SDL_FillRect( sdl_realscreen, NULL /* whole */, 0 );
2960 // render pixelboard
2963 for ( y = 0; y < ROWS; y++ ) {
2964 for ( x = 0; x < COLS; x++ ) {
2966 if ( 1||pixelboard [ ( y * COLS ) + x ] ) {
2969 r.x = x * ( PIXELW + MARGINW );
2970 r.y = y * ( PIXELH + MARGINH );
2974 c = SDL_MapRGB ( sdl_realscreen -> format, 100 /* r */, 0 /* g */, pixelboard [ ( y * COLS ) + x ] );
2976 SDL_FillRect( sdl_realscreen, &r /* whole */, c );
2984 unsigned char *pc = pixelboard;
2985 for ( y = 0; y < ROWS; y++ ) {
2986 for ( x = 0; x < COLS; x++ ) {
2996 // slide pixels upwards
2997 memmove ( pixelboard, pixelboard + COLS, ( COLS * ROWS ) - COLS );
2999 // render actual readable text
3002 // display up to cursor
3004 unsigned int cdraw = 0;
3008 if ( crevealed > 200 ) {
3009 cdraw = crevealed - 200;
3015 for ( ; cdraw < crevealed; cdraw++ ) {
3016 ctb [ 0 ] = cbuffer [ cdraw ];
3018 // move over or down
3019 if ( cbuffer [ cdraw ] == '\n' ) {
3024 if ( dest.y > 450 ) {
3030 cs = TTF_RenderText_Blended ( g_tab_font, ctb, rtextc );
3032 SDL_BlitSurface ( cs, NULL /* all */, sdl_realscreen, &dest );
3033 SDL_FreeSurface ( cs );
3043 SDL_FillRect ( sdl_realscreen, &dest /* whole */, 220 );
3045 // increment cursor to next character
3046 if ( cbuffer [ crevealed ] != '\0' ) {
3050 } // draw cursor text
3054 SDL_UpdateRect ( sdl_realscreen, 0, 0, 0, 0 ); // whole screen
3058 // any button? if so, about
3064 if ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_EVENTMASK(/*SDL_KEYUP|*/SDL_KEYDOWN) ) > 0 ) {
3073 SDL_FreeSurface ( rtext );
3077 } // while more text
3081 for ( i = 0; i < textmax; i++ ) {
3082 if ( textloop [ i ] ) {
3083 free ( textloop [ i ] );
3091 void ui_revealscreen ( void ) {
3092 char *labels [ 500 ];
3093 unsigned int labelmax = 0;
3095 char fulllabel [ 200 ];
3097 if ( ! category_count ( CFHIDDEN ) ) {
3098 return; // nothing to do
3101 // switch to hidden categories
3102 category_publish ( CFHIDDEN, NULL );
3104 // build up labels to show in menu
3105 for ( i = 0; i < g_categorycount; i++ ) {
3107 if ( g_categories [ i ] -> parent_catname ) {
3108 sprintf ( fulllabel, "%s [%s]", g_categories [ i ] -> catname, g_categories [ i ] -> parent_catname );
3110 sprintf ( fulllabel, "%s", g_categories [ i ] -> catname );
3113 labels [ labelmax++ ] = strdup ( fulllabel );
3117 int sel = ui_modal_single_menu ( labels, labelmax, "Temporary Category Reveal",
3118 "Enter to select; other to return." );
3120 // if selected, try to set this guy to visible
3123 // fix up category name, if its been hacked
3124 #if 0 // prepending and .. wtf crap is this
3125 if ( strchr ( g_categories [ sel ] -> catname, '.' ) ) {
3126 char *t = g_categories [ sel ] -> catname;
3127 g_categories [ sel ] -> catname = strdup ( strchr ( g_categories [ sel ] -> catname, '.' ) + 1 );
3132 // reflag this guy to be visible
3133 g_categories [ sel ] -> catflags = CFNORMAL;
3135 // switch to the new category.. cache name.
3136 char *switch_to_name = g_categories [ sel ] -> catname;
3138 // republish categories
3139 category_publish ( CFNORMAL, NULL );
3141 // switch to the new category.. with the cached name!
3142 ui_category = category_index ( switch_to_name );
3144 // ensure visibility
3145 unsigned int screen_width = ui_display_context.screen_width;
3146 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
3147 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
3148 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
3153 // republish categories
3154 category_publish ( CFNORMAL, NULL );
3157 render_mask |= CHANGED_CATEGORY;
3162 void ui_recache_context ( ui_context_t *c ) {
3164 c -> screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
3166 c -> font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
3167 c -> font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
3168 c -> font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
3169 c -> font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
3171 c -> grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
3172 c -> grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
3174 c -> icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
3175 c -> icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
3176 c -> icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
3177 c -> icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
3178 c -> sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
3179 c -> sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
3181 c -> text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
3182 c -> text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
3183 c -> text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
3184 c -> text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
3185 c -> text_hilite_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
3187 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 4 );
3188 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
3190 c -> cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
3191 c -> cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
3193 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
3194 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
3195 c -> arrow_bar_clip_w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
3196 c -> arrow_bar_clip_h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
3197 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
3198 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
3199 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
3200 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
3203 SDL_Color tmp = { c -> font_rgba_r, c -> font_rgba_g, c -> font_rgba_b, c -> font_rgba_a };
3204 c -> fontcolor = tmp;
3206 // now that we've got 'normal' (detail pane shown) param's, lets check if detail pane
3207 // is hidden; if so, override some values with those alternate skin values where possible.
3208 if ( ui_detail_hidden ) {
3209 // if detail panel is hidden, and theme cannot support it, unhide the bloody thing. (This may help
3210 // when someone is amid theme hacking or changing.)
3211 if ( ! ui_is_detail_hideable() ) {
3212 ui_detail_hidden = 0;
3216 if ( ui_detail_hidden ) {
3218 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max_w", c -> row_max );
3219 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max_w", c -> col_max );
3221 c -> cell_width = pnd_conf_get_as_int_d ( g_conf, "grid.cell_width_w", c -> cell_width );
3222 c -> cell_height = pnd_conf_get_as_int_d ( g_conf, "grid.cell_height_w", c -> cell_height );
3224 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x_w", 450 );
3225 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y_w", 100 );
3226 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x_w", 450 );
3227 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y_w", 80 );
3228 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x_w", 450 );
3229 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y_w", 80 );
3231 } // if detail hidden.. still.
3233 } // if detail hidden
3238 unsigned char ui_is_detail_hideable ( void ) {
3240 // if skin has a bit of info for wide-mode, we assume wide-mode is available
3241 if ( pnd_conf_get_as_char ( g_conf, "grid.row_max_w" ) != NULL ) {
3249 void ui_toggle_detail_pane ( void ) {
3251 // no bitmask trickery here; I like it to be stand-out obvious at 3am.
3253 if ( ui_detail_hidden ) {
3254 ui_detail_hidden = 0;
3256 ui_detail_hidden = 1;
3259 // repull skin config
3260 ui_recache_context ( &ui_display_context );
3263 render_mask |= CHANGED_EVERYTHING;
3268 void ui_menu_context ( mm_appref_t *a ) {
3270 unsigned char rescan_apps = 0;
3271 unsigned char context_alive = 1;
3276 context_file_delete,
3279 context_app_recategorize,
3280 context_app_recategorize_sub,
3282 context_app_cpuspeed,
3290 char *verbiage[] = {
3291 "Done (return to grid)", // context_done
3292 "Get info about file/dir", // context_file_info
3293 "Delete file/dir", // context_file_delete
3294 "Get info", // context_app_info
3295 "Hide application", // hide
3296 "Recategorize", // recategorize
3297 "Recategorize subcategory", // recategorize
3298 "Change displayed title", // rename
3299 "Set CPU speed for launch", // cpuspeed
3300 "Run application", // run
3301 "Edit notes line 1", // notes1
3302 "Edit notes line 2", // notes2
3303 "Edit notes line 3", // notes3
3306 unsigned short int menu [ context_menu_max ];
3307 char *menustring [ context_menu_max ];
3308 unsigned char menumax = 0;
3311 menu [ menumax ] = context_done; menustring [ menumax++ ] = verbiage [ context_done ];
3313 // hook up appropriate menu options based on tab-type and object-type
3314 if ( g_categories [ ui_category ] -> fspath ) {
3316 menu [ menumax ] = context_file_info; menustring [ menumax++ ] = verbiage [ context_file_info ];
3317 menu [ menumax ] = context_file_delete; menustring [ menumax++ ] = verbiage [ context_file_delete ];
3320 if ( a -> ref -> object_type == pnd_object_type_directory ) {
3321 return; // don't do anything if the guy is a subcat-as-folder
3324 //menu [ menumax ] = context_app_info; menustring [ menumax++ ] = verbiage [ context_app_info ];
3325 menu [ menumax ] = context_app_run; menustring [ menumax++ ] = verbiage [ context_app_run ];
3326 menu [ menumax ] = context_app_hide; menustring [ menumax++ ] = verbiage [ context_app_hide ];
3327 menu [ menumax ] = context_app_recategorize; menustring [ menumax++ ] = verbiage [ context_app_recategorize ];
3328 menu [ menumax ] = context_app_recategorize_sub; menustring [ menumax++ ] = verbiage [ context_app_recategorize_sub ];
3329 menu [ menumax ] = context_app_rename; menustring [ menumax++ ] = verbiage [ context_app_rename ];
3330 menu [ menumax ] = context_app_cpuspeed; menustring [ menumax++ ] = verbiage [ context_app_cpuspeed ];
3331 menu [ menumax ] = context_app_notes1; menustring [ menumax++ ] = verbiage [ context_app_notes1 ];
3332 menu [ menumax ] = context_app_notes2; menustring [ menumax++ ] = verbiage [ context_app_notes2 ];
3333 menu [ menumax ] = context_app_notes3; menustring [ menumax++ ] = verbiage [ context_app_notes3 ];
3337 while ( context_alive ) {
3339 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 */ );
3346 switch ( menu [ sel ] ) {
3352 case context_file_info:
3355 case context_file_delete:
3356 //ui_menu_twoby ( "Delete - Are you sure?", "B/enter; other to cancel", "Delete", "Do not delete" );
3359 case context_app_info:
3362 case context_app_hide:
3365 char confkey [ 1000 ];
3366 snprintf ( confkey, 999, "%s.%s", "appshow", a -> ref -> unique_id );
3369 pnd_conf_set_char ( g_conf, confkey, "0" );
3371 // write conf, so it will take next time
3372 conf_write ( g_conf, conf_determine_location ( g_conf ) );
3374 // can we just 'hide' this guy without reloading all apps? (this is for you, EvilDragon)
3377 // DOESN'T WORK YET; other parts of app are still hanging onto some values and blow up
3379 char *uid = strdup ( a -> ref -> unique_id );
3381 for ( i = 0; i < g_categorycount; i++ ) {
3382 mm_appref_t *p = g_categories [ i ] -> refs;
3387 if ( strcmp ( p -> ref -> unique_id, uid ) == 0 ) {
3389 if ( g_categories [ i ] -> refcount ) {
3390 g_categories [ i ] -> refcount--;
3395 } // while for each appref
3396 } // for each cat/tab
3401 // request rescan and wrap up
3405 context_alive = 0; // nolonger visible, so lets just get out
3411 case context_app_recategorize:
3414 unsigned char optmax = 0;
3417 // show custom categories
3418 if ( mmcustom_setup() ) {
3420 for ( i = 0; i < mmcustom_count; i++ ) {
3421 if ( mmcustom_complete [ i ].parent_cat == NULL ) {
3422 opts [ optmax++ ] = mmcustom_complete [ i ].cat;
3428 // show FD categories
3429 i = 2; // skip first two - Other and NoParentCategory
3432 if ( ! freedesktop_complete [ i ].cat ) {
3436 if ( ! freedesktop_complete [ i ].parent_cat ) {
3437 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3444 char prompt [ 101 ];
3445 snprintf ( prompt, 100, "Pick category [%s]", a -> ref -> main_category ? a -> ref -> main_category : "NoParentCategory" );
3447 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select parent category"*/, "Enter to select; other to skip." );
3450 char confirm [ 1001 ];
3451 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3453 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm categorization", "Do not set category" ) == 1 ) {
3454 ovr_replace_or_add ( a, "maincategory", opts [ sel ] );
3456 // when changing main cat, reset subcat, otherwise you go from Game/Emu to Network/Emu and get sent to Other right away
3457 ovr_replace_or_add ( a, "maincategorysub1", freedesktop_complete [ 2 ].cat );
3462 if ( mmcustom_is_ready() ) {
3463 mmcustom_shutdown();
3469 case context_app_recategorize_sub:
3472 unsigned char optmax = 0;
3473 unsigned char i = 0;
3475 char *whichparentarewe;
3476 if ( g_categories [ ui_category ] -> parent_catname ) {
3477 whichparentarewe = g_categories [ ui_category ] -> parent_catname;
3479 whichparentarewe = g_categories [ ui_category ] -> catname;
3482 // add NoSubcategory magic one
3483 opts [ optmax++ ] = freedesktop_complete [ 2 ].cat;
3485 // add custom categories
3486 if ( mmcustom_setup() ) {
3488 for ( i = 0; i < mmcustom_count; i++ ) {
3489 if ( mmcustom_complete [ i ].parent_cat && strcmp ( mmcustom_complete [ i ].parent_cat, whichparentarewe ) == 0 ) {
3490 opts [ optmax++ ] = mmcustom_complete [ i ].cat;
3496 // add FD categories
3499 if ( ! freedesktop_complete [ i ].cat ) {
3503 if ( ( freedesktop_complete [ i ].parent_cat ) &&
3504 ( strcasecmp ( freedesktop_complete [ i ].parent_cat, whichparentarewe ) == 0 )
3507 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3513 char prompt [ 101 ];
3514 //snprintf ( prompt, 100, "Currently: %s", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory" );
3515 snprintf ( prompt, 100, "%s [%s]", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory", whichparentarewe );
3517 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select subcategory"*/, "Enter to select; other to skip." );
3520 char confirm [ 1001 ];
3521 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3523 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm sub-categorization", "Do not set sub-category" ) == 1 ) {
3524 ovr_replace_or_add ( a, "maincategorysub1", opts [ sel ] );
3530 if ( mmcustom_is_ready() ) {
3531 mmcustom_shutdown();
3537 case context_app_rename:
3539 char namebuf [ 101 ];
3540 unsigned char changed;
3542 changed = ui_menu_get_text_line ( "Rename application", "Use keyboard; Enter when done.",
3543 a -> ref -> title_en ? a -> ref -> title_en : "blank", namebuf, 30, 0 /* alphanumeric */ );
3546 char confirm [ 1001 ];
3547 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3549 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm rename", "Do not rename" ) == 1 ) {
3550 ovr_replace_or_add ( a, "title", namebuf );
3560 case context_app_cpuspeed:
3562 char namebuf [ 101 ];
3563 unsigned char changed;
3565 changed = ui_menu_get_text_line ( "Specify runspeed", "Use keyboard; Enter when done.",
3566 a -> ref -> clockspeed ? a -> ref -> clockspeed : "500", namebuf, 6, 1 /* numeric */ );
3569 char confirm [ 1001 ];
3570 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3572 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm clockspeed", "Do not set" ) == 1 ) {
3573 ovr_replace_or_add ( a, "clockspeed", namebuf );
3583 case context_app_run:
3587 case context_app_notes1:
3588 case context_app_notes2:
3589 case context_app_notes3:
3591 char namebuf [ 101 ] = "";
3594 unsigned char notenum;
3597 if ( menu [ sel ] == context_app_notes1 ) {
3599 } else if ( menu [ sel ] == context_app_notes2 ) {
3601 } else if ( menu [ sel ] == context_app_notes3 ) {
3605 // figure out key for looking up existing, and for storing replacement
3606 snprintf ( key, 500, "Application-%u.note-%u", a -> ref -> subapp_number, notenum );
3608 // do we have existing value?
3610 char *existing = pnd_conf_get_as_char ( a -> ovrh, key );
3612 strncpy ( namebuf, existing, 100 );
3616 unsigned char changed;
3618 changed = ui_menu_get_text_line ( "Enter replacement note", "Use keyboard; Enter when done.",
3619 namebuf, namebuf, 30, 0 /* not-numeric-forced */ );
3622 ovr_replace_or_add ( a, strchr ( key, '.' ) + 1, namebuf );
3634 } // if useful return
3639 if ( rescan_apps ) {
3640 applications_free();
3641 applications_scan();
3647 unsigned char ui_menu_oneby ( char *title, char *footer, char *one ) {
3650 int sel = ui_modal_single_menu ( opts, 1, title, footer );
3657 unsigned char ui_menu_twoby ( char *title, char *footer, char *one, char *two ) {
3661 int sel = ui_modal_single_menu ( opts, 2, title, footer );
3668 unsigned char ui_menu_get_text_line ( char *title, char *footer, char *initialvalue,
3669 char *r_buffer, unsigned char maxlen, unsigned char numbersonlyp )
3671 SDL_Rect rects [ 40 ];
3672 SDL_Rect *dest = rects;
3676 char hacktext [ 1024 ];
3677 unsigned char shifted = 0;
3679 bzero ( rects, sizeof(SDL_Rect) * 40 );
3681 if ( initialvalue ) {
3682 if ( initialvalue == r_buffer ) {
3683 // already good to go
3685 strncpy ( r_buffer, initialvalue, maxlen );
3688 bzero ( r_buffer, maxlen );
3694 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3695 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3696 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
3697 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
3698 SDL_FillRect( sdl_realscreen, dest, 0 );
3700 // show dialog background
3701 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
3704 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
3705 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
3706 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3707 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3708 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
3712 // show dialog frame
3713 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
3714 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3715 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3716 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
3722 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
3723 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3724 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
3725 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3726 SDL_FreeSurface ( rtext );
3732 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
3733 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3734 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
3735 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
3737 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3738 SDL_FreeSurface ( rtext );
3742 // show text line - and embed cursor
3743 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3744 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( 0/*i*/ + 1 - 0/*first_visible*/ ) );
3746 strncpy ( hacktext, r_buffer, 1000 );
3747 strncat ( hacktext, "\n", 1000 ); // add [] in most fonts
3749 rtext = TTF_RenderText_Blended ( g_tab_font, hacktext, ui_display_context.fontcolor );
3750 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3751 SDL_FreeSurface ( rtext );
3754 // update all the rects and send it all to sdl
3755 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
3760 while ( SDL_WaitEvent ( &event ) ) {
3762 switch ( event.type ) {
3765 if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
3772 if ( event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_BACKSPACE ) {
3773 if ( strlen ( r_buffer ) > 0 ) {
3774 char *eol = strchr ( r_buffer, '\0' );
3775 *( eol - 1 ) = '\0';
3778 } else if ( event.key.keysym.sym == SDLK_UP ) {
3779 r_buffer [ 0 ] = '\0'; // truncate!
3781 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
3784 } else if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
3787 } else if ( event.key.keysym.sym == SDLK_ESCAPE ||
3788 event.key.keysym.sym == SDLK_PAGEUP ||
3789 event.key.keysym.sym == SDLK_PAGEDOWN ||
3790 event.key.keysym.sym == SDLK_HOME
3797 if ( isprint(event.key.keysym.sym) ) {
3799 unsigned char good = 1;
3801 if ( numbersonlyp && ( ! isdigit(event.key.keysym.sym) ) ) {
3805 if ( maxlen && strlen(r_buffer) >= maxlen ) {
3810 char b [ 2 ] = { '\0', '\0' };
3812 b [ 0 ] = toupper ( event.key.keysym.sym );
3814 b [ 0 ] = event.key.keysym.sym;
3816 strncat ( r_buffer, b, maxlen );
3829 } // while waiting for input
3836 unsigned char ovr_replace_or_add ( mm_appref_t *a, char *keybase, char *newvalue ) {
3837 //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 );
3839 char fullpath [ PATH_MAX ];
3841 sprintf ( fullpath, "%s/%s", a -> ref -> object_path, a -> ref -> object_filename );
3842 char *dot = strrchr ( fullpath, '.' );
3844 sprintf ( dot, PXML_SAMEPATH_OVERRIDE_FILEEXT );
3846 pnd_log ( pndn_error, "ERROR: Bad pnd-path in disco_t! %s\n", fullpath );
3850 struct stat statbuf;
3852 if ( stat ( fullpath, &statbuf ) == 0 ) {
3856 h = pnd_conf_fetch_by_path ( fullpath );
3859 return ( 0 ); // fail!
3863 snprintf ( key, 100, "Application-%u.%s", a -> ref -> subapp_number, keybase );
3865 pnd_conf_set_char ( h, key, newvalue );
3867 return ( pnd_conf_write ( h, fullpath ) );
3870 // file needs to be created - easy!
3872 FILE *f = fopen ( fullpath, "w" );
3875 fprintf ( f, "Application-%u.%s\t%s\n", a -> ref -> subapp_number, keybase, newvalue );
3879 return ( 0 ); // fail!
3887 void ui_manage_categories ( void ) {
3888 unsigned char require_app_scan = 0;
3890 if ( ! mmcustom_setup() ) {
3894 char *opts [ 20 ] = {
3895 "List custom categories",
3896 "List custom subcategories",
3897 "Register custom category",
3898 "Register custom subcategory",
3899 "Unregister custom category",
3900 "Unregister custom subcategory",
3906 int sel = ui_modal_single_menu ( opts, 7, "Custom Categories", "B to select; other to cancel." );
3910 case 0: // list custom
3911 if ( mmcustom_count ) {
3912 ui_pick_custom_category ( 0 );
3914 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
3918 case 1: // list custom sub
3919 if ( mmcustom_count ) {
3921 char *maincat = ui_pick_custom_category ( 0 );
3924 unsigned int subcount = mmcustom_count_subcats ( maincat );
3925 char titlebuf [ 201 ];
3927 snprintf ( titlebuf, 200, "Category: %s", maincat );
3929 if ( subcount == 0 ) {
3930 ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
3933 char **list = malloc ( subcount * sizeof(char*) );
3935 unsigned int counter = 0;
3937 for ( i = 0; i < mmcustom_count; i++ ) {
3938 if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
3939 list [ counter++ ] = mmcustom_complete [ i ].cat;
3943 ui_modal_single_menu ( list, counter, titlebuf, "Any button to exit." );
3947 } // more than 0 subcats?
3949 } // user picked a main cat?
3952 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
3956 case 2: // register custom
3958 unsigned char changed;
3959 char namebuf [ 101 ] = "";
3961 changed = ui_menu_get_text_line ( "Enter unique category name", "Use keyboard; Enter when done.",
3962 "Pandora", namebuf, 30, 0 /* alphanumeric */ );
3964 // did the user enter something?
3967 // and if so, is it existant already or not?
3968 if ( mmcustom_query ( namebuf, NULL ) ) {
3969 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a registered category." );
3970 } else if ( freedesktop_category_query ( namebuf, NULL ) ) {
3971 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard category." );
3974 char confirm [ 1001 ];
3975 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3977 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
3978 // register, save, recycle the current list
3979 mmcustom_register ( namebuf, NULL );
3980 mmcustom_write ( NULL );
3981 mmcustom_shutdown();
3987 } // entered something?
3992 case 3: // register custom sub
3993 if ( mmcustom_count ) {
3995 char *maincat = ui_pick_custom_category ( 1 /* include FD */ );
3998 char titlebuf [ 201 ];
4000 snprintf ( titlebuf, 200, "Subcat of: %s", maincat );
4002 unsigned char changed;
4003 char namebuf [ 101 ] = "";
4005 changed = ui_menu_get_text_line ( titlebuf, "Use keyboard; Enter when done.", "Submarine", namebuf, 30, 0 /* alphanumeric */ );
4007 // did the user enter something?
4010 // and if so, is it existant already or not?
4011 if ( mmcustom_query ( namebuf, maincat ) ) {
4012 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a subcategory." );
4013 } else if ( freedesktop_category_query ( namebuf, maincat ) ) {
4014 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard subcategory." );
4017 char confirm [ 1001 ];
4018 snprintf ( confirm, 1000, "Confirm: %s [%s]", namebuf, maincat );
4020 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
4021 // register, save, recycle the current list
4022 mmcustom_register ( namebuf, maincat );
4023 mmcustom_write ( NULL );
4024 mmcustom_shutdown();
4030 } // entered something?
4032 } // selected parent cat?
4035 ui_menu_oneby ( "Warning", "B/Enter to accept", "No categories registered." );
4039 case 4: // unreg custom
4040 if ( mmcustom_count ) {
4041 char *maincat = ui_pick_custom_category ( 0 );
4044 char confirm [ 1001 ];
4045 snprintf ( confirm, 1000, "Confirm remove: %s", maincat );
4047 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
4048 // register, save, recycle the current list
4049 mmcustom_unregister ( maincat, NULL );
4050 mmcustom_write ( NULL );
4051 mmcustom_shutdown();
4058 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4062 case 5: // unreg custom sub
4063 if ( mmcustom_count ) {
4064 char *maincat = ui_pick_custom_category ( 0 );
4067 unsigned int subcount = mmcustom_count_subcats ( maincat );
4068 char titlebuf [ 201 ];
4070 snprintf ( titlebuf, 200, "Category: %s", maincat );
4072 if ( subcount == 0 ) {
4073 ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
4076 char **list = malloc ( subcount * sizeof(char*) );
4078 unsigned int counter = 0;
4080 for ( i = 0; i < mmcustom_count; i++ ) {
4081 if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
4082 list [ counter++ ] = mmcustom_complete [ i ].cat;
4086 int sel = ui_modal_single_menu ( list, counter, titlebuf, "B to selct; other to exit." );
4089 char confirm [ 1001 ];
4090 snprintf ( confirm, 1000, "Confirm remove: %s", list [ sel ] );
4092 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
4093 // register, save, recycle the current list
4094 mmcustom_unregister ( list [ sel ], maincat );
4095 mmcustom_write ( NULL );
4096 mmcustom_shutdown();
4104 } // more than 0 subcats?
4106 } // user picked a main cat?
4109 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4116 if ( sel < 0 || sel > 5 ) {
4120 } // while running the menu
4122 // shut down custom cats
4123 mmcustom_shutdown();
4126 if ( require_app_scan ) {
4127 applications_free();
4128 applications_scan();
4132 render_mask |= CHANGED_EVERYTHING;
4137 char *ui_pick_custom_category ( unsigned char include_fd ) {
4140 unsigned int counter = 0;
4143 list = malloc ( (mmcustom_count+freedesktop_count()) * sizeof(char*) );
4145 list = malloc ( mmcustom_count * sizeof(char*) );
4149 for ( i = 0; i < mmcustom_count; i++ ) {
4150 if ( mmcustom_complete [ i ].parent_cat == NULL ) {
4151 list [ counter++ ] = mmcustom_complete [ i ].cat;
4160 if ( ! freedesktop_complete [ i ].cat ) {
4164 if ( freedesktop_complete [ i ].parent_cat == NULL ) {
4165 list [ counter++ ] = freedesktop_complete [ i ].cat;
4172 int sel = ui_modal_single_menu ( list, counter, "Custom Main Categories", "Any button to exit." );
4179 char *foo = list [ sel ];