From 6a8b7a3b43c939b24abdba78f3db244279cf9377 Mon Sep 17 00:00:00 2001 From: Pablo Alvarado-Moya Date: Sun, 22 Mar 2020 19:22:19 -0600 Subject: [PATCH] Fix warnings calling system in callbacks without checking the result. For that task the wrapper Util::systemWithMessage was created. --- src/control/pagetype/PageTypeHandler.cpp | 1 + src/gui/dialog/SettingsDialog.cpp | 4 ++-- src/gui/inputdevices/touchdisable/TouchDisableCustom.cpp | 7 +++++-- src/gui/inputdevices/touchdisable/TouchDisableGdk.cpp | 6 +++++- src/util/Util.cpp | 8 ++++++++ src/util/Util.h | 5 +++++ test/SpeedTest.cpp | 4 +++- 7 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/control/pagetype/PageTypeHandler.cpp b/src/control/pagetype/PageTypeHandler.cpp index 5dad8c3b..5fb4ab76 100644 --- a/src/control/pagetype/PageTypeHandler.cpp +++ b/src/control/pagetype/PageTypeHandler.cpp @@ -145,4 +145,5 @@ auto PageTypeHandler::getStringForPageTypeFormat(const PageTypeFormat& format) - case PageTypeFormat::Copy: return ":copy"; } + return "ruled"; } diff --git a/src/gui/dialog/SettingsDialog.cpp b/src/gui/dialog/SettingsDialog.cpp index 4a79ae86..72cfae28 100644 --- a/src/gui/dialog/SettingsDialog.cpp +++ b/src/gui/dialog/SettingsDialog.cpp @@ -36,12 +36,12 @@ SettingsDialog::SettingsDialog(GladeSearchpath* gladeSearchPath, Settings* setti g_signal_connect(get("btTestEnable"), "clicked", G_CALLBACK(+[](GtkButton* bt, SettingsDialog* self) { - system(gtk_entry_get_text(GTK_ENTRY(self->get("txtEnableTouchCommand")))); + Util::systemWithMessage(gtk_entry_get_text(GTK_ENTRY(self->get("txtEnableTouchCommand")))); }), this); g_signal_connect(get("btTestDisable"), "clicked", G_CALLBACK(+[](GtkButton* bt, SettingsDialog* self) { - system(gtk_entry_get_text(GTK_ENTRY(self->get("txtDisableTouchCommand")))); + Util::systemWithMessage(gtk_entry_get_text(GTK_ENTRY(self->get("txtDisableTouchCommand")))); }), this); diff --git a/src/gui/inputdevices/touchdisable/TouchDisableCustom.cpp b/src/gui/inputdevices/touchdisable/TouchDisableCustom.cpp index fb604cd8..0584ea18 100644 --- a/src/gui/inputdevices/touchdisable/TouchDisableCustom.cpp +++ b/src/gui/inputdevices/touchdisable/TouchDisableCustom.cpp @@ -2,11 +2,14 @@ #include +#include "Util.h" + + TouchDisableCustom::TouchDisableCustom(string enableCommand, string disableCommand): enableCommand(std::move(enableCommand)), disableCommand(std::move(disableCommand)) {} TouchDisableCustom::~TouchDisableCustom() = default; -void TouchDisableCustom::enableTouch() { system(enableCommand.c_str()); } +void TouchDisableCustom::enableTouch() { Util::systemWithMessage(enableCommand.c_str()); } -void TouchDisableCustom::disableTouch() { system(disableCommand.c_str()); } +void TouchDisableCustom::disableTouch() { Util::systemWithMessage(disableCommand.c_str()); } diff --git a/src/gui/inputdevices/touchdisable/TouchDisableGdk.cpp b/src/gui/inputdevices/touchdisable/TouchDisableGdk.cpp index f70b6049..5e315cdf 100644 --- a/src/gui/inputdevices/touchdisable/TouchDisableGdk.cpp +++ b/src/gui/inputdevices/touchdisable/TouchDisableGdk.cpp @@ -21,6 +21,8 @@ void TouchDisableGdk::enableTouch() { gtk_grab_remove(this->widget); // Todo(@ulrich): replace this with gdk_device_ungrab + // but gdk_device_ungrab is deprecated too, since GTK 3.20 + // gtk_seat_ungrab has to be used instead, gdk_pointer_ungrab(GDK_CURRENT_TIME); // NOLINT } @@ -34,7 +36,9 @@ void TouchDisableGdk::disableTouch() { * See the following link if window dragging by double clicks on empty widget space occurs * https://www.reddit.com/r/kde/comments/aaeo91 */ - // Todo(@ulrich): replace this with gdk_device_ungrab + // Todo(@ulrich): replace this with gdk_device_grab + // but gdk_device_grab is deprecated too, since GTK 3.20 + // gtk_seat_grab has to be used instead, gdk_pointer_grab(window, false, GDK_TOUCH_MASK, nullptr, nullptr, GDK_CURRENT_TIME); // NOLINT gtk_grab_add(this->widget); } diff --git a/src/util/Util.cpp b/src/util/Util.cpp index bc183ebd..a5f2a50a 100644 --- a/src/util/Util.cpp +++ b/src/util/Util.cpp @@ -1,6 +1,7 @@ #include "Util.h" #include +#include #include #include @@ -160,3 +161,10 @@ void Util::writeCoordinateString(OutputStream* out, double xVal, double yVal) { g_ascii_formatd(coordString.data(), G_ASCII_DTOSTR_BUF_SIZE, Util::PRECISION_FORMAT_STRING, yVal); out->write(coordString.data()); } + +void Util::systemWithMessage(const char* command) { + if (auto errc = std::system(command); errc != 0) { + string msg = FS(_F("Error {1} executing system command: {2}") % errc % command); + XojMsgBox::showErrorToUser(nullptr, msg); + } +} diff --git a/src/util/Util.h b/src/util/Util.h index 43cd3deb..50715c86 100644 --- a/src/util/Util.h +++ b/src/util/Util.h @@ -44,6 +44,11 @@ Path getTmpDirSubfolder(const Path& subfolder = ""); Path ensureFolderExists(const Path& p); +/** + * Wrap the system call to redirect errors to a dialog + */ +void systemWithMessage(const char* command); + /** * Execute the callback in the UI Thread. * diff --git a/test/SpeedTest.cpp b/test/SpeedTest.cpp index 56cb8e24..7117ff0c 100644 --- a/test/SpeedTest.cpp +++ b/test/SpeedTest.cpp @@ -50,6 +50,8 @@ private: static void printMemory() { string cmd = "bash -c \"cat /proc/"; cmd += std::to_string(::getpid()) + "/status | grep Vm\""; - system(cmd.c_str()); + if (system(cmd.c_str()) != 0) { + cout << "Error executing " << cmd.c_str() << endl; + }; } };