Make ondevice column appear and disappear when device is connected or disconnected

This commit is contained in:
Charles Haley 2010-05-09 22:39:50 +01:00
parent bb66cc1d8e
commit 5f2fe8fc54
2 changed files with 16 additions and 5 deletions

View File

@ -339,6 +339,7 @@ class BooksModel(QAbstractTableModel):
self.bool_yes_icon = QIcon(I('ok.svg')) self.bool_yes_icon = QIcon(I('ok.svg'))
self.bool_no_icon = QIcon(I('list_remove.svg')) self.bool_no_icon = QIcon(I('list_remove.svg'))
self.bool_blank_icon = QIcon(I('blank.svg')) self.bool_blank_icon = QIcon(I('blank.svg'))
self.device_connected = False
def is_custom_column(self, cc_label): def is_custom_column(self, cc_label):
return cc_label in self.custom_columns return cc_label in self.custom_columns
@ -353,7 +354,10 @@ class BooksModel(QAbstractTableModel):
self.headers = {} self.headers = {}
self.column_map = [] self.column_map = []
for col in cmap: # take out any columns no longer in the db for col in cmap: # take out any columns no longer in the db
if col in self.orig_headers or col in self.custom_columns: if col == 'ondevice':
if self.device_connected:
self.column_map.append(col)
elif col in self.orig_headers or col in self.custom_columns:
self.column_map.append(col) self.column_map.append(col)
for col in self.column_map: for col in self.column_map:
if col in self.orig_headers: if col in self.orig_headers:
@ -364,6 +368,12 @@ class BooksModel(QAbstractTableModel):
self.reset() self.reset()
self.emit(SIGNAL('columns_sorted()')) self.emit(SIGNAL('columns_sorted()'))
def set_device_connected(self, is_connected):
self.device_connected = is_connected
self.read_config()
self.refresh(reset=True)
self.database_changed.emit(self.db)
def set_book_on_device_func(self, func): def set_book_on_device_func(self, func):
self.book_on_device = func self.book_on_device = func

View File

@ -947,6 +947,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
self.device_manager.device) self.device_manager.device)
self.location_view.model().device_connected(self.device_manager.device) self.location_view.model().device_connected(self.device_manager.device)
self.eject_action.setEnabled(True) self.eject_action.setEnabled(True)
self.refresh_ondevice_info (device_connected = True)
else: else:
self.save_device_view_settings() self.save_device_view_settings()
self.device_connected = False self.device_connected = False
@ -959,7 +960,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
self.status_bar.reset_info() self.status_bar.reset_info()
self.location_view.setCurrentIndex(self.location_view.model().index(0)) self.location_view.setCurrentIndex(self.location_view.model().index(0))
self.eject_action.setEnabled(False) self.eject_action.setEnabled(False)
self.refresh_ondevice_info (clear_info = True) self.refresh_ondevice_info (device_connected = False)
def info_read(self, job): def info_read(self, job):
''' '''
@ -1015,13 +1016,13 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
view.verticalHeader().setDefaultSectionSize(height) view.verticalHeader().setDefaultSectionSize(height)
self.sync_news() self.sync_news()
self.sync_catalogs() self.sync_catalogs()
self.refresh_ondevice_info() self.refresh_ondevice_info(device_connected = True)
############################################################################ ############################################################################
### Force the library view to refresh, taking into consideration books information ### Force the library view to refresh, taking into consideration books information
def refresh_ondevice_info(self, clear_flags = False): def refresh_ondevice_info(self, device_connected):
self.book_on_device(None, reset=True) self.book_on_device(None, reset=True)
self.library_view.model().refresh() self.library_view.model().set_device_connected(device_connected)
############################################################################ ############################################################################
######################### Fetch annotations ################################ ######################### Fetch annotations ################################