1 | /* |
2 | This file is part of the kcalcore 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 CalFormat base class. |
25 | |
26 | @brief |
27 | Base class providing an interface to various calendar formats. |
28 | |
29 | @author Cornelius Schumacher \<schumacher@kde.org\> |
30 | */ |
31 | |
32 | #include <config-kcalcore.h> |
33 | #include "calformat.h" |
34 | #include "exceptions.h" |
35 | |
36 | #if defined(HAVE_UUID_UUID_H) |
37 | #include <uuid/uuid.h> |
38 | #else |
39 | #include <KRandom> |
40 | #include <QtCore/QDateTime> |
41 | #endif |
42 | |
43 | using namespace KCalCore; |
44 | |
45 | /** |
46 | Private class that helps to provide binary compatibility between releases. |
47 | @internal |
48 | */ |
49 | //@cond PRIVATE |
50 | class KCalCore::CalFormat::Private |
51 | { |
52 | public: |
53 | Private() : mException(0) {} |
54 | ~Private() { |
55 | delete mException; |
56 | } |
57 | static QString mApplication; // Name of application, for creating unique ID strings |
58 | static QString mProductId; // PRODID string to write to calendar files |
59 | QString mLoadedProductId; // PRODID string loaded from calendar file |
60 | Exception *mException; |
61 | }; |
62 | |
63 | QString CalFormat::Private::mApplication = QLatin1String("libkcal" ); |
64 | QString CalFormat::Private::mProductId = |
65 | QLatin1String("-//K Desktop Environment//NONSGML libkcal 4.3//EN" ); |
66 | //@endcond |
67 | |
68 | CalFormat::CalFormat() |
69 | : d(new KCalCore::CalFormat::Private) |
70 | { |
71 | } |
72 | |
73 | CalFormat::~CalFormat() |
74 | { |
75 | clearException(); |
76 | delete d; |
77 | } |
78 | |
79 | void CalFormat::clearException() |
80 | { |
81 | delete d->mException; |
82 | d->mException = 0; |
83 | } |
84 | |
85 | void CalFormat::setException(Exception *exception) |
86 | { |
87 | delete d->mException; |
88 | d->mException = exception; |
89 | } |
90 | |
91 | Exception *CalFormat::exception() const |
92 | { |
93 | return d->mException; |
94 | } |
95 | |
96 | void CalFormat::setApplication(const QString &application, |
97 | const QString &productID) |
98 | { |
99 | Private::mApplication = application; |
100 | Private::mProductId = productID; |
101 | } |
102 | |
103 | const QString &CalFormat::application() |
104 | { |
105 | return Private::mApplication; |
106 | } |
107 | |
108 | const QString &CalFormat::productId() |
109 | { |
110 | return Private::mProductId; |
111 | } |
112 | |
113 | QString CalFormat::loadedProductId() |
114 | { |
115 | return d->mLoadedProductId; |
116 | } |
117 | |
118 | void CalFormat::setLoadedProductId(const QString &id) |
119 | { |
120 | d->mLoadedProductId = id; |
121 | } |
122 | |
123 | QString CalFormat::createUniqueId() |
124 | { |
125 | #if defined(HAVE_UUID_UUID_H) |
126 | uuid_t uuid; |
127 | char suuid[64]; |
128 | |
129 | uuid_generate_random(uuid); |
130 | uuid_unparse(uuid, suuid); |
131 | return QString::fromLatin1(suuid); |
132 | #else |
133 | int hashTime = QTime::currentTime().hour() + |
134 | QTime::currentTime().minute() + QTime::currentTime().second() + |
135 | QTime::currentTime().msec(); |
136 | QString uidStr = QString("%1-%2.%3" ). |
137 | arg(Private::mApplication). |
138 | arg(KRandom::random()). |
139 | arg(hashTime); |
140 | return uidStr; |
141 | #endif |
142 | } |
143 | |
144 | void CalFormat::virtual_hook(int id, void *data) |
145 | { |
146 | Q_UNUSED(id); |
147 | Q_UNUSED(data); |
148 | Q_ASSERT(false); |
149 | } |
150 | |