Merge from custcol trunk

This commit is contained in:
Charles Haley 2010-05-20 18:07:11 +01:00
commit a1180981d0
7 changed files with 48 additions and 20 deletions

View File

@ -391,8 +391,8 @@ class BookList(list):
def __init__(self, oncard, prefix, settings):
pass
def supports_tags(self):
''' Return True if the the device supports tags (collections) for this book list. '''
def supports_collections(self):
''' Return True if the the device supports collections for this book list. '''
raise NotImplementedError()
def add_book(self, book, replace_metadata):

View File

@ -14,6 +14,7 @@ from calibre.devices.prs505 import MEDIA_XML
from calibre.devices.prs505 import CACHE_XML
from calibre.devices.prs505.sony_cache import XMLCache
from calibre import __appname__
from calibre.devices.usbms.books import CollectionsBookList
class PRS505(USBMS):
@ -23,8 +24,11 @@ class PRS505(USBMS):
author = 'Kovid Goyal'
supported_platforms = ['windows', 'osx', 'linux']
path_sep = '/'
booklist_class = CollectionsBookList
FORMATS = ['epub', 'lrf', 'lrx', 'rtf', 'pdf', 'txt']
CAN_SET_METADATA = True
VENDOR_ID = [0x054c] #: SONY Vendor Id
PRODUCT_ID = [0x031e]

View File

@ -97,8 +97,8 @@ class Book(MetaInformation):
class BookList(_BookList):
def supports_tags(self):
return True
def supports_collections(self):
return False
def add_book(self, book, replace_metadata):
if book not in self:
@ -109,6 +109,15 @@ class BookList(_BookList):
def remove_book(self, book):
self.remove(book)
def get_collections(self):
return {}
class CollectionsBookList(BookList):
def supports_collections(self):
return True
def get_collections(self, collection_attributes):
collections = {}
series_categories = set([])

View File

@ -37,7 +37,7 @@ class USBMS(CLI, Device):
book_class = Book
FORMATS = []
CAN_SET_METADATA = True
CAN_SET_METADATA = False
METADATA_CACHE = 'metadata.calibre'
def get_device_information(self, end_session=True):

View File

@ -161,7 +161,7 @@ class DeviceManager(Thread):
print 'Device connect failed again, giving up'
def umount_device(self, *args):
if self.is_device_connected:
if self.is_device_connected and not self.job_manager.has_device_jobs():
self.connected_device.eject()
self.ejected_devices.add(self.connected_device)
self.connected_slot(False, self.connected_device_is_folder)

View File

@ -729,6 +729,17 @@ class BooksModel(QAbstractTableModel): # {{{
class OnDeviceSearch(SearchQueryParser): # {{{
DEFAULT_LOCATIONS = [
'collections',
'title',
'author',
'format',
'search',
'date',
'all',
]
def __init__(self, model):
SearchQueryParser.__init__(self)
self.model = model
@ -738,6 +749,8 @@ class OnDeviceSearch(SearchQueryParser): # {{{
def get_matches(self, location, query):
location = location.lower().strip()
if location == 'authors':
location = 'author'
matchkind = CONTAINS_MATCH
if len(query) > 1:
@ -752,14 +765,15 @@ class OnDeviceSearch(SearchQueryParser): # {{{
if matchkind != REGEXP_MATCH: ### leave case in regexps because it can be significant e.g. \S \W \D
query = query.lower()
if location not in ('title', 'author', 'tag', 'all', 'format'):
if location not in self.DEFAULT_LOCATIONS:
return set([])
matches = set([])
locations = ['title', 'author', 'tag', 'format'] if location == 'all' else [location]
all_locs = set(self.DEFAULT_LOCATIONS) - set(['all'])
locations = all_locs if location == 'all' else [location]
q = {
'title' : lambda x : getattr(x, 'title').lower(),
'author': lambda x: ' & '.join(getattr(x, 'authors')).lower(),
'tag':lambda x: ','.join(getattr(x, 'tags')).lower(),
'collections':lambda x: ','.join(getattr(x, 'device_collections')).lower(),
'format':lambda x: os.path.splitext(x.path)[1].lower()
}
for index, row in enumerate(self.model.db):
@ -774,7 +788,7 @@ class OnDeviceSearch(SearchQueryParser): # {{{
else:
m = matchkind
if locvalue == 'tag':
if locvalue == 'collections':
vals = accessor(row).split(',')
else:
vals = [accessor(row)]
@ -802,12 +816,12 @@ class DeviceBooksModel(BooksModel): # {{{
self.column_map = ['inlibrary', 'title', 'authors', 'timestamp', 'size',
'collections']
self.headers = {
'inlibrary' : _('In Library'),
'title' : _('Title'),
'authors' : _('Author(s)'),
'timestamp' : _('Date'),
'size' : _('Size'),
'collections': _('Collections')
'inlibrary' : _('In Library'),
'title' : _('Title'),
'authors' : _('Author(s)'),
'timestamp' : _('Date'),
'size' : _('Size'),
'collections' : _('Collections')
}
self.marked_for_deletion = {}
self.search_engine = OnDeviceSearch(self)
@ -846,7 +860,8 @@ class DeviceBooksModel(BooksModel): # {{{
flags = QAbstractTableModel.flags(self, index)
if index.isValid() and self.editable:
cname = self.column_map[index.column()]
if cname in ('title', 'authors') or (cname == 'tags' and self.db.supports_tags()):
if cname in ('title', 'authors') or (cname == 'collection' and \
self.db.supports_collections()):
flags |= Qt.ItemIsEditable
return flags
@ -918,7 +933,7 @@ class DeviceBooksModel(BooksModel): # {{{
'authors' : authorcmp,
'size' : sizecmp,
'timestamp': datecmp,
'tags': tagscmp,
'collections': tagscmp,
'inlibrary': libcmp,
}[cname]
self.map.sort(cmp=fcmp, reverse=descending)
@ -1024,7 +1039,8 @@ class DeviceBooksModel(BooksModel): # {{{
elif role == Qt.ToolTipRole and index.isValid():
if self.map[row] in self.indices_to_be_deleted():
return QVariant(_('Marked for deletion'))
if cname in ['title', 'authors'] or (cname == 'tags' and self.db.supports_tags()):
if cname in ['title', 'authors'] or (cname == 'collections' and \
self.db.supports_collections()):
return QVariant(_("Double click to <b>edit</b> me<br><br>"))
elif role == Qt.DecorationRole and cname == 'inlibrary':
if self.db[self.map[row]].in_library:

View File

@ -222,7 +222,6 @@ class BooksView(QTableView): # {{{
return
for col, order in reversed(self.cleanup_sort_history(saved_history)[:3]):
self.sortByColumn(self.column_map.index(col), order)
#self.model().sort_history = saved_history
def apply_state(self, state):
h = self.column_header