]> sigrok.org Git - pulseview.git/commitdiff
Confirm with user when trying to close sessions with unsaved data
authorSoeren Apel <redacted>
Thu, 19 Jan 2017 21:01:43 +0000 (22:01 +0100)
committerSoeren Apel <redacted>
Thu, 19 Jan 2017 21:01:43 +0000 (22:01 +0100)
pv/dialogs/storeprogress.cpp
pv/mainwindow.cpp
pv/session.cpp
pv/session.hpp
pv/storesession.cpp
pv/storesession.hpp

index bd99cbadcfed4cc4a18d6069fb13d83e9591455f..b9c87ee70f49ba433860ab3cfdcda15842d78cf7 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <QMessageBox>
 
 
 #include <QMessageBox>
 
+#include "pv/session.hpp"
+
 #include "storeprogress.hpp"
 
 using std::map;
 #include "storeprogress.hpp"
 
 using std::map;
@@ -42,6 +44,8 @@ StoreProgress::StoreProgress(const QString &file_name,
 {
        connect(&session_, SIGNAL(progress_updated()),
                this, SLOT(on_progress_updated()));
 {
        connect(&session_, SIGNAL(progress_updated()),
                this, SLOT(on_progress_updated()));
+       connect(&session_, SIGNAL(store_successful()),
+               &session, SLOT(on_data_saved()));
 }
 
 StoreProgress::~StoreProgress()
 }
 
 StoreProgress::~StoreProgress()
index 8aaa1635c737d376321b8ebcb9202572182cde98..4aeecb260466c6a0885951f94a687dbe132058dc 100644 (file)
@@ -477,8 +477,20 @@ std::shared_ptr<Session> MainWindow::get_tab_session(int index) const
 
 void MainWindow::closeEvent(QCloseEvent *event)
 {
 
 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()
 }
 
 QMenu* MainWindow::createPopupMenu()
@@ -681,11 +693,13 @@ void MainWindow::on_tab_changed(int index)
 
 void MainWindow::on_tab_close_requested(int index)
 {
 
 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);
 
        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);
 }
 
                remove_session(session);
 }
 
index 2e98c8f73f40c08a70f451c60716824a1b348bbb..fcd0e135b5a190972613e85ac79ada3f067b7023 100644 (file)
@@ -105,7 +105,8 @@ Session::Session(DeviceManager &device_manager, QString name) :
        default_name_(name),
        name_(name),
        capture_state_(Stopped),
        default_name_(name),
        name_(name),
        capture_state_(Stopped),
-       cur_samplerate_(0)
+       cur_samplerate_(0),
+       data_saved_(true)
 {
 }
 
 {
 }
 
@@ -172,6 +173,11 @@ shared_ptr<pv::toolbars::MainBar> Session::main_bar() const
        return main_bar_;
 }
 
        return main_bar_;
 }
 
+bool Session::data_saved() const
+{
+       return data_saved_;
+}
+
 void Session::save_settings(QSettings &settings) const
 {
        map<string, string> dev_info;
 void Session::save_settings(QSettings &settings) const
 {
        map<string, string> dev_info;
@@ -851,6 +857,13 @@ void Session::sample_thread_proc(function<void (const QString)> error_handler)
                assert(0);
        }
 
                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."));
 }
        if (out_of_memory_)
                error_handler(tr("Out of memory, acquisition stopped."));
 }
@@ -1064,4 +1077,9 @@ void Session::data_feed_in(shared_ptr<sigrok::Device> device,
        }
 }
 
        }
 }
 
+void Session::on_data_saved()
+{
+       data_saved_ = true;
+}
+
 } // namespace pv
 } // namespace pv
index bc1fbb0d68245f1ddef1c57df4de197ede46ac9a..0f067a47be1f8e2875467c976cd4424e616c046b 100644 (file)
@@ -119,6 +119,11 @@ public:
 
        void set_main_bar(std::shared_ptr<pv::toolbars::MainBar> main_bar);
 
 
        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);
        void save_settings(QSettings &settings) const;
 
        void restore_settings(QSettings &settings);
@@ -218,6 +223,7 @@ private:
        std::thread sampling_thread_;
 
        bool out_of_memory_;
        std::thread sampling_thread_;
 
        bool out_of_memory_;
+       bool data_saved_;
 
 Q_SIGNALS:
        void capture_state_changed(int state);
 
 Q_SIGNALS:
        void capture_state_changed(int state);
@@ -237,6 +243,9 @@ Q_SIGNALS:
 
        void add_view(const QString &title, views::ViewType type,
                Session *session);
 
        void add_view(const QString &title, views::ViewType type,
                Session *session);
+
+public Q_SLOTS:
+       void on_data_saved();
 };
 
 } // namespace pv
 };
 
 } // namespace pv
index 4167bdae69e0e174af32d5ecc993a35a1792ea4d..eaa17ea5f98096519f88f44be1373a8a697c171c 100644 (file)
@@ -300,6 +300,7 @@ void StoreSession::store_proc(vector< shared_ptr<data::SignalBase> > achannel_li
        // Zeroing the progress variables indicates completion
        units_stored_ = unit_count_ = 0;
 
        // Zeroing the progress variables indicates completion
        units_stored_ = unit_count_ = 0;
 
+       store_successful();
        progress_updated();
 
        output_.reset();
        progress_updated();
 
        output_.reset();
index 23e25ec8b4425053601ff0c7ba9c22498c58a321..e89b3fd209da4e488ae208cd5d47820e0a085692 100644 (file)
@@ -83,6 +83,8 @@ private:
 Q_SIGNALS:
        void progress_updated();
 
 Q_SIGNALS:
        void progress_updated();
 
+       void store_successful();
+
 private:
        const std::string file_name_;
        const std::shared_ptr<sigrok::OutputFormat> output_format_;
 private:
        const std::string file_name_;
        const std::shared_ptr<sigrok::OutputFormat> output_format_;