KCal Library
kresult.cpp
Go to the documentation of this file.
00001 /* 00002 This file is part of KDE. 00003 00004 Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00034 #include "kresult.h" 00035 00036 #include <klocale.h> 00037 #include <kdebug.h> 00038 00039 using namespace KCal; 00040 00045 //@cond PRIVATE 00046 class KCal::KResult::Private 00047 { 00048 public: 00049 Private() 00050 : mType( Ok ), 00051 mErrorType( NotAnError ), 00052 mChainedResult( 0 ) 00053 { 00054 } 00055 00056 Private( Type type ) 00057 : mType( type ), 00058 mChainedResult( 0 ) 00059 { 00060 if ( mType == Error ) { 00061 mErrorType = Undefined; 00062 } else { 00063 mErrorType = NotAnError; 00064 } 00065 } 00066 00067 Private( ErrorType error, const QString &details ) 00068 : mType( Error ), 00069 mErrorType( error ), 00070 mDetails( details ), 00071 mChainedResult( 0 ) 00072 { 00073 } 00074 00075 Type mType; 00076 ErrorType mErrorType; 00077 QString mDetails; 00078 KResult *mChainedResult; 00079 }; 00080 //@endcond 00081 00082 KResult::KResult() 00083 : d( new KCal::KResult::Private ) 00084 { 00085 } 00086 00087 KResult::KResult( Type type ) 00088 : d( new KCal::KResult::Private( type ) ) 00089 { 00090 } 00091 00092 KResult::KResult( ErrorType error, const QString &details ) 00093 : d( new KCal::KResult::Private( error, details ) ) 00094 { 00095 } 00096 00097 KResult::~KResult() 00098 { 00099 delete d->mChainedResult; 00100 delete d; 00101 } 00102 00103 KResult::KResult( const KResult &o ) : d( new KCal::KResult::Private ) 00104 { 00105 d->mType = o.d->mType; 00106 d->mErrorType = o.d->mErrorType; 00107 d->mDetails = o.d->mDetails; 00108 if ( o.d->mChainedResult ) { 00109 d->mChainedResult = new KResult( *o.d->mChainedResult ); 00110 } else { 00111 d->mChainedResult = 0; 00112 } 00113 } 00114 00115 KResult::operator bool() const 00116 { 00117 return !isError(); 00118 } 00119 00120 bool KResult::isOk() const 00121 { 00122 return d->mType == Ok; 00123 } 00124 00125 bool KResult::isInProgress() const 00126 { 00127 return d->mType == InProgress; 00128 } 00129 00130 bool KResult::isError() const 00131 { 00132 return d->mType == Error; 00133 } 00134 00135 KResult::ErrorType KResult::error() const 00136 { 00137 return d->mErrorType; 00138 } 00139 00140 QString KResult::message() const 00141 { 00142 switch ( d->mType ) { 00143 case Ok: 00144 return i18n( "Ok" ); 00145 case InProgress: 00146 return i18n( "In progress" ); 00147 case Error: 00148 switch ( d->mErrorType ) { 00149 case NotAnError: 00150 return i18n( "Not an error" ); 00151 case Undefined: 00152 return i18n( "Error" ); 00153 case InvalidUrl: 00154 return i18n( "Invalid URL" ); 00155 case ConnectionFailed: 00156 return i18n( "Connection failed" ); 00157 case WriteError: 00158 return i18n( "Write error" ); 00159 case ReadError: 00160 return i18n( "Read error" ); 00161 case WrongParameter: 00162 return i18n( "Wrong Parameter" ); 00163 case ParseError: 00164 return i18n( "Parse Error" ); 00165 case WrongSchemaRevision: 00166 return i18n( "Wrong revision of schema" ); 00167 } 00168 } 00169 00170 kError() << "Unhandled case"; 00171 return QString(); 00172 } 00173 00174 void KResult::setDetails( const QString &details ) 00175 { 00176 d->mDetails = details; 00177 } 00178 00179 QString KResult::details() const 00180 { 00181 return d->mDetails; 00182 } 00183 00184 KResult &KResult::chain( const KResult &result ) 00185 { 00186 d->mChainedResult = new KResult( result ); 00187 return *this; 00188 } 00189 00190 bool KResult::hasChainedResult() const 00191 { 00192 return d->mChainedResult; 00193 } 00194 00195 KResult KResult::chainedResult() const 00196 { 00197 return *d->mChainedResult; 00198 } 00199 00200 QString KResult::fullMessage() const 00201 { 00202 QString msg = message(); 00203 if ( !details().isEmpty() ) { 00204 msg += ": " + details(); 00205 } 00206 return msg; 00207 } 00208 00209 QString KResult::chainedMessage() const 00210 { 00211 QString msg = fullMessage(); 00212 if ( hasChainedResult() ) { 00213 msg += '\n' + chainedResult().chainedMessage(); 00214 } 00215 return msg; 00216 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 05:05:30 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 05:05:30 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.