home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / python2.4 / site-packages / serpentine / services.py < prev    next >
Encoding:
Python Source  |  2006-08-23  |  3.4 KB  |  116 lines

  1. # Copyright (C) 2004 Tiago Cogumbreiro <cogumbreiro@users.sf.net>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. #
  17. # Authors: Tiago Cogumbreiro <cogumbreiro@users.sf.net>
  18.  
  19. import dbus, nautilusburn
  20.  
  21. import mastering
  22. SERVICE_DOMAIN = "de.berlios.Serpentine"
  23. OBJECT_DOMAIN = "/de/berlios/Serpentine"
  24.  
  25.  
  26. class Manager (dbus.Object):
  27.     """Provides services for Serpentine. It launches all needed services.
  28.     It registers the de.berlios.Serpentine.Manager, 
  29.     de.berlios.Serpentine.Playlist and de.berlios.Serpentine.Recorder
  30.     interfaces.
  31.     """
  32.     def __init__ (self, service, serpentine_object):
  33.         dbus.Object.__init__ (self,
  34.                               OBJECT_DOMAIN + "/Manager",
  35.                               service, [
  36.             self.Quit,
  37.             self.RecordPlaylist
  38.         ])
  39.         self.__serp = serpentine_object
  40.         # Register the Playlist
  41.         self.__playlist = Playlist (OBJECT_DOMAIN + "/Playlist", self.serpentine.masterer.source)
  42.         self.__update_drives ()
  43.     
  44.     def __update_drives (self):
  45.         self.__drives = {}
  46.         for dev in nautilusburn.get_drives_list (True):
  47.             device = dev.get_device ()
  48.             self.__drives[device] = Recorder (serpentine_object, device)
  49.     
  50.     serpentine = property (lambda self: self.__serp)
  51.     playlist = property (lambda self: self.__playlist)
  52.     
  53.     def Quit (self, message):
  54.         self.serpentine.quit ()
  55.     
  56.     def RecordPlaylist (self, message):
  57.         self.serpentine.burn ()
  58.     
  59.  
  60. class Playlist (dbus.Object):
  61.     """Represents the serpentine storage."""
  62.     def __init__ (self, domain, service, music_list):
  63.         dbus.Object.__init__ (self,
  64.                               domain,
  65.                               service, [
  66.             self.Clear,
  67.             self.Remove,
  68.             self.Add
  69.         ])
  70.         self.__music_list = music_list
  71.         
  72.     music_list = property (lambda self: self.__music_list)
  73.     
  74.     def Clear (self, message):
  75.         self.music_list.clear ()
  76.         
  77.     def Remove (self, message, music):
  78.         for music in self.music_list:
  79.             if music['location'] == music:
  80.                 music_list.remove (music)
  81.                 return
  82.  
  83.     def Add (self, message, music):
  84.         hints = {"location": music}
  85.         add_oper = mastering.AddFile (self.music_list, hints)
  86.         # TODO: add a listener and a signal event for this
  87.         add_oper.start ()
  88.  
  89.  
  90. class AudioRecorder (dbus.Object):
  91.     """Represents a recorder that can write audio tracks directly."""
  92.     def __init__ (self, domain, device):
  93.         if device.startswith ("/"):
  94.             name = device[1:].replacewith ("/", ".")
  95.         
  96.         dbus.Object.__init__ (self,
  97.                               domain + "/" + name,
  98.                               "de.berlios.Serpentine.AudioRecorder", [
  99.             self.WriteFiles,
  100.             self.IsRecording,
  101.             self.GetDevice
  102.         ])
  103.         
  104.         self.__device = device
  105.     
  106.     device = property (lambda self: self.__device)
  107.     
  108.     def WriteFiles (self, message, files):
  109.         return "There is no multiple drives preference yet."
  110.         
  111.     def IsRecording (self, message):
  112.         return self.device in self.serpentine.recording
  113.     
  114.     def GetDevice (self, message):
  115.         return self.device
  116.