Various minor bug fixes. Fixed dragging from library to device that had been broken by a previous commit. Improved device detection code. Improved rendering of titles/authors. Version bump as there were a lot og bug fixes

This commit is contained in:
Kovid Goyal 2006-12-24 19:01:17 +00:00
parent 695c27d229
commit 599543800c
3 changed files with 77 additions and 48 deletions

View File

@ -37,6 +37,6 @@ the following rule in C{/etc/udev/rules.d/90-local.rules} ::
You may have to adjust the GROUP and the location of the rules file to
suit your distribution.
"""
__version__ = "0.3.0a4"
__version__ = "0.3.0a5"
__docformat__ = "epytext"
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"

View File

@ -64,14 +64,14 @@ class Main(QObject, Ui_MainWindow):
self.device_view.show()
self.library_view.hide()
self.book_cover.setAcceptDrops(False)
self.current_view = self.device_view
self.device_view.resizeColumnsToContents()
self.device_view.resizeRowsToContents()
else:
self.action_add.setEnabled(True)
self.action_edit.setEnabled(True)
self.device_view.hide()
self.library_view.show()
self.book_cover.setAcceptDrops(True)
self.current_view = self.library_view
self.current_view.sortByColumn(3, Qt.DescendingOrder)
@ -96,29 +96,32 @@ class Main(QObject, Ui_MainWindow):
def model_modified(self):
if self.library_view.isVisible(): view = self.library_view
else: view = self.device_view
view.selectionModel().reset()
view.resizeColumnsToContents()
if self.current_view.selectionModel():
self.current_view.selectionModel().reset()
self.current_view.resizeColumnsToContents()
self.current_view.resizeRowsToContents()
self.book_cover.hide()
self.book_info.hide()
QCoreApplication.processEvents(QEventLoop.ExcludeUserInputEvents)
def resize_columns(self, topleft, bottomright):
if self.library_view.isVisible():
view = self.library_view
else: view = self.device_view
def resize_rows_and_columns(self, topleft, bottomright):
for c in range(topleft.column(), bottomright.column()+1):
view.resizeColumnToContents(c)
self.current_view.resizeColumnToContents(c)
for r in range(topleft.row(), bottomright.row()+1):
self.current_view.resizeRowToContents(c)
def show_book(self, current, previous):
if not len(self.current_view.selectedIndexes()):
return
if self.library_view.isVisible():
formats, tags, comments, cover = current.model().info(current.row())
formats, tags, comments, cover = self.library_model\
.info(current.row())
data = LIBRARY_BOOK_TEMPLATE.arg(formats).arg(tags).arg(comments)
tooltip = "To save the cover, drag it to the desktop.<br>To \
change the cover drag the new cover onto this picture"
else:
title, author, size, mime, cover = current.model().info(current.row())
title, author, size, mime, cover = self.device_view.model()\
.info(current.row())
data = DEVICE_BOOK_TEMPLATE.arg(title).arg(size).arg(author).arg(mime)
tooltip = "To save the cover, drag it to the desktop."
self.book_info.setText(data)
@ -194,7 +197,7 @@ class Main(QObject, Ui_MainWindow):
settings.setValue("add books dialog dir", \
QVariant(os.path.dirname(x)))
files = unicode(files.join("|||").toUtf8(), 'utf-8').split("|||")
self.add_books(files)
self.add_books(files)
def add_books(self, files):
self.window.setCursor(Qt.WaitCursor)
@ -256,7 +259,8 @@ class Main(QObject, Ui_MainWindow):
self.library_view.model().update_cover(self.library_view\
.currentIndex(), pix)
self.book_cover.setPixmap(pix)
except Exception, e: Error("Unable to change cover", e)
except Exception, e:
Error("Unable to change cover", e)
def upload_books(self, to, files, ids):
oncard = False if to == "reader" else True
@ -268,8 +272,10 @@ class Main(QObject, Ui_MainWindow):
model = self.card_model if oncard else self.reader_model
model.sort(col, order)
if self.device_view.isVisible() and self.device_view.model()\
== model: self.search.clear()
else: model.search("")
== model:
self.search.clear()
else:
model.search("")
def sync_lists():
self.status("Syncing media list to device main memory")
@ -299,7 +305,8 @@ class Main(QObject, Ui_MainWindow):
str(_buffer.buffer()))
ename = info["title"]
for f in files:
if re.match("......_"+str(_id)+"_", os.path.basename(f)):
if re.match("libprs500_\S+_......_" + \
str(_id) + "_", os.path.basename(f)):
formats.append(f)
_file = None
try:
@ -358,6 +365,14 @@ class Main(QObject, Ui_MainWindow):
self.window.setCursor(Qt.ArrowCursor)
self.update_availabe_space()
@apply
def current_view():
doc = """ The currently visible view """
def fget(self):
return self.library_view if self.library_view.isVisible() \
else self.device_view
return property(doc=doc, fget=fget)
def __init__(self, window, log_packets):
QObject.__init__(self)
Ui_MainWindow.__init__(self)
@ -373,25 +388,26 @@ class Main(QObject, Ui_MainWindow):
self.library_model = LibraryBooksModel(window)
self.library_model.set_data(LibraryDatabase(str(self.database_path)))
self.library_view.setModel(self.library_model)
self.current_view = self.library_view
QObject.connect(self.library_model, SIGNAL("layoutChanged()"), \
self.library_view.resizeRowsToContents)
QObject.connect(self.library_view.selectionModel(), \
SIGNAL("currentChanged(QModelIndex, QModelIndex)"), self.show_book)
QObject.connect(self.search, SIGNAL("textChanged(QString)"), \
self.library_model.search)
QObject.connect(self.library_model, SIGNAL("sorted()"), self.model_modified)
QObject.connect(self.library_model, SIGNAL("sorted()"), \
self.model_modified)
QObject.connect(self.library_model, SIGNAL("searched()"), \
self.model_modified)
QObject.connect(self.library_model, SIGNAL("deleted()"), \
self.model_modified)
QObject.connect(self.library_model, \
SIGNAL("dataChanged(QModelIndex, QModelIndex)"), self.resize_columns)
SIGNAL("dataChanged(QModelIndex, QModelIndex)"), \
self.resize_rows_and_columns)
QObject.connect(self.library_view, \
SIGNAL('books_dropped'), self.add_books)
QObject.connect(self.library_model, \
SIGNAL('formats_added'), self.formats_added)
self.library_view.resizeColumnsToContents()
self.library_view.sortByColumn(3, Qt.DescendingOrder)
# Create Device tree
model = DeviceModel(self.device_tree)
@ -417,8 +433,9 @@ class Main(QObject, Ui_MainWindow):
QObject.connect(model, SIGNAL("sorted()"), self.model_modified)
QObject.connect(model, SIGNAL("searched()"), self.model_modified)
QObject.connect(model, SIGNAL("deleted()"), self.model_modified)
QObject.connect(model, SIGNAL("dataChanged(QModelIndex, QModelIndex)")\
, self.resize_columns)
QObject.connect(model, \
SIGNAL("dataChanged(QModelIndex, QModelIndex)"), \
self.resize_rows_and_columns)
# Setup book display
self.book_cover.hide()
@ -441,17 +458,23 @@ class Main(QObject, Ui_MainWindow):
self.show_device(False)
self.df_template = self.df.text()
self.df.setText(self.df_template.arg("").arg("").arg(""))
window.show()
window.show()
self.library_view.resizeColumnsToContents()
self.library_view.resizeRowsToContents()
def device_removed(self):
""" @todo: only reset stuff if library is not shown """
self.df.setText(self.df_template.arg("").arg("").arg(""))
self.device_tree.hide_reader(True)
self.device_tree.hide_card(True)
self.book_cover.hide()
self.book_info.hide()
self.device_view.hide()
self.library_view.show()
self.device_tree.selectionModel().reset()
if self.device_view.isVisible():
self.device_view.hide()
self.library_view.selectionModel().reset()
self.library_view.show()
self.book_cover.hide()
self.book_info.hide()
def progress(self, val):
if val < 0:
@ -471,12 +494,12 @@ class Main(QObject, Ui_MainWindow):
self.status("Connecting to device")
try:
info = self.dev.get_device_information(end_session=False)
except DeviceBusy, e:
qFatal(str(e))
except DeviceError:
except DeviceBusy, err:
qFatal(str(err))
except DeviceError, err:
self.dev.reconnect()
self.detector.connection_failed()
return
self.thread().msleep(100)
return self.establish_connection()
except ProtocolError, e:
traceback.print_exc(e)
qFatal("Unable to connect to device. Please try unplugging and"+\
@ -522,10 +545,6 @@ class DeviceConnectDetector(QObject):
self.emit(SIGNAL("device_removed()"))
self.is_connected = False
def connection_failed(self):
# TODO: Do something intelligent if we're using HAL
self.is_connected = False
def udi_is_device(self, udi):
ans = False
try:

View File

@ -156,14 +156,17 @@ class FileDragAndDrop(object):
return self.drag_object_from_files(files), self._dragged_files
class TableView(FileDragAndDrop, QTableView):
class TableView(FileDragAndDrop, QTableView):
wrapper = textwrap.TextWrapper(width=20)
def __init__(self, parent):
FileDragAndDrop.__init__(self, QTableView)
QTableView.__init__(self, parent)
@classmethod
def wrap(cls, s, width=20):
return textwrap.fill(s, width)
def wrap(cls, s, width=20):
cls.wrapper.width = 20
return cls.wrapper.fill(s)
@classmethod
def human_readable(cls, size):
@ -452,7 +455,7 @@ class LibraryBooksModel(QAbstractTableModel):
row = index.row()
_id = self._data[row]["id"]
col = index.column()
val = unicode(value.toString().toUtf8(), 'utf-8')
val = unicode(value.toString().toUtf8(), 'utf-8').strip()
if col == 0:
col = "title"
elif col == 1:
@ -567,7 +570,9 @@ class LibraryBooksModel(QAbstractTableModel):
elif col == 1:
au = row["authors"]
if au:
text = TableView.wrap(re.sub("&", "\n", au), width=25)
au = au.split("&")
jau = [ TableView.wrap(a, width=25).strip() for a in au ]
text = "\n".join(jau)
elif col == 2:
text = TableView.human_readable(row["size"])
elif col == 3:
@ -575,7 +580,8 @@ class LibraryBooksModel(QAbstractTableModel):
time.strptime(row["date"], self.TIME_READ_FMT))
elif col == 5:
pub = row["publisher"]
if pub: text = TableView.wrap(pub, 20)
if pub:
text = TableView.wrap(pub, 20)
if text == None:
text = "Unknown"
return QVariant(text)
@ -689,8 +695,11 @@ class DeviceBooksModel(QAbstractTableModel):
book = self._data[row]
if col == 0:
text = TableView.wrap(book.title, width=40)
elif col == 1:
text = re.sub("&\s*", "\n", book.author)
elif col == 1:
au = book.author
au = au.split("&")
jau = [ TableView.wrap(a, width=25).strip() for a in au ]
text = "\n".join(jau)
elif col == 2:
text = TableView.human_readable(book.size)
elif col == 3:
@ -784,7 +793,8 @@ class DeviceModel(QAbstractListModel):
self.emit(SIGNAL("dataChanged(QModelIndex, QModelIndex)"), \
self.index(1), self.index(2))
def rowCount(self, parent): return 3
def rowCount(self, parent):
return 3
def update_free_space(self, reader, card):
self.memory_free = reader