/***************************************************************************
- * Copyright (C) 2005-08 by the Quassel Project *
+ * Copyright (C) 2005-09 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
-#include <QMetaProperty>
-#include <QVariantMap>
-
#include "identity.h"
-Identity::Identity(IdentityId id, QObject *parent) : SyncableObject(parent), _identityId(id) {
+#include <QMetaProperty>
+#include <QVariantMap>
+#include <QString>
+
+#ifdef Q_OS_MAC
+# include <CoreServices/CoreServices.h>
+# include "mac_utils.h"
+#endif
+
+#ifdef Q_OS_UNIX
+# include <sys/types.h>
+# include <pwd.h>
+# include <unistd.h>
+#endif
+
+#ifdef Q_OS_WIN32
+# include <windows.h>
+# include <Winbase.h>
+# define SECURITY_WIN32
+# include <Security.h>
+#endif
+
+INIT_SYNCABLE_OBJECT(Identity)
+Identity::Identity(IdentityId id, QObject *parent)
+ : SyncableObject(parent),
+ _identityId(id)
+{
init();
setToDefaults();
}
-Identity::Identity(const Identity &other, QObject *parent) : SyncableObject(parent),
- _identityId(other.id()),
- _identityName(other.identityName()),
- _realName(other.realName()),
- _nicks(other.nicks()),
- _awayNick(other.awayNick()),
- _awayNickEnabled(other.awayNickEnabled()),
- _awayReason(other.awayReason()),
- _awayReasonEnabled(other.awayReasonEnabled()),
- _autoAwayEnabled(other.autoAwayEnabled()),
- _autoAwayTime(other.autoAwayTime()),
- _autoAwayReason(other.autoAwayReason()),
- _autoAwayReasonEnabled(other.autoAwayReasonEnabled()),
- _detachAwayEnabled(other.detachAwayEnabled()),
- _detachAwayReason(other.detachAwayReason()),
- _detachAwayReasonEnabled(other.detachAwayReasonEnabled()),
- _ident(other.ident()),
- _kickReason(other.kickReason()),
- _partReason(other.partReason()),
- _quitReason(other.quitReason())
-
+Identity::Identity(const Identity &other, QObject *parent)
+ : SyncableObject(parent),
+ _identityId(other.id()),
+ _identityName(other.identityName()),
+ _realName(other.realName()),
+ _nicks(other.nicks()),
+ _awayNick(other.awayNick()),
+ _awayNickEnabled(other.awayNickEnabled()),
+ _awayReason(other.awayReason()),
+ _awayReasonEnabled(other.awayReasonEnabled()),
+ _autoAwayEnabled(other.autoAwayEnabled()),
+ _autoAwayTime(other.autoAwayTime()),
+ _autoAwayReason(other.autoAwayReason()),
+ _autoAwayReasonEnabled(other.autoAwayReasonEnabled()),
+ _detachAwayEnabled(other.detachAwayEnabled()),
+ _detachAwayReason(other.detachAwayReason()),
+ _detachAwayReasonEnabled(other.detachAwayReasonEnabled()),
+ _ident(other.ident()),
+ _kickReason(other.kickReason()),
+ _partReason(other.partReason()),
+ _quitReason(other.quitReason())
{
init();
}
setAllowClientUpdates(true);
}
+QString Identity::defaultNick() {
+ QString nick = QString("quassel%1").arg(qrand() & 0xff); // FIXME provide more sensible default nicks
+
+#ifdef Q_OS_MAC
+ QString shortUserName = CFStringToQString(CSCopyUserName(true));
+ if(!shortUserName.isEmpty())
+ nick = shortUserName;
+
+#elif defined(Q_OS_UNIX)
+ QString userName;
+ struct passwd *pwd = getpwuid(getuid());
+ if(pwd)
+ userName = pwd->pw_name;
+ if(!userName.isEmpty())
+ nick = userName;
+
+#elif defined(Q_OS_WIN32)
+ TCHAR infoBuf[128];
+ DWORD bufCharCount = 128;
+ //if(GetUserNameEx(/* NameSamCompatible */ 1, infoBuf, &bufCharCount))
+ if(GetUserNameEx(NameSamCompatible, infoBuf, &bufCharCount)) {
+ QString nickName(infoBuf);
+ int lastBs = nickName.lastIndexOf('\\');
+ if(lastBs != -1) {
+ nickName = nickName.mid(lastBs + 1);
+ }
+ if(!nickName.isEmpty())
+ nick = nickName;
+ }
+#endif
+
+ // cleaning forbidden characters from nick
+ QRegExp rx(QString("(^[\\d-]+|[^A-Za-z0-9\x5b-\x60\x7b-\x7d])"));
+ nick.remove(rx);
+ return nick;
+}
+
+QString Identity::defaultRealName() {
+ QString generalDefault = tr("Quassel IRC User");
+
+#ifdef Q_OS_MAC
+ return CFStringToQString(CSCopyUserName(false));
+
+#elif defined(Q_OS_UNIX)
+ QString realName;
+ struct passwd *pwd = getpwuid(getuid());
+ if(pwd)
+ realName = QString::fromUtf8(pwd->pw_gecos);
+ if(!realName.isEmpty())
+ return realName;
+ else
+ return generalDefault;
+
+#elif defined(Q_OS_WIN32)
+ TCHAR infoBuf[128];
+ DWORD bufCharCount = 128;
+ if(GetUserName(infoBuf, &bufCharCount))
+ return QString(infoBuf);
+ else
+ return generalDefault;
+#else
+ return generalDefault;
+#endif
+}
+
void Identity::setToDefaults() {
setIdentityName(tr("<empty>"));
- setRealName(tr("Quassel IRC User"));
- QStringList n;
- n << QString("quassel%1").arg(qrand() & 0xff); // FIXME provide more sensible default nicks
+ setRealName(defaultRealName());
+ QStringList n = QStringList() << defaultNick();
setNicks(n);
setAwayNick("");
setAwayNickEnabled(false);
setQuitReason(tr("http://quassel-irc.org - Chat comfortably. Anywhere."));
}
-bool Identity::isValid() const {
- return (id().toInt() > 0);
-}
-
-IdentityId Identity::id() const {
- return _identityId;
-}
-
-QString Identity::identityName() const {
- return _identityName;
-}
-
-QString Identity::realName() const {
- return _realName;
-}
-
-QStringList Identity::nicks() const {
- return _nicks;
-}
-
-QString Identity::awayNick() const {
- return _awayNick;
-}
-
-bool Identity::awayNickEnabled() const {
- return _awayNickEnabled;
-}
-
-QString Identity::awayReason() const {
- return _awayReason;
-}
-
-bool Identity::awayReasonEnabled() const {
- return _awayReasonEnabled;
-}
-
-bool Identity::autoAwayEnabled() const {
- return _autoAwayEnabled;
-}
-
-int Identity::autoAwayTime() const {
- return _autoAwayTime;
-}
-
-QString Identity::autoAwayReason() const {
- return _autoAwayReason;
-}
-
-bool Identity::autoAwayReasonEnabled() const {
- return _autoAwayReasonEnabled;
-}
-
-bool Identity::detachAwayEnabled() const {
- return _detachAwayEnabled;
-}
-
-QString Identity::detachAwayReason() const {
- return _detachAwayReason;
-}
-
-bool Identity::detachAwayReasonEnabled() const {
- return _detachAwayReasonEnabled;
-}
-
-QString Identity::ident() const {
- return _ident;
-}
-
-QString Identity::kickReason() const {
- return _kickReason;
-}
-
-QString Identity::partReason() const
-{return _partReason;}
-
-QString Identity::quitReason() const {
- return _quitReason;
-}
-
/*** setters ***/
-// NOTE: DO NOT USE ON SYNCHRONIZED OBJECTS!
void Identity::setId(IdentityId _id) {
_identityId = _id;
- setObjectName(QString::number(id().toInt()));
- //emit idSet(id);
+ SYNC(ARG(_id))
+ emit idSet(_id);
+ renameObject(QString::number(id().toInt()));
}
void Identity::setIdentityName(const QString &identityName) {
_identityName = identityName;
- emit identityNameSet(identityName);
+ SYNC(ARG(identityName))
}
void Identity::setRealName(const QString &realName) {
_realName = realName;
- emit realNameSet(realName);
+ SYNC(ARG(realName))
}
void Identity::setNicks(const QStringList &nicks) {
_nicks = nicks;
+ SYNC(ARG(nicks))
emit nicksSet(nicks);
}
void Identity::setAwayNick(const QString &nick) {
_awayNick = nick;
- emit awayNickSet(nick);
+ SYNC(ARG(nick))
}
void Identity::setAwayReason(const QString &reason) {
_awayReason = reason;
- emit awayReasonSet(reason);
+ SYNC(ARG(reason))
}
void Identity::setAwayNickEnabled(bool enabled) {
_awayNickEnabled = enabled;
- emit awayNickEnabledSet(enabled);
+ SYNC(ARG(enabled))
}
void Identity::setAwayReasonEnabled(bool enabled) {
_awayReasonEnabled = enabled;
- emit awayReasonEnabledSet(enabled);
+ SYNC(ARG(enabled))
}
void Identity::setAutoAwayEnabled(bool enabled) {
_autoAwayEnabled = enabled;
- emit autoAwayEnabledSet(enabled);
+ SYNC(ARG(enabled))
}
void Identity::setAutoAwayTime(int time) {
_autoAwayTime = time;
- emit autoAwayTimeSet(time);
+ SYNC(ARG(time))
}
-void Identity::setAutoAwayReason(const QString & reason) {
+void Identity::setAutoAwayReason(const QString &reason) {
_autoAwayReason = reason;
- emit autoAwayReasonSet(reason);
+ SYNC(ARG(reason))
}
void Identity::setAutoAwayReasonEnabled(bool enabled) {
_autoAwayReasonEnabled = enabled;
- emit autoAwayReasonEnabledSet(enabled);
+ SYNC(ARG(enabled))
}
void Identity::setDetachAwayEnabled(bool enabled) {
_detachAwayEnabled = enabled;
- emit detachAwayEnabledSet(enabled);
+ SYNC(ARG(enabled))
}
-void Identity::setDetachAwayReason(const QString & reason) {
+void Identity::setDetachAwayReason(const QString &reason) {
_detachAwayReason = reason;
- emit detachAwayReasonSet(reason);
+ SYNC(ARG(reason))
}
void Identity::setDetachAwayReasonEnabled(bool enabled) {
_detachAwayReasonEnabled = enabled;
- emit detachAwayReasonEnabledSet(enabled);
+ SYNC(ARG(enabled))
}
-void Identity::setIdent(const QString & ident) {
+void Identity::setIdent(const QString &ident) {
_ident = ident;
- emit identSet(ident);
+ SYNC(ARG(ident))
}
-void Identity::setKickReason(const QString & reason) {
+void Identity::setKickReason(const QString &reason) {
_kickReason = reason;
- emit kickReasonSet(reason);
+ SYNC(ARG(reason))
}
-void Identity::setPartReason(const QString & reason) {
+void Identity::setPartReason(const QString &reason) {
_partReason = reason;
- emit partReasonSet(reason);
+ SYNC(ARG(reason))
}
-void Identity::setQuitReason(const QString & reason) {
+void Identity::setQuitReason(const QString &reason) {
_quitReason = reason;
- emit quitReasonSet(reason);
+ SYNC(ARG(reason))
}
/*** ***/
-void Identity::update(const Identity &other) {
-for(int idx = metaObject()->propertyOffset(); idx < metaObject()->propertyCount(); idx++) {
- QMetaProperty metaProp = metaObject()->property(idx);
+void Identity::copyFrom(const Identity &other) {
+ for(int idx = staticMetaObject.propertyOffset(); idx < staticMetaObject.propertyCount(); idx++) {
+ QMetaProperty metaProp = staticMetaObject.property(idx);
Q_ASSERT(metaProp.isValid());
if(this->property(metaProp.name()) != other.property(metaProp.name())) {
setProperty(metaProp.name(), other.property(metaProp.name()));
}
}
-bool Identity::operator==(const Identity &other) {
- for(int idx = metaObject()->propertyOffset(); idx < metaObject()->propertyCount(); idx++) {
- QMetaProperty metaProp = metaObject()->property(idx);
+bool Identity::operator==(const Identity &other) const {
+ for(int idx = staticMetaObject.propertyOffset(); idx < staticMetaObject.propertyCount(); idx++) {
+ QMetaProperty metaProp = staticMetaObject.property(idx);
Q_ASSERT(metaProp.isValid());
QVariant v1 = this->property(metaProp.name());
QVariant v2 = other.property(metaProp.name()); // qDebug() << v1 << v2;
return true;
}
-bool Identity::operator!=(const Identity &other) {
+bool Identity::operator!=(const Identity &other) const {
return !(*this == other);
}
id.fromVariantMap(i);
return in;
}
+
+#ifdef HAVE_SSL
+INIT_SYNCABLE_OBJECT(CertManager)
+#endif // HAVE_SSL