Commit 128e3318 authored by Melroy van den Berg's avatar Melroy van den Berg

Implement a thread-safe Meyers singleton. Thanks Micha

parent 9864ea24
......@@ -3,7 +3,8 @@ if (POLICY CMP0048)
endif()
set(PROJECT_NAME WineGUI)
set(PROJECT_TARGET winegui)
project(${PROJECT_NAME} VERSION 1.1.0 DESCRIPTION "WineGUI is a user-friendly WINE graphical interface")
# Don't forget to update the about_dialog.h VERSION as well
project(${PROJECT_NAME} VERSION 1.2.0 DESCRIPTION "WineGUI is a user-friendly WINE graphical interface")
message("CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
message("PROJECT_VERSION = ${PROJECT_VERSION}")
......
......@@ -25,7 +25,7 @@
#include <string>
// Use major.minor.patch syntax, don't forget to update CMakeLists.txt file as well!
static const std::string VERSION = "v1.1.0";
static const std::string VERSION = "v1.2.0";
#if defined(PRODUCTION)
#define IMAGE_LOCATION "/usr/share/winegui/images/" /*!< Image location */
......
......@@ -43,7 +43,7 @@ public:
Glib::Dispatcher failureOnExec; /*!< Dispatch signal (thus in main thread) when exit code was non-zero */
// Singleton
static Helper* getInstance();
static Helper& getInstance();
static std::map<string, unsigned long> GetBottlesPaths(const string& dir_path);
static void RunProgram(string prefix_path, string program, bool is_msi_file);
......@@ -71,7 +71,10 @@ public:
static void SetAudioDriver(const string prefix_path, BottleTypes::AudioDriver audio_driver);
static string GetWinetricksLocation();
private:
static Helper* helper; /*< Singleton class storage */
Helper();
~Helper();
Helper(const Helper&)= delete;
Helper& operator=(const Helper&)= delete;
static string Exec(const char* cmd);
static void WineExec(const char* cmd, bool enableTracing = false);
......
......@@ -94,15 +94,13 @@ static const struct
{BottleTypes::Windows::Windows20, "2.0", "0", ""}
};
// Singleton
Helper* Helper::helper = 0;
// Meyers Singleton
Helper::Helper()= default;
Helper::~Helper()= default;
Helper* Helper::getInstance() {
if (helper == 0)
{
helper = new Helper();
}
return helper;
Helper& Helper::getInstance() {
static Helper instance;
return instance;
}
/****************************************************************************
......@@ -781,7 +779,7 @@ int Helper::CloseFile(std::FILE* file) {
// instead of the same context/thread in case of a signal.emit() call.
// This is needed because the CloseFile is called in a different context then usual!
// Signal error message to the user:
helper->failureOnExec();
Helper::getInstance().failureOnExec.emit();
}
}
return 0; // Just always return OK
......
......@@ -399,7 +399,7 @@ void MainWindow::CreateRightPanel()
Gtk::Image* reboot_image = Gtk::manage(new Gtk::Image());
reboot_image->set_from_icon_name("view-refresh", Gtk::IconSize(Gtk::ICON_SIZE_LARGE_TOOLBAR));
reboot_button.set_label("Reboot");
reboot_button.set_tooltip_text("Reboot the Wine Machine");
reboot_button.set_tooltip_text("Simulate Machine Reboot");
reboot_button.set_icon_widget(*reboot_image);
toolbar.insert(reboot_button, 5);
......
......@@ -113,11 +113,9 @@ void SignalDispatcher::DispatchSignals()
m_ErrorMessageDispatcher.connect(sigc::mem_fun(this, &SignalDispatcher::on_error_message));
// When the WineExec() results into a non-zero exit code the failureOnExec it triggered
Helper* helper = Helper::getInstance();
Helper& helper = Helper::getInstance();
// Using Dispatcher instead of signal, will result in that the message box runs in the main thread.
if (helper != NULL) {
helper->failureOnExec.connect(sigc::mem_fun(*mainWindow, &MainWindow::on_exec_failure));
}
helper.failureOnExec.connect(sigc::mem_fun(*mainWindow, &MainWindow::on_exec_failure));
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment