Skip to content

Commit

Permalink
GUI: Fix critical bugs introduced by last commit
Browse files Browse the repository at this point in the history
* Now restart sonic-pi with the args it was given with
* Disable some verbose logging
* Remove utils/paths.h as it's not needed
  • Loading branch information
SunderB committed Feb 13, 2021
1 parent c9df4aa commit 5d7b4fa
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
1 change: 0 additions & 1 deletion app/gui/qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ set(SOURCES
${QTAPP_ROOT}/utils/sonic_pi_i18n.h
${QTAPP_ROOT}/utils/ruby_help.h
${QTAPP_ROOT}/utils/lang_list.h
${QTAPP_ROOT}/utils/paths.h
${QTAPP_ROOT}/model/settings.h
)

Expand Down
35 changes: 27 additions & 8 deletions app/gui/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ using namespace oscpkt; // OSC specific stuff
#include "widgets/sonicpilog.h"

#include "utils/ruby_help.h"
#include "utils/paths.h"

#include "dpi.h"

Expand Down Expand Up @@ -162,7 +161,7 @@ MainWindow::MainWindow(QApplication& app, QSplashScreen* splash)
initPaths();

bool startupOK = false;
this->sonicPii18n = new SonicPii18n(ROOT_PATH);
this->sonicPii18n = new SonicPii18n(rootPath());
this->ui_language = sonicPii18n->determineUILanguage(piSettings->language);
std::cout << "Using language: " << ui_language.toUtf8().constData() << std::endl;
this->i18n = sonicPii18n->loadTranslations(ui_language);
Expand Down Expand Up @@ -229,7 +228,7 @@ MainWindow::MainWindow(QApplication& app, QSplashScreen* splash)
// The implementation of this method is dynamically generated and can
// be found in ruby_help.h:
std::cout << "[GUI] - initialising documentation window" << std::endl;
initDocsWindow(ui_language);
initDocsWindow();

//setup autocompletion
autocomplete->loadSamples(sample_path);
Expand Down Expand Up @@ -378,9 +377,23 @@ bool MainWindow::initAndCheckPorts()
}
#endif

QString MainWindow::rootPath()
{
// diversity is the spice of life
#if defined(Q_OS_MAC)
return QCoreApplication::applicationDirPath() + "/../Resources";
#elif defined(Q_OS_WIN)
// CMake builds, the exe is in build/debug/sonic-pi, etc.
// We should pass this to the build instead of wiring it up this way!
return QCoreApplication::applicationDirPath() + "/../../../../..";
#else
// On linux, CMake builds app into the build folder
return QCoreApplication::applicationDirPath() + "/../../../..";
#endif
}

void MainWindow::initPaths() {
QString root_path = ROOT_PATH;
QString root_path = rootPath();

#ifdef QT_OLD_API
#if defined(Q_OS_WIN)
Expand Down Expand Up @@ -544,7 +557,7 @@ void MainWindow::setupTheme()
{
// Syntax highlighting
QString themeFilename = QDir::homePath() + QDir::separator() + ".sonic-pi" + QDir::separator() + "config" + QDir::separator() + "colour-theme.properties";
this->theme = new SonicPiTheme(this, themeFilename, ROOT_PATH);
this->theme = new SonicPiTheme(this, themeFilename, rootPath());
}

void MainWindow::setupWindowStructure()
Expand Down Expand Up @@ -1326,7 +1339,7 @@ void MainWindow::startRubyServer()
// Register server pid for potential zombie clearing
QStringList regServerArgs;
#if QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)
regServerArgs << QDir::toNativeSeparators(ROOT_PATH + "/app/server/ruby/bin/task-register.rb")<< QString::number(serverProcess->processId());
regServerArgs << QDir::toNativeSeparators(rootPath() + "/app/server/ruby/bin/task-register.rb")<< QString::number(serverProcess->processId());
#endif
QProcess* regServerProcess = new QProcess();
regServerProcess->start(ruby_path, regServerArgs);
Expand Down Expand Up @@ -3773,8 +3786,15 @@ void MainWindow::restartApp() {
//this->hide(); // So it doesn't look like the app's frozen or crashed
sleep(4); // Allow cleanup to complete
// Create new process
QStringList args = qApp->arguments();
args.removeFirst();
QProcess process;
process.startDetached("sonic-pi", QStringList());
bool restart_success = process.startDetached(qApp->arguments()[0], args);
if (restart_success) {
std::cout << "Successfully restarted sonic-pi" << std::endl;
} else {
std::cout << "Failed to restart sonic-pi" << std::endl;
}
// Quit
app->exit(0);
exit(0);
Expand Down Expand Up @@ -4358,4 +4378,3 @@ SonicPiTheme* MainWindow::GetTheme() const
{
return theme;
}

4 changes: 2 additions & 2 deletions app/gui/qt/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ class MainWindow : public QMainWindow

private:
void initPaths();
QString rootPath();
QString osDescription();
QSignalMapper *signalMapper;
#ifdef QT_OLD_API
Expand Down Expand Up @@ -334,7 +335,7 @@ class MainWindow : public QMainWindow
std::string number_name(int);
std::string workspaceFilename(SonicPiScintilla* text);
SonicPiScintilla* filenameToWorkspace(std::string filename);

bool sendOSC(oscpkt::Message m);

// void initPrefsWindow();
Expand Down Expand Up @@ -363,7 +364,6 @@ class MainWindow : public QMainWindow
QString tooltipStrShiftMeta(char key, QString str);
QString tooltipStrMeta(char key, QString str);
QString readFile(QString name);
QString rootPath();

void addUniversalCopyShortcuts(QTextEdit *te);
void updateTranslatedUIText();
Expand Down
14 changes: 0 additions & 14 deletions app/gui/qt/utils/paths.h

This file was deleted.

8 changes: 4 additions & 4 deletions app/gui/qt/utils/sonic_pi_i18n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ SonicPii18n::~SonicPii18n() {

QString SonicPii18n::determineUILanguage(QString lang_pref) {
QStringList available_languages = getAvailableLanguages();
std::cout << available_languages.join("\n").toUtf8().constData() << std::endl;
//std::cout << available_languages.join("\n").toUtf8().constData() << std::endl;
QLocale locale;

if (lang_pref != "system_locale") {
Expand All @@ -63,14 +63,14 @@ QString SonicPii18n::determineUILanguage(QString lang_pref) {
l = preferred_languages[i];
l.replace("-", "_");

std::cout << preferred_languages[i].toUtf8().constData() << std::endl;
//std::cout << preferred_languages[i].toUtf8().constData() << std::endl;
if (available_languages.contains(l)) {
return l;
}
}
}

// Fpreferred_languages[i]preferred_languages[i]preferred_languages[i]allback to English
// Fallback to English
this->system_language_available = false;
return "en";
}
Expand All @@ -91,7 +91,7 @@ QStringList SonicPii18n::findAvailableLanguages() {
locale.truncate(locale.lastIndexOf('.')); // "sonic-pi_pt_BR"
locale.remove(0, locale.lastIndexOf("sonic-pi_") + 9); // "pt_BR"
//locale.replace("_", "-"); // Replace underscores with dashes so it matches the language codes e.g: "pt-BR"
std::cout << locale.toUtf8().constData() << '\n';
//std::cout << locale.toUtf8().constData() << '\n';
languages << locale;
}
// Add the source language
Expand Down

0 comments on commit 5d7b4fa

Please sign in to comment.