mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Option and implementation to open store in external browser.
This commit is contained in:
parent
0ad7222044
commit
8e166a19d6
@ -473,7 +473,11 @@ def as_unicode(obj, enc=preferred_encoding):
|
|||||||
obj = repr(obj)
|
obj = repr(obj)
|
||||||
return force_unicode(obj, enc=enc)
|
return force_unicode(obj, enc=enc)
|
||||||
|
|
||||||
|
def http_url_slash_cleaner(url):
|
||||||
|
'''
|
||||||
|
Removes redundant /'s from url's.
|
||||||
|
'''
|
||||||
|
return re.sub(r'(?<!http:)/{2,}', '/', url)
|
||||||
|
|
||||||
def human_readable(size):
|
def human_readable(size):
|
||||||
""" Convert a size in bytes into a human readable form """
|
""" Convert a size in bytes into a human readable form """
|
||||||
|
@ -10,6 +10,7 @@ from calibre.gui2 import gprefs
|
|||||||
from calibre.gui2.store.basic_config_widget_ui import Ui_Form
|
from calibre.gui2.store.basic_config_widget_ui import Ui_Form
|
||||||
|
|
||||||
def save_settings(config_widget):
|
def save_settings(config_widget):
|
||||||
|
gprefs[config_widget.store.name + '_open_external'] = config_widget.open_external.isChecked()
|
||||||
tags = unicode(config_widget.tags.text())
|
tags = unicode(config_widget.tags.text())
|
||||||
gprefs[config_widget.store.name + '_tags'] = tags
|
gprefs[config_widget.store.name + '_tags'] = tags
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ class BasicStoreConfigWidget(QWidget, Ui_Form):
|
|||||||
def load_setings(self):
|
def load_setings(self):
|
||||||
settings = self.store.get_settings()
|
settings = self.store.get_settings()
|
||||||
|
|
||||||
|
self.open_external.setChecked(settings.get(self.store.name + '_open_external'))
|
||||||
self.tags.setText(settings.get(self.store.name + '_tags', ''))
|
self.tags.setText(settings.get(self.store.name + '_tags', ''))
|
||||||
|
|
||||||
class BasicStoreConfig(object):
|
class BasicStoreConfig(object):
|
||||||
@ -42,6 +44,7 @@ class BasicStoreConfig(object):
|
|||||||
def get_settings(self):
|
def get_settings(self):
|
||||||
settings = {}
|
settings = {}
|
||||||
|
|
||||||
|
settings[self.name + '_open_external'] = gprefs.get(self.name + '_open_external', False)
|
||||||
settings[self.name + '_tags'] = gprefs.get(self.name + '_tags', self.name + ', store, download')
|
settings[self.name + '_tags'] = gprefs.get(self.name + '_tags', self.name + ', store, download')
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
|
@ -6,24 +6,31 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>501</width>
|
<width>460</width>
|
||||||
<height>46</height>
|
<height>69</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Form</string>
|
<string>Form</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Added Tags:</string>
|
<string>Added Tags:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QLineEdit" name="tags"/>
|
<widget class="QLineEdit" name="tags"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="0" colspan="2">
|
||||||
|
<widget class="QCheckBox" name="open_external">
|
||||||
|
<property name="text">
|
||||||
|
<string>Open store in external web browswer</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
@ -10,7 +10,10 @@ from contextlib import closing
|
|||||||
|
|
||||||
from lxml import html
|
from lxml import html
|
||||||
|
|
||||||
from calibre import browser
|
from PyQt4.Qt import QUrl
|
||||||
|
|
||||||
|
from calibre import browser, http_url_slash_cleaner
|
||||||
|
from calibre.gui2 import open_url
|
||||||
from calibre.gui2.store import StorePlugin
|
from calibre.gui2.store import StorePlugin
|
||||||
from calibre.gui2.store.basic_config import BasicStoreConfig
|
from calibre.gui2.store.basic_config import BasicStoreConfig
|
||||||
from calibre.gui2.store.search_result import SearchResult
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
@ -20,14 +23,22 @@ class DieselEbooksStore(BasicStoreConfig, StorePlugin):
|
|||||||
|
|
||||||
def open(self, parent=None, detail_item=None, external=False):
|
def open(self, parent=None, detail_item=None, external=False):
|
||||||
settings = self.get_settings()
|
settings = self.get_settings()
|
||||||
aff_id = '2049'
|
url = 'http://www.diesel-ebooks.com/'
|
||||||
|
|
||||||
|
aff_id = '?aid=2049'
|
||||||
# Use Kovid's affiliate id 30% of the time.
|
# Use Kovid's affiliate id 30% of the time.
|
||||||
if random.randint(1, 10) in (1, 2, 3):
|
if random.randint(1, 10) in (1, 2, 3):
|
||||||
aff_id = '2053'
|
aff_id = '?aid=2053'
|
||||||
d = WebStoreDialog(self.gui, 'http://www.diesel-ebooks.com/?aid=%s' % aff_id, parent, detail_item)
|
|
||||||
d.setWindowTitle(self.name)
|
if external or settings.get(self.name + '_open_external', False):
|
||||||
d.set_tags(settings.get(self.name + '_tags', ''))
|
if detail_item:
|
||||||
d = d.exec_()
|
url = url + detail_item
|
||||||
|
open_url(QUrl(http_url_slash_cleaner(url + aff_id)))
|
||||||
|
else:
|
||||||
|
d = WebStoreDialog(self.gui, url + aff_id, parent, detail_item)
|
||||||
|
d.setWindowTitle(self.name)
|
||||||
|
d.set_tags(settings.get(self.name + '_tags', ''))
|
||||||
|
d = d.exec_()
|
||||||
|
|
||||||
def search(self, query, max_results=10, timeout=60):
|
def search(self, query, max_results=10, timeout=60):
|
||||||
url = 'http://www.diesel-ebooks.com/index.php?page=seek&id[m]=&id[c]=scope%253Dinventory&id[q]=' + urllib2.quote(query)
|
url = 'http://www.diesel-ebooks.com/index.php?page=seek&id[m]=&id[c]=scope%253Dinventory&id[q]=' + urllib2.quote(query)
|
||||||
|
@ -9,7 +9,10 @@ from contextlib import closing
|
|||||||
|
|
||||||
from lxml import html
|
from lxml import html
|
||||||
|
|
||||||
from calibre import browser
|
from PyQt4.Qt import QUrl
|
||||||
|
|
||||||
|
from calibre import browser, http_url_slash_cleaner
|
||||||
|
from calibre.gui2 import open_url
|
||||||
from calibre.gui2.store import StorePlugin
|
from calibre.gui2.store import StorePlugin
|
||||||
from calibre.gui2.store.basic_config import BasicStoreConfig
|
from calibre.gui2.store.basic_config import BasicStoreConfig
|
||||||
from calibre.gui2.store.search_result import SearchResult
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
@ -19,10 +22,18 @@ class FeedbooksStore(BasicStoreConfig, StorePlugin):
|
|||||||
|
|
||||||
def open(self, parent=None, detail_item=None, external=False):
|
def open(self, parent=None, detail_item=None, external=False):
|
||||||
settings = self.get_settings()
|
settings = self.get_settings()
|
||||||
d = WebStoreDialog(self.gui, 'http://m.feedbooks.com/', parent, detail_item)
|
url = 'http://m.feedbooks.com/'
|
||||||
d.setWindowTitle(self.name)
|
ext_url = 'http://feedbooks.com/'
|
||||||
d.set_tags(settings.get(self.name + '_tags', ''))
|
|
||||||
d = d.exec_()
|
if external or settings.get(self.name + '_open_external', False):
|
||||||
|
if detail_item:
|
||||||
|
ext_url = ext_url + detail_item
|
||||||
|
open_url(QUrl(http_url_slash_cleaner(ext_url)))
|
||||||
|
else:
|
||||||
|
d = WebStoreDialog(self.gui, url, parent, detail_item)
|
||||||
|
d.setWindowTitle(self.name)
|
||||||
|
d.set_tags(settings.get(self.name + '_tags', ''))
|
||||||
|
d = d.exec_()
|
||||||
|
|
||||||
def search(self, query, max_results=10, timeout=60):
|
def search(self, query, max_results=10, timeout=60):
|
||||||
url = 'http://m.feedbooks.com/search?query=' + urllib2.quote(query)
|
url = 'http://m.feedbooks.com/search?query=' + urllib2.quote(query)
|
||||||
|
@ -9,7 +9,10 @@ from contextlib import closing
|
|||||||
|
|
||||||
from lxml import html
|
from lxml import html
|
||||||
|
|
||||||
from calibre import browser
|
from PyQt4.Qt import QUrl
|
||||||
|
|
||||||
|
from calibre import browser, http_url_slash_cleaner
|
||||||
|
from calibre.gui2 import open_url
|
||||||
from calibre.gui2.store import StorePlugin
|
from calibre.gui2.store import StorePlugin
|
||||||
from calibre.gui2.store.basic_config import BasicStoreConfig
|
from calibre.gui2.store.basic_config import BasicStoreConfig
|
||||||
from calibre.gui2.store.search_result import SearchResult
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
@ -19,10 +22,18 @@ class GutenbergStore(BasicStoreConfig, StorePlugin):
|
|||||||
|
|
||||||
def open(self, parent=None, detail_item=None, external=False):
|
def open(self, parent=None, detail_item=None, external=False):
|
||||||
settings = self.get_settings()
|
settings = self.get_settings()
|
||||||
d = WebStoreDialog(self.gui, 'http://m.gutenberg.org/', parent, detail_item)
|
url = 'http://m.gutenberg.org/'
|
||||||
d.setWindowTitle(self.name)
|
ext_url = 'http://gutenberg.org/'
|
||||||
d.set_tags(settings.get(self.name + '_tags', ''))
|
|
||||||
d = d.exec_()
|
if external or settings.get(self.name + '_open_external', False):
|
||||||
|
if detail_item:
|
||||||
|
ext_url = ext_url + detail_item
|
||||||
|
open_url(QUrl(http_url_slash_cleaner(ext_url)))
|
||||||
|
else:
|
||||||
|
d = WebStoreDialog(self.gui, url, parent, detail_item)
|
||||||
|
d.setWindowTitle(self.name)
|
||||||
|
d.set_tags(settings.get(self.name + '_tags', ''))
|
||||||
|
d = d.exec_()
|
||||||
|
|
||||||
def search(self, query, max_results=10, timeout=60):
|
def search(self, query, max_results=10, timeout=60):
|
||||||
# Gutenberg's website does not allow searching both author and title.
|
# Gutenberg's website does not allow searching both author and title.
|
||||||
|
@ -10,7 +10,10 @@ from contextlib import closing
|
|||||||
|
|
||||||
from lxml import html
|
from lxml import html
|
||||||
|
|
||||||
from calibre import browser
|
from PyQt4.Qt import QUrl
|
||||||
|
|
||||||
|
from calibre import browser, http_url_slash_cleaner
|
||||||
|
from calibre.gui2 import open_url
|
||||||
from calibre.gui2.store import StorePlugin
|
from calibre.gui2.store import StorePlugin
|
||||||
from calibre.gui2.store.basic_config import BasicStoreConfig
|
from calibre.gui2.store.basic_config import BasicStoreConfig
|
||||||
from calibre.gui2.store.search_result import SearchResult
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
@ -20,10 +23,17 @@ class ManyBooksStore(BasicStoreConfig, StorePlugin):
|
|||||||
|
|
||||||
def open(self, parent=None, detail_item=None, external=False):
|
def open(self, parent=None, detail_item=None, external=False):
|
||||||
settings = self.get_settings()
|
settings = self.get_settings()
|
||||||
d = WebStoreDialog(self.gui, 'http://manybooks.net/', parent, detail_item)
|
url = 'http://manybooks.net/'
|
||||||
d.setWindowTitle(self.name)
|
|
||||||
d.set_tags(settings.get(self.name + '_tags', ''))
|
if external or settings.get(self.name + '_open_external', False):
|
||||||
d = d.exec_()
|
if detail_item:
|
||||||
|
url = url + detail_item
|
||||||
|
open_url(QUrl(http_url_slash_cleaner(url)))
|
||||||
|
else:
|
||||||
|
d = WebStoreDialog(self.gui, url, parent, detail_item)
|
||||||
|
d.setWindowTitle(self.name)
|
||||||
|
d.set_tags(settings.get(self.name + '_tags', ''))
|
||||||
|
d = d.exec_()
|
||||||
|
|
||||||
def search(self, query, max_results=10, timeout=60):
|
def search(self, query, max_results=10, timeout=60):
|
||||||
# ManyBooks website separates results for title and author.
|
# ManyBooks website separates results for title and author.
|
||||||
|
@ -11,7 +11,10 @@ from contextlib import closing
|
|||||||
|
|
||||||
from lxml import html
|
from lxml import html
|
||||||
|
|
||||||
from calibre import browser
|
from PyQt4.Qt import QUrl
|
||||||
|
|
||||||
|
from calibre import browser, http_url_slash_cleaner
|
||||||
|
from calibre.gui2 import open_url
|
||||||
from calibre.gui2.store import StorePlugin
|
from calibre.gui2.store import StorePlugin
|
||||||
from calibre.gui2.store.basic_config import BasicStoreConfig
|
from calibre.gui2.store.basic_config import BasicStoreConfig
|
||||||
from calibre.gui2.store.search_result import SearchResult
|
from calibre.gui2.store.search_result import SearchResult
|
||||||
@ -21,14 +24,22 @@ class SmashwordsStore(BasicStoreConfig, StorePlugin):
|
|||||||
|
|
||||||
def open(self, parent=None, detail_item=None, external=False):
|
def open(self, parent=None, detail_item=None, external=False):
|
||||||
settings = self.get_settings()
|
settings = self.get_settings()
|
||||||
aff_id = 'usernone'
|
url = 'http://www.smashwords.com/'
|
||||||
|
|
||||||
|
aff_id = '?ref=usernone'
|
||||||
# Use Kovid's affiliate id 30% of the time.
|
# Use Kovid's affiliate id 30% of the time.
|
||||||
if random.randint(1, 10) in (1, 2, 3):
|
if random.randint(1, 10) in (1, 2, 3):
|
||||||
aff_id = 'kovidgoyal'
|
aff_id = '?ref=kovidgoyal'
|
||||||
d = WebStoreDialog(self.gui, 'http://www.smashwords.com/?ref=%s' % aff_id, parent, detail_item)
|
|
||||||
d.setWindowTitle(self.name)
|
if external or settings.get(self.name + '_open_external', False):
|
||||||
d.set_tags(settings.get(self.name + '_tags', ''))
|
if detail_item:
|
||||||
d = d.exec_()
|
url = url + detail_item
|
||||||
|
open_url(QUrl(http_url_slash_cleaner(url + aff_id)))
|
||||||
|
else:
|
||||||
|
d = WebStoreDialog(self.gui, url + aff_id, parent, detail_item)
|
||||||
|
d.setWindowTitle(self.name)
|
||||||
|
d.set_tags(settings.get(self.name + '_tags', ''))
|
||||||
|
d = d.exec_()
|
||||||
|
|
||||||
def search(self, query, max_results=10, timeout=60):
|
def search(self, query, max_results=10, timeout=60):
|
||||||
url = 'http://www.smashwords.com/books/search?query=' + urllib2.quote(query)
|
url = 'http://www.smashwords.com/books/search?query=' + urllib2.quote(query)
|
||||||
|
@ -9,6 +9,7 @@ import urllib
|
|||||||
|
|
||||||
from PyQt4.Qt import QDialog, QUrl
|
from PyQt4.Qt import QDialog, QUrl
|
||||||
|
|
||||||
|
from calibre import http_url_slash_cleaner
|
||||||
from calibre.gui2.store.web_store_dialog_ui import Ui_Dialog
|
from calibre.gui2.store.web_store_dialog_ui import Ui_Dialog
|
||||||
|
|
||||||
class WebStoreDialog(QDialog, Ui_Dialog):
|
class WebStoreDialog(QDialog, Ui_Dialog):
|
||||||
@ -51,5 +52,5 @@ class WebStoreDialog(QDialog, Ui_Dialog):
|
|||||||
# Reduce redundant /'s because some stores
|
# Reduce redundant /'s because some stores
|
||||||
# (Feedbooks) and server frameworks (cherrypy)
|
# (Feedbooks) and server frameworks (cherrypy)
|
||||||
# choke on them.
|
# choke on them.
|
||||||
url = re.sub(r'(?<!http:)/{2,}', '/', url)
|
url = http_url_slash_cleaner(url)
|
||||||
self.view.load(QUrl(url))
|
self.view.load(QUrl(url))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user