~fluendo-elisa/moovida/elisa-pancake

« back to all changes in this revision

Viewing changes to elisa-plugins/elisa/plugins/wmd/wmd_resource.py

  • Committer: pancake
  • Date: 2009-03-27 12:16:38 UTC
  • mfrom: (1115.2.37 elisa)
  • Revision ID: pancake@flubox-20090327121638-2da0c1a0zu3byufd
* Merge against the head

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
import pywintypes
36
36
 
37
37
import struct
 
38
import gobject
38
39
 
39
40
from twisted.internet import threads
40
41
from elisa.core.utils import defer
48
49
from elisa.plugins.base.models.device import DevicesModel, VolumeModel
49
50
from elisa.core.media_uri import MediaUri
50
51
 
 
52
from elisa.plugins.pigment.message import PigmentFrontendLoadedMessage
 
53
 
51
54
_ = install_translation('wmd')
52
55
 
53
56
MAX_DRIVES = 26
54
57
 
55
 
GUID_DEVINTERFACE_VOLUME = u'{53F5630D-B6BF-11D0-94F2-00A0C91EFB8B}'
56
 
 
57
58
class WMDVolumeModel(VolumeModel):
58
59
    """
59
60
    Volume model Win32 platform specific.
95
96
    supported_uri='^volumes://'
96
97
 
97
98
    def initialize(self):
98
 
        winprocs = {win32con.WM_DEVICECHANGE : self._on_device_change, }
99
 
        self._message_source = common.application.windows_message_source
100
 
        self._message_source.add_wndproc(winprocs)
101
 
        self._message_source.register_device_notification(GUID_DEVINTERFACE_VOLUME)
102
 
        self._message_source.attach()
103
 
 
 
99
        bus = common.application.bus
 
100
        bus.register(self._frontend_loaded, PigmentFrontendLoadedMessage)
104
101
        self._dfr_list = []
105
 
 
 
102
        self._signal_handler_id = None
106
103
        return super(WMDResource, self).initialize()
107
104
 
108
105
    def clean(self):
109
106
        self.debug('cleaning up')
110
 
        
 
107
        if self._signal_handler_id != None:
 
108
            gobject.disconnect(self._signal_handler_id)
 
109
            self._signal_handler_id = None
 
110
 
111
111
        dfr = super(WMDResource, self).clean()
112
112
 
113
 
        self._message_source.destroy()
114
 
 
115
113
        if self._dfr_list != []:
116
114
            dfr_list = defer.DeferredList(self._dfr_list)
117
115
            dfr.chainDeferred(dfr_list)
118
116
 
119
117
        return dfr
120
118
 
 
119
    def _frontend_loaded(self, message, frontend):
 
120
        frontend.windows_msg_handler.add_wndproc(win32con.WM_DEVICECHANGE,
 
121
                                                 self._on_device_change)
 
122
 
121
123
    def get(self, uri, context_model=None):
122
124
        """
123
125
        Simple method to retrieve volumes. You can access it with
291
293
            test_mask <<= 1
292
294
            letter_num += 1
293
295
        return drives
294
 
    
295
 
    def _on_device_change(self, hwnd, msg, wparam, lparam):
296
 
        info = UnpackDEV_BROADCAST(lparam)
297
 
        if (wparam != win32con.DBT_DEVICEARRIVAL \
298
 
                and wparam != win32con.DBT_DEVICEREMOVECOMPLETE) \
 
296
 
 
297
    def _on_device_change(self, viewport, event):
 
298
        info = UnpackDEV_BROADCAST(event.lparam)
 
299
        if (event.wparam != win32con.DBT_DEVICEARRIVAL \
 
300
                and event.wparam != win32con.DBT_DEVICEREMOVECOMPLETE) \
299
301
            or info.devicetype != win32con.DBT_DEVTYP_VOLUME:
300
 
            return
 
302
            return True
301
303
 
302
304
        self.debug('on device change')
303
305
 
304
306
        units = self._drive_units_from_mask(info.unitmask)
305
307
 
306
 
        if wparam == win32con.DBT_DEVICEARRIVAL:
 
308
        if event.wparam == win32con.DBT_DEVICEARRIVAL:
307
309
            dfr = threads.deferToThread(self._send_new_devices, units)
308
310
 
309
311
            def send_messages(messages):
322
324
 
323
325
        else: # DBT_DEVICEREMOVECOMPLETE
324
326
            self._send_removed_devices(units)
325
 
 
326
327
        return True
327
328
 
328
329
    def _send_new_devices(self, units):