Add completion for author and publisher fields in edit metadata dialog. Fixes #1383 (useful feature ideas) and #1521

This commit is contained in:
Kovid Goyal 2009-01-02 16:43:21 -08:00
parent 944435fd2f
commit e41f8b3a70
5 changed files with 64 additions and 33 deletions

View File

@ -1,5 +1,5 @@
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
__copyright__ = '2009, John Schember <john at nachtimwald.com'
'''
'''
@ -22,7 +22,7 @@ class Book(object):
@apply
def thumbnail():
return 0
return None
def __str__(self):
""" Return a utf-8 encoded string with title author and path information """
@ -37,11 +37,10 @@ class BookList(_BookList):
self.return_books(mountpath)
def return_books(self, mountpath):
books = [];
for path, dirs, files in os.walk(os.path.join(mountpath, EBOOK_DIR)):
for book_type in EBOOK_TYPES:
for filename in fnmatch.filter(files, '*.%s' % (book_type)):
self.append(Book(os.path.join(path, filename), filename, ""))
self.append(Book(os.path.join(path, filename), filename, ""))
def add_book(self, path, title):
self.append(Book(path, title, ""))

View File

@ -1,5 +1,5 @@
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
__copyright__ = '2009, John Schember <john at nachtimwald.com'
'''
Device driver for Bookeen's Cybook Gen 3

View File

@ -7,7 +7,7 @@ add/remove formats
import os
from PyQt4.QtCore import SIGNAL, QObject, QCoreApplication, Qt
from PyQt4.QtGui import QPixmap, QListWidgetItem, QErrorMessage, QDialog
from PyQt4.QtGui import QPixmap, QListWidgetItem, QErrorMessage, QDialog, QCompleter
from calibre.gui2 import qstring_to_unicode, error_dialog, file_icon_provider, \
@ -33,6 +33,13 @@ class Format(QListWidgetItem):
QListWidgetItem.__init__(self, file_icon_provider().icon_from_ext(ext),
text, parent, QListWidgetItem.UserType)
class AuthorCompleter(QCompleter):
def __init__(self, db):
all_authors = db.all_authors()
all_authors.sort(cmp=lambda x, y : cmp(x[1], y[1]))
QCompleter.__init__(self, [x[1] for x in all_authors])
class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
def do_reset_cover(self, *args):
@ -171,6 +178,8 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
self.cover_changed = False
self.cpixmap = None
self.cover.setAcceptDrops(True)
self._author_completer = AuthorCompleter(self.db)
self.authors.setCompleter(self._author_completer)
self.connect(self.cover, SIGNAL('cover_changed()'), self.cover_dropped)
QObject.connect(self.cover_button, SIGNAL("clicked(bool)"), \
self.select_cover)
@ -206,8 +215,6 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
self.authors.setText('')
aus = self.db.author_sort(row)
self.author_sort.setText(aus if aus else '')
pub = self.db.publisher(row)
self.publisher.setText(pub if pub else '')
tags = self.db.tags(row)
self.tags.setText(tags if tags else '')
rating = self.db.rating(row)
@ -226,7 +233,8 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
size = self.db.sizeof_format(row, ext)
Format(self.formats, ext, size)
self.initialize_series()
self.initialize_series_and_publisher()
self.series_index.setValue(self.db.series_index(row))
QObject.connect(self.series, SIGNAL('currentIndexChanged(int)'), self.enable_series_index)
@ -259,7 +267,7 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
def cover_dropped(self):
self.cover_changed = True
def initialize_series(self):
def initialize_series_and_publisher(self):
all_series = self.db.all_series()
all_series.sort(cmp=lambda x, y : cmp(x[1], y[1]))
series_id = self.db.series_id(self.row)
@ -283,6 +291,22 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
l.invalidate()
l.activate()
all_publishers = self.db.all_publishers()
all_publishers.sort(cmp=lambda x, y : cmp(x[1], y[1]))
publisher_id = self.db.publisher_id(self.row)
idx, c = None, 0
for i in all_publishers:
id, name = i
if id == publisher_id:
idx = c
self.publisher.addItem(name)
c += 1
self.publisher.setEditText('')
if idx is not None:
self.publisher.setCurrentIndex(idx)
self.layout().activate()
def edit_tags(self):
@ -337,7 +361,7 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
isbn = qstring_to_unicode(self.isbn.text())
title = qstring_to_unicode(self.title.text())
author = string_to_authors(unicode(self.authors.text()))[0]
publisher = qstring_to_unicode(self.publisher.text())
publisher = qstring_to_unicode(self.publisher.currentText())
if isbn or title or author or publisher:
d = FetchMetadata(self, isbn, title, author, publisher, self.timeout)
d.exec_()
@ -347,7 +371,7 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
self.title.setText(book.title)
self.authors.setText(authors_to_string(book.authors))
if book.author_sort: self.author_sort.setText(book.author_sort)
if book.publisher: self.publisher.setText(book.publisher)
if book.publisher: self.publisher.setEditText(book.publisher)
if book.isbn: self.isbn.setText(book.isbn)
summ = book.comments
if summ:
@ -386,7 +410,7 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
self.db.set_author_sort(self.id, aus, notify=False)
self.db.set_isbn(self.id, qstring_to_unicode(self.isbn.text()), notify=False)
self.db.set_rating(self.id, 2*self.rating.value(), notify=False)
self.db.set_publisher(self.id, qstring_to_unicode(self.publisher.text()), notify=False)
self.db.set_publisher(self.id, qstring_to_unicode(self.publisher.currentText()), notify=False)
self.db.set_tags(self.id, qstring_to_unicode(self.tags.text()).split(','), notify=False)
self.db.set_series(self.id, qstring_to_unicode(self.series.currentText()), notify=False)
self.db.set_series_index(self.id, self.series_index.value(), notify=False)

View File

@ -95,13 +95,6 @@
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="authors" >
<property name="toolTip" >
<string>Change the author(s) of this book. Multiple authors should be separated by an &amp;. If the author name contains an &amp;, use &amp;&amp; to represent it.</string>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="label_8" >
<property name="text" >
@ -111,7 +104,7 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy" >
<cstring>authors</cstring>
<cstring>author_sort</cstring>
</property>
</widget>
</item>
@ -185,13 +178,6 @@
</property>
</widget>
</item>
<item row="4" column="1" colspan="2" >
<widget class="QLineEdit" name="publisher" >
<property name="toolTip" >
<string>Change the publisher of this book</string>
</property>
</widget>
</item>
<item row="5" column="0" >
<widget class="QLabel" name="label_4" >
<property name="text" >
@ -330,6 +316,16 @@
<item row="8" column="1" colspan="2" >
<widget class="QLineEdit" name="isbn" />
</item>
<item row="4" column="1" >
<widget class="QComboBox" name="publisher" >
<property name="editable" >
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="authors" />
</item>
</layout>
</widget>
</item>
@ -615,8 +611,8 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>257</x>
<y>646</y>
<x>261</x>
<y>710</y>
</hint>
<hint type="destinationlabel" >
<x>157</x>
@ -631,8 +627,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>325</x>
<y>646</y>
<x>329</x>
<y>710</y>
</hint>
<hint type="destinationlabel" >
<x>286</x>

View File

@ -944,6 +944,10 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
return self.conn.get('SELECT publisher FROM meta WHERE id=?', (index,), all=False)
return self.data[index][3]
def publisher_id(self, index, index_is_id=False):
id = index if index_is_id else self.id(index)
return self.conn.get('SELECT publisher from books_publishers_link WHERE book=?', (id,), all=False)
def rating(self, index, index_is_id=False):
if index_is_id:
return self.conn.get('SELECT rating FROM meta WHERE id=?', (index,), all=False)
@ -1042,6 +1046,14 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
return [ (i[0], i[1]) for i in \
self.conn.get('SELECT id, name FROM series')]
def all_authors(self):
return [ (i[0], i[1]) for i in \
self.conn.get('SELECT id, name FROM authors')]
def all_publishers(self):
return [ (i[0], i[1]) for i in \
self.conn.get('SELECT id, name FROM publishers')]
def all_tags(self):
return [i[0].strip() for i in self.conn.get('SELECT name FROM tags') if i[0].strip()]