From 8fcc374cd70272f5f1b7d0546154f48606a91aac Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Tue, 23 Feb 2021 21:43:58 +0100 Subject: [PATCH] Check zenity presence, and block editor with message if missing --- plugins/editor/src/editor/Editor.cpp | 25 +++++++++++++++++++++ plugins/editor/src/editor/NativeHelpers.cpp | 9 +++++++- plugins/editor/src/editor/NativeHelpers.h | 4 ++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/plugins/editor/src/editor/Editor.cpp b/plugins/editor/src/editor/Editor.cpp index 64f5d91b..3d90ef38 100644 --- a/plugins/editor/src/editor/Editor.cpp +++ b/plugins/editor/src/editor/Editor.cpp @@ -768,6 +768,31 @@ void Editor::Impl::createFrameContents() mainView->setBackgroundColor(frameBackground); +#if LINUX + if (!isZenityAvailable()) { + CRect bounds = mainView->getViewSize(); + + CViewContainer* box = new CViewContainer(bounds); + mainView->addView(box); + box->setBackgroundColor(CColor(0x00, 0x00, 0x00, 0xc0)); + + CRect textSize = CRect(0, 0, 400, 80).centerInside(bounds); + CMultiLineTextLabel* textLabel = new CMultiLineTextLabel(textSize); + box->addView(textLabel); + textLabel->setTextInset(CPoint(10.0, 10.0)); + textLabel->setStyle(CParamDisplay::kRoundRectStyle); + textLabel->setRoundRectRadius(10.0); + textLabel->setFrameColor(CColor(0xb2, 0xb2, 0xb2)); + textLabel->setBackColor(CColor(0x2e, 0x34, 0x36)); + auto font = makeOwned("Roboto", 16.0); + textLabel->setFont(font); + textLabel->setLineLayout(CMultiLineTextLabel::LineLayout::wrap); + textLabel->setText( + "The required program \"zenity\" is missing.\n" + "Install this software package first, and restart sfizz."); + } +#endif + mainView_ = owned(mainView); } diff --git a/plugins/editor/src/editor/NativeHelpers.cpp b/plugins/editor/src/editor/NativeHelpers.cpp index 0a3ac516..393c3f8b 100644 --- a/plugins/editor/src/editor/NativeHelpers.cpp +++ b/plugins/editor/src/editor/NativeHelpers.cpp @@ -112,10 +112,12 @@ static std::vector createForkEnviron() return newEnv; } +static constexpr char zenityPath[] = "/usr/bin/zenity"; + bool askQuestion(const char *text) { char *argv[] = { - const_cast("/usr/bin/zenity"), + const_cast(zenityPath), const_cast("--question"), const_cast("--text"), const_cast(text), @@ -145,4 +147,9 @@ bool askQuestion(const char *text) return WEXITSTATUS(wstatus) == 0; } + +bool isZenityAvailable() +{ + return access(zenityPath, X_OK) == 0; +} #endif diff --git a/plugins/editor/src/editor/NativeHelpers.h b/plugins/editor/src/editor/NativeHelpers.h index 9ccb5410..92201d85 100644 --- a/plugins/editor/src/editor/NativeHelpers.h +++ b/plugins/editor/src/editor/NativeHelpers.h @@ -9,3 +9,7 @@ bool openFileInExternalEditor(const char *filename); bool openDirectoryInExplorer(const char *filename); bool askQuestion(const char *text); + +#if !defined(_WIN32) && !defined(__APPLE__) +bool isZenityAvailable(); +#endif