Skip to content

Commit

Permalink
Use info dialog to display per-album error log.
Browse files Browse the repository at this point in the history
When an error occurs during loading of a release, it will be visible
in info dialog for this release (which was unused).

New icon was added to mark visually releases with errors, and scrollbars
will appear in info dialog if needed.
  • Loading branch information
zas committed Jul 2, 2013
1 parent 694b1d6 commit 258e9c2
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 113 deletions.
20 changes: 13 additions & 7 deletions picard/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self, id, discid=None):
self._discid = discid
self._after_load_callbacks = queue.Queue()
self.unmatched_files = Cluster(_("Unmatched Files"), special=True, related_album=self, hide_if_empty=True)
self.errors = []

def __repr__(self):
return '<Album %s %r>' % (self.id, self.metadata[u"album"])
Expand Down Expand Up @@ -132,7 +133,7 @@ def _parse_release(self, document):
try:
run_album_metadata_processors(self, m, release_node)
except:
log.error(traceback.format_exc())
self.error_append(traceback.format_exc())

self._release_node = release_node
return True
Expand All @@ -144,7 +145,7 @@ def _release_request_finished(self, document, http, error):
parsed = False
try:
if error:
log.error("%r", unicode(http.errorString()))
self.error_append(unicode(http.errorString()))
# Fix for broken NAT releases
if error == QtNetwork.QNetworkReply.ContentNotFoundError:
nats = False
Expand All @@ -164,12 +165,16 @@ def _release_request_finished(self, document, http, error):
parsed = self._parse_release(document)
except:
error = True
log.error(traceback.format_exc())
self.error_append(traceback.format_exc())
finally:
self._requests -= 1
if parsed or error:
self._finalize_loading(error)

def error_append(self, msg):
log.error(msg)
self.errors.append(msg)

def _finalize_loading(self, error):
if error:
self.metadata.clear()
Expand Down Expand Up @@ -216,7 +221,7 @@ def _finalize_loading(self, error):
try:
run_track_metadata_processors(self, tm, self._release_node, track_node)
except:
log.error(traceback.format_exc())
self.error_append(traceback.format_exc())

totalalbumtracks = str(totalalbumtracks)

Expand All @@ -239,14 +244,14 @@ def _finalize_loading(self, error):
try:
parser.eval(script, track.metadata)
except:
log.error(traceback.format_exc())
self.error_append(traceback.format_exc())
# Strip leading/trailing whitespace
track.metadata.strip_whitespace()
# Run tagger script for the album itself
try:
parser.eval(script, self._new_metadata)
except:
log.error(traceback.format_exc())
self.error_append(traceback.format_exc())
self._new_metadata.strip_whitespace()

for track in self.tracks:
Expand Down Expand Up @@ -280,6 +285,7 @@ def load(self):
self._new_metadata = Metadata()
self._new_tracks = []
self._requests = 1
self.errors = []
require_authentication = False
inc = ['release-groups', 'media', 'recordings', 'artist-credits',
'artists', 'aliases', 'labels', 'isrcs', 'collections']
Expand Down Expand Up @@ -391,7 +397,7 @@ def can_refresh(self):
return True

def can_view_info(self):
return bool(self.loaded and self.metadata and self.metadata.images)
return (self.loaded and self.metadata and self.metadata.images) or self.errors

def is_album_like(self):
return True
Expand Down
266 changes: 189 additions & 77 deletions picard/resources.py

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions picard/ui/infodialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import os.path
from PyQt4 import QtGui
from PyQt4 import QtGui, QtCore
from picard.util import format_time, encode_filename, bytes2human
from picard.ui.ui_infodialog import Ui_InfoDialog

Expand Down Expand Up @@ -102,7 +102,9 @@ def _display_info_tab(self):
else:
ch = str(ch)
info.append((_('Channels:'), ch))
text = '<br/>'.join(map(lambda i: '<b>%s</b><br/>%s' % i, info))
text = '<br/>'.join(map(lambda i: '<b>%s</b><br/>%s' %
(QtCore.Qt.escape(i[0]),
QtCore.Qt.escape(i[1])), info))
self.ui.info.setText(text)


Expand All @@ -114,4 +116,15 @@ def __init__(self, album, parent=None):

def _display_info_tab(self):
tab = self.ui.info_tab
self.tab_hide(tab)
album = self.obj
if album.errors:
text = '<br />'.join(map(lambda s: '<font color="darkred">%s</font>' %
'<br />'.join(unicode(QtCore.Qt.escape(s))
.replace('\t', ' ')
.replace(' ', '&nbsp;')
.splitlines()
), album.errors)
)
self.ui.info.setText(text + '<hr />')
else:
self.tab_hide(tab)
8 changes: 7 additions & 1 deletion picard/ui/itemviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def create_icons(self):
ClusterItem.icon_dir = icontheme.lookup('folder', icontheme.ICON_SIZE_MENU)
AlbumItem.icon_cd = icontheme.lookup('media-optical', icontheme.ICON_SIZE_MENU)
AlbumItem.icon_cd_saved = icontheme.lookup('media-optical-saved', icontheme.ICON_SIZE_MENU)
AlbumItem.icon_error = icontheme.lookup('media-optical-error', icontheme.ICON_SIZE_MENU)
TrackItem.icon_note = QtGui.QIcon(":/images/note.png")
FileItem.icon_file = QtGui.QIcon(":/images/file.png")
FileItem.icon_file_pending = QtGui.QIcon(":/images/file-pending.png")
Expand Down Expand Up @@ -635,7 +636,12 @@ def update(self, update_tracks=True):
self.insertChildren(oldnum, items)
for item in items: # Update after insertChildren so that setExpanded works
item.update(update_album=False)
self.setIcon(0, AlbumItem.icon_cd_saved if album.is_complete() else AlbumItem.icon_cd)
if album.errors:
self.setIcon(0, AlbumItem.icon_error)
elif album.is_complete():
self.setIcon(0, AlbumItem.icon_cd_saved)
else:
self.setIcon(0, AlbumItem.icon_cd)
for i, column in enumerate(MainPanel.columns):
self.setText(i, album.column(column[1]))
if self.isSelected():
Expand Down
37 changes: 24 additions & 13 deletions picard/ui/ui_infodialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# Form implementation generated from reading ui file 'ui/infodialog.ui'
#
# Created: Sat Oct 6 19:08:31 2012
# by: PyQt4 UI code generator 4.9.4
# Created: Sat Jun 15 12:58:18 2013
# by: PyQt4 UI code generator 4.9.3
#
# WARNING! All changes made in this file will be lost!

Expand All @@ -18,26 +18,37 @@ class Ui_InfoDialog(object):
def setupUi(self, InfoDialog):
InfoDialog.setObjectName(_fromUtf8("InfoDialog"))
InfoDialog.resize(535, 436)
self.vboxlayout = QtGui.QVBoxLayout(InfoDialog)
self.vboxlayout.setObjectName(_fromUtf8("vboxlayout"))
self.verticalLayout = QtGui.QVBoxLayout(InfoDialog)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.tabWidget = QtGui.QTabWidget(InfoDialog)
self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
self.info_tab = QtGui.QWidget()
self.info_tab.setObjectName(_fromUtf8("info_tab"))
self.vboxlayout1 = QtGui.QVBoxLayout(self.info_tab)
self.vboxlayout1.setObjectName(_fromUtf8("vboxlayout1"))
self.info = QtGui.QLabel(self.info_tab)
self.vboxlayout = QtGui.QVBoxLayout(self.info_tab)
self.vboxlayout.setObjectName(_fromUtf8("vboxlayout"))
self.info_scroll = QtGui.QScrollArea(self.info_tab)
self.info_scroll.setWidgetResizable(True)
self.info_scroll.setObjectName(_fromUtf8("info_scroll"))
self.scrollAreaWidgetContents = QtGui.QWidget()
self.scrollAreaWidgetContents.setEnabled(True)
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 493, 334))
self.scrollAreaWidgetContents.setObjectName(_fromUtf8("scrollAreaWidgetContents"))
self.verticalLayoutLabel = QtGui.QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayoutLabel.setObjectName(_fromUtf8("verticalLayoutLabel"))
self.info = QtGui.QLabel(self.scrollAreaWidgetContents)
self.info.setText(_fromUtf8(""))
self.info.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.info.setWordWrap(True)
self.info.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse|QtCore.Qt.TextSelectableByKeyboard|QtCore.Qt.TextSelectableByMouse)
self.info.setObjectName(_fromUtf8("info"))
self.vboxlayout1.addWidget(self.info)
self.verticalLayoutLabel.addWidget(self.info)
self.info_scroll.setWidget(self.scrollAreaWidgetContents)
self.vboxlayout.addWidget(self.info_scroll)
self.tabWidget.addTab(self.info_tab, _fromUtf8(""))
self.artwork_tab = QtGui.QWidget()
self.artwork_tab.setObjectName(_fromUtf8("artwork_tab"))
self.vboxlayout2 = QtGui.QVBoxLayout(self.artwork_tab)
self.vboxlayout2.setObjectName(_fromUtf8("vboxlayout2"))
self.vboxlayout1 = QtGui.QVBoxLayout(self.artwork_tab)
self.vboxlayout1.setObjectName(_fromUtf8("vboxlayout1"))
self.artwork_list = QtGui.QListWidget(self.artwork_tab)
self.artwork_list.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
self.artwork_list.setIconSize(QtCore.QSize(170, 170))
Expand All @@ -48,13 +59,13 @@ def setupUi(self, InfoDialog):
self.artwork_list.setSpacing(10)
self.artwork_list.setViewMode(QtGui.QListView.IconMode)
self.artwork_list.setObjectName(_fromUtf8("artwork_list"))
self.vboxlayout2.addWidget(self.artwork_list)
self.vboxlayout1.addWidget(self.artwork_list)
self.tabWidget.addTab(self.artwork_tab, _fromUtf8(""))
self.vboxlayout.addWidget(self.tabWidget)
self.verticalLayout.addWidget(self.tabWidget)
self.buttonBox = QtGui.QDialogButtonBox(InfoDialog)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.vboxlayout.addWidget(self.buttonBox)
self.verticalLayout.addWidget(self.buttonBox)

self.retranslateUi(InfoDialog)
self.tabWidget.setCurrentIndex(0)
Expand Down
Binary file added resources/images/16x16/media-optical-error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/22x22/media-optical-error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions resources/picard.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<file>images/16x16/edit-cut.png</file>
<file>images/16x16/edit-paste.png</file>
<file>images/16x16/folder.png</file>
<file>images/16x16/media-optical-error.png</file>
<file>images/16x16/media-optical-saved.png</file>
<file>images/16x16/media-optical.png</file>
<file>images/16x16/picard.png</file>
Expand All @@ -18,6 +19,7 @@
<file>images/22x22/folder.png</file>
<file>images/22x22/list-remove.png</file>
<file>images/22x22/lookup-musicbrainz.png</file>
<file>images/22x22/media-optical-error.png</file>
<file>images/22x22/media-optical-saved.png</file>
<file>images/22x22/media-optical.png</file>
<file>images/22x22/picard-analyze.png</file>
Expand Down
46 changes: 34 additions & 12 deletions ui/infodialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<height>436</height>
</rect>
</property>
<layout class="QVBoxLayout">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
Expand All @@ -22,19 +22,41 @@
</attribute>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="info">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<widget class="QScrollArea" name="info_scroll">
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>493</width>
<height>334</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayoutLabel">
<item>
<widget class="QLabel" name="info">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
Expand Down

0 comments on commit 258e9c2

Please sign in to comment.