Developer Documentation
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 
45 
46 
47 //=============================================================================
48 //
49 // CLASS Core - IMPLEMENTATION
50 //
51 //=============================================================================
52 
53 
54 //== INCLUDES =================================================================
55 
56 #include "Core.hh"
57 
58 #include <OpenFlipper/widgets/processManagerWidget/BlockingWidget.hh>
59 
60 //== IMPLEMENTATION ==========================================================
61 
62 
63 // A job has been started by a plugin
64 void Core::slotStartJob( QString _jobId, QString _description , int _min , int _max, bool _blocking) {
65  std::cerr << "StartJob: " << _jobId.toStdString() << " " << _description.toStdString() << " " << _min << " " << _max << " " << _blocking <<std::endl;
66 
67  // Create job information
68  JobInfo info;
69  info.id = _jobId;
70  info.description = _description;
71  info.currentStep = 0;
72  info.minSteps = _min;
73  info.maxSteps = _max;
74  info.blocking = _blocking;
75  info.blockingWidget = 0;
76 
77 
78 
79  if (OpenFlipper::Options::gui()) {
80  // Don't show process status in process manager
81  // if blocking is enabled
82  if(_blocking) {
83  // Create blocking widget
84  BlockingWidget* widget = new BlockingWidget(_jobId, _description,
85  _min, _max);
86 
87  // Connect cancel button to local slot for further treatment
88  connect(widget, SIGNAL(cancelRequested(QString)),
89  this, SLOT(slotJobCancelRequested(QString)));
90 
91  info.blockingWidget = widget;
92 
93  int x = (coreWidget_->width() / 2) - (widget->width() / 2);
94  int y = (coreWidget_->height() / 2) - (widget->height() / 2);
95 
96  widget->setGeometry( x, y, widget->width(), widget->height());
97 
98  // Show blocking widget
99  widget->show();
100 
101  } else {
102  // Create process manager window if it has not been created before
103  if(!processManager_) {
105 
106  // Connect cancel buttons to local slot for further treatment
107  connect(processManager_, SIGNAL(cancelJobRequested(QString)),
108  this, SLOT(slotJobCancelRequested(QString)));
109  }
110 
111  // Add new item
112  processManager_->addJob(_jobId, _description, _min, _max);
113 
114  // Show window
115  processManager_->show();
116  }
117  }
118 
119  // Add job to local job list
120  currentJobs.push_back(info);
121 }
122 
123 //-----------------------------------------------------------------------------
124 bool Core::getJob(QString _jobId, int& _index) {
125 
126  for ( int i = 0 ; i < currentJobs.size() ; ++i) {
127  if ( currentJobs[i].id == _jobId ) {
128  _index = i;
129  return true;
130  }
131  }
132 
133  emit log(LOGERR,tr("Unable to find Job %1.").arg(_jobId));
134  _index = -1;
135  return false;
136 }
137 
138 //-----------------------------------------------------------------------------
139 
140 // A job state has been updated by a plugin
141 void Core::slotSetJobState(QString _jobId, int _value ) {
142  int id;
143 
144  if ( getJob(_jobId, id) ) {
145  currentJobs[id].currentStep = _value;
146 
147  if (!OpenFlipper::Options::gui())
148  return;
149  // Update gui
150  if(!currentJobs[id].blocking)
151  processManager_->updateStatus(_jobId, _value);
152  else {
153  BlockingWidget* w = 0;
154  w = dynamic_cast<BlockingWidget*>(currentJobs[id].blockingWidget);
155  if(w != 0) {
156  w->updateStatus(_value);
157  }
158  }
159  }
160 }
161 
162 //-----------------------------------------------------------------------------
163 
164 // A job's caption has been updated by a plugin
165 void Core::slotSetJobName(QString _jobId, QString _name ) {
166  int id;
167 
168  if ( getJob(_jobId, id) ) {
169  currentJobs[id].id = _name;
170 
171  if (!OpenFlipper::Options::gui())
172  return;
173  // Update gui
174  if(!currentJobs[id].blocking)
175  processManager_->setJobName(_jobId, _name);
176  else {
177  BlockingWidget* w = 0;
178  w = dynamic_cast<BlockingWidget*>(currentJobs[id].blockingWidget);
179  if(w != 0) {
180  w->setJobId(_name);
181  }
182  }
183  }
184 }
185 //-----------------------------------------------------------------------------
186 
187 // A job's widget's status text has been updated by a plugin
188 void Core::slotSetJobDescription(QString _jobId, QString _text ) {
189  int id;
190 
191  if ( getJob(_jobId, id) ) {
192  currentJobs[id].description = _text;
193 
194  if (!OpenFlipper::Options::gui())
195  return;
196  // Update gui
197  if(!currentJobs[id].blocking)
198  processManager_->setJobDescription(_jobId, _text);
199  else {
200  BlockingWidget* w = 0;
201  w = dynamic_cast<BlockingWidget*>(currentJobs[id].blockingWidget);
202  if(w != 0) {
203  w->setJobDescription(_text);
204  }
205  }
206  }
207 }
208 
209 //-----------------------------------------------------------------------------
210 
211 // A job state has been canceled by a plugin
212 void Core::slotCancelJob(QString _jobId ) {
213  int id;
214 
215  if ( getJob(_jobId, id) ) {
216 
217  if (OpenFlipper::Options::gui()) {
218  // Update gui
219  if(!currentJobs[id].blocking)
220  processManager_->removeJob(_jobId);
221  else {
222  BlockingWidget* w = 0;
223  w = dynamic_cast<BlockingWidget*>(currentJobs[id].blockingWidget);
224  if(w != 0) {
225  w->hide();
226  delete w;
227  }
228  }
229  }
230 
231  currentJobs.removeAt(id);
232  }
233 }
234 
235 //-----------------------------------------------------------------------------
236 
237 // A job state has been finished by a plugin
238 void Core::slotFinishJob(QString _jobId ) {
239  int id;
240 
241  if ( getJob(_jobId, id) ) {
242 
243  if (OpenFlipper::Options::gui()) {
244  // Update gui
245  if(!currentJobs[id].blocking) {
246  processManager_->removeJob(_jobId);
247 
248  // Hide widget if there's no job left
249  if(processManager_->getNumJobs() == 0) processManager_->hide();
250 
251  } else {
252  BlockingWidget* w = 0;
253  w = dynamic_cast<BlockingWidget*>(currentJobs[id].blockingWidget);
254  if(w != 0) {
255  w->hide();
256  delete w;
257  }
258  }
259  }
260 
261  currentJobs.removeAt(id);
262  }
263 }
264 
265 //-----------------------------------------------------------------------------
266 
267 // A job will be canceled by user request
268 void Core::slotJobCancelRequested(QString _jobId ) {
269 
270  std::cerr << "Cancel requested!" << std::endl;
271 
272  emit jobCanceled(_jobId);
273  // Cancel job still to be implemented...
274 
275 }
276 
277 //=============================================================================
void slotSetJobDescription(QString _jobId, QString _text)
A job&#39;s widget&#39;s status text has been updated by a plugin.
Definition: process.cc:188
ProcessManagerWidget * processManager_
A job has been started by a plugin.
Definition: Core.hh:1489
void slotFinishJob(QString _jobId)
A job state has been finished by a plugin.
Definition: process.cc:238
void jobCanceled(QString _jobId)
A job has been started by a plugin.
void slotSetJobName(QString _jobId, QString _name)
A job&#39;s widget caption has been updated by a plugin.
Definition: process.cc:165
void log(Logtype _type, QString _message)
Logg with OUT,WARN or ERR as type.
CoreWidget * coreWidget_
The main applications widget ( only created in gui mode )
Definition: Core.hh:1596
void slotJobCancelRequested(QString _jobId)
Called by dialogs if cancel button is pressed.
Definition: process.cc:268
Job Information class.
Definition: JobInfo.hh:59
void slotStartJob(QString _jobId, QString _description, int _min, int _max, bool _blocking)
A job has been started by a plugin.
Definition: process.cc:64
void slotSetJobState(QString _jobId, int _value)
A job state has been updated by a plugin.
Definition: process.cc:141
void slotCancelJob(QString _jobId)
A job state has been canceled by a plugin.
Definition: process.cc:212
bool getJob(QString _jobId, int &_index)
Find a job in the jobslist.
Definition: process.cc:124
QList< JobInfo > currentJobs
A job has been started by a plugin.
Definition: Core.hh:1487