summary refs log tree commit diff stats
path: root/code/entry.rb
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-06-13 02:20:46 +0200
committerhut <hut@lavabit.com>2009-06-13 02:20:46 +0200
commit2887ca25fb58362d5d644ecda5f0bc51c80ec404 (patch)
treeb066f5542d97b1a4a9134d0910692b873fe32363 /code/entry.rb
parent325ec37f65172b5b640d998eba300d86d1ddbfa5 (diff)
downloadranger-2887ca25fb58362d5d644ecda5f0bc51c80ec404.tar.gz
rewrite of the way files are executed, easier config
Diffstat (limited to 'code/entry.rb')
-rw-r--r--code/entry.rb26
1 files changed, 19 insertions, 7 deletions
diff --git a/code/entry.rb b/code/entry.rb
index f2871847..bc0d2d7b 100644
--- a/code/entry.rb
+++ b/code/entry.rb
@@ -5,8 +5,17 @@ class Directory::Entry
 	# to call File methods all the time
 
 	BAD_TIME = Time.at(0)
-	MOVIE_EXTENSIONS = %w(avi mpg mpeg mp4 mp5 ogv ogm wmv mkv flv fid vob div divx)
+	MIMETYPES = Marshal.load(File.read(
+		File.join(MYDIR, 'data', 'mime.dat')))
+
 	
+	## wrapper
+	def use() Use end
+	module Use
+		def self.method_missing(app,*_) throw(:use, app) end
+		def self.no_handler()           throw(:use, nil) end
+	end
+
 	def initialize(dirname, basename=nil)
 		if basename
 			@path = File.join(dirname, basename)
@@ -27,6 +36,7 @@ class Directory::Entry
 		@symlink = false
 		@writable = false
 		@infostring = ''
+		@mimetype = nil
 		@executable = false
 		@type = :nonexistent
 		@mtime = BAD_TIME
@@ -35,7 +45,7 @@ class Directory::Entry
 	end
 
 	attr_reader(*%w{
-		basename mtime rights type path ext
+		basename mtime rights type path ext mimetype
 		infostring readlink basename size ctime name
 	})
 
@@ -45,17 +55,18 @@ class Directory::Entry
 	def exists?() @exists end
 	def marked?() @marked end
 	def symlink?() @symlink end
+	def socket?() @type == :socket end
 	def movie?() @movie end
 	def broken_symlink?() @symlink and !@exists end
 	def dir?() @type == :dir end
 	def file?() @type == :file end
 	def writable?() @writable end
 	def executable?() @executable end
-	def mimetype()
-		if @type == :dir
-			nil
-		else
-			Fm::MIMETYPES[@ext]
+
+	def handler()
+		## get_handler has to be defined in another file
+		@handler = catch(:use) do
+			get_handler
 		end
 	end
 
@@ -109,6 +120,7 @@ class Directory::Entry
 				@type = :socket
 			else
 				@type = :file
+				@mimetype = MIMETYPES[@ext]
 				@size = File.size(@path)
 				if File.size?(@path)
 					@infostring << " #{File.size(@path).bytes 2}"