mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Allow copying the current search as a calibre:// URL by right clicking the search box
This commit is contained in:
parent
dc4f752ffb
commit
65dab30656
@ -90,6 +90,8 @@ Virtual library, use::
|
|||||||
If you want to switch to a particular Virtual library, use::
|
If you want to switch to a particular Virtual library, use::
|
||||||
|
|
||||||
calibre://search/Library_Name?virtual_library=Library%20Name
|
calibre://search/Library_Name?virtual_library=Library%20Name
|
||||||
|
or
|
||||||
|
calibre://search/Library_Name?encoded_virtual_library=hex_encoded_virtual_library_name
|
||||||
|
|
||||||
replacing spaces in the Virtual library name by ``%20``.
|
replacing spaces in the Virtual library name by ``%20``.
|
||||||
|
|
||||||
|
@ -172,6 +172,21 @@ class LocationManager(QObject): # {{{
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
def search_as_url(text):
|
||||||
|
if text:
|
||||||
|
from calibre.gui2.ui import get_gui
|
||||||
|
db = get_gui().current_db
|
||||||
|
lid = db.new_api.server_library_id
|
||||||
|
lid = lid.encode('utf-8').hex()
|
||||||
|
eq = text.encode('utf-8').hex()
|
||||||
|
vl = db.data.get_base_restriction_name()
|
||||||
|
ans = f'calibre://search/_hex_-{lid}?eq={eq}'
|
||||||
|
if vl:
|
||||||
|
vl = vl.encode('utf-8').hex()
|
||||||
|
ans += '&encoded_virtual_library=' + vl
|
||||||
|
return ans
|
||||||
|
|
||||||
|
|
||||||
class SearchBar(QFrame): # {{{
|
class SearchBar(QFrame): # {{{
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
@ -221,7 +236,7 @@ class SearchBar(QFrame): # {{{
|
|||||||
l.addWidget(sb)
|
l.addWidget(sb)
|
||||||
l.addWidget(parent.sort_sep)
|
l.addWidget(parent.sort_sep)
|
||||||
|
|
||||||
x = parent.search = SearchBox2(self)
|
x = parent.search = SearchBox2(self, as_url=search_as_url)
|
||||||
x.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
|
x.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
|
||||||
x.setObjectName("search")
|
x.setObjectName("search")
|
||||||
x.setToolTip(_("<p>Search the list of books by title, author, publisher, "
|
x.setToolTip(_("<p>Search the list of books by title, author, publisher, "
|
||||||
|
@ -35,6 +35,7 @@ class SearchLineEdit(QLineEdit): # {{{
|
|||||||
key_pressed = pyqtSignal(object)
|
key_pressed = pyqtSignal(object)
|
||||||
clear_history = pyqtSignal()
|
clear_history = pyqtSignal()
|
||||||
select_on_mouse_press = None
|
select_on_mouse_press = None
|
||||||
|
as_url = None
|
||||||
|
|
||||||
def keyPressEvent(self, event):
|
def keyPressEvent(self, event):
|
||||||
self.key_pressed.emit(event)
|
self.key_pressed.emit(event)
|
||||||
@ -59,6 +60,10 @@ class SearchLineEdit(QLineEdit): # {{{
|
|||||||
else:
|
else:
|
||||||
menu.addAction(ac)
|
menu.addAction(ac)
|
||||||
menu.addSeparator()
|
menu.addSeparator()
|
||||||
|
if self.as_url is not None:
|
||||||
|
url = self.as_url(self.text())
|
||||||
|
if url:
|
||||||
|
menu.addAction(_('Copy search as URL'), lambda : QApplication.clipboard().setText(url))
|
||||||
menu.addAction(_('&Clear search history')).triggered.connect(self.clear_history)
|
menu.addAction(_('&Clear search history')).triggered.connect(self.clear_history)
|
||||||
menu.exec_(ev.globalPos())
|
menu.exec_(ev.globalPos())
|
||||||
|
|
||||||
@ -109,9 +114,10 @@ class SearchBox2(QComboBox): # {{{
|
|||||||
changed = pyqtSignal()
|
changed = pyqtSignal()
|
||||||
focus_to_library = pyqtSignal()
|
focus_to_library = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, parent=None, add_clear_action=True):
|
def __init__(self, parent=None, add_clear_action=True, as_url=None):
|
||||||
QComboBox.__init__(self, parent)
|
QComboBox.__init__(self, parent)
|
||||||
self.line_edit = SearchLineEdit(self)
|
self.line_edit = SearchLineEdit(self)
|
||||||
|
self.line_edit.as_url = as_url
|
||||||
self.setLineEdit(self.line_edit)
|
self.setLineEdit(self.line_edit)
|
||||||
self.line_edit.clear_history.connect(self.clear_history)
|
self.line_edit.clear_history.connect(self.clear_history)
|
||||||
if add_clear_action:
|
if add_clear_action:
|
||||||
|
@ -718,7 +718,11 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
if sq:
|
if sq:
|
||||||
sq = sq[0]
|
sq = sq[0]
|
||||||
sq = sq or ''
|
sq = sq or ''
|
||||||
vl = (query.get('virtual_library') or ['-'])[0]
|
vl = None
|
||||||
|
if query.get('encoded_virtual_library'):
|
||||||
|
vl = bytes.fromhex(query.get('encoded_virtual_library')[0]).decode('utf-8')
|
||||||
|
elif query.get('virtual_library'):
|
||||||
|
vl = query.get('virtual_library')[0]
|
||||||
if vl == '-':
|
if vl == '-':
|
||||||
vl = None
|
vl = None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user