Package conduit :: Package modules :: Package N800Module :: Module N800Module
[hide private]

Source Code for Module conduit.modules.N800Module.N800Module

  1  """ 
  2  Provides a number of dataproviders which are associated with 
  3  a N800 device. Allow the transcoding of music, photos and video before  
  4  transferring them to the n800 
  5   
  6  Copyright 2007: Jaime Frutos Morales, John Stowers 
  7  License: GPLv2 
  8  """ 
  9  import logging 
 10  log = logging.getLogger("modules.N800") 
 11   
 12  import conduit 
 13  import conduit.datatypes.Video as Video 
 14  import conduit.datatypes.Audio as Audio 
 15  import conduit.datatypes.Photo as Photo 
 16  import conduit.dataproviders.VolumeFactory as VolumeFactory 
 17  import conduit.dataproviders.DataProviderCategory as DataProviderCategory 
 18  import conduit.dataproviders.File as FileDataProvider 
 19  import conduit.Exceptions as Exceptions 
 20  import conduit.Vfs as Vfs 
 21   
 22  from gettext import gettext as _ 
 23   
 24  MODULES = { 
 25      "N800Factory" : { "type": "dataprovider-factory" }, 
 26  } 
 27   
 28   
29 -class N800Factory(VolumeFactory.VolumeFactory):
30 - def is_interesting(self, udi, props):
31 if props.has_key("info.parent") and props.has_key("info.parent")!="": 32 prop2 = self._get_properties(props["info.parent"]) 33 if prop2.has_key("storage.model") and prop2["storage.model"] in ("N800", "N810"): 34 if prop2.has_key("storage.removable") and prop2["storage.removable"] == True: 35 return True 36 return False
37
38 - def get_category(self, udi, **kwargs):
39 return DataProviderCategory.DataProviderCategory( 40 "Nokia N800", 41 "n800", 42 kwargs['mount'])
43
44 - def get_dataproviders(self, udi, **kwargs):
46 47
48 -class N800Base(FileDataProvider.FolderTwoWay):
49 """ 50 TwoWay dataprovider for synchronizing a folder on a N800 51 """ 52 53 #Translators: Translate this in derived classes. 54 DEFAULT_FOLDER = _("Conduit") 55 #Translators: Format string used to describe the acceptable formats the 56 #device accepts. The first arg is replaced with DEFAULT_FOLDER and the second 57 #arg is a comma seperated list of encodings 58 FORMAT_CONVERSION_STRING = _("%s Format (%s)") 59 #Signifies that a conversion should not take place 60 NO_CONVERSION_STRING = _("unchanged") 61 62 _configurable_ = True 63
64 - def __init__(self, mount, udi, folder):
65 FileDataProvider.FolderTwoWay.__init__(self, 66 "file://"+folder, 67 "N800", 68 False, 69 False, 70 False 71 ) 72 self.mount = mount 73 self.udi = udi 74 self.encodings = {} 75 self.encoding = ""
76
77 - def configure(self, window):
78 import gtk 79 import conduit.gtkui.SimpleConfigurator as SimpleConfigurator 80 81 def setEnc(param): 82 self.encoding = str(param)
83 84 encodings = self.encodings.keys()+[self.NO_CONVERSION_STRING] 85 items = [ 86 { 87 "Name" : self.FORMAT_CONVERSION_STRING % (self.DEFAULT_FOLDER, ",".join(encodings)), 88 "Widget" : gtk.Entry, 89 "Callback" : setEnc, 90 "InitialValue" : self.encoding 91 } 92 ] 93 dialog = SimpleConfigurator.SimpleConfigurator(window, self._name_, items) 94 dialog.run()
95
96 - def refresh(self):
97 if not Vfs.uri_exists(self.folder): 98 try: 99 Vfs.uri_make_directory_and_parents(self.folder) 100 except: 101 raise Exceptions.RefreshError("Error Creating Directory") 102 FileDataProvider.FolderTwoWay.refresh(self)
103
104 - def get_input_conversion_args(self):
105 try: 106 return self.encodings[self.encoding] 107 except KeyError: 108 return {}
109
110 - def get_configuration(self):
111 return {'encoding':self.encoding}
112
113 - def get_UID(self):
114 return "%s" % self.udi
115
116 -class N800FolderTwoWay(N800Base):
117 """ 118 TwoWay dataprovider for synchronizing a folder on a N800 119 """ 120 121 _name_ = _("N800 Files") 122 _description_ = _("Synchronizes files/folders to a N800 device") 123 _in_type_ = "file" 124 _out_type_ = "file" 125 126 #To translators: default backup folder of N800 127 DEFAULT_FOLDER = _("Backups") 128
129 - def __init__(self, *args):
130 N800Base.__init__( 131 self, 132 mount=args[0], 133 udi=args[1], 134 folder=Vfs.uri_join(args[0],self.DEFAULT_FOLDER) 135 )
136
137 -class N800AudioTwoWay(N800Base):
138 """ 139 TwoWay dataprovider for synchronizing a folder on a N800 140 """ 141 142 _name_ = _("N800 Music") 143 _description_ = _("Synchronizes music to a N800 device") 144 _in_type_ = "file/audio" 145 _out_type_ = "file/audio" 146 _icon_ = "audio-x-generic" 147 148 #To translators: defaul music folder of N800 149 DEFAULT_FOLDER = _("Music") 150
151 - def __init__(self, *args):
152 N800Base.__init__( 153 self, 154 mount=args[0], 155 udi=args[1], 156 folder=Vfs.uri_join(args[0],self.DEFAULT_FOLDER) 157 ) 158 self.encodings = Audio.PRESET_ENCODINGS.copy() 159 self.encoding = "ogg"
160
161 -class N800VideoTwoWay(N800Base):
162 """ 163 TwoWay dataprovider for synchronizing a folder on a N800 164 """ 165 166 _name_ = _("N800 Videos") 167 _description_ = _("Synchronizes video to a N800 device") 168 _in_type_ = "file/video" 169 _out_type_ = "file/video" 170 _icon_ = "video-x-generic" 171 172 #To translators: defaul video folder of N800 173 DEFAULT_FOLDER = _("Video") 174
175 - def __init__(self, *args):
176 N800Base.__init__( 177 self, 178 mount=args[0], 179 udi=args[1], 180 folder=Vfs.uri_join(args[0],self.DEFAULT_FOLDER) 181 ) 182 self.encodings = Video.PRESET_ENCODINGS.copy() 183 self.encoding = "ogg"
184
185 -class N800PhotoTwoWay(N800Base):
186 """ 187 TwoWay dataprovider for synchronizing a folder on a N800 188 """ 189 190 _name_ = _("N800 Photos") 191 _description_ = _("Synchronizes video to a N800 device") 192 _in_type_ = "file/photo" 193 _out_type_ = "file/photo" 194 _icon_ = "image-x-generic" 195 196 #To translators: default photos folder of N800 197 DEFAULT_FOLDER = _("Photo") 198
199 - def __init__(self, *args):
200 N800Base.__init__( 201 self, 202 mount=args[0], 203 udi=args[1], 204 folder=Vfs.uri_join(args[0],self.DEFAULT_FOLDER) 205 ) 206 self.encodings = Photo.PRESET_ENCODINGS.copy() 207 #Add size = 800x480 to the default photo encodings 208 for k in self.encodings.keys(): 209 self.encodings[k]['size'] = '800x480' 210 self.encoding = "jpeg"
211