From 897a4efa96fc9ef4b1937c5524649a3f355339bb Mon Sep 17 00:00:00 2001 From: Alexander Shaduri Date: Sat, 26 Aug 2017 12:09:51 +0000 Subject: [PATCH] Save / load default window size and position (both for main window, size only for info window). --- gsmartcontrol/TODO | 1 + gsmartcontrol/src/gsc_info_window.cpp | 29 +++++++++++--- gsmartcontrol/src/gsc_info_window.h | 3 ++ gsmartcontrol/src/gsc_init.cpp | 1 - gsmartcontrol/src/gsc_main_window.cpp | 54 ++++++++++++++++++++++----- gsmartcontrol/src/gsc_main_window.h | 4 ++ 6 files changed, 77 insertions(+), 15 deletions(-) diff --git a/gsmartcontrol/TODO b/gsmartcontrol/TODO index 5480bc6..3f2c81f 100644 --- a/gsmartcontrol/TODO +++ b/gsmartcontrol/TODO @@ -28,6 +28,7 @@ Bugs / patches: TODO: +Implement PolKit support. Remember window size / position (at least the main window size/pos and info size) diff --git a/gsmartcontrol/src/gsc_info_window.cpp b/gsmartcontrol/src/gsc_info_window.cpp index c1a7099..a9c5c83 100644 --- a/gsmartcontrol/src/gsc_info_window.cpp +++ b/gsmartcontrol/src/gsc_info_window.cpp @@ -174,6 +174,15 @@ GscInfoWindow::GscInfoWindow(BaseObjectType* gtkcobj, const app_ui_res_ref_t& re : AppUIResWidget(gtkcobj, ref_ui), device_name_label(0), test_force_bar_update(true) { + // Size + { + int def_size_w = 0, def_size_h = 0; + rconfig::get_data("gui/info_window/default_size_w", def_size_w); + rconfig::get_data("gui/info_window/default_size_h", def_size_h); + if (def_size_w > 0 && def_size_h > 0) { + set_default_size(def_size_w, def_size_h); + } + } // Create missing widgets Gtk::Box* device_name_hbox = lookup_widget("device_name_label_hbox"); @@ -270,6 +279,20 @@ GscInfoWindow::GscInfoWindow(BaseObjectType* gtkcobj, const app_ui_res_ref_t& re +void GscInfoWindow::obj_destroy() +{ + // Main window size. We don't store position to avoid overlaps + { + int window_w = 0, window_h = 0; + get_size(window_w, window_h); + rconfig::set_data("gui/info_window/default_size_w", window_w); + rconfig::set_data("gui/info_window/default_size_h", window_h); + } + +} + + + void GscInfoWindow::set_drive(StorageDeviceRefPtr d) { if (drive) // if an old drive is present, disconnect our callback from it. @@ -1399,11 +1422,7 @@ void GscInfoWindow::on_save_info_button_clicked() void GscInfoWindow::on_close_window_button_clicked() { - if (drive && drive->get_test_is_active()) { // disallow close if test is active. - gui_show_warn_dialog("Please wait until all tests are finished.", this); - return; - } - destroy(this); + on_delete_event_before(0); } diff --git a/gsmartcontrol/src/gsc_info_window.h b/gsmartcontrol/src/gsc_info_window.h index 0135837..e9fbcec 100644 --- a/gsmartcontrol/src/gsc_info_window.h +++ b/gsmartcontrol/src/gsc_info_window.h @@ -37,6 +37,9 @@ class GscInfoWindow : public AppUIResWidget { virtual ~GscInfoWindow() { } + // Overridden from InstanceManager + virtual void obj_destroy(); + /// Set the drive to show void set_drive(StorageDeviceRefPtr d); diff --git a/gsmartcontrol/src/gsc_init.cpp b/gsmartcontrol/src/gsc_init.cpp index 426bfef..7888458 100644 --- a/gsmartcontrol/src/gsc_init.cpp +++ b/gsmartcontrol/src/gsc_init.cpp @@ -512,7 +512,6 @@ bool app_init_and_loop(int& argc, char**& argv) m.run(); debug_out_info("app", "Main loop exited.\n"); - // close the main window and delete its object GscMainWindow::destroy(); diff --git a/gsmartcontrol/src/gsc_main_window.cpp b/gsmartcontrol/src/gsc_main_window.cpp index 3a04bcf..ec03a8e 100644 --- a/gsmartcontrol/src/gsc_main_window.cpp +++ b/gsmartcontrol/src/gsc_main_window.cpp @@ -56,9 +56,29 @@ GscMainWindow::GscMainWindow(BaseObjectType* gtkcobj, const app_ui_res_ref_t& re // iconview, gtkuimanager stuff (menus), custom labels create_widgets(); + // Size + { + int def_size_w = 0, def_size_h = 0; + rconfig::get_data("gui/main_window/default_size_w", def_size_w); + rconfig::get_data("gui/main_window/default_size_h", def_size_h); + if (def_size_w > 0 && def_size_h > 0) { + set_default_size(def_size_w, def_size_h); + } + } + // show the window first, scan later show(); + // Position (after the window has been shown) + { + int pos_x = 0, pos_y = 0; + rconfig::get_data("gui/main_window/default_pos_x", pos_x); + rconfig::get_data("gui/main_window/default_pos_y", pos_y); + if (pos_x > 0 && pos_y > 0) { // to avoid situations where positions are not supported + this->move(pos_x, pos_y); + } + } + while (Gtk::Main::events_pending()) // allow the window to show Gtk::Main::iteration(); @@ -502,13 +522,7 @@ void GscMainWindow::on_action_activated(GscMainWindow::action_t action_type) switch (action_type) { case action_quit: - // if at least one drive is having a test performed, disallow. - if (this->testing_active()) { - if (!ask_about_quit_on_test(*this)) { - break; - } - } - app_quit(); // ends the main loop + quit_requested(); break; case action_view_details: @@ -1333,8 +1347,7 @@ void GscMainWindow::show_load_virtual_file_chooser() -// by default, delete_event calls hide(). -bool GscMainWindow::on_delete_event_before(GdkEventAny* e) +bool GscMainWindow::quit_requested() { // if at least one drive is having a test performed, disallow. if (this->testing_active()) { @@ -1342,12 +1355,35 @@ bool GscMainWindow::on_delete_event_before(GdkEventAny* e) return true; // handled } } + + // window size / pos + { + int window_w = 0, window_h = 0; + get_size(window_w, window_h); + rconfig::set_data("gui/main_window/default_size_w", window_w); + rconfig::set_data("gui/main_window/default_size_h", window_h); + + int pos_x = 0, pos_y = 0; + get_position(pos_x, pos_y); + rconfig::set_data("gui/main_window/default_pos_x", pos_x); + rconfig::set_data("gui/main_window/default_pos_y", pos_y); + } + app_quit(); // ends the main loop + return true; // event handled, don't call default virtual handler } +// by default, delete_event calls hide(). +bool GscMainWindow::on_delete_event_before(GdkEventAny* e) +{ + return quit_requested(); +} + + + diff --git a/gsmartcontrol/src/gsc_main_window.h b/gsmartcontrol/src/gsc_main_window.h index 26b7a7f..bbfc918 100644 --- a/gsmartcontrol/src/gsc_main_window.h +++ b/gsmartcontrol/src/gsc_main_window.h @@ -123,6 +123,10 @@ class GscMainWindow : public AppUIResWidget { void show_load_virtual_file_chooser(); + /// Called when quit has been requested (by delete event or Quit action) + bool quit_requested(); + + // -------------------- callbacks // ---------- overriden virtual methods