Show MessageBox on Stream Fail

This commit is contained in:
Florian Märkl 2019-08-18 12:42:46 +02:00
commit 44e9142886
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
3 changed files with 25 additions and 20 deletions

View file

@ -161,7 +161,6 @@ int RunMain(QApplication &app, Settings *settings)
int RunStream(QApplication &app, const StreamSessionConnectInfo &connect_info) int RunStream(QApplication &app, const StreamSessionConnectInfo &connect_info)
{ {
StreamWindow window(connect_info); StreamWindow window(connect_info);
window.show();
app.setQuitOnLastWindowClosed(true); app.setQuitOnLastWindowClosed(true);
return app.exec(); return app.exec();
} }

View file

@ -225,15 +225,7 @@ void MainWindow::ServerItemWidgetTriggered()
QString host = server->GetHostAddr(); QString host = server->GetHostAddr();
StreamSessionConnectInfo info(settings, host, server->registered_host.GetRPRegistKey(), server->registered_host.GetRPKey()); StreamSessionConnectInfo info(settings, host, server->registered_host.GetRPRegistKey(), server->registered_host.GetRPKey());
try new StreamWindow(info);
{
auto stream_window = new StreamWindow(info);
stream_window->show();
}
catch(const ChiakiException &e)
{
QMessageBox::critical(this, tr("Stream failed"), e.what());
}
} }
else else
{ {

View file

@ -24,6 +24,8 @@
StreamWindow::StreamWindow(const StreamSessionConnectInfo &connect_info, QWidget *parent) StreamWindow::StreamWindow(const StreamSessionConnectInfo &connect_info, QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
{
try
{ {
session = new StreamSession(connect_info, this); session = new StreamSession(connect_info, this);
@ -37,6 +39,15 @@ StreamWindow::StreamWindow(const StreamSessionConnectInfo &connect_info, QWidget
session->Start(); session->Start();
resize(connect_info.video_profile.width, connect_info.video_profile.height); resize(connect_info.video_profile.width, connect_info.video_profile.height);
show();
}
catch(const Exception &e)
{
session = nullptr;
av_widget = nullptr;
QMessageBox::critical(this, tr("Stream failed"), tr("Failed to initialize Stream Session: %1").arg(e.what()));
close();
}
} }
StreamWindow::~StreamWindow() StreamWindow::~StreamWindow()
@ -47,16 +58,19 @@ StreamWindow::~StreamWindow()
void StreamWindow::keyPressEvent(QKeyEvent *event) void StreamWindow::keyPressEvent(QKeyEvent *event)
{ {
if(session)
session->HandleKeyboardEvent(event); session->HandleKeyboardEvent(event);
} }
void StreamWindow::keyReleaseEvent(QKeyEvent *event) void StreamWindow::keyReleaseEvent(QKeyEvent *event)
{ {
if(session)
session->HandleKeyboardEvent(event); session->HandleKeyboardEvent(event);
} }
void StreamWindow::closeEvent(QCloseEvent *) void StreamWindow::closeEvent(QCloseEvent *)
{ {
if(session)
session->Stop(); session->Stop();
} }