mirror of
https://github.com/ashaduri/gsmartcontrol.git
synced 2026-09-25 21:35:33 +00:00
Ported from Gtk::Main to Gtk::Application.
This commit is contained in:
@@ -152,9 +152,9 @@ bool CommandExecutorGui::execute_tick_func(TickStatus status)
|
||||
|
||||
// If quit() was called during one of the manual iterations, and execute()
|
||||
// is called in a loop, we need to prevent any real execution past that point.
|
||||
if (Gtk::Main::iteration(false) && Gtk::Main::level() > 0) {
|
||||
return false; // try to abort execution
|
||||
}
|
||||
// if (Gtk::Main::iteration(false) && Gtk::Main::level() > 0) {
|
||||
// return false; // try to abort execution
|
||||
// }
|
||||
|
||||
execution_running_ = true;
|
||||
should_abort_ = false;
|
||||
@@ -181,14 +181,14 @@ bool CommandExecutorGui::execute_tick_func(TickStatus status)
|
||||
|
||||
if (status == TickStatus::running) {
|
||||
|
||||
while (Gtk::Main::events_pending()) {
|
||||
// Gtk::Main::iteration() returns true if Gtk::Main::quit() has been called, or if there's no Main yet.
|
||||
// debug_out_dump("app", Gtk::Main::level() << "\n");
|
||||
if (Gtk::Main::iteration() && Gtk::Main::level() > 0) {
|
||||
set_running_dialog_abort_mode(true);
|
||||
return false; // try to abort execution
|
||||
}
|
||||
}
|
||||
// while (Gtk::Main::events_pending()) {
|
||||
// // Gtk::Main::iteration() returns true if Gtk::Main::quit() has been called, or if there's no Main yet.
|
||||
// // debug_out_dump("app", Gtk::Main::level() << "\n");
|
||||
// if (Gtk::Main::iteration() && Gtk::Main::level() > 0) {
|
||||
// set_running_dialog_abort_mode(true);
|
||||
// return false; // try to abort execution
|
||||
// }
|
||||
// }
|
||||
|
||||
if (should_abort_) {
|
||||
should_abort_ = false;
|
||||
@@ -205,9 +205,9 @@ bool CommandExecutorGui::execute_tick_func(TickStatus status)
|
||||
|
||||
|
||||
if (status == TickStatus::stopping) {
|
||||
if (Gtk::Main::iteration(false) && Gtk::Main::level() > 0) {
|
||||
return false; // we're exiting from the main loop, so return early
|
||||
}
|
||||
// if (Gtk::Main::iteration(false) && Gtk::Main::level() > 0) {
|
||||
// return false; // we're exiting from the main loop, so return early
|
||||
// }
|
||||
|
||||
// show a dialog with "Aborting..."
|
||||
this->update_dialog_show_timer();
|
||||
|
||||
@@ -25,7 +25,8 @@ int main(int argc, char** argv)
|
||||
{
|
||||
return hz::main_exception_wrapper([&argc, &argv]()
|
||||
{
|
||||
Gtk::Main m(argc, argv);
|
||||
// Required by executor
|
||||
auto app = Gtk::Application::create("org.gsmartcontrol.examples.smartctl_executor");
|
||||
|
||||
// NOTE: Don't use long options (e.g. --info). Use short ones (e.g. -i),
|
||||
// because long options may be unsupported on some platforms.
|
||||
|
||||
+13
-8
@@ -323,13 +323,16 @@ bool app_init_and_loop(int& argc, char**& argv)
|
||||
// Note that changing GTK locale after it's inited isn't really supported by GTK,
|
||||
// but we have no other choice - glib needs system locale when parsing the
|
||||
// arguments, and gtk is inited while the parsing is performed.
|
||||
#if GTK_CHECK_VERSION(4, 0, 0)
|
||||
Glib::set_init_to_users_preferred_locale(args.arg_locale == TRUE);
|
||||
#else
|
||||
if (args.arg_locale == FALSE) {
|
||||
hz::locale_c_set("C");
|
||||
} else {
|
||||
// change the C++ locale to match the C one.
|
||||
hz::locale_cpp_set(""); // this may fail on some systems
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (args.arg_version == TRUE) {
|
||||
// show version information and exit
|
||||
@@ -410,23 +413,25 @@ bool app_init_and_loop(int& argc, char**& argv)
|
||||
| G_LOG_FLAG_RECURSION), glib_message_handler, nullptr);
|
||||
}
|
||||
|
||||
|
||||
#if !GTK_CHECK_VERSION(4, 0, 0)
|
||||
// Save the locale
|
||||
std::locale final_loc_cpp = hz::locale_cpp_get<std::locale>();
|
||||
#endif
|
||||
|
||||
// Initialize GTK+ (it's already initialized by command-line parser,
|
||||
// so this doesn't do much).
|
||||
// Initialize GTK+.
|
||||
// GTKMM 3 Notes (no longer valid as of gtkmm4):
|
||||
// Newer gtkmm will try to set the C++ locale here.
|
||||
// Note: passing false (as use_locale) as the third parameter here
|
||||
// will generate a gtk_disable_setlocale() warning (due to gtk being
|
||||
// already initialized), so manually save / restore the C++ locale
|
||||
// (C locale won't be touched).
|
||||
// Nothing is affected in gtkmm itself by C++ locale, so it's ok to do it.
|
||||
Gtk::Main m(argc, argv);
|
||||
auto app = Gtk::Application::create("org.gsmartcontrol.base");
|
||||
|
||||
#if !GTK_CHECK_VERSION(4, 0, 0)
|
||||
// Restore the locale
|
||||
hz::locale_cpp_set(final_loc_cpp);
|
||||
|
||||
#endif
|
||||
|
||||
debug_out_info("app", "Current C locale: " << hz::locale_c_get() << "\n");
|
||||
debug_out_info("app", "Current C++ locale: " << hz::locale_cpp_get<std::string>() << "\n");
|
||||
@@ -553,7 +558,7 @@ bool app_init_and_loop(int& argc, char**& argv)
|
||||
|
||||
// The Main Loop
|
||||
debug_out_info("app", "Entering main loop.\n");
|
||||
Gtk::Main::run();
|
||||
app->run(argc, argv);
|
||||
debug_out_info("app", "Main loop exited.\n");
|
||||
}
|
||||
|
||||
@@ -578,7 +583,7 @@ void app_quit()
|
||||
// exit the main loop
|
||||
debug_out_info("app", "Trying to exit the main loop...\n");
|
||||
|
||||
Gtk::Main::quit();
|
||||
Gtk::Application::get_default()->quit();
|
||||
|
||||
// don't destroy main window here - we may be in one of its callbacks
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user