mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Preserve the case of tags
This commit is contained in:
parent
6c307c1b83
commit
07fed161e5
@ -158,27 +158,7 @@ class TableView(QTableView):
|
||||
for i in range(len(self.cw)):
|
||||
self.setColumnWidth(i, self.cw[i])
|
||||
return True
|
||||
|
||||
def set_visible_columns(self, cols=None):
|
||||
'''
|
||||
@param cols: A list of booleans or None. If an entry is False the corresponding column
|
||||
is hidden, if True it is shown.
|
||||
'''
|
||||
key = self.__class__.__name__+'visible columns'
|
||||
if cols:
|
||||
dynamic[key] = cols
|
||||
else:
|
||||
cols = dynamic[key]
|
||||
if not cols:
|
||||
cols = [True for i in range(self.model().columnCount(QModelIndex()))]
|
||||
|
||||
for i in range(len(cols)):
|
||||
hidden = self.isColumnHidden(i)
|
||||
self.setColumnHidden(i, not cols[i])
|
||||
if hidden and cols[i]:
|
||||
self.resizeColumnToContents(i)
|
||||
|
||||
|
||||
class FileIconProvider(QFileIconProvider):
|
||||
|
||||
ICONS = {
|
||||
|
@ -21,7 +21,7 @@ class TagEditor(QDialog, Ui_TagEditor):
|
||||
else:
|
||||
tags = []
|
||||
if tags:
|
||||
tags = [tag.lower().strip() for tag in tags.split(',') if tag.strip()]
|
||||
tags = [tag.strip() for tag in tags.split(',') if tag.strip()]
|
||||
tags.sort()
|
||||
for tag in tags:
|
||||
self.applied_tags.addItem(tag)
|
||||
@ -30,7 +30,7 @@ class TagEditor(QDialog, Ui_TagEditor):
|
||||
|
||||
self.tags = tags
|
||||
|
||||
all_tags = [tag.lower() for tag in self.db.all_tags()]
|
||||
all_tags = [tag for tag in self.db.all_tags()]
|
||||
all_tags = list(set(all_tags))
|
||||
all_tags.sort()
|
||||
for tag in all_tags:
|
||||
@ -98,7 +98,7 @@ class TagEditor(QDialog, Ui_TagEditor):
|
||||
self.available_tags.sortItems()
|
||||
|
||||
def add_tag(self):
|
||||
tags = qstring_to_unicode(self.add_tag_input.text()).lower().split(',')
|
||||
tags = qstring_to_unicode(self.add_tag_input.text()).split(',')
|
||||
for tag in tags:
|
||||
tag = tag.strip()
|
||||
for item in self.available_tags.findItems(tag, Qt.MatchFixedString):
|
||||
|
@ -161,7 +161,7 @@
|
||||
sodipodi:rx="36"
|
||||
sodipodi:cy="92"
|
||||
sodipodi:cx="343.99899"
|
||||
style="fill:url(#linearGradient5167);fill-opacity:1"
|
||||
style="fill-opacity:1"
|
||||
r="36"
|
||||
rx="8.0010004"
|
||||
cx="343.99899"
|
||||
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
@ -1168,19 +1168,6 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE;
|
||||
self.conn.execute('INSERT INTO comments(book,text) VALUES (?,?)', (id, text))
|
||||
self.conn.commit()
|
||||
|
||||
def is_tag_used(self, tag):
|
||||
id = self.conn.get('SELECT id FROM tags WHERE name=?', (tag,), all=False)
|
||||
if not id:
|
||||
return False
|
||||
return bool(self.conn.get('SELECT tag FROM books_tags_link WHERE tag=?',(id,), all=False))
|
||||
|
||||
def delete_tag(self, tag):
|
||||
id = self.conn.get('SELECT id FROM tags WHERE name=?', (tag,), all=False)
|
||||
if id:
|
||||
self.conn.execute('DELETE FROM books_tags_link WHERE tag=?', (id,))
|
||||
self.conn.execute('DELETE FROM tags WHERE id=?', (id,))
|
||||
self.conn.commit()
|
||||
|
||||
def delete_tags(self, tags):
|
||||
for tag in tags:
|
||||
self.delete_tag(tag)
|
||||
|
@ -878,14 +878,22 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
self.conn.execute('DELETE FROM books_tags_link WHERE book=?', (id,))
|
||||
self.conn.execute('DELETE FROM tags WHERE (SELECT COUNT(id) FROM books_tags_link WHERE tag=tags.id) < 1')
|
||||
for tag in set(tags):
|
||||
tag = tag.lower().strip()
|
||||
tag = tag.strip()
|
||||
if not tag:
|
||||
continue
|
||||
if not isinstance(tag, unicode):
|
||||
tag = tag.decode(preferred_encoding, 'replace')
|
||||
t = self.conn.get('SELECT id FROM tags WHERE name=?', (tag,), all=False)
|
||||
if t:
|
||||
tid = t
|
||||
existing_tags = self.all_tags()
|
||||
lt = [t.lower() for t in existing_tags]
|
||||
try:
|
||||
idx = lt.index(tag.lower())
|
||||
except ValueError:
|
||||
idx = -1
|
||||
if idx > -1:
|
||||
etag = existing_tags[idx]
|
||||
tid = self.conn.get('SELECT id FROM tags WHERE name=?', (etag,), all=False)
|
||||
if etag != tag:
|
||||
self.conn.execute('UPDATE tags SET name=? WHERE id=?', (tag, tid))
|
||||
else:
|
||||
tid = self.conn.execute('INSERT INTO tags(name) VALUES(?)', (tag,)).lastrowid
|
||||
|
||||
@ -915,6 +923,29 @@ class LibraryDatabase2(LibraryDatabase):
|
||||
if notify:
|
||||
self.notify('metadata', [id])
|
||||
|
||||
def is_tag_used(self, tag):
|
||||
existing_tags = self.all_tags()
|
||||
lt = [t.lower() for t in existing_tags]
|
||||
try:
|
||||
lt.index(tag.lower())
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
def delete_tag(self, tag):
|
||||
existing_tags = self.all_tags()
|
||||
lt = [t.lower() for t in existing_tags]
|
||||
try:
|
||||
idx = lt.index(tag.lower())
|
||||
except ValueError:
|
||||
idx = -1
|
||||
if idx > -1:
|
||||
id = self.conn.get('SELECT id FROM tags WHERE name=?', (existing_tags[idx],), all=False)
|
||||
if id:
|
||||
self.conn.execute('DELETE FROM books_tags_link WHERE tag=?', (id,))
|
||||
self.conn.execute('DELETE FROM tags WHERE id=?', (id,))
|
||||
self.conn.commit()
|
||||
|
||||
|
||||
def set_series(self, id, series, notify=True):
|
||||
self.conn.execute('DELETE FROM books_series_link WHERE book=?',(id,))
|
||||
|
Loading…
x
Reference in New Issue
Block a user