KCalCore Library
calformat.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00032 #include <config-kcalcore.h>
00033 #include "calformat.h"
00034 #include "exceptions.h"
00035
00036 #if defined(HAVE_UUID_UUID_H)
00037 #include <uuid/uuid.h>
00038 #else
00039 #include <KRandom>
00040 #include <QtCore/QDateTime>
00041 #endif
00042
00043 using namespace KCalCore;
00044
00049
00050 class KCalCore::CalFormat::Private
00051 {
00052 public:
00053 Private() : mException( 0 ) {}
00054 ~Private() { delete mException; }
00055 static QString mApplication;
00056 static QString mProductId;
00057 QString mLoadedProductId;
00058 Exception *mException;
00059 };
00060
00061 QString CalFormat::Private::mApplication = QLatin1String( "libkcal" );
00062 QString CalFormat::Private::mProductId =
00063 QLatin1String( "-//K Desktop Environment//NONSGML libkcal 4.3//EN" );
00064
00065
00066 CalFormat::CalFormat()
00067 : d( new KCalCore::CalFormat::Private )
00068 {
00069 }
00070
00071 CalFormat::~CalFormat()
00072 {
00073 clearException();
00074 delete d;
00075 }
00076
00077 void CalFormat::clearException()
00078 {
00079 delete d->mException;
00080 d->mException = 0;
00081 }
00082
00083 void CalFormat::setException( Exception *exception )
00084 {
00085 delete d->mException;
00086 d->mException = exception;
00087 }
00088
00089 Exception *CalFormat::exception() const
00090 {
00091 return d->mException;
00092 }
00093
00094 void CalFormat::setApplication( const QString &application,
00095 const QString &productID )
00096 {
00097 Private::mApplication = application;
00098 Private::mProductId = productID;
00099 }
00100
00101 const QString &CalFormat::application()
00102 {
00103 return Private::mApplication;
00104 }
00105
00106 const QString &CalFormat::productId()
00107 {
00108 return Private::mProductId;
00109 }
00110
00111 QString CalFormat::loadedProductId()
00112 {
00113 return d->mLoadedProductId;
00114 }
00115
00116 void CalFormat::setLoadedProductId( const QString &id )
00117 {
00118 d->mLoadedProductId = id;
00119 }
00120
00121 QString CalFormat::createUniqueId()
00122 {
00123 #if defined(HAVE_UUID_UUID_H)
00124 uuid_t uuid;
00125 char suuid[64];
00126
00127 uuid_generate_random( uuid );
00128 uuid_unparse( uuid, suuid );
00129 return QString( suuid );
00130 #else
00131 int hashTime = QTime::currentTime().hour() +
00132 QTime::currentTime().minute() + QTime::currentTime().second() +
00133 QTime::currentTime().msec();
00134 QString uidStr = QString( "%1-%2.%3" ).
00135 arg( Private::mApplication ).
00136 arg( KRandom::random() ).
00137 arg( hashTime );
00138 return uidStr;
00139 #endif
00140 }
00141
00142 void CalFormat::virtual_hook( int id, void *data )
00143 {
00144 Q_UNUSED( id );
00145 Q_UNUSED( data );
00146 Q_ASSERT( false );
00147 }