Exemple #1
0
void gui_unload_preview()
{
    debug_start();

    if( tmp_preview != NULL )
    {
        GLES2D_FreeTexture( tmp_preview );
        tmp_preview = NULL;
    }

    video_quit( );

    if ( applications[category]->type[list_curpos[ category ]] ) // .pnd spotted
    {
        if( pnd_mounted )
        {
            pnd_pnd_unmount( pndrun, applications[category]->fullpath[list_curpos[ category ]], applications[category]->id[list_curpos[ category ]] );
            pnd_mounted = 0;
        }
    }

    preview_timer = 100;

    debug_end();
}
Exemple #2
0
unsigned char cache_preview ( pnd_disco_t *app, unsigned int maxwidth, unsigned int maxheight ) {
  SDL_Surface *s;
  mm_cache_t *c;

  // does this sucker even have a preview?
  if ( ! app -> preview_pic1 ) {
    return ( 1 ); // nothing here, so thats fine
  }

  // check if already cached
  if ( ( c = cache_query_preview ( app -> unique_id ) ) ) {
    return ( 1 ); // already got it
  }

  // 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? or can we find it in preview cache? or an override?
  char fullpath [ PATH_MAX ] = "";
  char filepath [ PATH_MAX ] = "";

  // first, check for preview override
  {
    char ovrfile [ PATH_MAX ];
    char *fooby;
    sprintf ( ovrfile, "%s/%s", app -> object_path, app -> object_filename );
    fooby = strcasestr ( ovrfile, PND_PACKAGE_FILEEXT );
    if ( fooby ) {
      sprintf ( fooby, "_pvw#%u.png", app -> subapp_number );
      struct stat statbuf;
      if ( stat ( ovrfile, &statbuf ) == 0 ) {
	strncpy ( filepath, ovrfile, PATH_MAX );
      } // stat
    } // ovr?
  }

  // if not yet found, try to find in cache
  if ( filepath [ 0 ] == '\0' && 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 );
    }
  }

  // unique-id to use for the cache mount
  char *uid = app -> unique_id;

  if ( app -> appdata_dirname ) {
    uid = app -> appdata_dirname;
  }

  // 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, uid ) ) {
      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, uid, app -> preview_pic1 );
  }

  // load whatever path we've got
  s = IMG_Load ( filepath );

  if ( ! s ) {
    // unmount it, if mounted
    if ( fullpath [ 0 ] ) {
      pnd_pnd_unmount ( pnd_run_script, fullpath, uid );
    }
    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 ( app -> object_path, 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
  if ( s -> w < maxwidth ) {
    // scale up?
    if ( pnd_conf_get_as_int_d ( g_conf, "previewpic.scale_up_bool", 1 ) ) {
      SDL_Surface *scaled;
      double scale = (double)maxwidth / (double)s -> w;
      //pnd_log ( pndn_debug, "  Upscaling; scale factor %f\n", scale );
      scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
      SDL_FreeSurface ( s );
      s = scaled;
    }
  } else if ( s -> w > maxwidth ) {
    SDL_Surface *scaled;
    double scale = (double)maxwidth / (double)s -> w;
    //pnd_log ( pndn_debug, "  Downscaling; scale factor %f\n", scale );
    scaled = rotozoomSurface ( s, 0 /* angle*/, scale /* scale */, 1 /* smooth==1*/ );
    SDL_FreeSurface ( s );
    s = scaled;
  }

  // add to cache
  c = (mm_cache_t*) malloc ( sizeof(mm_cache_t) );
  bzero ( c, sizeof(mm_cache_t) );

  if ( ! g_preview_cache ) {
    g_preview_cache = c;
  } else {
    c -> next = g_preview_cache;
    g_preview_cache = c;
  }

  strncpy ( c -> uniqueid, app -> unique_id, 1000 );
  c -> i = s;

  return ( 1 );
}
Exemple #3
0
void gui_load_preview( int cat, int n )
{
    debug_start();

	alpha_preview = 0;
	preview_scale = 0;

	if( tmp_preview != NULL )
	{
	    GLES2D_FreeTexture( tmp_preview );
	    tmp_preview = NULL;
	}

	if ( access ( applications[cat]->preview_pic1[n], R_OK ) == 0 )
	{
	    if ( is_avi( applications[cat]->preview_pic1[n] ) )
	    {
            debug_info( "Preview is a video" );
            video_play_preview( applications[cat]->preview_pic1[n] );
	    }
	    else
	    {
	        debug_info( "Preview is a picture" );
            if ( ( tmp_preview = GLES2D_CreateTexture( applications[cat]->preview_pic1[n], 0 ) ) == NULL )
            {
                debug_errorf( "GLES2D_CreateTexture(%s);", applications[cat]->preview_pic1[n] );
            }
	    }
	}
	else
	{
	    if ( access ( applications[cat]->fullpath[n], R_OK ) == 0 )
	    {
            if ( applications[cat]->type[n] == IS_PND )
            {
                char src[512];
                memset ( src, 0, 512 );
                sprintf( src, "/mnt/pnd/%s/%s", applications[cat]->id[n], applications[cat]->preview_pic1_name[n] );

                if ( is_avi( applications[cat]->preview_pic1_name[n] ) )
                {
                    pnd_pnd_mount ( pndrun, applications[cat]->fullpath[n], applications[cat]->id[n] );
                    pnd_mounted = 1;

                    if ( access ( src, R_OK ) == 0 )
                    {
                        pnd_pnd_mount ( pndrun, applications[cat]->fullpath[n], applications[cat]->id[n] );
                        pnd_mounted = 1;

                        video_play_preview( src );
                    }
                    else
                    {
                        pnd_pnd_unmount( pndrun, applications[cat]->fullpath[n], applications[cat]->id[n] );
                        pnd_mounted = 0;
                        debug_errorf("Preview pic do not exist (%s)", applications[cat]->preview_pic1[n]);
                        debug_info("Will use fail safe preview pic");
                    }
                }
                else
                {
                    debug_infof( "pnd_pnd_mount( pndrun, %s, %s );\n", applications[cat]->fullpath[n], applications[cat]->id[n] );

                    //pnd_pnd_mount ( pndrun, applications[cat]->fullpath[n], applications[cat]->id[n] );
			fast_mount( applications[cat]->fullpath[n] );

                    debug_info( "Done : pnd_pnd_mount()\n" );

			memset ( src, 0, 512 );
			sprintf( src, "/tmp/%s", applications[cat]->preview_pic1_name[n] );

                    debug_infof( "Creating preview texture from %s\n", src );

                    if ( ( tmp_preview = GLES2D_CreateTexture( src, 0 ) ) == NULL )
                    {
                        debug_errorf( "GLES2D_CreateTexture(%s);", applications[cat]->preview_pic1[n] );
                    }

                    debug_info( "pnd_pnd_umount()\n" );
                    //pnd_pnd_unmount ( pndrun, applications[cat]->fullpath[n], applications[cat]->id[n] );
			fast_umount( );
                    debug_info( "Done : pnd_pnd_umount()\n" );
                }
            }
            else
            {
                debug_errorf("Preview pic do not exist (%s)", applications[cat]->preview_pic1[n]);
                debug_info("Will use fail safe preview pic");
            }
	    }
	    else
	    {
            debug_errorf("Preview pic do not exist (%s)", applications[cat]->preview_pic1[n]);
            debug_info("Will use fail safe preview pic");
	    }
	}
	debug_end();
}