1. Leyorus
  2. MkvExtract-Gtk

Commits

Leyorus  committed 83d6245

Handle extraction process error

  • Participants
  • Parent commits 2d4bbcf
  • Branches master

Comments (0)

Files changed (2)

File src/gtk-gui/MainWindow.cpp

View file
  • Ignore whitespace
 			labelBox(true),
 			labelTable(1,2,true),
 			commandLineFrame(commandLineFrameName),
+			askedCancel(false),
 			verbose(false)
 {
     /* force using icons on stock buttons: */
 
 	current_state = stop_status;
 	pthread_mutex_init(&extraction_status_mutex, 0);
+	pthread_mutex_init(&bool_askedCancel_mutex, 0);
 }
 
 void MainWindow::printTracksInfos(std::vector<Core::track_info_t> tracks) {
 			}
 
 		}
-		setExtractionStatus(MainWindow::stop_status);
+		int exec_status;
+		waitpid(getExtractionProcessPID(), &exec_status, 0);
+		if (WIFEXITED(exec_status)){
+			setExtractionStatus(MainWindow::stop_status);
+		} else {
+				pthread_mutex_lock(&bool_askedCancel_mutex);
+				if (! askedCancel) {
+					setExtractionStatus(MainWindow::extraction_error);
+				} else {
+					askedCancel = false;
+					setExtractionStatus(MainWindow::stop_status);
+				}
+				pthread_mutex_unlock(&bool_askedCancel_mutex);
+		}
 	}
 }
 
 
 	switch (result) {
 	case (Gtk::RESPONSE_OK):
+		pthread_mutex_lock(&bool_askedCancel_mutex);
+		askedCancel = true;
+		pthread_mutex_unlock(&bool_askedCancel_mutex);
 		kill(this->extractionProcess_pid, SIGKILL);
 		disableTimer();
 		setExtractionStatus(stop_status);
 		onExtractionEnd(true);
 		ret = false; // disconnect timer
 		break;
+	case extraction_error:
+		onExtractionEnd(false);
+		ret = false; // disconnect timer
 	}
 	return ret;
 }
 }
 
 void MainWindow::onExtractionEnd(bool extractionSuccess) {
+	if (extractionSuccess) {
+		Gtk::MessageDialog dialog(*this, _("Extraction success !"));
+		dialog.set_secondary_text(std::string(_("Extraction done in")) + " " +readableTime(time_elapsed));
+		dialog.run();
+	} else {
+		if (current_state == MainWindow::extraction_error) {
+			Gtk::MessageDialog dialog(*this, _("Extraction error !"), false, Gtk::MESSAGE_ERROR);
+			dialog.set_secondary_text(_("Error occured during extraction."));
+			dialog.run();
+		}
+	}
+
 	this->set_title(mainWindowTitle);
 	extractOrPauseButton.set_label(extractButtonText);
 	cancelButton.set_sensitive(false);
 	labelStatus.set_text(statusLabelTextChooseTracks);
 	labelElapsedTime.set_visible(false);
 	labelRemainingTime.set_visible(false);
-	if (extractionSuccess) {
-		Gtk::MessageDialog dialog(*this, _("Extraction success !"));
-		dialog.set_secondary_text(std::string(_("Extraction done in")) + " " +readableTime(time_elapsed));
-		dialog.run();
-	} else {
 
-	}
 	checkUserSelection();
 }
 
 	case paused_status:
 		continueExtraction();
 		break;
+	case extraction_error:
 	case stop_status:
 		startExtraction();
 		break;

File src/gtk-gui/MainWindow.h

View file
  • Ignore whitespace
 #include <map>
 #include <pthread.h>
 
-
 class ModelColumns: public Gtk::TreeModelColumnRecord {
 public:
 
 
 	std::map<int,bool> tracksToExtract;
 
-	typedef enum {extracting_status, stop_status, paused_status} extraction_status_t;
+	typedef enum {extracting_status, stop_status, paused_status, extraction_error} extraction_status_t;
 	extraction_status_t current_state;
-
 	pthread_mutex_t extraction_status_mutex;
+
 	pthread_t extraction_thread;
 	pid_t extractionProcess_pid;
 
+	pthread_mutex_t bool_askedCancel_mutex;
+	bool askedCancel;
+
 	int progress_percentage;
 	int time_elapsed;
 	int remainingTime;