mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Enhancement #7172: drop on items in user categories. Also fixed a bug where the interface indicated that one could drop on a format, when you can't.
This commit is contained in:
parent
1caa991f6d
commit
8ecad1b0d7
@ -434,25 +434,24 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
action != Qt.CopyAction:
|
action != Qt.CopyAction:
|
||||||
return False
|
return False
|
||||||
idx = parent
|
idx = parent
|
||||||
p = self.parent(idx)
|
if idx.isValid():
|
||||||
if idx.isValid() and p.isValid():
|
node = self.data(idx, Qt.UserRole)
|
||||||
item = self.data(p, Qt.UserRole)
|
if node.type == TagTreeItem.TAG:
|
||||||
fm = self.db.metadata_for_field(item.category_key)
|
fm = self.db.metadata_for_field(node.tag.category)
|
||||||
if item.category_key in \
|
if node.tag.category in \
|
||||||
('tags', 'series', 'authors', 'rating', 'publisher') or \
|
('tags', 'series', 'authors', 'rating', 'publisher') or \
|
||||||
(fm['is_custom'] and \
|
(fm['is_custom'] and \
|
||||||
fm['datatype'] in ['text', 'rating', 'series']):
|
fm['datatype'] in ['text', 'rating', 'series']):
|
||||||
child = self.data(idx, Qt.UserRole)
|
|
||||||
mime = 'application/calibre+from_library'
|
mime = 'application/calibre+from_library'
|
||||||
ids = list(map(int, str(md.data(mime)).split()))
|
ids = list(map(int, str(md.data(mime)).split()))
|
||||||
self.handle_drop(item, child, ids)
|
self.handle_drop(node, ids)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def handle_drop(self, parent, child, ids):
|
def handle_drop(self, on_node, ids):
|
||||||
# print 'Dropped ids:', ids, parent.category_key, child.tag.name
|
#print 'Dropped ids:', ids, on_node.tag
|
||||||
key = parent.category_key
|
key = on_node.tag.category
|
||||||
if (key == 'authors' and len(ids) >= 5):
|
if (key == 'authors' and len(ids) >= 5):
|
||||||
if not confirm('<p>'+_('Changing the authors for several books can '
|
if not confirm('<p>'+_('Changing the authors for several books can '
|
||||||
'take a while. Are you sure?')
|
'take a while. Are you sure?')
|
||||||
@ -466,7 +465,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
|
|
||||||
fm = self.db.metadata_for_field(key)
|
fm = self.db.metadata_for_field(key)
|
||||||
is_multiple = fm['is_multiple']
|
is_multiple = fm['is_multiple']
|
||||||
val = child.tag.name
|
val = on_node.tag.name
|
||||||
for id in ids:
|
for id in ids:
|
||||||
mi = self.db.get_metadata(id, index_is_id=True)
|
mi = self.db.get_metadata(id, index_is_id=True)
|
||||||
|
|
||||||
@ -500,8 +499,6 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
self.db.commit()
|
self.db.commit()
|
||||||
self.drag_drop_finished.emit(ids)
|
self.drag_drop_finished.emit(ids)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def set_search_restriction(self, s):
|
def set_search_restriction(self, s):
|
||||||
self.search_restriction = s
|
self.search_restriction = s
|
||||||
|
|
||||||
@ -633,7 +630,14 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
|
|
||||||
def flags(self, index, *args):
|
def flags(self, index, *args):
|
||||||
ans = Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable
|
ans = Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable
|
||||||
if index.isValid() and self.parent(index).isValid():
|
if index.isValid():
|
||||||
|
node = self.data(index, Qt.UserRole)
|
||||||
|
if node.type == TagTreeItem.TAG:
|
||||||
|
fm = self.db.metadata_for_field(node.tag.category)
|
||||||
|
if node.tag.category in \
|
||||||
|
('tags', 'series', 'authors', 'rating', 'publisher') or \
|
||||||
|
(fm['is_custom'] and \
|
||||||
|
fm['datatype'] in ['text', 'rating', 'series']):
|
||||||
ans |= Qt.ItemIsDropEnabled
|
ans |= Qt.ItemIsDropEnabled
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ copyfile = os.link if hasattr(os, 'link') else shutil.copyfile
|
|||||||
class Tag(object):
|
class Tag(object):
|
||||||
|
|
||||||
def __init__(self, name, id=None, count=0, state=0, avg=0, sort=None,
|
def __init__(self, name, id=None, count=0, state=0, avg=0, sort=None,
|
||||||
tooltip=None, icon=None):
|
tooltip=None, icon=None, category=None):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.id = id
|
self.id = id
|
||||||
self.count = count
|
self.count = count
|
||||||
@ -81,9 +81,11 @@ class Tag(object):
|
|||||||
tooltip = _('%sAverage rating is %3.1f')%(tooltip, self.avg_rating)
|
tooltip = _('%sAverage rating is %3.1f')%(tooltip, self.avg_rating)
|
||||||
self.tooltip = tooltip
|
self.tooltip = tooltip
|
||||||
self.icon = icon
|
self.icon = icon
|
||||||
|
self.category = category
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return u'%s:%s:%s:%s:%s'%(self.name, self.count, self.id, self.state, self.tooltip)
|
return u'%s:%s:%s:%s:%s:%s'%(self.name, self.count, self.id, self.state,
|
||||||
|
self.category, self.tooltip)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return unicode(self).encode('utf-8')
|
return unicode(self).encode('utf-8')
|
||||||
@ -1115,8 +1117,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
formatter = (lambda x:unicode(x))
|
formatter = (lambda x:unicode(x))
|
||||||
|
|
||||||
categories[category] = [Tag(formatter(r[1]), count=r[2], id=r[0],
|
categories[category] = [Tag(formatter(r[1]), count=r[2], id=r[0],
|
||||||
avg=r[3], sort=r[4],
|
avg=r[3], sort=r[4], icon=icon,
|
||||||
icon=icon, tooltip=tooltip)
|
tooltip=tooltip, category=category)
|
||||||
for r in data if item_not_zero_func(r)]
|
for r in data if item_not_zero_func(r)]
|
||||||
|
|
||||||
# Needed for legacy databases that have multiple ratings that
|
# Needed for legacy databases that have multiple ratings that
|
||||||
@ -1148,7 +1150,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
WHERE format="%s"'''%fmt,
|
WHERE format="%s"'''%fmt,
|
||||||
all=False)
|
all=False)
|
||||||
if count > 0:
|
if count > 0:
|
||||||
categories['formats'].append(Tag(fmt, count=count, icon=icon))
|
categories['formats'].append(Tag(fmt, count=count, icon=icon,
|
||||||
|
category='formats'))
|
||||||
|
|
||||||
if sort == 'popularity':
|
if sort == 'popularity':
|
||||||
categories['formats'].sort(key=lambda x: x.count, reverse=True)
|
categories['formats'].sort(key=lambda x: x.count, reverse=True)
|
||||||
@ -1194,7 +1197,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
if icon_map and 'search' in icon_map:
|
if icon_map and 'search' in icon_map:
|
||||||
icon = icon_map['search']
|
icon = icon_map['search']
|
||||||
for srch in saved_searches().names():
|
for srch in saved_searches().names():
|
||||||
items.append(Tag(srch, tooltip=saved_searches().lookup(srch), icon=icon))
|
items.append(Tag(srch, tooltip=saved_searches().lookup(srch),
|
||||||
|
icon=icon, category='search'))
|
||||||
if len(items):
|
if len(items):
|
||||||
if icon_map is not None:
|
if icon_map is not None:
|
||||||
icon_map['search'] = icon_map['search']
|
icon_map['search'] = icon_map['search']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user