From 676b3204ea731314d6404b3a1e02a3cd590b5a2f Mon Sep 17 00:00:00 2001 From: Raphael Dumusc Date: Wed, 7 Dec 2016 13:45:46 +0100 Subject: [PATCH 1/2] 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. From 97dd60ebbcf31fb55cc4eb5d18a2026d8fd5ec85 Mon Sep 17 00:00:00 2001 From: Stefan Eilemann Date: Wed, 7 Dec 2016 14:25:52 +0100 Subject: [PATCH 2/2] CR #141 --- .travis.yml | 8 -------- apps/DesktopStreamer/CMakeLists.txt | 4 ++-- apps/DesktopStreamer/MainWindow.cpp | 6 +++--- apps/DesktopStreamer/nameUtils.cpp | 6 ++++-- apps/DesktopStreamer/nameUtils.h | 7 ++----- doc/Changelog.md | 2 +- 6 files changed, 12 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index eaf715d..2c0178d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,13 +3,6 @@ notifications: on_success: never language: cpp sudo: false -cache: - ccache: true - pip: true - directories: - - /usr/local -before_cache: - - brew cleanup os: - osx env: @@ -31,4 +24,3 @@ script: - cd $BUILD_TYPE - cmake -GNinja -DCMAKE_INSTALL_PREFIX=$PWD/install -DCMAKE_BUILD_TYPE=$BUILD_TYPE .. - ninja all && ninja $PROJECT_NAME-tests && ninja install - diff --git a/apps/DesktopStreamer/CMakeLists.txt b/apps/DesktopStreamer/CMakeLists.txt index c20dd45..f100b19 100644 --- a/apps/DesktopStreamer/CMakeLists.txt +++ b/apps/DesktopStreamer/CMakeLists.txt @@ -1,6 +1,6 @@ -# Copyright (c) 2013-2015, EPFL/Blue Brain Project -# Raphael Dumusc +# Copyright (c) 2013-2016, EPFL/Blue Brain Project +# Raphael Dumusc set(DESKTOPSTREAMER_HEADERS MainWindow.h diff --git a/apps/DesktopStreamer/MainWindow.cpp b/apps/DesktopStreamer/MainWindow.cpp index e2b7eb5..daeef0a 100644 --- a/apps/DesktopStreamer/MainWindow.cpp +++ b/apps/DesktopStreamer/MainWindow.cpp @@ -96,10 +96,10 @@ MainWindow::MainWindow() }); const auto username = nameutils::getFullUsername(); - if( !username.isEmpty( )) - _streamIdLineEdit->setText( username + "'s Desktop" ); - else + if( username.isEmpty( )) _streamIdLineEdit->setText( QHostInfo::localHostName( )); + else + _streamIdLineEdit->setText( username + "'s Desktop" ); connect( _streamButton, &QPushButton::clicked, this, &MainWindow::_update ); diff --git a/apps/DesktopStreamer/nameUtils.cpp b/apps/DesktopStreamer/nameUtils.cpp index 4900363..0445885 100644 --- a/apps/DesktopStreamer/nameUtils.cpp +++ b/apps/DesktopStreamer/nameUtils.cpp @@ -20,7 +20,7 @@ #include "nameUtils.h" #ifndef _WIN32 -#include +# include #endif namespace nameutils @@ -31,7 +31,9 @@ QString getFullUsername() #ifdef _WIN32 return qgetenv( "USERNAME" ); #else - const auto username = qgetenv( "USER" ); + auto username = qgetenv( "USER" ); + if( username.isEmpty( )) + username = qgetenv( "USERNAME" ); if( username.isEmpty( )) return {}; diff --git a/apps/DesktopStreamer/nameUtils.h b/apps/DesktopStreamer/nameUtils.h index 553ea6c..20cbf81 100644 --- a/apps/DesktopStreamer/nameUtils.h +++ b/apps/DesktopStreamer/nameUtils.h @@ -17,13 +17,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef NAMEUTILS_H -#define NAMEUTILS_H +#pragma once #include /** - * Cross-plateform utilities to retrieve the name of the user. + * Cross-platform utilities to retrieve the name of the user. */ namespace nameutils { @@ -35,5 +34,3 @@ namespace nameutils QString getFullUsername(); } - -#endif diff --git a/doc/Changelog.md b/doc/Changelog.md index be8340a..b0c35aa 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -5,7 +5,7 @@ Changelog {#Changelog} ### 0.12.0 (git master) -* [141](https://github.com/BlueBrain/Deflect/pull/141): +* [140](https://github.com/BlueBrain/Deflect/pull/140): 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