-- default to preload icons -- its fast, and doesn't slow user down later; they can set to defer themselves
-- default to unthreaded preview loads; better to hit the user now, than chug them for a few motions
-- show hourglass art while loading previews in foreground, so they know to wait
-- show previews after 2s or so, rather than 1s, of paused selection; give the user a bit more breather
--> this should all make the experience feel better
Preview caching--
-- if do_cache is set in conf, will now attempt to cache previews _to SD_ for long term storage
--> risk is the preview pics change, and mmenu never updates them; should maybe check preview pic
age and re-export it once a month or something, or if age < pmnd age, or something.
-- Seledct menu can do 'mass cache', which chugs for a few mins, but will do all preview caching
-- otherwise, with do_Cache on (default!), after the 2s wait, it'll cache out to SD and load preview
--> thus, first preview is slow, but very fast next time, even next mmenu session
pndrun /usr/pandora/scripts:./testdata/scripts # searchpath to locate "pnd_run.sh"; why aren't I looking in /etc/pandora/conf/apps for this?
load_previews_now 0 # if >0, will try to load preview pics from pnds at boot time, not defer till later
load_previews_later 1 # if >0, will try to load preview pics sometime (see defer_timer_ms as well)
-load_icons_later 1 # if >0, will try to load icons after grid is showing, not during app scanning
+load_icons_later 0 # if >0, will try to load icons after grid is showing, not during app scanning
defer_icon_us 100000 # when background loading icons (load_icons_later), time between icon loadsa
-threaded_preview 1 # if 1, will try to load the preview in background, to avoid slowing up navigation
+threaded_preview 0 # if 1, will try to load the preview in background, to avoid slowing up navigation
loglevel 0 # 0 is debug, lots of crap; 3 is better, means 'errors only'. Output may screw up the wrapper!
x11_present_sh /bin/pidof X # command to invoke to determine if X11 is running or not; expects a number on X is present.
desktop_apps 1 # search the pnd standard desktop searchpath for apps
font_rgba_a 20 # RGBA for the display text
battery_x 10 # (x,y) for battery level
battery_y 450 # (x,y) for battery level
-hintline Push SELECT for shutdown options # shown at bottom of screen
-hint_x 275 # (x,y) for hint line
+hintline Push SELECT for options # shown at bottom of screen
+hint_x 300 # (x,y) for hint line
hint_y 450 # (x,y) for hint line
clock_x 650 # (x,y) for clock
clock_y 450 # (x,y) for clock
cell_width 250 # width of cell (for text clipping)
[previewpic]
-defer_timer_ms 1000 # after setting selection, how long to wait before we try to load the previewpic
+defer_timer_ms 2000 # after setting selection, how long to wait before we try to load the previewpic
cell_offset_x 480 # left edge of text cell
cell_offset_y 90 # top edge of text cell
cell_width 285
cell_height 180
scale_up_bool 1 # if 0, will not try to scale up preview
+do_cache 1 # if 1, will try to cache previews to SD, for performance boost
+cache_searchpath /media/mmcblk[12]p? # devices to consider for caching to, in order
+cache_minfree 500 # if free space is less than this (in KB), move to next device
+cache_path /pandora/appdata/mmenu.pvwcache # where to write cached images to
+cache_findpath /media/mmcblk[12]p?/pandora/appdata/mmenu.pvwcache # where to look for cached preview pics
[graphics]
IMG_BACKGROUND_800480 800480_6.png
IMG_ARROW_UP arrowup.png
IMG_ARROW_DOWN arrowdown.png
IMG_ARROW_SCROLLBAR arrowscroller.png
+IMG_HOURGLASS hourglass.png
[categories]
do_all_cat 1 # if >0, will show an All category; if 0, skip it, just your cats.
#define PND_APPS_SEARCHPATH "/media/*/pandora/apps:/usr/pandora/apps"
#define PND_APPS_KEY "autodiscovery.searchpath"
+#define PND_APPS_APPDATA_PREFIX "/pandora/appdata" /* /media/DEVNAME + PREFIX + unique-id */
+
// default notify searchpath (and key to look it up in config)
#define PND_APPS_NOTIFYPATH "/media:/media/*/pandora/apps:/usr/pandora/apps"
#define PND_APPS_NOTIFY_KEY "autodiscovery.notifypath"
// consider for a similar effect: df /home -> look at "Mounted on"
unsigned char pnd_determine_mountpoint ( char *fullpath, char *r_mountpoint, unsigned char mountpoint_len );
+// filecopy will return >0 on success
+unsigned char pnd_filecopy ( char *sourcepath, char *targetpath );
+
#ifdef __cplusplus
} /* "C" */
#endif
*ws = '\0';
if ( r_path && path_len ) {
- snprintf ( r_path, path_len, "%s/appdata/%s/", cmdbuf, unique_id );
+ snprintf ( r_path, path_len, "%s/pandora/appdata/%s/", cmdbuf, unique_id );
}
return ( 1 );
return ( 0 );
}
+
+unsigned char pnd_filecopy ( char *sourcepath, char *targetpath ) {
+#define BITLEN (64*1024)
+ FILE *pnd, *target; // pnd == from, since I cribbed the code from pnd_desktop.c :/
+ unsigned char bits [ BITLEN ];
+ unsigned int bitlen;
+
+ pnd = fopen ( sourcepath, "rb" );
+
+ if ( ! pnd ) {
+ return ( 0 );
+ }
+
+ unsigned int len;
+
+ target = fopen ( targetpath, "wb" );
+
+ if ( ! target ) {
+ fclose ( pnd );
+ return ( 0 );
+ }
+
+ fseek ( pnd, 0, SEEK_END );
+ len = ftell ( pnd );
+ fseek ( pnd, 0, SEEK_SET );
+
+ while ( len ) {
+
+ if ( len > (BITLEN) ) {
+ bitlen = (BITLEN);
+ } else {
+ bitlen = len;
+ }
+
+ if ( fread ( bits, bitlen, 1, pnd ) != 1 ) {
+ fclose ( pnd );
+ fclose ( target );
+ unlink ( targetpath );
+ return ( 0 );
+ }
+
+ if ( fwrite ( bits, bitlen, 1, target ) != 1 ) {
+ fclose ( pnd );
+ fclose ( target );
+ unlink ( targetpath );
+ return ( 0 );
+ }
+
+ len -= bitlen;
+ } // while
+
+ fclose ( pnd );
+ fclose ( target );
+
+ return ( 1 );
+}
- libpnd: appdata-dir-name?
+- speed up render, use render mask?
+- evmapperd.. no force off, if charging on /sys/class/power_supply/bq27500-0/current_now is +ve
- skinning .. mmenu.conf and then skin.conf in each skin dir?
- preview pic override for davec :)
- some ultra primtive frame draw, so the 'detail menu' and any 'sub menus' can draw
#include "pnd_desktop.h"
#include "pnd_pndfiles.h"
#include "pnd_apps.h"
+#include "../lib/pnd_pathiter.h"
+#include "pnd_locate.h"
#include "mmenu.h"
#include "mmapps.h"
#include "mmcache.h"
+#include "mmcat.h"
+#include "mmui.h"
extern pnd_conf_handle g_conf;
+extern unsigned char g_pvwcache;
mm_cache_t *g_icon_cache = NULL;
mm_cache_t *g_preview_cache = NULL;
// not cached, load it up
//
+ // show hourglass
+ ui_show_hourglass ( 1 /* updaterect*/ );
+
// see if we can mount the pnd/dir
// does preview file exist?
// if so, load it up, size it, cache it
// if not, warning and bail
// unmount it
- // can we mount?
- char fullpath [ PATH_MAX ];
- char filepath [ PATH_MAX ];
+ // can we mount? or can we find it in preview cache?
+ char fullpath [ PATH_MAX ] = "";
+ char filepath [ PATH_MAX ] = "";
- sprintf ( fullpath, "%s/%s", app -> object_path, app -> object_filename );
+ if ( g_pvwcache ) {
+ static char *cache_findpath = NULL;
+ if ( ! cache_findpath ) {
+ cache_findpath = pnd_conf_get_as_char ( g_conf, "previewpic.cache_findpath" );
+ }
+ char buffer [ FILENAME_MAX ];
+ sprintf ( buffer, "%s.png", app -> unique_id );
+ char *f = pnd_locate_filename ( cache_findpath, buffer );
+ if ( f ) {
+ strncpy ( filepath, f, PATH_MAX );
+ }
+ }
+
+ // if we don't have a file path sorted out yet, means we need to mount and figure it
+ if ( ! filepath [ 0 ] ) {
+ sprintf ( fullpath, "%s/%s", app -> object_path, app -> object_filename );
+
+ if ( ! pnd_pnd_mount ( pnd_run_script, fullpath, app -> unique_id ) ) {
+ pnd_log ( pndn_debug, "Couldn't mount '%s' for preview\n", fullpath );
+ return ( 0 ); // couldn't mount?!
+ }
- if ( ! pnd_pnd_mount ( pnd_run_script, fullpath, app -> unique_id ) ) {
- pnd_log ( pndn_debug, "Couldn't mount '%s' for preview\n", fullpath );
- return ( 0 ); // couldn't mount?!
+ sprintf ( filepath, "%s/%s/%s", PND_MOUNT_PATH, app -> unique_id, app -> preview_pic1 );
}
- sprintf ( filepath, "%s/%s/%s", PND_MOUNT_PATH, app -> unique_id, app -> preview_pic1 );
+ // load whatever path we've got
s = IMG_Load ( filepath );
- pnd_pnd_unmount ( pnd_run_script, fullpath, app -> unique_id );
-
if ( ! s ) {
+ // unmount it, if mounted
+ if ( fullpath [ 0 ] ) {
+ pnd_pnd_unmount ( pnd_run_script, fullpath, app -> unique_id );
+ }
pnd_log ( pndn_debug, "Couldn't open image '%s' for preview\n", filepath );
return ( 0 );
}
+ // try to copy file to the cache, if we're doing that, and if mounted
+ if ( g_pvwcache && fullpath [ 0 ] ) {
+ char cacheoutpath [ PATH_MAX ] = "";
+
+ // figure out where we want to write the file to
+ if ( cache_find_writable ( cacheoutpath, PATH_MAX ) ) {
+ static char *cache_path = NULL;
+ char buffer [ PATH_MAX ];
+ if ( ! cache_path ) {
+ cache_path = pnd_conf_get_as_char ( g_conf, "previewpic.cache_path" );
+ }
+ // make the dir
+ snprintf ( buffer, PATH_MAX, "%s/%s", cacheoutpath, cache_path );
+ struct stat statbuf;
+ if ( stat ( buffer, &statbuf ) != 0 ) {
+ snprintf ( buffer, PATH_MAX, "/bin/mkdir -p %s/%s", cacheoutpath, cache_path );
+ system ( buffer );
+ }
+ // set up target filename to copy
+ snprintf ( buffer, PATH_MAX, "%s/%s/%s.png", cacheoutpath, cache_path, app -> unique_id );
+ pnd_log ( pndn_debug, "Found free space to cache preview to here: %s", buffer );
+ if ( ! pnd_filecopy ( filepath, buffer ) ) {
+ pnd_log ( pndn_error, "ERROR: Copying preview from %s to %s", filepath, buffer );
+ }
+ } else {
+ pnd_log ( pndn_warning, "WARN: Couldn't find a device to cache preview to.\n" );
+ }
+
+ } // preview file cache
+
+ // unmount it, if mounted
+ if ( fullpath [ 0 ] ) {
+ pnd_pnd_unmount ( pnd_run_script, fullpath, app -> unique_id );
+ }
+
//pnd_log ( pndn_debug, "Image size is %u x %u (max %u x %u)\n", s -> w, s -> h, maxwidth, maxheight );
// scale
mm_cache_t *cache_query_preview ( char *id ) {
return ( cache_query ( id, g_preview_cache ) );
}
+
+unsigned char cache_find_writable ( char *r_writepath, unsigned int len ) {
+ static char *searchpath = NULL;
+ static unsigned int minfree = 0;
+ char cmdbuf [ PATH_MAX ];
+ FILE *f;
+ unsigned int freespace = 0;
+
+ // try to find a device, in order of searchpath, with enough space for this cache-out
+
+ if ( ! searchpath ) {
+ searchpath = pnd_conf_get_as_char ( g_conf, "previewpic.cache_searchpath" );
+ minfree = pnd_conf_get_as_int_d ( g_conf, "previewpic.cache_minfree", 500 );
+ }
+
+ if ( ! searchpath ) {
+ return ( 0 ); // fail!
+ }
+
+ SEARCHPATH_PRE
+ {
+
+ // since I didn't figure out which /sys/block I can pull remaining space from, I'll use df for now :/
+ sprintf ( cmdbuf, "/bin/df %s", buffer );
+
+ f = popen ( cmdbuf, "r" );
+
+ if ( f ) {
+ while ( fgets ( cmdbuf, PATH_MAX, f ) ) {
+ // just eat it up
+ // /dev/sdc2 7471392 725260 6366600 11% /media/IMAGE
+ if ( sscanf ( cmdbuf, "%*s %*u %*u %u %*u %*s\n", &freespace ) == 1 ) {
+ strncpy ( r_writepath, buffer, len );
+ if ( freespace > minfree ) {
+ pclose ( f );
+ return ( 1 );
+ } // enough free?
+ } // df
+ } // while
+ pclose ( f );
+ }
+
+ }
+ SEARCHPATH_POST
+
+ return ( 0 );
+}
mm_cache_t *cache_query_icon ( char *id ); // specialized version
mm_cache_t *cache_query_preview ( char *id ); // specialized version
+unsigned char cache_find_writable ( char *r_writepath, unsigned int len );
+
#endif
char *g_skinpath = NULL;
unsigned char g_x11_present = 1; // >0 if X is present
unsigned char g_catmap = 0; // if 1, we're doing category mapping
+unsigned char g_pvwcache = 0; // if 1, we're trying to do preview caching
int main ( int argc, char *argv[] ) {
int logall = -1; // -1 means normal logging rules; >=0 means log all!
// show load screen
ui_loadscreen();
+ // store flag if we're doing preview caching or not
+ if ( pnd_conf_get_as_int_d ( g_conf, "previewpic.do_cache", 0 ) ) {
+ g_pvwcache = 1;
+ }
+
// set up static image cache
if ( ! ui_imagecache ( g_skinpath ) ) {
pnd_log ( pndn_error, "ERROR: Couldn't set up static UI image cache!\n" );
pndrun /usr/pandora/scripts:./testdata/scripts # searchpath to locate "pnd_run.sh"; why aren't I looking in /etc/pandora/conf/apps for this?
load_previews_now 0 # if >0, will try to load preview pics from pnds at boot time, not defer till later
load_previews_later 0 # if >0, will try to load preview pics sometime (see defer_timer_ms as well)
-load_icons_later 1 # if >0, will try to load icons after grid is showing, not during app scanning
+load_icons_later 0 # if >0, will try to load icons after grid is showing, not during app scanning
defer_icon_us 100000 # when background loading icons (load_icons_later), time between icon loadsa
-threaded_preview 1 # if 1, will try to load the preview in background, to avoid slowing up navigation
+threaded_preview 0 # if 1, will try to load the preview in background, to avoid slowing up navigation
loglevel 0 # 0 is debug, lots of crap; 3 is better, means 'errors only'. Output may screw up the wrapper!
x11_present_sh /bin/pidof X # command to invoke to determine if X11 is running or not; expects a number on X is present.
desktop_apps 1 # search the pnd standard desktop searchpath for apps
font_rgba_a 20 # RGBA for the display text
battery_x 10 # (x,y) for battery level
battery_y 450 # (x,y) for battery level
-hintline Push SELECT for shutdown options # shown at bottom of screen
-hint_x 275 # (x,y) for hint line
+hintline Push SELECT for options # shown at bottom of screen
+hint_x 300 # (x,y) for hint line
hint_y 450 # (x,y) for hint line
clock_x 650 # (x,y) for clock
clock_y 450 # (x,y) for clock
cell_width 250 # width of cell (for text clipping)
[previewpic]
-defer_timer_ms 1000 # after setting selection, how long to wait before we try to load the previewpic
+defer_timer_ms 2000 # after setting selection, how long to wait before we try to load the previewpic
cell_offset_x 480 # left edge of text cell
cell_offset_y 90 # top edge of text cell
cell_width 285
cell_height 180
scale_up_bool 1 # if 0, will not try to scale up preview
+do_cache 1 # if 1, will try to cache previews to SD, for performance boost
+cache_searchpath /media/mmcblk[12]p? # devices to consider for caching to, in order
+cache_minfree 500 # if free space is less than this (in KB), move to next device
+cache_path /pandora/appdata/mmenu.pvwcache # where to write cached images to
+cache_findpath /media/mmcblk[12]p?/pandora/appdata/mmenu.pvwcache # where to look for cached preview pics
[graphics]
IMG_BACKGROUND_800480 800480_6.png
IMG_ARROW_UP arrowup.png
IMG_ARROW_DOWN arrowdown.png
IMG_ARROW_SCROLLBAR arrowscroller.png
+IMG_HOURGLASS hourglass.png
[categories]
do_all_cat 1 # if >0, will show an All category; if 0, skip it, just your cats.
{ IMG_ARROW_UP, "graphics.IMG_ARROW_UP", },
{ IMG_ARROW_DOWN, "graphics.IMG_ARROW_DOWN", },
{ IMG_ARROW_SCROLLBAR, "graphics.IMG_ARROW_SCROLLBAR", },
+ { IMG_HOURGLASS, "graphics.IMG_HOURGLASS", },
{ IMG_MAX, NULL },
};
// timer went off, time to load something
if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.load_previews_later", 0 ) ) {
- pnd_log ( pndn_debug, "Deferred preview pic load ----------\n" );
-
// load the preview pics now!
pnd_disco_t *iter = ui_selected -> ref;
if ( iter -> preview_pic1 ) {
if ( pnd_conf_get_as_int_d ( g_conf, "minimenu.threaded_preview", 0 ) ) {
+ // load in bg thread, make user experience chuggy
g_preview_thread = SDL_CreateThread ( (void*)ui_threaded_defered_preview, iter );
}
} else {
+ // load it now, make user wait
if ( ! cache_preview ( iter, pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 ),
pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 ) )
} // got a preview at all?
- pnd_log ( pndn_debug, "Deferred preview pic load finish ---\n" );
-
ui_event++;
}
"Return to Minimenu",
"Shutdown Pandora",
"Rescan for Applications",
+ "Cache previews to SD now",
"Run xfce4 from Minimenu",
"Run a terminal/console",
"Exit and run xfce4",
ui_selected = NULL;
ui_rows_scrolled_down = 0;
} else if ( sel == 3 ) {
+ // cache preview to SD now
+ extern pnd_box_handle g_active_apps;
+ pnd_box_handle h = g_active_apps;
+
+ unsigned char maxwidth, maxheight;
+ maxwidth = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_width", 200 );
+ maxheight = pnd_conf_get_as_int_d ( g_conf, "previewpic.cell_height", 180 );
+
+ pnd_disco_t *iter = pnd_box_get_head ( h );
+
+ while ( iter ) {
+
+ // cache it
+ if ( ! cache_preview ( iter, maxwidth, maxheight ) ) {
+ pnd_log ( pndn_debug, "Force cache: Couldn't load preview pic: '%s' -> '%s'\n",
+ IFNULL(iter->title_en,"No Name"), iter -> preview_pic1 );
+ }
+
+ // next
+ iter = pnd_box_get_next ( iter );
+ } // while
+
+ } else if ( sel == 4 ) {
// run xfce
char buffer [ PATH_MAX ];
sprintf ( buffer, "%s %s\n", MM_RUN, "/usr/bin/startxfce4" );
emit_and_quit ( buffer );
- } else if ( sel == 4 ) {
+ } else if ( sel == 5 ) {
// run terminal
char *argv[5];
argv [ 0 ] = pnd_conf_get_as_char ( g_conf, "utility.terminal" );
ui_forkexec ( argv );
}
- } else if ( sel == 5 ) {
+ } else if ( sel == 6 ) {
// set env to xfce
sprintf ( buffer, "echo startxfce4 > /tmp/gui.load" );
system ( buffer );
//sprintf ( buffer, "sudo poweroff" );
//system ( buffer );
exit ( 0 );
- } else if ( sel == 6 ) {
+ } else if ( sel == 7 ) {
// set env to pmenu
sprintf ( buffer, "echo pmenu > /tmp/gui.load" );
system ( buffer );
//sprintf ( buffer, "sudo poweroff" );
//system ( buffer );
exit ( 0 );
- } else if ( sel == 7 ) {
- emit_and_quit ( MM_QUIT );
} else if ( sel == 8 ) {
+ emit_and_quit ( MM_QUIT );
+ } else if ( sel == 9 ) {
// about
}
return ( 0 );
}
+
+void ui_show_hourglass ( unsigned char updaterect ) {
+
+ SDL_Rect dest;
+ SDL_Surface *s = g_imagecache [ IMG_HOURGLASS ].i;
+
+ dest.x = ( 800 - s -> w ) / 2;
+ dest.y = ( 480 - s -> h ) / 2;
+
+ SDL_BlitSurface ( s, NULL /* whole image */, sdl_realscreen, &dest );
+
+ if ( updaterect ) {
+ SDL_UpdateRects ( sdl_realscreen, 1, &dest );
+ }
+
+ return;
+}
IMG_ARROW_UP,
IMG_ARROW_DOWN,
IMG_ARROW_SCROLLBAR,
+ IMG_HOURGLASS,
IMG_MAX, // before this point is loaded; after is generated
IMG_TRUEMAX
} mm_imgcache_e;
void ui_loadscreen ( void ); // show screen while loading the menu
void ui_discoverscreen ( unsigned char clearscreen ); // screen to show while scanning for apps
void ui_cachescreen ( unsigned char clearscreen, char *filename ); // while caching icons, categories and preview-pics-Now-mode
+void ui_show_hourglass ( unsigned char updaterect );
void ui_post_scan ( void );
/* internal functions follow