OpenWalnut  1.5.0dev
WApplication.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <exception>
26 
27 #include <QtGui>
28 
29 #include "WMainWindow.h"
30 
31 #include "WApplication.h"
32 
33 #include "core/common/WException.h"
34 #include "core/common/WLogger.h"
35 
36 #define OPENWALNUT_BUGREPORTER_URL "https://bsvgit.informatik.uni-leipzig.de/openwalnut/openwalnut/issues"
37 
38 WApplication::WApplication( int &argc, char** argv, bool GUIenabled ) // NOLINT
39  : QApplication( argc, argv, GUIenabled )
40  , myMainWidget( 0 )
41 {
42 }
43 
44 void WApplication::setMyMainWidget( QWidget* widget )
45 {
46  myMainWidget = widget;
47 }
48 
49 bool WApplication::notify( QObject* object, QEvent* event )
50 {
51  bool retval = false;
52  QString exception_msg;
53  try // do the default action, but catch exceptions
54  {
55  retval = QApplication::notify( object, event );
56  }
57  catch( const WException &we )
58  {
59  exception_msg = QString( we.what() );
60  }
61  catch( const std::exception &se )
62  {
63  exception_msg = QString( se.what() );
64  }
65 
66  if( !exception_msg.isEmpty() )
67  {
68  QMessageBox msgBox( myMainWidget );
69  msgBox.setIcon( QMessageBox::Critical );
70  QString info( "An uncaught exception occurred which may be due to a corrupt installation or a programming bug. "
71  "Please check the openwalnut bug reporter for similar tickets and report the issue including the "
72  "following text: <br><br><i>" + exception_msg + "</i><br><br> Please report to: <br><a href=\""
73  OPENWALNUT_BUGREPORTER_URL "\">" OPENWALNUT_BUGREPORTER_URL "</a>" );
74  msgBox.setInformativeText( tr( info.toStdString().c_str() ) );
75  QPushButton* websiteButton = msgBox.addButton( tr( "Go to web site" ), QMessageBox::ActionRole );
76  msgBox.setStandardButtons( QMessageBox::Ignore );
77  msgBox.setEscapeButton( QMessageBox::Ignore );
78  msgBox.exec();
79  if( msgBox.clickedButton() == websiteButton )
80  {
81  QDesktopServices::openUrl( QUrl( OPENWALNUT_BUGREPORTER_URL ) ); // we do not have use for the bool return value
82  }
83 
84  // also notify the logger, as it is setup, before WApplication::exec is called
85  wlog::error( "WApplication" ) << info.remove( QRegExp( "<[^>]*>" ) ).toStdString();
86  }
87 
88  return retval;
89 }
void setMyMainWidget(QWidget *widget)
store the main widget for error reporting and session management
QWidget * myMainWidget
Reference to the main widget set by setMyMainWidget.
Definition: WApplication.h:68
virtual bool notify(QObject *receiver, QEvent *e)
Overloaded to catch uncaught exceptions in event handlers and displays a bug-warning.
WApplication(int &argc, char **argv, bool GUIenabled=true)
default constructor, see QApplication
Basic exception handler.
Definition: WException.h:39
virtual const char * what() const
Returns the message string set on throw.
Definition: WException.cpp:90
WStreamedLogger error(const std::string &source)
Logging an error message.
Definition: WLogger.h:298