/usr/include/kcal/kresult.h is in kdepimlibs5-dev 4:4.14.10-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | /*
This file is part of KDE.
Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
/**
@file
This file is part of the API for handling calendar data and
defines the CalendarLocal class.
@author Cornelius Schumacher \<schumacher@kde.org\>
*/
#ifndef KRESULT_H
#define KRESULT_H
#include <QtCore/QString>
#include "kcal_export.h"
namespace KCal {
/**
@brief
This class represents the result of an operation. It's meant to be used
as return value of functions for returning status and especially error
information.
There are three main types of result: Ok (operation successful completed),
InProgress (operation still in progress) and Error (operation failed).
InProgress is used by asynchronous operations. Functions which start an
operation and return before the operation is finished should return the
InProgress type result.
An error result can include information about the type of the error and a
detailed error message. Translated error messages for the error types are
available through the message() function. Additional detailed error messages
can be set by the setDetails() function. A full error message including the
type specific message and the details is available through fullMessage().
KResult objects can be chained using the chain function. If an operation
executes a suboperation which indicates failure by returning a KResult object
the operation can create a new KResult object and chain the suboperation's
KResult object to it. The error information of chained results is available
through the chainedMessage() function.
Examples:
A function returning ok:
KResult load()
{
return KResultOk();
}
Alternative notation:
KResult load()
{
return KResult::Ok;
}
A function returning an error with a specific error message:
KResult load()
{
return KResultError( i18n("Details about error") );
}
A function returning an error of a sepcific type:
KResult load()
{
return KResultError( KResult::InvalidUrl );
}
Chaining errors:
KResult loadFile()
{
KResult result = mFile.load();
if ( !result.isError() ) {
return KResultError( "File load error" ).chain( result );
} else {
return result;
}
}
Checking for errors:
KResult load() { ... }
...
if ( !load() ) error();
*/
class KCAL_DEPRECATED_EXPORT KResult
{
public:
/**
The different types of results.
*/
enum Type {
Ok, /**< Operation successfully completed */
InProgress, /**< Operation still in-progress */
Error /**< Operation failed */
};
/**
The different types of error conditions.
*/
enum ErrorType {
NotAnError, /**< Not an error */
Undefined, /**< Undefined error */
InvalidUrl, /**< Invalid URL */
WrongParameter, /**< Invalid parameter */
ConnectionFailed, /**< unable to establish a connection */
WriteError, /**< Write error */
ReadError, /**< Read error */
ParseError, /**< Parse error */
WrongSchemaRevision /**< Invalid schema revision */
};
/**
Constructs a KResult object. Default Type is Ok.
*/
KResult();
/**
Copy constructor.
*/
KResult( const KResult & );
/**
Creates a KResult object of the specified Type.
@param type is the result #Type.
*/
explicit KResult( Type type );
/**
Creates a KResult object of the specified ErrorType and an optional
detailed error message.
@param error is the #ErrorType.
@param details is a QString containing optional details to add
to the message corresponding to this error.
*/
explicit KResult( ErrorType error, const QString &details = QString() );
/**
Destroys the result.
*/
~KResult();
/**
Behave like a bool in the corresponding context. Ok and InProgress are
considered as success and return true, Error is considered as failure and
returns false.
*/
operator bool() const;
/**
Returns true if the result is Ok.
*/
bool isOk() const;
/**
Returns true if the result is InProgress.
*/
bool isInProgress() const;
/**
Returns true if the result is Error.
*/
bool isError() const;
/**
Returns the specific result ErrorType.
*/
ErrorType error() const;
/**
Returns a translated string describing the result corresponding to Type
and ErrorType.
@see fullMessage().
*/
QString message() const;
/**
Sets a detailed error message. This error message should include all
details needed to understand and recover from the error. This could be
information like the URL which was tried, the file which could not be
written or which parameter was missing.
@param details is a QString containing details to add to the message
for this error.
@see details().
*/
void setDetails( const QString &details );
/**
Returns the detailed error message.
@see setDetails().
*/
QString details() const;
/**
Returns the full error message. This includes the type-specific message
(see message()) and the detailed message (see details()).
*/
QString fullMessage() const;
/**
Chains result objects. This can be used to remember the cause of an error.
The full error messages including the messages from chained objects can be
accessed through chainedMessage().
@param result is another KResult to chain this one to.
*/
KResult &chain( const KResult &result );
/**
Returns true if the KResult object has a chained KResult object;
else returns false.
*/
bool hasChainedResult() const;
/**
Returns a chained KResult object.
*/
KResult chainedResult() const;
/**
Returns an error message including full details of all chained messages.
This can constitute a backtrace of a error.
*/
QString chainedMessage() const;
private:
//@cond PRIVATE
class Private;
Private *const d;
//@endcond
};
/**
@brief
Convenience class for creating a KResult of type Ok.
*/
class KCAL_DEPRECATED_EXPORT KResultOk : public KResult
{
public:
/**
Create KResult object of type Ok.
*/
KResultOk() : KResult( Ok ), d( 0 ) {}
private:
//@cond PRIVATE
class Private;
Private *const d;
//@endcond
};
/**
@brief
Convenience class for creating a KResult of type InProgress.
*/
class KCAL_DEPRECATED_EXPORT KResultInProgress : public KResult
{
public:
/**
Create KResult object of type InProgress.
*/
KResultInProgress() : KResult( InProgress ), d( 0 ) {}
private:
//@cond PRIVATE
class Private;
Private *const d;
//@endcond
};
/**
@brief
Convenience class for creating a KResult of type Error.
*/
class KCAL_DEPRECATED_EXPORT KResultError : public KResult
{
public:
/**
Create KResult object of type Error.
*/
KResultError() : KResult( Error ), d( 0 ) {}
/**
Create KResult object of type Error with given error type and optionally
a detailed error message.
@param error is the #ErrorType.
@param details is a QString containing optional details to add
to the message corresponding to this error.
*/
explicit KResultError( ErrorType error, const QString &details = QString() )
: KResult( error, details ), d( 0 ) {}
/**
Create KResult object of type Error with given detailed error message.
@param details is a QString containing optional details to add
to the message corresponding to this error.
*/
KResultError( const QString &details ) :
KResult( Undefined, details ), d( 0 ) {}
private:
//@cond PRIVATE
Q_DISABLE_COPY( KResultError )
class Private;
Private *const d;
//@endcond PRIVATE
};
}
#endif
|