Fix cover not being detected for HTML RARballs. Plug possible hole in books database implementation. Add initial device job support to gui2.

This commit is contained in:
Kovid Goyal 2007-06-26 20:15:10 +00:00
parent 2ed012f023
commit fe2e72d699
10 changed files with 62 additions and 49 deletions

View File

@ -13,7 +13,7 @@
## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
''' E-book management software'''
__version__ = "0.3.56"
__version__ = "0.3.57"
__docformat__ = "epytext"
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
__appname__ = 'libprs500'

View File

@ -57,7 +57,7 @@ class Book(object):
size = book_metadata_field("size", formatter=int)
# When setting this attribute you must use an epoch
datetime = book_metadata_field("date", \
formatter=lambda x: time.strptime(x, "%a, %d %b %Y %H:%M:%S %Z"),
formatter=lambda x: time.strptime(x.strip(), "%a, %d %b %Y %H:%M:%S %Z"),
setter=lambda x: time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(x)))
@apply

View File

@ -1212,11 +1212,15 @@ def try_opf(path, options):
isbn.append((scheme, item.string))
if not options.cover:
for item in isbn:
matches = glob.glob(re.sub('-', '', item[1])+'.*')
src = item[1].replace('-', '')
matches = glob.glob(os.path.join(os.path.dirname(path), src+'.*'))
for match in matches:
if match.lower().endswith('.jpeg') or match.lower().endswith('.jpg') or \
match.lower().endswith('.gif') or match.lower().endswith('.png'):
test = os.path.splitext(match)[1].lower()
if test in ['.jpeg', '.jpg', '.gif', '.png']:
options.cover = match
break
if not options.cover:
# Search for cover image in opf as created by convertlit
ref = soup.package.find('reference', {'type':'other.ms-coverimage-standard'})

View File

@ -47,7 +47,7 @@ def Error(msg, e):
error_dialog.showMessage(msg)
error_dialog.show()
def human_readable(cls, size):
def human_readable(size):
""" Convert a size in bytes into a human readable form """
if size < 1024:
divisor, suffix = 1, "B"

View File

@ -88,19 +88,18 @@ class DeviceManager(QObject):
def get_info_func(self):
''' Return callable that returns device information and free space on device'''
def get_device_information(updater):
self.device.set_updater(updater)
self.device.set_progress_reporter(updater)
info = self.device.get_device_information(end_session=False)
info = {'name':info[0], 'version':info[1], 'swversion':[2], 'mimetype':info[3]}
info = [i.replace('\x00', '').replace('\x01', '') for i in info]
cp = self.device.card_prefix(end_session=False)
fs = self.device.free_space()
fs = {'main':fs[0], 'carda':fs[1], 'cardb':fs[2]}
return info, cp, fs
return get_device_information
def books_func(self):
'''Return callable that returns the list of books on device as two booklists'''
def books(updater):
self.device.set_updater(updater)
self.device.set_progress_reporter(updater)
mainlist = self.device.books(oncard=False, end_session=False)
cardlist = self.device.books(oncard=True)
return mainlist, cardlist

View File

@ -39,7 +39,10 @@ class Main(QObject, Ui_MainWindow):
self.job_manager = JobManager()
self.device_manager = None
self.temporary_slots = {}
self.df.setText(self.df.text().arg(VERSION))
####################### Vanity ########################
self.vanity_template = self.vanity.text().arg(VERSION)
self.vanity.setText(self.vanity_template.arg(' '))
####################### Status Bar #####################
self.status_bar = StatusBar()
@ -64,18 +67,25 @@ class Main(QObject, Ui_MainWindow):
self.detector.start(QThread.InheritPriority)
def job_exception(self, id, exception, formatted_traceback):
raise JobException, str(exception) + '\n\r' + formatted_traceback
def device_detected(self, cls, connected):
if connected:
def info_read(id, result, exception, formatted_traceback):
if exception:
pass #TODO: Handle error
info, cp, fs = result
print self, id, result, exception, formatted_traceback
self.temporary_slots['device_info_read'] = info_read
self.device_manager = DeviceManager(cls)
func = self.device_manager.get_info_func()
self.job_manager.run_device_job(info_read, func)
self.job_manager.run_device_job(self.info_read, func)
def info_read(self, id, result, exception, formatted_traceback):
if exception:
self.job_exception(id, exception, formatted_traceback)
return
info, cp, fs = result
self.location_view.model().update_devices(cp, fs)
self.vanity.setText(self.vanity_template.arg('Connected '+' '.join(info[:-1])))
def read_settings(self):

View File

@ -42,7 +42,7 @@
<number>0</number>
</property>
<item>
<widget class="LocationView" name="device_tree" >
<widget class="LocationView" name="location_view" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
@ -76,7 +76,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="df" >
<widget class="QLabel" name="vanity" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
@ -90,7 +90,7 @@
</size>
</property>
<property name="text" >
<string>For help visit &lt;a href="https://libprs500.kovidgoyal.net/wiki/GuiUsage">http://libprs500.kovidgoyal.net&lt;/a>&lt;br>&lt;br>&lt;b>libprs500&lt;/b>: %1 by &lt;b>Kovid Goyal&lt;/b> &amp;copy; 2007&lt;br>%2 %3 %4</string>
<string>For help visit &lt;a href="https://libprs500.kovidgoyal.net/wiki/GuiUsage">http://libprs500.kovidgoyal.net&lt;/a>&lt;br>&lt;br>&lt;b>libprs500&lt;/b>: %1 by &lt;b>Kovid Goyal&lt;/b> &amp;copy; 2007&lt;br>%2</string>
</property>
<property name="textFormat" >
<enum>Qt::RichText</enum>

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'main.ui'
#
# Created: Thu Jun 21 20:31:43 2007
# Created: Fri Jun 22 16:40:15 2007
# by: PyQt4 UI code generator 4-snapshot-20070606
#
# WARNING! All changes made in this file will be lost!
@ -32,35 +32,35 @@ class Ui_MainWindow(object):
self.hboxlayout.setMargin(0)
self.hboxlayout.setObjectName("hboxlayout")
self.device_tree = LocationView(self.centralwidget)
self.location_view = LocationView(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.device_tree.sizePolicy().hasHeightForWidth())
self.device_tree.setSizePolicy(sizePolicy)
self.device_tree.setMaximumSize(QtCore.QSize(10000,90))
self.device_tree.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.device_tree.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.device_tree.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
self.device_tree.setFlow(QtGui.QListView.TopToBottom)
self.device_tree.setSpacing(20)
self.device_tree.setViewMode(QtGui.QListView.IconMode)
self.device_tree.setObjectName("device_tree")
self.hboxlayout.addWidget(self.device_tree)
sizePolicy.setHeightForWidth(self.location_view.sizePolicy().hasHeightForWidth())
self.location_view.setSizePolicy(sizePolicy)
self.location_view.setMaximumSize(QtCore.QSize(10000,90))
self.location_view.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.location_view.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.location_view.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
self.location_view.setFlow(QtGui.QListView.TopToBottom)
self.location_view.setSpacing(20)
self.location_view.setViewMode(QtGui.QListView.IconMode)
self.location_view.setObjectName("location_view")
self.hboxlayout.addWidget(self.location_view)
self.df = QtGui.QLabel(self.centralwidget)
self.vanity = QtGui.QLabel(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.df.sizePolicy().hasHeightForWidth())
self.df.setSizePolicy(sizePolicy)
self.df.setMaximumSize(QtCore.QSize(16777215,90))
self.df.setTextFormat(QtCore.Qt.RichText)
self.df.setOpenExternalLinks(True)
self.df.setObjectName("df")
self.hboxlayout.addWidget(self.df)
sizePolicy.setHeightForWidth(self.vanity.sizePolicy().hasHeightForWidth())
self.vanity.setSizePolicy(sizePolicy)
self.vanity.setMaximumSize(QtCore.QSize(16777215,90))
self.vanity.setTextFormat(QtCore.Qt.RichText)
self.vanity.setOpenExternalLinks(True)
self.vanity.setObjectName("vanity")
self.hboxlayout.addWidget(self.vanity)
self.gridlayout.addLayout(self.hboxlayout,0,0,1,1)
self.hboxlayout1 = QtGui.QHBoxLayout()
@ -184,7 +184,7 @@ class Ui_MainWindow(object):
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "libprs500", None, QtGui.QApplication.UnicodeUTF8))
self.df.setText(QtGui.QApplication.translate("MainWindow", "For help visit <a href=\"https://libprs500.kovidgoyal.net/wiki/GuiUsage\">http://libprs500.kovidgoyal.net</a><br><br><b>libprs500</b>: %1 by <b>Kovid Goyal</b> &copy; 2007<br>%2 %3 %4", None, QtGui.QApplication.UnicodeUTF8))
self.vanity.setText(QtGui.QApplication.translate("MainWindow", "For help visit <a href=\"https://libprs500.kovidgoyal.net/wiki/GuiUsage\">http://libprs500.kovidgoyal.net</a><br><br><b>libprs500</b>: %1 by <b>Kovid Goyal</b> &copy; 2007<br>%2", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("MainWindow", "&Search:", None, QtGui.QApplication.UnicodeUTF8))
self.search.setToolTip(QtGui.QApplication.translate("MainWindow", "Search the list of books by title or author<br><br>Words separated by spaces are ANDed", None, QtGui.QApplication.UnicodeUTF8))
self.search.setWhatsThis(QtGui.QApplication.translate("MainWindow", "Search the list of books by title, author, publisher, tags and comments<br><br>Words separated by spaces are ANDed", None, QtGui.QApplication.UnicodeUTF8))

View File

@ -45,7 +45,7 @@ class LocationModel(QAbstractListModel):
data = self.icons[row]
elif role == Qt.SizeHintRole:
if row == 1:
return QVariant(QSize(150, 70))
return QVariant(QSize(150, 65))
elif role == Qt.FontRole:
font = QFont()
font.setBold(True)
@ -55,13 +55,13 @@ class LocationModel(QAbstractListModel):
def headerData(self, section, orientation, role):
return NONE
def update_devices(self, cp, fs):
def update_devices(self, cp=None, fs=[-1, -1, -1]):
self.free[0] = fs[0]
self.free[1] = max(fs[1:])
if cp == None:
self.free[1] = -1
self.emit(SIGNAL("dataChanged(QModelIndex, QModelIndex)"),
self.index(1), self.index(2))
print self.free, self.rowCount(None)
self.reset()
class LocationView(QListView):

View File

@ -31,10 +31,9 @@ def build_windows():
vm.loginInGuest('kovid', 'et tu brutus')
vm.loginInGuest(VIX_CONSOLE_USER_NAME, '')
vm.runProgramInGuest('C:\\Users\kovid\Desktop\libprs500.bat', '')
vm.runProgramInGuest('C:\Windows\system32\shutdown.exe', '/s')
if not glob.glob('dist/*.exe'):
raise Exception('Windows build has failed')
vm.runProgramInGuest('C:\Windows\system32\shutdown.exe', '/s')
return os.path.basename(glob.glob('dist/*.exe')[-1])
def build_osx():
@ -53,6 +52,7 @@ def build_osx():
c -= 10
if c%60==0:
print c/60, ',',
sys.stdout.flush()
print
if not os.path.exists('dist/dmgdone'):