1 /***************************************************************************
2 Copyright 2002 Tim Jansen <tim@tjansen.de>
3 Copyright 2002 Stefan Taferner <taferner@kde.org>
4 ***************************************************************************/
6 /***************************************************************************
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
13 ***************************************************************************/
15 #include "invitation.h"
18 * Function for (en/de)crypting strings for config file, taken from KMail
19 * Author: Stefan Taferner <taferner@alpin.or.at>
21 static QString
cryptStr(const QString
&aStr
) {
23 for ( int i
= 0; i
< aStr
.length(); i
++)
24 result
+= (aStr
[i
].unicode() < 0x20) ? aStr
[i
] :
25 QChar(0x1001F - aStr
[i
].unicode());
29 // a random string that doesn't contain i, I, o, O, 1, 0
30 // based on KRandom::randomString()
31 static QString
readableRandomString(int length
) {
35 int r
= KRandom::random() % 62;
55 Invitation::Invitation()
57 m_password
= readableRandomString(4)+'-'+readableRandomString(3);
58 m_creationTime
= QDateTime::currentDateTime();
59 m_expirationTime
= QDateTime::currentDateTime().addSecs(INVITATION_DURATION
);
62 Invitation::Invitation(const Invitation
&x
)
63 : m_password(x
.m_password
), m_creationTime(x
.m_creationTime
), m_expirationTime(x
.m_expirationTime
)
67 Invitation::Invitation(const KConfigGroup
&config
) {
68 m_password
= cryptStr(config
.readEntry("password", QString()));
69 m_creationTime
= config
.readEntry("creation", QDateTime());
70 m_expirationTime
= config
.readEntry("expiration", QDateTime());
73 Invitation::~Invitation() {
76 Invitation
&Invitation::operator= (const Invitation
&x
) {
77 m_password
= x
.m_password
;
78 m_creationTime
= x
.m_creationTime
;
79 m_expirationTime
= x
.m_expirationTime
;
83 void Invitation::save(KConfigGroup
&config
) const {
84 config
.writeEntry("password", cryptStr(m_password
));
85 config
.writeEntry("creation", m_creationTime
);
86 config
.writeEntry("expiration", m_expirationTime
);
89 QString
Invitation::password() const {
93 QDateTime
Invitation::expirationTime() const {
94 return m_expirationTime
;
97 QDateTime
Invitation::creationTime() const {
98 return m_creationTime
;
101 bool Invitation::isValid() const {
102 return m_expirationTime
> QDateTime::currentDateTime();
105 bool Invitation::operator ==(const Invitation
& ot
)
107 return m_creationTime
== ot
.m_creationTime
&& m_password
== ot
.m_password
;