43
43
44
44
#include < deflect/version.h>
45
45
46
+ #include < QHostInfo>
46
47
#include < QMessageBox>
47
48
#include < QPainter>
48
49
#include < QScreen>
@@ -56,37 +57,38 @@ typedef __int32 int32_t;
56
57
# include < windows.h>
57
58
#else
58
59
# include < stdint.h>
59
- # include < unistd.h>
60
60
#endif
61
61
62
- #ifdef DESKTOPSTREAMER_ENABLE_MULTIWINDOW
62
+ #ifdef DEFLECT_USE_QT5MACEXTRAS
63
63
# include " DesktopWindowsModel.h"
64
64
#endif
65
65
66
66
#define SHARE_DESKTOP_UPDATE_DELAY 0
67
67
#define FAILURE_UPDATE_DELAY 100
68
68
#define FRAME_RATE_DAMPING 0 .1f // influence of new value between 0-1
69
69
70
+ namespace
71
+ {
70
72
const std::vector< std::pair< QString, QString > > defaultHosts = {
71
73
{ " DisplayWall Ground floor" , " bbpav02.epfl.ch" },
72
74
{ " DisplayWall 3rd floor" , " bbpav04.epfl.ch" },
73
75
{ " DisplayWall 5th floor" , " bbpav05.epfl.ch" },
74
76
{ " DisplayWall 6th floor" , " bbpav06.epfl.ch" }
75
77
};
76
-
78
+ const QString streamButtonDefaultText = " Stream " ;
77
79
const QString streamSelected = " Stream selected item(s)" ;
80
+ }
78
81
79
82
MainWindow::MainWindow ()
80
83
: _streamID( 0 )
81
84
, _averageUpdate( 0 )
82
85
{
83
86
setupUi ( this );
84
87
85
- #ifndef __APPLE__
86
- // Event injection support is currently limited to OSX
87
- _remoteControlLabel->setVisible ( false );
88
- _remoteControlCheckBox->setVisible ( false );
89
- #endif
88
+ for ( const auto & entry : defaultHosts )
89
+ _hostComboBox->addItem ( entry.first , entry.second );
90
+
91
+ _hostComboBox->setCurrentIndex ( -1 ); // no default host selected initially
90
92
91
93
connect ( _hostComboBox, &QComboBox::currentTextChanged,
92
94
[&]( const QString& text )
@@ -95,47 +97,42 @@ MainWindow::MainWindow()
95
97
_listView->setEnabled ( !text.isEmpty ( ));
96
98
});
97
99
98
- for ( const auto & entry : defaultHosts )
99
- _hostComboBox->addItem ( entry.first , entry.second );
100
-
101
- // no default host selected initially
102
- _hostComboBox->setCurrentIndex ( -1 );
100
+ _streamIdLineEdit->setText ( QHostInfo::localHostName ( ));
103
101
104
- char hostname[256 ] = { 0 };
105
- gethostname ( hostname, 256 );
106
- _streamIdLineEdit->setText ( QString ( " %1" ).arg ( hostname ));
107
-
108
- #ifdef DESKTOPSTREAMER_ENABLE_MULTIWINDOW
109
- _listView->setModel ( new DesktopWindowsModel );
110
-
111
- // select 'Desktop' item as initial default stream item
112
- _listView->setCurrentIndex ( _listView->model ()->index ( 0 , 0 ));
113
- _streamButton->setText ( streamSelected );
114
-
115
- const int itemsHorizontal = std::min ( 3 .f ,
116
- std::ceil ( std::sqrt ( float (_listView->model ()->rowCount ( )))));
117
- const int itemsVertical = std::min ( 3 .f ,
118
- std::ceil (float ( _listView->model ()->rowCount ( )) / itemsHorizontal ));
119
-
120
- // 230 (itemSize + spacing), frameWidth for decorations
121
- resize ( QSize ( 230 * itemsHorizontal + 2 * _listView->frameWidth (),
122
- 230 * itemsVertical + 2 * _listView->frameWidth () + 50 ));
123
- #else
124
- _listView->setHidden ( true );
125
- adjustSize ();
126
- #endif
102
+ connect ( _streamButton, &QPushButton::clicked,
103
+ this , &MainWindow::_update );
104
+ connect ( _streamButton, &QPushButton::clicked,
105
+ _actionMultiWindowMode, &QAction::setDisabled );
127
106
128
107
connect ( _remoteControlCheckBox, &QCheckBox::clicked,
129
108
this , &MainWindow::_onStreamEventsBoxClicked );
130
109
131
- connect ( _streamButton, &QPushButton::clicked,
132
- this , &MainWindow::_update );
110
+ connect ( _actionAdvancedSettings, &QAction::triggered,
111
+ this , &MainWindow::_showAdvancedSettings );
112
+
113
+ connect ( _actionMultiWindowMode, &QAction::triggered,
114
+ [this ]( const bool checked )
115
+ {
116
+ if ( checked )
117
+ _showMultiWindowMode ();
118
+ else
119
+ _showSingleWindowMode ();
120
+ });
133
121
134
122
connect ( _actionAbout, &QAction::triggered,
135
123
this , &MainWindow::_openAboutWidget );
136
124
137
- // Update timer
138
125
connect ( &_updateTimer, &QTimer::timeout, this , &MainWindow::_update );
126
+
127
+ #ifndef __APPLE__
128
+ // Event injection support is currently limited to OSX
129
+ _showRemoteControl ( false );
130
+ #endif
131
+ #ifndef DEFLECT_USE_QT5MACEXTRAS
132
+ _actionMultiWindowMode->setVisible ( false );
133
+ #endif
134
+ _showAdvancedSettings ( false );
135
+ _showSingleWindowMode ();
139
136
}
140
137
141
138
MainWindow::~MainWindow () {}
@@ -193,11 +190,69 @@ void MainWindow::_update()
193
190
_stopStreaming ();
194
191
}
195
192
193
+ void MainWindow::_showRemoteControl ( const bool visible )
194
+ {
195
+ _remoteControlLabel->setVisible ( visible );
196
+ _remoteControlCheckBox->setVisible ( visible );
197
+ }
198
+
199
+ void MainWindow::_showMultiWindowMode ()
200
+ {
201
+ #ifdef DEFLECT_USE_QT5MACEXTRAS
202
+ if ( !_listView->model ( ))
203
+ {
204
+ auto model = new DesktopWindowsModel ();
205
+ model->setParent ( _listView );
206
+ _listView->setModel ( model );
207
+ }
208
+
209
+ _listView->setVisible ( true );
210
+
211
+ // select 'Desktop' item as initial default stream item
212
+ _listView->setCurrentIndex ( _listView->model ()->index ( 0 , 0 ));
213
+ _streamButton->setText ( streamSelected );
214
+
215
+ const int itemsHorizontal = std::min ( 3 .f ,
216
+ std::ceil ( std::sqrt ( float (_listView->model ()->rowCount ( )))));
217
+ const int itemsVertical = std::min ( 3 .f ,
218
+ std::ceil (float ( _listView->model ()->rowCount ( )) / itemsHorizontal ));
219
+
220
+ layout ()->setSizeConstraint ( QLayout::SetDefaultConstraint );
221
+ setFixedSize ( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX );
222
+ // 230 (itemSize + spacing), frameWidth for decorations
223
+ resize ( QSize ( 230 * itemsHorizontal + 2 * _listView->frameWidth (),
224
+ 230 * itemsVertical + 2 * _listView->frameWidth () + 50 ));
225
+ #endif
226
+ }
227
+
228
+ void MainWindow::_showSingleWindowMode ()
229
+ {
230
+ _listView->setHidden ( true );
231
+ _streamButton->setText ( streamButtonDefaultText );
232
+
233
+ layout ()->setSizeConstraint ( QLayout::SetFixedSize );
234
+ }
235
+
236
+ void MainWindow::_showAdvancedSettings ( const bool visible )
237
+ {
238
+ _maxFrameRateSpinBox->setVisible ( visible );
239
+ _maxFrameRateLabel->setVisible ( visible );
240
+
241
+ _streamIdLineEdit->setVisible ( visible );
242
+ _streamIdLabel->setVisible ( visible );
243
+ }
244
+
196
245
void MainWindow::_updateStreams ()
197
246
{
198
- const std::string& host = _getStreamHost ();
247
+ if ( _actionMultiWindowMode->isChecked ( ))
248
+ _updateMultipleStreams ();
249
+ else
250
+ _updateSingleStream ();
251
+ }
199
252
200
- #ifdef DESKTOPSTREAMER_ENABLE_MULTIWINDOW
253
+ void MainWindow::_updateMultipleStreams ()
254
+ {
255
+ #ifdef DEFLECT_USE_QT5MACEXTRAS
201
256
const QModelIndexList windowIndices =
202
257
_listView->selectionModel ()->selectedIndexes ();
203
258
@@ -219,12 +274,12 @@ void MainWindow::_updateStreams()
219
274
const int pid = index .isValid () ?
220
275
_listView->model ()->data ( index ,
221
276
DesktopWindowsModel::ROLE_PID).toInt (): 0 ;
277
+ const std::string host = _getStreamHost ();
222
278
StreamPtr stream ( new Stream ( *this , index , streamId, host, pid ));
223
279
224
280
if ( !stream->isConnected ( ))
225
281
{
226
- _statusbar->showMessage ( QString ( " Could not connect to host %1" ).
227
- arg ( host.c_str ( )));
282
+ _showConnectionErrorStatus ();
228
283
continue ;
229
284
}
230
285
@@ -240,9 +295,11 @@ void MainWindow::_updateStreams()
240
295
_streamButton->setChecked ( true );
241
296
_startStreaming ();
242
297
};
298
+ #endif
299
+ }
243
300
244
- # else // No window list: Stream button toggles
245
-
301
+ void MainWindow::_updateSingleStream ()
302
+ {
246
303
if ( !_streamButton->isChecked ( ))
247
304
{
248
305
_stopStreaming ();
@@ -254,7 +311,7 @@ void MainWindow::_updateStreams()
254
311
const QPersistentModelIndex index ; // default == use desktop
255
312
StreamPtr stream ( new Stream ( *this , index ,
256
313
_streamIdLineEdit->text ().toStdString (),
257
- host ));
314
+ _getStreamHost ( ) ));
258
315
if ( stream->isConnected ( ))
259
316
{
260
317
if ( _remoteControlCheckBox->isChecked ( ))
@@ -263,9 +320,14 @@ void MainWindow::_updateStreams()
263
320
_startStreaming ();
264
321
}
265
322
else
266
- _statusbar-> showMessage ( " Could not connect to host " );
323
+ _showConnectionErrorStatus ( );
267
324
}
268
- #endif
325
+ }
326
+
327
+ void MainWindow::_showConnectionErrorStatus ()
328
+ {
329
+ _statusbar->showMessage ( QString ( " Cannot connect to host: '%1'" ).
330
+ arg ( _getStreamHost ().c_str ( )));
269
331
}
270
332
271
333
void MainWindow::_processStreamEvents ()
@@ -306,22 +368,20 @@ void MainWindow::_shareDesktopUpdate()
306
368
}
307
369
}
308
370
309
- #ifdef DESKTOPSTREAMER_ENABLE_MULTIWINDOW
310
371
void MainWindow::_deselect ( ConstStreamPtr stream )
311
372
{
312
- const QPersistentModelIndex& index = stream->getIndex ();
313
- if ( index .isValid ( ))
373
+ if ( _actionMultiWindowMode->isChecked ( ))
314
374
{
315
- QItemSelectionModel* model = _listView->selectionModel ();
316
- model->select ( index , QItemSelectionModel::Deselect );
375
+ const QPersistentModelIndex& index = stream->getIndex ();
376
+ if ( index .isValid ( ))
377
+ {
378
+ QItemSelectionModel* model = _listView->selectionModel ();
379
+ model->select ( index , QItemSelectionModel::Deselect );
380
+ }
317
381
}
382
+ else
383
+ _streamButton->setChecked ( false );
318
384
}
319
- #else
320
- void MainWindow::_deselect ( ConstStreamPtr )
321
- {
322
- _streamButton->setChecked ( false );
323
- }
324
- #endif
325
385
326
386
void MainWindow::_regulateFrameRate ()
327
387
{
0 commit comments