rwddemo 0.90 → 0.91

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/Readme.txt +25 -6
  2. data/code/{rwdcalc → superant.com.rwdcalc}/ca2multiply.rb +0 -0
  3. data/code/{rwdcalc → superant.com.rwdcalc}/changescriptname.rb +0 -0
  4. data/code/superant.com.rwdcalc/clearrubyscriptscreendisplay.rb +9 -0
  5. data/code/{rwdcalc → superant.com.rwdcalc}/clearscriptscreendisplay.rb +0 -0
  6. data/code/{rwdcalc → superant.com.rwdcalc}/deletescriptrecord.rb +0 -0
  7. data/code/{rwdcalc → superant.com.rwdcalc}/fadd.rb +0 -0
  8. data/code/{rwdcalc → superant.com.rwdcalc}/frwdcleartape.rb +0 -0
  9. data/code/{rwdcalc → superant.com.rwdcalc}/frwddivide.rb +0 -0
  10. data/code/{rwdcalc → superant.com.rwdcalc}/frwdmultiply.rb +0 -0
  11. data/code/{rwdcalc → superant.com.rwdcalc}/frwdsubtract.rb +0 -0
  12. data/code/{rwdcalc → superant.com.rwdcalc}/helptexthashrwdcalc.rb +0 -0
  13. data/code/{rwdcalc → superant.com.rwdcalc}/listscripts.rb +0 -0
  14. data/code/superant.com.rwdcalc/loadrubyrecord.rb +20 -0
  15. data/code/{rwdcalc → superant.com.rwdcalc}/loadscriptrecord.rb +0 -0
  16. data/code/{rwdcalc → superant.com.rwdcalc}/mathcommands.rb +0 -0
  17. data/code/{rwdcalc → superant.com.rwdcalc}/openhelpwindowrwdcalc.rb +0 -0
  18. data/code/{rwdcalc → superant.com.rwdcalc}/playscript.rb +1 -1
  19. data/code/{rwdcalc → superant.com.rwdcalc}/renamecalcrecord.rb +0 -0
  20. data/code/{rwdcalc → superant.com.rwdcalc}/runrwdcalcwindow.rb +0 -0
  21. data/code/{rwdcalc → superant.com.rwdcalc}/rwdadd.rb +0 -0
  22. data/code/{rwdcalc → superant.com.rwdcalc}/rwdcleartape.rb +0 -0
  23. data/code/{rwdcalc → superant.com.rwdcalc}/rwddivision.rb +0 -0
  24. data/code/{rwdcalc → superant.com.rwdcalc}/rwdsubtraction.rb +0 -0
  25. data/code/{rwdcalc → superant.com.rwdcalc}/savechangedscript.rb +0 -0
  26. data/code/superant.com.rwdcalc/saverubyscript.rb +20 -0
  27. data/code/{rwdcalc → superant.com.rwdcalc}/viewscript.rb +0 -0
  28. data/code/superant.com.rwdshell/helptexthashshell.rb +24 -0
  29. data/code/superant.com.rwdshell/loadconfigurationrecord.rb +2 -2
  30. data/code/superant.com.rwdshell/openhelpwindowshell.rb +27 -0
  31. data/code/superant.com.rwdshell/playrubyscript.rb +2 -1
  32. data/code/superant.com.rwdshell/playscript.rb +2 -1
  33. data/code/superant.com.rwdshell/shelleval.rb +1 -1
  34. data/code/superant.com.rwdtinkerbackwindow/helptexthashtinkerwin2.rb +4 -1
  35. data/code/superant.com.rwdtinkerbackwindow/installapplet.rb +5 -3
  36. data/code/superant.com.rwdtinkerbackwindow/removeapplet.rb +10 -6
  37. data/configuration/language.cnf +3 -1
  38. data/configuration/language.dist +7 -0
  39. data/configuration/rwdapplicationidentity.cnf +2 -2
  40. data/configuration/rwdapplicationidentity.dist +3 -0
  41. data/configuration/rwdcalc.cnf +5 -2
  42. data/configuration/rwdcalc.dist +7 -0
  43. data/configuration/rwdcalendar.cnf +7 -1
  44. data/configuration/rwdcalendar.dist +10 -0
  45. data/configuration/rwdshell.cnf +3 -0
  46. data/configuration/rwdshell.dist +3 -0
  47. data/configuration/rwdtinker.cnf +3 -4
  48. data/configuration/rwdtinker.dist +15 -0
  49. data/configuration/tinkerwin2variables.cnf +6 -1
  50. data/configuration/tinkerwin2variables.dist +17 -0
  51. data/extras/cmdline_parse +47 -0
  52. data/extras/config_file +69 -0
  53. data/extras/errorMsg +19 -0
  54. data/extras/icalendar.rb +18 -0
  55. data/extras/makePlaylist +34 -0
  56. data/extras/mp3controld +289 -0
  57. data/extras/playlist +186 -0
  58. data/extras/rconftool.rb +380 -0
  59. data/extras/showHelp +18 -0
  60. data/gui/00coreguibegin/applicationguitop.rwd +1 -1
  61. data/gui/frontwindow0/{superant.com.tinkercalendar → superant.com.rwdcalendar}/hl9calendar.rwd +0 -0
  62. data/gui/frontwindow0/superant.com.shellscripts/1listplayscripts.rwd +1 -1
  63. data/gui/frontwindow0/superant.com.shellscripts/2listscripts.rwd +2 -2
  64. data/gui/frontwindow0/superant.com.shellscripts/6rwdshelleval.rwd +3 -4
  65. data/gui/frontwindowtdocuments/superant.com.shelldocument/vvdocshellxp.rwd +1 -0
  66. data/gui/tinkerbackwindows/superant.com.rwdshellbackwindow/46editscriptrecord.rwd +5 -5
  67. data/init.rb +42 -37
  68. data/rwd_files/HowTo_RwdCalc.txt +110 -0
  69. data/rwd_files/HowTo_Shell.txt +14 -1
  70. data/rwd_files/HowTo_Tinker.txt +16 -0
  71. data/rwdconfig.cnf +6 -0
  72. data/rwdconfig.dist +6 -0
  73. data/scripts/test02.rb +1 -1
  74. data/tests/checkdepends.sh +4 -0
  75. data/tests/cleancnf.sh +5 -0
  76. data/tests/makedist.rb +29 -0
  77. data/tests/rdep.rb +354 -0
  78. metadata +62 -48
  79. data/code/superant.com.rwdshell/helptexthashrubyslippers.rb +0 -81
  80. data/code/superant.com.rwdshell/openhelpwindowrubyslippers.rb +0 -50
  81. data/configuration/playscripts.cnf +0 -2
  82. data/configuration/rwdcalcversion.cnf +0 -2
  83. data/configuration/rwdcalendarversion.cnf +0 -4
  84. data/configuration/rwdshellversion.cnf +0 -2
  85. data/configuration/rwdtinkerversion.cnf +0 -2
  86. data/configuration/tinkerwin2version.cnf +0 -3
  87. data/installed/rwdtinkerwin2-0.5.inf +0 -8
  88. data/lang/alanguagehashbegin.rb +0 -4
  89. data/lang/languagehash.rb +0 -4
  90. data/lang/templangfile.rb +0 -22
  91. data/lang/vlanguagehashend.rb +0 -6
  92. data/lang/wlocallangstart.rb +0 -5
  93. data/lang/xlocallangfile.rb +0 -22
  94. data/lang/zlocallangend.rb +0 -2
  95. data/rwddemo-0.90.gem +0 -0
@@ -0,0 +1,15 @@
1
+ ##VERSION:1.58
2
+ ConfigurationDir = "configuration" # for use in program - init.rb has this value without using this constant
3
+ CodeName = "rwdtinker"
4
+ CodeNameFile = CodeName + ".rb"
5
+ RWDFile = "rwdtinker.rwd"
6
+ LangDir = "lang"
7
+ CodeDir = "code"
8
+ GuiDir = "gui"
9
+ $help_topic = "general_help"
10
+ $helptopicsarray = [ "general_help","network_help"]
11
+ $prevouswindow ="main"
12
+ $rwdcontrolports =["13713","13714","13715","13716","13717","13718"]
13
+ $port = 7705
14
+
15
+ RwdTinkerVersion = "1.58"
@@ -1,12 +1,17 @@
1
-
1
+ ##VERSION:1.57
2
2
  TinkerWin2ConfigurationFileName = "tinkerwin2variables.cnf" # this file name - do not change
3
+ ##NAME: $zipslocation:0
3
4
  $zipslocation = "zips" # location of applets to add
4
5
  $zipsarray = [""] ; $zipsarraylocal = [""]
6
+ ##NAME: $xpcommand:0
5
7
  $xpcommand = " " # Linux machines
6
8
  # $xpcommand = "cmd /C " # XP machines with cmd shell
9
+ ##NAME: $gemdirectory_withgemfiles:0
7
10
  $gemdirectory_withgemfiles = "/usr/lib/ruby/gems/1.8/gems"
8
11
  # $gemdirectory_withgemfiles = "c:\\ruby\\lib\\ruby\\gems\\1.8\\gems" # XP machine
12
+ ##NAME: $geminstalled_directory:0
9
13
  # $geminstalled_directory = "/ruby/lib/ruby/gems/1.8/gems" # XP machine
10
14
  $geminstalled_directory = "/usr/lib/ruby/gems/1.8/gems" # Debian Linux
11
15
 
16
+ RwdTinkerWin2Version = "0.8"
12
17
 
@@ -0,0 +1,17 @@
1
+ ##VERSION:1.57
2
+ TinkerWin2ConfigurationFileName = "tinkerwin2variables.cnf" # this file name - do not change
3
+ ##NAME:$zipslocation:0
4
+ $zipslocation = "zips" # location of applets to add
5
+ $zipsarray = [""] ; $zipsarraylocal = [""]
6
+ ##NAME:$xpcommand:0
7
+ $xpcommand = " " # Linux machines
8
+ # $xpcommand = "cmd /C " # XP machines with cmd shell
9
+ ##NAME:$gemdirectory_withgemfiles:0
10
+ $gemdirectory_withgemfiles = "/usr/lib/ruby/gems/1.8/gems"
11
+ # $gemdirectory_withgemfiles = "c:\\ruby\\lib\\ruby\\gems\\1.8\\gems" # XP machine
12
+ ##NAME:$geminstalled_directory:0
13
+ # $geminstalled_directory = "/ruby/lib/ruby/gems/1.8/gems" # XP machine
14
+ $geminstalled_directory = "/usr/lib/ruby/gems/1.8/gems" # Debian Linux
15
+
16
+ RwdTinkerWin2Version = "0.8"
17
+
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/ruby
2
+ # --- Parse command line ---
3
+ #
4
+ # Author: Magnus Engstr�m
5
+ # Email: magnus@gisab.se
6
+ # File: cmdline_parse
7
+ #
8
+ # Description
9
+ # -----------
10
+ # Parses the commandline and
11
+ # returns a hash with the
12
+ # switch as key and the
13
+ # value as value :)
14
+ # --------------------------
15
+
16
+ class Commandline
17
+ def Commandline::parse()
18
+
19
+ params = Hash::new() # Could be useful to have something to put the commandline in ;)
20
+ key = false # Just a really ugly hack to keep track on if we're reading key or value
21
+ foo = '' # Keeps the key name
22
+
23
+ # Iterate through the command line ($*) and put it in the params hash
24
+ $*.each { |param|
25
+ key = ( key == true ? false : true ) # Negate the value of key
26
+ if(key)
27
+ foo = param
28
+ else
29
+ params[foo] = param
30
+ end
31
+ }
32
+
33
+ # Validate the command line.
34
+ # Every key should begin with at least one '-' and have a value
35
+ if( !key ) # If key equals true, then the user should enter one more parameter
36
+ passed = true
37
+ params.each { |key, value| # Iterate through all parameters
38
+ passed = false if(key[0].chr() != '-') # Doesn't it start with a '-'? Not passed...
39
+ passed = false if(value == '') # I really want a value here, not just an empty string
40
+ }
41
+ end
42
+
43
+ # Return params if check passed, else return -1
44
+ passed ? params : -1
45
+
46
+ end
47
+ end
@@ -0,0 +1,69 @@
1
+ #!ruby
2
+ require 'ftools'
3
+ require 'tempfile'
4
+
5
+ class ConfigFile
6
+
7
+ def ConfigFile::parse(filename)
8
+ # Make sure this file exists and is readable
9
+ if( FileTest::readable_real?(filename) )
10
+ new(filename) # Return the class instance
11
+ else
12
+ -1 # Return -1 on failure
13
+ end
14
+ end
15
+
16
+ def initialize(filename)
17
+ @filename = filename
18
+ @config = Hash::new() # The class internal variable that holds the config data
19
+ section = ''
20
+
21
+ # Parse the configuration file (and in only TWO rows, God I love Ruby! =)
22
+ IO::foreach(@filename) { |configLine| @config[section = $1] = Hash::new() if(configLine.gsub(/\s*#.*$/, '') =~ /\s*(\S+)\s*\{/)
23
+ @config[section].update({$1 => $2}) if(configLine.gsub(/\s*#.*$/, '') =~ /\s*(\S+)\s*=\s*(.*)/) }
24
+ end
25
+
26
+ # Return the requested parameter
27
+ def getParam(section, parameter)
28
+ @config[section][parameter] if(@config[section].type == Hash)
29
+ end
30
+
31
+ # Set the provided parameter
32
+ def setParam(section, parameter, value)
33
+ # Create a temp file
34
+ temp = Tempfile::new('config')
35
+
36
+ current_section = ''
37
+ # Loop through the config file
38
+ IO::foreach(@filename) { |line|
39
+ current_section = $1 if( line =~ /^\s*(\S+)\s*{\s*(#.*)?$/ ) # Handle the section stuff
40
+ # Is this a correct parameter entry?
41
+ if( line =~ /^\s*(\S+)\s*=\s*\S+\s*(#.*)?$/ )
42
+
43
+ if( current_section == section && $1 == parameter ) # This is the line we want to change!
44
+ line.gsub!( /^(\s*\S+\s*=\s*)\S+(\s*(#.*)?)$/, "\\1#{value}\\2" ) # Change the parameter value to the one the user supplied
45
+ end
46
+
47
+ end
48
+
49
+ temp.puts(line) # Write the line to the tempfile
50
+ }
51
+
52
+ temp.close() # Close the file
53
+ File::copy(temp.path, @filename) # Copy the tempfile to overwrite the old one
54
+ temp.close(true) # Remove the file
55
+ end
56
+
57
+ # Loop through all sections
58
+ def each_section()
59
+ @config.each { |key,value| yield(key) }
60
+ end
61
+
62
+ # Loop through all parameters in a section
63
+ def each_parameter(section)
64
+ @config[section].each { |key,value| yield(key) }
65
+ end
66
+
67
+ attr_reader :filename
68
+
69
+ end
@@ -0,0 +1,19 @@
1
+ #!ruby
2
+
3
+ # --- errorMsg ---
4
+ #
5
+ # Author: Magnus Engstr�m
6
+ # Email: magnus@gisab.se
7
+ # File: errorWrite
8
+ #
9
+ # Description
10
+ # -----------
11
+ # Outputs an error message to the administrator
12
+ # ------------------
13
+
14
+ def errorMsg(message, exitapp = false)
15
+ STDERR.puts(message)
16
+ MP3Control::exit_mpg123() if(exitapp)
17
+ Kernel::exit(exitapp) if(exitapp) # Terminate application and return the exitapp value if it isn't falsew
18
+
19
+ end
@@ -0,0 +1,18 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ # Base classes and mixin modules
4
+ require 'icalendar/base'
5
+ require 'icalendar/component'
6
+ require 'icalendar/helpers'
7
+
8
+ # Calendar and components
9
+ require 'icalendar/calendar'
10
+ require 'icalendar/component/event'
11
+ require 'icalendar/component/journal'
12
+ require 'icalendar/component/todo'
13
+ require 'icalendar/component/freebusy'
14
+ require 'icalendar/component/timezone'
15
+ require 'icalendar/component/alarm'
16
+
17
+ # Calendar parser
18
+ require 'icalendar/calendar_parser'
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/ruby
2
+ require 'mp3tag'
3
+
4
+ def getList(dir)
5
+ Dir::chdir(dir)
6
+
7
+ # Find the files in this directory
8
+ Dir['*mp3'].each { |file|
9
+ if(FileTest::file?(file))
10
+ mp3tag = Mp3Tag::new(Dir::getwd()+"/"+file)
11
+ if(mp3tag.songname.length > 0)
12
+ puts("#{Dir::getwd()+"/"+file}||#{mp3tag.songname}||#{mp3tag.artist}||#{mp3tag.album}||#{mp3tag.year}||#{mp3tag.comment}||#{mp3tag.tracknum}||#{mp3tag.genre_id}||#{mp3tag.genre}")
13
+ else
14
+ name = Dir::getwd()+"/"+file
15
+ name =~ /([^\/]+)\.mp3$/
16
+ puts("#{Dir::getwd()+"/"+file}||#{$1}||#{mp3tag.artist}||#{mp3tag.album}||#{mp3tag.year}||#{mp3tag.comment}||#{mp3tag.tracknum}||#{mp3tag.genre_id}||#{mp3tag.genre}")
17
+ end
18
+ end
19
+ }
20
+
21
+ Dir['*'].each { |entry|
22
+ if(FileTest::directory?(entry))
23
+ getList(entry)
24
+ end
25
+ }
26
+ Dir::chdir('..')
27
+ end
28
+
29
+ # Change current directory to user supplied one
30
+ Dir::chdir(ARGV[0])
31
+ getList(ARGV[0])
32
+
33
+ #song = Mp3Tag::new(ARGV[0])
34
+ #puts song.songname()
@@ -0,0 +1,289 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # --- MP3 Control ---
4
+ #
5
+ # Author: Magnus Engstr�m
6
+ # Email: magnus@gisab.se
7
+ # File: mp3controld
8
+ #
9
+ # Description
10
+ # -----------
11
+ # An application which manages
12
+ # mp3 songs on the poor users
13
+ # computer.
14
+ # -------------------------
15
+
16
+ # --- External files ---
17
+ # Change directory to find all functions
18
+ #Dir::chdir("/usr/lib/mp3control")
19
+
20
+ load "extras/config_file" # Handles the mp3controld.conf configuration file
21
+ load "extras/cmdline_parse" # Provides the Commandline::parse which returns an hash of the commandline
22
+ load "extras/showHelp" # Hmmm... guess what? This function shows the help message =)
23
+ load "extras/errorMsg" # Outputs error messages to the admin
24
+ load "extras/playlist" # Core playlist functionality
25
+
26
+ # --- MP3Control - the main class ---
27
+ class MP3Control
28
+ # --- Core functions ---
29
+ # initialize() reads the config files and daemonizes!
30
+ def initialize()
31
+ # Parse the commandline
32
+ $commandline = Commandline::parse()
33
+
34
+ # Display help if the commandline sucks
35
+ if($commandline == -1)
36
+ showHelp()
37
+ Kernel::exit(-1)
38
+ end
39
+
40
+ # Make this class instance a background daemon
41
+ daemonize() if($commandline["--daemon"] != 'no' && $commandline["-D"] != 'no')
42
+
43
+ # Read the configuration file
44
+ configfile = ( $commandline["--configfile"] ? $commandline["--configfile"] : 'configuration/mp3controld.conf' ) # Use the --configfile if supplied, else use the default /etc/mp3controld/mp3controld.conf
45
+ $configFile = ConfigFile::parse(configfile) # Create an new config file object
46
+ errorMsg("Configuration file #{configfile} isn't readable or doesn't exist!", 137) if($configFile == -1)
47
+
48
+ # Find the default playlist (or use the user supplied one from the commandline)
49
+ defaultPlaylist = $configFile.getParam("programConfig", "defaultPlaylist")
50
+ defaultPlaylist = $commandline["--playlist"] if($commandline["--playlist"])
51
+ if( $configFile.getParam(defaultPlaylist, 'listFile').type == String) # Make sure the listFile contains a value
52
+ if(FileTest.readable_real?( $configFile.getParam(defaultPlaylist, 'listFile') )) # Make sure this file is readable
53
+ # Cool. Everything looks alright. Lets create a playlist!
54
+ errorMsg("Loading playlist '#{defaultPlaylist}' from #{$configFile.getParam(defaultPlaylist, 'listFile')}...") if($commandline['--verbose'] == 'on')
55
+ $current_playlist = Playlist::create_from_file($configFile.getParam(defaultPlaylist, 'listFile'))
56
+ $current_playlist_name = defaultPlaylist
57
+
58
+ # Errorhandling
59
+ errorMsg("Playlist creation from #{$current_playlist.filename} failed.", 1) if($current_playlist == -1) # Quit and complain if it didn't work
60
+ errorMsg("Playlist #{defaultPlaylist} (#{$current_playlist.filename}) doesn't contain any entries.", 1) if($current_playlist.length() < 1)
61
+ errorMsg("Playlist '#{defaultPlaylist}' loaded successfully.") if($commandline["--verbose"] == 'on')
62
+
63
+ # Fix wrap/repeat and shuffle the playlist if the configfile says so
64
+ $current_playlist.wrap = true if($configFile.getParam(defaultPlaylist, 'repeat') == 'true')
65
+ $current_playlist.shuffle() if($configFile.getParam(defaultPlaylist, 'random') == 'true')
66
+ $current_playlist.goto(0) # Rewind the playlist
67
+ else
68
+ errorMsg("The default playlist doesn't appear to exist, or has the wrong permissions. That's not good.", 1)
69
+ end
70
+ else # listFile returns other than string, that's baaaaad
71
+ errorMsg("the listFile value for '#{defaultPlaylist}' doesn't appear to exist in your #{$configFile.filename}. That's not good.", 1)
72
+ end
73
+
74
+ # Check for the existence of our mpg123 instance
75
+ errorMsg("Trying to find the mp3 player...") if($commandline["--verbose"] == 'on')
76
+ @mpg123 = $configFile.getParam('programConfig', 'application') # Get the application name, path, and possible arguments
77
+ mpg123_application = @mpg123.scan(/^\S+/)
78
+ if(mpg123_application.type == Array)
79
+ mpg123_application = mpg123_application[0]
80
+ else
81
+ errorMsg("Please check your ProgramConfig/application setting in the configuration file. It seems weird.", 1)
82
+ end
83
+
84
+ # Do some nice errorhandling
85
+ if( !FileTest::executable_real?(mpg123_application) )
86
+ errorMsg("#{mpg123_application} doesn't appear to exist. Please do something about it (no, not \"touch #{mpg123_application}\"! Stupid!).", 1)
87
+ else
88
+ errorMsg("Found #{mpg123_application}!") if($commandline["--verbose"] == 'on')
89
+ end
90
+
91
+ # Open an instance of mpg123, our high-performance mp3 player
92
+ @@mpg123 = IO::popen("#{@mpg123} -R -", 'r+')
93
+
94
+ # Start all plugins
95
+ load_plugins()
96
+
97
+ # Start the mp3 player
98
+ mpg123_control()
99
+
100
+ end
101
+
102
+ # mpg123_control() gets the input from the mpg123 process and handles it hopefully correctly :)
103
+ def mpg123_control()
104
+
105
+ # Initialize class variables
106
+ @@stopped = false
107
+
108
+ # Start playing if the configfile says so
109
+ if( $configFile.getParam('programConfig', 'playOnStartup') == 'true' )
110
+ MP3Control::play()
111
+ else
112
+ puts("Dont want to play!")
113
+ end
114
+
115
+ # The infinite 5 second loop =)
116
+ while(true)
117
+ begin
118
+ input = @@mpg123.readline.chop()
119
+ rescue EOFError
120
+ errorMsg("mpg123 error! Probably just a file that didn't exist (#{$current_playlist.song_info["filename"]}).")
121
+ @@mpg123 = IO::popen("#{@mpg123} -R -", 'r+') # Just start it again...
122
+ MP3Control::next_song() # Next song, so it doesn't die again...
123
+ end
124
+
125
+ # Song stopped
126
+ MP3Control::next_song() if(input == '@P 0' && @@stopped != true) # Change to the next song if current song stops and the user didn't told it to
127
+ @@stopped = false if(input == '@P 0' && @@stopped == true) # Reset the stop-flag if the user ordered the stop
128
+
129
+ # Time left
130
+ if(input[0,2] == '@F')
131
+ input =~ /^@F\s+\S+\s+\S+\s+(\S+)\s+(\S+)$/
132
+ @@time = $1
133
+ @@timeleft = $2
134
+ end
135
+
136
+ end
137
+ end
138
+
139
+ # start() creates a new instance. Just like .new, but a nicer name.
140
+ def MP3Control::start()
141
+ MP3Control::new()
142
+ end
143
+
144
+ # daemonize() daemonizes this process. Cool =)
145
+ def daemonize()
146
+ if(child_pid = fork) # Parent code
147
+ puts("PID #{child_pid}")
148
+ Kernel::exit(0) # We dont want this parent process any more. Too bad.
149
+ end
150
+
151
+ # Child code. And child wants to be free from parent
152
+ Process.setsid()
153
+ end
154
+
155
+ # load_plugins() loads all plugins that can be found in the plugins directory
156
+ def load_plugins()
157
+ Dir::entries('extras/plugins/').each { |plugin|
158
+ # Try to load every plugin except all files that begins with a dot
159
+ if(plugin[0].chr() != '.')
160
+ retval = 0
161
+ # Do some errorhandling
162
+ begin
163
+ load("extras/plugins/#{plugin}") # Load the files
164
+ errorMsg("Loaded plugin '#{plugin}'") if($commandline['--verbose'] == 'no')
165
+ rescue SyntaxError
166
+ errorMsg("Plugin '#{plugin}' has syntax errors.")
167
+ end
168
+
169
+ # Run the plugin in a separate thread
170
+ # Try to start the class with the same name as the plugin
171
+ eval("
172
+ Thread::new() {
173
+ start_again = true
174
+ while(start_again)
175
+ puts(\"Plugin starting...\")
176
+ begin
177
+ retval = #{plugin}::start()
178
+ rescue
179
+ error = $!
180
+ puts(error)
181
+ puts(error.backtrace)
182
+ puts(\"Error in plugin #{plugin}! Waiting for 5 seconds before attempting to start again...\")
183
+ sleep(5)
184
+ end
185
+ if(retval == -1)
186
+ errorMsg(\"Plugin 'plugins/#{plugin}' failed to load...\")
187
+ start_again = false
188
+ end
189
+ end
190
+ }
191
+ ")
192
+
193
+ end
194
+ }
195
+ end
196
+
197
+ # exit_mpg123() terminates the current mpg123 session
198
+ def MP3Control::exit_mpg123()
199
+ #system("kill `pidof mpg123`") # Yes, I know this isn't a nice way to do it in, please fix this and send me a patch :)
200
+ end
201
+
202
+ # mpg123_command() sends a command to mpg123
203
+ def MP3Control::mpg123_command(command)
204
+ errorMsg("mpg123 command: '#{command}'") if($commandline['--verbose'] == 'on')
205
+ @@mpg123.write("#{command}\n")
206
+ @@mpg123.flush()
207
+ end
208
+
209
+
210
+ # --- play functions ---
211
+ # play() plays the current index of the current playlist
212
+ def MP3Control::play()
213
+ @@stopped = false
214
+ mpg123_command("LOAD #{$current_playlist.song_info["filename"]}")
215
+ end
216
+
217
+ # stop() stops playing
218
+ def MP3Control::stop()
219
+ mpg123_command("PAUSE")
220
+ @@stopped = true # Set the stop-status to true
221
+ end
222
+
223
+ # pause() pauses playing
224
+ def MP3Control::pause()
225
+ @@stopped = false
226
+ mpg123_command("PAUSE")
227
+ end
228
+
229
+ # next_song() loads the next song. Yay...
230
+ def MP3Control::next_song()
231
+ retval = $current_playlist.next()
232
+ if(retval == -1)
233
+ errorMsg("Error while changing to the next song.") # Tell him/her
234
+ else
235
+ MP3Control::play() if(@@stopped == false)
236
+ end
237
+ end
238
+
239
+ # prev_song() loads the previous song. Yay...
240
+ def MP3Control::prev_song()
241
+ retval = $current_playlist.prev()
242
+ if(retval == -1)
243
+ errorMsg("Error while changing to the previous song.") # Tell him/her
244
+ else
245
+ MP3Control::play() if(@@stopped == false)
246
+ end
247
+ end
248
+
249
+ # forward(sec) jumps sec seconds forward
250
+ def MP3Control::forward(sec)
251
+ mpg123_command("JUMP +#{sec*38}")
252
+ end
253
+
254
+ # backward(sec) jumps sec seconds backward
255
+ def MP3Control::backward(sec)
256
+ mpg123_command("JUMP -#{sec*38}")
257
+ end
258
+
259
+
260
+ # --- Misc functions ---
261
+ # getTime() - Get the current song time information. getTime(true) for time left
262
+ def MP3Control::getTime(whichTime = 'elapsed')
263
+ case whichTime
264
+ when 'elapsed'
265
+ parsed = Time::at(@@time.to_i)
266
+ when 'left'
267
+ parsed = Time::at(@@timeleft.to_i)
268
+ when 'total'
269
+ parsed = Time::at( (@@time.to_f + @@timeleft.to_f).to_i )
270
+ end
271
+
272
+ hour = (parsed.hour - 1).to_s
273
+ min = parsed.min.to_s
274
+ sec = parsed.sec.to_s
275
+
276
+ hour = "0#{hour}" if(hour.length == 1)
277
+ min = "0#{min}" if(min.length == 1)
278
+ sec = "0#{sec}" if(sec.length == 1)
279
+
280
+ hour = (hour == '00' ? '' : "#{hour}:")
281
+
282
+ # Return the now formatted time
283
+ "#{hour}#{min}:#{sec}"
284
+ end
285
+
286
+ end
287
+
288
+ # Create an instance of the MP3Control class and start the application
289
+ MP3Control::start()