User defined driver: Add option to swap main memory and card a. Fixes #1020056 (User device swaps sd card and device)

This commit is contained in:
Kovid Goyal 2012-07-02 20:59:12 +05:30
commit a0db7b824a

View File

@ -66,6 +66,9 @@ class USER_DEFINED(USBMS):
_('Card A folder') + ':::<p>' +
_('Enter the folder where the books are to be stored. This folder '
'is prepended to any send_to_device template') + '</p>',
_('Swap main and card A') + ':::<p>' +
_('Check this box if the device\'s main memory is being seen as '
'card a and the card is being seen as main memory') + '</p>',
]
EXTRA_CUSTOMIZATION_DEFAULT = [
'0xffff',
@ -78,16 +81,19 @@ class USER_DEFINED(USBMS):
'',
'',
'',
False,
]
OPT_USB_VENDOR_ID = 0
OPT_USB_PRODUCT_ID = 1
OPT_USB_REVISION_ID = 2
# OPT 3 isn't used
OPT_USB_WINDOWS_MM_VEN_ID = 4
OPT_USB_WINDOWS_MM_ID = 5
OPT_USB_WINDOWS_CA_VEN_ID = 6
OPT_USB_WINDOWS_CA_ID = 7
OPT_MAIN_MEM_FOLDER = 8
OPT_CARD_A_FOLDER = 9
OPT_SWAP_MAIN_AND_CARD = 10
def initialize(self):
self.plugin_needs_delayed_initialization = True
@ -113,4 +119,41 @@ class USER_DEFINED(USBMS):
traceback.print_exc()
self.plugin_needs_delayed_initialization = False
def windows_sort_drives(self, drives):
if len(drives) < 2: return drives
e = self.settings().extra_customization
if not e[self.OPT_SWAP_MAIN_AND_CARD]:
return drives
main = drives.get('main', None)
carda = drives.get('carda', None)
if main and carda:
drives['main'] = carda
drives['carda'] = main
return drives
def linux_swap_drives(self, drives):
if len(drives) < 2 or not drives[1] or not drives[2]: return drives
e = self.settings().extra_customization
if not e[self.OPT_SWAP_MAIN_AND_CARD]:
return drives
drives = list(drives)
t = drives[0]
drives[0] = drives[1]
drives[1] = t
return tuple(drives)
def osx_sort_names(self, names):
if len(names) < 2: return names
e = self.settings().extra_customization
if not e[self.OPT_SWAP_MAIN_AND_CARD]:
return names
main = names.get('main', None)
card = names.get('carda', None)
if main is not None and card is not None:
names['main'] = card
names['carda'] = main
return names