~ubuntu-branches/ubuntu/lucid/exaile/lucid

« back to all changes in this revision

Viewing changes to plugins/daapserver/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2010-02-12 19:51:01 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20100212195101-8jt3tculxcl92e6v
Tags: 0.3.1~b1-0ubuntu1
* New upstream release.
* Adjust exaile.install for new plugins.
* debian/control:
 - Drop unneeded python-dev Build-Dep.
 - Bump Standards-Version to 3.8.4 
* debian/rules: No empty po files to delete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
import logging
 
3
import gobject
 
4
from xl import collection, event, settings
 
5
import spydaap.parser.exaile
 
6
 
 
7
log = logging.getLogger(__file__)
 
8
 
 
9
 
 
10
# todo support multiple connections?
 
11
class CollectionWrapper:
 
12
    class TrackWrapper:
 
13
        def __init__(self, id, track):
 
14
            self.track = track
 
15
            self.id = id
 
16
            self.parser = spydaap.parser.exaile.ExaileParser()
 
17
            self.daap = None
 
18
 
 
19
        def get_dmap_raw(self):
 
20
            if self.daap is None:
 
21
                self.daap = ''.join([d.encode() for d in self.parser.parse(self.track)[0]])
 
22
            return self.daap
 
23
 
 
24
        def get_original_filename(self):
 
25
            return self.track.local_file_name()
 
26
 
 
27
    def __init__(self, collection):
 
28
        self.collection = collection
 
29
        self.map = []
 
30
 
 
31
    def __iter__(self):
 
32
        print 'GEN ITERRR'
 
33
        i = 0
 
34
        self.map = []
 
35
        for t in self.collection:
 
36
            self.map.append(self.TrackWrapper(i, t))
 
37
            yield self.map[i]
 
38
            i += 1
 
39
    
 
40
    def get_item_by_id(self, id):
 
41
        return self.map[int(id)]
 
42
    
 
43
    def __getitem__(self, idx):
 
44
        return self.map[idx]
 
45
 
 
46
    def __len__(self):
 
47
        return len(self.collection)
 
48
 
 
49
from server import DaapServer
 
50
 
 
51
ds = None
 
52
def _enable(exaile):
 
53
    # real enable
 
54
    global ds
 
55
    
 
56
    event.add_callback(on_settings_change, 'option_set')
 
57
    
 
58
    port = int(settings.get_option('plugin/daapserver/port', 3689))
 
59
    name = settings.get_option('plugin/daapserver/name', 'Exaile Share')
 
60
    host = settings.get_option('plugin/daapserver/host', '0.0.0.0')
 
61
    
 
62
#    DaapServer.init(exaile.collection,port=port,name=name)
 
63
    ds = DaapServer(CollectionWrapper(exaile.collection), port=port, name=name, host=host)
 
64
    if( settings.get_option('plugin/daapserver/enabled', True) ):
 
65
        ds.start()
 
66
    
 
67
    
 
68
 
 
69
def __enb(evname, exaile, wat):
 
70
    gobject.idle_add(_enable, exaile)
 
71
 
 
72
 
 
73
def enable(exaile):
 
74
    if exaile.loading:
 
75
        event.add_callback(__enb, 'gui_loaded')
 
76
    else:
 
77
        __enb(None, exaile, None)
 
78
 
 
79
def teardown(exaile):
 
80
    ds.stop_server()
 
81
 
 
82
def disable(exaile):
 
83
    ds.stop_server()
 
84
    
 
85
    
 
86
 
 
87
# settings stuff
 
88
import daapserverprefs
 
89
 
 
90
def get_prefs_pane():
 
91
    return daapserverprefs
 
92
    
 
93
def on_settings_change(event, setting, option):
 
94
    if option == 'plugin/daapserver/name' and ds is not None:
 
95
        ds.set(name=settings.get_option(option,'Exaile Share'))
 
96
    if option == 'plugin/daapserver/port' and ds is not None:
 
97
        ds.set(port=settings.get_option(option,3689))
 
98
    if option == 'plugin/daapserver/host' and ds is not None:
 
99
        ds.set(host=settings.get_option(option,'0.0.0.0'))
 
100
    if option == 'plugin/daapserver/enabled' and ds is not None:
 
101
        enabled = setting.get_option(option, True)
 
102
        if enabled:
 
103
            if not ds.start():
 
104
                pass
 
105
#                settings.set_option('plugin/daapserver/enabled', False) ? 
 
106
        else:
 
107
            ds.stop_server()