mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Make the search engine used for searching for selected text configurable
This commit is contained in:
parent
4c1cd70233
commit
748b18b599
@ -47,6 +47,8 @@ def config(defaults=None):
|
||||
c.add_opt('hyphenate', default=False, help=_('Hyphenate text'))
|
||||
c.add_opt('hyphenate_default_lang', default='en',
|
||||
help=_('Default language for hyphenation rules'))
|
||||
c.add_opt('search_online_url', default='https://www.google.com/search?q={text}',
|
||||
help=_('The URL to use when searching for selected text online'))
|
||||
c.add_opt('remember_current_page', default=True,
|
||||
help=_('Save the current position in the document, when quitting'))
|
||||
c.add_opt('copy_bookmarks_to_file', default=True,
|
||||
@ -313,6 +315,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
||||
self.hyphenate_default_lang.setCurrentIndex(idx)
|
||||
self.hyphenate.setChecked(opts.hyphenate)
|
||||
self.hyphenate_default_lang.setEnabled(opts.hyphenate)
|
||||
self.search_online_url.setText(opts.search_online_url or '')
|
||||
self.opt_fit_images.setChecked(opts.fit_images)
|
||||
self.opt_fullscreen_clock.setChecked(opts.fullscreen_clock)
|
||||
self.opt_fullscreen_scrollbar.setChecked(opts.fullscreen_scrollbar)
|
||||
@ -397,6 +400,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
||||
self.hyphenate_default_lang.itemData(idx))
|
||||
c.set('line_scrolling_stops_on_pagebreaks',
|
||||
self.opt_line_scrolling_stops_on_pagebreaks.isChecked())
|
||||
c.set('search_online_url', self.search_online_url.text().strip())
|
||||
c.set('fullscreen_clock', self.opt_fullscreen_clock.isChecked())
|
||||
c.set('fullscreen_pos', self.opt_fullscreen_pos.isChecked())
|
||||
c.set('fullscreen_scrollbar', self.opt_fullscreen_scrollbar.isChecked())
|
||||
|
@ -240,8 +240,8 @@ QToolBox::tab:hover {
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>374</width>
|
||||
<height>211</height>
|
||||
<width>799</width>
|
||||
<height>378</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
@ -370,8 +370,8 @@ QToolBox::tab:hover {
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>381</width>
|
||||
<height>193</height>
|
||||
<width>799</width>
|
||||
<height>378</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
@ -472,8 +472,8 @@ QToolBox::tab:hover {
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>340</width>
|
||||
<height>70</height>
|
||||
<width>799</width>
|
||||
<height>378</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
@ -551,8 +551,8 @@ QToolBox::tab:hover {
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>384</width>
|
||||
<height>140</height>
|
||||
<width>799</width>
|
||||
<height>378</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
@ -636,7 +636,38 @@ QToolBox::tab:hover {
|
||||
<attribute name="label">
|
||||
<string>&Miscellaneous options</string>
|
||||
</attribute>
|
||||
<layout class="QFormLayout" name="formLayout_4">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="opt_remember_window_size">
|
||||
<property name="text">
|
||||
<string>Remember last used &window size and layout</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="opt_remember_current_page">
|
||||
<property name="text">
|
||||
<string>Remember the &current page when quitting</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="opt_copy_bookmarks_to_file">
|
||||
<property name="toolTip">
|
||||
<string>Keep a copy of all bookmarks/current page information inside the ebook file, so that you can share them by simply sending the ebook file itself. Currently only works with ebooks in the EPUB format.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Keep a copy of bookmarks/current page inside the ebook file, for easy sharing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="opt_show_controls">
|
||||
<property name="text">
|
||||
<string>Show &controls in the viewer window</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="hyphenate">
|
||||
<property name="text">
|
||||
@ -644,6 +675,13 @@ QToolBox::tab:hover {
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QPushButton" name="clear_search_history_button">
|
||||
<property name="text">
|
||||
<string>Clear search history</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="hyphenate_label">
|
||||
<property name="text">
|
||||
@ -661,44 +699,38 @@ QToolBox::tab:hover {
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QPushButton" name="clear_search_history_button">
|
||||
<property name="text">
|
||||
<string>Clear search history</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="opt_show_controls">
|
||||
<property name="text">
|
||||
<string>Show &controls in the viewer window</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QCheckBox" name="opt_remember_window_size">
|
||||
<widget class="QLabel" name="label_26">
|
||||
<property name="text">
|
||||
<string>Remember last used &window size and layout</string>
|
||||
<string>&Search online URL:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>search_online_url</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="opt_remember_current_page">
|
||||
<property name="text">
|
||||
<string>Remember the &current page when quitting</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="opt_copy_bookmarks_to_file">
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="search_online_url">
|
||||
<property name="toolTip">
|
||||
<string>Keep a copy of all bookmarks/current page information inside the ebook file, so that you can share them by simply sending the ebook file itself. Currently only works with ebooks in the EPUB format.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Keep a copy of bookmarks/current page inside the ebook file, for easy sharing</string>
|
||||
<string>Change the search engine used to perform online searches for selected text.
|
||||
You must enter the search URL for the search engine, with the placeholder
|
||||
{text}, which will be replaced by the selected text.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
@ -189,6 +189,7 @@ class Document(QWebPage): # {{{
|
||||
self.show_controls = opts.show_controls
|
||||
self.remember_current_page = opts.remember_current_page
|
||||
self.copy_bookmarks_to_file = opts.copy_bookmarks_to_file
|
||||
self.search_online_url = opts.search_online_url or 'https://www.google.com/search?q={text}'
|
||||
|
||||
def fit_images(self):
|
||||
if self.do_fit_images and not self.in_paged_mode:
|
||||
@ -701,7 +702,7 @@ class DocumentView(QWebView): # {{{
|
||||
if len(t) > 40:
|
||||
t = t[:40] + u'...'
|
||||
t = t.replace(u'&', u'&&')
|
||||
return _("S&earch Google for '%s'")%t
|
||||
return _("S&earch online for '%s'")%t
|
||||
|
||||
def popup_table(self):
|
||||
html = self.document.extract_node()
|
||||
@ -820,7 +821,7 @@ class DocumentView(QWebView): # {{{
|
||||
self.do_search_online(t)
|
||||
|
||||
def do_search_online(self, text):
|
||||
url = 'https://www.google.com/search?q=' + QUrl().toPercentEncoding(text)
|
||||
url = self.document.search_online_url.replace('{text}', QUrl().toPercentEncoding(text))
|
||||
open_url(QUrl.fromEncoded(url))
|
||||
|
||||
def set_manager(self, manager):
|
||||
|
Loading…
x
Reference in New Issue
Block a user