22
22
#include < QBoxLayout>
23
23
#include < QDesktopServices>
24
24
#include < QDesktopWidget>
25
+ #include < QDialogButtonBox>
25
26
#include < QDockWidget>
26
27
#include < QFileDialog>
27
28
#include < QLabel>
31
32
#include < QMenuBar>
32
33
#include < QMessageBox>
33
34
#include < QNetworkInterface>
35
+ #include < QPlainTextEdit>
34
36
#include < QScrollBar>
35
37
#include < QShortcut>
36
38
#include < QSplashScreen>
37
39
#include < QSplitter>
38
40
#include < QStatusBar>
39
41
#include < QStyle>
40
42
#include < QTextBrowser>
43
+ #include < QTextStream>
41
44
#include < QToolBar>
42
45
#include < QToolButton>
46
+ #include < QVBoxLayout>
43
47
44
48
#include " mainwindow.h"
45
49
@@ -146,10 +150,13 @@ MainWindow::MainWindow(QApplication& app, QSplashScreen* splash)
146
150
std::cout << " [GUI] - Using language: " << ui_language.toUtf8 ().constData () << std::endl;
147
151
this ->i18n = sonicPii18n->loadTranslations (ui_language);
148
152
149
- if (i18n) {
150
- std::cout << " [GUI] - translations available " << std::endl;
151
- } else {
152
- std::cout << " [GUI] - translations unavailable (using EN)" << std::endl;
153
+ if (i18n)
154
+ {
155
+ std::cout << " [GUI] - translations available " << std::endl;
156
+ }
157
+ else
158
+ {
159
+ std::cout << " [GUI] - translations unavailable (using EN)" << std::endl;
153
160
}
154
161
155
162
std::cout << " [GUI] - hiding main window" << std::endl;
@@ -184,7 +191,6 @@ MainWindow::MainWindow(QApplication& app, QSplashScreen* splash)
184
191
QThreadPool::globalInstance ()->setMaxThreadCount (3 );
185
192
186
193
startupOK = m_spAPI->WaitUntilReady ();
187
-
188
194
if (startupOK)
189
195
{
190
196
// We have a connection! Finish up loading app...
@@ -227,8 +233,9 @@ MainWindow::MainWindow(QApplication& app, QSplashScreen* splash)
227
233
228
234
app.setActiveWindow (tabs->currentWidget ());
229
235
230
- if (!i18n) {
231
- showLanguageLoadingError ();
236
+ if (!i18n)
237
+ {
238
+ showLanguageLoadingError ();
232
239
}
233
240
234
241
showWelcomeScreen ();
@@ -292,7 +299,6 @@ void MainWindow::checkForStudioMode()
292
299
}
293
300
}
294
301
295
-
296
302
void MainWindow::showWelcomeScreen ()
297
303
{
298
304
if (gui_settings->value (" first_time" , 1 ).toInt () == 1 )
@@ -433,8 +439,7 @@ void MainWindow::setupWindowStructure()
433
439
434
440
SonicPiScintilla* workspace = new SonicPiScintilla (lexer, theme, fileName, auto_indent);
435
441
connect (workspace, &SonicPiScintilla::bufferNewlineAndIndent, this , [this ](int point_line, int point_index, int first_line, const std::string& code, const std::string& fileName, const std::string& id) {
436
-
437
- m_spAPI->BufferNewLineAndIndent (point_line, point_index, first_line, code, fileName, id);
442
+ m_spAPI->BufferNewLineAndIndent (point_line, point_index, first_line, code, fileName, id);
438
443
});
439
444
440
445
workspace->setObjectName (QString (" Buffer %1" ).arg (ws));
@@ -1217,35 +1222,79 @@ void MainWindow::setMessageBoxStyle()
1217
1222
QApplication::setPalette (p);
1218
1223
}
1219
1224
1220
- void MainWindow::invokeStartupError (QString msg)
1225
+ void MainWindow::startupError (QString msg)
1221
1226
{
1222
- if (startup_error_reported->isChecked ())
1223
- {
1224
- return ;
1225
- }
1227
+ splashClose ();
1228
+ setMessageBoxStyle ();
1229
+
1230
+ QDialog* pDialog = new QDialog (this , Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint);
1231
+
1232
+ QVBoxLayout* pLayout = new QVBoxLayout (this );
1233
+ pDialog->setLayout (pLayout);
1234
+
1235
+ pDialog->setWindowTitle (tr (" Sonic Pi Boot Error" ));
1236
+
1237
+ QString text;
1238
+ QTextStream str (&text);
1239
+ str << tr (" Apologies, a critical error occurred during startup:\n " )
1240
+ << msg << " \n\n "
1241
+ << tr (" Please consider reporting a bug at" )
1242
+ << " \n http://github.com/samaaron/sonic-pi/issues\n "
1243
+ << " \n "
1244
+ << " Sonic Pi Boot Error Report\n "
1245
+ << " ==========================\n "
1246
+ << " \n "
1247
+ << " System Information\n "
1248
+ << " ------------------\n "
1249
+ << " \n "
1250
+ << " Sonic Pi version: " << version << " \n "
1251
+ << " OS: " << osDescription () << " \n "
1252
+ << " \n "
1253
+ << " Logs:\n\n "
1254
+ << QString::fromStdString (m_spAPI->GetLogs ());
1255
+
1256
+ // The text area for the message. Allows the user to scroll/view it.
1257
+ auto pTextArea = new QPlainTextEdit (text);
1258
+ pTextArea->setReadOnly (true );
1259
+ pLayout->addWidget (pTextArea);
1260
+
1261
+ // Add a dialog style OK button
1262
+ QDialogButtonBox* pButtons = new QDialogButtonBox (QDialogButtonBox::Ok, this );
1263
+ pLayout->addWidget (pButtons);
1264
+
1265
+ auto finished = [&]() {
1266
+ std::cout << " [GUI] - Aborting. Sorry about this." << std::endl;
1267
+ QApplication::exit (-1 );
1268
+ exit (EXIT_FAILURE);
1269
+ };
1226
1270
1227
- startup_error_reported->setChecked (true );
1271
+ // When the user hits OK, quit
1272
+ connect (pButtons, &QDialogButtonBox::accepted, this , [=]() {
1273
+ finished ();
1274
+ });
1275
+
1276
+ // When the dialog is done, quit
1277
+ connect (pDialog, &QDialog::finished, this , [=]() {
1278
+ finished ();
1279
+ });
1228
1280
1229
- QMetaObject::invokeMethod (this , " startupError" ,
1230
- Qt::QueuedConnection,
1231
- Q_ARG (QString, msg));
1281
+ // Make a sensible size, but then allow resizing
1282
+ pDialog->setFixedSize (QSize (ScaleHeightForDPI (750 ), ScaleHeightForDPI (800 )));
1283
+ pDialog->setMaximumSize (QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
1284
+ pDialog->exec ();
1232
1285
}
1233
1286
1234
- void MainWindow::startupError (QString msg )
1287
+ void MainWindow::showLanguageLoadingError ( )
1235
1288
{
1236
- // TODO: Add format error to API
1237
- }
1289
+ QMessageBox msgBox (this );
1290
+ msgBox.setIcon (QMessageBox::Warning);
1291
+ msgBox.setText (QString (tr (" Failed to load translations for language: %1" )).arg (sonicPii18n->getNativeLanguageName (this ->ui_language )));
1292
+ msgBox.setInformativeText (tr (" Falling back to English. Sorry about this." ) + " \n " + tr (" Please consider reporting a bug at" ) + " \n http://github.com/sonic-pi-net/sonic-pi/issues" );
1238
1293
1239
- void MainWindow::showLanguageLoadingError () {
1240
- QMessageBox msgBox (this );
1241
- msgBox.setIcon (QMessageBox::Warning);
1242
- msgBox.setText (QString (tr (" Failed to load translations for language: %1" )).arg (sonicPii18n->getNativeLanguageName (this ->ui_language )));
1243
- msgBox.setInformativeText (tr (" Falling back to English. Sorry about this." ) + " \n " + tr (" Please consider reporting a bug at" ) + " \n http://github.com/sonic-pi-net/sonic-pi/issues" );
1294
+ QPushButton* okButton = msgBox.addButton (tr (" OK" ), QMessageBox::AcceptRole);
1295
+ msgBox.setDefaultButton (okButton);
1244
1296
1245
- QPushButton *okButton = msgBox.addButton (tr (" OK" ), QMessageBox::AcceptRole);
1246
- msgBox.setDefaultButton (okButton);
1247
-
1248
- msgBox.exec ();
1297
+ msgBox.exec ();
1249
1298
}
1250
1299
1251
1300
void MainWindow::replaceBuffer (QString id, QString content, int line, int index, int first_line)
@@ -1542,7 +1591,7 @@ void MainWindow::beautifyCode()
1542
1591
1543
1592
bool MainWindow::sendOSC (Message m)
1544
1593
{
1545
- return m_spAPI->SendOSC (m);
1594
+ return m_spAPI->SendOSC (m);
1546
1595
}
1547
1596
1548
1597
void MainWindow::reloadServerCode ()
@@ -2923,32 +2972,35 @@ void MainWindow::createToolBar()
2923
2972
langActionGroup->setExclusive (true );
2924
2973
#endif
2925
2974
2926
- QSignalMapper * signalMapper = new QSignalMapper (this );
2975
+ QSignalMapper* signalMapper = new QSignalMapper (this );
2927
2976
2928
- for (size_t i = 0 ; i < available_languages.length (); i += 1 ) {
2929
- bool is_current_lang = (available_languages[i] == piSettings->language );
2977
+ for (size_t i = 0 ; i < available_languages.length (); i += 1 )
2978
+ {
2979
+ bool is_current_lang = (available_languages[i] == piSettings->language );
2930
2980
2931
- QAction * langAct = new QAction (sonicPii18n->getNativeLanguageName (available_languages[i]), this );
2932
- langAct->setCheckable (true );
2933
- langAct->setChecked (is_current_lang);
2981
+ QAction* langAct = new QAction (sonicPii18n->getNativeLanguageName (available_languages[i]), this );
2982
+ langAct->setCheckable (true );
2983
+ langAct->setChecked (is_current_lang);
2934
2984
2935
- connect (langAct, SIGNAL (triggered ()), signalMapper, SLOT (map ()));
2936
- signalMapper->setMapping (langAct, i);
2985
+ connect (langAct, SIGNAL (triggered ()), signalMapper, SLOT (map ()));
2986
+ signalMapper->setMapping (langAct, i);
2937
2987
2938
- langActionGroup->addAction (langAct);
2939
- languageMenu->addAction (langAct);
2988
+ langActionGroup->addAction (langAct);
2989
+ languageMenu->addAction (langAct);
2940
2990
2941
- if (i == 0 ) { // add separator after System language
2942
- languageMenu->addSeparator ();
2943
- }
2991
+ if (i == 0 )
2992
+ { // add separator after System language
2993
+ languageMenu->addSeparator ();
2994
+ }
2944
2995
}
2945
2996
2946
2997
connect (signalMapper, SIGNAL (mappedInt (int )), settingsWidget, SLOT (updateUILanguage (int )));
2947
2998
connect (settingsWidget, SIGNAL (uiLanguageChanged (QString)), this , SLOT (updateSelectedUILanguageAction (QString)));
2948
2999
}
2949
3000
2950
- void MainWindow::updateSelectedUILanguageAction (QString lang) {
2951
- langActionGroup->actions ()[sonicPii18n->getAvailableLanguages ().indexOf (lang)]->setChecked (true );
3001
+ void MainWindow::updateSelectedUILanguageAction (QString lang)
3002
+ {
3003
+ langActionGroup->actions ()[sonicPii18n->getAvailableLanguages ().indexOf (lang)]->setChecked (true );
2952
3004
}
2953
3005
2954
3006
QString MainWindow::readFile (QString name)
@@ -3320,16 +3372,16 @@ void MainWindow::onExitCleanup()
3320
3372
3321
3373
if (scopeWindow)
3322
3374
{
3323
- std::cout << " [GUI] - shutting down scope..." << std::endl;
3324
- scopeWindow->ShutDown ();
3375
+ std::cout << " [GUI] - shutting down scope..." << std::endl;
3376
+ scopeWindow->ShutDown ();
3325
3377
}
3326
3378
3327
3379
if (m_spClient)
3328
3380
{
3329
3381
if (loaded_workspaces)
3330
3382
{
3331
- // this should be a synchorous call to avoid the following sleep
3332
- saveWorkspaces ();
3383
+ // this should be a synchorous call to avoid the following sleep
3384
+ saveWorkspaces ();
3333
3385
}
3334
3386
3335
3387
std::this_thread::sleep_for (1s);
@@ -3342,7 +3394,8 @@ void MainWindow::onExitCleanup()
3342
3394
}
3343
3395
}
3344
3396
3345
- void MainWindow::restartApp () {
3397
+ void MainWindow::restartApp ()
3398
+ {
3346
3399
QApplication* app = dynamic_cast <QApplication*>(parent ());
3347
3400
statusBar ()->showMessage (tr (" Restarting Sonic Pi..." ), 10000 );
3348
3401
@@ -3357,10 +3410,13 @@ void MainWindow::restartApp() {
3357
3410
args.removeFirst ();
3358
3411
QProcess process;
3359
3412
bool restart_success = process.startDetached (qApp->arguments ()[0 ], args);
3360
- if (restart_success) {
3361
- std::cout << " [GUI] - successfully restarted sonic-pi" << std::endl;
3362
- } else {
3363
- std::cout << " [GUI] - failed to restart sonic-pi" << std::endl;
3413
+ if (restart_success)
3414
+ {
3415
+ std::cout << " [GUI] - successfully restarted sonic-pi" << std::endl;
3416
+ }
3417
+ else
3418
+ {
3419
+ std::cout << " [GUI] - failed to restart sonic-pi" << std::endl;
3364
3420
}
3365
3421
3366
3422
// Quit
@@ -3743,17 +3799,17 @@ QString MainWindow::sonicPiHomePath()
3743
3799
QString path = qgetenv (" SONIC_PI_HOME" ).constData ();
3744
3800
if (path.isEmpty ())
3745
3801
{
3746
- return QDir::homePath () + QDir::separator () + " .sonic-pi" ;
3802
+ return QDir::homePath () + QDir::separator () + " .sonic-pi" ;
3747
3803
}
3748
3804
else
3749
3805
{
3750
- return path;
3806
+ return path;
3751
3807
}
3752
3808
}
3753
3809
3754
3810
QString MainWindow::sonicPiConfigPath ()
3755
3811
{
3756
- return sonicPiHomePath () + QDir::separator () + " config" ;
3812
+ return sonicPiHomePath () + QDir::separator () + " config" ;
3757
3813
}
3758
3814
3759
3815
void MainWindow::zoomInLogs ()
0 commit comments