From 0fedc62c25cd712953bbea2ba20e88fdd74a1198 Mon Sep 17 00:00:00 2001 From: Alexander Shaduri Date: Wed, 12 Jan 2022 17:39:59 +0400 Subject: [PATCH] Fixes for github actions (autotools). --- src/gsc_main_window.cpp | 4 ++++ src/gsc_main_window_iconview.h | 30 +++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/gsc_main_window.cpp b/src/gsc_main_window.cpp index d6423fa..743d1a1 100644 --- a/src/gsc_main_window.cpp +++ b/src/gsc_main_window.cpp @@ -1203,6 +1203,10 @@ bool GscMainWindow::testing_active() const GscInfoWindow* GscMainWindow::show_device_info_window(StorageDeviceRefPtr drive) { + if (!drive) { + return 0; + } + // if a test is being run on it, disallow. if (drive->get_test_is_active()) { gui_show_warn_dialog("Please wait until the test is finished on this drive.", this); diff --git a/src/gsc_main_window_iconview.h b/src/gsc_main_window_iconview.h index 81e2857..f27e61b 100644 --- a/src/gsc_main_window_iconview.h +++ b/src/gsc_main_window_iconview.h @@ -69,6 +69,8 @@ class GscMainWindowIconView : public Gtk::IconView { columns.add(col_drive_ptr); + columns.add(col_populated); + // create a Tree Model ref_list_model = Gtk::ListStore::create(columns); // ref_list_model->set_sort_column(col_name, Gtk::SORT_ASCENDING); @@ -207,6 +209,10 @@ class GscMainWindowIconView : public Gtk::IconView { void on_cell_data_render(const Gtk::TreeModel::const_iterator& iter) { Gtk::TreeRow row = *iter; + if (!row[col_populated]) { // protect against rendering incomplete model entry + return; + } + Glib::RefPtr pixbuf = row[col_pixbuf]; // Gtkmm property_surface() doesn't work, so use plain C. @@ -241,6 +247,8 @@ class GscMainWindowIconView : public Gtk::IconView { this->decorate_entry(row); + row[col_populated] = true; // triggers rendering + drive->signal_changed.connect(sigc::mem_fun(this, &GscMainWindowIconView::on_drive_changed)); if (scroll_to_it) { @@ -279,6 +287,9 @@ class GscMainWindowIconView : public Gtk::IconView { void decorate_entry(Gtk::TreeModel::Row& row) { StorageDeviceRefPtr drive = row[col_drive_ptr]; + if (!drive) { + return; + } // it needs this space to be symmetric (why?); std::string name; // = "" + drive->get_device_with_type() + " \n"; @@ -473,8 +484,11 @@ class GscMainWindowIconView : public Gtk::IconView { } else { // enable drives menu, set proper smart toggles Gtk::TreePath model_path = *(this->get_selected_items().begin()); Gtk::TreeModel::Row row = *(ref_list_model->get_iter(model_path)); - StorageDeviceRefPtr drive = row[col_drive_ptr]; + if (!row[col_populated]) { // protect against using incomplete model entry + return; + } + StorageDeviceRefPtr drive = row[col_drive_ptr]; main_window->set_drive_menu_status(drive); } } @@ -488,8 +502,11 @@ class GscMainWindowIconView : public Gtk::IconView { return; Gtk::TreeModel::Row row = *(ref_list_model->get_iter(model_path)); - StorageDeviceRefPtr drive = row[col_drive_ptr]; + if (!row[col_populated]) { // protect against using incomplete model entry + return; + } + StorageDeviceRefPtr drive = row[col_drive_ptr]; main_window->show_device_info_window(drive); } @@ -536,9 +553,11 @@ class GscMainWindowIconView : public Gtk::IconView { this->unselect_all(); // unselect on empty area right-click } - Gtk::Menu* menu = main_window->get_popup_menu(drive); - if (menu) - menu->popup(event_button->button, event_button->time); + if (drive) { + Gtk::Menu* menu = main_window->get_popup_menu(drive); + if (menu) + menu->popup(event_button->button, event_button->time); + } return true; // stop handling } @@ -568,6 +587,7 @@ class GscMainWindowIconView : public Gtk::IconView { Gtk::TreeModelColumn col_description; ///< Model column Gtk::TreeModelColumn > col_pixbuf; ///< Model column Gtk::TreeModelColumn col_drive_ptr; ///< Model column + Gtk::TreeModelColumn col_populated; ///< Model column, indicates whether the model entry has been fully populated. Glib::RefPtr ref_list_model; ///< The icon view model unsigned int num_icons; ///< Track the number of icons, because liststore makes it difficult to count them.