Commit fe0500b8 authored by Johnny Jazeix's avatar Johnny Jazeix
Browse files

Bouton annuler pour la barre de progression

parent 9d772b35
......@@ -111,55 +111,75 @@ bool Interface_console::draw_trace(const string & filename, const int format){
svg.init(_path_to_export.c_str());
if (NULL == _trace){ /* no trace is loaded, parse the file */
if (NULL == _trace) { /* no trace is loaded, parse the file */
_trace = new Trace();
// Init of the thread
parsing_thread thread;
thread.init(&parser, _trace, filename);
_progress_dialog = new QProgressDialog("Parsing", "Cancel", 0, 100, _main_window);
_progress_dialog->show();
thread.start();
int loaded = 0;
_main_window->setDisabled (true);
if(_main_window != NULL) { // If we have a window we show a progress bar
_progress_dialog = new QProgressDialog("Parsing", "Cancel", 0, 100, _main_window);
_progress_dialog->setWindowTitle(QString::fromStdString("Loading of "+filename));
_progress_dialog->show();
_main_window->setDisabled(true);
_progress_dialog->setDisabled(false); // to be able to cancel while parsing
}
thread.start();
while(!parser.is_end_of_parsing()) {
loaded = parser.get_size_loaded();
sleep(1); // We wait 1 second
update_progress_bar(loaded);
QApplication::processEvents();
std::cout << "Loading of the trace : " << loaded << "%" << std::endl;
cout << "Loading of the trace : " << loaded << "%" << endl;
if(_main_window != NULL) { // If we have a window we show a progress bar
update_progress_bar(loaded);
QApplication::processEvents();
if(_progress_dialog->wasCanceled()) {
cout << "Canceled at " << loaded << "%" << endl;
parser.set_canceled();
*Message::get_instance() << "The trace opening was canceled by the user at " << loaded << "%" << Message::ende;
break; // Quit the loop
}
}
}
((ParserPaje)parser).reinit_cursor();
parser.reinit_cursor();
Error::print_numbers();
Error::flush("log.txt");
delete _progress_dialog;
_main_window->setDisabled (false);
// Wait for the end thread
if(_main_window != NULL) { // If we have a window we show a progress bar
delete _progress_dialog;
_main_window->setDisabled (false);
}
// Wait for the end of the thread
while(!thread.isFinished()) {
}
}
else if ( _file_opened != filename){/* just check if execution is normal */
else if ( _file_opened != filename) {/* just check if execution is normal */
*Message::get_instance() << "Try to use file: " << filename << " instead of a previous parsed file: " << _file_opened << Message::ende;
}
Interval interval(_time_start, ((0==_time_end)?_trace->get_max_date():_time_end) );
if (_DRAW_OPENGL == format){
if (_DRAW_OPENGL == format) {
drawing_ogl.build(_render_opengl, _trace, 0, interval);
_render_opengl->build();
_render_opengl->updateGL();
_render_opengl->refresh_scroll_bars();
_file_opened = filename;/* store filename for a future export */
}else if (_DRAW_SVG == format){
}else if (_DRAW_SVG == format) {
drawing_svg.build(&svg, _trace, 0, interval);
svg.end();
}else{/* error */
......
......@@ -13,5 +13,4 @@ void parsing_thread::run() {
catch (const std::string &error) {
((ParserPaje *)_parser)->finish();
}
}
......@@ -4,10 +4,10 @@ using namespace std;
ParserPaje::ParserPaje(){
_is_finished = false;
_is_canceled = false;
}
void ParserPaje::parse(string filename, Trace &trace){
_is_finished = false;
const unsigned int position_of_dot = filename.find_last_of('.');
if(position_of_dot == string::npos || filename.substr(position_of_dot) != ".trace"){
......@@ -23,7 +23,7 @@ void ParserPaje::parse(string filename, Trace &trace){
string event_identity_string;
unsigned int event_identity;
while(!line.is_eof()) {
while(!(line.is_eof() || _is_canceled)) {
line.newline();
if(line.starts_with(PERCENT)) {
......@@ -51,7 +51,6 @@ void ParserPaje::parse(string filename, Trace &trace){
trace);
}
}
finish();
trace.finish();
......@@ -80,3 +79,7 @@ bool ParserPaje::is_end_of_parsing() const{
void ParserPaje::finish() {
_is_finished = true;
}
void ParserPaje::set_canceled() {
_is_canceled = true;
}
......@@ -35,6 +35,7 @@ class ParserPaje : public Parser{
private:
std::string _file_to_parse;
bool _is_finished;
bool _is_canceled;
public:
......@@ -85,6 +86,11 @@ public:
*/
void finish();
/*!
* \fn set_canceled()
* \brief called when the loading of the trace is canceled by the user
*/
void set_canceled();
};
#endif // PARSERPAJE_HPP
......
......@@ -32,6 +32,10 @@ TokenSource::~TokenSource(){
_buffer = NULL;
close(_fd);
#endif
if (!_token.empty()) {
_token.clear();
}
}
void TokenSource::open(const char *filename){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment