+QString tcharToQString(TCHAR *tchar)
+{
+ return QString::fromLocal8Bit(tchar);
+}
+
+
+#endif
+
+#endif
+void Identity::init()
+{
+ setObjectName(QString::number(id().toInt()));
+ 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_WIN)
+ TCHAR infoBuf[128];
+ DWORD bufCharCount = 128;
+ //if(GetUserNameEx(/* NameSamCompatible */ 1, infoBuf, &bufCharCount))
+ if (GetUserNameEx(NameSamCompatible, infoBuf, &bufCharCount)) {
+ QString nickName(tcharToQString(infoBuf));
+ int lastBs = nickName.lastIndexOf('\\');
+ if (lastBs != -1) {
+ nickName = nickName.mid(lastBs + 1);
+ }
+ if (!nickName.isEmpty())
+ nick = nickName;
+ }