1/*
2 This file is part of the kcal library.
3
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21/**
22 @file
23 This file is part of the API for handling calendar data and
24 defines the Exception and ErrorFormat classes.
25
26 We don't use actual C++ exceptions right now. These classes are currently
27 returned by an error function; but we can build upon them, if/when we start
28 to use C++ exceptions.
29
30 @brief
31 Exceptions base class along with the Calendar ErrorFormat class.
32
33 @author Cornelius Schumacher \<schumacher@kde.org\>
34*/
35
36#include "exceptions.h"
37#include "calformat.h"
38
39#include <klocalizedstring.h>
40
41using namespace KCal;
42
43Exception::Exception( const QString &message )
44{
45 mMessage = message;
46}
47
48Exception::~Exception()
49{
50}
51
52QString Exception::message()
53{
54 if ( mMessage.isEmpty() ) {
55 return i18n( "%1 Error", CalFormat::application() );
56 } else {
57 return mMessage;
58 }
59}
60
61/**
62 Private class that helps to provide binary compatibility between releases.
63 @internal
64*/
65//@cond PRIVATE
66class KCal::ErrorFormat::Private
67{
68 public:
69 ErrorCodeFormat mCode;
70};
71//@endcond
72
73ErrorFormat::ErrorFormat( ErrorCodeFormat code, const QString &message )
74 : Exception( message ), d( new KCal::ErrorFormat::Private )
75{
76 d->mCode = code;
77}
78
79ErrorFormat::~ErrorFormat()
80{
81 delete d;
82}
83
84QString ErrorFormat::message()
85{
86 QString message = "";
87
88 switch ( d->mCode ) {
89 case LoadError:
90 message = i18n( "Load Error" );
91 break;
92 case SaveError:
93 message = i18n( "Save Error" );
94 break;
95 case ParseErrorIcal:
96 message = i18n( "Parse Error in libical" );
97 break;
98 case ParseErrorKcal:
99 message = i18n( "Parse Error in libkcal" );
100 break;
101 case NoCalendar:
102 message = i18n( "No calendar component found." );
103 break;
104 case CalVersion1:
105 message = i18n( "vCalendar Version 1.0 detected." );
106 break;
107 case CalVersion2:
108 message = i18n( "iCalendar Version 2.0 detected." );
109 break;
110 case CalVersionUnknown:
111 message = i18n( "Unknown calendar format detected." );
112 break;
113 case Restriction:
114 message = i18n( "Restriction violation" );
115 break;
116 case NoWritableFound:
117 message = i18n( "No writable resource found" );
118 break;
119 case UserCancel:
120 // no real error; the user canceled the operation
121 break;
122 }
123
124 if ( !mMessage.isEmpty() ) {
125 message += ": " + mMessage;
126 }
127
128 return message;
129}
130
131ErrorFormat::ErrorCodeFormat ErrorFormat::errorCode()
132{
133 return d->mCode;
134}
135