Class: GnomeWallpaperSlideshow
- Inherits:
-
Object
- Object
- GnomeWallpaperSlideshow
- Defined in:
- lib/gnome-wallpaper-slideshow.rb
Overview
Represents an XML file defining a wallpaper slideshow in GNOME
Defined Under Namespace
Classes: Wallpaper
Instance Method Summary collapse
-
#add_wallpaper(wallpaper) ⇒ Object
Adds a new wallpaper to the slideshow.
-
#create_new_slideshow(filename = "slideshow.xml") ⇒ Object
Creates a new wallpaper slideshow.
-
#initialize(&block) ⇒ GnomeWallpaperSlideshow
constructor
Create a new GnomeWallpaperSlideshow.
-
#load_slideshow(filename) ⇒ Object
Loads an existing wallpaper slideshow.
-
#path(filename = nil) ⇒ Object
Gets or sets the path of the slideshow XML file.
-
#remove_wallpaper(filename) ⇒ Object
Removes a wallpaper from the slideshow.
-
#save_xml ⇒ Object
Generates and saves the slideshow XML to the current @path.
-
#start_time(time = nil) ⇒ Object
Gets or sets the start time of the slideshow.
-
#wallpapers ⇒ Object
Gets the list of wallpapers in this slideshow.
Constructor Details
#initialize(&block) ⇒ GnomeWallpaperSlideshow
Create a new GnomeWallpaperSlideshow
9 10 11 |
# File 'lib/gnome-wallpaper-slideshow.rb', line 9 def initialize(&block) instance_eval(&block) if block_given? end |
Instance Method Details
#add_wallpaper(wallpaper) ⇒ Object
Adds a new wallpaper to the slideshow
58 59 60 |
# File 'lib/gnome-wallpaper-slideshow.rb', line 58 def add_wallpaper(wallpaper) wallpapers << wallpaper end |
#create_new_slideshow(filename = "slideshow.xml") ⇒ Object
Creates a new wallpaper slideshow
17 18 19 |
# File 'lib/gnome-wallpaper-slideshow.rb', line 17 def (filename = "slideshow.xml") @path = Pathname.new filename end |
#load_slideshow(filename) ⇒ Object
Loads an existing wallpaper slideshow
23 24 25 26 27 28 29 30 |
# File 'lib/gnome-wallpaper-slideshow.rb', line 23 def (filename) @path = Pathname.new filename # Load the content from the XML doc load_start_time load_wallpapers end |
#path(filename = nil) ⇒ Object
Gets or sets the path of the slideshow XML file
44 45 46 47 48 |
# File 'lib/gnome-wallpaper-slideshow.rb', line 44 def path(filename = nil) return @path unless filename @path = Pathname.new filename end |
#remove_wallpaper(filename) ⇒ Object
Removes a wallpaper from the slideshow
64 65 66 67 68 |
# File 'lib/gnome-wallpaper-slideshow.rb', line 64 def remove_wallpaper(filename) wallpapers.delete_if do |wallpaper| wallpaper.filename == filename end end |
#save_xml ⇒ Object
Generates and saves the slideshow XML to the current @path
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/gnome-wallpaper-slideshow.rb', line 71 def save_xml return "" if start_time.nil? or wallpapers.none? builder = Nokogiri::XML::Builder.new do |xml| xml.background { # The start time comes first xml.starttime { xml.year start_time.year xml.month start_time.month xml.day start_time.day xml.hour start_time.hour xml.minute start_time.min xml.second start_time.sec } # Transitions are in pairs of wallpapers wallpapers.each_cons(2) do |transition| # The static tag defines a wallpaper and how long it is displayed xml.static { xml.duration transition.first.duration xml.file transition.first.filename } # The transition tag defines how long the transition between this and the next takes xml.transition { xml.duration transition.first.transition_time xml.from transition.first.filename xml.to transition.last.filename } end # Now insert the last wallpaper and the transition back to the beginning xml.static { xml.duration wallpapers.last.duration xml.file wallpapers.last.filename } xml.transition { xml.duration wallpapers.last.transition_time xml.from wallpapers.last.filename xml.to wallpapers.first.filename } } end write_xml builder.to_xml end |
#start_time(time = nil) ⇒ Object
Gets or sets the start time of the slideshow
35 36 37 38 39 |
# File 'lib/gnome-wallpaper-slideshow.rb', line 35 def start_time(time = nil) return @start_time unless time @start_time = time end |
#wallpapers ⇒ Object
Gets the list of wallpapers in this slideshow
52 53 54 |
# File 'lib/gnome-wallpaper-slideshow.rb', line 52 def wallpapers return @wallpapers = @wallpapers || [] end |