summary refs log tree commit diff stats
path: root/code
diff options
context:
space:
mode:
Diffstat (limited to 'code')
-rw-r--r--code/directory.rb158
-rw-r--r--code/entry.rb140
2 files changed, 155 insertions, 143 deletions
diff --git a/code/directory.rb b/code/directory.rb
index d3c4382b..10966a4a 100644
--- a/code/directory.rb
+++ b/code/directory.rb
@@ -1,150 +1,12 @@
-require 'code/extensions/basic.rb'
-class Directory
-	BAD_TIME = Time.at(0)
-	MOVIE_EXTENSIONS = %w(avi mpg mpeg mp4 mp5 ogv ogm wmv mkv flv fid vob div divx)
-	class Entry #{{{
-		# Let's just cache every shit, because i don't want
-		# to call File methods all the time
-		
-		
-		def initialize(dirname, basename=nil)
-			if basename
-				@path = File.join(dirname, basename)
-				@dirname = dirname
-				@basename = basename
-			else
-				@path = dirname
-				@dirname = File.dirname(dirname)
-				@basename = File.basename(dirname)
-			end
-			@name, @ext = @basename.split_at_last_dot
-#			@ext = @basename.from_last('.') || ''
-			@movie = MOVIE_EXTENSIONS.include?(@ext)
-			@size = 0
-			@exists = false
-			@rights = '----------'
-			@readlink = ''
-			@symlink = false
-			@writable = false
-			@infostring = ''
-			@executable = false
-			@type = :nonexistent
-			@mtime = BAD_TIME
-			@ctime = BAD_TIME
-			@marked = false
-		end
-
-		attr_reader(*%w{
-			basename mtime rights type path ext
-			infostring readlink basename size ctime name
-		})
-
-		attr_accessor(:marked)
-		
-		def to_s() @path end
-		def exists?() @exists end
-		def marked?() @marked end
-		def symlink?() @symlink 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]
-			end
-		end
-
-		def delete!
-			if @type == :dir
-				Dir.delete(@path) rescue nil
-			else
-				File.delete(@path) rescue nil
-			end
-		end
-
-		def refresh
-			if File.exists?(@path)
-				if File.ctime(@path) != @ctime
-					get_data
-				end
-			else
-				get_data
-			end
-		end
-
-		def sh
-			@path.sh
-		end
-
-		def in? path
-			to_s[0, path.size] == path
-		end
-
-		def get_data
-			@size = 0
-			@infostring = ''
-
-			@exists = File.exists?(@path)
-			if @exists
-				@writable = File.writable?(@path)
-				@symlink = File.symlink?(@path)
-				if @symlink
-					@readlink = File.readlink(@path)
-				end
-				if File.directory?(@path)
-					@type = :dir
-					begin
-						sz = Dir.entries(@path).size - 2
-						@size = sz
-					rescue
-						sz = "?"
-					end
-					@infostring << "#{sz}"
-				elsif File.socket?(@path)
-					@type = :socket
-				else
-					@type = :file
-					@size = File.size(@path)
-					if File.size?(@path)
-						@infostring << " #{File.size(@path).bytes 2}"
-					else
-						@infostring << ""
-					end
-				end
-				@rights = File.modestr(@path)
-				@executable = File.executable?(@path)
-				@mtime = File.mtime(@path)
-				@ctime = File.ctime(@path)
+require 'code/extensions/basic'
 
-			else
-				if File.symlink?(@path)
-					@readlink = File.readlink(@path)
-					@infostring = '->'
-					@symlink = true
-				else
-					@symlink = false
-				end
-				@executable = false
-				@writable = false
-				@type = :nonexistent
-				@rights = '----------'
-				@mtime = BAD_TIME
-				@ctime = BAD_TIME
-			end
-		end
-	end #}}}
-
-	PLACEHOLDER = Entry.new('/', 'placeholder')
+class Directory
+	@@filter = nil
 
 	def initialize(path, allow_delay=false)
 		@path = path
 		@pos = 0
-		@files = [PLACEHOLDER]
+		@files = []
 		@file_size = 0
 		@pointed_file = nil
 		@width = 1000
@@ -157,13 +19,18 @@ class Directory
 
 	def read_dir
 		@mtime = File.mtime(@path)
-		@files = Dir.new(@path).to_a
+		log @path
+		@files = Dir.new(@path).to_a rescue []
 		if OPTIONS['hidden']
 			@files -= ['.', '..', 'lost+found']
 		else
 			@files.reject!{|x| x[0] == ?. or x == 'lost+found'}
 		end
 
+		if @@filter
+			@files.reject!{|x| x !~ @@filter}
+		end
+
 		if @files.empty?
 			@files = ['.']
 		end
@@ -176,6 +43,11 @@ class Directory
 					:file_size, :read)
 	attr_accessor(:scheduled)
 
+	def self.filter=(x)
+		@@filter = Regexp.new(x, Regexp::IGNORECASE) rescue nil
+	end
+	def self.filter() @@filter end
+
 	def scheduled?() @scheduled end
 	def read?() @read end
 
diff --git a/code/entry.rb b/code/entry.rb
new file mode 100644
index 00000000..f2871847
--- /dev/null
+++ b/code/entry.rb
@@ -0,0 +1,140 @@
+require 'code/directory'
+
+class Directory::Entry
+	# Let's just cache every shit, because i don't want
+	# 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)
+	
+	def initialize(dirname, basename=nil)
+		if basename
+			@path = File.join(dirname, basename)
+			@dirname = dirname
+			@basename = basename
+		else
+			@path = dirname
+			@dirname = File.dirname(dirname)
+			@basename = File.basename(dirname)
+		end
+		@name, @ext = @basename.split_at_last_dot
+#			@ext = @basename.from_last('.') || ''
+		@movie = MOVIE_EXTENSIONS.include?(@ext)
+		@size = 0
+		@exists = false
+		@rights = '----------'
+		@readlink = ''
+		@symlink = false
+		@writable = false
+		@infostring = ''
+		@executable = false
+		@type = :nonexistent
+		@mtime = BAD_TIME
+		@ctime = BAD_TIME
+		@marked = false
+	end
+
+	attr_reader(*%w{
+		basename mtime rights type path ext
+		infostring readlink basename size ctime name
+	})
+
+	attr_accessor(:marked)
+	
+	def to_s() @path end
+	def exists?() @exists end
+	def marked?() @marked end
+	def symlink?() @symlink 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]
+		end
+	end
+
+	def delete!
+		if @type == :dir
+			Dir.delete(@path) rescue nil
+		else
+			File.delete(@path) rescue nil
+		end
+	end
+
+	def refresh
+		if File.exists?(@path)
+			if File.ctime(@path) != @ctime
+				get_data
+			end
+		else
+			get_data
+		end
+	end
+
+	def sh
+		@path.sh
+	end
+
+	def in? path
+		to_s[0, path.size] == path
+	end
+
+	def get_data
+		@size = 0
+		@infostring = ''
+
+		@exists = File.exists?(@path)
+		if @exists
+			@writable = File.writable?(@path)
+			@symlink = File.symlink?(@path)
+			if @symlink
+				@readlink = File.readlink(@path)
+			end
+			if File.directory?(@path)
+				@type = :dir
+				begin
+					sz = Dir.entries(@path).size - 2
+					@size = sz
+				rescue
+					sz = "?"
+				end
+				@infostring << "#{sz}"
+			elsif File.socket?(@path)
+				@type = :socket
+			else
+				@type = :file
+				@size = File.size(@path)
+				if File.size?(@path)
+					@infostring << " #{File.size(@path).bytes 2}"
+				else
+					@infostring << ""
+				end
+			end
+			@rights = File.modestr(@path)
+			@executable = File.executable?(@path)
+			@mtime = File.mtime(@path)
+			@ctime = File.ctime(@path)
+
+		else
+			if File.symlink?(@path)
+				@readlink = File.readlink(@path) rescue nil
+				@infostring = '->'
+				@symlink = true
+			else
+				@symlink = false
+			end
+			@executable = false
+			@writable = false
+			@type = :nonexistent
+			@rights = '----------'
+			@mtime = BAD_TIME
+			@ctime = BAD_TIME
+		end
+	end
+end