Store: Make search dialog look better.

This commit is contained in:
John Schember 2011-04-22 08:18:47 -04:00
parent 4ff0747da0
commit f824581b5e
2 changed files with 34 additions and 49 deletions

View File

@ -16,7 +16,7 @@ from threading import Thread
from Queue import Queue from Queue import Queue
from PyQt4.Qt import (Qt, QAbstractItemModel, QDialog, QTimer, QVariant, from PyQt4.Qt import (Qt, QAbstractItemModel, QDialog, QTimer, QVariant,
QModelIndex, QPixmap, QSize, QCheckBox, QVBoxLayout) QModelIndex, QPixmap, QSize, QCheckBox, QVBoxLayout, QTreeView)
from calibre import browser from calibre import browser
from calibre.gui2 import NONE, JSONConfig from calibre.gui2 import NONE, JSONConfig
@ -57,9 +57,6 @@ class SearchDialog(QDialog, Ui_Dialog):
self.checker = QTimer() self.checker = QTimer()
self.hang_check = 0 self.hang_check = 0
self.model = Matches()
self.results_view.setModel(self.model)
# Add check boxes for each store so the user # Add check boxes for each store so the user
# can disable searching specific stores on a # can disable searching specific stores on a
# per search basis. # per search basis.
@ -74,7 +71,7 @@ class SearchDialog(QDialog, Ui_Dialog):
# Create and add the progress indicator # Create and add the progress indicator
self.pi = ProgressIndicator(self, 24) self.pi = ProgressIndicator(self, 24)
self.bottom_layout.insertWidget(0, self.pi) self.top_layout.addWidget(self.pi)
self.search.clicked.connect(self.do_search) self.search.clicked.connect(self.do_search)
self.checker.timeout.connect(self.get_results) self.checker.timeout.connect(self.get_results)
@ -91,18 +88,14 @@ class SearchDialog(QDialog, Ui_Dialog):
# Cover # Cover
self.results_view.setColumnWidth(0, 85) self.results_view.setColumnWidth(0, 85)
total = total - 85 total = total - 85
# Title # Title / Author
self.results_view.setColumnWidth(1,int(total*.35)) self.results_view.setColumnWidth(1,int(total*.40))
# Author
self.results_view.setColumnWidth(2,int(total*.35))
# Price # Price
self.results_view.setColumnWidth(3, int(total*.5)) self.results_view.setColumnWidth(2,int(total*.20))
# DRM # DRM
self.results_view.setColumnWidth(4, int(total*.5)) self.results_view.setColumnWidth(3, int(total*.15))
# Store # Store / Formats
self.results_view.setColumnWidth(5, int(total*.15)) self.results_view.setColumnWidth(4, int(total*.25))
# Formats
self.results_view.setColumnWidth(6, int(total*.5))
def do_search(self, checked=False): def do_search(self, checked=False):
# Stop all running threads. # Stop all running threads.
@ -165,7 +158,7 @@ class SearchDialog(QDialog, Ui_Dialog):
def save_state(self): def save_state(self):
self.config['store_search_geometry'] = bytearray(self.saveGeometry()) self.config['store_search_geometry'] = bytearray(self.saveGeometry())
self.config['store_search_store_splitter_state'] = bytearray(self.store_splitter.saveState()) self.config['store_search_store_splitter_state'] = bytearray(self.store_splitter.saveState())
self.config['store_search_results_view_column_width'] = [self.results_view.columnWidth(i) for i in range(self.model.columnCount())] self.config['store_search_results_view_column_width'] = [self.results_view.columnWidth(i) for i in range(self.results_view.model().columnCount())]
store_check = {} store_check = {}
for n in self.store_plugins: for n in self.store_plugins:
@ -184,7 +177,7 @@ class SearchDialog(QDialog, Ui_Dialog):
results_cwidth = self.config.get('store_search_results_view_column_width', None) results_cwidth = self.config.get('store_search_results_view_column_width', None)
if results_cwidth: if results_cwidth:
for i, x in enumerate(results_cwidth): for i, x in enumerate(results_cwidth):
if i >= self.model.columnCount(): if i >= self.results_view.model().columnCount():
break break
self.results_view.setColumnWidth(i, x) self.results_view.setColumnWidth(i, x)
else: else:
@ -243,7 +236,7 @@ class SearchDialog(QDialog, Ui_Dialog):
check.setChecked(False) check.setChecked(False)
def dialog_closed(self, result): def dialog_closed(self, result):
self.model.closing() self.results_view.model().closing()
self.search_pool.abort() self.search_pool.abort()
self.save_state() self.save_state()
@ -422,9 +415,11 @@ class DetailsThread(Thread):
except: except:
continue continue
class Matches(QAbstractItemModel): class Matches(QAbstractItemModel):
HEADERS = [_('Cover'), _('Title'), _('Author(s)'), _('Price'), _('DRM'), _('Store'), _('Formats')] HEADERS = [_('Cover'), _('Title'), _('Price'), _('DRM'), _('Store')]
HTML_COLS = (1, 4)
def __init__(self): def __init__(self):
QAbstractItemModel.__init__(self) QAbstractItemModel.__init__(self)
@ -539,22 +534,20 @@ class Matches(QAbstractItemModel):
result = self.matches[row] result = self.matches[row]
if role == Qt.DisplayRole: if role == Qt.DisplayRole:
if col == 1: if col == 1:
return QVariant(result.title) t = result.title if result.title else _('Unknown')
a = result.author if result.author else ''
return QVariant('<b>%s</b><br><i>%s</i>' % (t, a))
elif col == 2: elif col == 2:
return QVariant(result.author)
elif col == 3:
return QVariant(result.price) return QVariant(result.price)
elif col == 5: elif col == 4:
return QVariant(result.store_name) return QVariant('%s<br>%s' % (result.store_name, result.formats))
elif col == 6:
return QVariant(result.formats)
return NONE return NONE
elif role == Qt.DecorationRole: elif role == Qt.DecorationRole:
if col == 0 and result.cover_data: if col == 0 and result.cover_data:
p = QPixmap() p = QPixmap()
p.loadFromData(result.cover_data) p.loadFromData(result.cover_data)
return QVariant(p) return QVariant(p)
if col == 4: if col == 3:
if result.drm == SearchResult.DRM_LOCKED: if result.drm == SearchResult.DRM_LOCKED:
return QVariant(self.DRM_LOCKED_ICON) return QVariant(self.DRM_LOCKED_ICON)
elif result.drm == SearchResult.DRM_UNLOCKED: elif result.drm == SearchResult.DRM_UNLOCKED:
@ -565,19 +558,15 @@ class Matches(QAbstractItemModel):
if col == 1: if col == 1:
return QVariant('<p>%s</p>' % result.title) return QVariant('<p>%s</p>' % result.title)
elif col == 2: elif col == 2:
return QVariant('<p>%s</p>' % result.author)
elif col == 3:
return QVariant('<p>' + _('Detected price as: %s. Check with the store before making a purchase to verify this price is correct. This price often does not include promotions the store may be running.') % result.price + '</p>') return QVariant('<p>' + _('Detected price as: %s. Check with the store before making a purchase to verify this price is correct. This price often does not include promotions the store may be running.') % result.price + '</p>')
elif col == 4: elif col == 3:
if result.drm == SearchResult.DRM_LOCKED: if result.drm == SearchResult.DRM_LOCKED:
return QVariant('<p>' + _('This book as been detected as having DRM restrictions. This book may not work with your reader and you will have limitations placed upon you as to what you can do with this book. Check with the store before making any purchases to ensure you can actually read this book.') + '</p>') return QVariant('<p>' + _('This book as been detected as having DRM restrictions. This book may not work with your reader and you will have limitations placed upon you as to what you can do with this book. Check with the store before making any purchases to ensure you can actually read this book.') + '</p>')
elif result.drm == SearchResult.DRM_UNLOCKED: elif result.drm == SearchResult.DRM_UNLOCKED:
return QVariant('<p>' + _('This book has been detected as being DRM Free. You should be able to use this book on any device provided it is in a format calibre supports for conversion. However, before making a purchase double check the DRM status with the store. The store may not be disclosing the use of DRM.') + '</p>') return QVariant('<p>' + _('This book has been detected as being DRM Free. You should be able to use this book on any device provided it is in a format calibre supports for conversion. However, before making a purchase double check the DRM status with the store. The store may not be disclosing the use of DRM.') + '</p>')
else: else:
return QVariant('<p>' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '</p>') return QVariant('<p>' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '</p>')
elif col == 5: elif col == 4:
return QVariant('<p>%s</p>' % result.store_name)
elif col == 6:
return QVariant('<p>%s</p>' % result.formats) return QVariant('<p>%s</p>' % result.formats)
elif role == Qt.SizeHintRole: elif role == Qt.SizeHintRole:
return QSize(64, 64) return QSize(64, 64)
@ -588,20 +577,9 @@ class Matches(QAbstractItemModel):
if col == 1: if col == 1:
text = result.title text = result.title
elif col == 2: elif col == 2:
text = result.author
elif col == 3:
text = comparable_price(result.price) text = comparable_price(result.price)
elif col == 4: elif col == 4:
if result.drm == SearchResult.DRM_UNLOCKED:
text = 'a'
elif result.drm == SearchResult.DRM_LOCKED:
text = 'b'
else:
text = 'c'
elif col == 5:
text = result.store_name text = result.store_name
elif col == 6:
text = ', '.join(sorted(result.formats.split(',')))
return text return text
def sort(self, col, order, reset=True): def sort(self, col, order, reset=True):

View File

@ -14,7 +14,7 @@
<string>Get Books</string> <string>Get Books</string>
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset resource="../../../../resources/images.qrc"> <iconset>
<normaloff>:/images/store.png</normaloff>:/images/store.png</iconset> <normaloff>:/images/store.png</normaloff>:/images/store.png</iconset>
</property> </property>
<property name="sizeGripEnabled"> <property name="sizeGripEnabled">
@ -22,7 +22,7 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="top_layout">
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
@ -62,8 +62,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>170</width> <width>215</width>
<height>138</height> <height>116</height>
</rect> </rect>
</property> </property>
</widget> </widget>
@ -110,7 +110,7 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<widget class="QTreeView" name="results_view"> <widget class="ResultsView" name="results_view">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch> <horstretch>1</horstretch>
@ -178,6 +178,13 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>ResultsView</class>
<extends>QTreeView</extends>
<header>results_view.h</header>
</customwidget>
</customwidgets>
<resources> <resources>
<include location="../../../../resources/images.qrc"/> <include location="../../../../resources/images.qrc"/>
</resources> </resources>