1 /***************************************************************************
2 * Copyright (C) 2005-2007 by Tarek Saidi *
3 * tarek.saidi@arcor.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; version 2 of the License. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
23 KpxUuid::KpxUuid() : Data(16,0){
26 KpxUuid::KpxUuid(const void* src){
30 void KpxUuid::generate(){
33 quint32 Secs=QDateTime::currentDateTime().toTime_t();
34 quint16 mSecs=QTime::currentTime().msec();
35 mSecs=(mSecs & 0x3FF) | (*((quint16*)(uuid+4)) & 0xFC00); //msec has only 10 Bits, filling the rest with random data
36 memcpy((void*)uuid,&Secs,4);
37 memcpy((void*)(uuid+4),&mSecs,2);
38 Data=QByteArray(uuid,16);
41 QString KpxUuid::toString()const{
43 Q_ASSERT(Data.length()==16);
44 for(int i=0;i<16;i++){
46 HexByte.setNum((unsigned char)*(Data.data()+i),16);
47 if(HexByte.length()<2)HexByte="0"+HexByte;
50 return QString("{%1-%2-%3-%4-%5}")
58 void KpxUuid::toRaw(void* dst)const{
59 memcpy(dst,Data.data(),16);
62 void KpxUuid::fromRaw(const void* src){
63 Data=QByteArray((char*)src,16);
66 bool KpxUuid::operator==(const KpxUuid& other)const{
67 return other.Data==Data;
70 bool KpxUuid::operator!=(const KpxUuid& other)const{
71 return other.Data!=Data;
76 QString KpxDateTime::toString(Qt::DateFormat format) const{
77 if (*this==Date_Never)
78 return QCoreApplication::translate("Database","Never");
79 else if (format==Qt::SystemLocaleDate){
80 QString strFormat = QLocale::system().dateFormat(QLocale::ShortFormat);
81 if (!strFormat.contains("dd")) strFormat.replace("d", "dd");
82 if (!strFormat.contains("MM")) strFormat.replace("M", "MM");
83 if (!strFormat.contains("yyyy")) strFormat.replace("yy", "yyyy");
84 if (!strFormat.contains("hh")) strFormat.replace("h", "hh");
85 if (!strFormat.contains("HH")) strFormat.replace("H", "HH");
86 if (!strFormat.contains("mm")) strFormat.replace("m", "mm");
87 if (!strFormat.contains("ss")) strFormat.replace("s", "ss");
88 return date().toString(strFormat);
91 return QDateTime::toString(format);
94 QString KpxDateTime::dateToString(Qt::DateFormat format) const{
95 if (*this==Date_Never)
96 return QCoreApplication::translate("Database","Never");
97 else if (format==Qt::SystemLocaleDate){
98 QString strFormat = QLocale::system().dateFormat(QLocale::ShortFormat);
99 if (!strFormat.contains("dd")) strFormat.replace("d", "dd");
100 if (!strFormat.contains("MM")) strFormat.replace("M", "MM");
101 if (!strFormat.contains("yyyy")) strFormat.replace("yy", "yyyy");
102 return date().toString(strFormat);
105 return date().toString(format);
109 KpxDateTime KpxDateTime::fromString(const QString& string,Qt::DateFormat format){
110 if(string.toLower()=="never")
112 else return QDateTime::fromString(string,format);
118 Creation=QDateTime::currentDateTime();
119 LastMod=QDateTime::currentDateTime();
120 LastAccess=QDateTime::currentDateTime();
121 Expire=QDateTime(QDate(2999,12,28),QTime(23,59,59)); //Never
125 bool KpxDateTime::operator<(const QDateTime& other){
126 if(*this!=Date_Never && other!=Date_Never)return ((QDateTime)(*this)<other);
127 if(*this==Date_Never && other==Date_Never)return false;
128 if(*this==Date_Never)return false;
129 if(other==Date_Never)return true;