diff --git a/manual/url_scheme.rst b/manual/url_scheme.rst index 809cea18c6..1bb3ff5131 100644 --- a/manual/url_scheme.rst +++ b/manual/url_scheme.rst @@ -27,7 +27,7 @@ The URL syntax is:: Library names are the folder name of the library with spaces replaced by underscores. The special value ``_`` means the current library. You can also -use hex encoding for the library names, useful if the library names have +use :ref:`hex encoding ` for the library names, useful if the library names have special characters that would otherwise require URL encoding. Hex encoded library names look like:: @@ -62,3 +62,28 @@ Here, ``book_format`` is the format of the book, for example, ``EPUB`` or easiest way to get these links is to open a book in the viewer, then in the viewer controls select :guilabel:`Go to->Location` and there such a link will be given that you can copy/paste elsewhere. + + +Searching for books +------------------------------ + +The URL syntax is:: + + calibre://search/Library_Name?q=query + calibre://search/Library_Name?eq=hex_encoded_query + +Here query is any valid :ref:`search expression `. If the +search expression is complicated, :ref:`encode it as a hex string ` +and use ``eq`` instead. Leaving out the query will cause the current search to +be cleared. + + +.. _hex_encoding: + +Hex encoding of URL parameters +---------------------------------- + +Hex encoding of URL parameters is done by first encoding the parameter as UTF-8 +bytes, and then replacing each byte by two hexadecimal characters representing +the byte. For example, the string ``abc`` is the bytes ``0x61 0x62 and 0x63`` in +UTF-8, so the encoded version is the string: ``616263``. diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index c63dd2beab..a7bff978ea 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -707,6 +707,24 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{ else: doit() + elif action == 'search': + parts = tuple(filter(None, path.split('/'))) + if len(parts) != 1: + return + library_id = decode_library_id(parts[0]) + library_path = self.library_broker.path_for_library_id(library_id) + if library_path is None: + return + sq = query.get('eq') + if sq: + sq = bytes.fromhex(sq[0]).decode('utf-8') + else: + sq = query.get('q') + if sq: + sq = sq[0] + sq = sq or '' + self.search.set_search_string(sq) + def message_from_another_instance(self, msg): if isinstance(msg, bytes): msg = msg.decode('utf-8', 'replace')