process.cc 8.53 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
37
38
39
 *   $Revision$                                                         *
 *   $Author$                                                      *
 *   $Date$                   *
Jan Möbius's avatar
Jan Möbius committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 *                                                                           *
\*===========================================================================*/




//=============================================================================
//
//  CLASS Core - IMPLEMENTATION
//
//=============================================================================


//== INCLUDES =================================================================

#include "Core.hh"

57
58
#include <OpenFlipper/widgets/processManagerWidget/BlockingWidget.hh>

Jan Möbius's avatar
Jan Möbius committed
59
60
61
62
//== IMPLEMENTATION ==========================================================


// A job has been started by a plugin
63
64
void Core::slotStartJob( QString _jobId, QString _description , int _min , int _max, bool _blocking) {
  std::cerr << "StartJob: " << _jobId.toStdString() << " " << _description.toStdString() << " " << _min << " " << _max  << " " << _blocking <<std::endl;
65
66

  // Create job information
67
  JobInfo* info        = new JobInfo();
68
  info->id             = _jobId;
69
  info->description    = _description;
70
71
72
  info->currentStep    =  0;
  info->minSteps       = _min;
  info->maxSteps       = _max;
73
  info->blocking       = _blocking;
74
75

  // Add job to local job list
76
  currentJobs.push_back(info);
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

  // Don't show process status in process manager
  // if blocking is enabled
  if(_blocking) {
	  // Create blocking widget
	  BlockingWidget* widget = new BlockingWidget(_jobId, _description,
			  _min, _max);

	  // Connect cancel buttons to local slot for further treatment
	  connect(widget, 	SIGNAL(cancelRequested(QString)),
	  		  this,     SLOT(slotJobCancelRequested(QString)));

	  info->blockingWidget = widget;

	  // Show blocking widget
	  widget->show();

  } else {
	  // Create process manager window if it has not been created before
	  if(!processManager_) {
		  processManager_ = new ProcessManagerWidget();
      
		  // Connect cancel buttons to local slot for further treatment
		  connect(processManager_, SIGNAL(cancelJobRequested(QString)),
				  this,            SLOT(slotJobCancelRequested(QString)));
	  }

	  // Add new item
	  processManager_->addJob(_jobId, _description, _min, _max);

	  // Show window
	  processManager_->show();
  }
110
111
112
113
114
115
}

//-----------------------------------------------------------------------------
bool Core::getJob(QString _jobId, int& _index) {
  
  for ( int i = 0 ; i < currentJobs.size() ; ++i) {
116
      if ( currentJobs[i]->id == _jobId ) {
117
118
119
120
121
122
123
124
        _index = i;
        return true;
      }
  }
  
  emit log(LOGERR,tr("Unable to find Job %1.").arg(_jobId));
  _index = -1;
  return false;
Jan Möbius's avatar
Jan Möbius committed
125
126
127
128
129
130
}

//-----------------------------------------------------------------------------

// A job state has been updated by a plugin
void Core::slotSetJobState(QString _jobId, int _value ) {
131
132
133
  int id;
  
  if (  getJob(_jobId, id) ) {
134
    currentJobs[id]->currentStep = _value;
135
136
137
138
139
140
141
142
143
144
145

    // Update gui
    if(!currentJobs[id]->blocking)
    	processManager_->updateStatus(_jobId, _value);
    else {
    	BlockingWidget* w = 0;
    	w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
    	if(w != 0) {
    		w->updateStatus(_value);
    	}
    }
146
  }
Jan Möbius's avatar
Jan Möbius committed
147
148
149
150
}

//-----------------------------------------------------------------------------

151
152
153
154
155
156
// A job's caption has been updated by a plugin
void Core::slotSetJobName(QString _jobId, QString _name ) {
    int id;
    
    if (  getJob(_jobId, id) ) {
        currentJobs[id]->id = _name;
157
158
159
160
161
162
163
164
165
166
167

        // Update gui
        if(!currentJobs[id]->blocking)
        	processManager_->setJobName(_jobId, _name);
        else {
           	BlockingWidget* w = 0;
           	w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
           	if(w != 0) {
           		w->setJobId(_name);
           	}
        }
168
169
170
171
172
173
174
175
176
177
    }
}
//-----------------------------------------------------------------------------

// A job's widget's status text has been updated by a plugin
void Core::slotSetJobDescription(QString _jobId, QString _text ) {
    int id;
    
    if (  getJob(_jobId, id) ) {
        currentJobs[id]->description = _text;
178
179
180
181
182
183
184
185
186
187
188

        // Update gui
        if(!currentJobs[id]->blocking)
        	processManager_->setJobDescription(_jobId, _text);
        else {
           	BlockingWidget* w = 0;
           	w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
            if(w != 0) {
            	w->setJobDescription(_text);
            }
        }
189
190
191
192
193
    }
}

//-----------------------------------------------------------------------------

Jan Möbius's avatar
Jan Möbius committed
194
195
// A job state has been canceled by a plugin
void Core::slotCancelJob(QString _jobId ) {
196
197
198
  int id;
  
  if (  getJob(_jobId, id) ) {
199
200
201
202
203
204
205
206
207
208
209
210
211
212

	// Update gui
	if(!currentJobs[id]->blocking)
		processManager_->removeJob(_jobId);
	else {
		BlockingWidget* w = 0;
		w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
		if(w != 0) {
			w->hide();
			delete w;
		}
	}

	currentJobs.removeAt(id);
213
  }
Jan Möbius's avatar
Jan Möbius committed
214
215
216
217
218
219
}

//-----------------------------------------------------------------------------

// A job state has been finished by a plugin
void Core::slotFinishJob(QString _jobId ) {
220
221
222
  int id;
  
  if (  getJob(_jobId, id) ) {
223
224
225
226
227
228
229
230
231
232
233
234
235

	// Update gui
	if(!currentJobs[id]->blocking)
		processManager_->removeJob(_jobId);
	else {
		BlockingWidget* w = 0;
		w = dynamic_cast<BlockingWidget*>(currentJobs[id]->blockingWidget);
		if(w != 0) {
			w->hide();
			delete w;
		}
	}

236
237
238
239
    currentJobs.removeAt(id);
  }
}

240
//-----------------------------------------------------------------------------
Jan Möbius's avatar
Jan Möbius committed
241

242
243
244
245
246
// A job has shall be canceled since the user pushed
// the cancel button
void Core::slotJobCancelRequested(QString /*_jobId*/) {
    
    // Cancel job still to be implemented...
247
	std::cerr << "Cancel requested!" << std::endl;
248
}
Jan Möbius's avatar
Jan Möbius committed
249
250

//=============================================================================