Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apps/DesktopStreamer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

set(DESKTOPSTREAMER_HEADERS
MainWindow.h
nameUtils.h
Stream.h
)

Expand All @@ -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\"}, \
Expand Down
7 changes: 6 additions & 1 deletion apps/DesktopStreamer/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
/*********************************************************************/

#include "MainWindow.h"
#include "nameUtils.h"
#include "Stream.h"

#include <deflect/version.h>
Expand Down Expand Up @@ -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 );
Expand Down
48 changes: 48 additions & 0 deletions apps/DesktopStreamer/nameUtils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Copyright (c) 2016, EPFL/Blue Brain Project
* Raphael Dumusc <raphael.dumusc@epfl.ch>
*
* This file is part of Deflect <https://github.com/BlueBrain/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 <pwd.h>
#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
}

}
39 changes: 39 additions & 0 deletions apps/DesktopStreamer/nameUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Copyright (c) 2016, EPFL/Blue Brain Project
* Raphael Dumusc <raphael.dumusc@epfl.ch>
*
* This file is part of Deflect <https://github.com/BlueBrain/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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEFLECT_NAMEUTILS_H or similar prefix

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other files in DesktopStreamer don't do it. Should we use DESKTOPSTREAMER_ everywhere to avoid conflicts (e.g. in STREAM_H ) ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAMEUTILS_H sounds very likely to exist somewhere in the world already as a system header. Prefix with DESKTOPSTREAMER_ seems reasonable too. Or pragma once, what Stefan did.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added DESKTOPSTREAMER_ everywhere

#define NAMEUTILS_H

#include <QString>

/**
* Cross-plateform utilities to retrieve the name of the user.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo plateform

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argghh, I'll never get this one right..! thanks

*/
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
36 changes: 36 additions & 0 deletions apps/DesktopStreamer/nameUtils.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright (c) 2016, EPFL/Blue Brain Project
* Raphael Dumusc <raphael.dumusc@epfl.ch>
*
* This file is part of Deflect <https://github.com/BlueBrain/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 <Foundation/NSPathUtilities.h>

namespace nameutils
{

QString getFullUsername()
{
const auto fullname = QString{ [NSFullUserName() UTF8String] };
if( !fullname.isEmpty( ))
return fullname;

return qgetenv( "USER" );
}

}
2 changes: 2 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down