Sync to trunk.

This commit is contained in:
John Schember 2011-05-30 17:32:12 -04:00
commit 5b71c6189a
4 changed files with 39 additions and 21 deletions

View File

@ -350,3 +350,11 @@ send_news_to_device_location = "main"
# work on all operating systems) # work on all operating systems)
server_listen_on = '0.0.0.0' server_listen_on = '0.0.0.0'
#: Unified toolbar on OS X
# If you enable this option and restart calibre, the toolbar will be 'unified'
# with the titlebar as is normal for OS X applications. However, doing this has
# various bugs, for instance the minimum width of the toolbar becomes twice
# what it should be and it causes other random bugs on some systems, so turn it
# on at your own risk!
unified_title_toolbar_on_osx = False

View File

@ -249,10 +249,6 @@ class BarsManager(QObject):
self.menu_bar = MenuBar(self.location_manager, self.parent()) self.menu_bar = MenuBar(self.location_manager, self.parent())
self.parent().setMenuBar(self.menu_bar) self.parent().setMenuBar(self.menu_bar)
parent.addToolBar(Qt.TopToolBarArea, self.main_bars[0])
parent.addToolBar(Qt.BottomToolBarArea, self.main_bars[1])
parent.addToolBar(Qt.BottomToolBarArea, self.child_bars[0])
self.apply_settings() self.apply_settings()
self.init_bars() self.init_bars()
@ -292,15 +288,12 @@ class BarsManager(QObject):
''' '''
showing_device = self.location_manager.has_device showing_device = self.location_manager.has_device
main_bar = self.main_bars[1 if showing_device else 0] main_bar = self.main_bars[1 if showing_device else 0]
hidden_bar = self.main_bars[0 if showing_device else 1]
self.parent().addToolBar(Qt.BottomToolBarArea, hidden_bar)
child_bar = self.child_bars[0] child_bar = self.child_bars[0]
for bar in self.bars: for bar in self.bars:
bar.setVisible(False) bar.setVisible(False)
bar.update_lm_actions() bar.update_lm_actions()
if main_bar.added_actions: if main_bar.added_actions:
main_bar.setVisible(True) main_bar.setVisible(True)
self.parent().addToolBar(Qt.TopToolBarArea, main_bar)
if child_bar.added_actions: if child_bar.added_actions:
child_bar.setVisible(True) child_bar.setVisible(True)

View File

@ -17,6 +17,7 @@ from calibre.gui2.search_box import SearchBox2, SavedSearchBox
from calibre.gui2.throbber import ThrobbingButton from calibre.gui2.throbber import ThrobbingButton
from calibre.gui2.bars import BarsManager from calibre.gui2.bars import BarsManager
from calibre.gui2.widgets import ComboBoxWithHelp from calibre.gui2.widgets import ComboBoxWithHelp
from calibre.utils.config_base import tweaks
from calibre import human_readable from calibre import human_readable
class LocationManager(QObject): # {{{ class LocationManager(QObject): # {{{
@ -259,8 +260,15 @@ class MainWindowMixin(object): # {{{
self.search_bar = SearchBar(self) self.search_bar = SearchBar(self)
self.bars_manager = BarsManager(self.donate_button, self.bars_manager = BarsManager(self.donate_button,
self.location_manager, self) self.location_manager, self)
for bar in self.bars_manager.main_bars:
self.addToolBar(Qt.TopToolBarArea, bar)
for bar in self.bars_manager.child_bars:
self.addToolBar(Qt.BottomToolBarArea, bar)
self.bars_manager.update_bars() self.bars_manager.update_bars()
self.setUnifiedTitleAndToolBarOnMac(True) # This is disabled because it introduces various toolbar related bugs
# The width of the toolbar becomes the sum of both toolbars
if tweaks['unified_title_toolbar_on_osx']:
self.setUnifiedTitleAndToolBarOnMac(True)
l = self.centralwidget.layout() l = self.centralwidget.layout()
l.addWidget(self.search_bar) l.addWidget(self.search_bar)

View File

@ -6,6 +6,7 @@ __license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>' __copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import re
import urllib import urllib
from contextlib import closing from contextlib import closing
@ -25,6 +26,9 @@ class OReillyStore(BasicStoreConfig, StorePlugin):
def open(self, parent=None, detail_item=None, external=False): def open(self, parent=None, detail_item=None, external=False):
url = 'http://oreilly.com/ebooks/' url = 'http://oreilly.com/ebooks/'
if detail_item:
detail_item = 'https://epoch.oreilly.com/shop/cart.orm?prod=%s.EBOOK&p=CALIBRE' % detail_item
if external or self.config.get('open_external', False): if external or self.config.get('open_external', False):
open_url(QUrl(url_slash_cleaner(detail_item if detail_item else url))) open_url(QUrl(url_slash_cleaner(detail_item if detail_item else url)))
else: else:
@ -45,9 +49,11 @@ class OReillyStore(BasicStoreConfig, StorePlugin):
if counter <= 0: if counter <= 0:
break break
id = ''.join(data.xpath('.//div[@class="title"]/a/@href')) full_id = ''.join(data.xpath('.//div[@class="title"]/a/@href'))
if not id: mo = re.search('\d+', full_id)
if not mo:
continue continue
id = mo.group()
cover_url = ''.join(data.xpath('.//div[@class="bigCover"]//img/@src')) cover_url = ''.join(data.xpath('.//div[@class="bigCover"]//img/@src'))
@ -55,6 +61,18 @@ class OReillyStore(BasicStoreConfig, StorePlugin):
author = ''.join(data.xpath('.//div[@class="author"]/text()')) author = ''.join(data.xpath('.//div[@class="author"]/text()'))
author = author.split('By ')[-1].strip() author = author.split('By ')[-1].strip()
# Get the detail here because we need to get the ebook id for the detail_item.
with closing(br.open(full_id, timeout=timeout)) as nf:
idoc = html.fromstring(nf.read())
price = ''.join(idoc.xpath('(//span[@class="price"])[1]/span//text()'))
formats = ', '.join(idoc.xpath('//div[@class="ebook_formats"]//a/text()'))
eid = ''.join(idoc.xpath('(//a[@class="product_buy_link" and contains(@href, ".EBOOK")])[1]/@href')).strip()
mo = re.search('\d+', eid)
if mo:
id = mo.group()
counter -= 1 counter -= 1
s = SearchResult() s = SearchResult()
@ -62,17 +80,8 @@ class OReillyStore(BasicStoreConfig, StorePlugin):
s.title = title.strip() s.title = title.strip()
s.author = author.strip() s.author = author.strip()
s.detail_item = id.strip() s.detail_item = id.strip()
s.price = price.strip()
s.drm = SearchResult.DRM_UNLOCKED s.drm = SearchResult.DRM_UNLOCKED
s.formats = formats.upper()
yield s yield s
def get_details(self, search_result, timeout):
br = browser()
with closing(br.open(search_result.detail_item, timeout=timeout)) as nf:
doc = html.fromstring(nf.read())
search_result.price = ''.join(doc.xpath('(//span[@class="price"])[1]/span//text()')).strip()
search_result.formats = ', '.join(doc.xpath('//div[@class="ebook_formats"]//a/text()')).upper()
return True