From 9c0d9aa7241233b26620f16edcfd735e398c4be9 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sat, 21 May 2011 10:54:43 -0600
Subject: [PATCH 01/51] National Geographic by Anonymous
---
recipes/national_geographic_de.recipe | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
create mode 100644 recipes/national_geographic_de.recipe
diff --git a/recipes/national_geographic_de.recipe b/recipes/national_geographic_de.recipe
new file mode 100644
index 0000000000..46f4783f41
--- /dev/null
+++ b/recipes/national_geographic_de.recipe
@@ -0,0 +1,25 @@
+from calibre.web.feeds.news import BasicNewsRecipe
+
+class AdvancedUserRecipe1305567197(BasicNewsRecipe):
+ title = u'National Geographic (DE)'
+ __author__ = 'Anonymous'
+ language = 'de'
+ oldest_article = 7
+ max_articles_per_feed = 1000
+ no_stylesheets = True
+ use_embedded_content = False
+ remove_javascript = True
+ cover_url = 'http://www.nationalgeographic.de/images/national-geographic-logo.jpg'
+ keep_only_tags = [
+ dict(name='div', attrs={'class':['contentbox_no_top_border']}) ]
+
+ remove_tags = [
+ dict(name='div', attrs={'class':'related'}),
+ dict(name='li', attrs={'class':'first'}),
+ dict(name='div', attrs={'class':'extrasbox_inner'}),
+
+ ]
+
+ feeds = [ (u'National Geographic', u'http://feeds.nationalgeographic.de/ng-neueste-artikel'),
+
+ ]
From 87efd04aa1becb598d054a910cb8088ec779aa5b Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sat, 21 May 2011 11:10:38 -0600
Subject: [PATCH 02/51] Focus (DE) by Anonymous
---
recipes/focus_de.recipe | 48 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
create mode 100644 recipes/focus_de.recipe
diff --git a/recipes/focus_de.recipe b/recipes/focus_de.recipe
new file mode 100644
index 0000000000..d0b0f4aef8
--- /dev/null
+++ b/recipes/focus_de.recipe
@@ -0,0 +1,48 @@
+from calibre.web.feeds.news import BasicNewsRecipe
+
+class AdvancedUserRecipe1305567197(BasicNewsRecipe):
+ title = u'Focus (DE)'
+ __author__ = 'Anonymous'
+ language = 'de'
+ oldest_article = 7
+ max_articles_per_feed = 100
+ no_stylesheets = True
+ use_embedded_content = False
+ remove_javascript = True
+
+ def print_version(self, url):
+ return url + '?drucken=1'
+
+ keep_only_tags = [
+ dict(name='div', attrs={'id':['article']}) ]
+
+ remove_tags = [dict(name='div', attrs={'class':'sidebar'}),
+ dict(name='div', attrs={'class':'commentForm'}),
+ dict(name='div', attrs={'class':'comment clearfix oid-3534591 open'}),
+ dict(name='div', attrs={'class':'similarityBlock'}),
+ dict(name='div', attrs={'class':'footer'}),
+ dict(name='div', attrs={'class':'getMoreComments'}),
+ dict(name='div', attrs={'class':'moreComments'}),
+ dict(name='div', attrs={'class':'ads'}),
+ dict(name='div', attrs={'class':'articleContent'}),
+
+
+ ]
+ remove_tags_after = [
+ dict(name='div',attrs={'class':['commentForm','title', 'actions clearfix']})
+ ]
+
+
+ feeds = [ (u'Eilmeldungen', u'http://rss2.focus.de/c/32191/f/533875/index.rss'),
+ (u'Auto-News', u'http://rss2.focus.de/c/32191/f/443320/index.rss'),
+ (u'Digital-News', u'http://rss2.focus.de/c/32191/f/443315/index.rss'),
+ (u'Finanzen-News', u'http://rss2.focus.de/c/32191/f/443317/index.rss'),
+ (u'Gesundheit-News', u'http://rss2.focus.de/c/32191/f/443314/index.rss'),
+ (u'Immobilien-News', u'http://rss2.focus.de/c/32191/f/443318/index.rss'),
+ (u'Kultur-News', u'http://rss2.focus.de/c/32191/f/443321/index.rss'),
+ (u'Panorama-News', u'http://rss2.focus.de/c/32191/f/533877/index.rss'),
+ (u'Politik-News', u'http://rss2.focus.de/c/32191/f/443313/index.rss'),
+ (u'Reisen-News', u'http://rss2.focus.de/c/32191/f/443316/index.rss'),
+ (u'Sport-News', u'http://rss2.focus.de/c/32191/f/443319/index.rss'),
+ (u'Wissen-News', u'http://rss2.focus.de/c/32191/f/533876/index.rss'),
+ ]
From 224968f239436ad14f8d8bb3f481cddb07f01744 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sat, 21 May 2011 11:40:45 -0600
Subject: [PATCH 03/51] Windows: If creating a bytestring temp dir fails,
create a unicode one and hope the rest of calibre can handle it
---
src/calibre/ptempfile.py | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/calibre/ptempfile.py b/src/calibre/ptempfile.py
index ac7df1c4e3..bff13dd248 100644
--- a/src/calibre/ptempfile.py
+++ b/src/calibre/ptempfile.py
@@ -39,8 +39,20 @@ def base_dir():
if td and os.path.exists(td):
_base_dir = td
else:
- _base_dir = tempfile.mkdtemp(prefix='%s_%s_tmp_'%(__appname__,
- __version__), dir=os.environ.get('CALIBRE_TEMP_DIR', None))
+ base = os.environ.get('CALIBRE_TEMP_DIR', None)
+ prefix = u'%s_%s_tmp_'%(__appname__, __version__)
+ try:
+ # First try an ascii path as that is what was done historically
+ # and we dont want to break working code
+ # _base_dir will be a bytestring
+ _base_dir = tempfile.mkdtemp(prefix=prefix.encode('ascii'), dir=base)
+ except:
+ # Failed to create tempdir (probably localized windows)
+ # Try unicode. This means that all temp paths created by this
+ # module will be unicode, this may cause problems elsewhere, if
+ # so, hopefully people will open tickets and they can be fixed.
+ _base_dir = tempfile.mkdtemp(prefix=prefix, dir=base)
+
atexit.register(remove_dir, _base_dir)
return _base_dir
From c3a2c3f458304abaef826e08f61265a235df5d50 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 21 May 2011 19:24:04 +0100
Subject: [PATCH 04/51] Add option to color custom enumeration values in the
library view
---
src/calibre/gui2/library/delegates.py | 25 ++++++++++++++++
.../gui2/preferences/create_custom_column.py | 21 ++++++++++++--
.../gui2/preferences/create_custom_column.ui | 29 ++++++++++++++++---
3 files changed, 68 insertions(+), 7 deletions(-)
diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py
index e2234f6df5..ae01081736 100644
--- a/src/calibre/gui2/library/delegates.py
+++ b/src/calibre/gui2/library/delegates.py
@@ -274,6 +274,31 @@ class CcEnumDelegate(QStyledItemDelegate): # {{{
Delegate for text/int/float data.
'''
+ def __init__(self, parent):
+ QStyledItemDelegate.__init__(self, parent)
+ self.document = QTextDocument()
+
+ def paint(self, painter, option, index):
+ style = self.parent().style()
+ txt = unicode(index.data(Qt.DisplayRole).toString())
+ self.document.setPlainText(txt)
+ painter.save()
+ if hasattr(QStyle, 'CE_ItemViewItem'):
+ style.drawControl(QStyle.CE_ItemViewItem, option,
+ painter, self.parent())
+ elif option.state & QStyle.State_Selected:
+ painter.fillRect(option.rect, option.palette.highlight())
+ m = index.model()
+ col = m.column_map[index.column()]
+ colors = m.custom_columns[col]['display'].get('enum_colors', [])
+ values = m.custom_columns[col]['display']['enum_values']
+ if len(colors) > 0 and txt in values:
+ painter.fillRect(option.rect, QColor(colors[values.index(txt)]))
+ painter.setClipRect(option.rect)
+ painter.translate(option.rect.topLeft())
+ self.document.drawContents(painter)
+ painter.restore()
+
def createEditor(self, parent, option, index):
m = index.model()
col = m.column_map[index.column()]
diff --git a/src/calibre/gui2/preferences/create_custom_column.py b/src/calibre/gui2/preferences/create_custom_column.py
index 7b891b782c..180c3aed7a 100644
--- a/src/calibre/gui2/preferences/create_custom_column.py
+++ b/src/calibre/gui2/preferences/create_custom_column.py
@@ -6,7 +6,7 @@ __copyright__ = '2010, Kovid Goyal '
import re
from functools import partial
-from PyQt4.Qt import QDialog, Qt, QListWidgetItem, QVariant
+from PyQt4.Qt import QDialog, Qt, QListWidgetItem, QVariant, QColor
from calibre.gui2.preferences.create_custom_column_ui import Ui_QCreateCustomColumn
from calibre.gui2 import error_dialog
@@ -126,6 +126,7 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
c['display'].get('make_category', False))
elif ct == 'enumeration':
self.enum_box.setText(','.join(c['display'].get('enum_values', [])))
+ self.enum_colors.setText(','.join(c['display'].get('enum_colors', [])))
self.datatype_changed()
if ct in ['text', 'composite', 'enumeration']:
self.use_decorations.setChecked(c['display'].get('use_decorations', False))
@@ -170,7 +171,7 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
for x in ('box', 'default_label', 'label', 'sort_by', 'sort_by_label',
'make_category'):
getattr(self, 'composite_'+x).setVisible(col_type in ['composite', '*composite'])
- for x in ('box', 'default_label', 'label'):
+ for x in ('box', 'default_label', 'label', 'colors', 'colors_label'):
getattr(self, 'enum_'+x).setVisible(col_type == 'enumeration')
self.use_decorations.setVisible(col_type in ['text', 'composite', 'enumeration'])
self.is_names.setVisible(col_type == '*text')
@@ -247,7 +248,21 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
if l[i] in l[i+1:]:
return self.simple_error('', _('The value "{0}" is in the '
'list more than once').format(l[i]))
- display_dict = {'enum_values': l}
+ c = unicode(self.enum_colors.text())
+ if c:
+ c = [v.strip() for v in unicode(self.enum_colors.text()).split(',')]
+ else:
+ c = []
+ print c, len(c)
+ if len(c) != 0 and len(c) != len(l):
+ return self.simple_error('', _('The colors box must be empty or '
+ 'contain the same number of items as the value box'))
+ for tc in c:
+ if tc not in QColor.colorNames():
+ return self.simple_error('',
+ _('The color {0} is unknown').format(tc))
+
+ display_dict = {'enum_values': l, 'enum_colors': c}
elif col_type == 'text' and is_multiple:
display_dict = {'is_names': self.is_names.isChecked()}
diff --git a/src/calibre/gui2/preferences/create_custom_column.ui b/src/calibre/gui2/preferences/create_custom_column.ui
index 619b0c6212..2bdadd4b9d 100644
--- a/src/calibre/gui2/preferences/create_custom_column.ui
+++ b/src/calibre/gui2/preferences/create_custom_column.ui
@@ -304,8 +304,8 @@ Everything else will show nothing.
-
-
-
-
+
+
-
@@ -320,13 +320,34 @@ four values, the first of them being the empty value.
- -
+
-
The empty string is always the first value
- Default: (nothing)
+ Values
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ A list of color names to use when displaying an item. The
+list must be empty or contain a color for each value.
+
+
+
+ -
+
+
+ Colors
From 994974fb59afea4e781c99b0019c4d425f4ee714 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 21 May 2011 19:34:23 +0100
Subject: [PATCH 05/51] Add tooltip listing all colors available
---
src/calibre/gui2/preferences/create_custom_column.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/calibre/gui2/preferences/create_custom_column.py b/src/calibre/gui2/preferences/create_custom_column.py
index 180c3aed7a..3a245580dd 100644
--- a/src/calibre/gui2/preferences/create_custom_column.py
+++ b/src/calibre/gui2/preferences/create_custom_column.py
@@ -132,6 +132,9 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
self.use_decorations.setChecked(c['display'].get('use_decorations', False))
elif ct == '*text':
self.is_names.setChecked(c['display'].get('is_names', False))
+
+ all_colors = [unicode(s) for s in list(QColor.colorNames())]
+ self.enum_colors_label.setToolTip('' + ', '.join(all_colors) + '
')
self.exec_()
def shortcut_activated(self, url):
@@ -253,7 +256,6 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
c = [v.strip() for v in unicode(self.enum_colors.text()).split(',')]
else:
c = []
- print c, len(c)
if len(c) != 0 and len(c) != len(l):
return self.simple_error('', _('The colors box must be empty or '
'contain the same number of items as the value box'))
From 6eec4fa410eddb376b62d064549460ee754031bb Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sat, 21 May 2011 19:40:27 +0100
Subject: [PATCH 06/51] More robust coloring code in the CC Enum Delegate
---
src/calibre/gui2/library/delegates.py | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py
index ae01081736..1af0482a31 100644
--- a/src/calibre/gui2/library/delegates.py
+++ b/src/calibre/gui2/library/delegates.py
@@ -289,11 +289,14 @@ class CcEnumDelegate(QStyledItemDelegate): # {{{
elif option.state & QStyle.State_Selected:
painter.fillRect(option.rect, option.palette.highlight())
m = index.model()
- col = m.column_map[index.column()]
- colors = m.custom_columns[col]['display'].get('enum_colors', [])
- values = m.custom_columns[col]['display']['enum_values']
+ cc = m.custom_columns[m.column_map[index.column()]]['display']
+ colors = cc.get('enum_colors', [])
+ values = cc.get('enum_values', [])
if len(colors) > 0 and txt in values:
- painter.fillRect(option.rect, QColor(colors[values.index(txt)]))
+ try:
+ painter.fillRect(option.rect, QColor(colors[values.index(txt)]))
+ except:
+ pass
painter.setClipRect(option.rect)
painter.translate(option.rect.topLeft())
self.document.drawContents(painter)
From 9b52e0d4e8dfb9e5782fa48cffba3fc1d9272962 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sat, 21 May 2011 12:49:17 -0600
Subject: [PATCH 07/51] Fix #786264 (external IP and Ubuntu's 127.0.1.1 addr)
---
src/calibre/library/server/base.py | 2 +-
src/calibre/utils/mdns.py | 7 ++++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/calibre/library/server/base.py b/src/calibre/library/server/base.py
index eea28469a9..862e724809 100644
--- a/src/calibre/library/server/base.py
+++ b/src/calibre/library/server/base.py
@@ -218,7 +218,7 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache,
cherrypy.engine.start()
except:
ip = get_external_ip()
- if not ip or ip == '127.0.0.1':
+ if not ip or ip.startswith('127.'):
raise
cherrypy.log('Trying to bind to single interface: '+ip)
cherrypy.config.update({'server.socket_host' : ip})
diff --git a/src/calibre/utils/mdns.py b/src/calibre/utils/mdns.py
index b7cc8757d3..2be6bef49b 100644
--- a/src/calibre/utils/mdns.py
+++ b/src/calibre/utils/mdns.py
@@ -13,16 +13,17 @@ def _get_external_ip():
ipaddr = socket.gethostbyname(socket.gethostname())
except:
ipaddr = '127.0.0.1'
- if ipaddr == '127.0.0.1':
+ if ipaddr.startswith('127.'):
for addr in ('192.0.2.0', '198.51.100.0', 'google.com'):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((addr, 0))
ipaddr = s.getsockname()[0]
- if ipaddr != '127.0.0.1':
- return ipaddr
+ if not ipaddr.startswith('127.'):
+ break
except:
time.sleep(0.3)
+ #print 'ipaddr: %s' % ipaddr
return ipaddr
_ext_ip = None
From d4f79884a4d931bf59f462a5196032fdf7577a9a Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sat, 21 May 2011 14:16:49 -0600
Subject: [PATCH 08/51] Fix #786287 (Updated recipe for The Nation magazine)
---
recipes/icons/the_nation.png | Bin 0 -> 925 bytes
recipes/the_nation.recipe | 44 +++++++++++++++++++++++++++--------
2 files changed, 34 insertions(+), 10 deletions(-)
create mode 100644 recipes/icons/the_nation.png
diff --git a/recipes/icons/the_nation.png b/recipes/icons/the_nation.png
new file mode 100644
index 0000000000000000000000000000000000000000..fd6e6ebfb445f3beccce4f5dfb69435c7a43ee3e
GIT binary patch
literal 925
zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GXl4m>B|mLR{Y*KXGHy)E{r&e7t%4
z|NsB{BcgZs_+M;lJzZQnTTJr);w5WLEfy*$A5G0zuB8jqI|@caU^s=q{_ai7f&Pi`
zba4!+nA3aSo9}=E2TQ;f4WEU3{}*'
+__copyright__ = '2008 - 2011, Darko Miletic '
'''
thenation.com
'''
@@ -16,10 +16,17 @@ class Thenation(BasicNewsRecipe):
max_articles_per_feed = 100
no_stylesheets = True
language = 'en'
- use_embedded_content = False
- delay = 1
- masthead_url = 'http://www.thenation.com/sites/default/themes/thenation/images/logo-main.gif'
- exra_css = ' body{font-family: Arial,Helvetica,sans-serif;} .print-created{font-size: small;} .caption{display: block; font-size: x-small;} '
+ use_embedded_content = False
+ delay = 1
+ masthead_url = 'http://www.thenation.com/sites/default/themes/thenation/images/logo-main.gif'
+ login_url = 'http://www.thenation.com/user?destination=%3Cfront%3E'
+ publication_type = 'magazine'
+ needs_subscription = 'optional'
+ exra_css = """
+ body{font-family: Arial,Helvetica,sans-serif;}
+ .print-created{font-size: small;}
+ .caption{display: block; font-size: x-small;}
+ """
conversion_options = {
'comment' : description
@@ -28,13 +35,30 @@ class Thenation(BasicNewsRecipe):
, 'language' : language
}
- keep_only_tags = [ dict(attrs={'class':['print-title','print-created','print-content','print-links']}) ]
- remove_tags = [dict(name='link')]
+ keep_only_tags = [dict(attrs={'class':['print-title','print-created','print-content','print-links']})]
+ remove_tags = [dict(name=['link','iframe','base','meta','object','embed'])]
+ remove_attributes = ['lang']
- feeds = [(u"Editor's Picks", u'http://www.thenation.com/rss/editors_picks')]
+ feeds = [(u"Articles", u'http://www.thenation.com/rss/articles')]
def print_version(self, url):
return url.replace('.thenation.com/','.thenation.com/print/')
- def preprocess_html(self, soup):
- return self.adeify_images(soup)
+ def get_browser(self):
+ br = BasicNewsRecipe.get_browser()
+ br.open('http://www.thenation.com/')
+ if self.username is not None and self.password is not None:
+ br.open(self.login_url)
+ br.select_form(nr=1)
+ br['name'] = self.username
+ br['pass'] = self.password
+ br.submit()
+ return br
+
+ def get_cover_url(self):
+ soup = self.index_to_soup('http://www.thenation.com/issue/')
+ item = soup.find('div',attrs={'id':'cover-wrapper'})
+ if item:
+ return item.img['src']
+ return None
+
\ No newline at end of file
From 746b9b1d63cd6372cd19ac97d787f7bd524e6919 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sat, 21 May 2011 14:19:26 -0600
Subject: [PATCH 09/51] Fix #786293 (Updated recipe for Marca website)
---
recipes/icons/marca.png | Bin 0 -> 293 bytes
recipes/marca.recipe | 46 +++++++++++++++++-----------------------
2 files changed, 19 insertions(+), 27 deletions(-)
create mode 100644 recipes/icons/marca.png
diff --git a/recipes/icons/marca.png b/recipes/icons/marca.png
new file mode 100644
index 0000000000000000000000000000000000000000..e9231176b66532319eae2266c74d9d1c5ac30c1c
GIT binary patch
literal 293
zcmV+=0owkFP)|1AyZ(#|t
z;UK+U'
+__copyright__ = '2009-2011, Darko Miletic '
'''
www.marca.com
'''
from calibre.web.feeds.news import BasicNewsRecipe
-from calibre.ebooks.BeautifulSoup import Tag
class Marca(BasicNewsRecipe):
title = 'Marca'
@@ -22,35 +19,30 @@ class Marca(BasicNewsRecipe):
use_embedded_content = False
delay = 1
encoding = 'iso-8859-15'
- language = 'es'
+ language = 'es_ES'
+ publication_type = 'newsportal'
+ masthead_url = 'http://estaticos.marca.com/deporte/img/v3.0/img_marca-com.png'
+ extra_css = """
+ body{font-family: Tahoma,Geneva,sans-serif}
+ h1,h2,h3,h4,h5,h6{font-family: 'LatoBlack',Tahoma,Geneva,sans-serif}
+ .cab_articulo h4 {font-family: Georgia,"Times New Roman",Times,serif}
+ .antetitulo{text-transform: uppercase}
+ """
- direction = 'ltr'
+ feeds = [(u'Portada', u'http://estaticos.marca.com/rss/portada.xml')]
- html2lrf_options = [
- '--comment' , description
- , '--category' , category
- , '--publisher', publisher
- ]
-
- html2epub_options = 'publisher="' + publisher + '"\ncomments="' + description + '"\ntags="' + category + '"'
-
- feeds = [(u'Portada', u'http://rss.marca.com/rss/descarga.htm?data2=425')]
-
- keep_only_tags = [dict(name='div', attrs={'class':['cab_articulo','col_izq']})]
-
- remove_tags = [
- dict(name=['object','link','script'])
- ,dict(name='div', attrs={'class':['colC','peu']})
- ,dict(name='div', attrs={'class':['utilidades estirar','bloque_int_corr estirar']})
+ keep_only_tags = [dict(name='div', attrs={'class':['cab_articulo','cuerpo_articulo']})]
+ remove_attributes = ['lang']
+ remove_tags = [
+ dict(name=['object','link','script','embed','iframe','meta','base'])
+ ,dict(name='div', attrs={'class':'tabs'})
]
- remove_tags_after = [dict(name='div', attrs={'class':'bloque_int_corr estirar'})]
-
def preprocess_html(self, soup):
- soup.html['dir' ] = self.direction
- mcharset = Tag(soup,'meta',[("http-equiv","Content-Type"),("content","text/html; charset=utf-8")])
- soup.head.insert(0,mcharset)
for item in soup.findAll(style=True):
del item['style']
return soup
+ def get_article_url(self, article):
+ return article.get('guid', None)
+
From 13387225e04d6a9add3b7dac5ad7e2f5d11975c5 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sat, 21 May 2011 14:20:45 -0600
Subject: [PATCH 10/51] Fix #786299 (Updated recipe for El Mundo)
---
recipes/elmundo.recipe | 48 ++++++++++++++++++++++++++------------
recipes/icons/elmundo.png | Bin 550 -> 1082 bytes
2 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/recipes/elmundo.recipe b/recipes/elmundo.recipe
index aea60de304..dedd449f93 100644
--- a/recipes/elmundo.recipe
+++ b/recipes/elmundo.recipe
@@ -1,6 +1,6 @@
__license__ = 'GPL v3'
-__copyright__ = '2009, Darko Miletic '
+__copyright__ = '2009-2011, Darko Miletic '
'''
elmundo.es
'''
@@ -10,15 +10,24 @@ from calibre.web.feeds.news import BasicNewsRecipe
class ElMundo(BasicNewsRecipe):
title = 'El Mundo'
__author__ = 'Darko Miletic'
- description = 'News from Spain'
- publisher = 'El Mundo'
+ description = 'Lider de informacion en espaniol'
+ publisher = 'Unidad Editorial Informacion General S.L.U.'
category = 'news, politics, Spain'
oldest_article = 2
max_articles_per_feed = 100
no_stylesheets = True
use_embedded_content = False
encoding = 'iso8859_15'
- language = 'es'
+ language = 'es_ES'
+ masthead_url = 'http://estaticos03.elmundo.es/elmundo/iconos/v4.x/v4.01/bg_h1.png'
+ publication_type = 'newspaper'
+ extra_css = """
+ body{font-family: Arial,Helvetica,sans-serif}
+ .metadata_noticia{font-size: small}
+ h1,h2,h3,h4,h5,h6,.subtitulo {color: #3F5974}
+ .hora{color: red}
+ .update{color: gray}
+ """
conversion_options = {
'comments' : description
@@ -30,22 +39,31 @@ class ElMundo(BasicNewsRecipe):
keep_only_tags = [dict(name='div', attrs={'class':'noticia'})]
remove_tags_before = dict(attrs={'class':['titular','antetitulo'] })
remove_tags_after = dict(name='div' , attrs={'id':['desarrollo_noticia','tamano']})
-
+ remove_attributes = ['lang','border']
remove_tags = [
dict(name='div', attrs={'class':['herramientas','publicidad_google']})
,dict(name='div', attrs={'id':'modulo_multimedia' })
,dict(name='ul', attrs={'class':'herramientas' })
- ,dict(name=['object','link'])
+ ,dict(name=['object','link','embed','iframe','base','meta'])
]
feeds = [
- (u'Portada' , u'http://rss.elmundo.es/rss/descarga.htm?data2=4' )
- ,(u'Deportes' , u'http://rss.elmundo.es/rss/descarga.htm?data2=14')
- ,(u'Economia' , u'http://rss.elmundo.es/rss/descarga.htm?data2=7' )
- ,(u'Espana' , u'http://rss.elmundo.es/rss/descarga.htm?data2=8' )
- ,(u'Internacional' , u'http://rss.elmundo.es/rss/descarga.htm?data2=9' )
- ,(u'Cultura' , u'http://rss.elmundo.es/rss/descarga.htm?data2=6' )
- ,(u'Ciencia/Ecologia', u'http://rss.elmundo.es/rss/descarga.htm?data2=5' )
- ,(u'Comunicacion' , u'http://rss.elmundo.es/rss/descarga.htm?data2=26')
- ,(u'Television' , u'http://rss.elmundo.es/rss/descarga.htm?data2=76')
+ (u'Portada' , u'http://estaticos.elmundo.es/elmundo/rss/portada.xml' )
+ ,(u'Deportes' , u'http://estaticos.elmundo.es/elmundodeporte/rss/portada.xml')
+ ,(u'Economia' , u'http://estaticos.elmundo.es/elmundo/rss/economia.xml' )
+ ,(u'Espana' , u'http://estaticos.elmundo.es/elmundo/rss/espana.xml' )
+ ,(u'Internacional' , u'http://estaticos.elmundo.es/elmundo/rss/internacional.xml' )
+ ,(u'Cultura' , u'http://estaticos.elmundo.es/elmundo/rss/cultura.xml' )
+ ,(u'Ciencia/Ecologia', u'http://estaticos.elmundo.es/elmundo/rss/ciencia.xml' )
+ ,(u'Comunicacion' , u'http://estaticos.elmundo.es/elmundo/rss/comunicacion.xml' )
+ ,(u'Television' , u'http://estaticos.elmundo.es/elmundo/rss/television.xml' )
]
+
+ def preprocess_html(self, soup):
+ for item in soup.findAll(style=True):
+ del item['style']
+ return soup
+
+ def get_article_url(self, article):
+ return article.get('guid', None)
+
diff --git a/recipes/icons/elmundo.png b/recipes/icons/elmundo.png
index 754b3d0e154df866a55866b5b4174ad3e1ea1630..24467eac80e2881abcb243aa7cf797fd41050c6a 100644
GIT binary patch
literal 1082
zcmdr~{ZkSK0HxHmNU!b2cAe!fJ1@1Zwf(TVwKQx{DxI>_kZj08@UuCYD5i4e+3oCu
zlrbpzNaZs>5~mWOTuV@p_>%aXVu^qPf}W9m!?A^Wh?)~`gy%u=pg&1Hg5C8zg
zq^ChHh5e&lei#wf#N!9E0e}bq{9+C?96=es23FUaVqp~)8$?Wz1xD+b$wlY@0Z5AMBaqOWVTrC?F`nCc(}P=PocEFo_9K3
z^Arjd+4h&)z0lhyjLW?tS3F>Qg0TSUt~V
zw$=(J<#PFAFj!k#dq<>Au3~63njg-A5xJLT2CG0I*xcCmxZGr!71R2Z(mT@E|D=LG
zAQFj`N~PZJTwYoI{tQ_CQj2H5km&3NgMl(^2BluhZ63-3sv5dFiE2TV?XP%4sM!aE*bjf8J+{d{i-lG1ye;l%T(g+|gq9pV
z9K8ySrHl7QQNMlaHYa`sH-1LL5PsYTRFp^09b5N(%E~UtJ!**pr4{H7UFn!A7$ABg
z*&Zl(Pm3CiOORm)#9y4Yt_T2862jF%(B%VB7t0RNP8CG}LEHG81SCY0haHNqERBc%
zjqe-g-Y&1(%-}~>9!%)~+eV)?;6jyrW*p;v=}q?J)$WnZG76yX{Hw7^0^lJ-=sKo94f9k^KPZG_gHK+fdwdVh$ev?7MqUx!j^S73@Jl@ye
z|L~v2$O8oZakVKLGd49RevI;Qp7HPBZ~q=ip7r)M$r|(aO-}r~tyV*7hQ*Bti5n3!
zC2vGVay&AZ-)C5|*5XjXixY)A6nkcuz4`zD`F(pfH?~88|K~rnKm6XlUh>f2I~{)N
z5eFwGs|)B|;9mXr|HIGxY;JCkc>jL>F5kSpRqODYV6qdUr9emXsF8NKy
z;?w-j-l;2Q9AS8G|3AT^_OWE)O9pX^^52romw_TD%pTloHs{fqbjXG$XU!QN9~BlQ
zW@hHY`~Ux!oH0{ElHu^D;w38SFB*X1tXkq4QIcGgnpl#mn*t;lj0_Acbq$PwD8$gx
z%Fx2fz*yVBz{
Date: Sat, 21 May 2011 14:27:25 -0600
Subject: [PATCH 11/51] ...
---
setup/installer/windows/wix-template.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/setup/installer/windows/wix-template.xml b/setup/installer/windows/wix-template.xml
index 5de08e155f..9835ae8f6b 100644
--- a/setup/installer/windows/wix-template.xml
+++ b/setup/installer/windows/wix-template.xml
@@ -115,7 +115,7 @@
+ Message="This application is only supported on Windows XP SP3, or higher.">
= 501)]]>
From fb26c223a7346ea215b160c1df8b373a40b47a4a Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sat, 21 May 2011 16:29:57 -0600
Subject: [PATCH 12/51] Fix #786290 (Enhancements for building on NetBSD)
---
setup/__init__.py | 4 +++-
setup/extensions.py | 6 +++---
setup/install.py | 8 ++++----
src/calibre/__init__.py | 10 +++++-----
src/calibre/constants.py | 4 +++-
src/calibre/devices/libusb.py | 4 ++--
src/calibre/ebooks/html/input.py | 4 ++--
src/calibre/ebooks/pdf/pdftohtml.py | 6 +++---
src/calibre/gui2/__init__.py | 6 +++---
src/calibre/gui2/lrf_renderer/main.py | 6 +++---
src/calibre/gui2/viewer/main.py | 4 ++--
src/calibre/linux.py | 17 ++++++++++-------
src/calibre/utils/fonts/__init__.py | 8 ++++----
src/calibre/utils/help2man.py | 4 ++--
src/calibre/utils/network.py | 4 ++--
15 files changed, 51 insertions(+), 44 deletions(-)
diff --git a/setup/__init__.py b/setup/__init__.py
index 61bafd2282..4a8d9870be 100644
--- a/setup/__init__.py
+++ b/setup/__init__.py
@@ -12,7 +12,9 @@ is64bit = platform.architecture()[0] == '64bit'
iswindows = re.search('win(32|64)', sys.platform)
isosx = 'darwin' in sys.platform
isfreebsd = 'freebsd' in sys.platform
-islinux = not isosx and not iswindows and not isfreebsd
+isnetbsd = 'netbsd' in sys.platform
+isbsd = isnetbsd or isfreebsd
+islinux = not isosx and not iswindows and not isbsd
SRC = os.path.abspath('src')
sys.path.insert(0, SRC)
sys.resources_location = os.path.join(os.path.dirname(SRC), 'resources')
diff --git a/setup/extensions.py b/setup/extensions.py
index 6e8e7ce4b7..678859432d 100644
--- a/setup/extensions.py
+++ b/setup/extensions.py
@@ -11,7 +11,7 @@ from distutils import sysconfig
from PyQt4.pyqtconfig import QtGuiModuleMakefile
-from setup import Command, islinux, isfreebsd, isosx, SRC, iswindows
+from setup import Command, islinux, isfreebsd, isbsd, isosx, SRC, iswindows
from setup.build_environment import fc_inc, fc_lib, chmlib_inc_dirs, \
fc_error, poppler_libs, poppler_lib_dirs, poppler_inc_dirs, podofo_inc, \
podofo_lib, podofo_error, poppler_error, pyqt, OSX_SDK, NMAKE, \
@@ -21,7 +21,7 @@ from setup.build_environment import fc_inc, fc_lib, chmlib_inc_dirs, \
jpg_lib_dirs, chmlib_lib_dirs, sqlite_inc_dirs, icu_inc_dirs, \
icu_lib_dirs
MT
-isunix = islinux or isosx or isfreebsd
+isunix = islinux or isosx or isbsd
make = 'make' if isunix else NMAKE
@@ -205,7 +205,7 @@ if islinux:
ldflags.append('-lpython'+sysconfig.get_python_version())
-if isfreebsd:
+if isbsd:
cflags.append('-pthread')
ldflags.append('-shared')
cflags.append('-I'+sysconfig.get_python_inc())
diff --git a/setup/install.py b/setup/install.py
index e1a1190ff9..7290dbd799 100644
--- a/setup/install.py
+++ b/setup/install.py
@@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
import sys, os, textwrap, subprocess, shutil, tempfile, atexit, stat, shlex
-from setup import Command, islinux, isfreebsd, basenames, modules, functions, \
+from setup import Command, islinux, isfreebsd, isbsd, basenames, modules, functions, \
__appname__, __version__
HEADER = '''\
@@ -116,7 +116,7 @@ class Develop(Command):
def pre_sub_commands(self, opts):
- if not (islinux or isfreebsd):
+ if not (islinux or isbsd):
self.info('\nSetting up a source based development environment is only '
'supported on linux. On other platforms, see the User Manual'
' for help with setting up a development environment.')
@@ -156,7 +156,7 @@ class Develop(Command):
self.warn('Failed to compile mount helper. Auto mounting of',
' devices will not work')
- if not isfreebsd and os.geteuid() != 0:
+ if not isbsd and os.geteuid() != 0:
return self.warn('Must be run as root to compile mount helper. Auto '
'mounting of devices will not work.')
src = os.path.join(self.SRC, 'calibre', 'devices', 'linux_mount_helper.c')
@@ -168,7 +168,7 @@ class Develop(Command):
ret = p.wait()
if ret != 0:
return warn()
- if not isfreebsd:
+ if not isbsd:
os.chown(dest, 0, 0)
os.chmod(dest, stat.S_ISUID|stat.S_ISGID|stat.S_IRUSR|stat.S_IWUSR|\
stat.S_IXUSR|stat.S_IXGRP|stat.S_IXOTH)
diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py
index b82ea984ec..3a35feb66f 100644
--- a/src/calibre/__init__.py
+++ b/src/calibre/__init__.py
@@ -12,10 +12,10 @@ from functools import partial
warnings.simplefilter('ignore', DeprecationWarning)
-from calibre.constants import (iswindows, isosx, islinux, isfreebsd, isfrozen,
- preferred_encoding, __appname__, __version__, __author__,
- win32event, win32api, winerror, fcntl,
- filesystem_encoding, plugins, config_dir)
+from calibre.constants import (iswindows, isosx, islinux, isfrozen,
+ isbsd, preferred_encoding, __appname__, __version__, __author__,
+ win32event, win32api, winerror, fcntl,
+ filesystem_encoding, plugins, config_dir)
from calibre.startup import winutil, winutilerror
if False and islinux and not getattr(sys, 'frozen', False):
@@ -31,7 +31,7 @@ if False:
# Prevent pyflakes from complaining
winutil, winutilerror, __appname__, islinux, __version__
fcntl, win32event, isfrozen, __author__
- winerror, win32api, isfreebsd
+ winerror, win32api, isbsd
_mt_inited = False
def _init_mimetypes():
diff --git a/src/calibre/constants.py b/src/calibre/constants.py
index b22739cbb2..ef46b0bef2 100644
--- a/src/calibre/constants.py
+++ b/src/calibre/constants.py
@@ -27,7 +27,9 @@ iswindows = 'win32' in _plat or 'win64' in _plat
isosx = 'darwin' in _plat
isnewosx = isosx and getattr(sys, 'new_app_bundle', False)
isfreebsd = 'freebsd' in _plat
-islinux = not(iswindows or isosx or isfreebsd)
+isnetbsd = 'netbsd' in _plat
+isbsd = isfreebsd or isnetbsd
+islinux = not(iswindows or isosx or isbsd)
isfrozen = hasattr(sys, 'frozen')
isunix = isosx or islinux
diff --git a/src/calibre/devices/libusb.py b/src/calibre/devices/libusb.py
index 2d4911c799..016a6b18aa 100644
--- a/src/calibre/devices/libusb.py
+++ b/src/calibre/devices/libusb.py
@@ -8,10 +8,10 @@ from ctypes import cdll, POINTER, byref, pointer, Structure as _Structure, \
c_ubyte, c_ushort, c_int, c_char, c_void_p, c_byte, c_uint
from errno import EBUSY, ENOMEM
-from calibre import iswindows, isosx, isfreebsd, load_library
+from calibre import iswindows, isosx, isbsd, load_library
_libusb_name = 'libusb'
-PATH_MAX = 511 if iswindows else 1024 if (isosx or isfreebsd) else 4096
+PATH_MAX = 511 if iswindows else 1024 if (isosx or isbsd) else 4096
if iswindows:
class Structure(_Structure):
_pack_ = 1
diff --git a/src/calibre/ebooks/html/input.py b/src/calibre/ebooks/html/input.py
index b22f7d2791..3d5f6c00ef 100644
--- a/src/calibre/ebooks/html/input.py
+++ b/src/calibre/ebooks/html/input.py
@@ -20,7 +20,7 @@ from itertools import izip
from calibre.customize.conversion import InputFormatPlugin
from calibre.ebooks.chardet import xml_to_unicode
from calibre.customize.conversion import OptionRecommendation
-from calibre.constants import islinux, isfreebsd, iswindows
+from calibre.constants import islinux, isbsd, iswindows
from calibre import unicode_path, as_unicode
from calibre.utils.localization import get_lang
from calibre.utils.filenames import ascii_filename
@@ -302,7 +302,7 @@ class HTMLInput(InputFormatPlugin):
if getattr(self, '_is_case_sensitive', None) is not None:
return self._is_case_sensitive
if not path or not os.path.exists(path):
- return islinux or isfreebsd
+ return islinux or isbsd
self._is_case_sensitive = not (os.path.exists(path.lower()) \
and os.path.exists(path.upper()))
return self._is_case_sensitive
diff --git a/src/calibre/ebooks/pdf/pdftohtml.py b/src/calibre/ebooks/pdf/pdftohtml.py
index 4aa0953738..a791dab48a 100644
--- a/src/calibre/ebooks/pdf/pdftohtml.py
+++ b/src/calibre/ebooks/pdf/pdftohtml.py
@@ -13,7 +13,7 @@ from functools import partial
from calibre.ebooks import ConversionError, DRMError
from calibre.ptempfile import PersistentTemporaryFile
-from calibre.constants import isosx, iswindows, islinux, isfreebsd
+from calibre.constants import isosx, iswindows, islinux, isbsd
from calibre import CurrentDir
PDFTOHTML = 'pdftohtml'
@@ -23,7 +23,7 @@ if isosx and hasattr(sys, 'frameworks_dir'):
if iswindows and hasattr(sys, 'frozen'):
PDFTOHTML = os.path.join(os.path.dirname(sys.executable), 'pdftohtml.exe')
popen = partial(subprocess.Popen, creationflags=0x08) # CREATE_NO_WINDOW=0x08 so that no ugly console is popped up
-if (islinux or isfreebsd) and getattr(sys, 'frozen', False):
+if (islinux or isbsd) and getattr(sys, 'frozen', False):
PDFTOHTML = os.path.join(sys.executables_location, 'bin', 'pdftohtml')
def pdftohtml(output_dir, pdf_path, no_images):
@@ -43,7 +43,7 @@ def pdftohtml(output_dir, pdf_path, no_images):
# This is neccessary as pdftohtml doesn't always (linux) respect absolute paths
pdf_path = os.path.abspath(pdf_path)
cmd = [PDFTOHTML, '-enc', 'UTF-8', '-noframes', '-p', '-nomerge', '-nodrm', '-q', pdf_path, os.path.basename(index)]
- if isfreebsd:
+ if isbsd:
cmd.remove('-nodrm')
if no_images:
cmd.append('-i')
diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py
index 8007b6cd19..2cb18f3bda 100644
--- a/src/calibre/gui2/__init__.py
+++ b/src/calibre/gui2/__init__.py
@@ -12,7 +12,7 @@ from PyQt4.Qt import (QVariant, QFileInfo, QObject, SIGNAL, QBuffer, Qt,
ORG_NAME = 'KovidsBrain'
APP_UID = 'libprs500'
-from calibre.constants import islinux, iswindows, isfreebsd, isfrozen, isosx
+from calibre.constants import islinux, iswindows, isbsd, isfrozen, isosx
from calibre.utils.config import Config, ConfigProxy, dynamic, JSONConfig
from calibre.utils.localization import set_qt_translator
from calibre.ebooks.metadata import MetaInformation
@@ -628,7 +628,7 @@ class Application(QApplication):
st = self.style()
if st is not None:
st = unicode(st.objectName()).lower()
- if (islinux or isfreebsd) and st in ('windows', 'motif', 'cde'):
+ if (islinux or isbsd) and st in ('windows', 'motif', 'cde'):
from PyQt4.Qt import QStyleFactory
styles = set(map(unicode, QStyleFactory.keys()))
if 'Plastique' in styles and os.environ.get('KDE_FULL_SESSION',
@@ -697,7 +697,7 @@ def open_local_file(path):
def is_ok_to_use_qt():
global gui_thread, _store_app
- if (islinux or isfreebsd) and ':' not in os.environ.get('DISPLAY', ''):
+ if (islinux or isbsd) and ':' not in os.environ.get('DISPLAY', ''):
return False
if _store_app is None and QApplication.instance() is None:
_store_app = QApplication([])
diff --git a/src/calibre/gui2/lrf_renderer/main.py b/src/calibre/gui2/lrf_renderer/main.py
index e68e04adcf..0575d106f4 100644
--- a/src/calibre/gui2/lrf_renderer/main.py
+++ b/src/calibre/gui2/lrf_renderer/main.py
@@ -5,7 +5,7 @@ import sys, logging, os, traceback, time
from PyQt4.QtGui import QKeySequence, QPainter, QDialog, QSpinBox, QSlider, QIcon
from PyQt4.QtCore import Qt, QObject, SIGNAL, QCoreApplication, QThread
-from calibre import __appname__, setup_cli_handlers, islinux, isfreebsd
+from calibre import __appname__, setup_cli_handlers, islinux, isbsd
from calibre.ebooks.lrf.lrfparser import LRFDocument
from calibre.gui2 import ORG_NAME, APP_UID, error_dialog, \
@@ -258,7 +258,7 @@ def file_renderer(stream, opts, parent=None, logger=None):
level = logging.DEBUG if opts.verbose else logging.INFO
logger = logging.getLogger('lrfviewer')
setup_cli_handlers(logger, level)
- if islinux or isfreebsd:
+ if islinux or isbsd:
try: # Set lrfviewer as the default for LRF files for this user
from subprocess import call
call('xdg-mime default calibre-lrfviewer.desktop application/lrf', shell=True)
@@ -307,7 +307,7 @@ def main(args=sys.argv, logger=None):
if hasattr(opts, 'help'):
parser.print_help()
return 1
- pid = os.fork() if (islinux or isfreebsd) else -1
+ pid = os.fork() if (islinux or isbsd) else -1
if pid <= 0:
app = Application(args)
app.setWindowIcon(QIcon(I('viewer.png')))
diff --git a/src/calibre/gui2/viewer/main.py b/src/calibre/gui2/viewer/main.py
index 303d73dc11..e25d59c5ad 100644
--- a/src/calibre/gui2/viewer/main.py
+++ b/src/calibre/gui2/viewer/main.py
@@ -20,7 +20,7 @@ from calibre.gui2 import Application, ORG_NAME, APP_UID, choose_files, \
info_dialog, error_dialog, open_url, available_height
from calibre.ebooks.oeb.iterator import EbookIterator
from calibre.ebooks import DRMError
-from calibre.constants import islinux, isfreebsd, isosx, filesystem_encoding
+from calibre.constants import islinux, isbsd, isosx, filesystem_encoding
from calibre.utils.config import Config, StringConfig, JSONConfig
from calibre.gui2.search_box import SearchBox2
from calibre.ebooks.metadata import MetaInformation
@@ -801,7 +801,7 @@ def main(args=sys.argv):
parser = option_parser()
opts, args = parser.parse_args(args)
- pid = os.fork() if False and (islinux or isfreebsd) else -1
+ pid = os.fork() if False and (islinux or isbsd) else -1
if pid <= 0:
app = Application(args)
app.setWindowIcon(QIcon(I('viewer.png')))
diff --git a/src/calibre/linux.py b/src/calibre/linux.py
index d83bba061f..1e7a62b869 100644
--- a/src/calibre/linux.py
+++ b/src/calibre/linux.py
@@ -7,7 +7,7 @@ import sys, os, cPickle, textwrap, stat, importlib
from subprocess import check_call
from calibre import __appname__, prints, guess_type
-from calibre.constants import islinux, isfreebsd
+from calibre.constants import islinux, isnetbsd, isbsd
from calibre.customize.ui import all_input_formats
from calibre.ptempfile import TemporaryDirectory
from calibre import CurrentDir
@@ -136,17 +136,17 @@ class PostInstall:
self.icon_resources = []
self.menu_resources = []
self.mime_resources = []
- if islinux or isfreebsd:
+ if islinux or isbsd:
self.setup_completion()
self.install_man_pages()
- if islinux or isfreebsd:
+ if islinux or isbsd:
self.setup_desktop_integration()
self.create_uninstaller()
from calibre.utils.config import config_dir
if os.path.exists(config_dir):
os.chdir(config_dir)
- if islinux or isfreebsd:
+ if islinux or isbsd:
for f in os.listdir('.'):
if os.stat(f).st_uid == 0:
import shutil
@@ -196,7 +196,10 @@ class PostInstall:
if os.path.exists(bc):
f = os.path.join(bc, 'calibre')
else:
- f = os.path.join(self.opts.staging_etc, 'bash_completion.d/calibre')
+ if isnetbsd:
+ f = os.path.join(self.opts.staging_root, 'share/bash_completion.d/calibre')
+ else:
+ f = os.path.join(self.opts.staging_etc, 'bash_completion.d/calibre')
if not os.path.exists(os.path.dirname(f)):
os.makedirs(os.path.dirname(f))
self.manifest.append(f)
@@ -300,7 +303,7 @@ class PostInstall:
def install_man_pages(self): # {{{
try:
from calibre.utils.help2man import create_man_page
- if isfreebsd:
+ if isbsd:
manpath = os.path.join(self.opts.staging_root, 'man/man1')
else:
manpath = os.path.join(self.opts.staging_sharedir, 'man/man1')
@@ -316,7 +319,7 @@ class PostInstall:
continue
parser = parser()
raw = create_man_page(prog, parser)
- if isfreebsd:
+ if isbsd:
manfile = os.path.join(manpath, prog+'.1')
else:
manfile = os.path.join(manpath, prog+'.1'+__appname__+'.bz2')
diff --git a/src/calibre/utils/fonts/__init__.py b/src/calibre/utils/fonts/__init__.py
index 3db3a1b285..7b4f0abea4 100644
--- a/src/calibre/utils/fonts/__init__.py
+++ b/src/calibre/utils/fonts/__init__.py
@@ -8,14 +8,14 @@ __docformat__ = 'restructuredtext en'
import os, sys
-from calibre.constants import plugins, iswindows, islinux, isfreebsd
+from calibre.constants import plugins, iswindows, islinux, isbsd
_fc, _fc_err = plugins['fontconfig']
if _fc is None:
raise RuntimeError('Failed to load fontconfig with error:'+_fc_err)
-if islinux or isfreebsd:
+if islinux or isbsd:
Thread = object
else:
from threading import Thread
@@ -49,7 +49,7 @@ class FontConfig(Thread):
self.failed = True
def wait(self):
- if not (islinux or isfreebsd):
+ if not (islinux or isbsd):
self.join()
if self.failed:
raise RuntimeError('Failed to initialize fontconfig')
@@ -149,7 +149,7 @@ class FontConfig(Thread):
return fonts if all else (fonts[0] if fonts else None)
fontconfig = FontConfig()
-if islinux or isfreebsd:
+if islinux or isbsd:
# On X11 Qt also uses fontconfig, so initialization must happen in the
# main thread. In any case on X11 initializing fontconfig should be very
# fast
diff --git a/src/calibre/utils/help2man.py b/src/calibre/utils/help2man.py
index 7acf3e0c21..00989a168d 100644
--- a/src/calibre/utils/help2man.py
+++ b/src/calibre/utils/help2man.py
@@ -4,7 +4,7 @@ __copyright__ = '2009, Kovid Goyal '
__docformat__ = 'restructuredtext en'
import time, bz2
-from calibre.constants import isfreebsd
+from calibre.constants import isbsd
from calibre.constants import __version__, __appname__, __author__
@@ -58,7 +58,7 @@ def create_man_page(prog, parser):
lines = [x if isinstance(x, unicode) else unicode(x, 'utf-8', 'replace') for
x in lines]
- if not isfreebsd:
+ if not isbsd:
return bz2.compress((u'\n'.join(lines)).encode('utf-8'))
else:
return (u'\n'.join(lines)).encode('utf-8')
diff --git a/src/calibre/utils/network.py b/src/calibre/utils/network.py
index 7e840207cf..c47eacbe3f 100644
--- a/src/calibre/utils/network.py
+++ b/src/calibre/utils/network.py
@@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal '
__docformat__ = 'restructuredtext en'
-from calibre.constants import iswindows, islinux, isfreebsd
+from calibre.constants import iswindows, islinux, isbsd
class LinuxNetworkStatus(object):
@@ -47,7 +47,7 @@ class DummyNetworkStatus(object):
return True
_network_status = WindowsNetworkStatus() if iswindows else \
- LinuxNetworkStatus() if (islinux or isfreebsd) else \
+ LinuxNetworkStatus() if (islinux or isbsd) else \
DummyNetworkStatus()
def internet_connected():
From a6ece012ea51b4a5a07522e6823f909ac61f51f0 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sat, 21 May 2011 18:02:37 -0600
Subject: [PATCH 13/51] Windows installer: Remember and use previous
installation folder when upgrading
---
setup/installer/windows/wix-template.xml | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/setup/installer/windows/wix-template.xml b/setup/installer/windows/wix-template.xml
index 9835ae8f6b..8526c27720 100644
--- a/setup/installer/windows/wix-template.xml
+++ b/setup/installer/windows/wix-template.xml
@@ -26,6 +26,11 @@
+
+
+
+
@@ -43,6 +48,9 @@
+
+
+
@@ -87,7 +95,8 @@
ConfigurableDirectory="APPLICATIONFOLDER">
+ Description="All the files needed to run {app}" Absent="disallow">
+
From c3688278d0ac265fa4d53a084ca1b855300c9dcc Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sun, 22 May 2011 13:00:30 +0100
Subject: [PATCH 14/51] First cut at template-based column coloring
---
.../gui2/dialogs/template_line_editor.py | 31 +++++++
src/calibre/gui2/init.py | 1 +
src/calibre/gui2/library/delegates.py | 79 +++++++-----------
src/calibre/gui2/library/models.py | 36 +++++++-
src/calibre/gui2/preferences/look_feel.py | 8 ++
src/calibre/gui2/preferences/look_feel.ui | 83 +++++++++++++++++++
src/calibre/library/database2.py | 4 +
7 files changed, 191 insertions(+), 51 deletions(-)
create mode 100644 src/calibre/gui2/dialogs/template_line_editor.py
diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py
new file mode 100644
index 0000000000..d7ba8e4900
--- /dev/null
+++ b/src/calibre/gui2/dialogs/template_line_editor.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
+
+__license__ = 'GPL v3'
+__copyright__ = '2010, Kovid Goyal '
+__docformat__ = 'restructuredtext en'
+
+from PyQt4.Qt import (SIGNAL, QLineEdit)
+from calibre.gui2.dialogs.template_dialog import TemplateDialog
+
+class LineEditWithTextBox(QLineEdit):
+
+ '''
+ Extend the context menu of a QLineEdit to include more actions.
+ '''
+
+ def contextMenuEvent(self, event):
+ menu = self.createStandardContextMenu()
+ menu.addSeparator()
+
+ action_open_editor = menu.addAction(_('Open Editor'))
+
+ self.connect(action_open_editor, SIGNAL('triggered()'), self.open_editor)
+ menu.exec_(event.globalPos())
+
+ def open_editor(self):
+ t = TemplateDialog(self, self.text())
+ if t.exec_():
+ self.setText(t.textbox.toPlainText())
+
+
diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py
index a75ff01b21..079e1814c3 100644
--- a/src/calibre/gui2/init.py
+++ b/src/calibre/gui2/init.py
@@ -65,6 +65,7 @@ class LibraryViewMixin(object): # {{{
self.build_context_menus()
self.library_view.model().set_highlight_only(config['highlight_search_matches'])
+ self.library_view.model().set_color_templates()
def build_context_menus(self):
lm = QMenu(self)
diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py
index 1af0482a31..042e568d8b 100644
--- a/src/calibre/gui2/library/delegates.py
+++ b/src/calibre/gui2/library/delegates.py
@@ -7,11 +7,12 @@ __docformat__ = 'restructuredtext en'
from math import cos, sin, pi
-from PyQt4.Qt import QColor, Qt, QModelIndex, QSize, \
- QPainterPath, QLinearGradient, QBrush, \
+from PyQt4.Qt import QColor, Qt, QModelIndex, QSize, QPalette, \
+ QPainterPath, QLinearGradient, QBrush, QApplication, \
QPen, QStyle, QPainter, QStyleOptionViewItemV4, \
QIcon, QDoubleSpinBox, QVariant, QSpinBox, \
- QStyledItemDelegate, QComboBox, QTextDocument
+ QStyledItemDelegate, QComboBox, QTextDocument, \
+ QAbstractTextDocumentLayout
from calibre.gui2 import UNDEFINED_QDATE, error_dialog
from calibre.gui2.widgets import EnLineEdit
@@ -51,9 +52,7 @@ class RatingDelegate(QStyledItemDelegate): # {{{
return QSize(5*(self.SIZE), self.SIZE+4)
def paint(self, painter, option, index):
- style = self._parent.style()
- option = QStyleOptionViewItemV4(option)
- self.initStyleOption(option, self.dummy)
+ self.initStyleOption(option, index)
num = index.model().data(index, Qt.DisplayRole).toInt()[0]
def draw_star():
painter.save()
@@ -65,18 +64,24 @@ class RatingDelegate(QStyledItemDelegate): # {{{
painter.restore()
painter.save()
- if hasattr(QStyle, 'CE_ItemViewItem'):
- style.drawControl(QStyle.CE_ItemViewItem, option,
- painter, self._parent)
- elif option.state & QStyle.State_Selected:
+ if option.state & QStyle.State_Selected:
painter.fillRect(option.rect, option.palette.highlight())
+ else:
+ painter.fillRect(option.rect, option.backgroundBrush)
+
try:
painter.setRenderHint(QPainter.Antialiasing)
painter.setClipRect(option.rect)
y = option.rect.center().y()-self.SIZE/2.
x = option.rect.left()
- painter.setPen(self.PEN)
- painter.setBrush(self.brush)
+ brush = index.model().data(index, role=Qt.ForegroundRole)
+ if brush is None:
+ pen = self.PEN
+ painter.setBrush(self.COLOR)
+ else:
+ pen = QPen(brush, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
+ painter.setBrush(brush)
+ painter.setPen(pen)
painter.translate(x, y)
i = 0
while i < num:
@@ -274,34 +279,6 @@ class CcEnumDelegate(QStyledItemDelegate): # {{{
Delegate for text/int/float data.
'''
- def __init__(self, parent):
- QStyledItemDelegate.__init__(self, parent)
- self.document = QTextDocument()
-
- def paint(self, painter, option, index):
- style = self.parent().style()
- txt = unicode(index.data(Qt.DisplayRole).toString())
- self.document.setPlainText(txt)
- painter.save()
- if hasattr(QStyle, 'CE_ItemViewItem'):
- style.drawControl(QStyle.CE_ItemViewItem, option,
- painter, self.parent())
- elif option.state & QStyle.State_Selected:
- painter.fillRect(option.rect, option.palette.highlight())
- m = index.model()
- cc = m.custom_columns[m.column_map[index.column()]]['display']
- colors = cc.get('enum_colors', [])
- values = cc.get('enum_values', [])
- if len(colors) > 0 and txt in values:
- try:
- painter.fillRect(option.rect, QColor(colors[values.index(txt)]))
- except:
- pass
- painter.setClipRect(option.rect)
- painter.translate(option.rect.topLeft())
- self.document.drawContents(painter)
- painter.restore()
-
def createEditor(self, parent, option, index):
m = index.model()
col = m.column_map[index.column()]
@@ -339,17 +316,19 @@ class CcCommentsDelegate(QStyledItemDelegate): # {{{
self.document = QTextDocument()
def paint(self, painter, option, index):
- style = self.parent().style()
- self.document.setHtml(index.data(Qt.DisplayRole).toString())
+ self.initStyleOption(option, index)
+ style = QApplication.style() if option.widget is None \
+ else option.widget.style()
+ self.document.setHtml(option.text)
+ option.text = ""
+ style.drawControl(QStyle.CE_ItemViewItem, option, painter);
+ ctx = QAbstractTextDocumentLayout.PaintContext()
+ ctx.palette = option.palette #.setColor(QPalette.Text, QColor("red"));
+ textRect = style.subElementRect(QStyle.SE_ItemViewItemText, option)
painter.save()
- if hasattr(QStyle, 'CE_ItemViewItem'):
- style.drawControl(QStyle.CE_ItemViewItem, option,
- painter, self.parent())
- elif option.state & QStyle.State_Selected:
- painter.fillRect(option.rect, option.palette.highlight())
- painter.setClipRect(option.rect)
- painter.translate(option.rect.topLeft())
- self.document.drawContents(painter)
+ painter.translate(textRect.topLeft())
+ painter.setClipRect(textRect.translated(-textRect.topLeft()))
+ self.document.documentLayout().draw(painter, ctx)
painter.restore()
def createEditor(self, parent, option, index):
diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py
index fc1117167d..7d6cfadacb 100644
--- a/src/calibre/gui2/library/models.py
+++ b/src/calibre/gui2/library/models.py
@@ -14,6 +14,7 @@ from PyQt4.Qt import (QAbstractTableModel, Qt, pyqtSignal, QIcon, QImage,
from calibre.gui2 import NONE, UNDEFINED_QDATE
from calibre.utils.pyparsing import ParseException
from calibre.ebooks.metadata import fmt_sidx, authors_to_string, string_to_authors
+from calibre.ebooks.metadata.book.base import composite_formatter
from calibre.ptempfile import PersistentTemporaryFile
from calibre.utils.config import tweaks, prefs
from calibre.utils.date import dt_factory, qt_to_dt
@@ -96,6 +97,7 @@ class BooksModel(QAbstractTableModel): # {{{
self.ids_to_highlight_set = set()
self.current_highlighted_idx = None
self.highlight_only = False
+ self.column_color_map = {}
self.read_config()
def change_alignment(self, colname, alignment):
@@ -532,6 +534,16 @@ class BooksModel(QAbstractTableModel): # {{{
img = self.default_image
return img
+ def set_color_templates(self):
+ print 'here'
+ self.column_color_map = {}
+ for i in range(1,self.db.column_color_count+1):
+ name = self.db.prefs.get('column_color_name_'+str(i))
+ if name:
+ print name, self.db.prefs.get('column_color_template_'+str(i))
+ self.column_color_map[name] = \
+ self.db.prefs.get('column_color_template_'+str(i))
+ self.refresh()
def build_data_convertors(self):
def authors(r, idx=-1):
@@ -693,9 +705,31 @@ class BooksModel(QAbstractTableModel): # {{{
return NONE
if role in (Qt.DisplayRole, Qt.EditRole):
return self.column_to_dc_map[col](index.row())
- elif role == Qt.BackgroundColorRole:
+ elif role == Qt.BackgroundRole:
if self.id(index) in self.ids_to_highlight_set:
return QColor('lightgreen')
+ elif role == Qt.ForegroundRole:
+ key = self.column_map[col]
+ if key in self.column_color_map:
+ mi = self.db.get_metadata(self.id(index), index_is_id=True)
+ fmt = self.column_color_map[key]
+ try:
+ color = composite_formatter.safe_format(fmt, mi, '', mi)
+ return QColor(color)
+ except:
+ return None
+ elif self.is_custom_column(key) and \
+ self.custom_columns[key]['datatype'] == 'enumeration':
+ cc = self.custom_columns[self.column_map[col]]['display']
+ colors = cc.get('enum_colors', [])
+ values = cc.get('enum_values', [])
+ txt = unicode(index.data(Qt.DisplayRole).toString())
+ if len(colors) > 0 and txt in values:
+ try:
+ return QColor(colors[values.index(txt)])
+ except:
+ pass
+ return None
elif role == Qt.DecorationRole:
if self.column_to_dc_decorator_map[col] is not None:
return self.column_to_dc_decorator_map[index.column()](index.row())
diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py
index ee2d7a5428..fc6990fcc9 100644
--- a/src/calibre/gui2/preferences/look_feel.py
+++ b/src/calibre/gui2/preferences/look_feel.py
@@ -159,6 +159,13 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.df_up_button.clicked.connect(self.move_df_up)
self.df_down_button.clicked.connect(self.move_df_down)
+ choices = db.field_metadata.displayable_field_keys()
+ choices.sort(key=sort_key)
+ choices.insert(0, '')
+ for i in range(1, db.column_color_count+1):
+ r('column_color_name_'+str(i), db.prefs, choices=choices)
+ r('column_color_template_'+str(i), db.prefs)
+
def initialize(self):
ConfigWidgetBase.initialize(self)
font = gprefs['font']
@@ -238,6 +245,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
return rr
def refresh_gui(self, gui):
+ gui.library_view.model().set_color_templates()
self.update_font_display()
gui.tags_view.reread_collapse_parameters()
gui.library_view.refresh_book_details()
diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui
index 244b811cbd..d7fca70c08 100644
--- a/src/calibre/gui2/preferences/look_feel.ui
+++ b/src/calibre/gui2/preferences/look_feel.ui
@@ -407,6 +407,84 @@ then the tags will be displayed each on their own line.
+
+
+
+ :/images/cover_flow.png:/images/cover_flow.png
+
+
+ Column Coloring
+
+
+ -
+
+
+ Column name
+
+
+
+ -
+
+
+ Selection template
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 690
+ 283
+
+
+
+
+
+
@@ -417,6 +495,11 @@ then the tags will be displayed each on their own line.
QLineEdit
+
+ LineEditWithTextBox
+ QLineEdit
+ calibre/gui2/dialogs/template_line_editor.h
+
diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py
index 9a740a08b7..819ac2cd24 100644
--- a/src/calibre/library/database2.py
+++ b/src/calibre/library/database2.py
@@ -211,6 +211,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
defs = self.prefs.defaults
defs['gui_restriction'] = defs['cs_restriction'] = ''
defs['categories_using_hierarchy'] = []
+ self.column_color_count = 5
+ for i in range(1,self.column_color_count+1):
+ defs['column_color_name_'+str(i)] = ''
+ defs['column_color_template_'+str(i)] = ''
# Migrate the bool tristate tweak
defs['bools_are_tristate'] = \
From 3c92c4a988eca819c813baf2f306cc0cfbff69c9 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sun, 22 May 2011 14:14:23 +0100
Subject: [PATCH 15/51] More work on coloring columns. Refactor the template
editor, add some documentation for the new template function first_non_empty,
add help text to the configuration dialog.
---
.../gui2/dialogs/template_line_editor.py | 2 +-
src/calibre/gui2/library/models.py | 2 -
src/calibre/gui2/preferences/look_feel.py | 26 +++++++-
src/calibre/gui2/preferences/look_feel.ui | 66 +++++++++++--------
src/calibre/gui2/preferences/plugboard.py | 26 +-------
src/calibre/manual/template_lang.rst | 1 +
src/calibre/utils/formatter_functions.py | 19 +++++-
7 files changed, 85 insertions(+), 57 deletions(-)
diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py
index d7ba8e4900..69999f59a0 100644
--- a/src/calibre/gui2/dialogs/template_line_editor.py
+++ b/src/calibre/gui2/dialogs/template_line_editor.py
@@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
from PyQt4.Qt import (SIGNAL, QLineEdit)
from calibre.gui2.dialogs.template_dialog import TemplateDialog
-class LineEditWithTextBox(QLineEdit):
+class TemplateLineEditor(QLineEdit):
'''
Extend the context menu of a QLineEdit to include more actions.
diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py
index 7d6cfadacb..83bf5868ba 100644
--- a/src/calibre/gui2/library/models.py
+++ b/src/calibre/gui2/library/models.py
@@ -535,12 +535,10 @@ class BooksModel(QAbstractTableModel): # {{{
return img
def set_color_templates(self):
- print 'here'
self.column_color_map = {}
for i in range(1,self.db.column_color_count+1):
name = self.db.prefs.get('column_color_name_'+str(i))
if name:
- print name, self.db.prefs.get('column_color_template_'+str(i))
self.column_color_map[name] = \
self.db.prefs.get('column_color_template_'+str(i))
self.refresh()
diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py
index fc6990fcc9..97400c45bd 100644
--- a/src/calibre/gui2/preferences/look_feel.py
+++ b/src/calibre/gui2/preferences/look_feel.py
@@ -6,7 +6,7 @@ __copyright__ = '2010, Kovid Goyal '
__docformat__ = 'restructuredtext en'
from PyQt4.Qt import (QApplication, QFont, QFontInfo, QFontDialog,
- QAbstractListModel, Qt)
+ QAbstractListModel, Qt, QColor)
from calibre.gui2.preferences import ConfigWidgetBase, test_widget, CommaSeparatedList
from calibre.gui2.preferences.look_feel_ui import Ui_Form
@@ -159,12 +159,36 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.df_up_button.clicked.connect(self.move_df_up)
self.df_down_button.clicked.connect(self.move_df_down)
+ self.color_help_text.setWordWrap(True)
+ self.color_help_text.setText('' +
+ _('Here you can specify coloring rules for fields shown in the '
+ 'library view. Choose the field you wish to color, then '
+ 'supply a template that specifies the color to use.') +
+ '
' +
+ _('The template must evaluate to one of the color names shown '
+ 'below. You can use any legal template expression. '
+ 'For example, you can set the title to always display in '
+ 'green using the template "green" (without the quotes). '
+ 'To show the title in blue if the book has the tag "Science '
+ 'Fiction", red if the book has the tag "Mystery", or black if '
+ 'the book has neither tag, use '
+ '"{tags:switch(Science Fiction,blue,Mystery,red,)}" '
+ 'To show the title in green if it has one format, blue if it '
+ 'two formats, and red if more, use '
+ "\"program:cmp(count(field('formats'),','), 2, 'green', 'blue', 'red')\"") +
+ '
' +
+ _('Note: if you want to color a "custom column with a fixed set '
+ 'of values", it is possible and often easier to specify the '
+ 'colors in the column definition dialog. There you can '
+ 'provide a color for each value without using a template.')+ '
')
choices = db.field_metadata.displayable_field_keys()
choices.sort(key=sort_key)
choices.insert(0, '')
for i in range(1, db.column_color_count+1):
r('column_color_name_'+str(i), db.prefs, choices=choices)
r('column_color_template_'+str(i), db.prefs)
+ all_colors = [unicode(s) for s in list(QColor.colorNames())]
+ self.colors_box.setText(', '.join(all_colors))
def initialize(self):
ConfigWidgetBase.initialize(self)
diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui
index d7fca70c08..aa5afe26dd 100644
--- a/src/calibre/gui2/preferences/look_feel.ui
+++ b/src/calibre/gui2/preferences/look_feel.ui
@@ -416,72 +416,80 @@ then the tags will be displayed each on their own line.
Column Coloring
- -
+
-
Column name
- -
+
-
+
+
+
+ -
Selection template
- -
+
-
- -
-
-
-
- -
-
-
-
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
+
- -
-
-
- Qt::Vertical
+
-
+
+
+
+ -
+
+
+
+ -
+
+
+ Color names
-
-
- 690
- 283
-
+
+
+ -
+
+
+
+ 0
+ 1
+
-
+
@@ -496,7 +504,7 @@ then the tags will be displayed each on their own line.
- LineEditWithTextBox
+ TemplateLineEditor
QLineEdit
calibre/gui2/dialogs/template_line_editor.h
diff --git a/src/calibre/gui2/preferences/plugboard.py b/src/calibre/gui2/preferences/plugboard.py
index b4b1d4e08e..cf632c04c0 100644
--- a/src/calibre/gui2/preferences/plugboard.py
+++ b/src/calibre/gui2/preferences/plugboard.py
@@ -7,12 +7,12 @@ __docformat__ = 'restructuredtext en'
import copy
-from PyQt4.Qt import Qt, QLineEdit, QComboBox, SIGNAL, QListWidgetItem
+from PyQt4.Qt import Qt, QComboBox, QListWidgetItem
from calibre.customize.ui import is_disabled
from calibre.gui2 import error_dialog, question_dialog
from calibre.gui2.device import device_name_for_plugboards
-from calibre.gui2.dialogs.template_dialog import TemplateDialog
+from calibre.gui2.dialogs.template_line_editor import TemplateLineEditor
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
from calibre.gui2.preferences.plugboard_ui import Ui_Form
from calibre.customize.ui import metadata_writers, device_plugins
@@ -24,26 +24,6 @@ from calibre.library.server.content import plugboard_content_server_value, \
from calibre.utils.formatter import validation_formatter
-class LineEditWithTextBox(QLineEdit):
-
- '''
- Extend the context menu of a QLineEdit to include more actions.
- '''
-
- def contextMenuEvent(self, event):
- menu = self.createStandardContextMenu()
- menu.addSeparator()
-
- action_open_editor = menu.addAction(_('Open Editor'))
-
- self.connect(action_open_editor, SIGNAL('triggered()'), self.open_editor)
- menu.exec_(event.globalPos())
-
- def open_editor(self):
- t = TemplateDialog(self, self.text())
- if t.exec_():
- self.setText(t.textbox.toPlainText())
-
class ConfigWidget(ConfigWidgetBase, Ui_Form):
def genesis(self, gui):
@@ -107,7 +87,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.source_widgets = []
self.dest_widgets = []
for i in range(0, len(self.dest_fields)-1):
- w = LineEditWithTextBox(self)
+ w = TemplateLineEditor(self)
self.source_widgets.append(w)
self.fields_layout.addWidget(w, 5+i, 0, 1, 1)
w = QComboBox(self)
diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst
index 0fd396fb64..9b5fe63f25 100644
--- a/src/calibre/manual/template_lang.rst
+++ b/src/calibre/manual/template_lang.rst
@@ -234,6 +234,7 @@ The following functions are available in addition to those described in single-f
* ``cmp(x, y, lt, eq, gt)`` -- compares x and y after converting both to numbers. Returns ``lt`` if x < y. Returns ``eq`` if x == y. Otherwise returns ``gt``.
* ``divide(x, y)`` -- returns x / y. Throws an exception if either x or y are not numbers.
* ``field(name)`` -- returns the metadata field named by ``name``.
+ * ``first_non_empty(value, value, ...) -- returns the first value that is not empty. If all values are empty, then the empty value is returned. You can have as many values as you want.
* ``format_date(x, date_format)`` -- format_date(val, format_string) -- format the value, which must be a date field, using the format_string, returning a string. The formatting codes are::
d : the day as number without a leading zero (1 to 31)
diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py
index aa8e4fb3a3..59a750bcc5 100644
--- a/src/calibre/utils/formatter_functions.py
+++ b/src/calibre/utils/formatter_functions.py
@@ -562,6 +562,22 @@ class BuiltinBooksize(BuiltinFormatterFunction):
pass
return ''
+class BuiltinFirstNonEmpty(BuiltinFormatterFunction):
+ name = 'first_non_empty'
+ arg_count = -1
+ doc = _('first_non_empty(value, value, ...) -- '
+ 'returns the first value that is not empty. If all values are '
+ 'empty, then the empty value is returned.'
+ 'You can have as many values as you want.')
+
+ def evaluate(self, formatter, kwargs, mi, locals, *args):
+ i = 0
+ while i < len(args):
+ if args[i]:
+ return args[i]
+ i += 1
+ return ''
+
builtin_add = BuiltinAdd()
builtin_assign = BuiltinAssign()
builtin_booksize = BuiltinBooksize()
@@ -571,8 +587,9 @@ builtin_contains = BuiltinContains()
builtin_count = BuiltinCount()
builtin_divide = BuiltinDivide()
builtin_eval = BuiltinEval()
-builtin_format_date = BuiltinFormat_date()
+builtin_first_non_empty = BuiltinFirstNonEmpty()
builtin_field = BuiltinField()
+builtin_format_date = BuiltinFormat_date()
builtin_ifempty = BuiltinIfempty()
builtin_list_item = BuiltinListitem()
builtin_lookup = BuiltinLookup()
From 4ddb1e852ba181d6cfd03dcb8bd31aae758475d1 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sun, 22 May 2011 15:22:33 +0100
Subject: [PATCH 16/51] Improvements on coloring: add an in_list formatter
function. Add more documentation in the preference screen. Add a scroll bar
to the doc in the preferences screen.
---
src/calibre/gui2/preferences/look_feel.py | 24 ++++++++++++++++-------
src/calibre/gui2/preferences/look_feel.ui | 10 +++++++++-
src/calibre/utils/formatter_functions.py | 17 ++++++++++++++++
3 files changed, 43 insertions(+), 8 deletions(-)
diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py
index 97400c45bd..c96d980505 100644
--- a/src/calibre/gui2/preferences/look_feel.py
+++ b/src/calibre/gui2/preferences/look_feel.py
@@ -159,7 +159,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.df_up_button.clicked.connect(self.move_df_up)
self.df_down_button.clicked.connect(self.move_df_down)
- self.color_help_text.setWordWrap(True)
self.color_help_text.setText('' +
_('Here you can specify coloring rules for fields shown in the '
'library view. Choose the field you wish to color, then '
@@ -169,14 +168,25 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
'below. You can use any legal template expression. '
'For example, you can set the title to always display in '
'green using the template "green" (without the quotes). '
- 'To show the title in blue if the book has the tag "Science '
- 'Fiction", red if the book has the tag "Mystery", or black if '
- 'the book has neither tag, use '
- '"{tags:switch(Science Fiction,blue,Mystery,red,)}" '
+ 'To show the title in the color named in the custom column '
+ '#column, use "{#column}". To show the title in blue if the '
+ 'custom column #column contains the value "foo", in red if the '
+ 'column contains the value "bar", otherwise in black, use '
+ '
{#column:switch(foo,blue,bar,red,black)}
'
+ 'To show the title in blue if the book has the exact tag '
+ '"Science Fiction", red if the book has the exact tag '
+ '"Mystery", or black if the book has neither tag, use'
+ "program: \n"
+ " t = field('tags'); \n"
+ " first_non_empty(\n"
+ " in_list(t, ',', '^Science Fiction$', 'blue', ''), \n"
+ " in_list(t, ',', '^Mystery$', 'red', 'black'))
"
'To show the title in green if it has one format, blue if it '
- 'two formats, and red if more, use '
- "\"program:cmp(count(field('formats'),','), 2, 'green', 'blue', 'red')\"") +
+ 'two formats, and red if more, use'
+ "program:cmp(count(field('formats'),','), 2, 'green', 'blue', 'red')
") +
'
' +
+ _('You can access a multi-line template editor from the '
+ 'context menu (right-click).') + '
' +
_('Note: if you want to color a "custom column with a fixed set '
'of values", it is possible and often easier to specify the '
'colors in the column definition dialog. There you can '
diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui
index aa5afe26dd..1194109c6c 100644
--- a/src/calibre/gui2/preferences/look_feel.ui
+++ b/src/calibre/gui2/preferences/look_feel.ui
@@ -424,7 +424,12 @@ then the tags will be displayed each on their own line.
-
-
+
+
+ true
+
+
+
-
@@ -483,6 +488,9 @@ then the tags will be displayed each on their own line.
-
+
+ true
+
0
diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py
index 59a750bcc5..c53277f3ce 100644
--- a/src/calibre/utils/formatter_functions.py
+++ b/src/calibre/utils/formatter_functions.py
@@ -327,6 +327,22 @@ class BuiltinSwitch(BuiltinFormatterFunction):
return args[i+1]
i += 2
+class BuiltinInList(BuiltinFormatterFunction):
+ name = 'in_list'
+ arg_count = 5
+ doc = _('in_list(val, separator, pattern, found_val, not_found_val) -- '
+ 'treat val as a list of items separated by separator, '
+ 'comparing the pattern against each value in the list. If the '
+ 'pattern matches a value, return found_val, otherwise return '
+ 'not_found_val.')
+
+ def evaluate(self, formatter, kwargs, mi, locals, val, sep, pat, fv, nfv):
+ l = [v.strip() for v in val.split(sep) if v.strip()]
+ for v in l:
+ if re.search(pat, v):
+ return fv
+ return nfv
+
class BuiltinRe(BuiltinFormatterFunction):
name = 're'
arg_count = 3
@@ -591,6 +607,7 @@ builtin_first_non_empty = BuiltinFirstNonEmpty()
builtin_field = BuiltinField()
builtin_format_date = BuiltinFormat_date()
builtin_ifempty = BuiltinIfempty()
+builtin_in_list = BuiltinInList()
builtin_list_item = BuiltinListitem()
builtin_lookup = BuiltinLookup()
builtin_lowercase = BuiltinLowercase()
From ca5dc817c22e70ada00dd0c9feb7ad8ea0ea0238 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sun, 22 May 2011 15:26:32 +0100
Subject: [PATCH 17/51] Add the new in_list function to the documentation
---
src/calibre/manual/template_lang.rst | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst
index 9b5fe63f25..69c77e5bfd 100644
--- a/src/calibre/manual/template_lang.rst
+++ b/src/calibre/manual/template_lang.rst
@@ -123,7 +123,8 @@ The functions available are:
* ``contains(pattern, text if match, text if not match`` -- checks if field contains matches for the regular expression `pattern`. Returns `text if match` if matches are found, otherwise it returns `text if no match`.
* ``count(separator)`` -- interprets the value as a list of items separated by `separator`, returning the number of items in the list. Most lists use a comma as the separator, but authors uses an ampersand. Examples: `{tags:count(,)}`, `{authors:count(&)}`
* ``ifempty(text)`` -- if the field is not empty, return the value of the field. Otherwise return `text`.
- * ``list_item(index, separator)`` -- interpret the value as a list of items separated by `separator`, returning the `index`th item. The first item is number zero. The last item can be returned using `list_item(-1,separator)`. If the item is not in the list, then the empty value is returned. The separator has the same meaning as in the `count` function.
+ * ``in_list(separator, pattern, found_val, not_found_val)`` -- interpret the field as a list of items separated by `separator`, comparing the `pattern` against each value in the list. If the pattern matches a value, return `found_val`, otherwise return `not_found_val`.
+ * ``list_item(index, separator)`` -- interpret the field as a list of items separated by `separator`, returning the `index`th item. The first item is number zero. The last item can be returned using `list_item(-1,separator)`. If the item is not in the list, then the empty value is returned. The separator has the same meaning as in the `count` function.
* ``re(pattern, replacement)`` -- return the field after applying the regular expression. All instances of `pattern` are replaced with `replacement`. As in all of |app|, these are python-compatible regular expressions.
* ``shorten(left chars, middle text, right chars)`` -- Return a shortened version of the field, consisting of `left chars` characters from the beginning of the field, followed by `middle text`, followed by `right chars` characters from the end of the string. `Left chars` and `right chars` must be integers. For example, assume the title of the book is `Ancient English Laws in the Times of Ivanhoe`, and you want it to fit in a space of at most 15 characters. If you use ``{title:shorten(9,-,5)}``, the result will be `Ancient E-nhoe`. If the field's length is less than ``left chars`` + ``right chars`` + the length of ``middle text``, then the field will be used intact. For example, the title `The Dome` would not be changed.
* ``switch(pattern, value, pattern, value, ..., else_value)`` -- for each ``pattern, value`` pair, checks if the field matches the regular expression ``pattern`` and if so, returns that ``value``. If no ``pattern`` matches, then ``else_value`` is returned. You can have as many ``pattern, value`` pairs as you want.
From f97bcfb1a8799d685722c56f76b6b659836c8810 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sun, 22 May 2011 10:46:50 -0600
Subject: [PATCH 18/51] Try harder to recover on systems where people run temp
file cleaners that delete the temp files of running programs
---
src/calibre/ptempfile.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/calibre/ptempfile.py b/src/calibre/ptempfile.py
index bff13dd248..01e8f18339 100644
--- a/src/calibre/ptempfile.py
+++ b/src/calibre/ptempfile.py
@@ -29,6 +29,10 @@ def remove_dir(x):
def base_dir():
global _base_dir
+ if _base_dir is not None and not os.path.exists(_base_dir):
+ # Some people seem to think that running temp file cleaners that
+ # delete the temp dirs of running programs is a good idea!
+ _base_dir = None
if _base_dir is None:
td = os.environ.get('CALIBRE_WORKER_TEMP_DIR', None)
if td is not None:
From 8336bd6e4986effa3a184a410d885f95989c4d29 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sun, 22 May 2011 10:48:45 -0600
Subject: [PATCH 19/51] Update Washington Post. Fixes #786609 (Updated recipe
for The Washington Post)
---
recipes/icons/wash_post.png | Bin 0 -> 1158 bytes
recipes/wash_post.recipe | 119 ++++++++++++++++++++----------------
2 files changed, 65 insertions(+), 54 deletions(-)
create mode 100644 recipes/icons/wash_post.png
diff --git a/recipes/icons/wash_post.png b/recipes/icons/wash_post.png
new file mode 100644
index 0000000000000000000000000000000000000000..e392e4c3ff7b37e4106fb51359242e524fd80413
GIT binary patch
literal 1158
zcmV;11bO?3P)000C{Nklx)Fm$tUHn1T`pB@Ttt(^HNa$8s*_kt_87BKouTIfwzs!0FE4{^j5W{W#bFs^Z;zT_ZyXZCJZLmrU0w0j
zSh7mSkA^Uoi({0u6+Aj+Y7Z9EpgicPifQm2DiQfXt5x!c7O{l@*avq)a4=tkhW8JH
zpoW-3O@SRt2}`BjOf?D~9v*N(j0Nv1d`)P^(jOko)QVFg)7wEy@C0MqXvhn|3xmDC
zzsH7D`0`;ooxZ%h#59=XGOd)VWU{Xj(=v&;*CH-qsZQJk_qqD~MdGzf=>
zhw?N2MbPH!>x;j*k^zsz+~x%wA0L~~Xb6_52r%9mQi2zl0S+j$vor?mWB*U^|+4{1moQ9d{{v}EeboxQU>u->~!YsiL0n};OsC12){Sjcl{yI?m
zL>-Yt-e5?3xlBXA0e;f#ZJ3t_rwUX?cmGF*Q@^`rL!6kBL{*GJMh))Tjd-uhK%3ZU
z%Q_$|)oXD>Nbwq*WA>t6>e-RVh=n!mxf^7!=}a&y0aIhbGO!0=Ih{`ZgzxlxV!^$U
z>>#y#{ZQE0Qxo3Ava?C(ibL0ziUC&=Z9{Vgu+->G)I~&rlYjV1<>p+BosxKL2
zZ-!BAY|Ijz)U3yhIMf6s&Q^IgZ74fzY~+6{;Wx>GU|EroHdC|K7Fm*sdCFf6gQDJO
zNdb(2teH-Ty5%$k5{'
+'''
+www.washingtonpost.com
+'''
+
+from calibre import strftime
from calibre.web.feeds.news import BasicNewsRecipe
+class TheWashingtonPost(BasicNewsRecipe):
+ title = 'The Washington Post'
+ __author__ = 'Darko Miletic'
+ description = 'Leading source for news, video and opinion on politics, business, world and national news, science, travel, entertainment and more. Our local coverage includes reporting on education, crime, weather, traffic, real estate, jobs and cars for DC, Maryland and Virginia. Offering award-winning opinion writing, entertainment information and restaurant reviews.'
+ publisher = 'The Washington Post Company'
+ category = 'news, politics, USA'
+ oldest_article = 2
+ max_articles_per_feed = 200
+ no_stylesheets = True
+ encoding = 'utf8'
+ delay = 1
+ use_embedded_content = False
+ language = 'en'
+ remove_empty_feeds = True
+ publication_type = 'newspaper'
+ masthead_url = 'http://www.washingtonpost.com/rw/sites/twpweb/img/logos/twp_logo_300.gif'
+ cover_url = strftime('http://www.washingtonpost.com/rw/WashingtonPost/Content/Epaper/%Y-%m-%d/Ax1.pdf')
+ extra_css = """
+ body{font-family: Georgia,serif }
+ """
-class WashingtonPost(BasicNewsRecipe):
+ conversion_options = {
+ 'comment' : description
+ , 'tags' : category
+ , 'publisher' : publisher
+ , 'language' : language
+ }
- title = 'Washington Post'
- description = 'US political news'
- __author__ = 'Kovid Goyal'
- use_embedded_content = False
- max_articles_per_feed = 20
- language = 'en'
- encoding = 'utf-8'
+ keep_only_tags = [dict(attrs={'id':['content','entryhead','entrytext']})]
+ remove_tags = [
+ dict(name=['meta','link','iframe','base'])
+ ,dict(attrs={'id':'multimedia-leaf-page'})
+ ]
+ remove_attributes= ['lang','property','epochtime','datetitle','pagetype','contenttype','comparetime']
- remove_javascript = True
- no_stylesheets = True
-
feeds = [
- ('Politics', 'http://www.washingtonpost.com/rss/politics'),
- ('Nation', 'http://www.washingtonpost.com/rss/national'),
- ('World', 'http://www.washingtonpost.com/rss/world'),
- ('Business', 'http://www.washingtonpost.com/rss/business'),
- ('Lifestyle', 'http://www.washingtonpost.com/rss/lifestyle'),
- ('Sports', 'http://www.washingtonpost.com/rss/sports'),
- ('Redskins', 'http://www.washingtonpost.com/rss/sports/redskins'),
- ('Opinions', 'http://www.washingtonpost.com/rss/opinions'),
- ('Entertainment', 'http://www.washingtonpost.com/rss/entertainment'),
- ('Local', 'http://www.washingtonpost.com/rss/local'),
- ('Investigations',
- 'http://www.washingtonpost.com/rss/investigations'),
- ]
-
- remove_tags = [
- {'class':lambda x: x and 'article-toolbar' in x},
- {'class':lambda x: x and 'quick-comments' in x},
- {'class':lambda x: x and 'tweet' in x},
- {'class':lambda x: x and 'article-related' in x},
- {'class':lambda x: x and 'hidden' in x.split()},
- {'class':lambda x: x and 'also-read' in x.split()},
- {'class':lambda x: x and 'partners-content' in x.split()},
- {'class':['module share', 'module ads', 'comment-vars', 'hidden',
- 'share-icons-wrap', 'comments', 'flipper']},
- {'id':['right-rail', 'save-and-share']},
- {'width':'1', 'height':'1'},
-
- ]
-
- keep_only_tags = dict(id=['content', 'article'])
-
- def get_article_url(self, *args):
- ans = BasicNewsRecipe.get_article_url(self, *args)
- ans = ans.rpartition('?')[0]
- if ans.endswith('_video.html'):
- return None
- if 'ads.pheedo.com' in ans:
- return None
- #if not ans.endswith('_blog.html'):
- # return None
- return ans
-
+ (u'World' , u'http://feeds.washingtonpost.com/rss/world' )
+ ,(u'National' , u'http://feeds.washingtonpost.com/rss/national' )
+ ,(u'White House' , u'http://feeds.washingtonpost.com/rss/politics/whitehouse' )
+ ,(u'Business' , u'http://feeds.washingtonpost.com/rss/business' )
+ ,(u'Opinions' , u'http://feeds.washingtonpost.com/rss/opinions' )
+ ,(u'Investigations' , u'http://feeds.washingtonpost.com/rss/investigations' )
+ ,(u'Local' , u'http://feeds.washingtonpost.com/rss/local' )
+ ,(u'Entertainment' , u'http://feeds.washingtonpost.com/rss/entertainment' )
+ ,(u'Sports' , u'http://feeds.washingtonpost.com/rss/sports' )
+ ,(u'Redskins' , u'http://feeds.washingtonpost.com/rss/sports/redskins' )
+ ,(u'Special Reports', u'http://feeds.washingtonpost.com/rss/national/special-reports')
+ ]
def print_version(self, url):
- return url.replace('_story.html', '_singlePage.html')
+ if '_story.html' in url:
+ return url.replace('_story.html','_print.html')
+ return url
+
+ def get_article_url(self, article):
+ link = BasicNewsRecipe.get_article_url(self,article)
+ if not 'washingtonpost.com' in link:
+ self.log('Skipping adds:', link)
+ return None
+ for it in ['_video.html','_gallery.html','_links.html']:
+ if it in link:
+ self.log('Skipping non-article:', link)
+ return None
+ return link
From 1a4768a539bfdf65b2f5a6d68a133730683f9261 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sun, 22 May 2011 18:32:03 +0100
Subject: [PATCH 20/51] Make coloring work across change_libraries
---
src/calibre/gui2/init.py | 1 -
src/calibre/gui2/library/models.py | 2 ++
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py
index 079e1814c3..a75ff01b21 100644
--- a/src/calibre/gui2/init.py
+++ b/src/calibre/gui2/init.py
@@ -65,7 +65,6 @@ class LibraryViewMixin(object): # {{{
self.build_context_menus()
self.library_view.model().set_highlight_only(config['highlight_search_matches'])
- self.library_view.model().set_color_templates()
def build_context_menus(self):
lm = QMenu(self)
diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py
index 83bf5868ba..a3e7438908 100644
--- a/src/calibre/gui2/library/models.py
+++ b/src/calibre/gui2/library/models.py
@@ -157,6 +157,7 @@ class BooksModel(QAbstractTableModel): # {{{
self.database_changed.emit(db)
self.stop_metadata_backup()
self.start_metadata_backup()
+ self.set_color_templates()
def start_metadata_backup(self):
self.metadata_backup = MetadataBackup(self.db)
@@ -535,6 +536,7 @@ class BooksModel(QAbstractTableModel): # {{{
return img
def set_color_templates(self):
+ print 'here'
self.column_color_map = {}
for i in range(1,self.db.column_color_count+1):
name = self.db.prefs.get('column_color_name_'+str(i))
From 6087a6a6603868fa752b15a30b074ebd7e7e7243 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sun, 22 May 2011 18:34:34 +0100
Subject: [PATCH 21/51] Remove print statement
---
src/calibre/gui2/library/models.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py
index a3e7438908..b378256a42 100644
--- a/src/calibre/gui2/library/models.py
+++ b/src/calibre/gui2/library/models.py
@@ -536,7 +536,6 @@ class BooksModel(QAbstractTableModel): # {{{
return img
def set_color_templates(self):
- print 'here'
self.column_color_map = {}
for i in range(1,self.db.column_color_count+1):
name = self.db.prefs.get('column_color_name_'+str(i))
From b0db4939688f0b7d737feee16a50087ee2f775e7 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sun, 22 May 2011 12:29:31 -0600
Subject: [PATCH 22/51] ...
---
src/calibre/gui2/actions/copy_to_library.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/calibre/gui2/actions/copy_to_library.py b/src/calibre/gui2/actions/copy_to_library.py
index 2e4d0380be..7190d1486f 100644
--- a/src/calibre/gui2/actions/copy_to_library.py
+++ b/src/calibre/gui2/actions/copy_to_library.py
@@ -16,7 +16,7 @@ from calibre.gui2 import error_dialog, Dispatcher, warning_dialog
from calibre.gui2.dialogs.progress import ProgressDialog
from calibre.utils.config import prefs, tweaks
-class Worker(Thread):
+class Worker(Thread): # {{{
def __init__(self, ids, db, loc, progress, done, delete_after):
Thread.__init__(self)
@@ -75,7 +75,7 @@ class Worker(Thread):
if co is not None:
newdb.set_conversion_options(x, 'PIPE', co)
self.processed.add(x)
-
+# }}}
class CopyToLibraryAction(InterfaceAction):
From 3487ed762ea084d6d44d9e3a9446f6e87e87e1a8 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sun, 22 May 2011 19:34:03 +0100
Subject: [PATCH 23/51] Switch refresh to reset when loading column color
templates
---
src/calibre/gui2/library/models.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py
index b378256a42..2576518d92 100644
--- a/src/calibre/gui2/library/models.py
+++ b/src/calibre/gui2/library/models.py
@@ -153,11 +153,11 @@ class BooksModel(QAbstractTableModel): # {{{
self.headers[col] = self.custom_columns[col]['name']
self.build_data_convertors()
+ self.set_color_templates(reset=False)
self.reset()
self.database_changed.emit(db)
self.stop_metadata_backup()
self.start_metadata_backup()
- self.set_color_templates()
def start_metadata_backup(self):
self.metadata_backup = MetadataBackup(self.db)
@@ -535,14 +535,15 @@ class BooksModel(QAbstractTableModel): # {{{
img = self.default_image
return img
- def set_color_templates(self):
+ def set_color_templates(self, reset=True):
self.column_color_map = {}
for i in range(1,self.db.column_color_count+1):
name = self.db.prefs.get('column_color_name_'+str(i))
if name:
self.column_color_map[name] = \
self.db.prefs.get('column_color_template_'+str(i))
- self.refresh()
+ if reset:
+ self.reset()
def build_data_convertors(self):
def authors(r, idx=-1):
From 8a4ceb206d57b8e133cefec77736930c1d94e418 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sun, 22 May 2011 12:43:25 -0600
Subject: [PATCH 24/51] Fix ratings deleegate to use model supplied color
---
src/calibre/gui2/library/delegates.py | 20 +++++++++++++-------
src/calibre/gui2/library/models.py | 4 ++--
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py
index e2234f6df5..b3012a7211 100644
--- a/src/calibre/gui2/library/delegates.py
+++ b/src/calibre/gui2/library/delegates.py
@@ -40,10 +40,7 @@ class RatingDelegate(QStyledItemDelegate): # {{{
50 + 40 * sin(0.8 * i * pi))
self.star_path.closeSubpath()
self.star_path.setFillRule(Qt.WindingFill)
- gradient = QLinearGradient(0, 0, 0, 100)
- gradient.setColorAt(0.0, self.COLOR)
- gradient.setColorAt(1.0, self.COLOR)
- self.brush = QBrush(gradient)
+ self.gradient = QLinearGradient(0, 0, 0, 100)
self.factor = self.SIZE/100.
def sizeHint(self, option, index):
@@ -53,7 +50,8 @@ class RatingDelegate(QStyledItemDelegate): # {{{
def paint(self, painter, option, index):
style = self._parent.style()
option = QStyleOptionViewItemV4(option)
- self.initStyleOption(option, self.dummy)
+ self.initStyleOption(option, index)
+ option.text = u''
num = index.model().data(index, Qt.DisplayRole).toInt()[0]
def draw_star():
painter.save()
@@ -65,6 +63,7 @@ class RatingDelegate(QStyledItemDelegate): # {{{
painter.restore()
painter.save()
+
if hasattr(QStyle, 'CE_ItemViewItem'):
style.drawControl(QStyle.CE_ItemViewItem, option,
painter, self._parent)
@@ -75,8 +74,15 @@ class RatingDelegate(QStyledItemDelegate): # {{{
painter.setClipRect(option.rect)
y = option.rect.center().y()-self.SIZE/2.
x = option.rect.left()
- painter.setPen(self.PEN)
- painter.setBrush(self.brush)
+ color = index.data(Qt.ForegroundRole)
+ if color.isNull() or not color.isValid():
+ color = self.COLOR
+ else:
+ color = QColor(color)
+ painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
+ self.gradient.setColorAt(0.0, color)
+ self.gradient.setColorAt(1.0, color)
+ painter.setBrush(QBrush(self.gradient))
painter.translate(x, y)
i = 0
while i < num:
diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py
index fc1117167d..0baf98ecdd 100644
--- a/src/calibre/gui2/library/models.py
+++ b/src/calibre/gui2/library/models.py
@@ -693,9 +693,9 @@ class BooksModel(QAbstractTableModel): # {{{
return NONE
if role in (Qt.DisplayRole, Qt.EditRole):
return self.column_to_dc_map[col](index.row())
- elif role == Qt.BackgroundColorRole:
+ elif role == Qt.BackgroundRole:
if self.id(index) in self.ids_to_highlight_set:
- return QColor('lightgreen')
+ return QVariant(QColor('lightgreen'))
elif role == Qt.DecorationRole:
if self.column_to_dc_decorator_map[col] is not None:
return self.column_to_dc_decorator_map[index.column()](index.row())
From c90382e059de39be3da1778862f42cec995e60ca Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sun, 22 May 2011 12:46:06 -0600
Subject: [PATCH 25/51] ...
---
src/calibre/gui2/library/delegates.py | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py
index b3012a7211..7265be89c8 100644
--- a/src/calibre/gui2/library/delegates.py
+++ b/src/calibre/gui2/library/delegates.py
@@ -7,11 +7,11 @@ __docformat__ = 'restructuredtext en'
from math import cos, sin, pi
-from PyQt4.Qt import QColor, Qt, QModelIndex, QSize, \
- QPainterPath, QLinearGradient, QBrush, \
- QPen, QStyle, QPainter, QStyleOptionViewItemV4, \
- QIcon, QDoubleSpinBox, QVariant, QSpinBox, \
- QStyledItemDelegate, QComboBox, QTextDocument
+from PyQt4.Qt import (QColor, Qt, QModelIndex, QSize,
+ QPainterPath, QLinearGradient, QBrush,
+ QPen, QStyle, QPainter, QStyleOptionViewItemV4,
+ QIcon, QDoubleSpinBox, QVariant, QSpinBox,
+ QStyledItemDelegate, QComboBox, QTextDocument)
from calibre.gui2 import UNDEFINED_QDATE, error_dialog
from calibre.gui2.widgets import EnLineEdit
@@ -27,7 +27,6 @@ from calibre.gui2.dialogs.template_dialog import TemplateDialog
class RatingDelegate(QStyledItemDelegate): # {{{
COLOR = QColor("blue")
SIZE = 16
- PEN = QPen(COLOR, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
def __init__(self, parent):
QStyledItemDelegate.__init__(self, parent)
From 0bd580f572cd5b5a10c9167adc6f8f5c717d0dc3 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sun, 22 May 2011 19:53:26 +0100
Subject: [PATCH 26/51] Remove unused PEN declaration
---
src/calibre/gui2/library/delegates.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py
index 6d962c9129..4f002c2c48 100644
--- a/src/calibre/gui2/library/delegates.py
+++ b/src/calibre/gui2/library/delegates.py
@@ -28,7 +28,6 @@ from calibre.gui2.dialogs.template_dialog import TemplateDialog
class RatingDelegate(QStyledItemDelegate): # {{{
COLOR = QColor("blue")
SIZE = 16
- PEN = QPen(COLOR, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
def __init__(self, parent):
QStyledItemDelegate.__init__(self, parent)
From 29b453ba23177adc9cd740cada0f6b7ba08e23f4 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sun, 22 May 2011 19:55:46 +0100
Subject: [PATCH 27/51] Check for color valid when using column coloring
---
src/calibre/gui2/library/models.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py
index 2576518d92..6e8e79d3b3 100644
--- a/src/calibre/gui2/library/models.py
+++ b/src/calibre/gui2/library/models.py
@@ -726,7 +726,9 @@ class BooksModel(QAbstractTableModel): # {{{
txt = unicode(index.data(Qt.DisplayRole).toString())
if len(colors) > 0 and txt in values:
try:
- return QColor(colors[values.index(txt)])
+ color = colors[values.index(txt)]
+ if QColor.isValid(color):
+ return QColor(color)
except:
pass
return None
From de969af505aeaf32507c19229081371a850549b9 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sun, 22 May 2011 20:12:47 +0100
Subject: [PATCH 28/51] Improve robustness in column coloring.
---
src/calibre/gui2/library/models.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py
index 6e8e79d3b3..9d90c44f18 100644
--- a/src/calibre/gui2/library/models.py
+++ b/src/calibre/gui2/library/models.py
@@ -715,7 +715,8 @@ class BooksModel(QAbstractTableModel): # {{{
fmt = self.column_color_map[key]
try:
color = composite_formatter.safe_format(fmt, mi, '', mi)
- return QColor(color)
+ if QColor.isValid(color):
+ return QColor(color)
except:
return None
elif self.is_custom_column(key) and \
From 478369c7cba88cf04d8778d8d4b2ea14c40872ed Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sun, 22 May 2011 20:47:47 +0100
Subject: [PATCH 29/51] Add colors icon to preferences dialog. Correctly clean
template values when the column is set to empty.
---
src/calibre/gui2/preferences/look_feel.py | 8 +++++++-
src/calibre/gui2/preferences/look_feel.ui | 2 +-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py
index c96d980505..ffbc82eefd 100644
--- a/src/calibre/gui2/preferences/look_feel.py
+++ b/src/calibre/gui2/preferences/look_feel.py
@@ -194,7 +194,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
choices = db.field_metadata.displayable_field_keys()
choices.sort(key=sort_key)
choices.insert(0, '')
- for i in range(1, db.column_color_count+1):
+ self.column_color_count = db.column_color_count+1
+ for i in range(1, self.column_color_count):
r('column_color_name_'+str(i), db.prefs, choices=choices)
r('column_color_template_'+str(i), db.prefs)
all_colors = [unicode(s) for s in list(QColor.colorNames())]
@@ -267,6 +268,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.changed_signal.emit()
def commit(self, *args):
+ for i in range(1, self.column_color_count):
+ col = getattr(self, 'opt_column_color_name_'+str(i))
+ if not col.currentText():
+ temp = getattr(self, 'opt_column_color_template_'+str(i))
+ temp.setText('')
rr = ConfigWidgetBase.commit(self, *args)
if self.current_font != self.initial_font:
gprefs['font'] = (self.current_font[:4] if self.current_font else
diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui
index 1194109c6c..9dedcf4f8c 100644
--- a/src/calibre/gui2/preferences/look_feel.ui
+++ b/src/calibre/gui2/preferences/look_feel.ui
@@ -410,7 +410,7 @@ then the tags will be displayed each on their own line.
- :/images/cover_flow.png:/images/cover_flow.png
+ :/images/format-fill-color.png:/images/format-fill-color.png
Column Coloring
From ed7a6180aeca7aef8a93bc5738855f8d048cff4b Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Sun, 22 May 2011 22:30:35 +0100
Subject: [PATCH 30/51] Change pathname generation to use the correct value for
{id}
---
src/calibre/devices/usbms/device.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py
index c46e9539c9..45b72abe74 100644
--- a/src/calibre/devices/usbms/device.py
+++ b/src/calibre/devices/usbms/device.py
@@ -926,8 +926,8 @@ class Device(DeviceConfig, DevicePlugin):
if not isinstance(template, unicode):
template = template.decode('utf-8')
app_id = str(getattr(mdata, 'application_id', ''))
- # The db id will be in the created filename
- extra_components = get_components(template, mdata, fname,
+ id_ = mdata.get('id', fname)
+ extra_components = get_components(template, mdata, id_,
timefmt=opts.send_timefmt, length=maxlen-len(app_id)-1)
if not extra_components:
extra_components.append(sanitize(self.filename_callback(fname,
From a74ee044bb1dec7b164060fffacb496641aec634 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Sun, 22 May 2011 20:11:06 -0600
Subject: [PATCH 31/51] ...
---
src/calibre/gui2/preferences/look_feel.ui | 51 ++++++++++++++---------
1 file changed, 32 insertions(+), 19 deletions(-)
diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui
index 970052ad2e..ad990a1586 100644
--- a/src/calibre/gui2/preferences/look_feel.ui
+++ b/src/calibre/gui2/preferences/look_feel.ui
@@ -467,25 +467,6 @@ then the tags will be displayed each on their own line.
- -
-
-
-
- 0
- 1
-
-
-
-
- 16777215
- 100
-
-
-
- true
-
-
-
-
@@ -524,6 +505,38 @@ then the tags will be displayed each on their own line.
+ -
+
+
+
+ 16777215
+ 120
+
+
+
+ true
+
+
+
+
+ 0
+ 0
+ 687
+ 61
+
+
+
+
-
+
+
+ true
+
+
+
+
+
+
+
From 6ff2d3c346b57681ce3e2620f6f86999c77bbf1a Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Mon, 23 May 2011 13:58:56 +0100
Subject: [PATCH 32/51] Add syntax highlighting and parenthesis matching to the
template editor
---
src/calibre/gui2/dialogs/template_dialog.py | 203 +++++++++++++++++++-
1 file changed, 202 insertions(+), 1 deletion(-)
diff --git a/src/calibre/gui2/dialogs/template_dialog.py b/src/calibre/gui2/dialogs/template_dialog.py
index 174056ef80..da2b730444 100644
--- a/src/calibre/gui2/dialogs/template_dialog.py
+++ b/src/calibre/gui2/dialogs/template_dialog.py
@@ -5,10 +5,190 @@ __license__ = 'GPL v3'
import json
-from PyQt4.Qt import Qt, QDialog, QDialogButtonBox
+from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QSyntaxHighlighter,
+ QRegExp, QSettings, QVariant, QApplication,
+ QTextCharFormat, QFont, QColor, QCursor)
+
from calibre.gui2.dialogs.template_dialog_ui import Ui_TemplateDialog
from calibre.utils.formatter_functions import formatter_functions
+class ParenPosition:
+
+ def __init__(self, block, pos, paren):
+ self.block = block
+ self.pos = pos
+ self.paren = paren
+ self.highlight = False
+
+ def set_highlight(self, to_what):
+ self.highlight = to_what
+
+class TemplateHighlighter(QSyntaxHighlighter):
+
+ Config = {}
+ Rules = []
+ Formats = {}
+
+ KEYWORDS = ["program"]
+
+ def __init__(self, parent=None):
+ super(TemplateHighlighter, self).__init__(parent)
+
+ self.initializeFormats()
+
+ TemplateHighlighter.Rules.append((QRegExp(
+ "|".join([r"\b%s\b" % keyword for keyword in self.KEYWORDS])),
+ "keyword"))
+ TemplateHighlighter.Rules.append((QRegExp(
+ "|".join([r"\b%s\b" % builtin for builtin in
+ formatter_functions.get_builtins()])),
+ "builtin"))
+
+ TemplateHighlighter.Rules.append((QRegExp(
+ r"\b[+-]?[0-9]+[lL]?\b"
+ r"|\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b"
+ r"|\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b"),
+ "number"))
+
+ stringRe = QRegExp(r"""(?:[^:]'[^']*'|"[^"]*")""")
+ stringRe.setMinimal(True)
+ TemplateHighlighter.Rules.append((stringRe, "string"))
+
+ lparenRe = QRegExp(r'\(')
+ lparenRe.setMinimal(True)
+ TemplateHighlighter.Rules.append((lparenRe, "lparen"))
+ rparenRe = QRegExp(r'\)')
+ rparenRe.setMinimal(True)
+ TemplateHighlighter.Rules.append((rparenRe, "rparen"))
+
+ self.regenerate_paren_positions()
+ self.highlighted_paren = False
+
+ def initializeFormats(self):
+ Config = self.Config
+ Config["fontfamily"] = "Bitstream Vera Sans Mono"
+ Config["fontsize"] = 10
+ for name, color, bold, italic in (
+ ("normal", "#000000", False, False),
+ ("keyword", "#000080", True, False),
+ ("builtin", "#0000A0", False, False),
+ ("comment", "#007F00", False, True),
+ ("string", "#808000", False, False),
+ ("number", "#924900", False, False),
+ ("lparen", "#000000", True, True),
+ ("rparen", "#000000", True, True)):
+ Config["%sfontcolor" % name] = color
+ Config["%sfontbold" % name] = bold
+ Config["%sfontitalic" % name] = italic
+
+ baseFormat = QTextCharFormat()
+ baseFormat.setFontFamily(Config["fontfamily"])
+ baseFormat.setFontPointSize(Config["fontsize"])
+
+ for name in ("normal", "keyword", "builtin", "comment",
+ "string", "number", "lparen", "rparen"):
+ format = QTextCharFormat(baseFormat)
+ format.setForeground(QColor(Config["%sfontcolor" % name]))
+ if Config["%sfontbold" % name]:
+ format.setFontWeight(QFont.Bold)
+ format.setFontItalic(Config["%sfontitalic" % name])
+ self.Formats[name] = format
+
+ def find_paren(self, bn, pos):
+ for pp in self.paren_positions:
+ if pp.block == bn and pp.pos == pos:
+ return pp
+ return None
+
+ def highlightBlock(self, text):
+ bn = self.currentBlock().blockNumber()
+ textLength = text.length()
+
+ self.setFormat(0, textLength, self.Formats["normal"])
+
+ if text.isEmpty():
+ pass
+ elif text[0] == "#":
+ self.setFormat(0, text.length(), self.Formats["comment"])
+ return
+
+ for regex, format in TemplateHighlighter.Rules:
+ i = regex.indexIn(text)
+ while i >= 0:
+ length = regex.matchedLength()
+ if format in ['lparen', 'rparen']:
+ pp = self.find_paren(bn, i)
+ if pp and pp.highlight:
+ self.setFormat(i, length, self.Formats[format])
+ else:
+ self.setFormat(i, length, self.Formats[format])
+ i = regex.indexIn(text, i + length)
+
+ if self.generate_paren_positions:
+ t = unicode(text)
+ i = 0
+ first = True
+ while i < len(t):
+ c = t[i]
+ if c == ':':
+ if first and i+1 < len(t) and t[i+1] == "'":
+ i += 2
+ elif c in ["'", '"']:
+ first = False
+ i += 1
+ j = t[i:].find(c)
+ if j < 0:
+ i = len(t)
+ else:
+ i = i + j
+ elif c == '(':
+ self.paren_positions.append(ParenPosition(bn, i, '('))
+ elif c == ')':
+ self.paren_positions.append(ParenPosition(bn, i, ')'))
+ i += 1
+
+ def rehighlight(self):
+ QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
+ QSyntaxHighlighter.rehighlight(self)
+ QApplication.restoreOverrideCursor()
+
+ def check_cursor_pos(self, chr, block, pos_in_block):
+ found_pp = -1
+ for i, pp in enumerate(self.paren_positions):
+ pp.set_highlight(False)
+ if pp.block == block and pp.pos == pos_in_block:
+ found_pp = i
+
+ if chr not in ['(', ')']:
+ if self.highlighted_paren:
+ self.rehighlight()
+ self.highlighted_paren = False
+ return
+
+ if found_pp >= 0:
+ stack = 0
+ if chr == '(':
+ list = self.paren_positions[found_pp+1:]
+ else:
+ list = reversed(self.paren_positions[0:found_pp])
+ for pp in list:
+ if pp.paren == chr:
+ stack += 1;
+ elif stack:
+ stack -= 1
+ else:
+ pp.set_highlight(True)
+ self.paren_positions[found_pp].set_highlight(True)
+ break
+ self.highlighted_paren = True
+ self.rehighlight()
+
+ def regenerate_paren_positions(self):
+ self.generate_paren_positions = True
+ self.paren_positions = []
+ self.rehighlight()
+ self.generate_paren_positions = False
+
class TemplateDialog(QDialog, Ui_TemplateDialog):
def __init__(self, parent, text):
@@ -20,6 +200,11 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
self.setWindowFlags(self.windowFlags()&(~Qt.WindowContextHelpButtonHint))
self.setWindowIcon(icon)
+ self.last_text = ''
+ self.highlighter = TemplateHighlighter(self.textbox.document())
+ self.textbox.cursorPositionChanged.connect(self.text_cursor_changed)
+ self.textbox.textChanged.connect(self.textbox_changed)
+
self.textbox.setTabStopWidth(10)
self.source_code.setTabStopWidth(10)
self.documentation.setReadOnly(True)
@@ -46,6 +231,22 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
self.function.setCurrentIndex(0)
self.function.currentIndexChanged[str].connect(self.function_changed)
+ def textbox_changed(self):
+ cur_text = unicode(self.textbox.toPlainText())
+ if self.last_text != cur_text:
+ self.last_text = cur_text
+ self.highlighter.regenerate_paren_positions()
+
+ def text_cursor_changed(self):
+ cursor = self.textbox.textCursor()
+ block_number = cursor.blockNumber()
+ pos_in_block = cursor.positionInBlock()
+ position = cursor.position()
+ t = unicode(self.textbox.toPlainText())
+ if position < len(t):
+ self.highlighter.check_cursor_pos(t[position], block_number,
+ pos_in_block)
+
def function_changed(self, toWhat):
name = unicode(toWhat)
self.source_code.clear()
From e624da286e8bd3f47990750815bab6b9f1fb6842 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Mon, 23 May 2011 16:12:02 +0100
Subject: [PATCH 33/51] Improvements to paren matching algorithm.
---
src/calibre/gui2/dialogs/template_dialog.py | 25 ++++++++++++---------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/src/calibre/gui2/dialogs/template_dialog.py b/src/calibre/gui2/dialogs/template_dialog.py
index da2b730444..b82e8b00bd 100644
--- a/src/calibre/gui2/dialogs/template_dialog.py
+++ b/src/calibre/gui2/dialogs/template_dialog.py
@@ -28,6 +28,7 @@ class TemplateHighlighter(QSyntaxHighlighter):
Config = {}
Rules = []
Formats = {}
+ BN_FACTOR = 1000
KEYWORDS = ["program"]
@@ -95,10 +96,8 @@ class TemplateHighlighter(QSyntaxHighlighter):
self.Formats[name] = format
def find_paren(self, bn, pos):
- for pp in self.paren_positions:
- if pp.block == bn and pp.pos == pos:
- return pp
- return None
+ dex = bn * self.BN_FACTOR + pos
+ return self.paren_pos_map.get(dex, None)
def highlightBlock(self, text):
bn = self.currentBlock().blockNumber()
@@ -127,24 +126,27 @@ class TemplateHighlighter(QSyntaxHighlighter):
if self.generate_paren_positions:
t = unicode(text)
i = 0
- first = True
+ foundQuote = False
while i < len(t):
c = t[i]
if c == ':':
- if first and i+1 < len(t) and t[i+1] == "'":
+ # Deal with the funky syntax of template program mode.
+ # This won't work if there are more than one template
+ # expression in the document.
+ if not foundQuote and i+1 < len(t) and t[i+1] == "'":
i += 2
elif c in ["'", '"']:
- first = False
+ foundQuote = True
i += 1
j = t[i:].find(c)
if j < 0:
i = len(t)
else:
i = i + j
- elif c == '(':
- self.paren_positions.append(ParenPosition(bn, i, '('))
- elif c == ')':
- self.paren_positions.append(ParenPosition(bn, i, ')'))
+ elif c in ['(', ')']:
+ pp = ParenPosition(bn, i, c)
+ self.paren_positions.append(pp)
+ self.paren_pos_map[bn*self.BN_FACTOR+i] = pp
i += 1
def rehighlight(self):
@@ -186,6 +188,7 @@ class TemplateHighlighter(QSyntaxHighlighter):
def regenerate_paren_positions(self):
self.generate_paren_positions = True
self.paren_positions = []
+ self.paren_pos_map = {}
self.rehighlight()
self.generate_paren_positions = False
From e2cc48381d4fa53c5c7e92a10f7aec88fc6fcbba Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Mon, 23 May 2011 11:08:14 -0600
Subject: [PATCH 34/51] Nicer error message when user attempts to set
title/author via Edit metadata dialog and one of the files is open in another
program.
---
src/calibre/gui2/metadata/basic_widgets.py | 34 ++++++++++++++++++----
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/src/calibre/gui2/metadata/basic_widgets.py b/src/calibre/gui2/metadata/basic_widgets.py
index d662256def..d58ac4a379 100644
--- a/src/calibre/gui2/metadata/basic_widgets.py
+++ b/src/calibre/gui2/metadata/basic_widgets.py
@@ -88,11 +88,22 @@ class TitleEdit(EnLineEdit):
def commit(self, db, id_):
title = self.current_val
- if self.COMMIT:
- getattr(db, 'set_'+ self.TITLE_ATTR)(id_, title, notify=False)
- else:
- getattr(db, 'set_'+ self.TITLE_ATTR)(id_, title, notify=False,
- commit=False)
+ try:
+ if self.COMMIT:
+ getattr(db, 'set_'+ self.TITLE_ATTR)(id_, title, notify=False)
+ else:
+ getattr(db, 'set_'+ self.TITLE_ATTR)(id_, title, notify=False,
+ commit=False)
+ except (IOError, OSError) as err:
+ if getattr(err, 'errno', -1) == 13: # Permission denied
+ import traceback
+ fname = err.filename if err.filename else 'file'
+ error_dialog(self, _('Permission denied'),
+ _('Could not open %s. Is it being used by another'
+ ' program?')%fname, det_msg=traceback.format_exc(),
+ show=True)
+ return False
+ raise
return True
@dynamic_property
@@ -225,8 +236,19 @@ class AuthorsEdit(MultiCompleteComboBox):
def commit(self, db, id_):
authors = self.current_val
- self.books_to_refresh |= db.set_authors(id_, authors, notify=False,
+ try:
+ self.books_to_refresh |= db.set_authors(id_, authors, notify=False,
allow_case_change=True)
+ except (IOError, OSError) as err:
+ if getattr(err, 'errno', -1) == 13: # Permission denied
+ import traceback
+ fname = err.filename if err.filename else 'file'
+ error_dialog(self, _('Permission denied'),
+ _('Could not open %s. Is it being used by another'
+ ' program?')%fname, det_msg=traceback.format_exc(),
+ show=True)
+ return False
+ raise
return True
@dynamic_property
From a654486d81923e2800e8ac5a5ccdb45e306136a1 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Mon, 23 May 2011 12:06:03 -0600
Subject: [PATCH 35/51] Fix #786723 (Device to add - Pocketbook 360 Plus)
---
src/calibre/devices/eb600/driver.py | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/calibre/devices/eb600/driver.py b/src/calibre/devices/eb600/driver.py
index 01277980db..dbccd72ee9 100644
--- a/src/calibre/devices/eb600/driver.py
+++ b/src/calibre/devices/eb600/driver.py
@@ -95,9 +95,8 @@ class POCKETBOOK360(EB600):
FORMATS = ['epub', 'fb2', 'prc', 'mobi', 'pdf', 'djvu', 'rtf', 'chm', 'txt']
- VENDOR_NAME = 'PHILIPS'
- WINDOWS_MAIN_MEM = 'MASS_STORGE'
- WINDOWS_CARD_A_MEM = 'MASS_STORGE'
+ VENDOR_NAME = ['PHILIPS', '__POCKET']
+ WINDOWS_MAIN_MEM = WINDOWS_CARD_A_MEM = ['MASS_STORGE', 'BOOK_USB_STORAGE']
OSX_MAIN_MEM = 'Philips Mass Storge Media'
OSX_CARD_A_MEM = 'Philips Mass Storge Media'
From 669d3770533b35452812c9dd75f21af91cca7981 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Mon, 23 May 2011 12:07:33 -0600
Subject: [PATCH 36/51] Warn about Hotmail's asinine SMTP policy
---
src/calibre/gui2/wizard/send_email.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/calibre/gui2/wizard/send_email.py b/src/calibre/gui2/wizard/send_email.py
index 44cd8dd2e4..5c7d916e1a 100644
--- a/src/calibre/gui2/wizard/send_email.py
+++ b/src/calibre/gui2/wizard/send_email.py
@@ -138,8 +138,11 @@ class SendEmail(QWidget, Ui_Form):
'username': '',
'url': 'www.hotmail.com',
'extra': _('If you are setting up a new'
- ' hotmail account, you must log in to it '
- ' once before you will be able to send mails.'),
+ ' hotmail account, Microsoft requires that you '
+ ' verify your account periodically, before it'
+ ' will let calibre send email. In this case, I'
+ ' strongly suggest you setup a free gmail account'
+ ' instead.'),
}
}[service]
d = QDialog(self)
From 67d019712851b50eda01d96c5304e4cd4fa52ec9 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Mon, 23 May 2011 19:11:56 +0100
Subject: [PATCH 37/51] Add tags wizard. Robustness changes to the formatter,
model, and look_feel.
---
.../gui2/dialogs/template_line_editor.py | 100 +++++++++++++++++-
src/calibre/gui2/library/models.py | 9 +-
src/calibre/gui2/preferences/look_feel.py | 10 +-
src/calibre/utils/formatter.py | 2 +-
4 files changed, 112 insertions(+), 9 deletions(-)
diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py
index c3598a8abb..a6269a9bbc 100644
--- a/src/calibre/gui2/dialogs/template_line_editor.py
+++ b/src/calibre/gui2/dialogs/template_line_editor.py
@@ -5,8 +5,12 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal '
__docformat__ = 'restructuredtext en'
-from PyQt4.Qt import QLineEdit
+from PyQt4.Qt import (QLineEdit, QDialog, QGridLayout, QLabel,
+ QDialogButtonBox, QColor, QTimer, QComboBox)
+
from calibre.gui2.dialogs.template_dialog import TemplateDialog
+from calibre.gui2.complete import MultiCompleteComboBox
+from calibre.gui2 import error_dialog
class TemplateLineEditor(QLineEdit):
@@ -14,13 +18,22 @@ class TemplateLineEditor(QLineEdit):
Extend the context menu of a QLineEdit to include more actions.
'''
+ def __init__(self, parent):
+ QLineEdit.__init__(self, parent)
+ self.tags = None
+
+ def set_tags(self, tags):
+ self.tags = tags
+
def contextMenuEvent(self, event):
menu = self.createStandardContextMenu()
menu.addSeparator()
action_open_editor = menu.addAction(_('Open Template Editor'))
-
action_open_editor.triggered.connect(self.open_editor)
+ if self.tags:
+ action_tag_wizard = menu.addAction(_('Open Tag Wizard'))
+ action_tag_wizard.triggered.connect(self.tag_wizard)
menu.exec_(event.globalPos())
def open_editor(self):
@@ -29,4 +42,87 @@ class TemplateLineEditor(QLineEdit):
if t.exec_():
self.setText(t.textbox.toPlainText())
+ def tag_wizard(self):
+ txt = unicode(self.text())
+ if txt and not txt.startswith('program:\n#tag wizard'):
+ error_dialog(self, _('Invalid text'),
+ _('The text in the box was not generated by this wizard'),
+ show=True, show_copy_button=False)
+ return
+ d = TagWizard(self, self.tags, unicode(self.text()))
+ if d.exec_():
+ self.setText(d.template)
+class TagWizard(QDialog):
+
+ def __init__(self, parent, tags, txt):
+ QDialog.__init__(self, parent)
+
+ self.tags = tags
+ l = QGridLayout()
+ self.setLayout(l)
+ l.addWidget(QLabel(_('Tag Value')), 0, 0, 1, 1)
+ l.addWidget(QLabel(_('Color')), 0, 1, 1, 1)
+ self.tagboxes = []
+ self.colorboxes = []
+ self.colors = [unicode(s) for s in list(QColor.colorNames())]
+ self.colors.insert(0, '')
+ for i in range(0, 10):
+ tb = MultiCompleteComboBox(self)
+ tb.set_separator(', ')
+ tb.update_items_cache(self.tags)
+ self.tagboxes.append(tb)
+ l.addWidget(tb, i+1, 0, 1, 1)
+ cb = QComboBox(self)
+ cb.addItems(self.colors)
+ self.colorboxes.append(cb)
+ l.addWidget(cb, i+1, 1, 1, 1)
+
+ if txt:
+ lines = txt.split('\n')[3:]
+ i = 0
+ for line in lines:
+ if line.startswith('#'):
+ t,c = line[1:].split(':|:')
+ try:
+ self.colorboxes[i].setCurrentIndex(self.colorboxes[i].findText(c))
+ self.tagboxes[i].setText(t)
+ except:
+ pass
+ i += 1
+
+ bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel, parent=self)
+ l.addWidget(bb, 100, 1, 1, 1)
+ bb.accepted.connect(self.accepted)
+ bb.rejected.connect(self.reject)
+ self.template = ''
+
+ def accepted(self):
+ res = ("program:\n#tag wizard -- do not directly edit\n"
+ " t = field('tags');\n first_non_empty(\n")
+ lines = []
+ for tb, cb in zip(self.tagboxes, self.colorboxes):
+ tags = [t.strip() for t in unicode(tb.currentText()).split(',') if t.strip()]
+ c = unicode(cb.currentText()).strip()
+ if not tags or not c:
+ continue
+ if c not in self.colors:
+ error_dialog(self, _('Invalid color'),
+ _('The color {0} is not valid').format(c),
+ show=True, show_copy_button=False)
+ return False
+ for t in tags:
+ lines.append(" in_list(t, ',', '^{0}$', '{1}', '')".format(t, c))
+ res += ',\n'.join(lines)
+ res += ')\n'
+ self.template = res
+ res = ''
+ for tb, cb in zip(self.tagboxes, self.colorboxes):
+ t = unicode(tb.currentText()).strip()
+ if t.endswith(','):
+ t = t[:-1]
+ c = unicode(cb.currentText()).strip()
+ if t and c:
+ res += '#' + t + ':|:' + c + '\n'
+ self.template += res
+ self.accept()
\ No newline at end of file
diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py
index d698655746..86c5871193 100644
--- a/src/calibre/gui2/library/models.py
+++ b/src/calibre/gui2/library/models.py
@@ -98,6 +98,7 @@ class BooksModel(QAbstractTableModel): # {{{
self.current_highlighted_idx = None
self.highlight_only = False
self.column_color_map = {}
+ self.colors = [unicode(c) for c in QColor.colorNames()]
self.read_config()
def change_alignment(self, colname, alignment):
@@ -714,9 +715,11 @@ class BooksModel(QAbstractTableModel): # {{{
mi = self.db.get_metadata(self.id(index), index_is_id=True)
fmt = self.column_color_map[key]
try:
- color = QColor(composite_formatter.safe_format(fmt, mi, '', mi))
- if color.isValid():
- return QVariant(color)
+ color = composite_formatter.safe_format(fmt, mi, '', mi)
+ if color in self.colors:
+ color = QColor(color)
+ if color.isValid():
+ return QVariant(color)
except:
return NONE
elif self.is_custom_column(key) and \
diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py
index 1c9d4abfce..61ec47ef62 100644
--- a/src/calibre/gui2/preferences/look_feel.py
+++ b/src/calibre/gui2/preferences/look_feel.py
@@ -198,9 +198,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
choices.sort(key=sort_key)
choices.insert(0, '')
self.column_color_count = db.column_color_count+1
+ tags = db.all_tags()
for i in range(1, self.column_color_count):
r('column_color_name_'+str(i), db.prefs, choices=choices)
r('column_color_template_'+str(i), db.prefs)
+ temp = getattr(self, 'opt_column_color_template_'+str(i))
+ temp.set_tags(tags)
all_colors = [unicode(s) for s in list(QColor.colorNames())]
self.colors_box.setText(', '.join(all_colors))
@@ -273,9 +276,10 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
def commit(self, *args):
for i in range(1, self.column_color_count):
col = getattr(self, 'opt_column_color_name_'+str(i))
- if not col.currentText():
- temp = getattr(self, 'opt_column_color_template_'+str(i))
- temp.setText('')
+ tpl = getattr(self, 'opt_column_color_template_'+str(i))
+ if not col.currentIndex() or not unicode(tpl.text()).strip():
+ col.setCurrentIndex(0)
+ tpl.setText('')
rr = ConfigWidgetBase.commit(self, *args)
if self.current_font != self.initial_font:
gprefs['font'] = (self.current_font[:4] if self.current_font else
diff --git a/src/calibre/utils/formatter.py b/src/calibre/utils/formatter.py
index 2e40275beb..fccd0015c1 100644
--- a/src/calibre/utils/formatter.py
+++ b/src/calibre/utils/formatter.py
@@ -215,7 +215,7 @@ class TemplateFormatter(string.Formatter):
(r'\w+', lambda x,t: (2, t)),
(r'".*?((?
Date: Mon, 23 May 2011 19:19:18 +0100
Subject: [PATCH 38/51] Improved documentation
---
src/calibre/gui2/preferences/look_feel.py | 6 ++++++
src/calibre/gui2/preferences/look_feel.ui | 4 ++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py
index 61ec47ef62..7692a8aba7 100644
--- a/src/calibre/gui2/preferences/look_feel.py
+++ b/src/calibre/gui2/preferences/look_feel.py
@@ -167,6 +167,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
''
'tutorial on using templates.') +
'
' +
+ _('If you want to color a field based on tags, then right-click '
+ 'in an empty template line and choose tags wizard. '
+ 'It will build a template for you. You can later edit that '
+ 'template with the same wizard. If you edit it by hand, the '
+ 'wizard might not work or might restore old values.') +
+ '
' +
_('The template must evaluate to one of the color names shown '
'below. You can use any legal template expression. '
'For example, you can set the title to always display in '
diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui
index ad990a1586..31fa0df234 100644
--- a/src/calibre/gui2/preferences/look_feel.ui
+++ b/src/calibre/gui2/preferences/look_feel.ui
@@ -419,14 +419,14 @@ then the tags will be displayed each on their own line.
-
- Column name
+ Column to color
-
- Selection template
+ Color selection template
From 0c22359203d77f6adf5018cda5e5650ab4b22c36 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Mon, 23 May 2011 13:41:14 -0600
Subject: [PATCH 39/51] ...
---
src/calibre/gui2/widgets.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py
index a7ecdf7b88..dd8d876005 100644
--- a/src/calibre/gui2/widgets.py
+++ b/src/calibre/gui2/widgets.py
@@ -833,7 +833,7 @@ class PythonHighlighter(QSyntaxHighlighter):
Config["tabwidth"] = settings.value("tabwidth",
QVariant(4)).toInt()[0]
Config["fontfamily"] = settings.value("fontfamily",
- QVariant("Bitstream Vera Sans Mono")).toString()
+ QVariant("monospace")).toString()
Config["fontsize"] = settings.value("fontsize",
QVariant(10)).toInt()[0]
for name, color, bold, italic in (
From bd4b5ec6ea4f0a7fbdd22e9b3d1a96a9d8d17f20 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Mon, 23 May 2011 21:25:53 +0100
Subject: [PATCH 40/51] Add color tag wizard tool button
---
src/calibre/gui2/preferences/look_feel.py | 6 ++--
src/calibre/gui2/preferences/look_feel.ui | 44 +++++++++++++++++++++--
2 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py
index 7692a8aba7..483934825d 100644
--- a/src/calibre/gui2/preferences/look_feel.py
+++ b/src/calibre/gui2/preferences/look_feel.py
@@ -208,8 +208,10 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
for i in range(1, self.column_color_count):
r('column_color_name_'+str(i), db.prefs, choices=choices)
r('column_color_template_'+str(i), db.prefs)
- temp = getattr(self, 'opt_column_color_template_'+str(i))
- temp.set_tags(tags)
+ tpl = getattr(self, 'opt_column_color_template_'+str(i))
+ tpl.set_tags(tags)
+ toolbutton = getattr(self, 'opt_column_color_wizard_'+str(i))
+ toolbutton.clicked.connect(tpl.tag_wizard)
all_colors = [unicode(s) for s in list(QColor.colorNames())]
self.colors_box.setText(', '.join(all_colors))
diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui
index 31fa0df234..a67a3585cb 100644
--- a/src/calibre/gui2/preferences/look_feel.ui
+++ b/src/calibre/gui2/preferences/look_feel.ui
@@ -436,30 +436,70 @@ then the tags will be displayed each on their own line.
-
+ -
+
+
+
+ :/images/wizard.png:/images/wizard.png
+
+
+
-
-
+ -
+
+
+
+ :/images/wizard.png:/images/wizard.png
+
+
+
-
-
+ -
+
+
+
+ :/images/wizard.png:/images/wizard.png
+
+
+
-
-
+ -
+
+
+
+ :/images/wizard.png:/images/wizard.png
+
+
+
-
-
+ -
+
+
+
+ :/images/wizard.png:/images/wizard.png
+
+
+
-
@@ -467,7 +507,7 @@ then the tags will be displayed each on their own line.
- -
+
-
@@ -505,7 +545,7 @@ then the tags will be displayed each on their own line.
- -
+
-
From 610210f0b290f78c2957237b4c7b60e1e795bc27 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Mon, 23 May 2011 18:24:26 -0600
Subject: [PATCH 41/51] ...
---
src/calibre/manual/conversion.rst | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/calibre/manual/conversion.rst b/src/calibre/manual/conversion.rst
index 73358e0f72..540da0fc9a 100644
--- a/src/calibre/manual/conversion.rst
+++ b/src/calibre/manual/conversion.rst
@@ -655,6 +655,7 @@ Some limitations of PDF input are:
* Some PDFs use special glyphs to represent ll or ff or fi, etc. Conversion of these may or may not work depending on just how they are represented internally in the PDF.
* Some PDFs store their images upside down with a rotation instruction, |app| currently doesn't support that instruction, so the images will be rotated in the output as well.
* Links and Tables of Contents are not supported
+ * PDFs that use embedded non-unicode fonts to represent non-English characters will result in garbled output for those characters
To re-iterate **PDF is a really, really bad** format to use as input. If you absolutely must use PDF, then be prepared for an
output ranging anywhere from decent to unusable, depending on the input PDF.
From 99ad2c86b5cd71541b2f9370700ee14ec908c7f3 Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Tue, 24 May 2011 08:23:50 +0100
Subject: [PATCH 42/51] Small change to help text. Add tooltip to wizard
button. Have tag column expand in tag wizard when resizing dialog.
---
src/calibre/gui2/dialogs/template_line_editor.py | 1 +
src/calibre/gui2/preferences/look_feel.py | 4 ++--
src/calibre/gui2/preferences/look_feel.ui | 15 +++++++++++++++
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py
index 95727e442b..26f4dd0753 100644
--- a/src/calibre/gui2/dialogs/template_line_editor.py
+++ b/src/calibre/gui2/dialogs/template_line_editor.py
@@ -63,6 +63,7 @@ class TagWizard(QDialog):
self.tags = tags
l = QGridLayout()
self.setLayout(l)
+ l.setColumnStretch(0, 1)
l.addWidget(QLabel(_('Tag Value')), 0, 0, 1, 1)
l.addWidget(QLabel(_('Color')), 0, 1, 1, 1)
self.tagboxes = []
diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py
index 483934825d..49bfb1df1a 100644
--- a/src/calibre/gui2/preferences/look_feel.py
+++ b/src/calibre/gui2/preferences/look_feel.py
@@ -167,8 +167,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
''
'tutorial on using templates.') +
'
' +
- _('If you want to color a field based on tags, then right-click '
- 'in an empty template line and choose tags wizard. '
+ _('If you want to color a field based on tags, then click the '
+ 'button next to an empty line to open the tags wizard. '
'It will build a template for you. You can later edit that '
'template with the same wizard. If you edit it by hand, the '
'wizard might not work or might restore old values.') +
diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui
index a67a3585cb..fe6134f235 100644
--- a/src/calibre/gui2/preferences/look_feel.ui
+++ b/src/calibre/gui2/preferences/look_feel.ui
@@ -442,6 +442,9 @@ then the tags will be displayed each on their own line.
:/images/wizard.png:/images/wizard.png
+
+ Open the tags wizard.
+
-
@@ -456,6 +459,9 @@ then the tags will be displayed each on their own line.
:/images/wizard.png:/images/wizard.png
+
+ Open the tags wizard.
+
-
@@ -470,6 +476,9 @@ then the tags will be displayed each on their own line.
:/images/wizard.png:/images/wizard.png
+
+ Open the tags wizard.
+
-
@@ -484,6 +493,9 @@ then the tags will be displayed each on their own line.
:/images/wizard.png:/images/wizard.png
+
+ Open the tags wizard.
+
-
@@ -498,6 +510,9 @@ then the tags will be displayed each on their own line.
:/images/wizard.png:/images/wizard.png
+
+ Open the tags wizard.
+
-
From b897f6dc119645bef217fa6191fe9e179d8b9a3a Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Tue, 24 May 2011 15:07:46 +0100
Subject: [PATCH 43/51] Changes to descriptions, addition to declined.txt
---
src/calibre/customize/builtins.py | 56 ++++++++++++++---------------
src/calibre/gui2/store/declined.txt | 3 ++
2 files changed, 31 insertions(+), 28 deletions(-)
diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py
index 680e36d0f3..4c80c53d78 100644
--- a/src/calibre/customize/builtins.py
+++ b/src/calibre/customize/builtins.py
@@ -854,14 +854,14 @@ class ActionStore(InterfaceActionBase):
name = 'Store'
author = 'John Schember'
actual_plugin = 'calibre.gui2.actions.store:StoreAction'
-
+
def customization_help(self, gui=False):
return 'Customize the behavior of the store search.'
-
+
def config_widget(self):
from calibre.gui2.store.config.store import config_widget as get_cw
return get_cw()
-
+
def save_settings(self, config_widget):
from calibre.gui2.store.config.store import save_settings as save
save(config_widget)
@@ -1108,7 +1108,7 @@ class StoreAmazonKindleStore(StoreBase):
name = 'Amazon Kindle'
description = u'Kindle books from Amazon.'
actual_plugin = 'calibre.gui2.store.amazon_plugin:AmazonKindleStore'
-
+
drm_free_only = False
headquarters = 'US'
formats = ['KINDLE']
@@ -1118,7 +1118,7 @@ class StoreAmazonDEKindleStore(StoreBase):
author = 'Charles Haley'
description = u'Kindle Bücher von Amazon.'
actual_plugin = 'calibre.gui2.store.amazon_de_plugin:AmazonDEKindleStore'
-
+
drm_free_only = False
headquarters = 'DE'
formats = ['KINDLE']
@@ -1128,7 +1128,7 @@ class StoreAmazonUKKindleStore(StoreBase):
author = 'Charles Haley'
description = u'Kindle books from Amazon\'s UK web site. Also, includes French language ebooks.'
actual_plugin = 'calibre.gui2.store.amazon_uk_plugin:AmazonUKKindleStore'
-
+
drm_free_only = False
headquarters = 'UK'
formats = ['KINDLE']
@@ -1146,7 +1146,7 @@ class StoreBaenWebScriptionStore(StoreBase):
name = 'Baen WebScription'
description = u'Sci-Fi & Fantasy brought to you by Jim Baen.'
actual_plugin = 'calibre.gui2.store.baen_webscription_plugin:BaenWebScriptionStore'
-
+
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'LIT', 'LRF', 'MOBI', 'RB', 'RTF', 'ZIP']
@@ -1155,7 +1155,7 @@ class StoreBNStore(StoreBase):
name = 'Barnes and Noble'
description = u'The world\'s largest book seller. As the ultimate destination for book lovers, Barnes & Noble.com offers an incredible array of content.'
actual_plugin = 'calibre.gui2.store.bn_plugin:BNStore'
-
+
drm_free_only = False
headquarters = 'US'
formats = ['NOOK']
@@ -1163,9 +1163,9 @@ class StoreBNStore(StoreBase):
class StoreBeamEBooksDEStore(StoreBase):
name = 'Beam EBooks DE'
author = 'Charles Haley'
- description = u'Der eBook Shop.'
+ description = u'Bei uns finden Sie: Tausende deutschsprachige eBooks; Alle eBooks ohne hartes DRM; PDF, ePub und Mobipocket Format; Sofortige Verfügbarkeit - 24 Stunden am Tag; Günstige Preise; eBooks für viele Lesegeräte, PC,Mac und Smartphones; Viele Gratis eBooks'
actual_plugin = 'calibre.gui2.store.beam_ebooks_de_plugin:BeamEBooksDEStore'
-
+
drm_free_only = True
headquarters = 'DE'
formats = ['EPUB', 'MOBI', 'PDF']
@@ -1174,7 +1174,7 @@ class StoreBeWriteStore(StoreBase):
name = 'BeWrite Books'
description = u'Publishers of fine books. Highly selective and editorially driven. Does not offer: books for children or exclusively YA, erotica, swords-and-sorcery fantasy and space-opera-style science fiction. All other genres are represented.'
actual_plugin = 'calibre.gui2.store.bewrite_plugin:BeWriteStore'
-
+
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'MOBI', 'PDF']
@@ -1183,7 +1183,7 @@ class StoreDieselEbooksStore(StoreBase):
name = 'Diesel eBooks'
description = u'Instant access to over 2.4 million titles from hundreds of publishers including Harlequin, HarperCollins, John Wiley & Sons, McGraw-Hill, Simon & Schuster and Random House.'
actual_plugin = 'calibre.gui2.store.diesel_ebooks_plugin:DieselEbooksStore'
-
+
drm_free_only = False
headquarters = 'US'
formats = ['EPUB', 'PDF']
@@ -1192,7 +1192,7 @@ class StoreEbookscomStore(StoreBase):
name = 'eBooks.com'
description = u'Sells books in multiple electronic formats in all categories. Technical infrastructure is cutting edge, robust and scalable, with servers in the US and Europe.'
actual_plugin = 'calibre.gui2.store.ebooks_com_plugin:EbookscomStore'
-
+
drm_free_only = False
headquarters = 'US'
formats = ['EPUB', 'LIT', 'MOBI', 'PDF']
@@ -1200,9 +1200,9 @@ class StoreEbookscomStore(StoreBase):
class StoreEPubBuyDEStore(StoreBase):
name = 'EPUBBuy DE'
author = 'Charles Haley'
- description = u'Deutsch epub-Spezialisten.'
+ description = u'Bei EPUBBuy.com finden Sie ausschliesslich eBooks im weitverbreiteten EPUB-Format und ohne DRM. So haben Sie die freie Wahl, wo Sie Ihr eBook lesen: Tablet, eBook-Reader, Smartphone oder einfach auf Ihrem PC. So macht eBook-Lesen Spaß!'
actual_plugin = 'calibre.gui2.store.epubbuy_de_plugin:EPubBuyDEStore'
-
+
drm_free_only = True
headquarters = 'DE'
formats = ['EPUB']
@@ -1211,7 +1211,7 @@ class StoreEHarlequinStore(StoreBase):
name = 'eHarlequin'
description = u'A global leader in series romance and one of the world\'s leading publishers of books for women. Offers women a broad range of reading from romance to bestseller fiction, from young adult novels to erotic literature, from nonfiction to fantasy, from African-American novels to inspirational romance, and more.'
actual_plugin = 'calibre.gui2.store.eharlequin_plugin:EHarlequinStore'
-
+
drm_free_only = False
headquarters = 'CA'
formats = ['EPUB', 'PDF']
@@ -1220,7 +1220,7 @@ class StoreFeedbooksStore(StoreBase):
name = 'Feedbooks'
description = u'Feedbooks is a cloud publishing and distribution service, connected to a large ecosystem of reading systems and social networks. Provides a variety of genres from independent and classic books.'
actual_plugin = 'calibre.gui2.store.feedbooks_plugin:FeedbooksStore'
-
+
drm_free_only = False
headquarters = 'FR'
formats = ['EPUB', 'MOBI', 'PDF']
@@ -1249,7 +1249,7 @@ class StoreGoogleBooksStore(StoreBase):
name = 'Google Books'
description = u'Google Books'
actual_plugin = 'calibre.gui2.store.google_books_plugin:GoogleBooksStore'
-
+
drm_free_only = False
headquarters = 'US'
formats = ['EPUB', 'PDF', 'TXT']
@@ -1258,7 +1258,7 @@ class StoreGutenbergStore(StoreBase):
name = 'Project Gutenberg'
description = u'The first producer of free ebooks. Free in the United States because their copyright has expired. They may not be free of copyright in other countries. Readers outside of the United States must check the copyright laws of their countries before downloading or redistributing our ebooks.'
actual_plugin = 'calibre.gui2.store.gutenberg_plugin:GutenbergStore'
-
+
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'HTML', 'MOBI', 'PDB', 'TXT']
@@ -1267,7 +1267,7 @@ class StoreKoboStore(StoreBase):
name = 'Kobo'
description = u'With over 2.3 million eBooks to browse we have engaged readers in over 200 countries in Kobo eReading. Our eBook listings include New York Times Bestsellers, award winners, classics and more!'
actual_plugin = 'calibre.gui2.store.kobo_plugin:KoboStore'
-
+
drm_free_only = False
headquarters = 'CA'
formats = ['EPUB']
@@ -1276,7 +1276,7 @@ class StoreManyBooksStore(StoreBase):
name = 'ManyBooks'
description = u'Public domain and creative commons works from many sources.'
actual_plugin = 'calibre.gui2.store.manybooks_plugin:ManyBooksStore'
-
+
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'FB2', 'JAR', 'LIT', 'LRF', 'MOBI', 'PDB', 'PDF', 'RB', 'RTF', 'TCR', 'TXT', 'ZIP']
@@ -1295,7 +1295,7 @@ class StoreNextoStore(StoreBase):
author = u'Tomasz Długosz'
description = u'Największy w Polsce sklep internetowy z audiobookami mp3, ebookami pdf oraz prasą do pobrania on-line.'
actual_plugin = 'calibre.gui2.store.nexto_plugin:NextoStore'
-
+
drm_free_only = False
headquarters = 'PL'
formats = ['EPUB', 'PDF']
@@ -1304,7 +1304,7 @@ class StoreOpenLibraryStore(StoreBase):
name = 'Open Library'
description = u'One web page for every book ever published. The goal is to be a true online library. Over 20 million records from a variety of large catalogs as well as single contributions, with more on the way.'
actual_plugin = 'calibre.gui2.store.open_library_plugin:OpenLibraryStore'
-
+
drm_free_only = True
headquarters = ['US']
formats = ['DAISY', 'DJVU', 'EPUB', 'MOBI', 'PDF', 'TXT']
@@ -1313,7 +1313,7 @@ class StoreOReillyStore(StoreBase):
name = 'OReilly'
description = u'Programming and tech ebooks from OReilly.'
actual_plugin = 'calibre.gui2.store.oreilly_plugin:OReillyStore'
-
+
drm_free_only = True
headquarters = 'US'
formats = ['APK', 'DAISY', 'EPUB', 'MOBI', 'PDF']
@@ -1331,7 +1331,7 @@ class StoreSmashwordsStore(StoreBase):
name = 'Smashwords'
description = u'An ebook publishing and distribution platform for ebook authors, publishers and readers. Covers many genres and formats.'
actual_plugin = 'calibre.gui2.store.smashwords_plugin:SmashwordsStore'
-
+
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'HTML', 'LRF', 'MOBI', 'PDB', 'RTF', 'TXT']
@@ -1341,7 +1341,7 @@ class StoreWaterstonesUKStore(StoreBase):
author = 'Charles Haley'
description = u'Waterstone\'s mission is to be the leading Bookseller on the High Street and online providing customers the widest choice, great value and expert advice from a team passionate about Bookselling.'
actual_plugin = 'calibre.gui2.store.waterstones_uk_plugin:WaterstonesUKStore'
-
+
drm_free_only = False
headquarters = 'UK'
formats = ['EPUB', 'PDF']
@@ -1359,7 +1359,7 @@ class StoreWizardsTowerBooksStore(StoreBase):
name = 'Wizards Tower Books'
description = u'A science fiction and fantasy publisher. Concentrates mainly on making out-of-print works available once more as e-books, and helping other small presses exploit the e-book market. Also publishes a small number of limited-print-run anthologies with a view to encouraging diversity in the science fiction and fantasy field.'
actual_plugin = 'calibre.gui2.store.wizards_tower_books_plugin:WizardsTowerBooksStore'
-
+
drm_free_only = True
headquarters = 'UK'
formats = ['EPUB', 'MOBI']
@@ -1389,7 +1389,7 @@ plugins += [
StoreEHarlequinStore,
StoreFeedbooksStore,
StoreFoylesUKStore,
- StoreGandalfStore,
+ StoreGandalfStore,
StoreGoogleBooksStore,
StoreGutenbergStore,
StoreKoboStore,
diff --git a/src/calibre/gui2/store/declined.txt b/src/calibre/gui2/store/declined.txt
index 2b0e5caed2..2186303d4b 100644
--- a/src/calibre/gui2/store/declined.txt
+++ b/src/calibre/gui2/store/declined.txt
@@ -3,3 +3,6 @@ or asked not to be included in the store integration.
* Borders (http://www.borders.com/)
* WH Smith (http://www.whsmith.co.uk/)
+ Refused to permit signing up for the affiliate program
+* Libraria Rizzoli (http://libreriarizzoli.corriere.it/).
+ No reply with two attempts over 2 weeks
\ No newline at end of file
From 1bb4911ece2374f3fc2fce0e57383fc11f847e8c Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Tue, 24 May 2011 10:54:06 -0600
Subject: [PATCH 44/51] ...
---
src/calibre/linux.py | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/calibre/linux.py b/src/calibre/linux.py
index 1e7a62b869..9e58d4f638 100644
--- a/src/calibre/linux.py
+++ b/src/calibre/linux.py
@@ -356,7 +356,7 @@ class PostInstall:
mimetypes = set([])
for x in all_input_formats():
mt = guess_type('dummy.'+x)[0]
- if mt and 'chemical' not in mt:
+ if mt and 'chemical' not in mt and 'ctc-posml' not in mt:
mimetypes.add(mt)
def write_mimetypes(f):
@@ -376,11 +376,10 @@ class PostInstall:
des = ('calibre-gui.desktop', 'calibre-lrfviewer.desktop',
'calibre-ebook-viewer.desktop')
for x in des:
- cmd = ['xdg-desktop-menu', 'install', './'+x]
- if x != des[-1]:
- cmd.insert(2, '--noupdate')
+ cmd = ['xdg-desktop-menu', 'install', '--noupdate', './'+x]
check_call(' '.join(cmd), shell=True)
self.menu_resources.append(x)
+ check_call(['xdg-desktop-menu', 'forceupdate'])
f = open('calibre-mimetypes', 'wb')
f.write(MIME)
f.close()
From 268a81499cde8ae38063679343306113148b158a Mon Sep 17 00:00:00 2001
From: Charles Haley <>
Date: Tue, 24 May 2011 18:26:04 +0100
Subject: [PATCH 45/51] Change control to a line edit. Improve generated
template code.
---
.../gui2/dialogs/template_line_editor.py | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py
index 26f4dd0753..98b74b391d 100644
--- a/src/calibre/gui2/dialogs/template_line_editor.py
+++ b/src/calibre/gui2/dialogs/template_line_editor.py
@@ -9,7 +9,7 @@ from PyQt4.Qt import (QLineEdit, QDialog, QGridLayout, QLabel,
QDialogButtonBox, QColor, QComboBox, QIcon)
from calibre.gui2.dialogs.template_dialog import TemplateDialog
-from calibre.gui2.complete import MultiCompleteComboBox
+from calibre.gui2.complete import MultiCompleteLineEdit
from calibre.gui2 import error_dialog
class TemplateLineEditor(QLineEdit):
@@ -64,14 +64,15 @@ class TagWizard(QDialog):
l = QGridLayout()
self.setLayout(l)
l.setColumnStretch(0, 1)
- l.addWidget(QLabel(_('Tag Value')), 0, 0, 1, 1)
+ l.setColumnMinimumWidth(0, 300)
+ l.addWidget(QLabel(_('Tags (more than one per box permitted)')), 0, 0, 1, 1)
l.addWidget(QLabel(_('Color')), 0, 1, 1, 1)
self.tagboxes = []
self.colorboxes = []
self.colors = [unicode(s) for s in list(QColor.colorNames())]
self.colors.insert(0, '')
for i in range(0, 10):
- tb = MultiCompleteComboBox(self)
+ tb = MultiCompleteLineEdit(self)
tb.set_separator(', ')
tb.update_items_cache(self.tags)
self.tagboxes.append(tb)
@@ -102,10 +103,11 @@ class TagWizard(QDialog):
def accepted(self):
res = ("program:\n#tag wizard -- do not directly edit\n"
- " t = field('tags');\n first_non_empty(\n")
+ " t = field('tags');\n first_non_empty(\n")
lines = []
for tb, cb in zip(self.tagboxes, self.colorboxes):
- tags = [t.strip() for t in unicode(tb.currentText()).split(',') if t.strip()]
+ tags = [t.strip() for t in unicode(tb.text()).split(',') if t.strip()]
+ tags = '$|^'.join(tags)
c = unicode(cb.currentText()).strip()
if not tags or not c:
continue
@@ -114,14 +116,13 @@ class TagWizard(QDialog):
_('The color {0} is not valid').format(c),
show=True, show_copy_button=False)
return False
- for t in tags:
- lines.append(" in_list(t, ',', '^{0}$', '{1}', '')".format(t, c))
+ lines.append(" in_list(t, ',', '^{0}$', '{1}', '')".format(tags, c))
res += ',\n'.join(lines)
res += ')\n'
self.template = res
res = ''
for tb, cb in zip(self.tagboxes, self.colorboxes):
- t = unicode(tb.currentText()).strip()
+ t = unicode(tb.text()).strip()
if t.endswith(','):
t = t[:-1]
c = unicode(cb.currentText()).strip()
From 2fec4aa6c3719767d52c8e4558697dbc4f088ebb Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Tue, 24 May 2011 13:33:52 -0600
Subject: [PATCH 46/51] ...
---
src/calibre/library/server/base.py | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/calibre/library/server/base.py b/src/calibre/library/server/base.py
index 862e724809..319feefa44 100644
--- a/src/calibre/library/server/base.py
+++ b/src/calibre/library/server/base.py
@@ -221,7 +221,12 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache,
if not ip or ip.startswith('127.'):
raise
cherrypy.log('Trying to bind to single interface: '+ip)
+ # Change the host we listen on
cherrypy.config.update({'server.socket_host' : ip})
+ # This ensures that the change is actually applied
+ cherrypy.server.socket_host = ip
+ cherrypy.server.httpserver = cherrypy.server.instance = None
+
cherrypy.engine.start()
self.is_running = True
@@ -231,6 +236,8 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache,
cherrypy.engine.block()
except Exception as e:
self.exception = e
+ import traceback
+ traceback.print_exc()
finally:
self.is_running = False
try:
From 3a78a875afe7c980aae8497d89e1a1d784335c2f Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Tue, 24 May 2011 15:18:47 -0600
Subject: [PATCH 47/51] Amazon metadata download: Use separate identifiers for
country specific downloads so that the links to Amazon in the Book details
panel work when downloading metadata from country specific amazon websites.
Fixes #786146 (German Amazon Metadata)
---
src/calibre/ebooks/metadata/sources/amazon.py | 63 +++++++++++++------
1 file changed, 43 insertions(+), 20 deletions(-)
diff --git a/src/calibre/ebooks/metadata/sources/amazon.py b/src/calibre/ebooks/metadata/sources/amazon.py
index f291959475..7da37ce5af 100644
--- a/src/calibre/ebooks/metadata/sources/amazon.py
+++ b/src/calibre/ebooks/metadata/sources/amazon.py
@@ -29,7 +29,7 @@ class Worker(Thread): # Get details {{{
Get book details from amazons book page in a separate thread
'''
- def __init__(self, url, result_queue, browser, log, relevance, plugin, timeout=20):
+ def __init__(self, url, result_queue, browser, log, relevance, domain, plugin, timeout=20):
Thread.__init__(self)
self.daemon = True
self.url, self.result_queue = url, result_queue
@@ -37,7 +37,7 @@ class Worker(Thread): # Get details {{{
self.relevance, self.plugin = relevance, plugin
self.browser = browser.clone_browser()
self.cover_url = self.amazon_id = self.isbn = None
- self.domain = self.plugin.domain
+ self.domain = domain
months = {
'de': {
@@ -199,7 +199,8 @@ class Worker(Thread): # Get details {{{
return
mi = Metadata(title, authors)
- mi.set_identifier('amazon', asin)
+ idtype = 'amazon' if self.domain == 'com' else 'amazon_'+self.domain
+ mi.set_identifier(idtype, asin)
self.amazon_id = asin
try:
@@ -404,12 +405,30 @@ class Amazon(Source):
'country\'s Amazon website.'), choices=AMAZON_DOMAINS),
)
+ def get_domain_and_asin(self, identifiers):
+ for key, val in identifiers.iteritems():
+ key = key.lower()
+ if key in ('amazon', 'asin'):
+ return 'com', val
+ if key.startswith('amazon_'):
+ domain = key.split('_')[-1]
+ if domain and domain in self.AMAZON_DOMAINS:
+ return domain, val
+ return None, None
+
def get_book_url(self, identifiers): # {{{
- asin = identifiers.get('amazon', None)
- if asin is None:
- asin = identifiers.get('asin', None)
- if asin:
- return ('amazon', asin, 'http://amzn.com/%s'%asin)
+ domain, asin = self.get_domain_and_asin(identifiers)
+ if domain and asin:
+ url = None
+ if domain == 'com':
+ url = 'http://amzn.com/'+asin
+ elif domain == 'uk':
+ url = 'http://www.amazon.co.uk/dp/'+asin
+ else:
+ url = 'http://www.amazon.%s/dp/%s'%(domain, asin)
+ if url:
+ idtype = 'amazon' if self.domain == 'com' else 'amazon_'+self.domain
+ return (idtype, asin, url)
# }}}
@property
@@ -420,8 +439,14 @@ class Amazon(Source):
return domain
- def create_query(self, log, title=None, authors=None, identifiers={}): # {{{
- domain = self.domain
+ def create_query(self, log, title=None, authors=None, identifiers={}, # {{{
+ domain=None):
+ if domain is None:
+ domain = self.domain
+
+ idomain, asin = self.get_domain_and_asin(identifiers)
+ if idomain is not None:
+ domain = idomain
# See the amazon detailed search page to get all options
q = { 'search-alias' : 'aps',
@@ -433,7 +458,6 @@ class Amazon(Source):
else:
q['sort'] = 'relevancerank'
- asin = identifiers.get('amazon', None)
isbn = check_isbn(identifiers.get('isbn', None))
if asin is not None:
@@ -456,23 +480,22 @@ class Amazon(Source):
if not ('field-keywords' in q or 'field-isbn' in q or
('field-title' in q)):
# Insufficient metadata to make an identify query
- return None
+ return None, None
latin1q = dict([(x.encode('latin1', 'ignore'), y.encode('latin1',
'ignore')) for x, y in
q.iteritems()])
+ udomain = domain
if domain == 'uk':
- domain = 'co.uk'
- url = 'http://www.amazon.%s/s/?'%domain + urlencode(latin1q)
- return url
+ udomain = 'co.uk'
+ url = 'http://www.amazon.%s/s/?'%udomain + urlencode(latin1q)
+ return url, domain
# }}}
def get_cached_cover_url(self, identifiers): # {{{
url = None
- asin = identifiers.get('amazon', None)
- if asin is None:
- asin = identifiers.get('asin', None)
+ domain, asin = self.get_domain_and_asin(identifiers)
if asin is None:
isbn = identifiers.get('isbn', None)
if isbn is not None:
@@ -489,7 +512,7 @@ class Amazon(Source):
Note this method will retry without identifiers automatically if no
match is found with identifiers.
'''
- query = self.create_query(log, title=title, authors=authors,
+ query, domain = self.create_query(log, title=title, authors=authors,
identifiers=identifiers)
if query is None:
log.error('Insufficient metadata to construct query')
@@ -571,7 +594,7 @@ class Amazon(Source):
log.error('No matches found with query: %r'%query)
return
- workers = [Worker(url, result_queue, br, log, i, self) for i, url in
+ workers = [Worker(url, result_queue, br, log, i, domain, self) for i, url in
enumerate(matches)]
for w in workers:
From 1395c6d5d814349102d23d9cdfb26af8689b4bb0 Mon Sep 17 00:00:00 2001
From: Kovid Goyal
Date: Tue, 24 May 2011 15:48:27 -0600
Subject: [PATCH 48/51] EPUB Output: Change any white-space:pre declarations in
the CSS to pre-wrap to accomodate readers that cannot scroll horizontally.
Fixes #786722 (chm to epub conversion fails to reflow text in
tag)
---
src/calibre/ebooks/epub/output.py | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/calibre/ebooks/epub/output.py b/src/calibre/ebooks/epub/output.py
index 0ed6d7e222..bea90eeba8 100644
--- a/src/calibre/ebooks/epub/output.py
+++ b/src/calibre/ebooks/epub/output.py
@@ -413,6 +413,13 @@ class EPUBOutput(OutputFormatPlugin):
rule.style.removeProperty('margin-left')
# padding-left breaks rendering in webkit and gecko
rule.style.removeProperty('padding-left')
+ # Change whitespace:pre to pre-line to accommodate readers that
+ # cannot scroll horizontally
+ for rule in stylesheet.data.cssRules.rulesOfType(CSSRule.STYLE_RULE):
+ style = rule.style
+ ws = style.getPropertyValue('white-space')
+ if ws == 'pre':
+ style.setProperty('white-space', 'pre-wrap')
# }}}
From 50c80a8505c395c43904d0139dbaf908628c7298 Mon Sep 17 00:00:00 2001
From: John Schember
Date: Tue, 24 May 2011 19:34:04 -0400
Subject: [PATCH 49/51] Store: Fix some bugs. Add basic store chooser which
give information and allows enabling and disabling store plugins in a user
friendly manner.
---
src/calibre/customize/builtins.py | 4 +-
src/calibre/gui2/actions/store.py | 7 +
src/calibre/gui2/store/config/chooser.py | 18 +
.../gui2/store/config/chooser/__init__.py | 0
.../config/chooser/adv_search_builder.py | 131 ++++++
.../config/chooser/adv_search_builder.ui | 416 ++++++++++++++++++
.../store/config/chooser/chooser_dialog.py | 28 ++
.../store/config/chooser/chooser_widget.py | 35 ++
.../store/config/chooser/chooser_widget.ui | 87 ++++
.../gui2/store/config/chooser/models.py | 244 ++++++++++
.../gui2/store/config/chooser/results_view.py | 31 ++
.../gui2/store/config/search/__init__.py | 0
.../config/{ => search}/search_widget.py | 2 +-
.../config/{ => search}/search_widget.ui | 0
src/calibre/gui2/store/config/store.py | 2 +-
src/calibre/gui2/store/mobileread/models.py | 1 +
.../gui2/store/search/adv_search_builder.py | 2 +-
src/calibre/gui2/store/search/search.py | 2 +-
src/calibre/gui2/store/search/search.ui | 7 +-
19 files changed, 1009 insertions(+), 8 deletions(-)
create mode 100644 src/calibre/gui2/store/config/chooser.py
create mode 100644 src/calibre/gui2/store/config/chooser/__init__.py
create mode 100644 src/calibre/gui2/store/config/chooser/adv_search_builder.py
create mode 100644 src/calibre/gui2/store/config/chooser/adv_search_builder.ui
create mode 100644 src/calibre/gui2/store/config/chooser/chooser_dialog.py
create mode 100644 src/calibre/gui2/store/config/chooser/chooser_widget.py
create mode 100644 src/calibre/gui2/store/config/chooser/chooser_widget.ui
create mode 100644 src/calibre/gui2/store/config/chooser/models.py
create mode 100644 src/calibre/gui2/store/config/chooser/results_view.py
create mode 100644 src/calibre/gui2/store/config/search/__init__.py
rename src/calibre/gui2/store/config/{ => search}/search_widget.py (96%)
rename src/calibre/gui2/store/config/{ => search}/search_widget.ui (100%)
diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py
index d9e8be00b5..5c90e5699b 100644
--- a/src/calibre/customize/builtins.py
+++ b/src/calibre/customize/builtins.py
@@ -1316,7 +1316,7 @@ class StoreOpenLibraryStore(StoreBase):
actual_plugin = 'calibre.gui2.store.open_library_plugin:OpenLibraryStore'
drm_free_only = True
- headquarters = ['US']
+ headquarters = 'US'
formats = ['DAISY', 'DJVU', 'EPUB', 'MOBI', 'PDF', 'TXT']
class StoreOReillyStore(StoreBase):
@@ -1381,7 +1381,7 @@ class StoreWoblinkStore(StoreBase):
actual_plugin = 'calibre.gui2.store.woblink_plugin:WoblinkStore'
drm_free_only = False
- location = 'PL'
+ headquarters = 'PL'
formats = ['EPUB']
plugins += [
diff --git a/src/calibre/gui2/actions/store.py b/src/calibre/gui2/actions/store.py
index c8507e851c..effe470359 100644
--- a/src/calibre/gui2/actions/store.py
+++ b/src/calibre/gui2/actions/store.py
@@ -34,6 +34,8 @@ class StoreAction(InterfaceAction):
self.store_list_menu = self.store_menu.addMenu(_('Stores'))
for n, p in sorted(self.gui.istores.items(), key=lambda x: x[0].lower()):
self.store_list_menu.addAction(n, partial(self.open_store, p))
+ self.store_menu.addSeparator()
+ self.store_menu.addAction(_('Choose stores'), self.choose)
self.qaction.setMenu(self.store_menu)
def do_search(self):
@@ -107,6 +109,11 @@ class StoreAction(InterfaceAction):
query = 'author:"%s" title:"%s"' % (self._get_author(row), self._get_title(row))
self.search(query)
+ def choose(self):
+ from calibre.gui2.store.config.chooser.chooser_dialog import StoreChooserDialog
+ d = StoreChooserDialog(self.gui)
+ d.exec_()
+
def open_store(self, store_plugin):
self.show_disclaimer()
store_plugin.open(self.gui)
diff --git a/src/calibre/gui2/store/config/chooser.py b/src/calibre/gui2/store/config/chooser.py
new file mode 100644
index 0000000000..f5c40a18ae
--- /dev/null
+++ b/src/calibre/gui2/store/config/chooser.py
@@ -0,0 +1,18 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+
+__license__ = 'GPL 3'
+__copyright__ = '2011, John Schember '
+__docformat__ = 'restructuredtext en'
+
+'''
+Config widget access functions for enabling and disabling stores.
+'''
+
+def config_widget():
+ from calibre.gui2.store.config.chooser.chooser_widget import StoreChooserWidget
+ return StoreChooserWidget()
+
+def save_settings(config_widget):
+ pass
diff --git a/src/calibre/gui2/store/config/chooser/__init__.py b/src/calibre/gui2/store/config/chooser/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/src/calibre/gui2/store/config/chooser/adv_search_builder.py b/src/calibre/gui2/store/config/chooser/adv_search_builder.py
new file mode 100644
index 0000000000..7b519abcd1
--- /dev/null
+++ b/src/calibre/gui2/store/config/chooser/adv_search_builder.py
@@ -0,0 +1,131 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+
+__license__ = 'GPL 3'
+__copyright__ = '2011, John Schember '
+__docformat__ = 'restructuredtext en'
+
+import re
+
+from PyQt4.Qt import (QDialog, QDialogButtonBox)
+
+from calibre.gui2.store.config.chooser.adv_search_builder_ui import Ui_Dialog
+from calibre.library.caches import CONTAINS_MATCH, EQUALS_MATCH
+
+class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
+
+ def __init__(self, parent):
+ QDialog.__init__(self, parent)
+ self.setupUi(self)
+
+ self.buttonBox.accepted.connect(self.advanced_search_button_pushed)
+ self.tab_2_button_box.accepted.connect(self.accept)
+ self.tab_2_button_box.rejected.connect(self.reject)
+ self.clear_button.clicked.connect(self.clear_button_pushed)
+ self.adv_search_used = False
+ self.mc = ''
+
+ self.tabWidget.setCurrentIndex(0)
+ self.tabWidget.currentChanged[int].connect(self.tab_changed)
+ self.tab_changed(0)
+
+ def tab_changed(self, idx):
+ if idx == 1:
+ self.tab_2_button_box.button(QDialogButtonBox.Ok).setDefault(True)
+ else:
+ self.buttonBox.button(QDialogButtonBox.Ok).setDefault(True)
+
+ def advanced_search_button_pushed(self):
+ self.adv_search_used = True
+ self.accept()
+
+ def clear_button_pushed(self):
+ self.name_box.setText('')
+ self.description_box.setText('')
+ self.headquarters_box.setText('')
+ self.format_box.setText('')
+ self.enabled_combo.setIndex(0)
+ self.drm_combo.setIndex(0)
+
+ def tokens(self, raw):
+ phrases = re.findall(r'\s*".*?"\s*', raw)
+ for f in phrases:
+ raw = raw.replace(f, ' ')
+ phrases = [t.strip('" ') for t in phrases]
+ return ['"' + self.mc + t + '"' for t in phrases + [r.strip() for r in raw.split()]]
+
+ def search_string(self):
+ if self.adv_search_used:
+ return self.adv_search_string()
+ else:
+ return self.box_search_string()
+
+ def adv_search_string(self):
+ mk = self.matchkind.currentIndex()
+ if mk == CONTAINS_MATCH:
+ self.mc = ''
+ elif mk == EQUALS_MATCH:
+ self.mc = '='
+ else:
+ self.mc = '~'
+ all, any, phrase, none = map(lambda x: unicode(x.text()),
+ (self.all, self.any, self.phrase, self.none))
+ all, any, none = map(self.tokens, (all, any, none))
+ phrase = phrase.strip()
+ all = ' and '.join(all)
+ any = ' or '.join(any)
+ none = ' and not '.join(none)
+ ans = ''
+ if phrase:
+ ans += '"%s"'%phrase
+ if all:
+ ans += (' and ' if ans else '') + all
+ if none:
+ ans += (' and not ' if ans else 'not ') + none
+ if any:
+ ans += (' or ' if ans else '') + any
+ return ans
+
+ def token(self):
+ txt = unicode(self.text.text()).strip()
+ if txt:
+ if self.negate.isChecked():
+ txt = '!'+txt
+ tok = self.FIELDS[unicode(self.field.currentText())]+txt
+ if re.search(r'\s', tok):
+ tok = '"%s"'%tok
+ return tok
+
+ def box_search_string(self):
+ mk = self.matchkind.currentIndex()
+ if mk == CONTAINS_MATCH:
+ self.mc = ''
+ elif mk == EQUALS_MATCH:
+ self.mc = '='
+ else:
+ self.mc = '~'
+
+ ans = []
+ self.box_last_values = {}
+ name = unicode(self.name_box.text()).strip()
+ if name:
+ ans.append('name:"' + self.mc + name + '"')
+ description = unicode(self.description_box.text()).strip()
+ if description:
+ ans.append('description:"' + self.mc + description + '"')
+ headquarters = unicode(self.headquarters_box.text()).strip()
+ if headquarters:
+ ans.append('headquarters:"' + self.mc + headquarters + '"')
+ format = unicode(self.format_box.text()).strip()
+ if format:
+ ans.append('format:"' + self.mc + format + '"')
+ enabled = unicode(self.enabled_combo.currentText()).strip()
+ if enabled:
+ ans.append('enabled:' + enabled)
+ drm = unicode(self.drm_combo.currentText()).strip()
+ if drm:
+ ans.append('drm:' + drm)
+ if ans:
+ return ' and '.join(ans)
+ return ''
diff --git a/src/calibre/gui2/store/config/chooser/adv_search_builder.ui b/src/calibre/gui2/store/config/chooser/adv_search_builder.ui
new file mode 100644
index 0000000000..7d57321c72
--- /dev/null
+++ b/src/calibre/gui2/store/config/chooser/adv_search_builder.ui
@@ -0,0 +1,416 @@
+
+
+ Dialog
+
+
+
+ 0
+ 0
+ 752
+ 472
+
+
+
+ Advanced Search
+
+
+
+ :/images/search.png:/images/search.png
+
+
+ -
+
+
+ &What kind of match to use:
+
+
+ matchkind
+
+
+
+ -
+
+
-
+
+ Contains: the word or phrase matches anywhere in the metadata field
+
+
+ -
+
+ Equals: the word or phrase must match the entire metadata field
+
+
+ -
+
+ Regular expression: the expression must match anywhere in the metadata field
+
+
+
+
+ -
+
+
+ 0
+
+
+
+ A&dvanced Search
+
+
+
-
+
+
+ Find entries that have...
+
+
+
-
+
+
-
+
+
+ &All these words:
+
+
+ all
+
+
+
+ -
+
+
+
+
+ -
+
+
-
+
+
+ This exact &phrase:
+
+
+ all
+
+
+
+ -
+
+
+
+
+ -
+
+
-
+
+
+ &One or more of these words:
+
+
+ all
+
+
+
+ -
+
+
+
+
+
+
+
+ -
+
+
+ But dont show entries that have...
+
+
+
-
+
+
-
+
+
+ Any of these &unwanted words:
+
+
+ all
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+ 16777215
+ 30
+
+
+
+ See the <a href="http://calibre-ebook.com/user_manual/gui.html#the-search-interface">User Manual</a> for more help
+
+
+ true
+
+
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+
+
+
+
+ Nam&e/Description ...
+
+
+ -
+
+
+ &Name:
+
+
+ name_box
+
+
+
+ -
+
+
+ Enter the title.
+
+
+
+ -
+
+
+ &Description:
+
+
+ description_box
+
+
+
+ -
+
+
+ &Headquarters:
+
+
+ headquarters_box
+
+
+
+ -
+
+
-
+
+
+ &Clear
+
+
+
+ -
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+ -
+
+
+ Search only in specific fields:
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ &Format:
+
+
+ format_box
+
+
+
+ -
+
+
+ -
+
+
+ Enabled:
+
+
+
+ -
+
+
+ DRM:
+
+
+
+ -
+
+
-
+
+
+
+
+ -
+
+ true
+
+
+ -
+
+ false
+
+
+
+
+ -
+
+
-
+
+
+
+
+ -
+
+ true
+
+
+ -
+
+ false
+
+
+
+
+
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+
+
+
+ EnLineEdit
+ QLineEdit
+
+
+
+
+ all
+ phrase
+ any
+ none
+ buttonBox
+ name_box
+ description_box
+ headquarters_box
+ format_box
+ clear_button
+ tab_2_button_box
+ tabWidget
+ matchkind
+
+
+
+
+
+
+ buttonBox
+ accepted()
+ Dialog
+ accept()
+
+
+ 248
+ 254
+
+
+ 157
+ 274
+
+
+
+
+ buttonBox
+ rejected()
+ Dialog
+ reject()
+
+
+ 316
+ 260
+
+
+ 286
+ 274
+
+
+
+
+
diff --git a/src/calibre/gui2/store/config/chooser/chooser_dialog.py b/src/calibre/gui2/store/config/chooser/chooser_dialog.py
new file mode 100644
index 0000000000..c94796dc11
--- /dev/null
+++ b/src/calibre/gui2/store/config/chooser/chooser_dialog.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+
+__license__ = 'GPL 3'
+__copyright__ = '2011, John Schember '
+__docformat__ = 'restructuredtext en'
+
+from PyQt4.Qt import (QDialog, QDialogButtonBox, QVBoxLayout)
+
+from calibre.gui2.store.config.chooser.chooser_widget import StoreChooserWidget
+
+class StoreChooserDialog(QDialog):
+
+ def __init__(self, parent):
+ QDialog.__init__(self, parent)
+
+ self.setWindowTitle(_('Choose stores'))
+
+ button_box = QDialogButtonBox(QDialogButtonBox.Close)
+ button_box.accepted.connect(self.accept)
+ button_box.rejected.connect(self.reject)
+ v = QVBoxLayout(self)
+ self.config_widget = StoreChooserWidget()
+ v.addWidget(self.config_widget)
+ v.addWidget(button_box)
+
+ self.resize(800, 600)
diff --git a/src/calibre/gui2/store/config/chooser/chooser_widget.py b/src/calibre/gui2/store/config/chooser/chooser_widget.py
new file mode 100644
index 0000000000..93630d69a7
--- /dev/null
+++ b/src/calibre/gui2/store/config/chooser/chooser_widget.py
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+
+__license__ = 'GPL 3'
+__copyright__ = '2011, John Schember '
+__docformat__ = 'restructuredtext en'
+
+from PyQt4.Qt import (QWidget, QIcon, QDialog)
+
+from calibre.gui2.store.config.chooser.adv_search_builder import AdvSearchBuilderDialog
+from calibre.gui2.store.config.chooser.chooser_widget_ui import Ui_Form
+
+class StoreChooserWidget(QWidget, Ui_Form):
+
+ def __init__(self):
+ QWidget.__init__(self)
+ self.setupUi(self)
+
+ self.adv_search_builder.setIcon(QIcon(I('search.png')))
+
+ self.search.clicked.connect(self.do_search)
+ self.adv_search_builder.clicked.connect(self.build_adv_search)
+ self.results_view.activated.connect(self.toggle_plugin)
+
+ def do_search(self):
+ self.results_view.model().search(unicode(self.query.text()))
+
+ def toggle_plugin(self, index):
+ self.results_view.model().toggle_plugin(index)
+
+ def build_adv_search(self):
+ adv = AdvSearchBuilderDialog(self)
+ if adv.exec_() == QDialog.Accepted:
+ self.query.setText(adv.search_string())
diff --git a/src/calibre/gui2/store/config/chooser/chooser_widget.ui b/src/calibre/gui2/store/config/chooser/chooser_widget.ui
new file mode 100644
index 0000000000..69117406b1
--- /dev/null
+++ b/src/calibre/gui2/store/config/chooser/chooser_widget.ui
@@ -0,0 +1,87 @@
+
+
+ Form
+
+
+
+ 0
+ 0
+ 610
+ 553
+
+
+
+ Form
+
+
+ -
+
+
-
+
+
+ Query:
+
+
+
+ -
+
+
+ ...
+
+
+
+ -
+
+
+ -
+
+
+ Search
+
+
+
+
+
+ -
+
+
+ true
+
+
+ QAbstractItemView::SingleSelection
+
+
+ QAbstractItemView::SelectRows
+
+
+ false
+
+
+ true
+
+
+ false
+
+
+ true
+
+
+ false
+
+
+ false
+
+
+
+
+
+
+
+ ResultsView
+ QTreeView
+
+
+
+
+
+
diff --git a/src/calibre/gui2/store/config/chooser/models.py b/src/calibre/gui2/store/config/chooser/models.py
new file mode 100644
index 0000000000..460b698878
--- /dev/null
+++ b/src/calibre/gui2/store/config/chooser/models.py
@@ -0,0 +1,244 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+
+__license__ = 'GPL 3'
+__copyright__ = '2011, John Schember '
+__docformat__ = 'restructuredtext en'
+
+from PyQt4.Qt import (Qt, QAbstractItemModel, QIcon, QVariant, QModelIndex)
+
+from calibre.gui2 import NONE
+from calibre.customize.ui import is_disabled, disable_plugin, enable_plugin
+from calibre.library.caches import _match, CONTAINS_MATCH, EQUALS_MATCH, \
+ REGEXP_MATCH
+from calibre.utils.icu import sort_key
+from calibre.utils.search_query_parser import SearchQueryParser
+
+
+class Matches(QAbstractItemModel):
+
+ HEADERS = [_('Enabled'), _('Name'), _('No DRM'), _('Headquarters'), _('Formats')]
+ HTML_COLS = [1]
+
+ def __init__(self, plugins):
+ QAbstractItemModel.__init__(self)
+
+ self.NO_DRM_ICON = QIcon(I('ok.png'))
+
+ self.all_matches = plugins
+ self.matches = plugins
+ self.filter = ''
+ self.search_filter = SearchFilter(self.all_matches)
+
+ self.sort_col = 1
+ self.sort_order = Qt.AscendingOrder
+
+ def get_plugin(self, index):
+ row = index.row()
+ if row < len(self.matches):
+ return self.matches[row]
+ else:
+ return None
+
+ def search(self, filter):
+ self.filter = filter.strip()
+ if not self.filter:
+ self.matches = self.all_matches
+ else:
+ try:
+ self.matches = list(self.search_filter.parse(self.filter))
+ except:
+ self.matches = self.all_matches
+ self.layoutChanged.emit()
+ self.sort(self.sort_col, self.sort_order)
+
+ def toggle_plugin(self, index):
+ new_index = self.createIndex(index.row(), 0)
+ data = QVariant(is_disabled(self.get_plugin(index)))
+ self.setData(new_index, data, Qt.CheckStateRole)
+
+ def index(self, row, column, parent=QModelIndex()):
+ return self.createIndex(row, column)
+
+ def parent(self, index):
+ if not index.isValid() or index.internalId() == 0:
+ return QModelIndex()
+ return self.createIndex(0, 0)
+
+ def rowCount(self, *args):
+ return len(self.matches)
+
+ def columnCount(self, *args):
+ return len(self.HEADERS)
+
+ def headerData(self, section, orientation, role):
+ if role != Qt.DisplayRole:
+ return NONE
+ text = ''
+ if orientation == Qt.Horizontal:
+ if section < len(self.HEADERS):
+ text = self.HEADERS[section]
+ return QVariant(text)
+ else:
+ return QVariant(section+1)
+
+ def data(self, index, role):
+ row, col = index.row(), index.column()
+ result = self.matches[row]
+ if role in (Qt.DisplayRole, Qt.EditRole):
+ if col == 1:
+ return QVariant('%s
%s' % (result.name, result.description))
+ elif col == 3:
+ return QVariant(result.headquarters)
+ elif col == 4:
+ return QVariant(', '.join(result.formats).upper())
+ elif role == Qt.DecorationRole:
+ if col == 2:
+ if result.drm_free_only:
+ return QVariant(self.NO_DRM_ICON)
+ elif role == Qt.CheckStateRole:
+ if col == 0:
+ if is_disabled(result):
+ return Qt.Unchecked
+ return Qt.Checked
+ elif role == Qt.ToolTipRole:
+ return QVariant('%s
' % result.description)
+ return NONE
+
+ def setData(self, index, data, role):
+ if not index.isValid():
+ return False
+ row, col = index.row(), index.column()
+ if col == 0:
+ if data.toBool():
+ enable_plugin(self.get_plugin(index))
+ else:
+ disable_plugin(self.get_plugin(index))
+ self.dataChanged.emit(self.index(index.row(), 0), self.index(index.row(), self.columnCount() - 1))
+ return True
+
+ def flags(self, index):
+ if index.column() == 0:
+ return QAbstractItemModel.flags(self, index) | Qt.ItemIsUserCheckable
+ return QAbstractItemModel.flags(self, index)
+
+ def data_as_text(self, match, col):
+ text = ''
+ if col == 0:
+ text = 'b' if is_disabled(match) else 'a'
+ elif col == 1:
+ text = match.name
+ elif col == 2:
+ text = 'b' if match.drm else 'a'
+ elif col == 3:
+ text = match.headquarteres
+ return text
+
+ def sort(self, col, order, reset=True):
+ self.sort_col = col
+ self.sort_order = order
+ if not self.matches:
+ return
+ descending = order == Qt.DescendingOrder
+ self.matches.sort(None,
+ lambda x: sort_key(unicode(self.data_as_text(x, col))),
+ descending)
+ if reset:
+ self.reset()
+
+
+class SearchFilter(SearchQueryParser):
+
+ USABLE_LOCATIONS = [
+ 'all',
+ 'description',
+ 'drm',
+ 'enabled',
+ 'format',
+ 'formats',
+ 'headquarters',
+ 'name',
+ ]
+
+ def __init__(self, all_plugins=[]):
+ SearchQueryParser.__init__(self, locations=self.USABLE_LOCATIONS)
+ self.srs = set(all_plugins)
+
+ def universal_set(self):
+ return self.srs
+
+ def get_matches(self, location, query):
+ location = location.lower().strip()
+ if location == 'formats':
+ location = 'format'
+
+ matchkind = CONTAINS_MATCH
+ if len(query) > 1:
+ if query.startswith('\\'):
+ query = query[1:]
+ elif query.startswith('='):
+ matchkind = EQUALS_MATCH
+ query = query[1:]
+ elif query.startswith('~'):
+ matchkind = REGEXP_MATCH
+ query = query[1:]
+ if matchkind != REGEXP_MATCH: ### leave case in regexps because it can be significant e.g. \S \W \D
+ query = query.lower()
+
+ if location not in self.USABLE_LOCATIONS:
+ return set([])
+ matches = set([])
+ all_locs = set(self.USABLE_LOCATIONS) - set(['all'])
+ locations = all_locs if location == 'all' else [location]
+ q = {
+ 'description': lambda x: x.description.lower(),
+ 'drm': lambda x: not x.drm_free_only,
+ 'enabled': lambda x: not is_disabled(x),
+ 'format': lambda x: ','.join(x.formats).lower(),
+ 'headquarters': lambda x: x.headquarters.lower(),
+ 'name': lambda x : x.name.lower(),
+ }
+ q['formats'] = q['format']
+ for sr in self.srs:
+ for locvalue in locations:
+ accessor = q[locvalue]
+ if query == 'true':
+ if locvalue in ('drm', 'enabled'):
+ if accessor(sr) == True:
+ matches.add(sr)
+ elif accessor(sr) is not None:
+ matches.add(sr)
+ continue
+ if query == 'false':
+ if locvalue in ('drm', 'enabled'):
+ if accessor(sr) == False:
+ matches.add(sr)
+ elif accessor(sr) is None:
+ matches.add(sr)
+ continue
+ # this is bool, so can't match below
+ if locvalue in ('drm', 'enabled'):
+ continue
+ try:
+ ### Can't separate authors because comma is used for name sep and author sep
+ ### Exact match might not get what you want. For that reason, turn author
+ ### exactmatch searches into contains searches.
+ if locvalue == 'name' and matchkind == EQUALS_MATCH:
+ m = CONTAINS_MATCH
+ else:
+ m = matchkind
+
+ if locvalue == 'format':
+ vals = accessor(sr).split(',')
+ else:
+ vals = [accessor(sr)]
+ if _match(query, vals, m):
+ matches.add(sr)
+ break
+ except ValueError: # Unicode errors
+ import traceback
+ traceback.print_exc()
+ return matches
+
+
\ No newline at end of file
diff --git a/src/calibre/gui2/store/config/chooser/results_view.py b/src/calibre/gui2/store/config/chooser/results_view.py
new file mode 100644
index 0000000000..52d7696e4f
--- /dev/null
+++ b/src/calibre/gui2/store/config/chooser/results_view.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+
+__license__ = 'GPL 3'
+__copyright__ = '2011, John Schember '
+__docformat__ = 'restructuredtext en'
+
+from PyQt4.Qt import (QTreeView, QSize)
+
+from calibre.customize.ui import store_plugins
+from calibre.gui2.metadata.single_download import RichTextDelegate
+from calibre.gui2.store.config.chooser.models import Matches
+
+class ResultsView(QTreeView):
+
+ def __init__(self, *args):
+ QTreeView.__init__(self,*args)
+
+ self._model = Matches([p for p in store_plugins()])
+ self.setModel(self._model)
+
+ self.setIconSize(QSize(24, 24))
+
+ self.rt_delegate = RichTextDelegate(self)
+
+ for i in self._model.HTML_COLS:
+ self.setItemDelegateForColumn(i, self.rt_delegate)
+
+ for i in xrange(self._model.columnCount()):
+ self.resizeColumnToContents(i)
diff --git a/src/calibre/gui2/store/config/search/__init__.py b/src/calibre/gui2/store/config/search/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/src/calibre/gui2/store/config/search_widget.py b/src/calibre/gui2/store/config/search/search_widget.py
similarity index 96%
rename from src/calibre/gui2/store/config/search_widget.py
rename to src/calibre/gui2/store/config/search/search_widget.py
index 43e911a432..b2e55d2ad1 100644
--- a/src/calibre/gui2/store/config/search_widget.py
+++ b/src/calibre/gui2/store/config/search/search_widget.py
@@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
from PyQt4.Qt import QWidget
from calibre.gui2 import JSONConfig
-from calibre.gui2.store.config.search_widget_ui import Ui_Form
+from calibre.gui2.store.config.search.search_widget_ui import Ui_Form
class StoreConfigWidget(QWidget, Ui_Form):
diff --git a/src/calibre/gui2/store/config/search_widget.ui b/src/calibre/gui2/store/config/search/search_widget.ui
similarity index 100%
rename from src/calibre/gui2/store/config/search_widget.ui
rename to src/calibre/gui2/store/config/search/search_widget.ui
diff --git a/src/calibre/gui2/store/config/store.py b/src/calibre/gui2/store/config/store.py
index ddc24870bd..852f602d08 100644
--- a/src/calibre/gui2/store/config/store.py
+++ b/src/calibre/gui2/store/config/store.py
@@ -11,7 +11,7 @@ Config widget access functions for configuring the store action.
'''
def config_widget():
- from calibre.gui2.store.config.search_widget import StoreConfigWidget
+ from calibre.gui2.store.config.search.search_widget import StoreConfigWidget
return StoreConfigWidget()
def save_settings(config_widget):
diff --git a/src/calibre/gui2/store/mobileread/models.py b/src/calibre/gui2/store/mobileread/models.py
index a080affb51..297707e248 100644
--- a/src/calibre/gui2/store/mobileread/models.py
+++ b/src/calibre/gui2/store/mobileread/models.py
@@ -47,6 +47,7 @@ class BooksModel(QAbstractItemModel):
self.books = list(self.search_filter.parse(self.filter))
except:
self.books = self.all_books
+ self.layoutChanged.emit()
self.sort(self.sort_col, self.sort_order)
self.total_changed.emit(self.rowCount())
diff --git a/src/calibre/gui2/store/search/adv_search_builder.py b/src/calibre/gui2/store/search/adv_search_builder.py
index 50d4d3f3f4..745e709f90 100644
--- a/src/calibre/gui2/store/search/adv_search_builder.py
+++ b/src/calibre/gui2/store/search/adv_search_builder.py
@@ -116,7 +116,7 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
if price:
ans.append('price:"' + self.mc + price + '"')
format = unicode(self.format_box.text()).strip()
- if author:
+ if format:
ans.append('format:"' + self.mc + format + '"')
if ans:
return ' and '.join(ans)
diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py
index c7c252034d..ffc6ec097e 100644
--- a/src/calibre/gui2/store/search/search.py
+++ b/src/calibre/gui2/store/search/search.py
@@ -14,7 +14,7 @@ from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QTimer, QCheckBox,
from calibre.gui2 import JSONConfig, info_dialog
from calibre.gui2.progress_indicator import ProgressIndicator
-from calibre.gui2.store.config.search_widget import StoreConfigWidget
+from calibre.gui2.store.config.search.search_widget import StoreConfigWidget
from calibre.gui2.store.search.adv_search_builder import AdvSearchBuilderDialog
from calibre.gui2.store.search.download_thread import SearchThreadPool, \
CacheUpdateThreadPool
diff --git a/src/calibre/gui2/store/search/search.ui b/src/calibre/gui2/store/search/search.ui
index 0360fa5f98..1451aa09f1 100644
--- a/src/calibre/gui2/store/search/search.ui
+++ b/src/calibre/gui2/store/search/search.ui
@@ -82,8 +82,8 @@
0
0
- 102
- 129
+ 125
+ 127
@@ -159,6 +159,9 @@
false
+
+ false
+
-
From b871315864d5e39a9f9e768b37d5268387decf73 Mon Sep 17 00:00:00 2001
From: John Schember
Date: Tue, 24 May 2011 19:45:20 -0400
Subject: [PATCH 50/51] Store: Chooser, set sort and sort indicator.
---
src/calibre/gui2/store/config/chooser/results_view.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/calibre/gui2/store/config/chooser/results_view.py b/src/calibre/gui2/store/config/chooser/results_view.py
index 52d7696e4f..1c18a18d7b 100644
--- a/src/calibre/gui2/store/config/chooser/results_view.py
+++ b/src/calibre/gui2/store/config/chooser/results_view.py
@@ -6,7 +6,7 @@ __license__ = 'GPL 3'
__copyright__ = '2011, John Schember '
__docformat__ = 'restructuredtext en'
-from PyQt4.Qt import (QTreeView, QSize)
+from PyQt4.Qt import (Qt, QTreeView, QSize)
from calibre.customize.ui import store_plugins
from calibre.gui2.metadata.single_download import RichTextDelegate
@@ -29,3 +29,6 @@ class ResultsView(QTreeView):
for i in xrange(self._model.columnCount()):
self.resizeColumnToContents(i)
+
+ self.model().sort(1, Qt.AscendingOrder)
+ self.header().setSortIndicator(self.model().sort_col, self.model().sort_order)
From 41cc4be9528bfd8835e1f0b67bc6aff494d579f1 Mon Sep 17 00:00:00 2001
From: John Schember
Date: Wed, 25 May 2011 06:55:52 -0400
Subject: [PATCH 51/51] Store: Reload store plugins accessible by GUI after
using the store chooser.
---
src/calibre/gui2/actions/store.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/calibre/gui2/actions/store.py b/src/calibre/gui2/actions/store.py
index effe470359..0fd783f0a3 100644
--- a/src/calibre/gui2/actions/store.py
+++ b/src/calibre/gui2/actions/store.py
@@ -113,6 +113,8 @@ class StoreAction(InterfaceAction):
from calibre.gui2.store.config.chooser.chooser_dialog import StoreChooserDialog
d = StoreChooserDialog(self.gui)
d.exec_()
+ self.gui.load_store_plugins()
+ self.load_menu()
def open_store(self, store_plugin):
self.show_disclaimer()