- return CFStringToQString(CSCopyUserName(true));
-#else
- return QString("quassel%1").arg(qrand() & 0xff); // FIXME provide more sensible default nicks
+ 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(tcharToQString(infoBuf));
+ int lastBs = nickName.lastIndexOf('\\');
+ if(lastBs != -1) {
+ nickName = nickName.mid(lastBs + 1);
+ }
+ if(!nickName.isEmpty())
+ nick = nickName;
+ }