[futurebasic] Re: [FB] Total items count for folder/Filter

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2013 : Group Archive : Group : All Groups

From: Bernie <fblist.bw@...>
Date: Thu, 27 Jun 2013 23:44:21 +0100
rc wrote:

> // FILTER CONSTANTS
> Begin Enum 0
> _AnyFile  
> _AnyImage  
> _AnyMovie 
> _PDFFilter 
> _PICTFilter 
> _JPEGFilter 
> _JFIFFilter 
> _GIFFilter 
> _PShopFilter 
> _TIFFFilter 
> _PNGFilter 
> _qtifFilter  
> _PNTGFilter 
> _FreebieType  
> _Folders  
> end enum
> 
> Local Fn FileFilter( filterType as short, itemURL as CFURLRef)
> dim as short result
> dim as CFStringRef itemUTI
> 
> result = _false // assume failure, saves time
>  
> beginCCode
> [(NSURL *)itemURL getResourceValue:(id*)&itemUTI forKey:NSURLTypeIdentifierKey error:nil];
> endC
> select filterType
> case _AnyImage
> if fn UTTypeConformsTo( itemUTI, kUTTypeImage          ) then result = _true 
> case _GIFFilter
> if fn UTTypeConformsTo( itemUTI, kUTTypeGIF            ) then result = _true 
> <…..>

I wonder if you could reduce the number of ifs by passing filterType as CFStringRef?

'---------------
local fn FileFilter( itemURL as CFURLRef, filterType as CFStringRef )
'~'1
dim as Boolean   result

BeginCCode
result = [(NSURL *)itemURL getResourceValue:(id*)&itemUTI forKey:NSURLTypeIdentifierKey error:nil];
EndC
if ( result == _false ) then return

long if ( fn CFStringCompare( filterType, @"MyFileFilterTypeAnyFile", 0 ) != _kCFCompareEqualTo )
result = fn UTTypeConformsTo( itemUTI, filterType )
xelse

// .....

end if
end fn = result
'---------------