Save / load default window size and position (both for main window, size only

for info window).
This commit is contained in:
Alexander Shaduri
2017-08-26 12:09:51 +00:00
parent 6ab53c5436
commit 897a4efa96
6 changed files with 77 additions and 15 deletions
+1
View File
@@ -28,6 +28,7 @@ Bugs / patches:
TODO:
Implement PolKit support.
Remember window size / position (at least the main window size/pos and info size)
+24 -5
View File
@@ -174,6 +174,15 @@ GscInfoWindow::GscInfoWindow(BaseObjectType* gtkcobj, const app_ui_res_ref_t& re
: AppUIResWidget<GscInfoWindow, true>(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<Gtk::Box*>("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);
}
+3
View File
@@ -37,6 +37,9 @@ class GscInfoWindow : public AppUIResWidget<GscInfoWindow, true> {
virtual ~GscInfoWindow()
{ }
// Overridden from InstanceManager
virtual void obj_destroy();
/// Set the drive to show
void set_drive(StorageDeviceRefPtr d);
-1
View File
@@ -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();
+45 -9
View File
@@ -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();
}
+4
View File
@@ -123,6 +123,10 @@ class GscMainWindow : public AppUIResWidget<GscMainWindow, false> {
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