openlp/openlp/core/ui/exceptionform.py

256 lines
10 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2012-12-29 09:35:24 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2012-12-29 20:56:56 +00:00
# Copyright (c) 2008-2013 Raoul Snyman #
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
2012-11-11 21:16:14 +00:00
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
2012-10-21 13:16:22 +00:00
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
2013-02-01 19:58:18 +00:00
"""
The actual exception dialog form.
"""
2010-12-21 19:39:35 +00:00
import logging
import re
import os
2010-12-11 00:26:41 +00:00
import platform
2010-12-11 00:26:41 +00:00
import sqlalchemy
import BeautifulSoup
from lxml import etree
2011-12-12 22:10:37 +00:00
from PyQt4 import Qt, QtCore, QtGui, QtWebKit
try:
from PyQt4.phonon import Phonon
PHONON_VERSION = Phonon.phononVersion()
except ImportError:
PHONON_VERSION = u'-'
try:
import migrate
MIGRATE_VERSION = getattr(migrate, u'__version__', u'< 0.7')
except ImportError:
MIGRATE_VERSION = u'-'
try:
import chardet
CHARDET_VERSION = chardet.__version__
except ImportError:
CHARDET_VERSION = u'-'
try:
import enchant
ENCHANT_VERSION = enchant.__version__
except ImportError:
ENCHANT_VERSION = u'-'
2010-12-11 00:26:41 +00:00
try:
import sqlite
SQLITE_VERSION = sqlite.version
2010-12-11 00:26:41 +00:00
except ImportError:
SQLITE_VERSION = u'-'
try:
import mako
MAKO_VERSION = mako.__version__
except ImportError:
MAKO_VERSION = u'-'
try:
import icu
ICU_VERSION = u'OK'
except ImportError:
ICU_VERSION = u'-'
try:
import uno
arg = uno.createUnoStruct(u'com.sun.star.beans.PropertyValue')
arg.Name = u'nodepath'
arg.Value = u'/org.openoffice.Setup/Product'
context = uno.getComponentContext()
2012-12-29 09:35:24 +00:00
provider = context.ServiceManager.createInstance(u'com.sun.star.configuration.ConfigurationProvider')
node = provider.createInstanceWithArguments(u'com.sun.star.configuration.ConfigurationAccess', (arg,))
UNO_VERSION = node.getByName(u'ooSetupVersion')
except ImportError:
UNO_VERSION = u'-'
except:
UNO_VERSION = u'- (Possible non-standard UNO installation)'
2011-12-12 22:10:37 +00:00
try:
WEBKIT_VERSION = QtWebKit.qWebKitVersion()
except AttributeError:
WEBKIT_VERSION = u'-'
2013-03-14 10:46:19 +00:00
try:
from openlp.core.ui.media.vlcplayer import VERSION
VLC_VERSION = VERSION
except ImportError:
VLC_VERSION = u'-'
2011-12-12 22:10:37 +00:00
2013-02-05 08:05:28 +00:00
from openlp.core.lib import UiStrings, Settings, translate
2011-03-28 17:29:25 +00:00
from openlp.core.utils import get_application_version
from exceptiondialog import Ui_ExceptionDialog
2010-12-21 19:39:35 +00:00
log = logging.getLogger(__name__)
2013-02-01 19:58:18 +00:00
class ExceptionForm(QtGui.QDialog, Ui_ExceptionDialog):
"""
The exception dialog
"""
def __init__(self, parent):
2013-02-01 19:58:18 +00:00
"""
Constructor.
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
2013-02-14 21:31:17 +00:00
self.settings_section = u'crashreport'
2011-02-03 17:11:20 +00:00
def exec_(self):
2013-02-01 19:58:18 +00:00
"""
Show the dialog.
"""
2013-03-05 14:02:56 +00:00
self.description_text_edit.setPlainText(u'')
2013-03-05 14:05:19 +00:00
self.on_description_updated()
self.file_attachment = None
2011-02-03 17:11:20 +00:00
return QtGui.QDialog.exec_(self)
2013-03-05 14:14:37 +00:00
def _create_report(self):
2013-02-01 19:58:18 +00:00
"""
Create an exception report.
"""
2011-03-28 17:29:25 +00:00
openlp_version = get_application_version()
2013-03-05 14:02:56 +00:00
description = self.description_text_edit.toPlainText()
traceback = self.exception_text_edit.toPlainText()
2012-12-29 09:35:24 +00:00
system = translate('OpenLP.ExceptionForm', 'Platform: %s\n') % platform.platform()
libraries = u'Python: %s\n' % platform.python_version() + \
u'Qt4: %s\n' % Qt.qVersion() + \
u'Phonon: %s\n' % PHONON_VERSION + \
u'PyQt4: %s\n' % Qt.PYQT_VERSION_STR + \
2011-12-12 22:10:37 +00:00
u'QtWebkit: %s\n' % WEBKIT_VERSION + \
u'SQLAlchemy: %s\n' % sqlalchemy.__version__ + \
u'SQLAlchemy Migrate: %s\n' % MIGRATE_VERSION + \
u'BeautifulSoup: %s\n' % BeautifulSoup.__version__ + \
u'lxml: %s\n' % etree.__version__ + \
u'Chardet: %s\n' % CHARDET_VERSION + \
u'PyEnchant: %s\n' % ENCHANT_VERSION + \
u'PySQLite: %s\n' % SQLITE_VERSION + \
u'Mako: %s\n' % MAKO_VERSION + \
u'pyICU: %s\n' % ICU_VERSION + \
2013-03-14 10:46:19 +00:00
u'pyUNO bridge: %s\n' % UNO_VERSION + \
u'VLC: %s\n' % VLC_VERSION
if platform.system() == u'Linux':
if os.environ.get(u'KDE_FULL_SESSION') == u'true':
2013-02-04 21:26:27 +00:00
system += u'Desktop: KDE SC\n'
elif os.environ.get(u'GNOME_DESKTOP_SESSION_ID'):
2013-02-04 21:26:27 +00:00
system += u'Desktop: GNOME\n'
2013-03-14 10:46:19 +00:00
elif os.environ.get(u'DESKTOP_SESSION') == u'xfce':
system += u'Desktop: Xfce\n'
2011-02-03 17:11:20 +00:00
return (openlp_version, description, traceback, system, libraries)
2010-12-13 14:24:16 +00:00
2013-03-05 14:14:37 +00:00
def on_save_report_button_clicked(self):
"""
2012-12-29 09:35:24 +00:00
Saving exception log and system information to a file.
"""
2012-05-17 18:57:01 +00:00
report_text = translate('OpenLP.ExceptionForm',
2010-12-11 00:26:41 +00:00
'**OpenLP Bug Report**\n'
'Version: %s\n\n'
2011-02-03 17:11:20 +00:00
'--- Details of the Exception. ---\n\n%s\n\n '
2010-12-11 00:26:41 +00:00
'--- Exception Traceback ---\n%s\n'
'--- System information ---\n%s\n'
2012-05-17 18:57:01 +00:00
'--- Library Versions ---\n%s\n')
filename = QtGui.QFileDialog.getSaveFileName(self,
translate('OpenLP.ExceptionForm', 'Save Crash Report'),
2013-02-14 21:31:17 +00:00
Settings().value(self.settings_section + u'/last directory'),
translate('OpenLP.ExceptionForm', 'Text files (*.txt *.log *.text)'))
if filename:
2012-02-26 21:09:22 +00:00
filename = unicode(filename).replace(u'/', os.path.sep)
2013-02-14 21:31:17 +00:00
Settings().setValue(self.settings_section + u'/last directory', os.path.dirname(filename))
2013-03-05 14:14:37 +00:00
report_text = report_text % self._create_report()
try:
2011-06-01 05:42:56 +00:00
report_file = open(filename, u'w')
try:
2011-06-01 05:42:56 +00:00
report_file.write(report_text)
except UnicodeError:
2011-06-01 05:42:56 +00:00
report_file.close()
report_file = open(filename, u'wb')
report_file.write(report_text.encode(u'utf-8'))
finally:
2011-06-01 05:42:56 +00:00
report_file.close()
except IOError:
log.exception(u'Failed to write crash report')
finally:
2011-06-01 05:42:56 +00:00
report_file.close()
2013-03-05 14:14:37 +00:00
def on_send_report_button_clicked(self):
"""
2013-03-14 10:46:19 +00:00
Opening systems default email client and inserting exception log and system information.
"""
2012-05-17 18:57:01 +00:00
body = translate('OpenLP.ExceptionForm',
'*OpenLP Bug Report*\n'
2010-12-11 00:26:41 +00:00
'Version: %s\n\n'
2011-02-03 17:11:20 +00:00
'--- Details of the Exception. ---\n\n%s\n\n '
2010-12-11 00:26:41 +00:00
'--- Exception Traceback ---\n%s\n'
'--- System information ---\n%s\n'
'--- Library Versions ---\n%s\n',
'Please add the information that bug reports are favoured written '
2012-05-17 18:57:01 +00:00
'in English.')
2013-03-05 14:14:37 +00:00
content = self._create_report()
2011-10-23 17:22:11 +00:00
source = u''
exception = u''
2011-02-03 17:23:24 +00:00
for line in content[2].split(u'\n'):
if re.search(r'[/\\]openlp[/\\]', line):
source = re.sub(r'.*[/\\]openlp[/\\](.*)".*', r'\1', line)
if u':' in line:
exception = line.split(u'\n')[-1].split(u':')[0]
2011-10-15 21:21:22 +00:00
subject = u'Bug report: %s in %s' % (exception, source)
mailto_url = QtCore.QUrl(u'mailto:bugs@openlp.org')
2011-10-15 21:21:22 +00:00
mailto_url.addQueryItem(u'subject', subject)
mailto_url.addQueryItem(u'body', body % content)
2013-03-05 14:05:19 +00:00
if self.file_attachment:
mailto_url.addQueryItem(u'attach', self.file_attachment)
QtGui.QDesktopServices.openUrl(mailto_url)
2011-02-03 17:11:20 +00:00
2013-03-05 14:05:19 +00:00
def on_description_updated(self):
2013-02-01 19:58:18 +00:00
"""
Update the minimum number of characters needed in the description.
"""
2013-03-05 14:02:56 +00:00
count = int(20 - len(self.description_text_edit.toPlainText()))
2011-02-03 17:11:20 +00:00
if count < 0:
count = 0
2013-03-05 14:14:37 +00:00
self.__button_state(True)
2011-02-03 19:07:27 +00:00
else:
2013-03-05 14:14:37 +00:00
self.__button_state(False)
2013-03-05 14:02:56 +00:00
self.description_word_count.setText(
2012-12-29 09:35:24 +00:00
translate('OpenLP.ExceptionDialog', 'Description characters to enter : %s') % count)
2011-02-03 17:11:20 +00:00
2013-03-05 14:14:37 +00:00
def on_attach_file_button_clicked(self):
2013-02-01 19:58:18 +00:00
"""
Attache files to the bug report e-mail.
"""
2011-02-03 19:07:27 +00:00
files = QtGui.QFileDialog.getOpenFileName(
2012-05-19 15:30:09 +00:00
self, translate('ImagePlugin.ExceptionDialog', 'Select Attachment'),
2013-02-14 21:31:17 +00:00
Settings().value(self.settings_section + u'/last directory'), u'%s (*.*) (*)' % UiStrings().AllFiles)
2011-02-03 19:07:27 +00:00
log.info(u'New files(s) %s', unicode(files))
if files:
2013-03-05 14:05:19 +00:00
self.file_attachment = unicode(files)
2011-02-03 19:07:27 +00:00
2013-03-05 14:14:37 +00:00
def __button_state(self, state):
2013-02-01 19:58:18 +00:00
"""
Toggle the button state.
"""
2013-03-05 14:02:56 +00:00
self.save_report_button.setEnabled(state)
self.send_report_button.setEnabled(state)