Author: duncan
Date: Wed Jan 10 20:32:48 2007
New Revision: 8961

Modified:
   branches/rel-1/freevo/src/helpers/cache.py
   branches/rel-1/freevo/src/util/fileops.py
   branches/rel-1/freevo/src/util/vfs.py
   branches/rel-1/freevo/src/www/htdocs/fileinfo.rpy
   branches/rel-1/freevo/src/www/htdocs/library.rpy
   branches/rel-1/freevo/src/www/web_types.py

Log:
Applied patch from Chandan for resizing opened window
Fixed cache, to allow deletion of webserver cache images
Updated calls to webserver code for changes to cache


Modified: branches/rel-1/freevo/src/helpers/cache.py
==============================================================================
--- branches/rel-1/freevo/src/helpers/cache.py  (original)
+++ branches/rel-1/freevo/src/helpers/cache.py  Wed Jan 10 20:32:48 2007
@@ -84,7 +84,15 @@
     """
     delete cachfiles/entries for files which don't exists anymore
     """
-    #TODO Add WWW_LINK_CACHE and WWW_IMAGE_CACNE
+    print 'deleting old webserver thumbnails.....................',
+    sys.__stdout__.flush()
+    num = 0
+    for file in util.match_files_recursively(vfs.www_image_cachedir(), 
config.IMAGE_SUFFIX):
+        if not 
vfs.isfile(file[len(vfs.www_image_cachedir()):file.rindex('.')]):
+            os.unlink(file)
+            num += 1
+    print 'deleted %s file%s' % (num, num != 1 and 's' or '')
+
     print 'deleting old cachefiles...............................',
     sys.__stdout__.flush()
     num = 0
@@ -170,9 +178,9 @@
 
     files = util.misc.unique(files)
     for filename in copy.copy(files):
-        sinfo = os.stat(filename)
         thumb = vfs.getoverlay(filename + '.raw')
         try:
+            sinfo = os.stat(filename)
             if os.stat(thumb)[stat.ST_MTIME] > sinfo[stat.ST_MTIME]:
                 files.remove(filename)
         except OSError:
@@ -210,22 +218,20 @@
     sys.__stdout__.flush()
 
     files = []
-    for d in config.VIDEO_ITEMS + config.AUDIO_ITEMS + config.IMAGE_ITEMS:
+    for d in config.IMAGE_ITEMS:
         try:
             d = d[1]
         except:
             pass
         if not os.path.isdir(d):
             continue
-        files += util.match_files_recursively(d, config.IMAGE_SUFFIX) + \
-                 util.match_files_recursively(vfs.getoverlay(d), 
config.IMAGE_SUFFIX)
+        files += util.match_files_recursively(d, config.IMAGE_SUFFIX)
 
-    cache_dir = util.fileops.www_image_cachedir()
     files = util.misc.unique(files)
     for filename in copy.copy(files):
-        sinfo = os.stat(filename)
-        thumb = util.cache_www_thumbnail_path(filename)
+        thumb = util.www_thumbnail_path(filename)
         try:
+            sinfo = os.stat(filename)
             if os.stat(thumb)[stat.ST_MTIME] > sinfo[stat.ST_MTIME]:
                 files.remove(filename)
         except OSError:
@@ -246,7 +252,7 @@
             fname = fname[:20] + ' [...] ' + fname[-40:]
         print '  %4d/%-4d %s' % (files.index(filename)+1, len(files), fname)
 
-        util.cache_www_image(filename)
+        util.create_www_thumbnail(filename)
 
     if files:
         print

Modified: branches/rel-1/freevo/src/util/fileops.py
==============================================================================
--- branches/rel-1/freevo/src/util/fileops.py   (original)
+++ branches/rel-1/freevo/src/util/fileops.py   Wed Jan 10 20:32:48 2007
@@ -560,43 +560,31 @@
     return (scaled_width, scaled_height)
 
 
-def www_link_cachedir():
-    '''returns the www link cache directory name
-    if the directory does not exist it is created
-    '''
-    cache_dir = '%s/link_cache/' % (config.WEBSERVER_CACHEDIR)
-    if not os.path.isdir(cache_dir):
-        os.mkdir(cache_dir, 
stat.S_IMODE(os.stat(config.WEBSERVER_CACHEDIR)[stat.ST_MODE]))
-    return cache_dir
-
-
-def www_image_cachedir():
-    '''returns the www image cache directory name
-    if the directory does not exist it is created
-    '''
-    cache_dir = '%s/image_cache/' % (config.WEBSERVER_CACHEDIR)
-    if not os.path.isdir(cache_dir):
-        os.mkdir(cache_dir, 
stat.S_IMODE(os.stat(config.WEBSERVER_CACHEDIR)[stat.ST_MODE]))
-    return cache_dir
-
-
-def cache_www_thumbnail_path(filename):
+def www_thumbnail_path(filename):
     '''returns the path to the thumbnail image for a given filename
     '''
     file_ext_index = filename.rindex(".")
     file_ext = filename[file_ext_index:].lower()
     if file_ext == ".gif":
         file_ext += ".jpg"
-    imagepath = filename[:file_ext_index].replace("/", "_") + file_ext
-    thumb_path = os.path.join(www_image_cachedir(), imagepath)
+    # the filename extension needs to be lowercase for imlib2 but we need to
+    # keep the original filename for cache to be able to clean the files
+    imagepath = filename + file_ext
+    thumb_path = vfs.getwwwoverlay(imagepath)
     return thumb_path
 
 
-def cache_www_image(filename):
+def create_www_thumbnail(filename):
     '''creates a webserver thumbnail image and returns its size.
     '''
-    thumb_path = cache_www_thumbnail_path(filename)
+    thumb_path = www_thumbnail_path(filename)
     try:
+        try:
+            if not os.path.isdir(os.path.dirname(thumb_path)):
+                os.makedirs(os.path.dirname(thumb_path), mode=04775)
+        except IOError:
+            print 'error creating dir %s' % os.path.dirname(thumb_path)
+            raise IOError
         image = imlib2.open(filename)
         thumb = image.scale_preserve_aspect(config.WWW_IMAGE_THUMBNAIL_SIZE)
         thumb.save(thumb_path)
@@ -606,9 +594,9 @@
     return thumb.size
 
 
-def cache_www_image_size(filename):
+def get_www_thumbnail_size(filename):
     '''returns the size from a webserver cached image.
     '''
-    thumb_path = cache_www_thumbnail_path(filename)
+    thumb_path = www_thumbnail_path(filename)
     image = imlib2.open(filename)
     return image.size

Modified: branches/rel-1/freevo/src/util/vfs.py
==============================================================================
--- branches/rel-1/freevo/src/util/vfs.py       (original)
+++ branches/rel-1/freevo/src/util/vfs.py       Wed Jan 10 20:32:48 2007
@@ -34,16 +34,34 @@
 #
 # -----------------------------------------------------------------------
 
-
 import os
 import copy
 import traceback
 import codecs
 from stat import ST_MTIME
 
-
 import config
 
+def www_link_cachedir():
+    '''returns the www link cache directory name
+    if the directory does not exist it is created
+    '''
+    cache_dir = '%s/link_cache' % (config.WEBSERVER_CACHEDIR)
+    if not os.path.isdir(cache_dir):
+        os.mkdir(cache_dir, 
stat.S_IMODE(os.stat(config.WEBSERVER_CACHEDIR)[stat.ST_MODE]))
+    return cache_dir
+
+
+def www_image_cachedir():
+    '''returns the www image cache directory name
+    if the directory does not exist it is created
+    '''
+    cache_dir = '%s/image_cache' % (config.WEBSERVER_CACHEDIR)
+    if not os.path.isdir(cache_dir):
+        os.mkdir(cache_dir, 
stat.S_IMODE(os.stat(config.WEBSERVER_CACHEDIR)[stat.ST_MODE]))
+    return cache_dir
+
+
 def getoverlay(directory):
     if not directory.startswith('/'):
         directory = os.path.abspath(directory)
@@ -56,6 +74,14 @@
     return config.OVERLAY_DIR + directory
 
 
+def getwwwoverlay(directory):
+    if not directory.startswith('/'):
+        directory = os.path.abspath(directory)
+    if directory.startswith(www_image_cachedir()):
+        return directory
+    return www_image_cachedir() + directory
+
+
 def abspath(name):
     """
     return the complete filename (including OVERLAY_DIR)

Modified: branches/rel-1/freevo/src/www/htdocs/fileinfo.rpy
==============================================================================
--- branches/rel-1/freevo/src/www/htdocs/fileinfo.rpy   (original)
+++ branches/rel-1/freevo/src/www/htdocs/fileinfo.rpy   Wed Jan 10 20:32:48 2007
@@ -39,7 +39,6 @@
 
     def __init__(self):
         print '__init__(self)'
-        self.cache_dir = util.fileops.www_link_cachedir()
         self.allowed_dirs = []
         self.allowed_dirs.extend(config.VIDEO_ITEMS)
         self.allowed_dirs.extend(config.AUDIO_ITEMS)

Modified: branches/rel-1/freevo/src/www/htdocs/library.rpy
==============================================================================
--- branches/rel-1/freevo/src/www/htdocs/library.rpy    (original)
+++ branches/rel-1/freevo/src/www/htdocs/library.rpy    Wed Jan 10 20:32:48 2007
@@ -53,7 +53,6 @@
 
     def __init__(self):
         print '__init__(self)'
-        self.cache_dir = util.www_image_cachedir()
         self.allowed_dirs = []
         self.allowed_dirs.extend(config.VIDEO_ITEMS)
         self.allowed_dirs.extend(config.AUDIO_ITEMS)
@@ -480,11 +479,11 @@
                         status = 'favorite'
                     ### show image
                     if action_mediatype == "images":
-                        scaled_image_path = util.cache_www_thumbnail_path(item)
+                        scaled_image_path = util.www_thumbnail_path(item)
                         if not os.path.exists(scaled_image_path):
-                            size = util.cache_www_image(item)
+                            size = util.create_www_thumbnail(item)
                         else:
-                            size = util.cache_www_image_size(item)
+                            size = util.get_www_thumbnail_size(item)
                         image_link = self.convert_dir(filepath)
                         scaled_image_link = self.convert_dir(scaled_image_path)
                         fv.tableCell('<div class="image"><a 
href="javascript:openfoto(\''+image_link+'\','+str(size[0])+','+str(size[1])+')">'\

Modified: branches/rel-1/freevo/src/www/web_types.py
==============================================================================
--- branches/rel-1/freevo/src/www/web_types.py  (original)
+++ branches/rel-1/freevo/src/www/web_types.py  Wed Jan 10 20:32:48 2007
@@ -443,37 +443,61 @@
         self.res += """<script language="JavaScript" type="text/javascript" 
style="display:none;">
         var width = 0;
         var height = 0;
-        var max_width = screen.width - 10;
-        var max_height = screen.height - 100;
-        
+        var max_width = screen.availWidth;
+        var max_height = screen.availHeight - 100;
+        var client_width = 0;
+        var client_height = 0;
+
         function openfoto(loc,width_img,height_img){
             width = width_img;
             height = height_img;
-            
+
             if (width >= max_width || height >= max_height) {
                 getNewSize();
             }
-            var 
params="toolbar=no,location=no,status=no,menubar=no,resizable=no,scrollbars=no,top=0,left=0,width="+width+",height="+height;
+            var 
params="toolbar=no,location=no,status=no,menubar=yes,resizable=no,top=0,left=0,width="+width+",height="+height;
             foto = 
window.open("fileinfo.rpy?img="+loc+"&w="+width+"&h="+height,"Images",params);
-        }
-        
-        function getNewSize(){                
-            if (width > max_width || height > max_height){
-                //Determine what dimension is off by more
-                deltaWidth = width - max_width;
-                deltaHeight= height - max_height;
-        
-                if (deltaHeight > deltaWidth){
-                    //Scale by the height
-                    scaleFactor = max_height / height;
+
+            // Some funky code here
+            // 1. First we resize the window to the size we want
+            // 2. Calculate the client area of this resized window
+            // 3. Subtract the client area from the actual size
+            // 4. Add the difference to the window size
+
+            // Step 1. First we resize the window to the size we want
+            foto.resizeTo(width, height);
+
+            // Step 2. Calculate the client area of this resized window
+            if (parseInt(navigator.appVersion) > 3) {
+                if (navigator.appName=="Netscape") {
+                    client_width = foto.innerWidth;
+                    client_height = foto.innerHeight;
                 }
-                else{
-                    //Scale by the Width
-                    scaleFactor = max_width / width;
+                if (navigator.appName.indexOf("Microsoft") != -1) {
+                    client_width = foto.body.offsetWidth;
+                    client_height = foto.body.offsetHeight;
                 }
-        
-                width *= scaleFactor;
-                height *= scaleFactor;
+            }
+
+            // Step 3. Subtract the client area from the actual size
+            var diff_width = width - client_width;
+            var diff_height = height - client_height;
+
+            // Step 4. Add the difference to the window size
+            foto.resizeBy(diff_width, diff_height);
+
+            foto.focus();
+         }
+
+         function getNewSize(){
+            // recalculate width / height maintaining aspect
+            if (max_width / max_height > width / height) {
+                width = Math.round(max_height * width / height);
+                height = max_height;
+            }
+            else {
+                height = Math.round(max_width * height / width);
+                width = max_width;
             }
         }
         </script> """

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to