Commits

Leyorus committed 149d456

Add some message dialog to secure extraction cancel

Comments (0)

Files changed (2)

src/gtk-gui/MainWindow.cpp

 #include <sys/wait.h>
 #include <gtkmm/image.h>
 #include <glibmm/refptr.h>
+#include <gtkmm/messagedialog.h>
 
 #include <sys/time.h> // for gettimeofday() function
 
 			extractOrPauseButton("Extract"),
 			cancelButton(Gtk::Stock::CANCEL)
 {
-	this->set_title("MkvExtract-Gtk hello world vim !");
+	this->set_title("MkvExtract-Gtk");
 	this->signal_delete_event().connect(sigc::mem_fun(this, &MainWindow::onCloseButton));
 	this->set_border_width(10);
 	this->set_size_request(500,350);
 	cancelButton.set_can_focus(false);
 	cancelButton.set_sensitive(false);
 
+	progressBar.set_show_text(true);
+
 	this->show_all();
 
 	current_state = stop_status;
 	return name;
 }
 
-void MainWindow::stopExtraction()
-{
-    kill(this->extractionProcess_pid, SIGKILL);
-    setExtractionStatus(stop_status);
-    onExtractionEnd();
+bool MainWindow::stopExtraction() {
+
+	Gtk::MessageDialog dialog(*this, "Extraction process is currently running.",
+			false /* use_markup */, Gtk::MESSAGE_QUESTION,
+			Gtk::BUTTONS_OK_CANCEL);
+
+	dialog.set_secondary_text("Are you sure you want to cancel the extraction ?");
+	int result = dialog.run();
+
+	switch (result) {
+	case (Gtk::RESPONSE_OK):
+		kill(this->extractionProcess_pid, SIGKILL);
+		disableTimer();
+		setExtractionStatus(stop_status);
+		onExtractionEnd(false);
+		return true;
+		break;
+	case (Gtk::RESPONSE_CANCEL):
+		break;
+	default:
+		break;
+	}
+	return false;
 }
 
 void MainWindow::pauseExtraction()
 
 
 void MainWindow::enableTimer() {
-	sigc::connection con = Glib::signal_timeout().connect(sigc::mem_fun(*this, &MainWindow::onTimeOut), 500);
+	con = Glib::signal_timeout().connect(sigc::mem_fun(*this, &MainWindow::onTimeOut), 500);
+}
+
+void MainWindow::disableTimer() {
+	con.disconnect();
 }
 
 bool MainWindow::onTimeOut() {
 		updateProgress(); // return true = continue timer
 		break;
 	case stop_status:
-		onExtractionEnd();
+		onExtractionEnd(true);
 		ret = false; // disconnect timer
 		break;
 	}
 	progressBar.set_text(Core::toString(progress_percentage)+ "%, Time elapsed = " + readableTime(time_elapsed) +", Time remaining = " + readableTime(remainingTime));
 }
 
-void MainWindow::onExtractionEnd() {
+void MainWindow::onExtractionEnd(bool extractionSuccess) {
 	extractOrPauseButton.set_label("Extract");
 	cancelButton.set_sensitive(false);
 	extractOrPauseButton.set_image(*Gtk::manage (new Gtk::Image (Gtk::Stock::CONVERT, Gtk::ICON_SIZE_BUTTON)));
 
 bool MainWindow::onCloseButton(GdkEventAny * ev) {
 	if (isExtracting()) {
-		this->stopExtraction();
+
+		if (!stopExtraction()) {
+			return true;
+		}
 	}
 	return false;
 }

src/gtk-gui/MainWindow.h

 #include <gtkmm/progressbar.h>
 #include <gtkmm/buttonbox.h>
 #include <gtkmm/scrolledwindow.h>
+#include <gtkmm/label.h>
 
 
 #include <core/Common.h>
 	int time_elapsed;
 	int remainingTime;
 	timeval lastStartTime;
+	sigc::connection con;
 
 	void startExtraction();
-	void stopExtraction();
+	bool stopExtraction();
 	void pauseExtraction();
 	void continueExtraction();
 	void enableTimer();
+	void disableTimer();
     void onFileSet();
 	void printTracksInfos(std::vector<Core::track_info_t> tracks);
 	void updateProgress();
-	void onExtractionEnd();
+	void onExtractionEnd(bool extractionSuccess);
 	void onCheckboxClicked(Glib::ustring path);
 	void onExtractOrPauseButton();
 	void onCancelButton();