mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
GR changes supporting ondevice
This commit is contained in:
parent
99b494fb7b
commit
2501e40e43
@ -33,7 +33,7 @@ class GenerateCatalogAction(InterfaceAction):
|
|||||||
show=True)
|
show=True)
|
||||||
|
|
||||||
# Calling gui2.tools:generate_catalog()
|
# Calling gui2.tools:generate_catalog()
|
||||||
ret = generate_catalog(self.gui, dbspec, ids, self.gui.device_manager.device)
|
ret = generate_catalog(self.gui, dbspec, ids, self.gui.device_manager)
|
||||||
if ret is None:
|
if ret is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ def fetch_scheduled_recipe(arg):
|
|||||||
|
|
||||||
return 'gui_convert', args, _('Fetch news from ')+arg['title'], fmt.upper(), [pt]
|
return 'gui_convert', args, _('Fetch news from ')+arg['title'], fmt.upper(), [pt]
|
||||||
|
|
||||||
def generate_catalog(parent, dbspec, ids, device):
|
def generate_catalog(parent, dbspec, ids, device_manager):
|
||||||
from calibre.gui2.dialogs.catalog import Catalog
|
from calibre.gui2.dialogs.catalog import Catalog
|
||||||
|
|
||||||
# Build the Catalog dialog in gui2.dialogs.catalog
|
# Build the Catalog dialog in gui2.dialogs.catalog
|
||||||
@ -252,9 +252,18 @@ def generate_catalog(parent, dbspec, ids, device):
|
|||||||
|
|
||||||
# Profile the connected device
|
# Profile the connected device
|
||||||
# Parallel initialization in calibre.library.cli:command_catalog()
|
# Parallel initialization in calibre.library.cli:command_catalog()
|
||||||
connected_device = { 'storage':None,'serial':None,'save_template':None,'name':None}
|
connected_device = {
|
||||||
|
'is_device_connected': device_manager.is_device_connected,
|
||||||
|
'kind': device_manager.connected_device_kind,
|
||||||
|
'name': None,
|
||||||
|
'save_template': None,
|
||||||
|
'serial': None,
|
||||||
|
'storage': None
|
||||||
|
}
|
||||||
|
|
||||||
if device:
|
if device_manager.is_device_connected:
|
||||||
|
device = device_manager.device
|
||||||
|
connected_device['name'] = device.gui_name
|
||||||
try:
|
try:
|
||||||
storage = []
|
storage = []
|
||||||
if device._main_prefix:
|
if device._main_prefix:
|
||||||
@ -263,11 +272,10 @@ def generate_catalog(parent, dbspec, ids, device):
|
|||||||
storage.append(os.path.join(device._card_a_prefix, device.EBOOK_DIR_CARD_A))
|
storage.append(os.path.join(device._card_a_prefix, device.EBOOK_DIR_CARD_A))
|
||||||
if device._card_b_prefix:
|
if device._card_b_prefix:
|
||||||
storage.append(os.path.join(device._card_b_prefix, device.EBOOK_DIR_CARD_B))
|
storage.append(os.path.join(device._card_b_prefix, device.EBOOK_DIR_CARD_B))
|
||||||
connected_device = { 'storage': storage,
|
connected_device['storage'] = storage
|
||||||
'serial': device.detected_device.serial if \
|
connected_device['serial'] = device.detected_device.serial if \
|
||||||
hasattr(device.detected_device,'serial') else None,
|
hasattr(device.detected_device,'serial') else None
|
||||||
'save_template': device.save_template(),
|
connected_device['save_template'] = device.save_template()
|
||||||
'name': device.gui_name}
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -67,6 +67,8 @@ class CSV_XML(CatalogPlugin):
|
|||||||
if opts.verbose:
|
if opts.verbose:
|
||||||
opts_dict = vars(opts)
|
opts_dict = vars(opts)
|
||||||
log("%s(): Generating %s" % (self.name,self.fmt))
|
log("%s(): Generating %s" % (self.name,self.fmt))
|
||||||
|
if opts.connected_device['is_device_connected']:
|
||||||
|
log(" connected_device: %s" % opts.connected_device['name'])
|
||||||
if opts_dict['search_text']:
|
if opts_dict['search_text']:
|
||||||
log(" --search='%s'" % opts_dict['search_text'])
|
log(" --search='%s'" % opts_dict['search_text'])
|
||||||
|
|
||||||
@ -81,7 +83,6 @@ class CSV_XML(CatalogPlugin):
|
|||||||
else:
|
else:
|
||||||
log(" Fields: %s" % opts_dict['fields'])
|
log(" Fields: %s" % opts_dict['fields'])
|
||||||
|
|
||||||
|
|
||||||
# If a list of ids are provided, don't use search_text
|
# If a list of ids are provided, don't use search_text
|
||||||
if opts.ids:
|
if opts.ids:
|
||||||
opts.search_text = None
|
opts.search_text = None
|
||||||
@ -888,6 +889,7 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
self.__totalSteps += 2
|
self.__totalSteps += 2
|
||||||
|
|
||||||
# Accessors
|
# Accessors
|
||||||
|
if True:
|
||||||
'''
|
'''
|
||||||
@dynamic_property
|
@dynamic_property
|
||||||
def xxxx(self):
|
def xxxx(self):
|
||||||
@ -897,7 +899,6 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
self.__ = val
|
self.__ = val
|
||||||
return property(fget=fget, fset=fset)
|
return property(fget=fget, fset=fset)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@dynamic_property
|
@dynamic_property
|
||||||
def authorClip(self):
|
def authorClip(self):
|
||||||
def fget(self):
|
def fget(self):
|
||||||
@ -1206,7 +1207,6 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
|
|
||||||
self.generateOPF()
|
self.generateOPF()
|
||||||
self.generateNCXHeader()
|
self.generateNCXHeader()
|
||||||
self.generateNCXDescriptions("Descriptions")
|
|
||||||
self.generateNCXByAuthor("Authors")
|
self.generateNCXByAuthor("Authors")
|
||||||
if self.opts.generate_titles:
|
if self.opts.generate_titles:
|
||||||
self.generateNCXByTitle("Titles")
|
self.generateNCXByTitle("Titles")
|
||||||
@ -1215,6 +1215,7 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
if self.generateRecentlyRead:
|
if self.generateRecentlyRead:
|
||||||
self.generateNCXByDateRead("Recently Read")
|
self.generateNCXByDateRead("Recently Read")
|
||||||
self.generateNCXByGenre("Genres")
|
self.generateNCXByGenre("Genres")
|
||||||
|
self.generateNCXDescriptions("Descriptions")
|
||||||
self.writeNCX()
|
self.writeNCX()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -1570,8 +1571,8 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
if title['series']:
|
if title['series']:
|
||||||
# title<br />series series_index
|
# title<br />series series_index
|
||||||
brTag = Tag(soup,'br')
|
brTag = Tag(soup,'br')
|
||||||
title_tokens = title['title'].split(': ')
|
title_tokens = list(title['title'].partition(':'))
|
||||||
emTag.insert(0, escape(NavigableString(title_tokens[1])))
|
emTag.insert(0, escape(NavigableString(title_tokens[2].strip())))
|
||||||
emTag.insert(1, brTag)
|
emTag.insert(1, brTag)
|
||||||
smallTag = Tag(soup,'small')
|
smallTag = Tag(soup,'small')
|
||||||
smallTag.insert(0, escape(NavigableString(title_tokens[0])))
|
smallTag.insert(0, escape(NavigableString(title_tokens[0])))
|
||||||
@ -1747,8 +1748,8 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
nspt = deepcopy(self.booksByTitle)
|
nspt = deepcopy(self.booksByTitle)
|
||||||
for book in nspt:
|
for book in nspt:
|
||||||
if book['series']:
|
if book['series']:
|
||||||
tokens = book['title'].split(': ')
|
tokens = book['title'].partition(':')
|
||||||
book['title'] = '%s (%s)' % (tokens[1], tokens[0])
|
book['title'] = '%s (%s)' % (tokens[2].strip(), tokens[0])
|
||||||
book['title_sort'] = self.generateSortTitle(book['title'])
|
book['title_sort'] = self.generateSortTitle(book['title'])
|
||||||
nspt = sorted(nspt,
|
nspt = sorted(nspt,
|
||||||
key=lambda x:(x['title_sort'].upper(), x['title_sort'].upper()))
|
key=lambda x:(x['title_sort'].upper(), x['title_sort'].upper()))
|
||||||
@ -1929,7 +1930,7 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
current_series = book['series']
|
current_series = book['series']
|
||||||
pSeriesTag = Tag(soup,'p')
|
pSeriesTag = Tag(soup,'p')
|
||||||
pSeriesTag['class'] = "series"
|
pSeriesTag['class'] = "series"
|
||||||
pSeriesTag.insert(0,NavigableString(self.NOT_READ_SYMBOL + book['series']))
|
pSeriesTag.insert(0,NavigableString(self.NOT_READ_SYMBOL + '%s Series' % book['series']))
|
||||||
divTag.insert(dtc,pSeriesTag)
|
divTag.insert(dtc,pSeriesTag)
|
||||||
dtc += 1
|
dtc += 1
|
||||||
if current_series and not book['series']:
|
if current_series and not book['series']:
|
||||||
@ -2046,7 +2047,7 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
current_series = new_entry['series']
|
current_series = new_entry['series']
|
||||||
pSeriesTag = Tag(soup,'p')
|
pSeriesTag = Tag(soup,'p')
|
||||||
pSeriesTag['class'] = "series"
|
pSeriesTag['class'] = "series"
|
||||||
pSeriesTag.insert(0,NavigableString(self.NOT_READ_SYMBOL + new_entry['series']))
|
pSeriesTag.insert(0,NavigableString(self.NOT_READ_SYMBOL + '%s Series' % new_entry['series']))
|
||||||
divTag.insert(dtc,pSeriesTag)
|
divTag.insert(dtc,pSeriesTag)
|
||||||
dtc += 1
|
dtc += 1
|
||||||
if current_series and not new_entry['series']:
|
if current_series and not new_entry['series']:
|
||||||
@ -2186,8 +2187,8 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
nspt = deepcopy(self.booksByTitle)
|
nspt = deepcopy(self.booksByTitle)
|
||||||
for book in nspt:
|
for book in nspt:
|
||||||
if book['series']:
|
if book['series']:
|
||||||
tokens = book['title'].split(': ')
|
tokens = book['title'].partition(':')
|
||||||
book['title'] = '%s (%s)' % (tokens[1], tokens[0])
|
book['title'] = '%s (%s)' % (tokens[2].strip(), tokens[0])
|
||||||
book['title_sort'] = self.generateSortTitle(book['title'])
|
book['title_sort'] = self.generateSortTitle(book['title'])
|
||||||
self.booksByDateRange = sorted(nspt, key=lambda x:(x['timestamp'], x['timestamp']),reverse=True)
|
self.booksByDateRange = sorted(nspt, key=lambda x:(x['timestamp'], x['timestamp']),reverse=True)
|
||||||
|
|
||||||
@ -2683,22 +2684,7 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
# HTML files - add books to manifest and spine
|
# HTML files - add books to manifest and spine
|
||||||
sort_descriptions_by = self.booksByAuthor if self.opts.sort_descriptions_by_author \
|
sort_descriptions_by = self.booksByAuthor if self.opts.sort_descriptions_by_author \
|
||||||
else self.booksByTitle
|
else self.booksByTitle
|
||||||
for book in sort_descriptions_by:
|
# Add html_files to manifest and spine
|
||||||
# manifest
|
|
||||||
itemTag = Tag(soup, "item")
|
|
||||||
itemTag['href'] = "content/book_%d.html" % int(book['id'])
|
|
||||||
itemTag['id'] = "book%d" % int(book['id'])
|
|
||||||
itemTag['media-type'] = "application/xhtml+xml"
|
|
||||||
manifest.insert(mtc, itemTag)
|
|
||||||
mtc += 1
|
|
||||||
|
|
||||||
# spine
|
|
||||||
itemrefTag = Tag(soup, "itemref")
|
|
||||||
itemrefTag['idref'] = "book%d" % int(book['id'])
|
|
||||||
spine.insert(stc, itemrefTag)
|
|
||||||
stc += 1
|
|
||||||
|
|
||||||
# Add other html_files to manifest and spine
|
|
||||||
|
|
||||||
for file in self.htmlFileList:
|
for file in self.htmlFileList:
|
||||||
itemTag = Tag(soup, "item")
|
itemTag = Tag(soup, "item")
|
||||||
@ -2734,6 +2720,21 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
spine.insert(stc, itemrefTag)
|
spine.insert(stc, itemrefTag)
|
||||||
stc += 1
|
stc += 1
|
||||||
|
|
||||||
|
for book in sort_descriptions_by:
|
||||||
|
# manifest
|
||||||
|
itemTag = Tag(soup, "item")
|
||||||
|
itemTag['href'] = "content/book_%d.html" % int(book['id'])
|
||||||
|
itemTag['id'] = "book%d" % int(book['id'])
|
||||||
|
itemTag['media-type'] = "application/xhtml+xml"
|
||||||
|
manifest.insert(mtc, itemTag)
|
||||||
|
mtc += 1
|
||||||
|
|
||||||
|
# spine
|
||||||
|
itemrefTag = Tag(soup, "itemref")
|
||||||
|
itemrefTag['idref'] = "book%d" % int(book['id'])
|
||||||
|
spine.insert(stc, itemrefTag)
|
||||||
|
stc += 1
|
||||||
|
|
||||||
# Guide
|
# Guide
|
||||||
referenceTag = Tag(soup, "reference")
|
referenceTag = Tag(soup, "reference")
|
||||||
referenceTag['type'] = 'masthead'
|
referenceTag['type'] = 'masthead'
|
||||||
@ -2821,15 +2822,15 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
navLabelTag = Tag(ncx_soup, "navLabel")
|
navLabelTag = Tag(ncx_soup, "navLabel")
|
||||||
textTag = Tag(ncx_soup, "text")
|
textTag = Tag(ncx_soup, "text")
|
||||||
if book['series']:
|
if book['series']:
|
||||||
tokens = book['title'].split(': ')
|
tokens = list(book['title'].partition(':'))
|
||||||
if self.generateForKindle:
|
if self.generateForKindle:
|
||||||
# Don't include Author for Kindle
|
# Don't include Author for Kindle
|
||||||
textTag.insert(0, NavigableString(self.formatNCXText('%s (%s)' % \
|
textTag.insert(0, NavigableString(self.formatNCXText('%s (%s)' % \
|
||||||
(tokens[1], tokens[0]), dest='title')))
|
(tokens[2].strip(), tokens[0]), dest='title')))
|
||||||
else:
|
else:
|
||||||
# Include Author for non-Kindle
|
# Include Author for non-Kindle
|
||||||
textTag.insert(0, NavigableString(self.formatNCXText('%s · %s (%s)' % \
|
textTag.insert(0, NavigableString(self.formatNCXText('%s · %s (%s)' % \
|
||||||
(tokens[1], book['author'], tokens[0]), dest='title')))
|
(tokens[2].strip(), book['author'], tokens[0]), dest='title')))
|
||||||
else:
|
else:
|
||||||
if self.generateForKindle:
|
if self.generateForKindle:
|
||||||
# Don't include Author for Kindle
|
# Don't include Author for Kindle
|
||||||
@ -3752,7 +3753,7 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
current_series = book['series']
|
current_series = book['series']
|
||||||
pSeriesTag = Tag(soup,'p')
|
pSeriesTag = Tag(soup,'p')
|
||||||
pSeriesTag['class'] = "series"
|
pSeriesTag['class'] = "series"
|
||||||
pSeriesTag.insert(0,NavigableString(self.NOT_READ_SYMBOL + book['series']))
|
pSeriesTag.insert(0,NavigableString(self.NOT_READ_SYMBOL + '%s Series' % book['series']))
|
||||||
divTag.insert(dtc,pSeriesTag)
|
divTag.insert(dtc,pSeriesTag)
|
||||||
dtc += 1
|
dtc += 1
|
||||||
|
|
||||||
@ -3897,7 +3898,7 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p class="title"></p>
|
<p class="title"></p>
|
||||||
<div class="hr"><blockquote><hr/></blockquote></div>
|
<!--div class="hr"><blockquote><hr/></blockquote></div-->
|
||||||
<div class="authors"></div>
|
<div class="authors"></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -4231,6 +4232,7 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
op = opts.output_profile
|
op = opts.output_profile
|
||||||
if op is None:
|
if op is None:
|
||||||
op = 'default'
|
op = 'default'
|
||||||
|
|
||||||
if opts.connected_device['name'] and 'kindle' in opts.connected_device['name'].lower():
|
if opts.connected_device['name'] and 'kindle' in opts.connected_device['name'].lower():
|
||||||
opts.connected_kindle = True
|
opts.connected_kindle = True
|
||||||
if opts.connected_device['serial'] and opts.connected_device['serial'][:4] in ['B004','B005']:
|
if opts.connected_device['serial'] and opts.connected_device['serial'][:4] in ['B004','B005']:
|
||||||
@ -4256,7 +4258,8 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
opts.exclude_genre = '\[^.\]'
|
opts.exclude_genre = '\[^.\]'
|
||||||
build_log.append(" converting empty exclude_genre to '\[^.\]'")
|
build_log.append(" converting empty exclude_genre to '\[^.\]'")
|
||||||
|
|
||||||
if opts.connected_device['name']:
|
if opts.connected_device['is_device_connected'] and \
|
||||||
|
opts.connected_device['kind'] == 'device':
|
||||||
if opts.connected_device['serial']:
|
if opts.connected_device['serial']:
|
||||||
build_log.append(u" connected_device: '%s' #%s%s " % \
|
build_log.append(u" connected_device: '%s' #%s%s " % \
|
||||||
(opts.connected_device['name'],
|
(opts.connected_device['name'],
|
||||||
@ -4270,6 +4273,8 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
for storage in opts.connected_device['storage']:
|
for storage in opts.connected_device['storage']:
|
||||||
if storage:
|
if storage:
|
||||||
build_log.append(u" mount point: %s" % storage)
|
build_log.append(u" mount point: %s" % storage)
|
||||||
|
else:
|
||||||
|
build_log.append(u" connected_device: '%s'" % opts.connected_device['name'])
|
||||||
|
|
||||||
opts_dict = vars(opts)
|
opts_dict = vars(opts)
|
||||||
if opts_dict['ids']:
|
if opts_dict['ids']:
|
||||||
|
@ -672,7 +672,14 @@ def command_catalog(args, dbpath):
|
|||||||
|
|
||||||
# No support for connected device in CLI environment
|
# No support for connected device in CLI environment
|
||||||
# Parallel initialization in calibre.gui2.tools:generate_catalog()
|
# Parallel initialization in calibre.gui2.tools:generate_catalog()
|
||||||
opts.connected_device = { 'storage':None,'serial':None,'save_template':None,'name':None}
|
opts.connected_device = {
|
||||||
|
'is_device_connected': False,
|
||||||
|
'kind': device_manager.connected_device_kind,
|
||||||
|
'name': None,
|
||||||
|
'save_template': None,
|
||||||
|
'serial': None,
|
||||||
|
'storage': None,
|
||||||
|
}
|
||||||
|
|
||||||
with plugin:
|
with plugin:
|
||||||
plugin.run(args[1], opts, get_db(dbpath, opts))
|
plugin.run(args[1], opts, get_db(dbpath, opts))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user