mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add bulk setting of the rest of the custom column types
This commit is contained in:
parent
2464da207e
commit
d3e2c90a23
@ -403,9 +403,7 @@ class BulkBase(Base):
|
||||
val = self.getter()
|
||||
val = self.normalize_ui_val(val)
|
||||
if val != self.initial_val:
|
||||
for book_id in book_ids:
|
||||
QCoreApplication.processEvents()
|
||||
self.db.set_custom(book_id, val, num=self.col_id, notify=notify)
|
||||
self.db.set_custom_bulk(book_ids, val, num=self.col_id, notify=notify)
|
||||
|
||||
class BulkBool(BulkBase, Bool):
|
||||
pass
|
||||
@ -448,18 +446,21 @@ class BulkSeries(BulkBase):
|
||||
val = self.normalize_ui_val(val)
|
||||
update_indices = self.idx_widget.checkState()
|
||||
if val != '':
|
||||
extras = []
|
||||
next_index = self.db.get_next_cc_series_num_for(val, num=self.col_id)
|
||||
for book_id in book_ids:
|
||||
QCoreApplication.processEvents()
|
||||
if update_indices:
|
||||
if tweaks['series_index_auto_increment'] == 'next':
|
||||
s_index = self.db.get_next_cc_series_num_for\
|
||||
(val, num=self.col_id)
|
||||
s_index = next_index
|
||||
next_index += 1
|
||||
else:
|
||||
s_index = 1.0
|
||||
else:
|
||||
s_index = self.db.get_custom_extra(book_id, num=self.col_id,
|
||||
index_is_id=True)
|
||||
self.db.set_custom(book_id, val, extra=s_index,
|
||||
extras.append(s_index)
|
||||
self.db.set_custom_bulk(book_ids, val, extras=extras,
|
||||
num=self.col_id, notify=notify)
|
||||
|
||||
class RemoveTags(QWidget):
|
||||
@ -540,14 +541,13 @@ class BulkText(BulkBase):
|
||||
add = set([v.strip() for v in txt.split(',')])
|
||||
else:
|
||||
add = set()
|
||||
self.db.set_custom_bulk(book_ids, add=add, remove=remove, num=self.col_id)
|
||||
self.db.set_custom_bulk_multiple(book_ids, add=add, remove=remove,
|
||||
num=self.col_id)
|
||||
else:
|
||||
val = self.getter()
|
||||
val = self.normalize_ui_val(val)
|
||||
if val != self.initial_val:
|
||||
for book_id in book_ids:
|
||||
QCoreApplication.processEvents()
|
||||
self.db.set_custom(book_id, val, num=self.col_id, notify=notify)
|
||||
self.db.set_custom_bulk(book_ids, val, num=self.col_id, notify=notify)
|
||||
|
||||
def getter(self, original_value = None):
|
||||
if self.col_metadata['is_multiple']:
|
||||
|
@ -313,7 +313,7 @@ class CustomColumns(object):
|
||||
self.conn.commit()
|
||||
return changed
|
||||
|
||||
def set_custom_bulk(self, ids, add=[], remove=[],
|
||||
def set_custom_bulk_multiple(self, ids, add=[], remove=[],
|
||||
label=None, num=None, notify=False):
|
||||
'''
|
||||
Fast algorithm for updating custom column is_multiple datatypes.
|
||||
@ -394,7 +394,30 @@ class CustomColumns(object):
|
||||
if notify:
|
||||
self.notify('metadata', ids)
|
||||
|
||||
def set_custom(self, id_, val, label=None, num=None,
|
||||
def set_custom_bulk(self, ids, val, label=None, num=None,
|
||||
append=False, notify=True, extras=None):
|
||||
'''
|
||||
Change the value of a column for a set of books. The ids parameter is a
|
||||
list of book ids to change. The extra field must be None or a list the
|
||||
same length as ids.
|
||||
'''
|
||||
if extras is not None and len(extras) != len(ids):
|
||||
raise ValueError('Lentgh of ids and extras is not the same')
|
||||
ev = None
|
||||
for idx,id in enumerate(ids):
|
||||
if extras is not None:
|
||||
ev = extras[idx]
|
||||
self._set_custom(id, val, label=label, num=num, append=append,
|
||||
notify=notify, extra=ev)
|
||||
self.conn.commit()
|
||||
|
||||
def set_custom(self, id, val, label=None, num=None,
|
||||
append=False, notify=True, extra=None):
|
||||
self._set_custom(id, val, label=label, num=num, append=append,
|
||||
notify=notify, extra=extra)
|
||||
self.conn.commit()
|
||||
|
||||
def _set_custom(self, id_, val, label=None, num=None,
|
||||
append=False, notify=True, extra=None):
|
||||
if label is not None:
|
||||
data = self.custom_column_label_map[label]
|
||||
@ -450,7 +473,6 @@ class CustomColumns(object):
|
||||
self.conn.execute(
|
||||
'''INSERT INTO %s(book, value)
|
||||
VALUES (?,?)'''%lt, (id_, xid))
|
||||
self.conn.commit()
|
||||
nval = self.conn.get(
|
||||
'SELECT custom_%s FROM meta2 WHERE id=?'%data['num'],
|
||||
(id_,), all=False)
|
||||
@ -462,7 +484,6 @@ class CustomColumns(object):
|
||||
self.conn.execute(
|
||||
'INSERT INTO %s(book,value) VALUES (?,?)'%table,
|
||||
(id_, val))
|
||||
self.conn.commit()
|
||||
nval = self.conn.get(
|
||||
'SELECT custom_%s FROM meta2 WHERE id=?'%data['num'],
|
||||
(id_,), all=False)
|
||||
|
Loading…
x
Reference in New Issue
Block a user