Merge from trunk

This commit is contained in:
Charles Haley 2010-10-07 18:55:59 +01:00
commit 622887a1b4
3 changed files with 24 additions and 11 deletions

View File

@ -17,7 +17,7 @@ from calibre.gui2 import gprefs, warning_dialog, Dispatcher, error_dialog, \
question_dialog, info_dialog
from calibre.gui2.actions import InterfaceAction
class LibraryUsageStats(object):
class LibraryUsageStats(object): # {{{
def __init__(self):
self.stats = {}
@ -73,7 +73,7 @@ class LibraryUsageStats(object):
if stats is not None:
self.stats[newloc] = stats
self.write_stats()
# }}}
class ChooseLibraryAction(InterfaceAction):
@ -147,9 +147,11 @@ class ChooseLibraryAction(InterfaceAction):
self.qs_locations = [i[1] for i in locations]
self.rename_menu.clear()
self.delete_menu.clear()
quick_actions = []
for name, loc in locations:
self.quick_menu.addAction(name, Dispatcher(partial(self.switch_requested,
ac = self.quick_menu.addAction(name, Dispatcher(partial(self.switch_requested,
loc)))
quick_actions.append(ac)
self.rename_menu.addAction(name, Dispatcher(partial(self.rename_requested,
name, loc)))
self.delete_menu.addAction(name, Dispatcher(partial(self.delete_requested,
@ -164,6 +166,7 @@ class ChooseLibraryAction(InterfaceAction):
self.quick_menu_action.setVisible(bool(locations))
self.rename_menu_action.setVisible(bool(locations))
self.delete_menu_action.setVisible(bool(locations))
self.gui.location_manager.set_switch_actions(quick_actions)
def location_selected(self, loc):
@ -263,11 +266,6 @@ class ChooseLibraryAction(InterfaceAction):
c.exec_()
def change_library_allowed(self):
if self.gui.device_connected:
warning_dialog(self.gui, _('Not allowed'),
_('You cannot change libraries when a device is'
' connected.'), show=True)
return False
if self.gui.job_manager.has_jobs():
warning_dialog(self.gui, _('Not allowed'),
_('You cannot change libraries while jobs'

View File

@ -24,6 +24,7 @@ class LocationManager(QObject): # {{{
locations_changed = pyqtSignal()
unmount_device = pyqtSignal()
location_selected = pyqtSignal(object)
switch_actions_set = pyqtSignal(object)
def __init__(self, parent=None):
QObject.__init__(self, parent)
@ -60,7 +61,7 @@ class LocationManager(QObject): # {{{
return ac
ac('library', _('Library'), 'lt.png',
self.library_action = ac('library', _('Library'), 'lt.png',
_('Show books in calibre library'))
ac('main', _('Device'), 'reader.png',
_('Show books in the main memory of the device'))
@ -69,6 +70,13 @@ class LocationManager(QObject): # {{{
ac('cardb', _('Card B'), 'sd.png',
_('Show books in storage card B'))
def set_switch_actions(self, actions):
self.switch_menu = QMenu()
for ac in actions:
self.switch_menu.addAction(ac)
self.library_action.setMenu(self.switch_menu)
self.switch_actions_set.emit(bool(actions))
def _location_selected(self, location, *args):
if location != self.current_location and hasattr(self,
'location_'+location):
@ -197,14 +205,14 @@ class SearchBar(QWidget): # {{{
# }}}
class Spacer(QWidget):
class Spacer(QWidget): # {{{
def __init__(self, parent):
QWidget.__init__(self, parent)
self.l = QHBoxLayout()
self.setLayout(self.l)
self.l.addStretch(10)
# }}}
class ToolBar(QToolBar): # {{{

View File

@ -390,6 +390,13 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
except:
import traceback
traceback.print_exc()
if self.device_connected:
self.set_books_in_library(self.booklists(), reset=True)
self.refresh_ondevice()
self.memory_view.reset()
self.card_a_view.reset()
self.card_b_view.reset()
def set_window_title(self):
self.setWindowTitle(__appname__ + u' - ||%s||'%self.iactions['Choose Library'].library_name())