kmobiletools
errorlogdialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "errorlogdialog.h"
00021
00022 #include <QVBoxLayout>
00023 #include <QDateTime>
00024
00025 #include <KLocale>
00026 #include <KIconLoader>
00027
00028 using namespace KMobileTools;
00029
00030 ErrorLogDialog::ErrorLogDialog( QWidget* parent )
00031 : KDialog( parent )
00032 {
00033 setCaption( i18n( "Error log" ) );
00034 setButtons( KDialog::Ok );
00035
00036
00037 m_errorLogListWidget = new QListWidget( this );
00038 m_errorDetailsTextEdit = new KTextEdit( this );
00039 m_errorDetailsTextEdit->setReadOnly( true );
00040
00041 QVBoxLayout* layout = new QVBoxLayout();
00042 layout->addWidget( m_errorLogListWidget );
00043 layout->addWidget( m_errorDetailsTextEdit );
00044
00045 QWidget* dummyWidget = new QWidget( this );
00046 dummyWidget->setLayout( layout );
00047
00048
00049 setInitialSize( QSize( 500, 400 ) );
00050
00051 setMainWidget( dummyWidget );
00052
00053 connect( m_errorLogListWidget, SIGNAL(itemActivated(QListWidgetItem *)),
00054 this, SLOT(showErrorDetails(QListWidgetItem *)) );
00055 connect( m_errorLogListWidget, SIGNAL(currentItemChanged ( QListWidgetItem*, QListWidgetItem* )),
00056 this, SLOT(showErrorDetails(QListWidgetItem *)) );
00057
00058
00059 }
00060
00061
00062 ErrorLogDialog::~ErrorLogDialog()
00063 {
00064 }
00065
00066 void ErrorLogDialog::show() {
00067 updateErrorStack();
00068 updateErrorView();
00069 KDialog::show();
00070 }
00071
00072 void ErrorLogDialog::updateErrorStack() {
00073 QStack<const BaseError*> newErrorStack = ErrorHandler::instance()->errorStack();
00074
00075 if( newErrorStack.isEmpty() )
00076 return;
00077
00078 m_errorStack = newErrorStack;
00079 return;
00080 }
00081
00082 void ErrorLogDialog::updateErrorView() {
00083 if( m_errorStack.isEmpty() ) {
00084 m_errorLogListWidget->clear();
00085 return;
00086 }
00087
00088 m_errorLogListWidget->clear();
00089
00090 for( int i = ( m_errorStack.size() - 1 ); i>=0; i-- )
00091 new ErrorLogItem( m_errorStack.at(i), m_errorLogListWidget );
00092
00093 m_errorLogListWidget->setCurrentItem( m_errorLogListWidget->item( 0 ) );
00094 }
00095
00096 void ErrorLogDialog::showErrorDetails( QListWidgetItem* widgetItem ) {
00097 ErrorLogItem* errorItem = dynamic_cast<ErrorLogItem*>( widgetItem );
00098 if( errorItem == 0 )
00099 return;
00100
00101 const BaseError* errorObject = errorItem->errorObject();
00102
00103 QString htmlDescription;
00104 htmlDescription += "<strong>";
00105 htmlDescription += i18n("Error description:");
00106 htmlDescription += "</strong><br>";
00107 htmlDescription += errorObject->description();
00108 htmlDescription += "<br><br>";
00109
00110
00111 htmlDescription += "<strong>";
00112 htmlDescription += i18n("Error occurred on:");
00113 htmlDescription += "</strong><br>";
00114 htmlDescription += errorObject->dateTime().toString( Qt::LocaleDate );
00115 htmlDescription += "<br><br>";
00116
00117
00118 htmlDescription += "<strong>";
00119 htmlDescription += i18n("Error priority:");
00120 htmlDescription += "</strong><br>";
00121 switch( errorObject->priority() ) {
00122 case BaseError::Low:
00123 htmlDescription += i18n("Low");
00124 break;
00125
00126 case BaseError::Medium:
00127 htmlDescription += i18n("Medium");
00128 break;
00129
00130 case BaseError::High:
00131 htmlDescription += i18n("High");
00132 break;
00133 }
00134 htmlDescription += "<br><br>";
00135
00136
00137 htmlDescription += "<strong>";
00138 htmlDescription += i18n("The following information is relevant for developers only:");
00139 htmlDescription += "</strong><br><br>";
00140
00141
00142 htmlDescription += "<strong>";
00143 htmlDescription += i18n("Error occurred in:");
00144 htmlDescription += "</strong><br>";
00145 htmlDescription += QString( "%1:%2").arg( errorObject->fileName() )
00146 .arg( QString::number( errorObject->lineNumber() ) );
00147 htmlDescription += "<br><br>";
00148
00149
00150 htmlDescription += "<strong>";
00151 htmlDescription += i18n("Method name:");
00152 htmlDescription += "</strong><br>";
00153 htmlDescription += errorObject->methodName();
00154 htmlDescription += "<br><br>";
00155
00156
00157 htmlDescription += "<strong>";
00158 htmlDescription += i18n("Additional debug information:");
00159 htmlDescription += "</strong><br>";
00160 QHashIterator<QString, QVariant> i( errorObject->customDebugInformation() );
00161 while( i.hasNext() ) {
00162 i.next();
00163 htmlDescription += QString( "%1: %2<br>" ).arg( i.key() )
00164 .arg( i.value().toString() );
00165 }
00166
00167 m_errorDetailsTextEdit->setHtml( htmlDescription );
00168 }
00169
00170
00171
00172 ErrorLogItem::ErrorLogItem( const KMobileTools::BaseError* errorObject, QListWidget* parent )
00173 : QListWidgetItem( parent, QListWidgetItem::UserType ) {
00174 m_errorObject = errorObject;
00175
00176
00177 QString errorText;
00178 errorText += errorObject->dateTime().toString( Qt::LocaleDate );
00179 errorText += ": ";
00180 errorText += errorObject->description();
00181
00182 setText( errorText );
00183
00184
00185 QIcon icon;
00186 switch( errorObject->priority() ) {
00187 case BaseError::Low:
00188 break;
00189
00190 case BaseError::Medium:
00191 icon = KIcon("dialog-warning");
00192 break;
00193
00194 case BaseError::High:
00195 icon = KIcon("dialog-error");
00196 break;
00197 }
00198 setIcon( icon );
00199 }
00200
00201 const BaseError* ErrorLogItem::errorObject() const {
00202 return m_errorObject;
00203 }
00204
00205 #include "errorlogdialog.moc"