summaryrefslogtreecommitdiff
path: root/kcalcore/calformat.cpp
blob: c9d2015e827ae8689cb61d10bbf0aea96f9d8cfb (plain)
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
/*
  This file is part of the kcalcore library.

  Copyright (c) 2001 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 CalFormat base class.

  @brief
  Base class providing an interface to various calendar formats.

  @author Cornelius Schumacher \<schumacher@kde.org\>
*/

#include <config-kcalcore.h>
#include "calformat.h"
#include "exceptions.h"

#if defined(HAVE_UUID_UUID_H)
#include <uuid/uuid.h>
#else
#include <krandom.h>
#include <QtCore/QDateTime>
#endif

using namespace KCalCore;

/**
  Private class that helps to provide binary compatibility between releases.
  @internal
*/
//@cond PRIVATE
class KCalCore::CalFormat::Private
{
  public:
    Private() : mException( 0 ) {}
    ~Private() { delete mException; }
    static QString mApplication; // Name of application, for creating unique ID strings
    static QString mProductId;   // PRODID string to write to calendar files
    QString mLoadedProductId;    // PRODID string loaded from calendar file
    Exception *mException;
};

QString CalFormat::Private::mApplication = QLatin1String( "libkcal" );
QString CalFormat::Private::mProductId =
  QLatin1String( "-//K Desktop Environment//NONSGML libkcal 4.3//EN" );
//@endcond

CalFormat::CalFormat()
  : d( new KCalCore::CalFormat::Private )
{
}

CalFormat::~CalFormat()
{
  clearException();
  delete d;
}

void CalFormat::clearException()
{
  delete d->mException;
  d->mException = 0;
}

void CalFormat::setException( Exception *exception )
{
  delete d->mException;
  d->mException = exception;
}

Exception *CalFormat::exception() const
{
  return d->mException;
}

void CalFormat::setApplication( const QString &application,
                                const QString &productID )
{
  Private::mApplication = application;
  Private::mProductId = productID;
}

const QString &CalFormat::application()
{
  return Private::mApplication;
}

const QString &CalFormat::productId()
{
  return Private::mProductId;
}

QString CalFormat::loadedProductId()
{
  return d->mLoadedProductId;
}

void CalFormat::setLoadedProductId( const QString &id )
{
  d->mLoadedProductId = id;
}

QString CalFormat::createUniqueId()
{
#if defined(HAVE_UUID_UUID_H)
  uuid_t uuid;
  char suuid[64];

  uuid_generate_random( uuid );
  uuid_unparse( uuid, suuid );
  return QString( suuid );
#else
  int hashTime = QTime::currentTime().hour() +
                 QTime::currentTime().minute() + QTime::currentTime().second() +
                 QTime::currentTime().msec();
  QString uidStr = QString( "%1-%2.%3" ).
                   arg( Private::mApplication ).
                   arg( KRandom::random() ).
                   arg( hashTime );
  return uidStr;
#endif
}

void CalFormat::virtual_hook( int id, void *data )
{
  Q_UNUSED( id );
  Q_UNUSED( data );
  Q_ASSERT( false );
}