From: Marcus Eggenberger Date: Sat, 7 Feb 2009 16:07:29 +0000 (+0100) Subject: Providing proper defaults for nick and realname on Mac OS using CoreServices X-Git-Tag: 0.4.0~114 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=4bdaf5f2fd6d70155a60e13e125e80cb4b811a22 Providing proper defaults for nick and realname on Mac OS using CoreServices --- diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index dc790b6a..fae257d4 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -56,9 +56,17 @@ set(HEADERS ${MOC_HDRS} types.h util.h) +if(APPLE) + set(SOURCES ${SOURCES} mac_utils.cpp) + set(HEADERS ${HEADERS} mac_utils.h) +endif(APPLE) + qt4_wrap_cpp(MOC ${MOC_HDRS}) include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) # for version.inc and version.gen set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES version.gen) add_library(mod_common STATIC ${SOURCES} ${MOC}) +if(APPLE) + target_link_libraries(mod_common "-framework CoreServices" "-framework CoreFoundation") +endif(APPLE) \ No newline at end of file diff --git a/src/common/identity.cpp b/src/common/identity.cpp index 4eadff9e..31b8a4a2 100644 --- a/src/common/identity.cpp +++ b/src/common/identity.cpp @@ -18,10 +18,15 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "identity.h" + #include #include -#include "identity.h" +#ifdef Q_OS_MAC +# include +# include "mac_utils.h" +#endif Identity::Identity(IdentityId id, QObject *parent) : SyncableObject(parent), @@ -61,11 +66,27 @@ void Identity::init() { setAllowClientUpdates(true); } +QString Identity::defaultNick() { +#ifdef Q_OS_MAC + return CFStringToQString(CSCopyUserName(true)); +#else + return QString("quassel%1").arg(qrand() & 0xff); // FIXME provide more sensible default nicks +#endif +} + +QString Identity::defaultRealName() { +#ifdef Q_OS_MAC + return CFStringToQString(CSCopyUserName(false)); +#else + return tr("Quassel IRC User"); +#endif +} + void Identity::setToDefaults() { setIdentityName(tr("")); - setRealName(tr("Quassel IRC User")); + setRealName(defaultRealName()); QStringList n; - n << QString("quassel%1").arg(qrand() & 0xff); // FIXME provide more sensible default nicks + n << defaultNick(); setNicks(n); setAwayNick(""); setAwayNickEnabled(false); diff --git a/src/common/identity.h b/src/common/identity.h index a5fc9cd2..3e9a5607 100644 --- a/src/common/identity.h +++ b/src/common/identity.h @@ -147,6 +147,8 @@ private: QString _ident, _kickReason, _partReason, _quitReason; void init(); + QString defaultNick(); + QString defaultRealName(); friend QDataStream &operator>>(QDataStream &in, Identity &identity); }; diff --git a/src/common/mac_utils.cpp b/src/common/mac_utils.cpp new file mode 100644 index 00000000..c76c71cc --- /dev/null +++ b/src/common/mac_utils.cpp @@ -0,0 +1,37 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "mac_utils.h" + +#include + +QString CFStringToQString(CFStringRef str) { + if(!str) + return QString(); + + CFIndex length = CFStringGetLength(str); + const UniChar *chars = CFStringGetCharactersPtr(str); + if(chars) + return QString(reinterpret_cast(chars), length); + + QVarLengthArray buffer(length); + CFStringGetCharacters(str, CFRangeMake(0, length), buffer.data()); + return QString(reinterpret_cast(buffer.constData()), length); +} diff --git a/src/common/mac_utils.h b/src/common/mac_utils.h new file mode 100644 index 00000000..78bd58ce --- /dev/null +++ b/src/common/mac_utils.h @@ -0,0 +1,29 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef MAC_UTILS_H +#define MAC_UTILS_H + +#include +#include + +QString CFStringToQString(CFStringRef str); + +#endif //MAC_UTILS_H