Re-organize Send to device menu

This commit is contained in:
Kovid Goyal 2010-05-18 10:43:44 -06:00
parent 7fb8fa9323
commit 5fa9a5b935

View File

@ -327,15 +327,17 @@ class DeviceManager(Thread):
class DeviceAction(QAction): class DeviceAction(QAction):
a_s = pyqtSignal(object)
def __init__(self, dest, delete, specific, icon_path, text, parent=None): def __init__(self, dest, delete, specific, icon_path, text, parent=None):
if delete:
text += ' ' + _('and delete from library')
QAction.__init__(self, QIcon(icon_path), text, parent) QAction.__init__(self, QIcon(icon_path), text, parent)
self.dest = dest self.dest = dest
self.delete = delete self.delete = delete
self.specific = specific self.specific = specific
self.connect(self, SIGNAL('triggered(bool)'), self.triggered.connect(self.emit_triggered)
lambda x : self.emit(SIGNAL('a_s(QAction)'), self))
def emit_triggered(self, *args):
self.a_s.emit(self)
def __repr__(self): def __repr__(self):
return self.__class__.__name__ + ':%s:%s:%s'%(self.dest, self.delete, return self.__class__.__name__ + ':%s:%s:%s'%(self.dest, self.delete,
@ -356,6 +358,7 @@ class DeviceMenu(QMenu):
self.set_default_menu = self.addMenu(_('Set default send to device' self.set_default_menu = self.addMenu(_('Set default send to device'
' action')) ' action'))
self.addSeparator()
opts = email_config().parse() opts = email_config().parse()
default_account = None default_account = None
if opts.accounts: if opts.accounts:
@ -379,51 +382,65 @@ class DeviceMenu(QMenu):
self.connect(action2, SIGNAL('a_s(QAction)'), self.connect(action2, SIGNAL('a_s(QAction)'),
self.action_triggered) self.action_triggered)
_actions = [ basic_actions = [
('main:', False, False, I('reader.svg'), ('main:', False, False, I('reader.svg'),
_('Send to main memory')), _('Send to main memory')),
('carda:0', False, False, I('sd.svg'), ('carda:0', False, False, I('sd.svg'),
_('Send to storage card A')), _('Send to storage card A')),
('cardb:0', False, False, I('sd.svg'), ('cardb:0', False, False, I('sd.svg'),
_('Send to storage card B')), _('Send to storage card B')),
'-----',
('main:', True, False, I('reader.svg'),
_('Send to main memory')),
('carda:0', True, False, I('sd.svg'),
_('Send to storage card A')),
('cardb:0', True, False, I('sd.svg'),
_('Send to storage card B')),
'-----',
('main:', False, True, I('reader.svg'),
_('Send specific format to main memory')),
('carda:0', False, True, I('sd.svg'),
_('Send specific format to storage card A')),
('cardb:0', False, True, I('sd.svg'),
_('Send specific format to storage card B')),
] ]
delete_actions = [
('main:', True, False, I('reader.svg'),
_('Main Memory')),
('carda:0', True, False, I('sd.svg'),
_('Storage Card A')),
('cardb:0', True, False, I('sd.svg'),
_('Storage Card B')),
]
specific_actions = [
('main:', False, True, I('reader.svg'),
_('Main Memory')),
('carda:0', False, True, I('sd.svg'),
_('Storage Card A')),
('cardb:0', False, True, I('sd.svg'),
_('Storage Card B')),
]
if default_account is not None: if default_account is not None:
_actions.insert(2, default_account) for x in (basic_actions, delete_actions):
_actions.insert(6, list(default_account)) ac = list(default_account)
_actions[6][1] = True if x is delete_actions:
for round in (0, 1): ac[1] = True
for dest, delete, specific, icon, text in _actions: x.insert(1, tuple(ac))
if dest == '-':
(self.set_default_menu if round else self).addSeparator() for menu in (self, self.set_default_menu):
continue for actions, desc in (
(basic_actions, ''),
(delete_actions, _('Send and delete from library')),
(specific_actions, _('Send specific format'))
):
mdest = menu
if actions is not basic_actions:
mdest = menu.addMenu(desc)
self._memory.append(mdest)
for dest, delete, specific, icon, text in actions:
action = DeviceAction(dest, delete, specific, icon, text, self) action = DeviceAction(dest, delete, specific, icon, text, self)
self._memory.append(action) self._memory.append(action)
if round == 1: if menu is self.set_default_menu:
action.setCheckable(True) action.setCheckable(True)
action.setText(action.text()) action.setText(action.text())
self.group.addAction(action) self.group.addAction(action)
self.set_default_menu.addAction(action)
else: else:
self.connect(action, SIGNAL('a_s(QAction)'), action.a_s.connect(self.action_triggered)
self.action_triggered)
self.actions.append(action) self.actions.append(action)
self.addAction(action) mdest.addAction(action)
if actions is not specific_actions:
menu.addSeparator()
da = config['default_send_to_device_action'] da = config['default_send_to_device_action']
done = False done = False
@ -437,8 +454,7 @@ class DeviceMenu(QMenu):
action.setChecked(True) action.setChecked(True)
config['default_send_to_device_action'] = repr(action) config['default_send_to_device_action'] = repr(action)
self.connect(self.group, SIGNAL('triggered(QAction*)'), self.group.triggered.connect(self.change_default_action)
self.change_default_action)
if opts.accounts: if opts.accounts:
self.addSeparator() self.addSeparator()
self.addMenu(self.email_to_menu) self.addMenu(self.email_to_menu)