From 676b3204ea731314d6404b3a1e02a3cd590b5a2f Mon Sep 17 00:00:00 2001 From: Raphael Dumusc Date: Wed, 7 Dec 2016 13:45:46 +0100 Subject: [PATCH] DesktopStreamer: use full user name as default stream name --- apps/DesktopStreamer/CMakeLists.txt | 7 +++++ apps/DesktopStreamer/MainWindow.cpp | 7 ++++- apps/DesktopStreamer/nameUtils.cpp | 48 +++++++++++++++++++++++++++++ apps/DesktopStreamer/nameUtils.h | 39 +++++++++++++++++++++++ apps/DesktopStreamer/nameUtils.mm | 36 ++++++++++++++++++++++ doc/Changelog.md | 2 ++ 6 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 apps/DesktopStreamer/nameUtils.cpp create mode 100644 apps/DesktopStreamer/nameUtils.h create mode 100644 apps/DesktopStreamer/nameUtils.mm diff --git a/apps/DesktopStreamer/CMakeLists.txt b/apps/DesktopStreamer/CMakeLists.txt index 56a7bbb..c20dd45 100644 --- a/apps/DesktopStreamer/CMakeLists.txt +++ b/apps/DesktopStreamer/CMakeLists.txt @@ -4,6 +4,7 @@ set(DESKTOPSTREAMER_HEADERS MainWindow.h + nameUtils.h Stream.h ) @@ -22,6 +23,12 @@ set(DESKTOPSTREAMER_LINK_LIBRARIES Qt5::Widgets ) +if(APPLE) + list(APPEND DESKTOPSTREAMER_SOURCES nameUtils.mm) +else() + list(APPEND DESKTOPSTREAMER_SOURCES nameUtils.cpp) +endif() + set(DEFLECT_DESKTOPSTREAMER_HOSTS "\ {\"DisplayWall Ground floor\", \"bbpav02.epfl.ch\"}, \ diff --git a/apps/DesktopStreamer/MainWindow.cpp b/apps/DesktopStreamer/MainWindow.cpp index b70eb61..e2b7eb5 100644 --- a/apps/DesktopStreamer/MainWindow.cpp +++ b/apps/DesktopStreamer/MainWindow.cpp @@ -39,6 +39,7 @@ /*********************************************************************/ #include "MainWindow.h" +#include "nameUtils.h" #include "Stream.h" #include @@ -94,7 +95,11 @@ MainWindow::MainWindow() _listView->setEnabled( !text.isEmpty( )); }); - _streamIdLineEdit->setText( QHostInfo::localHostName( )); + const auto username = nameutils::getFullUsername(); + if( !username.isEmpty( )) + _streamIdLineEdit->setText( username + "'s Desktop" ); + else + _streamIdLineEdit->setText( QHostInfo::localHostName( )); connect( _streamButton, &QPushButton::clicked, this, &MainWindow::_update ); diff --git a/apps/DesktopStreamer/nameUtils.cpp b/apps/DesktopStreamer/nameUtils.cpp new file mode 100644 index 0000000..4900363 --- /dev/null +++ b/apps/DesktopStreamer/nameUtils.cpp @@ -0,0 +1,48 @@ +/* Copyright (c) 2016, EPFL/Blue Brain Project + * Raphael Dumusc + * + * This file is part of Deflect + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License version 3.0 as published + * by the Free Software Foundation. + * + * This library 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "nameUtils.h" + +#ifndef _WIN32 +#include +#endif + +namespace nameutils +{ + +QString getFullUsername() +{ +#ifdef _WIN32 + return qgetenv( "USERNAME" ); +#else + const auto username = qgetenv( "USER" ); + if( username.isEmpty( )) + return {}; + + if( auto userinfo = getpwnam( username.constData( ))) + { + const auto fullname = QString{ userinfo->pw_gecos }; + if( !fullname.isEmpty( )) + return fullname; + } + return username; +#endif +} + +} diff --git a/apps/DesktopStreamer/nameUtils.h b/apps/DesktopStreamer/nameUtils.h new file mode 100644 index 0000000..553ea6c --- /dev/null +++ b/apps/DesktopStreamer/nameUtils.h @@ -0,0 +1,39 @@ +/* Copyright (c) 2016, EPFL/Blue Brain Project + * Raphael Dumusc + * + * This file is part of Deflect + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License version 3.0 as published + * by the Free Software Foundation. + * + * This library 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef NAMEUTILS_H +#define NAMEUTILS_H + +#include + +/** + * Cross-plateform utilities to retrieve the name of the user. + */ +namespace nameutils +{ + +/** + * Retrieve the full name of the user (e.g. "John Doe"). + * @return full name if available, else the basic username or an empty string. + */ +QString getFullUsername(); + +} + +#endif diff --git a/apps/DesktopStreamer/nameUtils.mm b/apps/DesktopStreamer/nameUtils.mm new file mode 100644 index 0000000..48ad618 --- /dev/null +++ b/apps/DesktopStreamer/nameUtils.mm @@ -0,0 +1,36 @@ +/* Copyright (c) 2016, EPFL/Blue Brain Project + * Raphael Dumusc + * + * This file is part of Deflect + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License version 3.0 as published + * by the Free Software Foundation. + * + * This library 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "nameUtils.h" + +#import + +namespace nameutils +{ + +QString getFullUsername() +{ + const auto fullname = QString{ [NSFullUserName() UTF8String] }; + if( !fullname.isEmpty( )) + return fullname; + + return qgetenv( "USER" ); +} + +} diff --git a/doc/Changelog.md b/doc/Changelog.md index 45f4337..be8340a 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -5,6 +5,8 @@ Changelog {#Changelog} ### 0.12.0 (git master) +* [141](https://github.com/BlueBrain/Deflect/pull/141): + The DesktopStreamer app uses the full user name as the default stream name. * [139](https://github.com/BlueBrain/Deflect/pull/139): OSX: AppNap is now disabled for all QmlStreamers. The AppNapSuspender class is now available in Deflect library for use in external applications.