#include <QMessageBox>
+#include "pv/session.hpp"
+
#include "storeprogress.hpp"
using std::map;
{
connect(&session_, SIGNAL(progress_updated()),
this, SLOT(on_progress_updated()));
+ connect(&session_, SIGNAL(store_successful()),
+ &session, SLOT(on_data_saved()));
}
StoreProgress::~StoreProgress()
void MainWindow::closeEvent(QCloseEvent *event)
{
- save_ui_settings();
- event->accept();
+ bool data_saved = true;
+
+ for (auto entry : session_windows_)
+ if (!entry.first->data_saved())
+ data_saved = false;
+
+ if (!data_saved && (QMessageBox::question(this, tr("Confirmation"),
+ tr("There is unsaved data. Close anyway?"),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)) {
+ event->ignore();
+ } else {
+ save_ui_settings();
+ event->accept();
+ }
}
QMenu* MainWindow::createPopupMenu()
void MainWindow::on_tab_close_requested(int index)
{
- // TODO Ask user if this is intended in case data is unsaved
-
shared_ptr<Session> session = get_tab_session(index);
- if (session)
+ assert(session);
+
+ if (session->data_saved() || (QMessageBox::question(this, tr("Confirmation"),
+ tr("This session contains unsaved data. Close it anyway?"),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes))
remove_session(session);
}
default_name_(name),
name_(name),
capture_state_(Stopped),
- cur_samplerate_(0)
+ cur_samplerate_(0),
+ data_saved_(true)
{
}
return main_bar_;
}
+bool Session::data_saved() const
+{
+ return data_saved_;
+}
+
void Session::save_settings(QSettings &settings) const
{
map<string, string> dev_info;
assert(0);
}
+ // We now have unsaved data unless we just "captured" from a file
+ shared_ptr<devices::File> file_device =
+ dynamic_pointer_cast<devices::File>(device_);
+
+ if (!file_device)
+ data_saved_ = false;
+
if (out_of_memory_)
error_handler(tr("Out of memory, acquisition stopped."));
}
}
}
+void Session::on_data_saved()
+{
+ data_saved_ = true;
+}
+
} // namespace pv
void set_main_bar(std::shared_ptr<pv::toolbars::MainBar> main_bar);
+ /**
+ * Indicates whether the captured data was saved to disk already or not
+ */
+ bool data_saved() const;
+
void save_settings(QSettings &settings) const;
void restore_settings(QSettings &settings);
std::thread sampling_thread_;
bool out_of_memory_;
+ bool data_saved_;
Q_SIGNALS:
void capture_state_changed(int state);
void add_view(const QString &title, views::ViewType type,
Session *session);
+
+public Q_SLOTS:
+ void on_data_saved();
};
} // namespace pv
// Zeroing the progress variables indicates completion
units_stored_ = unit_count_ = 0;
+ store_successful();
progress_updated();
output_.reset();
Q_SIGNALS:
void progress_updated();
+ void store_successful();
+
private:
const std::string file_name_;
const std::shared_ptr<sigrok::OutputFormat> output_format_;