Class: Sh::Global

Inherits:
Object show all
Defined in:
lib/sh_global.rb

Constant Summary collapse

SUPPORTED_EXTENSIONS =
%w{.mp3 .m4a .ogg .oga .flac .wma .wav}
GLADE =
{}
PATHS =
{}

Class Method Summary collapse

Class Method Details

.initObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/sh_global.rb', line 20

def self.init
	# Setup some commonly used directories
  PATHS[:home_dir] = home_dir = GLib.home_dir
  PATHS[:config_dir] = config_dir = "#{home_dir}/.shroom"
  FileUtils.mkdir config_dir unless File.exists? config_dir
  PATHS[:cover_dir] = cover_dir = "#{config_dir}/covers"
  FileUtils.mkdir cover_dir unless File.exists? cover_dir
  # Store paths to relevant Shroom files
  PATHS[:prefs_file] = "#{config_dir}/preferences.yml"
  PATHS[:plugin_prefs_file] = "#{config_dir}/plugin_prefs.yml"
  PATHS[:db_file] = "#{config_dir}/songs.db"
  PATHS[:log_file] = log_file = "#{config_dir}/shroom.log"
  PATHS[:playlists_file] = "#{config_dir}/playlists.yml"

			# Set default preferences
  @@prefs = {
    :library_dir => "#{home_dir}/Music",
    :cover_art => true,
    :lyrics => true
  }
  
  # Load saved preferences
  load_prefs
  
  # Set log outputs
  Sh::Log.add_output_stream :stdout
  Sh::Log.add_output_stream open(log_file, "w")

			# Parse Glade interface
  add_toplevel_glade('dlg_preferences')
  add_toplevel_glade('dlg_song')
  add_toplevel_glade('dlg_plugins')
  GLADE.freeze

			# Initialize plugins
  Plugin.init
  load_plugins
end

.load_pluginsObject

Search for Shroom plugins and load them



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/sh_global.rb', line 86

def self.load_plugins
  plugin_dirs = ["#{self.locate("plugins")}", "#{PATHS[:config_dir]}/.plugins"]
  plugin_dirs.each do |dir|
    Dir["#{dir}/*.rb"].each do |rb_file|
      begin
        require rb_file
      rescue Exception
      	Sh::Log.warning "Error loading plugin \"#{rb_file}\"", $!
      end
    end
  end
end

.load_prefsObject

Set current preferences to those in the preferences file



69
70
71
72
73
74
75
76
# File 'lib/sh_global.rb', line 69

def self.load_prefs
  if File.exists?(PATHS[:prefs_file])
    prefs = YAML::load(File.read(PATHS[:prefs_file]))
    prefs.each do |k, v|
      @@prefs[k] = v
    end
  end
end

.locate(file) ⇒ Object



59
60
61
62
# File 'lib/sh_global.rb', line 59

def self.locate(file)
  signpost = find_in_load_path(File.join("res", "shroom_resources_signpost"))
  return Pathname.new(signpost).dirname.join(file).expand_path.to_s if signpost
end

.prefsObject



64
65
66
# File 'lib/sh_global.rb', line 64

def self.prefs
  return @@prefs
end

.save_prefsObject

Store current preferences in the preferences file



79
80
81
82
83
# File 'lib/sh_global.rb', line 79

def self.save_prefs
  File.open(PATHS[:prefs_file], 'w') do |f|
    f.write @@prefs.to_yaml
  end
end