Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
process.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //=============================================================================
54 //
55 // CLASS Core - IMPLEMENTATION
56 //
57 //=============================================================================
58 
59 
60 //== INCLUDES =================================================================
61 
62 #include "Core.hh"
63 
64 #include <OpenFlipper/widgets/processManagerWidget/BlockingWidget.hh>
65 
66 //== IMPLEMENTATION ==========================================================
67 
68 
69 // A job has been started by a plugin
70 void Core::slotStartJob( QString _jobId, QString _description , int _min , int _max, bool _blocking) {
71  std::cerr << "StartJob: " << _jobId.toStdString() << " " << _description.toStdString() << " " << _min << " " << _max << " " << _blocking <<std::endl;
72 
73  // Create job information
74  JobInfo info;
75  info.id = _jobId;
76  info.description = _description;
77  info.currentStep = 0;
78  info.minSteps = _min;
79  info.maxSteps = _max;
80  info.blocking = _blocking;
81  info.blockingWidget = 0;
82 
83 
84 
85  if (OpenFlipper::Options::gui()) {
86  // Don't show process status in process manager
87  // if blocking is enabled
88  if(_blocking) {
89  // Create blocking widget
90  BlockingWidget* widget = new BlockingWidget(_jobId, _description,
91  _min, _max);
92 
93  // Connect cancel button to local slot for further treatment
94  connect(widget, SIGNAL(cancelRequested(QString)),
95  this, SLOT(slotJobCancelRequested(QString)));
96 
97  info.blockingWidget = widget;
98 
99  int x = (coreWidget_->width() / 2) - (widget->width() / 2);
100  int y = (coreWidget_->height() / 2) - (widget->height() / 2);
101 
102  widget->setGeometry( x, y, widget->width(), widget->height());
103 
104  // Show blocking widget
105  widget->show();
106 
107  } else {
108  // Create process manager window if it has not been created before
109  if(!processManager_) {
111 
112  // Connect cancel buttons to local slot for further treatment
113  connect(processManager_, SIGNAL(cancelJobRequested(QString)),
114  this, SLOT(slotJobCancelRequested(QString)));
115  }
116 
117  // Add new item
118  processManager_->addJob(_jobId, _description, _min, _max);
119 
120  // Show window
121  processManager_->show();
122  }
123  }
124 
125  // Add job to local job list
126  currentJobs.push_back(info);
127 }
128 
129 //-----------------------------------------------------------------------------
130 bool Core::getJob(QString _jobId, int& _index) {
131 
132  for ( int i = 0 ; i < currentJobs.size() ; ++i) {
133  if ( currentJobs[i].id == _jobId ) {
134  _index = i;
135  return true;
136  }
137  }
138 
139  emit log(LOGERR,tr("Unable to find Job %1.").arg(_jobId));
140  _index = -1;
141  return false;
142 }
143 
144 //-----------------------------------------------------------------------------
145 
146 // A job state has been updated by a plugin
147 void Core::slotSetJobState(QString _jobId, int _value ) {
148  int id;
149 
150  if ( getJob(_jobId, id) ) {
151  currentJobs[id].currentStep = _value;
152 
153  if (!OpenFlipper::Options::gui())
154  return;
155  // Update gui
156  if(!currentJobs[id].blocking)
157  processManager_->updateStatus(_jobId, _value);
158  else {
159  BlockingWidget* w = 0;
160  w = dynamic_cast<BlockingWidget*>(currentJobs[id].blockingWidget);
161  if(w != 0) {
162  w->updateStatus(_value);
163  }
164  }
165  }
166 }
167 
168 //-----------------------------------------------------------------------------
169 
170 // A job's caption has been updated by a plugin
171 void Core::slotSetJobName(QString _jobId, QString _name ) {
172  int id;
173 
174  if ( getJob(_jobId, id) ) {
175  currentJobs[id].id = _name;
176 
177  if (!OpenFlipper::Options::gui())
178  return;
179  // Update gui
180  if(!currentJobs[id].blocking)
181  processManager_->setJobName(_jobId, _name);
182  else {
183  BlockingWidget* w = 0;
184  w = dynamic_cast<BlockingWidget*>(currentJobs[id].blockingWidget);
185  if(w != 0) {
186  w->setJobId(_name);
187  }
188  }
189  }
190 }
191 //-----------------------------------------------------------------------------
192 
193 // A job's widget's status text has been updated by a plugin
194 void Core::slotSetJobDescription(QString _jobId, QString _text ) {
195  int id;
196 
197  if ( getJob(_jobId, id) ) {
198  currentJobs[id].description = _text;
199 
200  if (!OpenFlipper::Options::gui())
201  return;
202  // Update gui
203  if(!currentJobs[id].blocking)
204  processManager_->setJobDescription(_jobId, _text);
205  else {
206  BlockingWidget* w = 0;
207  w = dynamic_cast<BlockingWidget*>(currentJobs[id].blockingWidget);
208  if(w != 0) {
209  w->setJobDescription(_text);
210  }
211  }
212  }
213 }
214 
215 //-----------------------------------------------------------------------------
216 
217 // A job state has been canceled by a plugin
218 void Core::slotCancelJob(QString _jobId ) {
219  int id;
220 
221  if ( getJob(_jobId, id) ) {
222 
223  if (OpenFlipper::Options::gui()) {
224  // Update gui
225  if(!currentJobs[id].blocking)
226  processManager_->removeJob(_jobId);
227  else {
228  BlockingWidget* w = 0;
229  w = dynamic_cast<BlockingWidget*>(currentJobs[id].blockingWidget);
230  if(w != 0) {
231  w->hide();
232  delete w;
233  }
234  }
235  }
236 
237  currentJobs.removeAt(id);
238  }
239 }
240 
241 //-----------------------------------------------------------------------------
242 
243 // A job state has been finished by a plugin
244 void Core::slotFinishJob(QString _jobId ) {
245  int id;
246 
247  if ( getJob(_jobId, id) ) {
248 
249  if (OpenFlipper::Options::gui()) {
250  // Update gui
251  if(!currentJobs[id].blocking) {
252  processManager_->removeJob(_jobId);
253 
254  // Hide widget if there's no job left
255  if(processManager_->getNumJobs() == 0) processManager_->hide();
256 
257  } else {
258  BlockingWidget* w = 0;
259  w = dynamic_cast<BlockingWidget*>(currentJobs[id].blockingWidget);
260  if(w != 0) {
261  w->hide();
262  delete w;
263  }
264  }
265  }
266 
267  currentJobs.removeAt(id);
268  }
269 }
270 
271 //-----------------------------------------------------------------------------
272 
273 // A job will be canceled by user request
274 void Core::slotJobCancelRequested(QString _jobId ) {
275 
276  std::cerr << "Cancel requested!" << std::endl;
277 
278  emit jobCanceled(_jobId);
279  // Cancel job still to be implemented...
280 
281 }
282 
283 //=============================================================================
void jobCanceled(QString _jobId)
A job has been started by a plugin.
bool getJob(QString _jobId, int &_index)
Find a job in the jobslist.
Definition: process.cc:130
void slotCancelJob(QString _jobId)
A job state has been canceled by a plugin.
Definition: process.cc:218
void slotFinishJob(QString _jobId)
A job state has been finished by a plugin.
Definition: process.cc:244
void slotStartJob(QString _jobId, QString _description, int _min, int _max, bool _blocking)
A job has been started by a plugin.
Definition: process.cc:70
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
Job Information class.
Definition: JobInfo.hh:65
ProcessManagerWidget * processManager_
A job has been started by a plugin.
Definition: Core.hh:1446
void slotSetJobDescription(QString _jobId, QString _text)
A job's widget's status text has been updated by a plugin.
Definition: process.cc:194
CoreWidget * coreWidget_
The main applications widget ( only created in gui mode )
Definition: Core.hh:1553
QList< JobInfo > currentJobs
A job has been started by a plugin.
Definition: Core.hh:1444
void slotSetJobState(QString _jobId, int _value)
A job state has been updated by a plugin.
Definition: process.cc:147
void slotSetJobName(QString _jobId, QString _name)
A job's widget caption has been updated by a plugin.
Definition: process.cc:171
void slotJobCancelRequested(QString _jobId)
Called by dialogs if cancel button is pressed.
Definition: process.cc:274