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 SDL_Thread *g_icon_thread = NULL;
55 unsigned char g_icon_thread_stop = 0; /* if !0 means thread should stop and maim app may block until it goes back to 0.. */
56 unsigned char g_icon_thread_busy = 0; /* if !0 means thread is running right now */
58 #define MIMETYPE_EXE "/usr/bin/file" /* check for file type prior to invocation */
62 SDL_Surface *sdl_realscreen = NULL;
63 unsigned int sdl_ticks = 0;
64 SDL_Thread *g_preview_thread = NULL;
65 SDL_Thread *g_timer_thread = NULL;
67 enum { sdl_user_ticker = 0,
68 sdl_user_finishedpreview = 1,
69 sdl_user_finishedicon = 2,
75 unsigned short int g_scale = 1; // 1 == noscale
77 SDL_Surface *g_imgcache [ IMG_MAX ];
79 TTF_Font *g_big_font = NULL;
80 TTF_Font *g_grid_font = NULL;
81 TTF_Font *g_detailtext_font = NULL;
82 TTF_Font *g_tab_font = NULL;
84 extern pnd_conf_handle g_conf;
86 /* current display state
88 int ui_rows_scrolled_down = 0; // number of rows that should be missing from top of the display
89 mm_appref_t *ui_selected = NULL;
90 unsigned char ui_category = 0; // current category
91 unsigned char ui_catshift = 0; // how many cats are offscreen to the left
92 ui_context_t ui_display_context; // display paramaters: see mmui_context.h
93 unsigned char ui_detail_hidden = 0; // if >0, detail panel is hidden
94 // FUTURE: If multiple panels can be shown/hidden, convert ui_detail_hidden to a bitmask
96 static SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ); // height -1 means ignore
97 static int ui_selected_index ( void );
98 static void ui_start_defered_icon_thread ( void );
99 static void ui_stop_defered_icon_thread ( void );
101 unsigned char ui_setup ( void ) {
106 SDL_Init ( SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE );
108 SDL_JoystickOpen ( 0 ); // turn on joy-0
110 SDL_WM_SetCaption ( "mmenu", "mmenu" );
112 // hide the mouse cursor if we can
113 if ( SDL_ShowCursor ( -1 ) == 1 ) {
114 SDL_ShowCursor ( 0 );
120 unsigned int svm = SDL_SWSURFACE /*| SDL_FULLSCREEN*/ /* 0*/;
121 if ( pnd_conf_get_as_int_d ( g_conf, "display.fullscreen", 0 ) > 0 ) {
122 svm |= SDL_FULLSCREEN;
126 SDL_SetVideoMode ( 800 * g_scale, 480 * g_scale, 16 /*bpp*/, svm );
128 if ( ! sdl_realscreen ) {
129 pnd_log ( pndn_error, "ERROR: Couldn't open SDL real screen; dieing." );
133 pnd_log ( pndn_debug, "Pixel format:" );
134 pnd_log ( pndn_debug, "bpp b: %u\n", sdl_realscreen -> format -> BitsPerPixel );
135 pnd_log ( pndn_debug, "bpp B: %u\n", sdl_realscreen -> format -> BytesPerPixel );
136 pnd_log ( pndn_debug, "R mask: %08x\n", sdl_realscreen -> format -> Rmask );
137 pnd_log ( pndn_debug, "G mask: %08x\n", sdl_realscreen -> format -> Gmask );
138 pnd_log ( pndn_debug, "B mask: %08x\n", sdl_realscreen -> format -> Bmask );
144 /* Set 16-bit stereo audio at 22Khz */
145 fmt.freq = 44100; //22050;
146 fmt.format = AUDIO_S16; //AUDIO_S16;
148 fmt.samples = 2048; /* A good value for games */
149 fmt.callback = mixaudio;
152 /* Open the audio device and start playing sound! */
153 if ( SDL_OpenAudio ( &fmt, NULL ) < 0 ) {
154 zotlog ( "Unable to open audio: %s\n", SDL_GetError() );
158 SDL_PauseAudio ( 0 );
163 SDL_EnableKeyRepeat ( 500, 125 /* 150 */ );
166 //IMG_Init ( IMG_INIT_JPG | IMG_INIT_PNG );
172 if ( TTF_Init() == -1 ) {
173 pnd_log ( pndn_error, "ERROR: Couldn't set up SDL TTF lib\n" );
174 return ( 0 ); // couldn't set up SDL TTF
177 char fullpath [ PATH_MAX ];
179 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "minimenu.font" ) );
180 g_big_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
181 if ( ! g_big_font ) {
182 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
183 pnd_conf_get_as_char ( g_conf, "minimenu.font" ), pnd_conf_get_as_int_d ( g_conf, "minimenu.font_ptsize", 24 ) );
184 return ( 0 ); // couldn't set up SDL TTF
188 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "grid.font" ) );
189 g_grid_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
190 if ( ! g_grid_font ) {
191 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
192 pnd_conf_get_as_char ( g_conf, "grid.font" ), pnd_conf_get_as_int_d ( g_conf, "grid.font_ptsize", 10 ) );
193 return ( 0 ); // couldn't set up SDL TTF
197 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "detailtext.font" ) );
198 g_detailtext_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
199 if ( ! g_detailtext_font ) {
200 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
201 pnd_conf_get_as_char ( g_conf, "detailtext.font" ), pnd_conf_get_as_int_d ( g_conf, "detailtext.font_ptsize", 10 ) );
202 return ( 0 ); // couldn't set up SDL TTF
206 sprintf ( fullpath, "%s/%s", g_skinpath, pnd_conf_get_as_char ( g_conf, "tabs.font" ) );
207 g_tab_font = TTF_OpenFont ( fullpath, pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
208 if ( ! g_tab_font ) {
209 pnd_log ( pndn_error, "ERROR: Couldn't load font '%s' for size %u\n",
210 pnd_conf_get_as_char ( g_conf, "tabs.font" ), pnd_conf_get_as_int_d ( g_conf, "tabs.font_ptsize", 10 ) );
211 return ( 0 ); // couldn't set up SDL TTF
214 // determine display context
215 if ( pnd_conf_get_as_int_d ( g_conf, "display.show_detail_pane", 1 ) > 0 ) {
216 ui_detail_hidden = 0;
218 ui_detail_hidden = 1;
220 ui_recache_context ( &ui_display_context );
225 mm_imgcache_t g_imagecache [ IMG_TRUEMAX ] = {
226 { IMG_BACKGROUND_800480, "graphics.IMG_BACKGROUND_800480" },
227 { IMG_BACKGROUND_TABMASK, "graphics.IMG_BACKGROUND_TABMASK" },
228 { IMG_DETAIL_PANEL, "graphics.IMG_DETAIL_PANEL" },
229 { IMG_DETAIL_BG, "graphics.IMG_DETAIL_BG" },
230 { IMG_SELECTED_ALPHAMASK, "graphics.IMG_SELECTED_ALPHAMASK" },
231 { IMG_TAB_SEL, "graphics.IMG_TAB_SEL" },
232 { IMG_TAB_SEL_L, "graphics.IMG_TAB_SEL_L" },
233 { IMG_TAB_SEL_R, "graphics.IMG_TAB_SEL_R" },
234 { IMG_TAB_UNSEL, "graphics.IMG_TAB_UNSEL" },
235 { IMG_TAB_UNSEL_L, "graphics.IMG_TAB_UNSEL_L" },
236 { IMG_TAB_UNSEL_R, "graphics.IMG_TAB_UNSEL_R" },
237 { IMG_TAB_LINE, "graphics.IMG_TAB_LINE" },
238 { IMG_TAB_LINEL, "graphics.IMG_TAB_LINEL" },
239 { IMG_TAB_LINER, "graphics.IMG_TAB_LINER" },
240 { IMG_ICON_MISSING, "graphics.IMG_ICON_MISSING" },
241 { IMG_SELECTED_HILITE, "graphics.IMG_SELECTED_HILITE" },
242 { IMG_PREVIEW_MISSING, "graphics.IMG_PREVIEW_MISSING" },
243 { IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
244 { IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
245 { IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
246 { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
247 { IMG_FOLDER, "graphics.IMG_FOLDER", },
248 { IMG_EXECBIN, "graphics.IMG_EXECBIN", },
249 { IMG_SUBCATFOLDER, "graphics.IMG_SUBCATFOLDER", "graphics.IMG_FOLDER", },
250 { IMG_DOTDOTFOLDER, "graphics.IMG_DOTDOTFOLDER", "graphics.IMG_FOLDER", },
254 unsigned char ui_imagecache ( char *basepath ) {
256 char fullpath [ PATH_MAX ];
261 for ( i = 0; i < IMG_MAX; i++ ) {
263 if ( g_imagecache [ i ].id != i ) {
264 pnd_log ( pndn_error, "ERROR: Internal table mismatch during caching [%u]\n", i );
268 for ( try = 0; try < 2; try++ ) {
273 filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].confname );
275 if ( g_imagecache [ i ].alt_confname ) {
276 filename = pnd_conf_get_as_char ( g_conf, g_imagecache [ i ].alt_confname );
283 pnd_log ( pndn_error, "ERROR: (Try %u) Missing filename in conf for key: %s\n", try + 1, g_imagecache [ i ].confname );
284 if ( try == 0 ) { continue; } else { return ( 0 ); }
287 if ( filename [ 0 ] == '/' ) {
288 strncpy ( fullpath, filename, PATH_MAX );
290 sprintf ( fullpath, "%s/%s", basepath, filename );
293 if ( ( g_imagecache [ i ].i = IMG_Load ( fullpath ) ) ) {
294 break; // no retry needed
296 pnd_log ( pndn_error, "ERROR: (Try %u) Couldn't load static cache image: %s\n", try + 1, fullpath );
297 if ( try == 0 ) { continue; } else { return ( 0 ); }
305 //g_imagecache [ IMG_SELECTED_ALPHAMASK ].i = SDL_CreateRGBSurface ( SDL_SWSURFACE, 60, 60, 32, 0xFF0000, 0x00FF00, 0xFF, 0xFF000000 );
306 //boxRGBA ( g_imagecache [ IMG_SELECTED_ALPHAMASK ].i, 0, 0, 60, 60, 100, 100, 100, 250 );
312 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 );
313 // scale text hilight
314 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 );
315 // scale preview no-pic
316 g_imagecache [ IMG_PREVIEW_MISSING ].i = ui_scale_image ( g_imagecache [ IMG_PREVIEW_MISSING ].i,
317 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ),
318 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 50 ) );
320 // set alpha on detail panel
321 //SDL_SetAlpha ( g_imagecache [ IMG_DETAIL_BG ].i, SDL_SRCALPHA, pnd_conf_get_as_int_d ( g_conf, "display.detail_bg_alpha", 50 ) );
326 void ui_render ( void ) {
329 // divide width: 550 / 250
330 // divide left side: 5 columns == 110px width
331 // 20px buffer either side == 70px wide icon + 20 + 20?
333 // what jobs to do during render?
337 #define R_TABS (1<<1)
338 #define R_DETAIL (1<<2)
339 #define R_GRID (1<<3)
341 #define R_ALL (R_BG|R_TABS|R_DETAIL|R_GRID)
343 unsigned int render_jobs_b = 0;
345 if ( render_mask & CHANGED_EVERYTHING ) {
346 render_jobs_b |= R_ALL;
349 if ( render_mask & CHANGED_SELECTION ) {
350 render_jobs_b |= R_GRID;
351 render_jobs_b |= R_DETAIL;
354 if ( render_mask & CHANGED_CATEGORY ) {
355 render_jobs_b |= R_ALL;
358 render_mask = CHANGED_NOTHING;
362 unsigned int icon_rows;
365 SDL_Rect rects [ MAXRECTS ], src;
366 SDL_Rect *dest = rects;
367 bzero ( dest, sizeof(SDL_Rect)*MAXRECTS );
369 unsigned int row, displayrow, col;
370 mm_appref_t *appiter;
372 ui_context_t *c = &ui_display_context; // for convenience and shorthand
374 // how many total rows do we need?
375 if ( g_categorycount ) {
376 icon_rows = g_categories [ ui_category ] -> refcount / c -> col_max;
377 if ( g_categories [ ui_category ] -> refcount % c -> col_max > 0 ) {
385 // if no selected app yet, select the first one
386 if ( ! ui_selected && pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) ) {
388 // pick first visible app
389 ui_selected = g_categories [ ui_category ] -> refs;
391 // change.. so we pick first visible if option is set .. but now we also try to restore
392 // selection to the last app selected in previous session (if there is one.)
393 char *previous_unique_id = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_app_uid" );
395 if ( previous_unique_id ) {
397 // 1) we should already be in the right category, since its set in ui_post_scan to minimenu.last_known_catname
398 // 2) so we just pick the app in question..
399 mm_appref_t *previter = g_categories [ ui_category ] -> refs;
401 if ( strcmp ( previter -> ref -> unique_id, previous_unique_id ) == 0 ) {
404 previter = previter -> next;
408 ui_selected = previter;
416 // reset touchscreen regions
417 if ( render_jobs_b ) {
421 // ensure selection is visible
424 unsigned char autoscrolled = 1;
425 while ( autoscrolled ) {
428 int index = ui_selected_index();
429 int topleft = c -> col_max * ui_rows_scrolled_down;
430 int botright = ( c -> col_max * ( ui_rows_scrolled_down + c -> row_max ) - 1 );
432 if ( index < topleft ) {
433 ui_rows_scrolled_down -= pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
434 render_jobs_b |= R_ALL;
436 } else if ( index > botright ) {
437 ui_rows_scrolled_down += pnd_conf_get_as_int_d ( g_conf, "grid.scroll_increment", 1 );
438 render_jobs_b |= R_ALL;
442 } // while autoscrolling
444 if ( ui_rows_scrolled_down < 0 ) {
445 ui_rows_scrolled_down = 0;
446 } else if ( ui_rows_scrolled_down > icon_rows ) {
447 ui_rows_scrolled_down = icon_rows;
453 if ( render_jobs_b & R_BG ) {
455 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
458 dest -> w = sdl_realscreen -> w;
459 dest -> h = sdl_realscreen -> h;
460 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
465 if ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i ) {
468 dest -> w = sdl_realscreen -> w;
469 dest -> h = sdl_realscreen -> h;
470 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, NULL /* whole image */, sdl_realscreen, dest /* 0,0 */ );
477 if ( g_imagecache [ IMG_TAB_SEL ].i && g_imagecache [ IMG_TAB_UNSEL ].i ) {
478 static unsigned int tab_width;
479 static unsigned int tab_height;
480 static unsigned int tab_offset_x;
481 static unsigned int tab_offset_y;
482 static unsigned int text_offset_x;
483 static unsigned int text_offset_y;
484 static unsigned int text_width;
486 static unsigned char tab_first_run = 1;
487 if ( tab_first_run ) {
489 tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
490 tab_height = pnd_conf_get_as_int ( g_conf, "tabs.tab_height" );
491 tab_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_x" );
492 tab_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.tab_offset_y" );
493 text_offset_x = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_x" );
494 text_offset_y = pnd_conf_get_as_int ( g_conf, "tabs.text_offset_y" );
495 text_width = pnd_conf_get_as_int ( g_conf, "tabs.text_width" );
498 unsigned int maxtab = ( c -> screen_width / tab_width ) < g_categorycount ? ( c -> screen_width / tab_width ) + ui_catshift : g_categorycount + ui_catshift;
499 unsigned int maxtabspot = ( c -> screen_width / tab_width );
501 if ( g_categorycount > 0 ) {
503 // draw tabs with categories
504 for ( col = ui_catshift;
511 // if this is the first (leftmost) tab, we use different artwork
512 // than if the other tabs (so skinner can link lines up nicely.)
513 if ( col == ui_catshift ) {
514 // leftmost tab, special case
516 if ( col == ui_category ) {
517 s = g_imagecache [ IMG_TAB_SEL_L ].i;
519 s = g_imagecache [ IMG_TAB_UNSEL_L ].i;
522 } else if ( col == maxtab - 1 ) {
523 // rightmost tab, special case
525 if ( col == ui_category ) {
526 s = g_imagecache [ IMG_TAB_SEL_R ].i;
528 s = g_imagecache [ IMG_TAB_UNSEL_R ].i;
532 // normal (not leftmost) tab
534 if ( col == ui_category ) {
535 s = g_imagecache [ IMG_TAB_SEL ].i;
537 s = g_imagecache [ IMG_TAB_UNSEL ].i;
540 } // first col, or not first col?
547 if ( col == ui_category ) {
548 src.h = tab_selheight;
556 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
557 dest -> y = tab_offset_y;
560 ui_register_tab ( col, dest -> x, dest -> y, tab_width, tab_height );
562 if ( render_jobs_b & R_TABS ) {
563 //pnd_log ( pndn_debug, "tab %u at %ux%u\n", col, dest.x, dest.y );
564 SDL_BlitSurface ( s, &src, sdl_realscreen, dest );
568 if ( col == ui_category ) {
569 // no line for selected tab
571 if ( col - ui_catshift == 0 ) {
572 s = g_imagecache [ IMG_TAB_LINEL ].i;
573 } else if ( col - ui_catshift == maxtabspot - 1 ) {
574 s = g_imagecache [ IMG_TAB_LINER ].i;
576 s = g_imagecache [ IMG_TAB_LINE ].i;
578 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
579 dest -> y = tab_offset_y + tab_height;
580 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
586 rtext = TTF_RenderText_Blended ( g_tab_font, g_categories [ col ] -> catname, c -> fontcolor );
589 src.w = rtext -> w < text_width ? rtext -> w : text_width;
591 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width ) + text_offset_x;
592 dest -> y = tab_offset_y + text_offset_y;
593 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
594 SDL_FreeSurface ( rtext );
601 } // if we got categories
603 if ( render_jobs_b & R_TABS ) {
605 // draw tab lines under where tabs would be if we had categories
606 for ( /* foo */; col < maxtabspot; col++ ) {
609 if ( col - ui_catshift == 0 ) {
610 s = g_imagecache [ IMG_TAB_LINEL ].i;
611 } else if ( col - ui_catshift == maxtabspot - 1 ) {
612 s = g_imagecache [ IMG_TAB_LINER ].i;
614 s = g_imagecache [ IMG_TAB_LINE ].i;
616 dest -> x = tab_offset_x + ( (col-ui_catshift) * tab_width );
617 dest -> y = tab_offset_y + tab_height;
618 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, dest );
627 // scroll bars and arrows
628 if ( render_jobs_b & R_BG ) {
629 unsigned char show_bar = 0;
632 if ( ui_rows_scrolled_down && g_imagecache [ IMG_ARROW_UP ].i ) {
633 dest -> x = c -> arrow_up_x;
634 dest -> y = c -> arrow_up_y;
635 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_UP ].i, NULL /* whole image */, sdl_realscreen, dest );
642 if ( ui_rows_scrolled_down + c -> row_max < icon_rows && g_imagecache [ IMG_ARROW_DOWN ].i ) {
643 dest -> x = c -> arrow_down_x;
644 dest -> y = c -> arrow_down_y;
645 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_DOWN ].i, NULL /* whole image */, sdl_realscreen, dest );
652 // show scrollbar as well
655 src.w = c -> arrow_bar_clip_w;
656 src.h = c -> arrow_bar_clip_h;
657 dest -> x = c -> arrow_bar_x;
658 dest -> y = c -> arrow_bar_y;
659 SDL_BlitSurface ( g_imagecache [ IMG_ARROW_SCROLLBAR ].i, &src /* whole image */, sdl_realscreen, dest );
663 } // r_bg, scroll bars
665 // render detail pane bg
666 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
668 if ( pnd_conf_get_as_int_d ( g_conf, "detailpane.show", 1 ) ) {
671 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
672 src.x = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
673 src.y = 0; // pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
674 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> w;
675 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_PANEL ].i)) -> h;
676 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
677 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
678 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
682 // render detail pane
683 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
684 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
685 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
686 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
690 } // detailpane frame/bg
694 // anything to render?
695 if ( render_jobs_b & R_GRID && g_categorycount ) {
697 // if just rendering grid, and nothing else, better clear it first
698 if ( ! ( render_jobs_b & R_BG ) ) {
699 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
700 src.x = c -> grid_offset_x;
701 src.y = c -> grid_offset_y + c -> sel_icon_offset_y;
702 src.w = c -> col_max * c -> cell_width;
703 src.h = c -> row_max * c -> cell_height;
705 dest -> x = c -> grid_offset_x;
706 dest -> y = c -> grid_offset_y + c -> sel_icon_offset_y;
708 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
714 if ( g_categories [ ui_category ] -> refs ) {
716 appiter = g_categories [ ui_category ] -> refs;
720 // until we run out of apps, or run out of space
721 while ( appiter != NULL ) {
723 for ( col = 0; col < c -> col_max && appiter != NULL; col++ ) {
725 // do we even need to render it? or are we suppressing it due to rows scrolled off the top?
726 if ( row >= ui_rows_scrolled_down ) {
728 // selected? show hilights
729 if ( appiter == ui_selected ) {
730 SDL_Surface *s = g_imagecache [ IMG_SELECTED_ALPHAMASK ].i;
732 //dest -> x = grid_offset_x + ( col * cell_width ) + icon_offset_x + ( ( icon_max_width - s -> w ) / 2 );
733 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + c -> sel_icon_offset_x;
734 //dest -> y = grid_offset_y + ( displayrow * cell_height ) + icon_offset_y + ( ( icon_max_height - s -> h ) / 2 );
735 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + c -> sel_icon_offset_y;
736 SDL_BlitSurface ( s, NULL /* all */, sdl_realscreen, dest );
739 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
740 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_hilite_offset_y;
741 SDL_BlitSurface ( g_imagecache [ IMG_SELECTED_HILITE ].i, NULL /* all */, sdl_realscreen, dest );
746 mm_cache_t *ic = cache_query_icon ( appiter -> ref -> unique_id );
747 SDL_Surface *iconsurface;
749 iconsurface = ic -> i;
751 //pnd_log ( pndn_warning, "WARNING: TBD: Need Missin-icon icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
753 // no icon override; was this a pnd-file (show the unknown icon then), or was this generated from
754 // filesystem (file or directory icon)
755 if ( appiter -> ref -> object_flags & PND_DISCO_GENERATED ) {
756 if ( appiter -> ref -> object_type == pnd_object_type_directory ) {
758 // is this a subcat, a .., or a filesystem folder?
759 //iconsurface = g_imagecache [ IMG_FOLDER ].i;
760 if ( g_categories [ ui_category ] -> fspath ) {
761 iconsurface = g_imagecache [ IMG_FOLDER ].i;
762 } else if ( strcmp ( appiter -> ref -> title_en, ".." ) == 0 ) {
763 iconsurface = g_imagecache [ IMG_DOTDOTFOLDER ].i;
765 iconsurface = g_imagecache [ IMG_SUBCATFOLDER ].i;
769 iconsurface = g_imagecache [ IMG_EXECBIN ].i;
772 iconsurface = g_imagecache [ IMG_ICON_MISSING ].i;
777 // got an icon I hope?
779 //pnd_log ( pndn_debug, "Got an icon for '%s'\n", IFNULL(appiter -> ref -> title_en,"No Name") );
785 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> icon_offset_x + (( c -> icon_max_width - iconsurface -> w ) / 2);
786 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> icon_offset_y + (( c -> icon_max_height - iconsurface -> h ) / 2);
788 SDL_BlitSurface ( iconsurface, &src, sdl_realscreen, dest );
791 ui_register_app ( appiter, dest -> x, dest -> y, src.w, src.h );
798 if ( appiter -> ref -> title_en ) {
800 rtext = TTF_RenderText_Blended ( g_grid_font, appiter -> ref -> title_en, c -> fontcolor );
803 src.w = c -> text_width < rtext -> w ? c -> text_width : rtext -> w;
805 if ( rtext -> w > c -> text_width ) {
806 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_clip_x;
808 dest -> x = c -> grid_offset_x + ( col * c -> cell_width ) + c -> text_offset_x - ( rtext -> w / 2 );
810 dest -> y = c -> grid_offset_y + ( displayrow * c -> cell_height ) + c -> text_offset_y;
811 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
812 SDL_FreeSurface ( rtext );
816 } // display now? or scrolled away..
819 appiter = appiter -> next;
821 } // for column 1...X
823 if ( row >= ui_rows_scrolled_down ) {
829 // are we done displaying rows?
830 if ( displayrow >= c -> row_max ) {
837 // no apps to render?
838 pnd_log ( pndn_rem, "No applications to render?\n" );
843 // detail panel - show app details or blank-message
844 if ( render_jobs_b & R_DETAIL && ui_detail_hidden == 0 ) {
846 unsigned int cell_offset_x = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_x" );
847 unsigned int cell_offset_y = pnd_conf_get_as_int ( g_conf, "detailtext.cell_offset_y" );
848 unsigned int cell_width = pnd_conf_get_as_int ( g_conf, "detailtext.cell_width" );
850 unsigned int desty = cell_offset_y;
857 if ( ui_selected -> ref -> title_en ) {
859 rtext = TTF_RenderText_Blended ( g_detailtext_font, ui_selected -> ref -> title_en, c -> fontcolor );
862 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
864 dest -> x = cell_offset_x;
866 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
867 SDL_FreeSurface ( rtext );
874 if ( ui_selected -> ref -> main_category ) {
876 sprintf ( buffer, "Category: %s", ui_selected -> ref -> main_category );
879 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
882 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
884 dest -> x = cell_offset_x;
886 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
887 SDL_FreeSurface ( rtext );
894 if ( ui_selected -> ref -> clockspeed ) {
896 sprintf ( buffer, "CPU Clock: %s", ui_selected -> ref -> clockspeed );
899 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
902 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
904 dest -> x = cell_offset_x;
906 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
907 SDL_FreeSurface ( rtext );
912 // show sub-app# on right side of cpu clock?
913 //if ( ui_selected -> ref -> subapp_number )
915 sprintf ( buffer, "(app#%u)", ui_selected -> ref -> subapp_number );
918 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
919 dest -> x = cell_offset_x + cell_width - rtext -> w;
920 dest -> y = desty - src.h;
921 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
922 SDL_FreeSurface ( rtext );
927 #if 0 // merged into hint-line
928 if ( ui_selected -> ref -> info_filename ) {
930 sprintf ( buffer, "Documentation - hit Y" );
933 rtext = TTF_RenderText_Blended ( g_detailtext_font, buffer, c -> fontcolor );
936 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
938 dest -> x = cell_offset_x;
940 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
941 SDL_FreeSurface ( rtext );
948 if ( ui_selected -> ovrh ) {
953 desty += 5; // a touch of spacing can't hurt
955 for ( i = 1; i < 4; i++ ) {
956 sprintf ( buffer, "Application-%u.note-%u", ui_selected -> ref -> subapp_number, i );
957 n = pnd_conf_get_as_char ( ui_selected -> ovrh, buffer );
961 rtext = TTF_RenderText_Blended ( g_detailtext_font, n, c -> fontcolor );
964 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
966 dest -> x = cell_offset_x;
968 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
969 SDL_FreeSurface ( rtext );
975 } // r_detail -> notes
978 mm_cache_t *ic = cache_query_preview ( ui_selected -> ref -> unique_id );
979 SDL_Surface *previewpic;
982 previewpic = ic -> i;
984 previewpic = g_imagecache [ IMG_PREVIEW_MISSING ].i;
988 dest -> x = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_x", 50 ) +
989 ( ( pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 50 ) - previewpic -> w ) / 2 );
990 dest -> y = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_offset_y", 50 );
991 SDL_BlitSurface ( previewpic, NULL /* whole image */, sdl_realscreen, dest );
997 char *empty_message = "Press SELECT for menu";
1001 rtext = TTF_RenderText_Blended ( g_detailtext_font, empty_message, c -> fontcolor );
1005 src.w = rtext -> w < cell_width ? rtext -> w : cell_width;
1007 dest -> x = cell_offset_x;
1009 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1010 SDL_FreeSurface ( rtext );
1015 rtext = TTF_RenderText_Blended ( g_detailtext_font, "START or B to run app", c -> fontcolor );
1016 dest -> x = cell_offset_x;
1018 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1019 SDL_FreeSurface ( rtext );
1023 rtext = TTF_RenderText_Blended ( g_detailtext_font, "SPACE for app menu", c -> fontcolor );
1024 dest -> x = cell_offset_x;
1026 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1027 SDL_FreeSurface ( rtext );
1031 rtext = TTF_RenderText_Blended ( g_detailtext_font, "A to toggle details", c -> fontcolor );
1032 dest -> x = cell_offset_x;
1034 SDL_BlitSurface ( rtext, &src, sdl_realscreen, dest );
1035 SDL_FreeSurface ( rtext );
1039 } // r_detail && selected?
1047 if ( render_jobs_b & R_BG ) {
1048 static int last_battlevel = 0;
1049 static unsigned char batterylevel = 0;
1050 char buffer [ 100 ];
1052 if ( time ( NULL ) - last_battlevel > 60 ) {
1053 batterylevel = pnd_device_get_battery_gauge_perc();
1054 last_battlevel = time ( NULL );
1057 sprintf ( buffer, "Battery: %u%%", batterylevel );
1060 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1061 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.battery_x", 20 );
1062 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.battery_y", 450 );
1063 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1064 SDL_FreeSurface ( rtext );
1069 if ( pnd_conf_get_as_char ( g_conf, "display.hintline" ) ) {
1071 unsigned int hintx, hinty;
1072 hintx = pnd_conf_get_as_int_d ( g_conf, "display.hint_x", 40 );
1073 hinty = pnd_conf_get_as_int_d ( g_conf, "display.hint_y", 450 );
1074 static unsigned int lastwidth = 3000;
1076 if ( ui_selected && ui_selected -> ref -> info_filename ) {
1077 buffer = "Documentation - hit Y";
1079 buffer = pnd_conf_get_as_char ( g_conf, "display.hintline" );
1083 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1086 if ( ! ( render_jobs_b & R_BG ) ) {
1093 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_TABMASK ].i, &src, sdl_realscreen, dest );
1095 lastwidth = rtext -> w;
1101 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1102 SDL_FreeSurface ( rtext );
1107 if ( render_jobs_b & R_BG &&
1108 pnd_conf_get_as_int_d ( g_conf, "display.clock_x", -1 ) != -1 )
1112 time_t t = time ( NULL );
1113 struct tm *tm = localtime ( &t );
1114 strftime ( buffer, 50, "%a %H:%M %F", tm );
1117 rtext = TTF_RenderText_Blended ( g_grid_font, buffer, c -> fontcolor );
1118 dest -> x = pnd_conf_get_as_int_d ( g_conf, "display.clock_x", 700 );
1119 dest -> y = pnd_conf_get_as_int_d ( g_conf, "display.clock_y", 450 );
1120 SDL_BlitSurface ( rtext, NULL /* all */, sdl_realscreen, dest );
1121 SDL_FreeSurface ( rtext );
1125 // update all the rects and send it all to sdl
1126 // - at this point, we could probably just do 1 rect, of the
1127 // whole screen, and be faster :/
1128 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
1132 void ui_process_input ( pnd_dbusnotify_handle dbh, pnd_notify_handle nh ) {
1135 unsigned char ui_event = 0; // if we get a ui event, flip to 1 and break
1136 //static ui_sdl_button_e ui_mask = uisb_none; // current buttons down
1138 while ( ( ! ui_event ) &&
1139 /*block_p ?*/ SDL_WaitEvent ( &event ) /*: SDL_PollEvent ( &event )*/ )
1142 switch ( event.type ) {
1147 // the user-defined SDL events are all for threaded/delayed previews (and icons, which
1148 // generally are not used); if we're in wide mode, we can skip previews
1149 // to avoid slowing things down when they're not shown.
1151 if ( event.user.code == sdl_user_ticker ) {
1153 if ( ui_detail_hidden ) {
1154 break; // skip building previews when not showing them
1157 // timer went off, time to load something
1158 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
1160 if ( ! ui_selected ) {
1164 // load the preview pics now!
1165 pnd_disco_t *iter = ui_selected -> ref;
1167 if ( iter -> preview_pic1 ) {
1169 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
1170 // load in bg thread, make user experience chuggy
1172 g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
1174 if ( ! g_preview_thread ) {
1175 pnd_log ( pndn_error, "ERROR: Couldn't create preview thread\n" );
1179 // load it now, make user wait
1181 if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
1182 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
1185 pnd_log ( pndn_debug, " Couldn't load preview pic: '%s' -> '%s'\n",
1186 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1191 } // got a preview at all?
1196 } else if ( event.user.code == sdl_user_finishedpreview ) {
1198 // if we just finished the one we happen to be looking at, better redraw now; otherwise, if
1199 // we finished another, no big woop
1200 if ( ui_selected && event.user.data1 == ui_selected -> ref ) {
1204 } else if ( event.user.code == sdl_user_finishedicon ) {
1205 // redraw, so we can show the newly loaded icon
1208 } else if ( event.user.code == sdl_user_checksd ) {
1209 // check if any inotify-type events occured, forcing us to rescan/re-disco the SDs
1211 unsigned char watch_dbus = 0;
1212 unsigned char watch_inotify = 0;
1215 watch_dbus = pnd_dbusnotify_rediscover_p ( dbh );
1219 watch_inotify = pnd_notify_rediscover_p ( nh );
1222 if ( watch_dbus || watch_inotify ) {
1223 pnd_log ( pndn_debug, "dbusnotify detected SD event\n" );
1224 applications_free();
1225 applications_scan();
1232 render_mask |= CHANGED_EVERYTHING;
1236 #if 0 // joystick motion
1237 case SDL_JOYAXISMOTION:
1239 pnd_log ( PND_LOG_DEFAULT, "joystick axis\n" );
1241 if ( event.jaxis.axis == 0 ) {
1243 if ( event.jaxis.value < 0 ) {
1245 pnd_log ( PND_LOG_DEFAULT, "joystick axis - LEFT\n" );
1246 } else if ( event.jaxis.value > 0 ) {
1247 ui_push_right ( 0 );
1248 pnd_log ( PND_LOG_DEFAULT, "joystick axis - RIGHT\n" );
1250 } else if ( event.jaxis.axis == 1 ) {
1252 if ( event.jaxis.value < 0 ) {
1254 } else if ( event.jaxis.value > 0 ) {
1264 #if 0 // joystick buttons
1265 case SDL_JOYBUTTONDOWN:
1267 pnd_log ( PND_LOG_DEFAULT, "joystick button down %u\n", event.jbutton.button );
1269 if ( event.jbutton.button == 0 ) { // B
1271 } else if ( event.jbutton.button == 1 ) { // Y
1273 } else if ( event.jbutton.button == 2 ) { // X
1275 } else if ( event.jbutton.button == 3 ) { // A
1278 } else if ( event.jbutton.button == 4 ) { // Select
1279 ui_mask |= uisb_select;
1280 } else if ( event.jbutton.button == 5 ) { // Start
1281 ui_mask |= uisb_start;
1283 } else if ( event.jbutton.button == 7 ) { // L
1285 } else if ( event.jbutton.button == 8 ) { // R
1294 case SDL_JOYBUTTONUP:
1296 pnd_log ( PND_LOG_DEFAULT, "joystick button up %u\n", event.jbutton.button );
1298 if ( event.jbutton.button == 0 ) { // B
1301 } else if ( event.jbutton.button == 1 ) { // Y
1303 } else if ( event.jbutton.button == 2 ) { // X
1305 } else if ( event.jbutton.button == 3 ) { // A
1308 } else if ( event.jbutton.button == 4 ) { // Select
1309 ui_mask &= ~uisb_select;
1310 } else if ( event.jbutton.button == 5 ) { // Start
1311 ui_mask &= ~uisb_start;
1313 } else if ( event.jbutton.button == 7 ) { // L
1316 } else if ( event.jbutton.button == 8 ) { // R
1327 #if 1 // keyboard events
1331 //pnd_log ( pndn_debug, "key up %u\n", event.key.keysym.sym );
1333 // SDLK_LALT -> Start
1334 // page up/down for y/x
1335 // home/end for a and b
1338 if ( event.key.keysym.sym == SDLK_RIGHT ) {
1339 ui_push_right ( 0 );
1341 } else if ( event.key.keysym.sym == SDLK_LEFT ) {
1344 } else if ( event.key.keysym.sym == SDLK_UP ) {
1347 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
1350 } else if ( event.key.keysym.sym == SDLK_END ) { // B
1353 } else if ( event.key.keysym.sym == SDLK_SPACE ) { // space
1354 if ( ui_selected ) {
1355 ui_menu_context ( ui_selected );
1357 // TBD: post an error?
1359 render_mask |= CHANGED_EVERYTHING;
1361 } else if ( event.key.keysym.sym == SDLK_TAB || event.key.keysym.sym == SDLK_HOME ) { // tab or A
1362 // if detail panel is togglable, then toggle it
1363 // if not, make sure its ruddy well shown!
1364 if ( ui_is_detail_hideable() ) {
1365 ui_toggle_detail_pane();
1367 ui_detail_hidden = 0;
1370 } else if ( event.key.keysym.sym == SDLK_RSHIFT || event.key.keysym.sym == SDLK_COMMA ) { // left trigger or comma
1373 } else if ( event.key.keysym.sym == SDLK_RCTRL || event.key.keysym.sym == SDLK_PERIOD ) { // right trigger or period
1377 } else if ( event.key.keysym.sym == SDLK_PAGEUP ) { // Y
1379 if ( ui_selected ) {
1380 ui_show_info ( pnd_run_script, ui_selected -> ref );
1383 } else if ( event.key.keysym.sym == SDLK_PAGEDOWN ) { // X
1386 // forget the selection, nolonger applies
1388 ui_set_selected ( ui_selected );
1390 if ( g_categories [ ui_category ] -> fspath ) {
1391 category_fs_restock ( g_categories [ ui_category ] );
1394 render_mask |= CHANGED_EVERYTHING;
1397 } else if ( event.key.keysym.sym == SDLK_LALT ) { // start button
1401 } else if ( event.key.keysym.sym == SDLK_LCTRL /*LALT*/ ) { // select button
1402 char *opts [ 20 ] = {
1403 "Reveal hidden category",
1405 "Configure Minimenu",
1406 "Manage custom app categories",
1407 "Rescan for applications",
1408 "Cache previews to SD now",
1409 "Run a terminal/console",
1410 "Run another GUI (xfce, etc)",
1412 "Select a Minimenu skin",
1415 int sel = ui_modal_single_menu ( opts, 11, "Minimenu", "Enter to select; other to return." );
1417 char buffer [ 100 ];
1421 } else if ( sel == 1 ) {
1423 sprintf ( buffer, "sudo poweroff" );
1425 } else if ( sel == 2 ) {
1427 unsigned char restart = conf_run_menu ( NULL );
1428 conf_write ( g_conf, conf_determine_location ( g_conf ) );
1429 conf_write ( g_conf, CONF_PREF_TEMPPATH );
1431 emit_and_quit ( MM_RESTART );
1433 } else if ( sel == 3 ) {
1434 // manage custom categories
1435 ui_manage_categories();
1436 } else if ( sel == 4 ) {
1438 pnd_log ( pndn_debug, "Freeing up applications\n" );
1439 applications_free();
1440 pnd_log ( pndn_debug, "Rescanning applications\n" );
1441 applications_scan();
1442 } else if ( sel == 5 ) {
1443 // cache preview to SD now
1444 extern pnd_box_handle g_active_apps;
1445 pnd_box_handle h = g_active_apps;
1447 unsigned int maxwidth, maxheight;
1448 maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
1449 maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
1451 pnd_disco_t *iter = pnd_box_get_head ( h );
1456 if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
1457 pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
1458 IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
1462 iter = pnd_box_get_next ( iter );
1465 } else if ( sel == 6 ) {
1468 argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
1472 ui_forkexec ( argv );
1475 } else if ( sel == 7 ) {
1476 char buffer [ PATH_MAX ];
1477 sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/pandora/scripts/op_switchgui.sh" );
1478 emit_and_quit ( buffer );
1479 } else if ( sel == 8 ) {
1480 emit_and_quit ( MM_QUIT );
1481 } else if ( sel == 9 ) {
1483 if ( ui_pick_skin() ) {
1484 emit_and_quit ( MM_RESTART );
1486 } else if ( sel == 10 ) {
1488 char buffer [ PATH_MAX ];
1489 sprintf ( buffer, "%s/about.txt", g_skinpath );
1490 ui_aboutscreen ( buffer );
1494 render_mask |= CHANGED_EVERYTHING;
1497 // unknown SDLK_ keycode?
1499 // many SDLK_keycodes map to ASCII ("a" is ascii(a)), so try to jump to a filename of that name, in this category?
1500 // and if already there, try to jump to next, maybe?
1501 // future: look for sequence typing? ie: user types 'm' then 'a', look for 'ma*' instead of 'm' then 'a' matching
1502 if ( isalpha ( event.key.keysym.sym ) && g_categories [ ui_category ] -> refcount > 0 ) {
1503 mm_appref_t *app = g_categories [ ui_category ] -> refs;
1505 //fprintf ( stderr, "sel %s next %s\n", ui_selected -> ref -> title_en, ui_selected -> next -> ref -> title_en );
1507 // are we already matching the same char? and next item is also same char?
1508 if ( app && ui_selected && ui_selected -> next &&
1509 ui_selected -> ref -> title_en && ui_selected -> next -> ref -> title_en &&
1510 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( ui_selected -> next -> ref -> title_en [ 0 ] ) &&
1511 toupper ( ui_selected -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym )
1514 // just skip down one
1515 app = ui_selected -> next;
1518 // walk the category, looking for a first-char match
1520 if ( app -> ref -> title_en && toupper ( app -> ref -> title_en [ 0 ] ) == toupper ( event.key.keysym.sym ) ) {
1526 } // same start letter, or new run?
1528 // found something, or no?
1530 // looks like we found a potential match; try switching it to visible selection
1532 ui_set_selected ( ui_selected );
1537 } // SDLK_alphanumeric?
1543 if ( event.key.keysym.sym == SDLK_ESCAPE ) {
1544 emit_and_quit ( MM_QUIT );
1551 #if 1 // mouse / touchscreen
1553 case SDL_MOUSEBUTTONDOWN:
1554 if ( event.button.button == SDL_BUTTON_LEFT ) {
1555 cb_pointer_press ( gc, event.button.x / g_scale, event.button.y / g_scale );
1561 case SDL_MOUSEBUTTONUP:
1562 if ( event.button.button == SDL_BUTTON_LEFT ) {
1563 ui_touch_act ( event.button.x, event.button.y );
1576 } // switch event type
1583 void ui_push_left ( unsigned char forcecoil ) {
1585 if ( ! ui_selected ) {
1586 ui_push_right ( 0 );
1590 // what column we in?
1591 unsigned int col = ui_determine_screen_col ( ui_selected );
1593 // are we already at first item?
1594 if ( forcecoil == 0 &&
1595 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1598 unsigned int i = ui_display_context.col_max - 1;
1599 while ( i && ui_selected -> next ) {
1600 ui_push_right ( 0 );
1604 } else if ( g_categories [ ui_category ] -> refs == ui_selected ) {
1605 // can't go any more left, we're at the head
1608 // figure out the previous item; yay for singly linked list :/
1609 mm_appref_t *i = g_categories [ ui_category ] -> refs;
1611 if ( i -> next == ui_selected ) {
1619 ui_set_selected ( ui_selected );
1624 void ui_push_right ( unsigned char forcecoil ) {
1626 if ( ui_selected ) {
1628 // what column we in?
1629 unsigned int col = ui_determine_screen_col ( ui_selected );
1632 if ( forcecoil == 0 &&
1633 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_horiz_samerow", 0 ) &&
1634 // and selected is far-right, or last icon in category (might not be far right)
1635 ( ( col == ui_display_context.col_max - 1 ) ||
1636 ( ui_selected -> next == NULL ) )
1640 //unsigned int i = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 ) - 1;
1641 while ( col /*i*/ ) {
1647 // just go to the next
1649 if ( ui_selected -> next ) {
1650 ui_selected = ui_selected -> next;
1656 ui_selected = g_categories [ ui_category ] -> refs;
1659 ui_set_selected ( ui_selected );
1664 void ui_push_up ( void ) {
1665 unsigned char col_max = ui_display_context.col_max;
1667 if ( ! ui_selected ) {
1672 unsigned int row = ui_determine_row ( ui_selected );
1675 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1677 // wrap around instead
1679 unsigned int col = ui_determine_screen_col ( ui_selected );
1682 ui_selected = g_categories [ ui_category ] -> refs;
1683 while ( ui_selected -> next ) {
1684 ui_selected = ui_selected -> next;
1687 // try to move to same column
1688 unsigned int newcol = ui_determine_screen_col ( ui_selected );
1689 if ( newcol > col ) {
1697 // scroll down to show it
1698 int r = ui_determine_row ( ui_selected ) - 1;
1699 if ( r - ui_display_context.row_max > 0 ) {
1700 ui_rows_scrolled_down = (unsigned int) r;
1704 // stop at top/bottom
1716 void ui_push_down ( void ) {
1717 unsigned char col_max = ui_display_context.col_max;
1719 if ( ui_selected ) {
1722 unsigned int row = ui_determine_row ( ui_selected );
1725 unsigned int icon_rows = g_categories [ ui_category ] -> refcount / col_max;
1726 if ( g_categories [ ui_category ] -> refcount % col_max > 0 ) {
1731 if ( row == ( icon_rows - 1 ) &&
1732 pnd_conf_get_as_int_d ( g_conf, "grid.wrap_vert_stop", 0 ) == 0 )
1735 unsigned char col = ui_determine_screen_col ( ui_selected );
1737 ui_selected = g_categories [ ui_category ] -> refs;
1740 ui_selected = ui_selected -> next;
1744 ui_rows_scrolled_down = 0;
1746 render_mask |= CHANGED_EVERYTHING;
1751 ui_push_right ( 1 );
1758 ui_push_right ( 0 );
1764 // 'backup' is currently 'X', for going back up in a folder/subcat without having to hit exec on the '..' entry
1765 void ui_push_backup ( void ) {
1767 // a subcat-as-dir, or a dir browser?
1768 if ( g_categories [ ui_category] -> fspath ) {
1769 // dir browser, just climb our way back up
1774 // lop off last word; if the thing ends with /, lop that one, then the next word.
1775 while ( ( c = strrchr ( g_categories [ ui_category] -> fspath, '/' ) ) ) {
1776 *c = '\0'; // lop off the last hunk
1777 if ( *(c+1) != '\0' ) {
1783 if ( g_categories [ ui_category] -> fspath [ 0 ] == '\0' ) {
1784 free ( g_categories [ ui_category] -> fspath );
1785 g_categories [ ui_category] -> fspath = strdup ( "/" );
1789 // a pnd subcat .. are we in one, or at the 'top'?
1790 char *pcatname = g_categories [ ui_category ] -> parent_catname;
1793 return; // we're at the 'top' already
1796 // set to first cat!
1799 // republish cats .. shoudl just be the one
1800 category_publish ( CFNORMAL, NULL );
1803 ui_category = category_index ( pcatname );
1805 // ensure tab visible?
1806 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
1807 if ( ui_category > ui_catshift + ( ui_display_context.screen_width / tab_width ) - 1 ) {
1808 ui_catshift = ui_category - ( ui_display_context.screen_width / tab_width ) + 1;
1818 void ui_push_exec ( void ) {
1820 if ( ! ui_selected ) {
1824 // cache the category/app so we can come back to it another time
1825 if ( ui_selected ) {
1826 pnd_conf_set_char ( g_conf, "minimenu.last_known_app_uid", ui_selected -> ref -> unique_id );
1828 if ( g_categories [ 0 ] ) {
1829 pnd_conf_set_char ( g_conf, "minimenu.last_known_catname", g_categories [ ui_category ] -> catname );
1831 // and also the parent cat..
1832 if ( g_categories [ ui_category ] -> parent_catname ) {
1833 pnd_conf_set_char ( g_conf, "minimenu.last_known_parentcatname", g_categories [ ui_category ] -> parent_catname );
1835 char *kv = pnd_box_find_by_key ( g_conf, "minimenu.last_known_parentcatname" );
1837 pnd_box_delete_node ( g_conf, kv );
1843 // cache last known cat/app to /tmp, so we can use it again later
1844 conf_write ( g_conf, CONF_PREF_TEMPPATH );
1846 // was this icon generated from filesystem, or from pnd-file?
1847 if ( ui_selected -> ref -> object_flags & PND_DISCO_GENERATED ) {
1849 if ( ! ui_selected -> ref -> title_en ) {
1850 return; // no filename
1853 if ( ui_selected -> ref -> object_type == pnd_object_type_directory ) {
1855 // check if this guy is a dir-browser tab, or is a directory on a pnd tab
1856 if ( ! g_categories [ ui_category] -> fspath ) {
1857 // pnd subcat as dir
1859 // are we already in a subcat? if so, go back to parent; there is no grandparenting or deeper
1860 if ( g_categories [ ui_category ] -> parent_catname ) {
1865 // delve into subcat
1867 // set to first cat!
1871 // republish cats .. shoudl just be the one
1872 category_publish ( CFBYNAME, ui_selected -> ref -> object_path );
1876 // forget the selection, nolonger applies
1878 ui_set_selected ( ui_selected );
1880 render_mask |= CHANGED_EVERYTHING;
1884 // delve up/down the dir tree
1885 if ( strcmp ( ui_selected -> ref -> title_en, ".." ) == 0 ) {
1890 char *temp = malloc ( strlen ( g_categories [ ui_category] -> fspath ) + strlen ( ui_selected -> ref -> title_en ) + 1 + 1 );
1891 sprintf ( temp, "%s/%s", g_categories [ ui_category] -> fspath, ui_selected -> ref -> title_en );
1892 free ( g_categories [ ui_category] -> fspath );
1893 g_categories [ ui_category] -> fspath = temp;
1896 pnd_log ( pndn_debug, "Cat %s is now in path %s\n", g_categories [ ui_category ] -> catname, g_categories [ ui_category ]-> fspath );
1898 // forget the selection, nolonger applies
1900 ui_set_selected ( ui_selected );
1902 category_fs_restock ( g_categories [ ui_category ] );
1904 render_mask |= CHANGED_SELECTION;
1906 } // directory browser or pnd subcat?
1909 // just run it arbitrarily?
1911 // if this a pnd-file, or just some executable?
1912 if ( strcasestr ( ui_selected -> ref -> object_filename, PND_PACKAGE_FILEEXT ) ) {
1913 // looks like a pnd, now what do we do..
1914 pnd_box_handle h = pnd_disco_file ( ui_selected -> ref -> object_path, ui_selected -> ref -> object_filename );
1917 pnd_disco_t *d = pnd_box_get_head ( h );
1918 pnd_apps_exec_disco ( pnd_run_script, d, PND_EXEC_OPTION_NORUN, NULL );
1919 char buffer [ PATH_MAX ];
1920 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
1921 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1922 emit_and_quit ( buffer );
1924 emit_and_run ( buffer );
1931 // is it even executable? if we don't have handlers for non-executables yet (Jan 2011 we don't),
1932 // then don't even try to run things not-flagged as executable.. but wait most people are on
1933 // FAT filesystems, what a drag, we can't tell at the fs level.
1934 // ... but we can still invoke 'file' and grep out the good bits, at least.
1936 // open a stream reading 'file /path/to/file' and check output for 'executable'
1937 // -- not checking for "ARM" so it can pick up x86 (or whatever native) executables in build environment
1938 unsigned char is_executable = 0;
1942 char popenbuf [ FILENAME_MAX ];
1943 snprintf ( popenbuf, FILENAME_MAX, "%s %s/%s", MIMETYPE_EXE, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1946 if ( ! ( marceau = popen ( popenbuf, "r" ) ) ) {
1947 return; // error, we need some useful error handling and dialog boxes here
1950 if ( fgets ( popenbuf, FILENAME_MAX, marceau ) ) {
1951 //printf ( "File test returns: %s\n", popenbuf );
1952 if ( strstr ( popenbuf, "executable" ) != NULL ) {
1961 if ( ! is_executable ) {
1962 fprintf ( stderr, "ERROR: File to invoke is not executable, skipping. (%s)\n", ui_selected -> ref -> title_en );
1963 return; // need some error handling here
1966 #if 0 // eat up any pending SDL events and toss 'em?
1970 while ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_ALLEVENTS ) > 0 ) {
1980 // get CWD so we can restore it on return
1981 char cwd [ PATH_MAX ];
1982 getcwd ( cwd, PATH_MAX );
1984 // full path to executable so we don't rely on implicit "./"
1985 char execbuf [ FILENAME_MAX ];
1986 snprintf ( execbuf, FILENAME_MAX, "%s/%s", g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1989 chdir ( g_categories [ ui_category ] -> fspath );
1990 exec_raw_binary ( execbuf /*ui_selected -> ref -> title_en*/ );
1993 // DEPRECATED / NOT TESTED
1994 // get mmwrapper to run it
1995 char buffer [ PATH_MAX ];
1996 sprintf ( buffer, "%s %s/%s\n", MM_RUN, g_categories [ ui_category ] -> fspath, ui_selected -> ref -> title_en );
1997 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
1998 emit_and_quit ( buffer );
2000 emit_and_run ( buffer );
2009 // set app-run speed
2010 int use_run_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.use_run_speed", 0 );
2011 if ( use_run_speed > 0 ) {
2012 int mm_speed = pnd_conf_get_as_int_d ( g_conf, "minimenu.run_speed", -1 );
2013 if ( mm_speed > -1 ) {
2014 char buffer [ 512 ];
2015 snprintf ( buffer, 500, "sudo /usr/pandora/scripts/op_cpuspeed.sh %d", mm_speed );
2018 } // do speed change?
2020 // request app to run and quit mmenu
2021 pnd_apps_exec_disco ( pnd_run_script, ui_selected -> ref, PND_EXEC_OPTION_NORUN, NULL );
2022 char buffer [ PATH_MAX ];
2023 sprintf ( buffer, "%s %s\n", MM_RUN, pnd_apps_exec_runline() );
2024 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.live_on_run", 0 ) == 0 ) {
2025 emit_and_quit ( buffer );
2027 emit_and_run ( buffer );
2034 void ui_push_ltrigger ( void ) {
2035 unsigned char oldcat = ui_category;
2036 unsigned int screen_width = ui_display_context.screen_width;
2037 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2039 if ( g_categorycount == 0 ) {
2043 if ( g_icon_thread_busy ) {
2044 ui_stop_defered_icon_thread();
2047 if ( ui_category > 0 ) {
2049 category_fs_restock ( g_categories [ ui_category ] );
2051 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
2052 ui_category = g_categorycount - 1;
2054 if ( ui_category >= ( screen_width / tab_width ) ) {
2055 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2057 category_fs_restock ( g_categories [ ui_category ] );
2061 if ( oldcat != ui_category ) {
2063 ui_set_selected ( ui_selected );
2066 // make tab visible?
2067 if ( ui_catshift > 0 && ui_category == ui_catshift - 1 ) {
2072 ui_rows_scrolled_down = 0;
2074 render_mask |= CHANGED_CATEGORY;
2075 ui_start_defered_icon_thread();
2080 void ui_push_rtrigger ( void ) {
2081 unsigned char oldcat = ui_category;
2083 if ( g_categorycount == 0 ) {
2087 if ( g_icon_thread_busy ) {
2088 ui_stop_defered_icon_thread();
2091 unsigned int screen_width = ui_display_context.screen_width;
2092 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2094 if ( ui_category < ( g_categorycount - 1 ) ) {
2096 category_fs_restock ( g_categories [ ui_category ] );
2098 if ( pnd_conf_get_as_int_d ( g_conf, "tabs.wraparound", 0 ) > 0 ) {
2101 category_fs_restock ( g_categories [ ui_category ] );
2105 if ( oldcat != ui_category ) {
2107 ui_set_selected ( ui_selected );
2110 // make tab visible?
2111 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2116 ui_rows_scrolled_down = 0;
2118 render_mask |= CHANGED_CATEGORY;
2119 ui_start_defered_icon_thread();
2124 SDL_Surface *ui_scale_image ( SDL_Surface *s, unsigned int maxwidth, int maxheight ) {
2125 double scale = 1000000.0;
2126 double scalex = 1000000.0;
2127 double scaley = 1000000.0;
2128 SDL_Surface *scaled;
2130 scalex = (double)maxwidth / (double)s -> w;
2132 if ( maxheight == -1 ) {
2135 scaley = (double)maxheight / (double)s -> h;
2137 if ( scaley < scalex ) {
2145 scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
2146 SDL_FreeSurface ( s );
2152 void ui_loadscreen ( void ) {
2157 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2161 rtext = TTF_RenderText_Blended ( g_big_font, "Setting up menu...", ui_display_context.fontcolor );
2164 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2165 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2166 SDL_FreeSurface ( rtext );
2171 void ui_discoverscreen ( unsigned char clearscreen ) {
2176 if ( clearscreen ) {
2177 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2179 // render background
2180 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2183 dest.w = sdl_realscreen -> w;
2184 dest.h = sdl_realscreen -> h;
2185 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2186 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2193 rtext = TTF_RenderText_Blended ( g_big_font, "Looking for applications...", ui_display_context.fontcolor );
2194 if ( clearscreen ) {
2201 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, &dest );
2202 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2203 SDL_FreeSurface ( rtext );
2206 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2207 dest.x = rtext -> w + 30;
2209 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, &dest );
2210 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2216 void ui_cachescreen ( unsigned char clearscreen, char *filename ) {
2218 SDL_Rect rects [ 4 ];
2219 SDL_Rect *dest = rects;
2221 bzero ( dest, sizeof(SDL_Rect)* 4 );
2223 unsigned int font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
2224 unsigned int font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
2225 unsigned int font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
2226 unsigned int font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
2228 static unsigned int stepx = 0;
2231 if ( clearscreen ) {
2232 SDL_FillRect( SDL_GetVideoSurface(), NULL, 0 );
2234 // render background
2235 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2238 dest -> w = sdl_realscreen -> w;
2239 dest -> h = sdl_realscreen -> h;
2240 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, NULL /* whole image */, sdl_realscreen, NULL /* 0,0 */ );
2246 // render background
2247 if ( g_imagecache [ IMG_BACKGROUND_800480 ].i ) {
2250 src.w = sdl_realscreen -> w;
2254 dest -> w = sdl_realscreen -> w;
2255 dest -> h = sdl_realscreen -> h;
2256 SDL_BlitSurface ( g_imagecache [ IMG_BACKGROUND_800480 ].i, &src, sdl_realscreen, dest );
2264 SDL_Color tmpfontcolor = { font_rgba_r, font_rgba_g, font_rgba_b, font_rgba_a };
2265 rtext = TTF_RenderText_Blended ( g_big_font, "Caching applications artwork...", tmpfontcolor );
2268 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2269 SDL_FreeSurface ( rtext );
2273 if ( g_imagecache [ IMG_ICON_MISSING ].i ) {
2274 dest -> x = rtext -> w + 30 + stepx;
2276 SDL_BlitSurface ( g_imagecache [ IMG_ICON_MISSING ].i, NULL, sdl_realscreen, dest );
2282 rtext = TTF_RenderText_Blended ( g_tab_font, filename, tmpfontcolor );
2285 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2286 SDL_FreeSurface ( rtext );
2293 if ( stepx > 350 ) {
2297 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2302 int ui_selected_index ( void ) {
2304 if ( ! ui_selected ) {
2305 return ( -1 ); // no index
2308 mm_appref_t *r = g_categories [ ui_category ] -> refs;
2311 if ( r == ui_selected ) {
2321 static mm_appref_t *timer_ref = NULL;
2322 void ui_set_selected ( mm_appref_t *r ) {
2324 render_mask |= CHANGED_SELECTION;
2326 // preview pic stuff
2329 if ( ! pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
2330 return; // no desire to defer anything
2335 SDL_SetTimer ( 0, NULL );
2340 SDL_SetTimer ( pnd_conf_get_as_int_d ( g_conf, "previewpic.defer_timer_ms", 1000 ), ui_callback_f );
2346 unsigned int ui_callback_f ( unsigned int t ) {
2348 if ( ui_selected != timer_ref ) {
2349 return ( 0 ); // user has moved it, who cares
2353 bzero ( &e, sizeof(SDL_Event) );
2354 e.type = SDL_USEREVENT;
2355 e.user.code = sdl_user_ticker;
2356 SDL_PushEvent ( &e );
2361 int ui_modal_single_menu ( char *argv[], unsigned int argc, char *title, char *footer ) {
2362 SDL_Rect rects [ 40 ];
2363 SDL_Rect *dest = rects;
2366 unsigned char max_visible = pnd_conf_get_as_int_d ( g_conf, "detailtext.max_visible" , 11 );
2367 unsigned char first_visible = 0;
2369 bzero ( rects, sizeof(SDL_Rect) * 40 );
2371 unsigned int sel = 0;
2373 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 };
2381 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2382 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2383 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
2384 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
2385 SDL_FillRect( sdl_realscreen, dest, 0 );
2387 // show dialog background
2388 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
2391 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
2392 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
2393 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2394 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2395 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2396 // repeat for darken?
2397 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2398 //SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
2399 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2403 // show dialog frame
2404 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
2405 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
2406 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
2407 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
2408 //SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2414 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
2415 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2416 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
2417 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2418 SDL_FreeSurface ( rtext );
2424 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
2425 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2426 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
2427 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
2429 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2430 SDL_FreeSurface ( rtext );
2435 for ( i = first_visible; i < first_visible + max_visible && i < argc; i++ ) {
2439 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], selfontcolor );
2441 rtext = TTF_RenderText_Blended ( g_tab_font, argv [ i ], ui_display_context.fontcolor );
2443 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
2444 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( i + 1 - first_visible ) );
2445 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
2446 SDL_FreeSurface ( rtext );
2451 // update all the rects and send it all to sdl
2452 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
2456 while ( SDL_WaitEvent ( &event ) ) {
2458 switch ( event.type ) {
2463 if ( event.key.keysym.sym == SDLK_UP ) {
2467 if ( sel < first_visible ) {
2472 } else if ( event.key.keysym.sym == SDLK_DOWN ) {
2474 if ( sel < argc - 1 ) {
2477 // ensure visibility
2478 if ( sel >= first_visible + max_visible ) {
2484 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
2488 } else if ( event.key.keysym.sym == SDLK_q ) {
2493 return ( -1 ); // nada
2508 unsigned char ui_determine_row ( mm_appref_t *a ) {
2509 unsigned int row = 0;
2511 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2516 row /= ui_display_context.col_max;
2521 unsigned char ui_determine_screen_row ( mm_appref_t *a ) {
2522 return ( ui_determine_row ( a ) % ui_display_context.row_max );
2525 unsigned char ui_determine_screen_col ( mm_appref_t *a ) {
2526 unsigned int col = 0;
2528 mm_appref_t *i = g_categories [ ui_category ] -> refs;
2533 col %= ui_display_context.col_max;
2538 unsigned char ui_show_info ( char *pndrun, pnd_disco_t *p ) {
2539 char *viewer, *searchpath;
2540 pnd_conf_handle desktoph;
2543 searchpath = pnd_conf_query_searchpath();
2545 desktoph = pnd_conf_fetch_by_id ( pnd_conf_desktop, searchpath );
2551 viewer = pnd_conf_get_as_char ( desktoph, "info.viewer" );
2554 return ( 0 ); // no way to view the file
2558 if ( ! p -> unique_id ) {
2562 if ( ! p -> info_filename ) {
2566 if ( ! p -> info_name ) {
2577 if ( pnd_conf_get_as_char ( desktoph, "info.viewer_args" ) ) {
2578 snprintf ( pargs, 1001, "%s %s",
2579 pnd_conf_get_as_char ( desktoph, "info.viewer_args" ), p -> info_filename );
2584 char pndfile [ 1024 ];
2585 if ( p -> object_type == pnd_object_type_directory ) {
2586 // for PXML-app-dir, pnd_run.sh doesn't want the PXML.xml.. it just wants the dir-name
2587 strncpy ( pndfile, p -> object_path, 1000 );
2588 } else if ( p -> object_type == pnd_object_type_pnd ) {
2589 // pnd_run.sh wants the full path and filename for the .pnd file
2590 snprintf ( pndfile, 1020, "%s/%s", p -> object_path, p -> object_filename );
2593 if ( ! pnd_apps_exec ( pndrun, pndfile, p -> unique_id, viewer, p -> startdir, pargs,
2594 p -> clockspeed ? atoi ( p -> clockspeed ) : 0, PND_EXEC_OPTION_NORUN ) )
2599 pnd_log ( pndn_debug, "Info Exec=%s\n", pnd_apps_exec_runline() );
2603 if ( ( x = fork() ) < 0 ) {
2604 pnd_log ( pndn_error, "ERROR: Couldn't fork()\n" );
2609 execl ( "/bin/sh", "/bin/sh", "-c", pnd_apps_exec_runline(), (char*)NULL );
2610 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", pnd_apps_exec_runline() );
2622 #define MAXTOUCH 100
2623 ui_touch_t ui_touchrects [ MAXTOUCH ];
2624 unsigned char ui_touchrect_count = 0;
2626 void ui_register_reset ( void ) {
2627 bzero ( ui_touchrects, sizeof(ui_touch_t)*MAXTOUCH );
2628 ui_touchrect_count = 0;
2632 void ui_register_tab ( unsigned char catnum, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2634 if ( ui_touchrect_count == MAXTOUCH ) {
2638 ui_touchrects [ ui_touchrect_count ].r.x = x;
2639 ui_touchrects [ ui_touchrect_count ].r.y = y;
2640 ui_touchrects [ ui_touchrect_count ].r.w = w;
2641 ui_touchrects [ ui_touchrect_count ].r.h = h;
2642 ui_touchrects [ ui_touchrect_count ].catnum = catnum;
2643 ui_touchrect_count++;
2648 void ui_register_app ( mm_appref_t *app, unsigned int x, unsigned int y, unsigned int w, unsigned int h ) {
2650 if ( ui_touchrect_count == MAXTOUCH ) {
2654 ui_touchrects [ ui_touchrect_count ].r.x = x;
2655 ui_touchrects [ ui_touchrect_count ].r.y = y;
2656 ui_touchrects [ ui_touchrect_count ].r.w = w;
2657 ui_touchrects [ ui_touchrect_count ].r.h = h;
2658 ui_touchrects [ ui_touchrect_count ].ref = app;
2659 ui_touchrect_count++;
2664 void ui_touch_act ( unsigned int x, unsigned int y ) {
2669 for ( i = 0; i < ui_touchrect_count; i++ ) {
2670 t = &(ui_touchrects [ i ]);
2672 if ( x >= t -> r.x &&
2673 x <= t -> r.x + t -> r.w &&
2675 y <= t -> r.y + t -> r.h
2680 ui_selected = t -> ref;
2683 if ( ui_category != t -> catnum ) {
2686 ui_category = t -> catnum;
2687 render_mask |= CHANGED_CATEGORY;
2689 category_fs_restock ( g_categories [ ui_category ] );
2690 ui_start_defered_icon_thread();
2701 unsigned char ui_forkexec ( char *argv[] ) {
2702 char *fooby = argv[0];
2705 if ( ( x = fork() ) < 0 ) {
2706 pnd_log ( pndn_error, "ERROR: Couldn't fork() for '%s'\n", fooby );
2710 if ( x == 0 ) { // child
2711 execv ( fooby, argv );
2712 pnd_log ( pndn_error, "ERROR: Couldn't exec(%s)\n", fooby );
2720 unsigned char ui_threaded_timer_create ( void ) {
2722 g_timer_thread = SDL_CreateThread ( (void*)ui_threaded_timer, NULL );
2724 if ( ! g_timer_thread ) {
2725 pnd_log ( pndn_error, "ERROR: Couldn't create timer thread\n" );
2732 int ui_threaded_timer ( pnd_disco_t *p ) {
2734 // this timer's job is to ..
2735 // - do nothing for quite awhile
2736 // - on wake, post event to SDL event queue, so that main thread will check if SD insert/eject occurred
2739 unsigned int delay_s = 2; // seconds
2744 //sleep ( delay_s );
2745 SDL_Delay ( delay_s * 1000 );
2747 // .. trigger SD check
2749 bzero ( &e, sizeof(SDL_Event) );
2750 e.type = SDL_USEREVENT;
2751 e.user.code = sdl_user_checksd;
2752 SDL_PushEvent ( &e );
2759 unsigned char ui_threaded_defered_preview ( pnd_disco_t *p ) {
2761 if ( ! cache_preview ( p, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
2762 pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
2765 pnd_log ( pndn_debug, "THREAD: Couldn't load preview pic: '%s' -> '%s'\n",
2766 IFNULL(p->title_en,"No Name"), p -> preview_pic1 );
2769 // trigger that we completed
2771 bzero ( &e, sizeof(SDL_Event) );
2772 e.type = SDL_USEREVENT;
2773 e.user.code = sdl_user_finishedpreview;
2775 SDL_PushEvent ( &e );
2780 void ui_post_scan ( void ) {
2784 ui_rows_scrolled_down = 0;
2785 // set back to first tab, to be safe
2789 // do we have a preferred category to jump to? or a last known one?
2790 char *dc = pnd_conf_get_as_char ( g_conf, "categories.default_cat" );
2791 char *lastcat = pnd_conf_get_as_char ( g_conf, "minimenu.last_known_catname" );
2793 ( pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) && lastcat ) )
2795 char *catpick = NULL;
2797 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.start_selected", 0 ) && lastcat ) {
2800 // if this is a subcat, we have some doctoring to do :/ the hackishness is really
2801 // starting to show..
2802 if ( pnd_conf_get_as_char ( g_conf, "minimenu.last_known_parentcatname" ) ) {
2803 // in subcat view, we only have one cat
2806 // the cat name to search for is Child*Parent
2808 sprintf ( key, "%s*%s",
2809 pnd_conf_get_as_char ( g_conf, "minimenu.last_known_catname" )
2810 , pnd_conf_get_as_char ( g_conf, "minimenu.last_known_parentcatname" ) );
2811 category_publish ( CFBYNAME, key );
2812 // since we forced it by hand, no need to do a cat-scan below
2820 // attempt to find default cat; if we do find it, select it; otherwise
2821 // default behaviour will pick first cat (ie: usually All)
2825 for ( i = 0; i < g_categorycount; i++ ) {
2826 if ( strcasecmp ( g_categories [ i ] -> catname, catpick ) == 0 ) {
2828 // ensure visibility
2829 unsigned int screen_width = ui_display_context.screen_width;
2830 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
2831 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
2832 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
2838 if ( i == g_categorycount ) {
2839 pnd_log ( pndn_warning, " User defined default category or last known cat '%s' but not found, so using default behaviour\n", catpick );
2846 // if we're sent right to a dirbrowser tab, restock it now (normally we restock on entry)
2847 if ( g_categories [ ui_category ] -> fspath ) {
2848 printf ( "Restock on start: '%s'\n", g_categories [ ui_category ] -> fspath );
2849 category_fs_restock ( g_categories [ ui_category ] );
2853 render_mask |= CHANGED_EVERYTHING;
2855 // if deferred icon load, kick off the thread now
2856 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 1 ) {
2857 ui_start_defered_icon_thread();
2858 } // deferred icon load
2863 unsigned char ui_threaded_defered_icon ( void *p ) {
2864 extern pnd_box_handle g_active_apps;
2866 unsigned char maxwidth, maxheight;
2867 maxwidth = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_width", 50 );
2868 maxheight = pnd_conf_get_as_int_d ( g_conf, "grid.icon_max_height", 50 );
2872 g_icon_thread_busy = 1;
2874 // work at it in order within current category
2876 mm_appref_t *refiter = g_categories [ ui_category ] -> refs;
2877 while ( refiter && ! g_icon_thread_stop ) {
2878 iter = refiter -> ref;
2880 // has an icon that is not already cached?
2881 if ( ( iter -> pnd_icon_pos ) ||
2882 ( iter -> icon && iter -> object_flags & PND_DISCO_CUSTOM1 )
2887 if ( ! cache_icon ( iter, maxwidth, maxheight ) ) {
2888 //pnd_log ( pndn_warning, " Couldn't load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2892 // trigger that we completed
2894 bzero ( &e, sizeof(SDL_Event) );
2895 e.type = SDL_USEREVENT;
2896 e.user.code = sdl_user_finishedicon;
2897 SDL_PushEvent ( &e );
2899 //pnd_log ( pndn_warning, " Finished deferred load icon: '%s'\n", IFNULL(iter->title_en,"No Name") );
2900 //usleep ( pnd_conf_get_as_int_d ( g_conf, "minimenu.defer_icon_us", 50000 ) );
2905 iter -> pnd_icon_pos = 0;
2906 if ( iter -> icon ) {
2907 free ( iter -> icon );
2908 iter -> icon = NULL;
2911 // let user do something..
2916 refiter = refiter -> next;
2920 g_icon_thread_busy = 0;
2925 void ui_show_hourglass ( unsigned char updaterect ) {
2928 SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
2930 dest.x = ( 800 - s -> w ) / 2;
2931 dest.y = ( 480 - s -> h ) / 2;
2933 SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
2936 SDL_UpdateRects ( sdl_realscreen, 1, &dest );
2942 unsigned char ui_pick_skin ( void ) {
2944 char *skins [ MAXSKINS ];
2947 char *searchpath = pnd_conf_get_as_char ( g_conf, "minimenu.skin_searchpath" );
2948 char tempname [ 100 ];
2952 skins [ iter++ ] = "No skin change";
2956 DIR *d = opendir ( buffer );
2961 while ( ( dd = readdir ( d ) ) ) {
2963 if ( dd -> d_name [ 0 ] == '.' ) {
2965 } else if ( ( dd -> d_type == DT_DIR || dd -> d_type == DT_UNKNOWN ) &&
2968 snprintf ( tempname, 100, "Skin: %s", dd -> d_name );
2969 skins [ iter++ ] = strdup ( tempname );
2980 int sel = ui_modal_single_menu ( skins, iter, "Skins", "Enter to select; other to return." );
2982 // did they pick one?
2986 char *s = strdup ( pnd_conf_get_as_char ( g_conf, "minimenu.skin_selected" ) );
2987 s = pnd_expand_tilde ( s );
2989 f = fopen ( s, "w" );
2994 fprintf ( f, "%s\n", skins [ sel ] + 6 );
3004 void ui_aboutscreen ( char *textpath ) {
3011 #define ROWS SCRH / ( PIXELH + MARGINH )
3012 #define COLS SCRW / ( PIXELW + MARGINW )
3014 unsigned char pixelboard [ ROWS * COLS ]; // pixel heat
3015 bzero ( pixelboard, ROWS * COLS );
3020 SDL_Color rtextc = { 200, 200, 200, 100 };
3023 char *textloop [ 500 ];
3024 unsigned int textmax = 0;
3025 bzero ( textloop, 500 * sizeof(char*) );
3028 char cbuffer [ 50000 ];
3029 bzero ( cbuffer, 50000 );
3030 unsigned int crevealed = 0;
3032 FILE *f = fopen ( textpath, "r" );
3035 pnd_log ( pndn_error, "ERROR: Couldn't open about text: %s\n", textpath );
3039 char textbuf [ 100 ];
3040 while ( fgets ( textbuf, 100, f ) ) {
3042 // add to full buffer
3043 strncat ( cbuffer, textbuf, 50000 );
3046 if ( strchr ( textbuf, '\n' ) ) {
3047 * strchr ( textbuf, '\n' ) = '\0';
3050 // add to pixel loop
3051 if ( 1||textbuf [ 0 ] ) {
3052 textloop [ textmax ] = strdup ( textbuf );
3060 unsigned int textiter = 0;
3061 while ( textiter < textmax ) {
3062 char *text = textloop [ textiter ];
3066 // render to surface
3067 rtext = TTF_RenderText_Blended ( g_grid_font, text, rtextc );
3069 // render font to pixelboard
3070 unsigned int px, py;
3072 unsigned int *pixels = rtext -> pixels;
3073 unsigned char cr, cg, cb, ca;
3074 for ( py = 0; py < rtext -> h; py ++ ) {
3075 for ( px = 0; px < ( rtext -> w > COLS ? COLS : rtext -> w ); px++ ) {
3077 SDL_GetRGBA ( pixels [ ( py * rtext -> pitch / 4 ) + px ],
3078 rtext -> format, &cr, &cg, &cb, &ca );
3082 ph = pixelboard + ( /*y offset */ 30 * COLS ) + ( py * COLS ) + px /* / 2 */;
3089 if ( *ph + ca < 250 ) {
3100 unsigned int runcount = 10;
3101 while ( runcount-- ) {
3104 SDL_FillRect( sdl_realscreen, NULL /* whole */, 0 );
3106 // render pixelboard
3109 for ( y = 0; y < ROWS; y++ ) {
3110 for ( x = 0; x < COLS; x++ ) {
3112 if ( 1||pixelboard [ ( y * COLS ) + x ] ) {
3115 r.x = x * ( PIXELW + MARGINW );
3116 r.y = y * ( PIXELH + MARGINH );
3120 c = SDL_MapRGB ( sdl_realscreen -> format, 100 /* r */, 0 /* g */, pixelboard [ ( y * COLS ) + x ] );
3122 SDL_FillRect( sdl_realscreen, &r /* whole */, c );
3130 unsigned char *pc = pixelboard;
3131 for ( y = 0; y < ROWS; y++ ) {
3132 for ( x = 0; x < COLS; x++ ) {
3142 // slide pixels upwards
3143 memmove ( pixelboard, pixelboard + COLS, ( COLS * ROWS ) - COLS );
3145 // render actual readable text
3148 // display up to cursor
3150 unsigned int cdraw = 0;
3154 if ( crevealed > 200 ) {
3155 cdraw = crevealed - 200;
3161 for ( ; cdraw < crevealed; cdraw++ ) {
3162 ctb [ 0 ] = cbuffer [ cdraw ];
3164 // move over or down
3165 if ( cbuffer [ cdraw ] == '\n' ) {
3170 if ( dest.y > 450 ) {
3176 cs = TTF_RenderText_Blended ( g_tab_font, ctb, rtextc );
3178 SDL_BlitSurface ( cs, NULL /* all */, sdl_realscreen, &dest );
3179 SDL_FreeSurface ( cs );
3189 SDL_FillRect ( sdl_realscreen, &dest /* whole */, 220 );
3191 // increment cursor to next character
3192 if ( cbuffer [ crevealed ] != '\0' ) {
3196 } // draw cursor text
3200 SDL_UpdateRect ( sdl_realscreen, 0, 0, 0, 0 ); // whole screen
3204 // any button? if so, about
3210 if ( SDL_PeepEvents ( &e, 1, SDL_GETEVENT, SDL_EVENTMASK(/*SDL_KEYUP|*/SDL_KEYDOWN) ) > 0 ) {
3219 SDL_FreeSurface ( rtext );
3223 } // while more text
3227 for ( i = 0; i < textmax; i++ ) {
3228 if ( textloop [ i ] ) {
3229 free ( textloop [ i ] );
3237 void ui_revealscreen ( void ) {
3238 char *labels [ 500 ];
3239 unsigned int labelmax = 0;
3241 char fulllabel [ 200 ];
3243 if ( ! category_count ( CFHIDDEN ) ) {
3244 return; // nothing to do
3247 // switch to hidden categories
3248 category_publish ( CFHIDDEN, NULL );
3250 // build up labels to show in menu
3251 for ( i = 0; i < g_categorycount; i++ ) {
3253 if ( g_categories [ i ] -> parent_catname ) {
3254 sprintf ( fulllabel, "%s [%s]", g_categories [ i ] -> catname, g_categories [ i ] -> parent_catname );
3256 sprintf ( fulllabel, "%s", g_categories [ i ] -> catname );
3259 labels [ labelmax++ ] = strdup ( fulllabel );
3263 int sel = ui_modal_single_menu ( labels, labelmax, "Temporary Category Reveal",
3264 "Enter to select; other to return." );
3266 // if selected, try to set this guy to visible
3269 // fix up category name, if its been hacked
3270 #if 0 // prepending and .. wtf crap is this
3271 if ( strchr ( g_categories [ sel ] -> catname, '.' ) ) {
3272 char *t = g_categories [ sel ] -> catname;
3273 g_categories [ sel ] -> catname = strdup ( strchr ( g_categories [ sel ] -> catname, '.' ) + 1 );
3278 // reflag this guy to be visible
3279 g_categories [ sel ] -> catflags = CFNORMAL;
3281 // switch to the new category.. cache name.
3282 char *switch_to_name = g_categories [ sel ] -> catname;
3284 // republish categories
3285 category_publish ( CFNORMAL, NULL );
3287 // switch to the new category.. with the cached name!
3288 ui_category = category_index ( switch_to_name );
3290 // ensure visibility
3291 unsigned int screen_width = ui_display_context.screen_width;
3292 unsigned int tab_width = pnd_conf_get_as_int ( g_conf, "tabs.tab_width" );
3293 if ( ui_category > ui_catshift + ( screen_width / tab_width ) - 1 ) {
3294 ui_catshift = ui_category - ( screen_width / tab_width ) + 1;
3299 // republish categories
3300 category_publish ( CFNORMAL, NULL );
3303 render_mask |= CHANGED_CATEGORY;
3304 ui_start_defered_icon_thread();
3309 void ui_recache_context ( ui_context_t *c ) {
3311 c -> screen_width = pnd_conf_get_as_int_d ( g_conf, "display.screen_width", 800 );
3313 c -> font_rgba_r = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_r", 200 );
3314 c -> font_rgba_g = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_g", 200 );
3315 c -> font_rgba_b = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_b", 200 );
3316 c -> font_rgba_a = pnd_conf_get_as_int_d ( g_conf, "display.font_rgba_a", 100 );
3318 c -> grid_offset_x = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_x" );
3319 c -> grid_offset_y = pnd_conf_get_as_int ( g_conf, "grid.grid_offset_y" );
3321 c -> icon_offset_x = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_x" );
3322 c -> icon_offset_y = pnd_conf_get_as_int ( g_conf, "grid.icon_offset_y" );
3323 c -> icon_max_width = pnd_conf_get_as_int ( g_conf, "grid.icon_max_width" );
3324 c -> icon_max_height = pnd_conf_get_as_int ( g_conf, "grid.icon_max_height" );
3325 c -> sel_icon_offset_x = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_x", 0 );
3326 c -> sel_icon_offset_y = pnd_conf_get_as_int_d ( g_conf, "grid.sel_offoffset_y", 0 );
3328 c -> text_width = pnd_conf_get_as_int ( g_conf, "grid.text_width" );
3329 c -> text_clip_x = pnd_conf_get_as_int ( g_conf, "grid.text_clip_x" );
3330 c -> text_offset_x = pnd_conf_get_as_int ( g_conf, "grid.text_offset_x" );
3331 c -> text_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_offset_y" );
3332 c -> text_hilite_offset_y = pnd_conf_get_as_int ( g_conf, "grid.text_hilite_offset_y" );
3334 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max", 4 );
3335 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max", 5 );
3337 c -> cell_width = pnd_conf_get_as_int ( g_conf, "grid.cell_width" );
3338 c -> cell_height = pnd_conf_get_as_int ( g_conf, "grid.cell_height" );
3340 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x", 450 );
3341 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y", 100 );
3342 c -> arrow_bar_clip_w = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_w", 10 );
3343 c -> arrow_bar_clip_h = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_clip_h", 100 );
3344 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x", 450 );
3345 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y", 80 );
3346 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x", 450 );
3347 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y", 80 );
3350 SDL_Color tmp = { c -> font_rgba_r, c -> font_rgba_g, c -> font_rgba_b, c -> font_rgba_a };
3351 c -> fontcolor = tmp;
3353 // now that we've got 'normal' (detail pane shown) param's, lets check if detail pane
3354 // is hidden; if so, override some values with those alternate skin values where possible.
3355 if ( ui_detail_hidden ) {
3356 // if detail panel is hidden, and theme cannot support it, unhide the bloody thing. (This may help
3357 // when someone is amid theme hacking or changing.)
3358 if ( ! ui_is_detail_hideable() ) {
3359 ui_detail_hidden = 0;
3363 if ( ui_detail_hidden ) {
3365 c -> row_max = pnd_conf_get_as_int_d ( g_conf, "grid.row_max_w", c -> row_max );
3366 c -> col_max = pnd_conf_get_as_int_d ( g_conf, "grid.col_max_w", c -> col_max );
3368 c -> cell_width = pnd_conf_get_as_int_d ( g_conf, "grid.cell_width_w", c -> cell_width );
3369 c -> cell_height = pnd_conf_get_as_int_d ( g_conf, "grid.cell_height_w", c -> cell_height );
3371 c -> arrow_bar_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_x_w", 450 );
3372 c -> arrow_bar_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_bar_y_w", 100 );
3373 c -> arrow_up_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_x_w", 450 );
3374 c -> arrow_up_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_up_y_w", 80 );
3375 c -> arrow_down_x = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_x_w", 450 );
3376 c -> arrow_down_y = pnd_conf_get_as_int_d ( g_conf, "grid.arrow_down_y_w", 80 );
3378 } // if detail hidden.. still.
3380 } // if detail hidden
3385 unsigned char ui_is_detail_hideable ( void ) {
3387 // if skin has a bit of info for wide-mode, we assume wide-mode is available
3388 if ( pnd_conf_get_as_char ( g_conf, "grid.row_max_w" ) != NULL ) {
3396 void ui_toggle_detail_pane ( void ) {
3398 // no bitmask trickery here; I like it to be stand-out obvious at 3am.
3400 if ( ui_detail_hidden ) {
3401 ui_detail_hidden = 0;
3403 ui_detail_hidden = 1;
3406 // repull skin config
3407 ui_recache_context ( &ui_display_context );
3410 render_mask |= CHANGED_EVERYTHING;
3415 void ui_menu_context ( mm_appref_t *a ) {
3417 unsigned char rescan_apps = 0;
3418 unsigned char context_alive = 1;
3423 context_file_delete,
3426 context_app_recategorize,
3427 context_app_recategorize_sub,
3429 context_app_cpuspeed,
3437 char *verbiage[] = {
3438 "Done (return to grid)", // context_done
3439 "Get info about file/dir", // context_file_info
3440 "Delete file/dir", // context_file_delete
3441 "Get info", // context_app_info
3442 "Hide application", // hide
3443 "Recategorize", // recategorize
3444 "Recategorize subcategory", // recategorize
3445 "Change displayed title", // rename
3446 "Set CPU speed for launch", // cpuspeed
3447 "Run application", // run
3448 "Edit notes line 1", // notes1
3449 "Edit notes line 2", // notes2
3450 "Edit notes line 3", // notes3
3453 unsigned short int menu [ context_menu_max ];
3454 char *menustring [ context_menu_max ];
3455 unsigned char menumax = 0;
3458 menu [ menumax ] = context_done; menustring [ menumax++ ] = verbiage [ context_done ];
3460 // hook up appropriate menu options based on tab-type and object-type
3461 if ( g_categories [ ui_category ] -> fspath ) {
3463 menu [ menumax ] = context_file_info; menustring [ menumax++ ] = verbiage [ context_file_info ];
3464 menu [ menumax ] = context_file_delete; menustring [ menumax++ ] = verbiage [ context_file_delete ];
3467 if ( a -> ref -> object_type == pnd_object_type_directory ) {
3468 return; // don't do anything if the guy is a subcat-as-folder
3471 //menu [ menumax ] = context_app_info; menustring [ menumax++ ] = verbiage [ context_app_info ];
3472 menu [ menumax ] = context_app_run; menustring [ menumax++ ] = verbiage [ context_app_run ];
3473 menu [ menumax ] = context_app_hide; menustring [ menumax++ ] = verbiage [ context_app_hide ];
3474 menu [ menumax ] = context_app_recategorize; menustring [ menumax++ ] = verbiage [ context_app_recategorize ];
3475 menu [ menumax ] = context_app_recategorize_sub; menustring [ menumax++ ] = verbiage [ context_app_recategorize_sub ];
3476 menu [ menumax ] = context_app_rename; menustring [ menumax++ ] = verbiage [ context_app_rename ];
3477 menu [ menumax ] = context_app_cpuspeed; menustring [ menumax++ ] = verbiage [ context_app_cpuspeed ];
3478 menu [ menumax ] = context_app_notes1; menustring [ menumax++ ] = verbiage [ context_app_notes1 ];
3479 menu [ menumax ] = context_app_notes2; menustring [ menumax++ ] = verbiage [ context_app_notes2 ];
3480 menu [ menumax ] = context_app_notes3; menustring [ menumax++ ] = verbiage [ context_app_notes3 ];
3484 while ( context_alive ) {
3486 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 */ );
3493 switch ( menu [ sel ] ) {
3499 case context_file_info:
3502 case context_file_delete:
3503 //ui_menu_twoby ( "Delete - Are you sure?", "B/enter; other to cancel", "Delete", "Do not delete" );
3506 case context_app_info:
3509 case context_app_hide:
3512 char confkey [ 1000 ];
3513 snprintf ( confkey, 999, "%s.%s", "appshow", a -> ref -> unique_id );
3516 pnd_conf_set_char ( g_conf, confkey, "0" );
3518 // write conf, so it will take next time
3519 conf_write ( g_conf, conf_determine_location ( g_conf ) );
3520 conf_write ( g_conf, CONF_PREF_TEMPPATH );
3522 // can we just 'hide' this guy without reloading all apps? (this is for you, EvilDragon)
3525 // DOESN'T WORK YET; other parts of app are still hanging onto some values and blow up
3527 char *uid = strdup ( a -> ref -> unique_id );
3529 for ( i = 0; i < g_categorycount; i++ ) {
3530 mm_appref_t *p = g_categories [ i ] -> refs;
3535 if ( strcmp ( p -> ref -> unique_id, uid ) == 0 ) {
3537 if ( g_categories [ i ] -> refcount ) {
3538 g_categories [ i ] -> refcount--;
3543 } // while for each appref
3544 } // for each cat/tab
3549 // request rescan and wrap up
3553 context_alive = 0; // nolonger visible, so lets just get out
3559 case context_app_recategorize:
3562 unsigned char optmax = 0;
3565 // show custom categories
3566 if ( mmcustom_setup() ) {
3568 for ( i = 0; i < mmcustom_count; i++ ) {
3569 if ( mmcustom_complete [ i ].parent_cat == NULL ) {
3570 opts [ optmax++ ] = mmcustom_complete [ i ].cat;
3576 // show FD categories
3577 i = 2; // skip first two - Other and NoParentCategory
3580 if ( ! freedesktop_complete [ i ].cat ) {
3584 if ( ! freedesktop_complete [ i ].parent_cat ) {
3585 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3592 char prompt [ 101 ];
3593 snprintf ( prompt, 100, "Pick category [%s]", a -> ref -> main_category ? a -> ref -> main_category : "NoParentCategory" );
3595 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select parent category"*/, "Enter to select; other to skip." );
3598 char confirm [ 1001 ];
3599 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3601 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm categorization", "Do not set category" ) == 1 ) {
3602 ovr_replace_or_add ( a, "maincategory", opts [ sel ] );
3604 // when changing main cat, reset subcat, otherwise you go from Game/Emu to Network/Emu and get sent to Other right away
3605 ovr_replace_or_add ( a, "maincategorysub1", freedesktop_complete [ 2 ].cat );
3610 if ( mmcustom_is_ready() ) {
3611 mmcustom_shutdown();
3617 case context_app_recategorize_sub:
3620 unsigned char optmax = 0;
3621 unsigned char i = 0;
3623 char *whichparentarewe;
3624 if ( g_categories [ ui_category ] -> parent_catname ) {
3625 whichparentarewe = g_categories [ ui_category ] -> parent_catname;
3627 whichparentarewe = g_categories [ ui_category ] -> catname;
3630 // add NoSubcategory magic one
3631 opts [ optmax++ ] = freedesktop_complete [ 2 ].cat;
3633 // add custom categories
3634 if ( mmcustom_setup() ) {
3636 for ( i = 0; i < mmcustom_count; i++ ) {
3637 if ( mmcustom_complete [ i ].parent_cat && strcmp ( mmcustom_complete [ i ].parent_cat, whichparentarewe ) == 0 ) {
3638 opts [ optmax++ ] = mmcustom_complete [ i ].cat;
3644 // add FD categories
3647 if ( ! freedesktop_complete [ i ].cat ) {
3651 if ( ( freedesktop_complete [ i ].parent_cat ) &&
3652 ( strcasecmp ( freedesktop_complete [ i ].parent_cat, whichparentarewe ) == 0 )
3655 opts [ optmax++ ] = freedesktop_complete [ i ].cat;
3661 char prompt [ 101 ];
3662 //snprintf ( prompt, 100, "Currently: %s", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory" );
3663 snprintf ( prompt, 100, "%s [%s]", a -> ref -> main_category1 ? a -> ref -> main_category1 : "NoSubcategory", whichparentarewe );
3665 int sel = ui_modal_single_menu ( opts, optmax, prompt /*"Select subcategory"*/, "Enter to select; other to skip." );
3668 char confirm [ 1001 ];
3669 snprintf ( confirm, 1000, "Confirm: %s", opts [ sel ] );
3671 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm sub-categorization", "Do not set sub-category" ) == 1 ) {
3672 ovr_replace_or_add ( a, "maincategorysub1", opts [ sel ] );
3678 if ( mmcustom_is_ready() ) {
3679 mmcustom_shutdown();
3685 case context_app_rename:
3687 char namebuf [ 101 ];
3688 unsigned char changed;
3690 changed = ui_menu_get_text_line ( "Rename application", "Use keyboard; Enter when done.",
3691 a -> ref -> title_en ? a -> ref -> title_en : "blank", namebuf, 30, 0 /* alphanumeric */ );
3694 char confirm [ 1001 ];
3695 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3697 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm rename", "Do not rename" ) == 1 ) {
3698 ovr_replace_or_add ( a, "title", namebuf );
3708 case context_app_cpuspeed:
3710 char namebuf [ 101 ];
3711 unsigned char changed;
3713 changed = ui_menu_get_text_line ( "Specify runspeed", "Use keyboard; Enter when done.",
3714 a -> ref -> clockspeed ? a -> ref -> clockspeed : "500", namebuf, 6, 1 /* numeric */ );
3717 char confirm [ 1001 ];
3718 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
3720 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm clockspeed", "Do not set" ) == 1 ) {
3721 ovr_replace_or_add ( a, "clockspeed", namebuf );
3731 case context_app_run:
3735 case context_app_notes1:
3736 case context_app_notes2:
3737 case context_app_notes3:
3739 char namebuf [ 101 ] = "";
3742 unsigned char notenum;
3745 if ( menu [ sel ] == context_app_notes1 ) {
3747 } else if ( menu [ sel ] == context_app_notes2 ) {
3749 } else if ( menu [ sel ] == context_app_notes3 ) {
3753 // figure out key for looking up existing, and for storing replacement
3754 snprintf ( key, 500, "Application-%u.note-%u", a -> ref -> subapp_number, notenum );
3756 // do we have existing value?
3758 char *existing = pnd_conf_get_as_char ( a -> ovrh, key );
3760 strncpy ( namebuf, existing, 100 );
3764 unsigned char changed;
3766 changed = ui_menu_get_text_line ( "Enter replacement note", "Use keyboard; Enter when done.",
3767 namebuf, namebuf, 30, 0 /* not-numeric-forced */ );
3770 ovr_replace_or_add ( a, strchr ( key, '.' ) + 1, namebuf );
3782 } // if useful return
3787 if ( rescan_apps ) {
3788 applications_free();
3789 applications_scan();
3795 unsigned char ui_menu_oneby ( char *title, char *footer, char *one ) {
3798 int sel = ui_modal_single_menu ( opts, 1, title, footer );
3805 unsigned char ui_menu_twoby ( char *title, char *footer, char *one, char *two ) {
3809 int sel = ui_modal_single_menu ( opts, 2, title, footer );
3816 unsigned char ui_menu_get_text_line ( char *title, char *footer, char *initialvalue,
3817 char *r_buffer, unsigned char maxlen, unsigned char numbersonlyp )
3819 SDL_Rect rects [ 40 ];
3820 SDL_Rect *dest = rects;
3824 char hacktext [ 1024 ];
3825 unsigned char shifted = 0;
3827 bzero ( rects, sizeof(SDL_Rect) * 40 );
3829 if ( initialvalue ) {
3830 if ( initialvalue == r_buffer ) {
3831 // already good to go
3833 strncpy ( r_buffer, initialvalue, maxlen );
3836 bzero ( r_buffer, maxlen );
3842 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3843 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3844 dest -> w = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> w;
3845 dest -> h = ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h;
3846 SDL_FillRect( sdl_realscreen, dest, 0 );
3848 // show dialog background
3849 if ( g_imagecache [ IMG_DETAIL_BG ].i ) {
3852 src.w = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> w;
3853 src.h = ((SDL_Surface*)(g_imagecache [ IMG_DETAIL_BG ].i)) -> h;
3854 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3855 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3856 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_BG ].i, &src, sdl_realscreen, dest );
3860 // show dialog frame
3861 if ( g_imagecache [ IMG_DETAIL_PANEL ].i ) {
3862 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 );
3863 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 );
3864 SDL_BlitSurface ( g_imagecache [ IMG_DETAIL_PANEL ].i, NULL /* whole image */, sdl_realscreen, dest );
3870 rtext = TTF_RenderText_Blended ( g_tab_font, title, ui_display_context.fontcolor );
3871 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3872 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 20;
3873 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3874 SDL_FreeSurface ( rtext );
3880 rtext = TTF_RenderText_Blended ( g_tab_font, footer, ui_display_context.fontcolor );
3881 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3882 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) +
3883 ((SDL_Surface*) g_imagecache [ IMG_DETAIL_PANEL ].i) -> h
3885 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3886 SDL_FreeSurface ( rtext );
3890 // show text line - and embed cursor
3891 dest -> x = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_x", 460 ) + 20;
3892 dest -> y = pnd_conf_get_as_int_d ( g_conf, "detailpane.pane_offset_y", 60 ) + 40 + ( 20 * ( 0/*i*/ + 1 - 0/*first_visible*/ ) );
3894 strncpy ( hacktext, r_buffer, 1000 );
3895 strncat ( hacktext, "\n", 1000 ); // add [] in most fonts
3897 rtext = TTF_RenderText_Blended ( g_tab_font, hacktext, ui_display_context.fontcolor );
3898 SDL_BlitSurface ( rtext, NULL /* full src */, sdl_realscreen, dest );
3899 SDL_FreeSurface ( rtext );
3902 // update all the rects and send it all to sdl
3903 SDL_UpdateRects ( sdl_realscreen, dest - rects, rects );
3908 while ( SDL_WaitEvent ( &event ) ) {
3910 switch ( event.type ) {
3913 if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
3920 if ( event.key.keysym.sym == SDLK_LEFT || event.key.keysym.sym == SDLK_BACKSPACE ) {
3921 if ( strlen ( r_buffer ) > 0 ) {
3922 char *eol = strchr ( r_buffer, '\0' );
3923 *( eol - 1 ) = '\0';
3926 } else if ( event.key.keysym.sym == SDLK_UP ) {
3927 r_buffer [ 0 ] = '\0'; // truncate!
3929 } else if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_END ) { // return, or "B"
3930 // on Enter/Return or B, if the buffer has 1 or more chars, we return it as valid.. otherwise, invalid.
3931 if ( strlen ( r_buffer ) > 0 ) {
3936 } else if ( event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT ) {
3939 } else if ( event.key.keysym.sym == SDLK_ESCAPE ||
3940 event.key.keysym.sym == SDLK_PAGEUP ||
3941 event.key.keysym.sym == SDLK_PAGEDOWN ||
3942 event.key.keysym.sym == SDLK_HOME
3949 if ( isprint(event.key.keysym.sym) ) {
3951 unsigned char good = 1;
3953 if ( numbersonlyp && ( ! isdigit(event.key.keysym.sym) ) ) {
3957 if ( maxlen && strlen(r_buffer) >= maxlen ) {
3962 char b [ 2 ] = { '\0', '\0' };
3964 b [ 0 ] = toupper ( event.key.keysym.sym );
3966 b [ 0 ] = event.key.keysym.sym;
3968 strncat ( r_buffer, b, maxlen );
3981 } // while waiting for input
3988 unsigned char ovr_replace_or_add ( mm_appref_t *a, char *keybase, char *newvalue ) {
3989 //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 );
3991 char fullpath [ PATH_MAX ];
3993 sprintf ( fullpath, "%s/%s", a -> ref -> object_path, a -> ref -> object_filename );
3994 char *dot = strrchr ( fullpath, '.' );
3996 sprintf ( dot, PXML_SAMEPATH_OVERRIDE_FILEEXT );
3998 pnd_log ( pndn_error, "ERROR: Bad pnd-path in disco_t! %s\n", fullpath );
4002 struct stat statbuf;
4004 if ( stat ( fullpath, &statbuf ) == 0 ) {
4008 h = pnd_conf_fetch_by_path ( fullpath );
4011 return ( 0 ); // fail!
4015 snprintf ( key, 100, "Application-%u.%s", a -> ref -> subapp_number, keybase );
4017 pnd_conf_set_char ( h, key, newvalue );
4019 return ( pnd_conf_write ( h, fullpath ) );
4022 // file needs to be created - easy!
4024 FILE *f = fopen ( fullpath, "w" );
4027 fprintf ( f, "Application-%u.%s\t%s\n", a -> ref -> subapp_number, keybase, newvalue );
4031 return ( 0 ); // fail!
4039 void ui_manage_categories ( void ) {
4040 unsigned char require_app_scan = 0;
4042 if ( ! mmcustom_setup() ) {
4046 char *opts [ 20 ] = {
4047 "List custom categories",
4048 "List custom subcategories",
4049 "Register custom category",
4050 "Register custom subcategory",
4051 "Unregister custom category",
4052 "Unregister custom subcategory",
4058 int sel = ui_modal_single_menu ( opts, 7, "Custom Categories", "B to select; other to cancel." );
4062 case 0: // list custom
4063 ui_pick_custom_category ( 0 );
4066 case 1: // list custom sub
4067 if ( mmcustom_count ) {
4069 char *maincat = ui_pick_custom_category ( 2 );
4072 unsigned int subcount = mmcustom_count_subcats ( maincat );
4073 char titlebuf [ 201 ];
4075 snprintf ( titlebuf, 200, "Category: %s", maincat );
4077 if ( subcount == 0 ) {
4078 ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
4081 char **list = malloc ( subcount * sizeof(char*) );
4083 unsigned int counter = 0;
4085 for ( i = 0; i < mmcustom_count; i++ ) {
4086 if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
4087 list [ counter++ ] = mmcustom_complete [ i ].cat;
4091 ui_modal_single_menu ( list, counter, titlebuf, "Any button to exit." );
4095 } // more than 0 subcats?
4097 } // user picked a main cat?
4100 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4104 case 2: // register custom
4106 unsigned char changed;
4107 char namebuf [ 101 ] = "";
4109 changed = ui_menu_get_text_line ( "Enter unique category name", "Use keyboard; Enter when done.",
4110 "Pandora", namebuf, 30, 0 /* alphanumeric */ );
4112 // did the user enter something?
4115 // and if so, is it existant already or not?
4116 if ( mmcustom_query ( namebuf, NULL ) ) {
4117 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a registered category." );
4118 } else if ( freedesktop_category_query ( namebuf, NULL ) ) {
4119 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard category." );
4122 char confirm [ 1001 ];
4123 snprintf ( confirm, 1000, "Confirm: %s", namebuf );
4125 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
4126 // register, save, recycle the current list
4127 mmcustom_register ( namebuf, NULL );
4128 mmcustom_write ( NULL );
4129 mmcustom_shutdown();
4135 } // entered something?
4140 case 3: // register custom sub
4141 if ( 1 /*mmcustom_count -- we allow FD cats now, so this isn't applicable error */ ) {
4143 char *maincat = ui_pick_custom_category ( 1 /* include FD */ );
4146 char titlebuf [ 201 ];
4148 snprintf ( titlebuf, 200, "Subcat of: %s", maincat );
4150 unsigned char changed;
4151 char namebuf [ 101 ] = "";
4153 changed = ui_menu_get_text_line ( titlebuf, "Use keyboard; Enter when done.", "Submarine", namebuf, 30, 0 /* alphanumeric */ );
4155 // did the user enter something?
4158 // and if so, is it existant already or not?
4159 if ( mmcustom_query ( namebuf, maincat ) ) {
4160 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a subcategory." );
4161 } else if ( freedesktop_category_query ( namebuf, maincat ) ) {
4162 ui_menu_oneby ( "Warning", "B/Enter to accept", "Already a Standard subcategory." );
4165 char confirm [ 1001 ];
4166 snprintf ( confirm, 1000, "Confirm: %s [%s]", namebuf, maincat );
4168 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm new category", "Do not register" ) == 1 ) {
4169 // register, save, recycle the current list
4170 mmcustom_register ( namebuf, maincat );
4171 mmcustom_write ( NULL );
4172 mmcustom_shutdown();
4178 } // entered something?
4180 } // selected parent cat?
4183 ui_menu_oneby ( "Warning", "B/Enter to accept", "No categories registered." );
4187 case 4: // unreg custom
4188 if ( mmcustom_count ) {
4189 char *maincat = ui_pick_custom_category ( 0 );
4192 char confirm [ 1001 ];
4193 snprintf ( confirm, 1000, "Confirm remove: %s", maincat );
4195 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
4196 // register, save, recycle the current list
4197 mmcustom_unregister ( maincat, NULL );
4198 mmcustom_write ( NULL );
4199 mmcustom_shutdown();
4206 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4210 case 5: // unreg custom sub
4211 if ( mmcustom_count ) {
4212 char *maincat = ui_pick_custom_category ( 2 );
4215 unsigned int subcount = mmcustom_count_subcats ( maincat );
4216 char titlebuf [ 201 ];
4218 snprintf ( titlebuf, 200, "Category: %s", maincat );
4220 if ( subcount == 0 ) {
4221 ui_menu_oneby ( titlebuf, "B/Enter to accept", "Category has no subcategories." );
4224 char **list = malloc ( subcount * sizeof(char*) );
4226 unsigned int counter = 0;
4228 for ( i = 0; i < mmcustom_count; i++ ) {
4229 if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, maincat ) == 0 ) {
4230 list [ counter++ ] = mmcustom_complete [ i ].cat;
4234 int sel = ui_modal_single_menu ( list, counter, titlebuf, "B to selct; other to exit." );
4237 char confirm [ 1001 ];
4238 snprintf ( confirm, 1000, "Confirm remove: %s", list [ sel ] );
4240 if ( ui_menu_twoby ( confirm, "B/enter; other to cancel", "Confirm unregister", "Do not unregister" ) == 1 ) {
4241 // register, save, recycle the current list
4242 mmcustom_unregister ( list [ sel ], maincat );
4243 mmcustom_write ( NULL );
4244 mmcustom_shutdown();
4252 } // more than 0 subcats?
4254 } // user picked a main cat?
4257 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4264 if ( sel < 0 || sel > 5 ) {
4268 } // while running the menu
4270 // shut down custom cats
4271 mmcustom_shutdown();
4274 if ( require_app_scan ) {
4275 applications_free();
4276 applications_scan();
4280 render_mask |= CHANGED_EVERYTHING;
4285 // mode 0 == custom main only; 1 == custom main + FD main; 2 == custom main + FD mains-with-custom-subs
4286 char *ui_pick_custom_category ( unsigned char mode ) {
4289 unsigned int counter = 0;
4291 // alloc space for list, depending on scope
4293 list = malloc ( (mmcustom_count+freedesktop_count()) * sizeof(char*) );
4295 list = malloc ( mmcustom_count * sizeof(char*) );
4299 for ( i = 0; i < mmcustom_count; i++ ) {
4300 if ( mmcustom_complete [ i ].parent_cat == NULL ) {
4301 list [ counter++ ] = mmcustom_complete [ i ].cat;
4311 if ( ! freedesktop_complete [ i ].cat ) {
4316 if ( freedesktop_complete [ i ].parent_cat == NULL ) {
4318 // mode 1 == include them all
4319 // mode 2 == include them if they have a custom subcat
4320 if ( ( mode == 1 ) ||
4321 ( mmcustom_subcount ( freedesktop_complete [ i ].cat ) ) )
4323 list [ counter++ ] = freedesktop_complete [ i ].cat;
4333 // we actually showing anything?
4335 ui_menu_oneby ( "Warning", "B/Enter to accept", "There are none registered." );
4340 int sel = ui_modal_single_menu ( list, counter, "Custom Categories", "Any button to exit." );
4347 char *foo = list [ sel ];
4353 void ui_start_defered_icon_thread ( void ) {
4355 if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_icons_later", 0 ) == 0 ) {
4359 if ( g_icon_thread_busy ) {
4360 //fprintf ( stderr, "REM: Waiting for thread to stop..\n" );
4361 ui_stop_defered_icon_thread();
4364 //fprintf ( stderr, "WARN: Starting new icon caching thread..\n" );
4365 g_icon_thread = SDL_CreateThread ( (void*)ui_threaded_defered_icon, NULL );
4367 if ( ! g_icon_thread ) {
4368 pnd_log ( pndn_error, "ERROR: Couldn't create icon thread\n" );
4374 void ui_stop_defered_icon_thread ( void ) {
4375 time_t started = time ( NULL );
4377 // ask thread to stop, then wait for it (if two run at same time, or if we change
4378 // category content under neath it, could be bad..)
4379 g_icon_thread_stop = 1;
4380 while ( g_icon_thread_busy ) {
4381 time ( NULL ); // spin
4383 g_icon_thread_stop = 0;
4385 fprintf ( stderr, "REM: Thread stoppage took %u seconds.\n", (int) ( time ( NULL ) - started ) );