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", },
243 { IMG_SUBCATFOLDER, "graphics.IMG_SUBCATFOLDER", "graphics.IMG_FOLDER", },
244 { IMG_DOTDOTFOLDER, "graphics.IMG_DOTDOTFOLDER", "graphics.IMG_FOLDER", },
248 unsigned char ui_imagecache ( char *basepath ) {
250 char fullpath [ PATH_MAX ];
255 for ( i = 0; i < IMG_MAX; i++ ) {
257 if ( g_imagecache [ i ].id != i ) {
258 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
262 for ( try = 0; try < 2; try++ ) {
267 filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
269 if ( g_imagecache [ i ].alt_confname ) {
270 filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].alt_confname );
277 pnd_log ( pndn_error, "ERROR: (Try %u) Missing filename in conf for key: %s\n", try + 1, g_imagecache [ i ].confname );
278 if ( try == 0 ) { continue; } else { return ( 0 ); }
281 if ( filename [ 0 ] == '/' ) {
282 strncpy ( fullpath, filename, PATH_MAX );
284 sprintf ( fullpath, "%s/%s", basepath, filename );
287 if ( ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
288 break; // no retry needed
290 pnd_log ( pndn_error, "ERROR: (Try %u) Couldn't load static cache image: %s\n", try + 1, fullpath );
291 if ( try == 0 ) { continue; } else { return ( 0 ); }
299 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
300 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
306 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 );
307 // scale text hilight
308 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 );
309 // scale preview no-pic
310 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
311 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
312 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
314 // set alpha on detail panel
315 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
320 void ui_render ( void ) {
323 // divide width: 550 / 250
324 // divide left side: 5 columns == 110px width
325 // 20px buffer either side == 70px wide icon + 20 + 20?
327 // what jobs to do during render?
331 #define R_TABS (1<<1)
332 #define R_DETAIL (1<<2)
333 #define R_GRID (1<<3)
335 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
337 unsigned int render_jobs_b = 0;
339 if ( render_mask & CHANGED_EVERYTHING ) {
340 render_jobs_b |= R_ALL;
343 if ( render_mask & CHANGED_SELECTION ) {
344 render_jobs_b |= R_GRID;
345 render_jobs_b |= R_DETAIL;
348 if ( render_mask & CHANGED_CATEGORY ) {
349 render_jobs_b |= R_ALL;
352 render_mask = CHANGED_NOTHING;
356 unsigned int icon_rows;
359 SDL_Rect rects [ MAXRECTS ], src;
360 SDL_Rect *dest = rects;
361 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
363 unsigned int row, displayrow, col;
364 mm_appref_t *appiter;
366 ui_context_t *c = &ui_display_context; // for convenience and shorthand
368 // how many total rows do we need?
369 if ( g_categorycount ) {
370 icon_rows = g_categories [ ui_category ] -> refcount / c -> col_max;
371 if ( g_categories [ ui_category ] -> refcount % c -> col_max > 0 ) {
379 // if no selected app yet, select the first one
380 if ( ! ui_selected && pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) ) {
381 ui_selected = g_categories [ ui_category ] -> refs;
385 // reset touchscreen regions
386 if ( render_jobs_b ) {
390 // ensure selection is visible
393 unsigned char autoscrolled = 1;
394 while ( autoscrolled ) {
397 int index = ui_selected_index();
398 int topleft = c -> col_max * ui_rows_scrolled_down;
399 int botright = ( c -> col_max * ( ui_rows_scrolled_down + c -> row_max ) - 1 );
401 if ( index < topleft ) {
402 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
403 render_jobs_b |= R_ALL;
405 } else if ( index > botright ) {
406 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
407 render_jobs_b |= R_ALL;
411 } // while autoscrolling
413 if ( ui_rows_scrolled_down < 0 ) {
414 ui_rows_scrolled_down = 0;
415 } else if ( ui_rows_scrolled_down > icon_rows ) {
416 ui_rows_scrolled_down = icon_rows;
422 if ( render_jobs_b & R_BG ) {
424 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
427 dest -> w = sdl_realscreen -> w;
428 dest -> h = sdl_realscreen -> h;
429 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
434 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
437 dest -> w = sdl_realscreen -> w;
438 dest -> h = sdl_realscreen -> h;
439 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
446 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
447 static unsigned int tab_width;
448 static unsigned int tab_height;
449 static unsigned int tab_offset_x;
450 static unsigned int tab_offset_y;
451 static unsigned int text_offset_x;
452 static unsigned int text_offset_y;
453 static unsigned int text_width;
455 static unsigned char tab_first_run = 1;
456 if ( tab_first_run ) {
458 tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
459 tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
460 tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
461 tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
462 text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
463 text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
464 text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
467 unsigned int maxtab = ( c -> screen_width / tab_width ) < g_categorycount ? ( c -> screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
468 unsigned int maxtabspot = ( c -> screen_width / tab_width );
470 if ( g_categorycount > 0 ) {
472 // draw tabs with categories
473 for ( col = ui_catshift;
480 // if this is the first (leftmost) tab, we use different artwork
481 // than if the other tabs (so skinner can link lines up nicely.)
482 if ( col == ui_catshift ) {
483 // leftmost tab, special case
485 if ( col == ui_category ) {
486 s = g_imagecache [ IMG_TAB_SEL_L ].i;
488 s = g_imagecache [ IMG_TAB_UNSEL_L ].i;
491 } else if ( col == maxtab - 1 ) {
492 // rightmost tab, special case
494 if ( col == ui_category ) {
495 s = g_imagecache [ IMG_TAB_SEL_R ].i;
497 s = g_imagecache [ IMG_TAB_UNSEL_R ].i;
501 // normal (not leftmost) tab
503 if ( col == ui_category ) {
504 s = g_imagecache [ IMG_TAB_SEL ].i;
506 s = g_imagecache [ IMG_TAB_UNSEL ].i;
509 } // first col, or not first col?
516 if ( col == ui_category ) {
517 src.h = tab_selheight;
525 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
526 dest -> y = tab_offset_y;
529 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
531 if ( render_jobs_b & R_TABS ) {
532 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
533 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
537 if ( col == ui_category ) {
538 // no line for selected tab
540 if ( col - ui_catshift == 0 ) {
541 s = g_imagecache [ IMG_TAB_LINEL ].i;
542 } else if ( col - ui_catshift == maxtabspot - 1 ) {
543 s = g_imagecache [ IMG_TAB_LINER ].i;
545 s = g_imagecache [ IMG_TAB_LINE ].i;
547 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
548 dest -> y = tab_offset_y + tab_height;
549 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
555 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ] -> catname, c -> fontcolor );
558 src.w = rtext -> w < text_width ? rtext -> w : text_width;
560 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
561 dest -> y = tab_offset_y + text_offset_y;
562 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
563 SDL_FreeSurface ( rtext );
570 } // if we got categories
572 if ( render_jobs_b & R_TABS ) {
574 // draw tab lines under where tabs would be if we had categories
575 for ( /* foo */; col < maxtabspot; col++ ) {
578 if ( col - ui_catshift == 0 ) {
579 s = g_imagecache [ IMG_TAB_LINEL ].i;
580 } else if ( col - ui_catshift == maxtabspot - 1 ) {
581 s = g_imagecache [ IMG_TAB_LINER ].i;
583 s = g_imagecache [ IMG_TAB_LINE ].i;
585 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
586 dest -> y = tab_offset_y + tab_height;
587 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
596 // scroll bars and arrows
597 if ( render_jobs_b & R_BG ) {
598 unsigned char show_bar = 0;
601 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
602 dest -> x = c -> arrow_up_x;
603 dest -> y = c -> arrow_up_y;
604 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
611 if ( ui_rows_scrolled_down + c -> row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
612 dest -> x = c -> arrow_down_x;
613 dest -> y = c -> arrow_down_y;
614 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
621 // show scrollbar as well
624 src.w = c -> arrow_bar_clip_w;
625 src.h = c -> arrow_bar_clip_h;
626 dest -> x = c -> arrow_bar_x;
627 dest -> y = c -> arrow_bar_y;
628 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
632 } // r_bg, scroll bars
634 // render detail pane bg
635 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
637 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
640 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
641 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
642 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
643 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
644 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
645 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
646 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
647 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
651 // render detail pane
652 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
653 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
654 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
655 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
659 } // detailpane frame/bg
663 // anything to render?
664 if ( render_jobs_b & R_GRID && g_categorycount ) {
666 // if just rendering grid, and nothing else, better clear it first
667 if ( ! ( render_jobs_b & R_BG ) ) {
668 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
669 src.x = c -> grid_offset_x;
670 src.y = c -> grid_offset_y + c -> sel_icon_offset_y;
671 src.w = c -> col_max * c -> cell_width;
672 src.h = c -> row_max * c -> cell_height;
674 dest -> x = c -> grid_offset_x;
675 dest -> y = c -> grid_offset_y + c -> sel_icon_offset_y;
677 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
683 if ( g_categories [ ui_category ] -> refs ) {
685 appiter = g_categories [ ui_category ] -> refs;
689 // until we run out of apps, or run out of space
690 while ( appiter != NULL ) {
692 for ( col = 0; col < c -> col_max && appiter != NULL; col++ ) {
694 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
695 if ( row >= ui_rows_scrolled_down ) {
697 // selected? show hilights
698 if ( appiter == ui_selected ) {
699 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
701 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
702 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + c -> sel_icon_offset_x;
703 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
704 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + c -> sel_icon_offset_y;
705 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
708 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
709 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_hilite_offset_y;
710 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
715 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
716 SDL_Surface *iconsurface;
718 iconsurface = ic -> i;
720 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
722 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
723 // filesystem (file or directory icon)
724 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
725 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
727 // is this a subcat, a .., or a filesystem folder?
728 //iconsurface = g_imagecache [ IMG_FOLDER ].i;
729 if ( g_categories [ ui_category ] -> fspath ) {
730 iconsurface = g_imagecache [ IMG_FOLDER ].i;
731 } else if ( strcmp ( appiter -> ref -> title_en, ".." ) == 0 ) {
732 iconsurface = g_imagecache [ IMG_DOTDOTFOLDER ].i;
734 iconsurface = g_imagecache [ IMG_SUBCATFOLDER ].i;
738 iconsurface = g_imagecache [ IMG_EXECBIN ].i;
741 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
746 // got an icon I hope?
748 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
754 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + (( c -> icon_max_width - iconsurface -> w ) / 2);
755 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + (( c -> icon_max_height - iconsurface -> h ) / 2);
757 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
760 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
767 if ( appiter -> ref -> title_en ) {
769 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, c -> fontcolor );
772 src.w = c -> text_width < rtext -> w ? c -> text_width : rtext -> w;
774 if ( rtext -> w > c -> text_width ) {
775 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
777 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_offset_x - ( rtext -> w / 2 );
779 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_offset_y;
780 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
781 SDL_FreeSurface ( rtext );
785 } // display now? or scrolled away..
788 appiter = appiter -> next;
790 } // for column 1...X
792 if ( row >= ui_rows_scrolled_down ) {
798 // are we done displaying rows?
799 if ( displayrow >= c -> row_max ) {
806 // no apps to render?
807 pnd_log ( pndn_rem, "No applications to render?\n" );
812 // detail panel - show app details or blank-message
813 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
815 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
816 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
817 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
819 unsigned int desty = cell_offset_y;
826 if ( ui_selected -> ref -> title_en ) {
828 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, c -> fontcolor );
831 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
833 dest -> x = cell_offset_x;
835 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
836 SDL_FreeSurface ( rtext );
843 if ( ui_selected -> ref -> main_category ) {
845 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
848 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
851 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
853 dest -> x = cell_offset_x;
855 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
856 SDL_FreeSurface ( rtext );
863 if ( ui_selected -> ref -> clockspeed ) {
865 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
868 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
871 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
873 dest -> x = cell_offset_x;
875 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
876 SDL_FreeSurface ( rtext );
881 // show sub-app# on right side of cpu clock?
882 //if ( ui_selected -> ref -> subapp_number )
884 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
887 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
888 dest -> x = cell_offset_x + cell_width - rtext -> w;
889 dest -> y = desty - src.h;
890 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
891 SDL_FreeSurface ( rtext );
896 #if 0 // merged into hint-line
897 if ( ui_selected -> ref -> info_filename ) {
899 sprintf ( buffer, "Documentation - hit Y" );
902 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
905 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
907 dest -> x = cell_offset_x;
909 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
910 SDL_FreeSurface ( rtext );
917 if ( ui_selected -> ovrh ) {
922 desty += 5; // a touch of spacing can't hurt
924 for ( i = 1; i < 4; i++ ) {
925 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
926 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
930 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, c -> fontcolor );
933 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
935 dest -> x = cell_offset_x;
937 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
938 SDL_FreeSurface ( rtext );
944 } // r_detail -> notes
947 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
948 SDL_Surface *previewpic;
951 previewpic = ic -> i;
953 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
957 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
958 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
959 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
960 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
966 char *empty_message = "Press SELECT for menu";
970 rtext = TTF_RenderText_Blended ( g_detailtext_font, empty_message, c -> fontcolor );
974 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
976 dest -> x = cell_offset_x;
978 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
979 SDL_FreeSurface ( rtext );
984 rtext = TTF_RenderText_Blended ( g_detailtext_font, "START or B to run app", c -> fontcolor );
985 dest -> x = cell_offset_x;
987 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
988 SDL_FreeSurface ( rtext );
992 rtext = TTF_RenderText_Blended ( g_detailtext_font, "SPACE for app menu", c -> fontcolor );
993 dest -> x = cell_offset_x;
995 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
996 SDL_FreeSurface ( rtext );
1000 rtext = TTF_RenderText_Blended ( g_detailtext_font, "A to toggle details", c -> fontcolor );
1001 dest -> x = cell_offset_x;
1003 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1004 SDL_FreeSurface ( rtext );
1008 } // r_detail && selected?
1016 if ( render_jobs_b & R_BG ) {
1017 static int last_battlevel = 0;
1018 static unsigned char batterylevel = 0;
1019 char buffer [ 100 ];
1021 if ( time ( NULL ) - last_battlevel > 60 ) {
1022 batterylevel = pnd_device_get_battery_gauge_perc();
1023 last_battlevel = time ( NULL );
1026 sprintf ( buffer, "Battery: %u%%", batterylevel );
1029 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1030 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
1031 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
1032 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1033 SDL_FreeSurface ( rtext );
1038 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
1040 unsigned int hintx, hinty;
1041 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
1042 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
1043 static unsigned int lastwidth = 3000;
1045 if ( ui_selected && ui_selected -> ref -> info_filename ) {
1046 buffer = "Documentation - hit Y";
1048 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
1052 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1055 if ( ! ( render_jobs_b & R_BG ) ) {
1062 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
1064 lastwidth = rtext -> w;
1070 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1071 SDL_FreeSurface ( rtext );
1076 if ( render_jobs_b & R_BG &&
1077 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
1081 time_t t = time ( NULL );
1082 struct tm *tm = localtime ( &t );
1083 strftime ( buffer, 50, "%a %H:%M %F", tm );
1086 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1087 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
1088 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
1089 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1090 SDL_FreeSurface ( rtext );
1094 // update all the rects and send it all to sdl
1095 // - at this point, we could probably just do 1 rect, of the
1096 // whole screen, and be faster :/
1097 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1101 void ui_process_input ( pnd_dbusnotify_handle dbh, pnd_notify_handle nh ) {
1104 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
1105 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
1107 while ( ( ! ui_event ) &&
1108 /*block_p ?*/ SDL_WaitEvent ( &event ) /*: SDL_PollEvent ( &event )*/ )
1111 switch ( event.type ) {
1116 // the user-defined SDL events are all for threaded/delayed previews (and icons, which
1117 // generally are not used); if we're in wide mode, we can skip previews
1118 // to avoid slowing things down when they're not shown.
1120 if ( event.user.code == sdl_user_ticker ) {
1122 if ( ui_detail_hidden ) {
1123 break; // skip building previews when not showing them
1126 // timer went off, time to load something
1127 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1129 if ( ! ui_selected ) {
1133 // load the preview pics now!
1134 pnd_disco_t *iter = ui_selected -> ref;
1136 if ( iter -> preview_pic1 ) {
1138 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
1139 // load in bg thread, make user experience chuggy
1141 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
1143 if ( ! g_preview_thread ) {
1144 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
1148 // load it now, make user wait
1150 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1151 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1154 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
1155 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1160 } // got a preview at all?
1165 } else if ( event.user.code == sdl_user_finishedpreview ) {
1167 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1168 // we finished another, no big woop
1169 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1173 } else if ( event.user.code == sdl_user_finishedicon ) {
1174 // redraw, so we can show the newly loaded icon
1177 } else if ( event.user.code == sdl_user_checksd ) {
1178 // check if any inotify-type events occured, forcing us to rescan/re-disco the SDs
1180 unsigned char watch_dbus = 0;
1181 unsigned char watch_inotify = 0;
1184 watch_dbus = pnd_dbusnotify_rediscover_p ( dbh );
1188 watch_inotify = pnd_notify_rediscover_p ( nh );
1191 if ( watch_dbus || watch_inotify ) {
1192 pnd_log ( pndn_debug, "dbusnotify detected SD event\n" );
1193 applications_free();
1194 applications_scan();
1201 render_mask |= CHANGED_EVERYTHING;
1205 #if 0 // joystick motion
1206 case SDL_JOYAXISMOTION:
1208 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1210 if ( event.jaxis.axis == 0 ) {
1212 if ( event.jaxis.value < 0 ) {
1214 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1215 } else if ( event.jaxis.value > 0 ) {
1216 ui_push_right ( 0 );
1217 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1219 } else if ( event.jaxis.axis == 1 ) {
1221 if ( event.jaxis.value < 0 ) {
1223 } else if ( event.jaxis.value > 0 ) {
1233 #if 0 // joystick buttons
1234 case SDL_JOYBUTTONDOWN:
1236 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1238 if ( event.jbutton.button == 0 ) { // B
1240 } else if ( event.jbutton.button == 1 ) { // Y
1242 } else if ( event.jbutton.button == 2 ) { // X
1244 } else if ( event.jbutton.button == 3 ) { // A
1247 } else if ( event.jbutton.button == 4 ) { // Select
1248 ui_mask |= uisb_select;
1249 } else if ( event.jbutton.button == 5 ) { // Start
1250 ui_mask |= uisb_start;
1252 } else if ( event.jbutton.button == 7 ) { // L
1254 } else if ( event.jbutton.button == 8 ) { // R
1263 case SDL_JOYBUTTONUP:
1265 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1267 if ( event.jbutton.button == 0 ) { // B
1270 } else if ( event.jbutton.button == 1 ) { // Y
1272 } else if ( event.jbutton.button == 2 ) { // X
1274 } else if ( event.jbutton.button == 3 ) { // A
1277 } else if ( event.jbutton.button == 4 ) { // Select
1278 ui_mask &= ~uisb_select;
1279 } else if ( event.jbutton.button == 5 ) { // Start
1280 ui_mask &= ~uisb_start;
1282 } else if ( event.jbutton.button == 7 ) { // L
1285 } else if ( event.jbutton.button == 8 ) { // R
1296 #if 1 // keyboard events
1300 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1302 // SDLK_LALT -> Start
1303 // page up/down for y/x
1304 // home/end for a and b
1307 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1308 ui_push_right ( 0 );
1310 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1313 } else if ( event.key.keysym.sym == SDLK_UP ) {
1316 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1319 } else if ( event.key.keysym.sym == SDLK_END ) { // B
1322 } else if ( event.key.keysym.sym == SDLK_SPACE ) { // space
1323 if ( ui_selected ) {
1324 ui_menu_context ( ui_selected );
1326 // TBD: post an error?
1328 render_mask |= CHANGED_EVERYTHING;
1330 } else if ( event.key.keysym.sym == SDLK_TAB || event.key.keysym.sym == SDLK_HOME ) { // tab or A
1331 // if detail panel is togglable, then toggle it
1332 // if not, make sure its ruddy well shown!
1333 if ( ui_is_detail_hideable() ) {
1334 ui_toggle_detail_pane();
1336 ui_detail_hidden = 0;
1339 } else if ( event.key.keysym.sym == SDLK_RSHIFT || event.key.keysym.sym == SDLK_COMMA ) { // left trigger or comma
1342 } else if ( event.key.keysym.sym == SDLK_RCTRL || event.key.keysym.sym == SDLK_PERIOD ) { // right trigger or period
1346 } else if ( event.key.keysym.sym == SDLK_PAGEUP ) { // Y
1348 if ( ui_selected ) {
1349 ui_show_info ( pnd_run_script, ui_selected -> ref );
1352 } else if ( event.key.keysym.sym == SDLK_PAGEDOWN ) { // X
1355 // forget the selection, nolonger applies
1357 ui_set_selected ( ui_selected );
1359 if ( g_categories [ ui_category ] -> fspath ) {
1360 category_fs_restock ( g_categories [ ui_category ] );
1363 render_mask |= CHANGED_EVERYTHING;
1366 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1370 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1371 char *opts [ 20 ] = {
1372 "Reveal hidden category",
1374 "Configure Minimenu",
1375 "Manage custom app categories",
1376 "Rescan for applications",
1377 "Cache previews to SD now",
1378 "Run a terminal/console",
1379 "Run another GUI (xfce, etc)",
1381 "Select a Minimenu skin",
1384 int sel = ui_modal_single_menu ( opts, 11, "Minimenu", "Enter to select; other to return." );
1386 char buffer [ 100 ];
1390 } else if ( sel == 1 ) {
1392 sprintf ( buffer, "sudo poweroff" );
1394 } else if ( sel == 2 ) {
1396 unsigned char restart = conf_run_menu ( NULL );
1397 conf_write ( g_conf, conf_determine_location ( g_conf ) );
1399 emit_and_quit ( MM_RESTART );
1401 } else if ( sel == 3 ) {
1402 // manage custom categories
1403 ui_manage_categories();
1404 } else if ( sel == 4 ) {
1406 pnd_log ( pndn_debug, "Freeing up applications\n" );
1407 applications_free();
1408 pnd_log ( pndn_debug, "Rescanning applications\n" );
1409 applications_scan();
1410 } else if ( sel == 5 ) {
1411 // cache preview to SD now
1412 extern pnd_box_handle g_active_apps;
1413 pnd_box_handle h = g_active_apps;
1415 unsigned int maxwidth, maxheight;
1416 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1417 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1419 pnd_disco_t *iter = pnd_box_get_head ( h );
1424 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1425 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1426 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1430 iter = pnd_box_get_next ( iter );
1433 } else if ( sel == 6 ) {
1436 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1440 ui_forkexec ( argv );
1443 } else if ( sel == 7 ) {
1444 char buffer [ PATH_MAX ];
1445 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
1446 emit_and_quit ( buffer );
1447 } else if ( sel == 8 ) {
1448 emit_and_quit ( MM_QUIT );
1449 } else if ( sel == 9 ) {
1451 if ( ui_pick_skin() ) {
1452 emit_and_quit ( MM_RESTART );
1454 } else if ( sel == 10 ) {
1456 char buffer [ PATH_MAX ];
1457 sprintf ( buffer, "%s/about.txt", g_skinpath );
1458 ui_aboutscreen ( buffer );
1462 render_mask |= CHANGED_EVERYTHING;
1465 // unknown SDLK_ keycode?
1467 // many SDLK_keycodes map to ASCII ("a" is ascii(a)), so try to jump to a filename of that name, in this category?
1468 // and if already there, try to jump to next, maybe?
1469 // future: look for sequence typing? ie: user types 'm' then 'a', look for 'ma*' instead of 'm' then 'a' matching
1470 if ( isalpha ( event.key.keysym.sym ) && g_categories [ ui_category ] -> refcount > 0 ) {
1471 mm_appref_t *app = g_categories [ ui_category ] -> refs;
1473 //fprintf ( stderr, "sel %s next %s\n", ui_selected -> ref -> title_en, ui_selected -> next -> ref -> title_en );
1475 // are we already matching the same char? and next item is also same char?
1476 if ( app && ui_selected && ui_selected -> next &&
1477 ui_selected -> ref -> title_en && ui_selected -> next -> ref -> title_en &&
1478 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( ui_selected -> next -> ref -> title_en [ 0 ] ) &&
1479 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym )
1482 // just skip down one
1483 app = ui_selected -> next;
1486 // walk the category, looking for a first-char match
1488 if ( app -> ref -> title_en && toupper ( app -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym ) ) {
1494 } // same start letter, or new run?
1496 // found something, or no?
1498 // looks like we found a potential match; try switching it to visible selection
1500 ui_set_selected ( ui_selected );
1505 } // SDLK_alphanumeric?
1511 if ( event.key.keysym.sym == SDLK_ESCAPE ) {
1512 emit_and_quit ( MM_QUIT );
1519 #if 1 // mouse / touchscreen
1521 case SDL_MOUSEBUTTONDOWN:
1522 if ( event.button.button == SDL_BUTTON_LEFT ) {
1523 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1529 case SDL_MOUSEBUTTONUP:
1530 if ( event.button.button == SDL_BUTTON_LEFT ) {
1531 ui_touch_act ( event.button.x, event.button.y );
1544 } // switch event type
1551 void ui_push_left ( unsigned char forcecoil ) {
1553 if ( ! ui_selected ) {
1554 ui_push_right ( 0 );
1558 // what column we in?
1559 unsigned int col = ui_determine_screen_col ( ui_selected );
1561 // are we already at first item?
1562 if ( forcecoil == 0 &&
1563 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1566 unsigned int i = ui_display_context.col_max - 1;
1567 while ( i && ui_selected -> next ) {
1568 ui_push_right ( 0 );
1572 } else if ( g_categories [ ui_category ] -> refs == ui_selected ) {
1573 // can't go any more left, we're at the head
1576 // figure out the previous item; yay for singly linked list :/
1577 mm_appref_t *i = g_categories [ ui_category ] -> refs;
1579 if ( i -> next == ui_selected ) {
1587 ui_set_selected ( ui_selected );
1592 void ui_push_right ( unsigned char forcecoil ) {
1594 if ( ui_selected ) {
1596 // what column we in?
1597 unsigned int col = ui_determine_screen_col ( ui_selected );
1600 if ( forcecoil == 0 &&
1601 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1602 // and selected is far-right, or last icon in category (might not be far right)
1603 ( ( col == ui_display_context.col_max - 1 ) ||
1604 ( ui_selected -> next == NULL ) )
1608 //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1609 while ( col /*i*/ ) {
1615 // just go to the next
1617 if ( ui_selected -> next ) {
1618 ui_selected = ui_selected -> next;
1624 ui_selected = g_categories [ ui_category ] -> refs;
1627 ui_set_selected ( ui_selected );
1632 void ui_push_up ( void ) {
1633 unsigned char col_max = ui_display_context.col_max;
1635 if ( ! ui_selected ) {
1640 unsigned int row = ui_determine_row ( ui_selected );
1643 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1645 // wrap around instead
1647 unsigned int col = ui_determine_screen_col ( ui_selected );
1650 ui_selected = g_categories [ ui_category ] -> refs;
1651 while ( ui_selected -> next ) {
1652 ui_selected = ui_selected -> next;
1655 // try to move to same column
1656 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1657 if ( newcol > col ) {
1665 // scroll down to show it
1666 int r = ui_determine_row ( ui_selected ) - 1;
1667 if ( r - ui_display_context.row_max > 0 ) {
1668 ui_rows_scrolled_down = (unsigned int) r;
1672 // stop at top/bottom
1684 void ui_push_down ( void ) {
1685 unsigned char col_max = ui_display_context.col_max;
1687 if ( ui_selected ) {
1690 unsigned int row = ui_determine_row ( ui_selected );
1693 unsigned int icon_rows = g_categories [ ui_category ] -> refcount / col_max;
1694 if ( g_categories [ ui_category ] -> refcount % col_max > 0 ) {
1699 if ( row == ( icon_rows - 1 ) &&
1700 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1703 unsigned char col = ui_determine_screen_col ( ui_selected );
1705 ui_selected = g_categories [ ui_category ] -> refs;
1708 ui_selected = ui_selected -> next;
1712 ui_rows_scrolled_down = 0;
1714 render_mask |= CHANGED_EVERYTHING;
1719 ui_push_right ( 1 );
1726 ui_push_right ( 0 );
1732 // 'backup' is currently 'X', for going back up in a folder/subcat without having to hit exec on the '..' entry
1733 void ui_push_backup ( void ) {
1735 // a subcat-as-dir, or a dir browser?
1736 if ( g_categories [ ui_category] -> fspath ) {
1737 // dir browser, just climb our way back up
1742 // lop off last word; if the thing ends with /, lop that one, then the next word.
1743 while ( ( c = strrchr ( g_categories [ ui_category] -> fspath, '/' ) ) ) {
1744 *c = '\0'; // lop off the last hunk
1745 if ( *(c+1) != '\0' ) {
1751 if ( g_categories [ ui_category] -> fspath [ 0 ] == '\0' ) {
1752 free ( g_categories [ ui_category] -> fspath );
1753 g_categories [ ui_category] -> fspath = strdup ( "/" );
1757 // a pnd subcat .. are we in one, or at the 'top'?
1758 char *pcatname = g_categories [ ui_category ] -> parent_catname;
1761 return; // we're at the 'top' already
1764 // set to first cat!
1767 // republish cats .. shoudl just be the one
1768 category_publish ( CFNORMAL, NULL );
1771 ui_category = category_index ( pcatname );
1773 // ensure tab visible?
1774 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1775 if ( ui_category > ui_catshift + ( ui_display_context.screen_width / tab_width ) - 1 ) {
1776 ui_catshift = ui_category - ( ui_display_context.screen_width / tab_width ) + 1;
1786 void ui_push_exec ( void ) {
1788 if ( ! ui_selected ) {
1792 // was this icon generated from filesystem, or from pnd-file?
1793 if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
1795 if ( ! ui_selected -> ref -> title_en ) {
1796 return; // no filename
1799 if ( ui_selected -> ref -> object_type == pnd_object_type_directory ) {
1801 // check if this guy is a dir-browser tab, or is a directory on a pnd tab
1802 if ( ! g_categories [ ui_category] -> fspath ) {
1803 // pnd subcat as dir
1805 // are we already in a subcat? if so, go back to parent; there is no grandparenting or deeper
1806 if ( g_categories [ ui_category ] -> parent_catname ) {
1811 // delve into subcat
1813 // set to first cat!
1817 // republish cats .. shoudl just be the one
1818 category_publish ( CFBYNAME, ui_selected -> ref -> object_path );
1822 // forget the selection, nolonger applies
1824 ui_set_selected ( ui_selected );
1826 render_mask |= CHANGED_EVERYTHING;
1830 // delve up/down the dir tree
1831 if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
1836 char *temp = malloc ( strlen ( g_categories [ ui_category] -> fspath ) + strlen ( ui_selected -> ref -> title_en ) + 1 + 1 );
1837 sprintf ( temp, "%s/%s", g_categories [ ui_category] -> fspath, ui_selected -> ref -> title_en );
1838 free ( g_categories [ ui_category] -> fspath );
1839 g_categories [ ui_category] -> fspath = temp;
1842 pnd_log ( pndn_debug, "Cat %s is now in path %s\n", g_categories [ ui_category ] -> catname, g_categories [ ui_category ]-> fspath );
1844 // forget the selection, nolonger applies
1846 ui_set_selected ( ui_selected );
1848 category_fs_restock ( g_categories [ ui_category ] );
1850 render_mask |= CHANGED_SELECTION;
1852 } // directory browser or pnd subcat?
1855 // just run it arbitrarily?
1857 // if this a pnd-file, or just some executable?
1858 if ( strcasestr ( ui_selected -> ref -> object_filename, PND_PACKAGE_FILEEXT ) ) {
1859 // looks like a pnd, now what do we do..
1860 pnd_box_handle h = pnd_disco_file ( ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1863 pnd_disco_t *d = pnd_box_get_head ( h );
1864 pnd_apps_exec_disco ( pnd_run_script, d, PND_EXEC_OPTION_NORUN, NULL );
1865 char buffer [ PATH_MAX ];
1866 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1867 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1868 emit_and_quit ( buffer );
1870 emit_and_run ( buffer );
1877 // is it even executable? if we don't have handlers for non-executables yet (Jan 2011 we don't),
1878 // then don't even try to run things not-flagged as executable.. but wait most people are on
1879 // FAT filesystems, what a drag, we can't tell at the fs level.
1880 // ... but we can still invoke 'file' and grep out the good bits, at least.
1882 // open a stream reading 'file /path/to/file' and check output for 'executable'
1883 // -- not checking for "ARM" so it can pick up x86 (or whatever native) executables in build environment
1884 unsigned char is_executable = 0;
1888 char popenbuf [ FILENAME_MAX ];
1889 snprintf ( popenbuf, FILENAME_MAX, "%s %s/%s", MIMETYPE_EXE, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1892 if ( ! ( marceau = popen ( popenbuf, "r" ) ) ) {
1893 return; // error, we need some useful error handling and dialog boxes here
1896 if ( fgets ( popenbuf, FILENAME_MAX, marceau ) ) {
1897 //printf ( "File test returns: %s\n", popenbuf );
1898 if ( strstr ( popenbuf, "executable" ) != NULL ) {
1907 if ( ! is_executable ) {
1908 fprintf ( stderr, "ERROR: File to invoke is not executable, skipping. (%s)\n", ui_selected -> ref -> title_en );
1909 return; // need some error handling here
1912 #if 0 // eat up any pending SDL events and toss 'em?
1916 while ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_ALLEVENTS ) > 0 ) {
1926 // get CWD so we can restore it on return
1927 char cwd [ PATH_MAX ];
1928 getcwd ( cwd, PATH_MAX );
1930 // full path to executable so we don't rely on implicit "./"
1931 char execbuf [ FILENAME_MAX ];
1932 snprintf ( execbuf, FILENAME_MAX, "%s/%s", g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1935 chdir ( g_categories [ ui_category ] -> fspath );
1936 exec_raw_binary ( execbuf /*ui_selected -> ref -> title_en*/ );
1939 // DEPRECATED / NOT TESTED
1940 // get mmwrapper to run it
1941 char buffer [ PATH_MAX ];
1942 sprintf ( buffer, "%s %s/%s\n", MM_RUN, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1943 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1944 emit_and_quit ( buffer );
1946 emit_and_run ( buffer );
1955 // set app-run speed
1956 int use_run_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.use_run_speed", 0 );
1957 if ( use_run_speed > 0 ) {
1958 int mm_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.run_speed", -1 );
1959 if ( mm_speed > -1 ) {
1960 char buffer [ 512 ];
1961 snprintf ( buffer, 500, "sudo /usr/pandora/scripts/op_cpuspeed.sh %d", mm_speed );
1964 } // do speed change?
1966 // request app to run and quit mmenu
1967 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
1968 char buffer [ PATH_MAX ];
1969 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1970 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1971 emit_and_quit ( buffer );
1973 emit_and_run ( buffer );
1980 void ui_push_ltrigger ( void ) {
1981 unsigned char oldcat = ui_category;
1982 unsigned int screen_width = ui_display_context.screen_width;
1983 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1985 if ( g_categorycount == 0 ) {
1989 if ( ui_category > 0 ) {
1991 category_fs_restock ( g_categories [ ui_category ] );
1993 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
1994 ui_category = g_categorycount - 1;
1996 if ( ui_category >= ( screen_width / tab_width ) ) {
1997 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
1999 category_fs_restock ( g_categories [ ui_category ] );
2003 if ( oldcat != ui_category ) {
2005 ui_set_selected ( ui_selected );
2008 // make tab visible?
2009 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
2014 ui_rows_scrolled_down = 0;
2016 render_mask |= CHANGED_CATEGORY;
2021 void ui_push_rtrigger ( void ) {
2022 unsigned char oldcat = ui_category;
2024 if ( g_categorycount == 0 ) {
2028 unsigned int screen_width = ui_display_context.screen_width;
2029 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2031 if ( ui_category < ( g_categorycount - 1 ) ) {
2033 category_fs_restock ( g_categories [ ui_category ] );
2035 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
2038 category_fs_restock ( g_categories [ ui_category ] );
2042 if ( oldcat != ui_category ) {
2044 ui_set_selected ( ui_selected );
2047 // make tab visible?
2048 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2053 ui_rows_scrolled_down = 0;
2055 render_mask |= CHANGED_CATEGORY;
2060 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
2061 double scale = 1000000.0;
2062 double scalex = 1000000.0;
2063 double scaley = 1000000.0;
2064 SDL_Surface *scaled;
2066 scalex = (double)maxwidth / (double)s -> w;
2068 if ( maxheight == -1 ) {
2071 scaley = (double)maxheight / (double)s -> h;
2073 if ( scaley < scalex ) {
2081 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
2082 SDL_FreeSurface ( s );
2088 void ui_loadscreen ( void ) {
2093 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2097 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", ui_display_context.fontcolor );
2100 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2101 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2102 SDL_FreeSurface ( rtext );
2107 void ui_discoverscreen ( unsigned char clearscreen ) {
2112 if ( clearscreen ) {
2113 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2115 // render background
2116 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2119 dest.w = sdl_realscreen -> w;
2120 dest.h = sdl_realscreen -> h;
2121 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2122 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2129 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", ui_display_context.fontcolor );
2130 if ( clearscreen ) {
2137 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2138 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2139 SDL_FreeSurface ( rtext );
2142 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2143 dest.x = rtext -> w + 30;
2145 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
2146 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2152 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
2154 SDL_Rect rects [ 4 ];
2155 SDL_Rect *dest = rects;
2157 bzero ( dest, sizeof(SDL_Rect)* 4 );
2159 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2160 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2161 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
2162 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
2164 static unsigned int stepx = 0;
2167 if ( clearscreen ) {
2168 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2170 // render background
2171 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2174 dest -> w = sdl_realscreen -> w;
2175 dest -> h = sdl_realscreen -> h;
2176 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2182 // render background
2183 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2186 src.w = sdl_realscreen -> w;
2190 dest -> w = sdl_realscreen -> w;
2191 dest -> h = sdl_realscreen -> h;
2192 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
2200 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
2201 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
2204 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2205 SDL_FreeSurface ( rtext );
2209 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2210 dest -> x = rtext -> w + 30 + stepx;
2212 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
2218 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
2221 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2222 SDL_FreeSurface ( rtext );
2229 if ( stepx > 350 ) {
2233 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2238 int ui_selected_index ( void ) {
2240 if ( ! ui_selected ) {
2241 return ( -1 ); // no index
2244 mm_appref_t *r = g_categories [ ui_category ] -> refs;
2247 if ( r == ui_selected ) {
2257 static mm_appref_t *timer_ref = NULL;
2258 void ui_set_selected ( mm_appref_t *r ) {
2260 render_mask |= CHANGED_SELECTION;
2262 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
2263 return; // no desire to defer anything
2268 SDL_SetTimer ( 0, NULL );
2273 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
2279 unsigned int ui_callback_f ( unsigned int t ) {
2281 if ( ui_selected != timer_ref ) {
2282 return ( 0 ); // user has moved it, who cares
2286 bzero ( &e, sizeof(SDL_Event) );
2287 e.type = SDL_USEREVENT;
2288 e.user.code = sdl_user_ticker;
2289 SDL_PushEvent ( &e );
2294 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
2295 SDL_Rect rects [ 40 ];
2296 SDL_Rect *dest = rects;
2299 unsigned char max_visible = pnd_conf_get_as_int_d ( g_conf, "detailtext.max_visible" , 11 );
2300 unsigned char first_visible = 0;
2302 bzero ( rects, sizeof(SDL_Rect) * 40 );
2304 unsigned int sel = 0;
2306 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 };
2314 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2315 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2316 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
2317 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
2318 SDL_FillRect( sdl_realscreen, dest, 0 );
2320 // show dialog background
2321 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
2324 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
2325 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
2326 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2327 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2328 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2329 // repeat for darken?
2330 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2331 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2332 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2336 // show dialog frame
2337 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
2338 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2339 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2340 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
2341 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2347 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
2348 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2349 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
2350 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2351 SDL_FreeSurface ( rtext );
2357 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
2358 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2359 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
2360 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
2362 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2363 SDL_FreeSurface ( rtext );
2368 for ( i = first_visible; i < first_visible + max_visible && i < argc; i++ ) {
2372 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
2374 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], ui_display_context.fontcolor );
2376 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2377 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 - first_visible ) );
2378 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2379 SDL_FreeSurface ( rtext );
2384 // update all the rects and send it all to sdl
2385 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2389 while ( SDL_WaitEvent ( &event ) ) {
2391 switch ( event.type ) {
2396 if ( event.key.keysym.sym == SDLK_UP ) {
2400 if ( sel < first_visible ) {
2405 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
2407 if ( sel < argc - 1 ) {
2410 // ensure visibility
2411 if ( sel >= first_visible + max_visible ) {
2417 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
2421 } else if ( event.key.keysym.sym == SDLK_q ) {
2426 return ( -1 ); // nada
2441 unsigned char ui_determine_row ( mm_appref_t *a ) {
2442 unsigned int row = 0;
2444 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2449 row /= ui_display_context.col_max;
2454 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
2455 return ( ui_determine_row ( a ) % ui_display_context.row_max );
2458 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
2459 unsigned int col = 0;
2461 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2466 col %= ui_display_context.col_max;
2471 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
2472 char *viewer, *searchpath;
2473 pnd_conf_handle desktoph;
2476 searchpath = pnd_conf_query_searchpath();
2478 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
2484 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
2487 return ( 0 ); // no way to view the file
2491 if ( ! p -> unique_id ) {
2495 if ( ! p -> info_filename ) {
2499 if ( ! p -> info_name ) {
2510 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
2511 snprintf ( pargs, 1001, "%s %s",
2512 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
2517 char pndfile [ 1024 ];
2518 if ( p -> object_type == pnd_object_type_directory ) {
2519 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
2520 strncpy ( pndfile, p -> object_path, 1000 );
2521 } else if ( p -> object_type == pnd_object_type_pnd ) {
2522 // pnd_run.sh wants the full path and filename for the .pnd file
2523 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2526 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2527 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2532 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2536 if ( ( x = fork() ) < 0 ) {
2537 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2542 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2543 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2555 #define MAXTOUCH 100
2556 ui_touch_t ui_touchrects [ MAXTOUCH ];
2557 unsigned char ui_touchrect_count = 0;
2559 void ui_register_reset ( void ) {
2560 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2561 ui_touchrect_count = 0;
2565 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2567 if ( ui_touchrect_count == MAXTOUCH ) {
2571 ui_touchrects [ ui_touchrect_count ].r.x = x;
2572 ui_touchrects [ ui_touchrect_count ].r.y = y;
2573 ui_touchrects [ ui_touchrect_count ].r.w = w;
2574 ui_touchrects [ ui_touchrect_count ].r.h = h;
2575 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2576 ui_touchrect_count++;
2581 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2583 if ( ui_touchrect_count == MAXTOUCH ) {
2587 ui_touchrects [ ui_touchrect_count ].r.x = x;
2588 ui_touchrects [ ui_touchrect_count ].r.y = y;
2589 ui_touchrects [ ui_touchrect_count ].r.w = w;
2590 ui_touchrects [ ui_touchrect_count ].r.h = h;
2591 ui_touchrects [ ui_touchrect_count ].ref = app;
2592 ui_touchrect_count++;
2597 void ui_touch_act ( unsigned int x, unsigned int y ) {
2602 for ( i = 0; i < ui_touchrect_count; i++ ) {
2603 t = &(ui_touchrects [ i ]);
2605 if ( x >= t -> r.x &&
2606 x <= t -> r.x + t -> r.w &&
2608 y <= t -> r.y + t -> r.h
2613 ui_selected = t -> ref;
2616 if ( ui_category != t -> catnum ) {
2619 ui_category = t -> catnum;
2620 render_mask |= CHANGED_CATEGORY;
2622 category_fs_restock ( g_categories [ ui_category ] );
2633 unsigned char ui_forkexec ( char *argv[] ) {
2634 char *fooby = argv[0];
2637 if ( ( x = fork() ) < 0 ) {
2638 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2642 if ( x == 0 ) { // child
2643 execv ( fooby, argv );
2644 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2652 unsigned char ui_threaded_timer_create ( void ) {
2654 g_timer_thread = SDL_CreateThread ( (void*)ui_threaded_timer, NULL );
2656 if ( ! g_timer_thread ) {
2657 pnd_log ( pndn_error, "ERROR: Couldn't create timer thread\n" );
2664 int ui_threaded_timer ( pnd_disco_t *p ) {
2666 // this timer's job is to ..
2667 // - do nothing for quite awhile
2668 // - on wake, post event to SDL event queue, so that main thread will check if SD insert/eject occurred
2671 unsigned int delay_s = 2; // seconds
2678 // .. trigger SD check
2680 bzero ( &e, sizeof(SDL_Event) );
2681 e.type = SDL_USEREVENT;
2682 e.user.code = sdl_user_checksd;
2683 SDL_PushEvent ( &e );
2690 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
2692 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
2693 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
2696 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
2697 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
2700 // trigger that we completed
2702 bzero ( &e, sizeof(SDL_Event) );
2703 e.type = SDL_USEREVENT;
2704 e.user.code = sdl_user_finishedpreview;
2706 SDL_PushEvent ( &e );
2711 SDL_Thread *g_icon_thread = NULL;
2712 void ui_post_scan ( void ) {
2714 // if deferred icon load, kick off the thread now
2715 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2717 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
2719 if ( ! g_icon_thread ) {
2720 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
2723 } // deferred icon load
2727 ui_rows_scrolled_down = 0;
2728 // set back to first tab, to be safe
2732 // do we have a preferred category to jump to?
2733 char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
2736 // attempt to find default cat; if we do find it, select it; otherwise
2737 // default behaviour will pick first cat (ie: usually All)
2739 for ( i = 0; i < g_categorycount; i++ ) {
2740 if ( strcasecmp ( g_categories [ i ] -> catname, dc ) == 0 ) {
2742 // ensure visibility
2743 unsigned int screen_width = ui_display_context.screen_width;
2744 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2745 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2746 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2752 if ( i == g_categorycount ) {
2753 pnd_log ( pndn_warning, " User defined default category '%s' but not found, so using default behaviour\n", dc );
2758 // if we're sent right to a dirbrowser tab, restock it now (normally we restock on entry)
2759 if ( g_categories [ ui_category ] -> fspath ) {
2760 printf ( "Restock on start: '%s'\n", g_categories [ ui_category ] -> fspath );
2761 category_fs_restock ( g_categories [ ui_category ] );
2765 render_mask |= CHANGED_EVERYTHING;
2770 unsigned char ui_threaded_defered_icon ( void *p ) {
2771 extern pnd_box_handle g_active_apps;
2772 pnd_box_handle h = g_active_apps;
2774 unsigned char maxwidth, maxheight;
2775 maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
2776 maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
2778 pnd_disco_t *iter = pnd_box_get_head ( h );
2783 if ( iter -> pnd_icon_pos &&
2784 ! cache_icon ( iter, maxwidth, maxheight ) )
2786 pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2789 // trigger that we completed
2791 bzero ( &e, sizeof(SDL_Event) );
2792 e.type = SDL_USEREVENT;
2793 e.user.code = sdl_user_finishedicon;
2794 SDL_PushEvent ( &e );
2796 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2797 usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2802 iter = pnd_box_get_next ( iter );
2808 void ui_show_hourglass ( unsigned char updaterect ) {
2811 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2813 dest.x = ( 800 - s -> w ) / 2;
2814 dest.y = ( 480 - s -> h ) / 2;
2816 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2819 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2825 unsigned char ui_pick_skin ( void ) {
2827 char *skins [ MAXSKINS ];
2830 char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
2831 char tempname [ 100 ];
2835 skins [ iter++ ] = "No skin change";
2839 DIR *d = opendir ( buffer );
2844 while ( ( dd = readdir ( d ) ) ) {
2846 if ( dd -> d_name [ 0 ] == '.' ) {
2848 } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
2851 snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
2852 skins [ iter++ ] = strdup ( tempname );
2863 int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
2865 // did they pick one?
2869 char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
2870 s = pnd_expand_tilde ( s );
2872 f = fopen ( s, "w" );
2877 fprintf ( f, "%s\n", skins [ sel ] + 6 );
2887 void ui_aboutscreen ( char *textpath ) {
2894 #define ROWS SCRH / ( PIXELH + MARGINH )
2895 #define COLS SCRW / ( PIXELW + MARGINW )
2897 unsigned char pixelboard [ ROWS * COLS ]; // pixel heat
2898 bzero ( pixelboard, ROWS * COLS );
2903 SDL_Color rtextc = { 200, 200, 200, 100 };
2906 char *textloop [ 500 ];
2907 unsigned int textmax = 0;
2908 bzero ( textloop, 500 * sizeof(char*) );
2911 char cbuffer [ 50000 ];
2912 bzero ( cbuffer, 50000 );
2913 unsigned int crevealed = 0;
2915 FILE *f = fopen ( textpath, "r" );
2918 pnd_log ( pndn_error, "ERROR: Couldn't open about text: %s\n", textpath );
2922 char textbuf [ 100 ];
2923 while ( fgets ( textbuf, 100, f ) ) {
2925 // add to full buffer
2926 strncat ( cbuffer, textbuf, 50000 );
2929 if ( strchr ( textbuf, '\n' ) ) {
2930 * strchr ( textbuf, '\n' ) = '\0';
2933 // add to pixel loop
2934 if ( 1||textbuf [ 0 ] ) {
2935 textloop [ textmax ] = strdup ( textbuf );
2943 unsigned int textiter = 0;
2944 while ( textiter < textmax ) {
2945 char *text = textloop [ textiter ];
2949 // render to surface
2950 rtext = TTF_RenderText_Blended ( g_grid_font, text, rtextc );
2952 // render font to pixelboard
2953 unsigned int px, py;
2955 unsigned int *pixels = rtext -> pixels;
2956 unsigned char cr, cg, cb, ca;
2957 for ( py = 0; py < rtext -> h; py ++ ) {
2958 for ( px = 0; px < ( rtext -> w > COLS ? COLS : rtext -> w ); px++ ) {
2960 SDL_GetRGBA ( pixels [ ( py * rtext -> pitch / 4 ) + px ],
2961 rtext -> format, &cr, &cg, &cb, &ca );
2965 ph = pixelboard + ( /*y offset */ 30 * COLS ) + ( py * COLS ) + px /* / 2 */;
2972 if ( *ph + ca < 250 ) {
2983 unsigned int runcount = 10;
2984 while ( runcount-- ) {
2987 SDL_FillRect( sdl_realscreen, NULL /* whole */, 0 );
2989 // render pixelboard
2992 for ( y = 0; y < ROWS; y++ ) {
2993 for ( x = 0; x < COLS; x++ ) {
2995 if ( 1||pixelboard [ ( y * COLS ) + x ] ) {
2998 r.x = x * ( PIXELW + MARGINW );
2999 r.y = y * ( PIXELH + MARGINH );
3003 c = SDL_MapRGB ( sdl_realscreen -> format, 100 /* r */, 0 /* g */, pixelboard [ ( y * COLS ) + x ] );
3005 SDL_FillRect( sdl_realscreen, &r /* whole */, c );
3013 unsigned char *pc = pixelboard;
3014 for ( y = 0; y < ROWS; y++ ) {
3015 for ( x = 0; x < COLS; x++ ) {
3025 // slide pixels upwards
3026 memmove ( pixelboard, pixelboard + COLS, ( COLS * ROWS ) - COLS );
3028 // render actual readable text
3031 // display up to cursor
3033 unsigned int cdraw = 0;
3037 if ( crevealed > 200 ) {
3038 cdraw = crevealed - 200;
3044 for ( ; cdraw < crevealed; cdraw++ ) {
3045 ctb [ 0 ] = cbuffer [ cdraw ];
3047 // move over or down
3048 if ( cbuffer [ cdraw ] == '\n' ) {
3053 if ( dest.y > 450 ) {
3059 cs = TTF_RenderText_Blended ( g_tab_font, ctb, rtextc );
3061 SDL_BlitSurface ( cs, NULL /* all */, sdl_realscreen, &dest );
3062 SDL_FreeSurface ( cs );
3072 SDL_FillRect ( sdl_realscreen, &dest /* whole */, 220 );
3074 // increment cursor to next character
3075 if ( cbuffer [ crevealed ] != '\0' ) {
3079 } // draw cursor text
3083 SDL_UpdateRect ( sdl_realscreen, 0, 0, 0, 0 ); // whole screen
3087 // any button? if so, about
3093 if ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_EVENTMASK(/*SDL_KEYUP|*/SDL_KEYDOWN) ) > 0 ) {
3102 SDL_FreeSurface ( rtext );
3106 } // while more text
3110 for ( i = 0; i < textmax; i++ ) {
3111 if ( textloop [ i ] ) {
3112 free ( textloop [ i ] );
3120 void ui_revealscreen ( void ) {
3121 char *labels [ 500 ];
3122 unsigned int labelmax = 0;
3124 char fulllabel [ 200 ];
3126 if ( ! category_count ( CFHIDDEN ) ) {
3127 return; // nothing to do
3130 // switch to hidden categories
3131 category_publish ( CFHIDDEN, NULL );
3133 // build up labels to show in menu
3134 for ( i = 0; i < g_categorycount; i++ ) {
3136 if ( g_categories [ i ] -> parent_catname ) {
3137 sprintf ( fulllabel, "%s [%s]", g_categories [ i ] -> catname, g_categories [ i ] -> parent_catname );
3139 sprintf ( fulllabel, "%s", g_categories [ i ] -> catname );
3142 labels [ labelmax++ ] = strdup ( fulllabel );
3146 int sel = ui_modal_single_menu ( labels, labelmax, "Temporary Category Reveal",
3147 "Enter to select; other to return." );
3149 // if selected, try to set this guy to visible
3152 // fix up category name, if its been hacked
3153 #if 0 // prepending and .. wtf crap is this
3154 if ( strchr ( g_categories [ sel ] -> catname, '.' ) ) {
3155 char *t = g_categories [ sel ] -> catname;
3156 g_categories [ sel ] -> catname = strdup ( strchr ( g_categories [ sel ] -> catname, '.' ) + 1 );
3161 // reflag this guy to be visible
3162 g_categories [ sel ] -> catflags = CFNORMAL;
3164 // switch to the new category.. cache name.
3165 char *switch_to_name = g_categories [ sel ] -> catname;
3167 // republish categories
3168 category_publish ( CFNORMAL, NULL );
3170 // switch to the new category.. with the cached name!
3171 ui_category = category_index ( switch_to_name );
3173 // ensure visibility
3174 unsigned int screen_width = ui_display_context.screen_width;
3175 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
3176 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
3177 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
3182 // republish categories
3183 category_publish ( CFNORMAL, NULL );
3186 render_mask |= CHANGED_CATEGORY;
3191 void ui_recache_context ( ui_context_t *c ) {
3193 c -> screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
3195 c -> font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
3196 c -> font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
3197 c -> font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
3198 c -> font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
3200 c -> grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
3201 c -> grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
3203 c -> icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
3204 c -> icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
3205 c -> icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
3206 c -> icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
3207 c -> sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
3208 c -> sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
3210 c -> text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
3211 c -> text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
3212 c -> text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
3213 c -> text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
3214 c -> text_hilite_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
3216 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 4 );
3217 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
3219 c -> cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
3220 c -> cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
3222 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
3223 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
3224 c -> arrow_bar_clip_w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
3225 c -> arrow_bar_clip_h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
3226 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
3227 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
3228 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
3229 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
3232 SDL_Color tmp = { c -> font_rgba_r, c -> font_rgba_g, c -> font_rgba_b, c -> font_rgba_a };
3233 c -> fontcolor = tmp;
3235 // now that we've got 'normal' (detail pane shown) param's, lets check if detail pane
3236 // is hidden; if so, override some values with those alternate skin values where possible.
3237 if ( ui_detail_hidden ) {
3238 // if detail panel is hidden, and theme cannot support it, unhide the bloody thing. (This may help
3239 // when someone is amid theme hacking or changing.)
3240 if ( ! ui_is_detail_hideable() ) {
3241 ui_detail_hidden = 0;
3245 if ( ui_detail_hidden ) {
3247 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max_w", c -> row_max );
3248 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max_w", c -> col_max );
3250 c -> cell_width = pnd_conf_get_as_int_d ( g_conf, "grid.cell_width_w", c -> cell_width );
3251 c -> cell_height = pnd_conf_get_as_int_d ( g_conf, "grid.cell_height_w", c -> cell_height );
3253 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x_w", 450 );
3254 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y_w", 100 );
3255 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x_w", 450 );
3256 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y_w", 80 );
3257 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x_w", 450 );
3258 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y_w", 80 );
3260 } // if detail hidden.. still.
3262 } // if detail hidden
3267 unsigned char ui_is_detail_hideable ( void ) {
3269 // if skin has a bit of info for wide-mode, we assume wide-mode is available
3270 if ( pnd_conf_get_as_char ( g_conf, "grid.row_max_w" ) != NULL ) {
3278 void ui_toggle_detail_pane ( void ) {
3280 // no bitmask trickery here; I like it to be stand-out obvious at 3am.
3282 if ( ui_detail_hidden ) {
3283 ui_detail_hidden = 0;
3285 ui_detail_hidden = 1;
3288 // repull skin config
3289 ui_recache_context ( &ui_display_context );
3292 render_mask |= CHANGED_EVERYTHING;
3297 void ui_menu_context ( mm_appref_t *a ) {
3299 unsigned char rescan_apps = 0;
3300 unsigned char context_alive = 1;
3305 context_file_delete,
3308 context_app_recategorize,
3309 context_app_recategorize_sub,
3311 context_app_cpuspeed,
3319 char *verbiage[] = {
3320 "Done (return to grid)", // context_done
3321 "Get info about file/dir", // context_file_info
3322 "Delete file/dir", // context_file_delete
3323 "Get info", // context_app_info
3324 "Hide application", // hide
3325 "Recategorize", // recategorize
3326 "Recategorize subcategory", // recategorize
3327 "Change displayed title", // rename
3328 "Set CPU speed for launch", // cpuspeed
3329 "Run application", // run
3330 "Edit notes line 1", // notes1
3331 "Edit notes line 2", // notes2
3332 "Edit notes line 3", // notes3
3335 unsigned short int menu [ context_menu_max ];
3336 char *menustring [ context_menu_max ];
3337 unsigned char menumax = 0;
3340 menu [ menumax ] = context_done; menustring [ menumax++ ] = verbiage [ context_done ];
3342 // hook up appropriate menu options based on tab-type and object-type
3343 if ( g_categories [ ui_category ] -> fspath ) {
3345 menu [ menumax ] = context_file_info; menustring [ menumax++ ] = verbiage [ context_file_info ];
3346 menu [ menumax ] = context_file_delete; menustring [ menumax++ ] = verbiage [ context_file_delete ];
3349 if ( a -> ref -> object_type == pnd_object_type_directory ) {
3350 return; // don't do anything if the guy is a subcat-as-folder
3353 //menu [ menumax ] = context_app_info; menustring [ menumax++ ] = verbiage [ context_app_info ];
3354 menu [ menumax ] = context_app_run; menustring [ menumax++ ] = verbiage [ context_app_run ];
3355 menu [ menumax ] = context_app_hide; menustring [ menumax++ ] = verbiage [ context_app_hide ];
3356 menu [ menumax ] = context_app_recategorize; menustring [ menumax++ ] = verbiage [ context_app_recategorize ];
3357 menu [ menumax ] = context_app_recategorize_sub; menustring [ menumax++ ] = verbiage [ context_app_recategorize_sub ];
3358 menu [ menumax ] = context_app_rename; menustring [ menumax++ ] = verbiage [ context_app_rename ];
3359 menu [ menumax ] = context_app_cpuspeed; menustring [ menumax++ ] = verbiage [ context_app_cpuspeed ];
3360 menu [ menumax ] = context_app_notes1; menustring [ menumax++ ] = verbiage [ context_app_notes1 ];
3361 menu [ menumax ] = context_app_notes2; menustring [ menumax++ ] = verbiage [ context_app_notes2 ];
3362 menu [ menumax ] = context_app_notes3; menustring [ menumax++ ] = verbiage [ context_app_notes3 ];
3366 while ( context_alive ) {
3368 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 */ );
3375 switch ( menu [ sel ] ) {
3381 case context_file_info:
3384 case context_file_delete:
3385 //ui_menu_twoby ( "Delete - Are you sure?", "B/enter; other to cancel", "Delete", "Do not delete" );
3388 case context_app_info:
3391 case context_app_hide:
3394 char confkey [ 1000 ];
3395 snprintf ( confkey, 999, "%s.%s", "appshow", a -> ref -> unique_id );
3398 pnd_conf_set_char ( g_conf, confkey, "0" );
3400 // write conf, so it will take next time
3401 conf_write ( g_conf, conf_determine_location ( g_conf ) );
3403 // can we just 'hide' this guy without reloading all apps? (this is for you, EvilDragon)
3406 // DOESN'T WORK YET; other parts of app are still hanging onto some values and blow up
3408 char *uid = strdup ( a -> ref -> unique_id );
3410 for ( i = 0; i < g_categorycount; i++ ) {
3411 mm_appref_t *p = g_categories [ i ] -> refs;
3416 if ( strcmp ( p -> ref -> unique_id, uid ) == 0 ) {
3418 if ( g_categories [ i ] -> refcount ) {
3419 g_categories [ i ] -> refcount--;
3424 } // while for each appref
3425 } // for each cat/tab
3430 // request rescan and wrap up
3434 context_alive = 0; // nolonger visible, so lets just get out
3440 case context_app_recategorize:
3443 unsigned char optmax = 0;
3446 // show custom categories
3447 if ( mmcustom_setup() ) {
3449 for ( i = 0; i < mmcustom_count; i++ ) {
3450 if ( mmcustom_complete [ i ].parent_cat == NULL ) {
3451 opts [ optmax++ ] = mmcustom_complete [ i ].cat;
3457 // show FD categories
3458 i = 2; // skip first two - Other and NoParentCategory
3461 if ( ! freedesktop_complete [ i ].cat ) {
3465 if ( ! freedesktop_complete [ i ].parent_cat ) {
3466 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3473 char prompt [ 101 ];
3474 snprintf ( prompt, 100, "Pick category [%s]", a -> ref -> main_category ? a -> ref -> main_category : "NoParentCategory" );
3476 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select parent category"*/, "Enter to select; other to skip." );
3479 char confirm [ 1001 ];
3480 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3482 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm categorization", "Do not set category" ) == 1 ) {
3483 ovr_replace_or_add ( a, "maincategory", opts [ sel ] );
3485 // when changing main cat, reset subcat, otherwise you go from Game/Emu to Network/Emu and get sent to Other right away
3486 ovr_replace_or_add ( a, "maincategorysub1", freedesktop_complete [ 2 ].cat );
3491 if ( mmcustom_is_ready() ) {
3492 mmcustom_shutdown();
3498 case context_app_recategorize_sub:
3501 unsigned char optmax = 0;
3502 unsigned char i = 0;
3504 char *whichparentarewe;
3505 if ( g_categories [ ui_category ] -> parent_catname ) {
3506 whichparentarewe = g_categories [ ui_category ] -> parent_catname;
3508 whichparentarewe = g_categories [ ui_category ] -> catname;
3511 // add NoSubcategory magic one
3512 opts [ optmax++ ] = freedesktop_complete [ 2 ].cat;
3514 // add custom categories
3515 if ( mmcustom_setup() ) {
3517 for ( i = 0; i < mmcustom_count; i++ ) {
3518 if ( mmcustom_complete [ i ].parent_cat && strcmp ( mmcustom_complete [ i ].parent_cat, whichparentarewe ) == 0 ) {
3519 opts [ optmax++ ] = mmcustom_complete [ i ].cat;
3525 // add FD categories
3528 if ( ! freedesktop_complete [ i ].cat ) {
3532 if ( ( freedesktop_complete [ i ].parent_cat ) &&
3533 ( strcasecmp ( freedesktop_complete [ i ].parent_cat, whichparentarewe ) == 0 )
3536 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3542 char prompt [ 101 ];
3543 //snprintf ( prompt, 100, "Currently: %s", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory" );
3544 snprintf ( prompt, 100, "%s [%s]", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory", whichparentarewe );
3546 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select subcategory"*/, "Enter to select; other to skip." );
3549 char confirm [ 1001 ];
3550 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3552 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm sub-categorization", "Do not set sub-category" ) == 1 ) {
3553 ovr_replace_or_add ( a, "maincategorysub1", opts [ sel ] );
3559 if ( mmcustom_is_ready() ) {
3560 mmcustom_shutdown();
3566 case context_app_rename:
3568 char namebuf [ 101 ];
3569 unsigned char changed;
3571 changed = ui_menu_get_text_line ( "Rename application", "Use keyboard; Enter when done.",
3572 a -> ref -> title_en ? a -> ref -> title_en : "blank", namebuf, 30, 0 /* alphanumeric */ );
3575 char confirm [ 1001 ];
3576 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3578 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm rename", "Do not rename" ) == 1 ) {
3579 ovr_replace_or_add ( a, "title", namebuf );
3589 case context_app_cpuspeed:
3591 char namebuf [ 101 ];
3592 unsigned char changed;
3594 changed = ui_menu_get_text_line ( "Specify runspeed", "Use keyboard; Enter when done.",
3595 a -> ref -> clockspeed ? a -> ref -> clockspeed : "500", namebuf, 6, 1 /* numeric */ );
3598 char confirm [ 1001 ];
3599 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3601 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm clockspeed", "Do not set" ) == 1 ) {
3602 ovr_replace_or_add ( a, "clockspeed", namebuf );
3612 case context_app_run:
3616 case context_app_notes1:
3617 case context_app_notes2:
3618 case context_app_notes3:
3620 char namebuf [ 101 ] = "";
3623 unsigned char notenum;
3626 if ( menu [ sel ] == context_app_notes1 ) {
3628 } else if ( menu [ sel ] == context_app_notes2 ) {
3630 } else if ( menu [ sel ] == context_app_notes3 ) {
3634 // figure out key for looking up existing, and for storing replacement
3635 snprintf ( key, 500, "Application-%u.note-%u", a -> ref -> subapp_number, notenum );
3637 // do we have existing value?
3639 char *existing = pnd_conf_get_as_char ( a -> ovrh, key );
3641 strncpy ( namebuf, existing, 100 );
3645 unsigned char changed;
3647 changed = ui_menu_get_text_line ( "Enter replacement note", "Use keyboard; Enter when done.",
3648 namebuf, namebuf, 30, 0 /* not-numeric-forced */ );
3651 ovr_replace_or_add ( a, strchr ( key, '.' ) + 1, namebuf );
3663 } // if useful return
3668 if ( rescan_apps ) {
3669 applications_free();
3670 applications_scan();
3676 unsigned char ui_menu_oneby ( char *title, char *footer, char *one ) {
3679 int sel = ui_modal_single_menu ( opts, 1, title, footer );
3686 unsigned char ui_menu_twoby ( char *title, char *footer, char *one, char *two ) {
3690 int sel = ui_modal_single_menu ( opts, 2, title, footer );
3697 unsigned char ui_menu_get_text_line ( char *title, char *footer, char *initialvalue,
3698 char *r_buffer, unsigned char maxlen, unsigned char numbersonlyp )
3700 SDL_Rect rects [ 40 ];
3701 SDL_Rect *dest = rects;
3705 char hacktext [ 1024 ];
3706 unsigned char shifted = 0;
3708 bzero ( rects, sizeof(SDL_Rect) * 40 );
3710 if ( initialvalue ) {
3711 if ( initialvalue == r_buffer ) {
3712 // already good to go
3714 strncpy ( r_buffer, initialvalue, maxlen );
3717 bzero ( r_buffer, maxlen );
3723 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3724 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3725 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
3726 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
3727 SDL_FillRect( sdl_realscreen, dest, 0 );
3729 // show dialog background
3730 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
3733 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
3734 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
3735 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3736 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3737 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
3741 // show dialog frame
3742 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
3743 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3744 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3745 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
3751 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
3752 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3753 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
3754 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3755 SDL_FreeSurface ( rtext );
3761 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
3762 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3763 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
3764 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
3766 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3767 SDL_FreeSurface ( rtext );
3771 // show text line - and embed cursor
3772 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3773 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( 0/*i*/ + 1 - 0/*first_visible*/ ) );
3775 strncpy ( hacktext, r_buffer, 1000 );
3776 strncat ( hacktext, "\n", 1000 ); // add [] in most fonts
3778 rtext = TTF_RenderText_Blended ( g_tab_font, hacktext, ui_display_context.fontcolor );
3779 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3780 SDL_FreeSurface ( rtext );
3783 // update all the rects and send it all to sdl
3784 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
3789 while ( SDL_WaitEvent ( &event ) ) {
3791 switch ( event.type ) {
3794 if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
3801 if ( event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_BACKSPACE ) {
3802 if ( strlen ( r_buffer ) > 0 ) {
3803 char *eol = strchr ( r_buffer, '\0' );
3804 *( eol - 1 ) = '\0';
3807 } else if ( event.key.keysym.sym == SDLK_UP ) {
3808 r_buffer [ 0 ] = '\0'; // truncate!
3810 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
3811 // on Enter/Return or B, if the buffer has 1 or more chars, we return it as valid.. otherwise, invalid.
3812 if ( strlen ( r_buffer ) > 0 ) {
3817 } else if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
3820 } else if ( event.key.keysym.sym == SDLK_ESCAPE ||
3821 event.key.keysym.sym == SDLK_PAGEUP ||
3822 event.key.keysym.sym == SDLK_PAGEDOWN ||
3823 event.key.keysym.sym == SDLK_HOME
3830 if ( isprint(event.key.keysym.sym) ) {
3832 unsigned char good = 1;
3834 if ( numbersonlyp && ( ! isdigit(event.key.keysym.sym) ) ) {
3838 if ( maxlen && strlen(r_buffer) >= maxlen ) {
3843 char b [ 2 ] = { '\0', '\0' };
3845 b [ 0 ] = toupper ( event.key.keysym.sym );
3847 b [ 0 ] = event.key.keysym.sym;
3849 strncat ( r_buffer, b, maxlen );
3862 } // while waiting for input
3869 unsigned char ovr_replace_or_add ( mm_appref_t *a, char *keybase, char *newvalue ) {
3870 //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 );
3872 char fullpath [ PATH_MAX ];
3874 sprintf ( fullpath, "%s/%s", a -> ref -> object_path, a -> ref -> object_filename );
3875 char *dot = strrchr ( fullpath, '.' );
3877 sprintf ( dot, PXML_SAMEPATH_OVERRIDE_FILEEXT );
3879 pnd_log ( pndn_error, "ERROR: Bad pnd-path in disco_t! %s\n", fullpath );
3883 struct stat statbuf;
3885 if ( stat ( fullpath, &statbuf ) == 0 ) {
3889 h = pnd_conf_fetch_by_path ( fullpath );
3892 return ( 0 ); // fail!
3896 snprintf ( key, 100, "Application-%u.%s", a -> ref -> subapp_number, keybase );
3898 pnd_conf_set_char ( h, key, newvalue );
3900 return ( pnd_conf_write ( h, fullpath ) );
3903 // file needs to be created - easy!
3905 FILE *f = fopen ( fullpath, "w" );
3908 fprintf ( f, "Application-%u.%s\t%s\n", a -> ref -> subapp_number, keybase, newvalue );
3912 return ( 0 ); // fail!
3920 void ui_manage_categories ( void ) {
3921 unsigned char require_app_scan = 0;
3923 if ( ! mmcustom_setup() ) {
3927 char *opts [ 20 ] = {
3928 "List custom categories",
3929 "List custom subcategories",
3930 "Register custom category",
3931 "Register custom subcategory",
3932 "Unregister custom category",
3933 "Unregister custom subcategory",
3939 int sel = ui_modal_single_menu ( opts, 7, "Custom Categories", "B to select; other to cancel." );
3943 case 0: // list custom
3944 if ( mmcustom_count ) {
3945 ui_pick_custom_category ( 0 );
3947 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
3951 case 1: // list custom sub
3952 if ( mmcustom_count ) {
3954 char *maincat = ui_pick_custom_category ( 0 );
3957 unsigned int subcount = mmcustom_count_subcats ( maincat );
3958 char titlebuf [ 201 ];
3960 snprintf ( titlebuf, 200, "Category: %s", maincat );
3962 if ( subcount == 0 ) {
3963 ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
3966 char **list = malloc ( subcount * sizeof(char*) );
3968 unsigned int counter = 0;
3970 for ( i = 0; i < mmcustom_count; i++ ) {
3971 if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
3972 list [ counter++ ] = mmcustom_complete [ i ].cat;
3976 ui_modal_single_menu ( list, counter, titlebuf, "Any button to exit." );
3980 } // more than 0 subcats?
3982 } // user picked a main cat?
3985 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
3989 case 2: // register custom
3991 unsigned char changed;
3992 char namebuf [ 101 ] = "";
3994 changed = ui_menu_get_text_line ( "Enter unique category name", "Use keyboard; Enter when done.",
3995 "Pandora", namebuf, 30, 0 /* alphanumeric */ );
3997 // did the user enter something?
4000 // and if so, is it existant already or not?
4001 if ( mmcustom_query ( namebuf, NULL ) ) {
4002 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a registered category." );
4003 } else if ( freedesktop_category_query ( namebuf, NULL ) ) {
4004 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard category." );
4007 char confirm [ 1001 ];
4008 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
4010 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
4011 // register, save, recycle the current list
4012 mmcustom_register ( namebuf, NULL );
4013 mmcustom_write ( NULL );
4014 mmcustom_shutdown();
4020 } // entered something?
4025 case 3: // register custom sub
4026 if ( mmcustom_count ) {
4028 char *maincat = ui_pick_custom_category ( 1 /* include FD */ );
4031 char titlebuf [ 201 ];
4033 snprintf ( titlebuf, 200, "Subcat of: %s", maincat );
4035 unsigned char changed;
4036 char namebuf [ 101 ] = "";
4038 changed = ui_menu_get_text_line ( titlebuf, "Use keyboard; Enter when done.", "Submarine", namebuf, 30, 0 /* alphanumeric */ );
4040 // did the user enter something?
4043 // and if so, is it existant already or not?
4044 if ( mmcustom_query ( namebuf, maincat ) ) {
4045 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a subcategory." );
4046 } else if ( freedesktop_category_query ( namebuf, maincat ) ) {
4047 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard subcategory." );
4050 char confirm [ 1001 ];
4051 snprintf ( confirm, 1000, "Confirm: %s [%s]", namebuf, maincat );
4053 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
4054 // register, save, recycle the current list
4055 mmcustom_register ( namebuf, maincat );
4056 mmcustom_write ( NULL );
4057 mmcustom_shutdown();
4063 } // entered something?
4065 } // selected parent cat?
4068 ui_menu_oneby ( "Warning", "B/Enter to accept", "No categories registered." );
4072 case 4: // unreg custom
4073 if ( mmcustom_count ) {
4074 char *maincat = ui_pick_custom_category ( 0 );
4077 char confirm [ 1001 ];
4078 snprintf ( confirm, 1000, "Confirm remove: %s", maincat );
4080 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
4081 // register, save, recycle the current list
4082 mmcustom_unregister ( maincat, NULL );
4083 mmcustom_write ( NULL );
4084 mmcustom_shutdown();
4091 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4095 case 5: // unreg custom sub
4096 if ( mmcustom_count ) {
4097 char *maincat = ui_pick_custom_category ( 0 );
4100 unsigned int subcount = mmcustom_count_subcats ( maincat );
4101 char titlebuf [ 201 ];
4103 snprintf ( titlebuf, 200, "Category: %s", maincat );
4105 if ( subcount == 0 ) {
4106 ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
4109 char **list = malloc ( subcount * sizeof(char*) );
4111 unsigned int counter = 0;
4113 for ( i = 0; i < mmcustom_count; i++ ) {
4114 if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
4115 list [ counter++ ] = mmcustom_complete [ i ].cat;
4119 int sel = ui_modal_single_menu ( list, counter, titlebuf, "B to selct; other to exit." );
4122 char confirm [ 1001 ];
4123 snprintf ( confirm, 1000, "Confirm remove: %s", list [ sel ] );
4125 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
4126 // register, save, recycle the current list
4127 mmcustom_unregister ( list [ sel ], maincat );
4128 mmcustom_write ( NULL );
4129 mmcustom_shutdown();
4137 } // more than 0 subcats?
4139 } // user picked a main cat?
4142 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4149 if ( sel < 0 || sel > 5 ) {
4153 } // while running the menu
4155 // shut down custom cats
4156 mmcustom_shutdown();
4159 if ( require_app_scan ) {
4160 applications_free();
4161 applications_scan();
4165 render_mask |= CHANGED_EVERYTHING;
4170 char *ui_pick_custom_category ( unsigned char include_fd ) {
4173 unsigned int counter = 0;
4176 list = malloc ( (mmcustom_count+freedesktop_count()) * sizeof(char*) );
4178 list = malloc ( mmcustom_count * sizeof(char*) );
4182 for ( i = 0; i < mmcustom_count; i++ ) {
4183 if ( mmcustom_complete [ i ].parent_cat == NULL ) {
4184 list [ counter++ ] = mmcustom_complete [ i ].cat;
4193 if ( ! freedesktop_complete [ i ].cat ) {
4197 if ( freedesktop_complete [ i ].parent_cat == NULL ) {
4198 list [ counter++ ] = freedesktop_complete [ i ].cat;
4205 int sel = ui_modal_single_menu ( list, counter, "Custom Main Categories", "Any button to exit." );
4212 char *foo = list [ sel ];