Merge from trunk

This commit is contained in:
Charles Haley 2010-09-21 19:59:49 +01:00
commit 1bfccfa4c4
5 changed files with 16 additions and 19 deletions

View File

@ -40,8 +40,7 @@ class TweakEpubAction(InterfaceAction):
_('No ePub available. First convert the book to ePub.'),
show=True)
# Launch a modal dialog waiting for user to complete or cancel
# Launch modal dialog waiting for user to tweak or cancel
dlg = TweakEpub(self.gui, path_to_epub)
if dlg.exec_() == dlg.Accepted:
self.update_db(book_id, dlg._output)

View File

@ -21,8 +21,6 @@ class TweakEpub(QDialog, Ui_Dialog):
'''
Display controls for tweaking ePubs
To do:
- need way to kill file browser proc in cleanup()
'''
def __init__(self, parent, epub):
@ -30,7 +28,6 @@ class TweakEpub(QDialog, Ui_Dialog):
self._epub = epub
self._exploded = None
#self._file_browser_proc = None
self._output = None
# Run the dialog setup generated from tweak_epub.ui

View File

@ -32,7 +32,7 @@
<string>&amp;Explode ePub</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/wizard.png</normaloff>:/images/wizard.png</iconset>
</property>
</widget>
@ -49,7 +49,7 @@
<string>&amp;Rebuild ePub</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/exec.png</normaloff>:/images/exec.png</iconset>
</property>
</widget>
@ -63,7 +63,7 @@
<string>&amp;Cancel</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<iconset>
<normaloff>:/images/window-close.png</normaloff>:/images/window-close.png</iconset>
</property>
</widget>
@ -71,7 +71,7 @@
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>First, explode the epub. Then edit is contents by right clicking on the individual files and selecting the editor of your choice. When you are done, click rebuild epub and the epub in your calibre library will be updated with the changes you have made.</string>
<string>Explode the ePub to display contents in a file browser window. To tweak individual files, right-click, then 'Open with...' your editor of choice. When tweaks are complete, close the file browser window. Rebuild the ePub, updating your calibre library.</string>
</property>
<property name="wordWrap">
<bool>true</bool>

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import re, itertools
import re, itertools, time
from itertools import repeat
from datetime import timedelta
from threading import Thread, RLock
@ -38,7 +38,6 @@ class CoverCache(Thread):
self.keep_running = False
def _image_for_id(self, id_):
import time
time.sleep(0.050) # Limit 20/second to not overwhelm the GUI
img = self.cover_func(id_, index_is_id=True, as_image=True)
if img is None:

View File

@ -437,7 +437,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
if current_path and os.path.exists(spath): # Migrate existing files
cdata = self.cover(id, index_is_id=True)
if cdata is not None:
open(os.path.join(tpath, 'cover.jpg'), 'wb').write(cdata)
with open(os.path.join(tpath, 'cover.jpg'), 'wb') as f:
f.write(cdata)
for format in formats:
# Get data as string (can't use file as source and target files may be the same)
f = self.format(id, format, index_is_id=True, as_file=False)
@ -447,7 +448,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
self.add_format(id, format, stream, index_is_id=True,
path=tpath, notify=False)
self.conn.execute('UPDATE books SET path=? WHERE id=?', (path, id))
self.conn.commit()
self.data.set(id, self.FIELD_MAP['path'], path, row_is_id=True)
# Delete not needed directories
if current_path and os.path.exists(spath):
@ -551,10 +551,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
return self.field_metadata.sortable_field_keys()
def searchable_fields(self):
return self.field_metadata.searchable_fields()
return self.field_metadata.searchable_field_keys()
def search_term_to_field_key(self, term):
return self.field_metadata.search_term_to_field_key(term)
return self.field_metadata.search_term_to_key(term)
def metadata_for_field(self, key):
return self.field_metadata[key]
@ -1211,7 +1211,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
result.append(r)
return ' & '.join(result).replace('|', ',')
def set_authors(self, id, authors, notify=True):
def set_authors(self, id, authors, notify=True, commit=True):
'''
`authors`: A list of authors.
'''
@ -1239,7 +1239,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
ss = self.author_sort_from_book(id, index_is_id=True)
self.conn.execute('UPDATE books SET author_sort=? WHERE id=?',
(ss, id))
self.conn.commit()
if commit:
self.conn.commit()
self.data.set(id, self.FIELD_MAP['authors'],
','.join([a.replace(',', '|') for a in authors]),
row_is_id=True)
@ -1248,7 +1249,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
if notify:
self.notify('metadata', [id])
def set_title(self, id, title, notify=True):
def set_title(self, id, title, notify=True, commit=True):
if not title:
return
if not isinstance(title, unicode):
@ -1260,7 +1261,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
else:
self.data.set(id, self.FIELD_MAP['sort'], title, row_is_id=True)
self.set_path(id, index_is_id=True)
self.conn.commit()
if commit:
self.conn.commit()
if notify:
self.notify('metadata', [id])