• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kmobiletools

errorlogdialog.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002    Copyright (C) 2007 by Matthias Lechner <matthias@lmme.de>
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2 of the License, or
00007    (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the
00016    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017    Boston, MA 02110-1301, USA.
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     // create widgets and layout
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     // set initial size
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     // set item text
00177     QString errorText;
00178     errorText += errorObject->dateTime().toString( Qt::LocaleDate );
00179     errorText += ": ";
00180     errorText += errorObject->description();
00181 
00182     setText( errorText );
00183 
00184     // set icon according to error priority
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"

kmobiletools

Skip menu "kmobiletools"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal