• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdenetwork
  • Sitemap
  • Contact Us
 

krfb

invitation.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002      Copyright 2002 Tim Jansen <tim@tjansen.de>
00003      Copyright 2002 Stefan Taferner <taferner@kde.org>
00004  ***************************************************************************/
00005 
00006 /***************************************************************************
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  ***************************************************************************/
00014 
00015 #include "invitation.h"
00016 
00017 #include <KConfigGroup>
00018 #include <KDebug>
00019 #include <KRandom>
00020 #include <KStringHandler>
00021 
00022 // a random string that doesn't contain i, I, o, O, 1, 0
00023 // based on KRandom::randomString()
00024 static QString readableRandomString(int length) {
00025    QString str;
00026    while (length)
00027    {
00028       int r = KRandom::random() % 62;
00029       r += 48;
00030       if (r > 57)
00031           r += 7;
00032       if (r > 90)
00033           r += 6;
00034       char c = char(r);
00035       if ((c == 'i') ||
00036       (c == 'I') ||
00037       (c == '1') ||
00038       (c == 'o') ||
00039       (c == 'O') ||
00040       (c == '0'))
00041           continue;
00042       str += c;
00043       length--;
00044    }
00045    return str;
00046 }
00047 
00048 Invitation::Invitation()
00049 {
00050     m_password = readableRandomString(4)+'-'+readableRandomString(3);
00051     m_creationTime = QDateTime::currentDateTime();
00052     m_expirationTime = QDateTime::currentDateTime().addSecs(INVITATION_DURATION);
00053 }
00054 
00055 Invitation::Invitation(const Invitation &x)
00056     : m_password(x.m_password), m_creationTime(x.m_creationTime), m_expirationTime(x.m_expirationTime)
00057 {
00058 }
00059 
00060 Invitation::Invitation(const KConfigGroup &config) {
00061     m_password = KStringHandler::obscure(config.readEntry("password", QString()));
00062     kDebug() << "read: " << config.readEntry("password", QString()) << " = " << m_password;
00063     m_creationTime = config.readEntry("creation", QDateTime());
00064     m_expirationTime = config.readEntry("expiration", QDateTime());
00065 }
00066 
00067 Invitation::~Invitation() {
00068 }
00069 
00070 Invitation &Invitation::operator= (const Invitation&x) {
00071     m_password = x.m_password;
00072     m_creationTime = x.m_creationTime;
00073     m_expirationTime = x.m_expirationTime;
00074     return *this;
00075 }
00076 
00077 void Invitation::save(KConfigGroup &config) const 
00078 {
00079     config.writeEntry("password", KStringHandler::obscure(m_password));
00080     config.writeEntry("creation", m_creationTime);
00081     config.writeEntry("expiration", m_expirationTime);
00082 }
00083 
00084 QString Invitation::password() const {
00085     return m_password;
00086 }
00087 
00088 QDateTime Invitation::expirationTime() const {
00089     return m_expirationTime;
00090 }
00091 
00092 QDateTime Invitation::creationTime() const {
00093     return m_creationTime;
00094 }
00095 
00096 bool Invitation::isValid() const {
00097     return m_expirationTime > QDateTime::currentDateTime();
00098 }
00099 
00100 bool Invitation::operator ==(const Invitation & ot)
00101 {
00102     return m_creationTime == ot.m_creationTime && m_password == ot.m_password;
00103 }

krfb

Skip menu "krfb"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal