E-book viewer: Make the search engine used for searching for selected text configurable

This commit is contained in:
Kovid Goyal 2015-06-13 09:24:02 +05:30
parent 4c1cd70233
commit 748b18b599
3 changed files with 77 additions and 40 deletions

View File

@ -47,6 +47,8 @@ def config(defaults=None):
c.add_opt('hyphenate', default=False, help=_('Hyphenate text')) c.add_opt('hyphenate', default=False, help=_('Hyphenate text'))
c.add_opt('hyphenate_default_lang', default='en', c.add_opt('hyphenate_default_lang', default='en',
help=_('Default language for hyphenation rules')) 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, c.add_opt('remember_current_page', default=True,
help=_('Save the current position in the document, when quitting')) help=_('Save the current position in the document, when quitting'))
c.add_opt('copy_bookmarks_to_file', default=True, 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_default_lang.setCurrentIndex(idx)
self.hyphenate.setChecked(opts.hyphenate) self.hyphenate.setChecked(opts.hyphenate)
self.hyphenate_default_lang.setEnabled(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_fit_images.setChecked(opts.fit_images)
self.opt_fullscreen_clock.setChecked(opts.fullscreen_clock) self.opt_fullscreen_clock.setChecked(opts.fullscreen_clock)
self.opt_fullscreen_scrollbar.setChecked(opts.fullscreen_scrollbar) self.opt_fullscreen_scrollbar.setChecked(opts.fullscreen_scrollbar)
@ -397,6 +400,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
self.hyphenate_default_lang.itemData(idx)) self.hyphenate_default_lang.itemData(idx))
c.set('line_scrolling_stops_on_pagebreaks', c.set('line_scrolling_stops_on_pagebreaks',
self.opt_line_scrolling_stops_on_pagebreaks.isChecked()) 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_clock', self.opt_fullscreen_clock.isChecked())
c.set('fullscreen_pos', self.opt_fullscreen_pos.isChecked()) c.set('fullscreen_pos', self.opt_fullscreen_pos.isChecked())
c.set('fullscreen_scrollbar', self.opt_fullscreen_scrollbar.isChecked()) c.set('fullscreen_scrollbar', self.opt_fullscreen_scrollbar.isChecked())

View File

@ -240,8 +240,8 @@ QToolBox::tab:hover {
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>374</width> <width>799</width>
<height>211</height> <height>378</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
@ -370,8 +370,8 @@ QToolBox::tab:hover {
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>381</width> <width>799</width>
<height>193</height> <height>378</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
@ -472,8 +472,8 @@ QToolBox::tab:hover {
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>340</width> <width>799</width>
<height>70</height> <height>378</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
@ -551,8 +551,8 @@ QToolBox::tab:hover {
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>384</width> <width>799</width>
<height>140</height> <height>378</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
@ -636,7 +636,38 @@ QToolBox::tab:hover {
<attribute name="label"> <attribute name="label">
<string>&amp;Miscellaneous options</string> <string>&amp;Miscellaneous options</string>
</attribute> </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 &amp;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 &amp;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 &amp;controls in the viewer window</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2"> <item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="hyphenate"> <widget class="QCheckBox" name="hyphenate">
<property name="text"> <property name="text">
@ -644,6 +675,13 @@ QToolBox::tab:hover {
</property> </property>
</widget> </widget>
</item> </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"> <item row="1" column="0">
<widget class="QLabel" name="hyphenate_label"> <widget class="QLabel" name="hyphenate_label">
<property name="text"> <property name="text">
@ -661,44 +699,38 @@ QToolBox::tab:hover {
</property> </property>
</widget> </widget>
</item> </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 &amp;controls in the viewer window</string>
</property>
</widget>
</item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QCheckBox" name="opt_remember_window_size"> <widget class="QLabel" name="label_26">
<property name="text"> <property name="text">
<string>Remember last used &amp;window size and layout</string> <string>&amp;Search online URL:</string>
</property>
<property name="buddy">
<cstring>search_online_url</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="3" column="1">
<widget class="QCheckBox" name="opt_remember_current_page"> <widget class="QLineEdit" name="search_online_url">
<property name="text">
<string>Remember the &amp;current page when quitting</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="opt_copy_bookmarks_to_file">
<property name="toolTip"> <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> <string>Change the search engine used to perform online searches for selected text.
</property> You must enter the search URL for the search engine, with the placeholder
<property name="text"> {text}, which will be replaced by the selected text.</string>
<string>Keep a copy of bookmarks/current page inside the ebook file, for easy sharing</string>
</property> </property>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
</widget> </widget>

View File

@ -189,6 +189,7 @@ class Document(QWebPage): # {{{
self.show_controls = opts.show_controls self.show_controls = opts.show_controls
self.remember_current_page = opts.remember_current_page self.remember_current_page = opts.remember_current_page
self.copy_bookmarks_to_file = opts.copy_bookmarks_to_file 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): def fit_images(self):
if self.do_fit_images and not self.in_paged_mode: if self.do_fit_images and not self.in_paged_mode:
@ -701,7 +702,7 @@ class DocumentView(QWebView): # {{{
if len(t) > 40: if len(t) > 40:
t = t[:40] + u'...' t = t[:40] + u'...'
t = t.replace(u'&', u'&&') t = t.replace(u'&', u'&&')
return _("S&earch Google for '%s'")%t return _("S&earch online for '%s'")%t
def popup_table(self): def popup_table(self):
html = self.document.extract_node() html = self.document.extract_node()
@ -820,7 +821,7 @@ class DocumentView(QWebView): # {{{
self.do_search_online(t) self.do_search_online(t)
def do_search_online(self, text): 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)) open_url(QUrl.fromEncoded(url))
def set_manager(self, manager): def set_manager(self, manager):