Module: Gnome::Wallpaper::Changer::Configuration::ClassMethods

Included in:
Gnome::Wallpaper::Changer::Configuration
Defined in:
lib/gnome-wallpaper-changer/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#activeObject Also known as: active?

Returns the value of attribute active.



26
27
28
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 26

def active
  @active
end

#filesObject

Returns the value of attribute files.



26
27
28
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 26

def files
  @files
end

#foldersObject

Returns the value of attribute folders.



26
27
28
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 26

def folders
  @folders
end

#intervalObject

Returns the value of attribute interval.



26
27
28
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 26

def interval
  @interval
end

#portObject

Returns the value of attribute port.



26
27
28
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 26

def port
  @port
end

Instance Method Details

#add_folder(folder) ⇒ Object



148
149
150
151
152
153
154
155
156
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 148

def add_folder folder
  if folders.find{ |f| f[:path] == folder }
    false
  else
    folders << { path: folder, excluded: [] }
    save!
    true
  end
end

#autostart_installed?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 192

def autostart_installed?
  File.exists? AUTOSTART
end

#current_configObject



56
57
58
59
60
61
62
63
64
65
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 56

def current_config
  {
    version: VERSION,
    port: self.port,
    interval: self.interval,
    active: self.active?,
    folders: self.folders,
    files: self.files
  }
end

#default_configObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 39

def default_config
  {
    interval: 60 * 10,
    port: 12345,
    active: false,
    folders: [ {
        path: ENV['HOME'] + '/Pictures',
        excluded: []
      }, {
        path: '/usr/share/backgrounds',
        excluded: []
      }
    ],
    files: [ ]
  }
end

#ensure_autostart_dir_existsObject



196
197
198
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 196

def ensure_autostart_dir_exists
  FileUtils.mkdir_p AUTOSTART_DIR unless File.exists?( AUTOSTART_DIR )
end

#exclude_all(folder) ⇒ Object



137
138
139
140
141
142
143
144
145
146
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 137

def exclude_all folder
  folder = folders.find { |f| f[:path] == folder }
  if folder
    folder[:excluded] = Updater.get_files_in_folder folder[:path]
    save!
    true
  else
    false
  end
end

#exclude_file(folder, file) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 124

def exclude_file folder, file
  # => basic sanity check...
  if File.dirname(file) == folder
    folder = folders.find { |f| f[:path] == folder }
    return false unless folder
    folder[:excluded] << file unless folder[:excluded].include?( file )
    save!
    true
  else
    false
  end
end

#include_all(folder) ⇒ Object



113
114
115
116
117
118
119
120
121
122
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 113

def include_all folder
  folder = folders.find { |f| f[:path] == folder }
  if folder
    folder[:excluded] = []
    save!
    true
  else
    false
  end
end

#include_file(folder, file) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 100

def include_file folder, file
  # => basic sanity check...
  if File.dirname(file) == folder
    folder = folders.find { |f| f[:path] == folder }
    return false unless folder
    folder[:excluded].delete file
    save!
    true
  else
    false
  end
end

#install_autostart!Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 163

def install_autostart!
  bin = begin
    require "rvm"
    wrapper = RVM.path + "/bin/" + RVM.current.environment_name + "_gnome-wallpaper-changer"
    if !File.exists? wrapper
      RVM.current.wrapper RVM.current.environment_name, RVM.current.environment_name, "gnome-wallpaper-changer"
    end
    wrapper
  rescue
    Gem.bindir( Gem.dir ) + '/gnome-wallpaper-changer'
  end
  puts "Detected bin: #{bin}"
  ensure_autostart_dir_exists
  File.open AUTOSTART, "w" do |io|
    io.puts "[Desktop Entry]"
    io.puts "Type=Application"
    io.puts "Terminal=false"
    io.puts "Name=Wallpaper Changer"
    io.puts "Comment=Periodically changes the Gnome wallpaper"
    io.puts "Exec=#{bin} --autostart"
  end
rescue Gem::GemNotFoundException => e
  puts "Cannot activate autostart with a development version"
end

#loadObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 74

def load
  
  unless Dir.exists?( CONFIG_DIR )
    FileUtils.mkdir_p CONFIG_DIR
  end

  config = if File.exists?( CONFIG_FILE )
    YAML.load File.read( CONFIG_FILE )
  else
    default_config
  end

  default_config.keys.each do |key|
    self.send "#{key}=".to_sym, config[key]
  end

  save unless File.exists?( CONFIG_FILE )

end

#remove_folder(folder) ⇒ Object



158
159
160
161
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 158

def remove_folder folder
  folders.reject! { |f| f[:path] == folder }
  save!
end

#reset!Object



67
68
69
70
71
72
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 67

def reset!
  if File.exists?( CONFIG_FILE )
    FileUtils.rm CONFIG_FILE
  end
  uninstall_autostart!
end

#save!Object



94
95
96
97
98
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 94

def save!
  File.open CONFIG_FILE, "w" do |io|
    io.write current_config.to_yaml
  end
end

#uninstall_autostart!Object



188
189
190
# File 'lib/gnome-wallpaper-changer/configuration.rb', line 188

def uninstall_autostart!
  FileUtils.rm AUTOSTART if autostart_installed?
end