From 4542abe17b0d48040e251325e7f0517708d65fed Mon Sep 17 00:00:00 2001 From: Raphael Dumusc Date: Tue, 18 Apr 2017 14:10:12 +0200 Subject: [PATCH 1/2] DesktopStreamer OSX: read default hosts from file --- apps/DesktopStreamer/CMakeLists.txt | 14 ++++- apps/DesktopStreamer/MainWindow.cpp | 7 ++- apps/DesktopStreamer/defaults.cpp | 87 +++++++++++++++++++++++++++ apps/DesktopStreamer/defaults.h | 52 ++++++++++++++++ apps/DesktopStreamer/defaults.json.in | 5 ++ doc/Changelog.md | 4 ++ 6 files changed, 164 insertions(+), 5 deletions(-) create mode 100644 apps/DesktopStreamer/defaults.cpp create mode 100644 apps/DesktopStreamer/defaults.h create mode 100644 apps/DesktopStreamer/defaults.json.in diff --git a/apps/DesktopStreamer/CMakeLists.txt b/apps/DesktopStreamer/CMakeLists.txt index 39a1ef0..e886880 100644 --- a/apps/DesktopStreamer/CMakeLists.txt +++ b/apps/DesktopStreamer/CMakeLists.txt @@ -3,12 +3,14 @@ # Raphael Dumusc set(DESKTOPSTREAMER_HEADERS + defaults.h MainWindow.h nameUtils.h Stream.h ) set(DESKTOPSTREAMER_SOURCES + defaults.cpp main.cpp MainWindow.cpp MainWindow.ui @@ -31,8 +33,8 @@ set(DEFLECT_DESKTOPSTREAMER_HOSTS {\"DisplayWall 6th floor\", \"bbpav06.bbp.epfl.ch\"}" CACHE STRING "List of default hosts for the DesktopStreamer application" ) -set_source_files_properties(MainWindow.cpp PROPERTIES COMPILE_DEFINITIONS - _HOSTS=${DEFLECT_DESKTOPSTREAMER_HOSTS} +set_source_files_properties(defaults.cpp PROPERTIES COMPILE_DEFINITIONS + _DEFAULT_HOSTS=${DEFLECT_DESKTOPSTREAMER_HOSTS} ) set(DESKTOPSTREAMER_APP_NAME desktopstreamer) @@ -57,6 +59,14 @@ if(APPLE) else() list(APPEND DESKTOPSTREAMER_LINK_LIBRARIES "-framework CoreGraphics") endif() + + # Configure 'defaults.json' and copy it in the app bundle's 'Resources' folder + string(REGEX REPLACE "\"," "\":" _JSON_HOSTS ${DEFLECT_DESKTOPSTREAMER_HOSTS}) + set(_defaults_file ${CMAKE_CURRENT_BINARY_DIR}/defaults.json) + configure_file(defaults.json.in ${_defaults_file}) + list(APPEND DESKTOPSTREAMER_SOURCES ${_defaults_file}) + set_source_files_properties(${_defaults_file} PROPERTIES + MACOSX_PACKAGE_LOCATION Resources) else() list(APPEND DESKTOPSTREAMER_SOURCES nameUtils.cpp) endif() diff --git a/apps/DesktopStreamer/MainWindow.cpp b/apps/DesktopStreamer/MainWindow.cpp index 5e9f38f..f6f70d4 100644 --- a/apps/DesktopStreamer/MainWindow.cpp +++ b/apps/DesktopStreamer/MainWindow.cpp @@ -1,6 +1,6 @@ /*********************************************************************/ /* Copyright (c) 2011-2012, The University of Texas at Austin. */ -/* Copyright (c) 2013-2016, EPFL/Blue Brain Project */ +/* Copyright (c) 2013-2017, EPFL/Blue Brain Project */ /* Raphael Dumusc */ /* All rights reserved. */ /* */ @@ -39,7 +39,9 @@ /*********************************************************************/ #include "MainWindow.h" + #include "Stream.h" +#include "defaults.h" #include "nameUtils.h" #include @@ -69,7 +71,6 @@ typedef __int32 int32_t; namespace { -const std::vector> defaultHosts = {_HOSTS}; const QString streamButtonDefaultText = "Stream"; const QString streamSelected = "Stream selected item(s)"; const int SHARE_DESKTOP_UPDATE_DELAY = 0; @@ -83,7 +84,7 @@ MainWindow::MainWindow() { setupUi(this); - for (const auto& entry : defaultHosts) + for (const auto& entry : defaults::getHosts()) _hostComboBox->addItem(entry.first, entry.second); _hostComboBox->setCurrentIndex(-1); // no default host selected initially diff --git a/apps/DesktopStreamer/defaults.cpp b/apps/DesktopStreamer/defaults.cpp new file mode 100644 index 0000000..1b98a3c --- /dev/null +++ b/apps/DesktopStreamer/defaults.cpp @@ -0,0 +1,87 @@ +/*********************************************************************/ +/* Copyright (c) 2017, EPFL/Blue Brain Project */ +/* Raphael Dumusc */ +/* All rights reserved. */ +/* */ +/* Redistribution and use in source and binary forms, with or */ +/* without modification, are permitted provided that the following */ +/* conditions are met: */ +/* */ +/* 1. Redistributions of source code must retain the above */ +/* copyright notice, this list of conditions and the following */ +/* disclaimer. */ +/* */ +/* 2. Redistributions in binary form must reproduce the above */ +/* copyright notice, this list of conditions and the following */ +/* disclaimer in the documentation and/or other materials */ +/* provided with the distribution. */ +/* */ +/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */ +/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */ +/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ +/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ +/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */ +/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ +/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */ +/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */ +/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ +/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */ +/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ +/* POSSIBILITY OF SUCH DAMAGE. */ +/* */ +/* The views and conclusions contained in the software and */ +/* documentation are those of the authors and should not be */ +/* interpreted as representing official policies, either expressed */ +/* or implied, of The University of Texas at Austin. */ +/*********************************************************************/ + +#include "defaults.h" + +#include +#include +#include +#include +#include +#include + +#include + +namespace defaults +{ +std::vector> getHosts() +{ +#ifdef __APPLE__ + const auto appPath = QApplication::applicationDirPath(); + QFile file{appPath + "/../Resources/defaults.json"}; + if (!file.exists() || !file.open(QIODevice::ReadOnly)) + { + std::cerr << "could not open file 'defaults.json'" << std::endl; + return {}; + } + QJsonParseError error; + const auto doc = QJsonDocument::fromJson(file.readAll(), &error); + if (doc.isNull()) + { + std::cerr << "defaults.json parsing error: " + << error.errorString().toStdString() << std::endl; + return {}; + } + std::vector> hosts; + for (const auto& value : doc.object()["hosts"].toArray()) + { + const auto entry = value.toObject(); + if (entry.size() != 1) + continue; + const auto name = entry.begin().key(); + const auto addr = entry.begin().value().toString(); + if (!name.isEmpty() && !addr.isEmpty()) + hosts.emplace_back(name, addr); + } + return hosts; +#else + return {_DEFAULT_HOSTS}; // CMake DEFLECT_DESKTOPSTREAMER_HOSTS +#endif +} +} diff --git a/apps/DesktopStreamer/defaults.h b/apps/DesktopStreamer/defaults.h new file mode 100644 index 0000000..d0963fa --- /dev/null +++ b/apps/DesktopStreamer/defaults.h @@ -0,0 +1,52 @@ +/*********************************************************************/ +/* Copyright (c) 2017, EPFL/Blue Brain Project */ +/* Raphael Dumusc */ +/* All rights reserved. */ +/* */ +/* Redistribution and use in source and binary forms, with or */ +/* without modification, are permitted provided that the following */ +/* conditions are met: */ +/* */ +/* 1. Redistributions of source code must retain the above */ +/* copyright notice, this list of conditions and the following */ +/* disclaimer. */ +/* */ +/* 2. Redistributions in binary form must reproduce the above */ +/* copyright notice, this list of conditions and the following */ +/* disclaimer in the documentation and/or other materials */ +/* provided with the distribution. */ +/* */ +/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */ +/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */ +/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ +/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ +/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */ +/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ +/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */ +/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */ +/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ +/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */ +/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ +/* POSSIBILITY OF SUCH DAMAGE. */ +/* */ +/* The views and conclusions contained in the software and */ +/* documentation are those of the authors and should not be */ +/* interpreted as representing official policies, either expressed */ +/* or implied, of The University of Texas at Austin. */ +/*********************************************************************/ + +#ifndef DEFAULTS_H +#define DEFAULTS_H + +#include +#include + +namespace defaults +{ +/** @return the list of default hosts as [name, address] pairs. */ +std::vector> getHosts(); +} + +#endif diff --git a/apps/DesktopStreamer/defaults.json.in b/apps/DesktopStreamer/defaults.json.in new file mode 100644 index 0000000..b419286 --- /dev/null +++ b/apps/DesktopStreamer/defaults.json.in @@ -0,0 +1,5 @@ +{ + "hosts": [ + ${_JSON_HOSTS} + ] +} diff --git a/doc/Changelog.md b/doc/Changelog.md index 976ea2a..e7ff683 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -3,6 +3,10 @@ Changelog {#Changelog} ## Deflect 0.13 (git master) +* [161](https://github.com/BlueBrain/Deflect/pull/161): + DesktopStreamer OSX: the default hosts are read from a json file in the app + bundle. This is useful for external users who want to adapt the official + BlueBrain releases to their own needs without recompiling. * [156](https://github.com/BlueBrain/Deflect/pull/156): Deflect can be released as a Debian/Ubuntu package. Once installed, DesktopStreamer can be launched from the desktop's applications menu. From 8a681cc0bfab61b3bab5ccda47563ad7dc0bde77 Mon Sep 17 00:00:00 2001 From: Raphael Dumusc Date: Thu, 13 Apr 2017 14:39:50 +0200 Subject: [PATCH 2/2] Fix Travis: new location of CMake AUTOUI'ed ui_MainWindow.h --- CMakeLists.txt | 1 + apps/DesktopStreamer/CMakeLists.txt | 2 ++ apps/DesktopStreamer/MainWindow.h | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c39eadd..9fdbfb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ set(DEFLECT_DEB_DEPENDS freeglut3-dev libxi-dev libxmu-dev libboost-program-options-dev libboost-test-dev qtbase5-dev qtdeclarative5-dev) set(DEFLECT_PORT_DEPENDS boost freeglut qt5) +set(DEFLECT_BREW_DEPENDS boost freeglut jpeg-turbo qt5) include(Common) diff --git a/apps/DesktopStreamer/CMakeLists.txt b/apps/DesktopStreamer/CMakeLists.txt index e886880..69e71fa 100644 --- a/apps/DesktopStreamer/CMakeLists.txt +++ b/apps/DesktopStreamer/CMakeLists.txt @@ -2,6 +2,8 @@ # Copyright (c) 2013-2017, EPFL/Blue Brain Project # Raphael Dumusc +include_directories(${CMAKE_CURRENT_BINARY_DIR}) # for autogenerated ui_* file + set(DESKTOPSTREAMER_HEADERS defaults.h MainWindow.h diff --git a/apps/DesktopStreamer/MainWindow.h b/apps/DesktopStreamer/MainWindow.h index d2ec6e0..d306951 100644 --- a/apps/DesktopStreamer/MainWindow.h +++ b/apps/DesktopStreamer/MainWindow.h @@ -41,7 +41,7 @@ #ifndef DESKTOPSTREAMER_MAINWINDOW_H #define DESKTOPSTREAMER_MAINWINDOW_H -#include +#include "ui_MainWindow.h" // Generated by CMake in CMAKE_CURRENT_BINARY_DIR #ifdef __APPLE__ #include