]> SALOME platform Git repositories - modules/jobmanager.git/blob - src/genericgui/BL_CreateJobWizard.cxx
Salome HOME
Updated copyright comment
[modules/jobmanager.git] / src / genericgui / BL_CreateJobWizard.cxx
1 // Copyright (C) 2009-2024  CEA, EDF
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "BL_CreateJobWizard.hxx"
21 #include "BL_JobsManager_QT.hxx"
22
23 #include <QFileDialog>
24 #include <QMessageBox>
25 #include <QTreeView>
26 #include <QDir>
27
28 #ifndef WNT
29 #include <unistd.h>
30 #include <pwd.h>
31 #endif
32 #include <sys/types.h>
33 #include <stdlib.h>
34 #include <time.h>
35
36 #include <ui_ResourceRequirementsWizardPage.h>
37 #include <ui_FilesWizardPage.h>
38 #include <ui_AdvancedParametersWizardPage.h>
39
40 #ifdef WNT
41 #undef ERROR
42 #endif
43
44 using namespace std;
45 using namespace BL;
46
47 BL::CreateJobWizard::CreateJobWizard(BL::JobsManager_QT * jobs_manager, BL::SALOMEServices * salome_services)
48 {
49   DEBTRACE("Creating BL::CreateJobWizard");
50   BL_ASSERT(jobs_manager);
51   BL_ASSERT(salome_services);
52   _jobs_manager = jobs_manager;
53   _salome_services = salome_services;
54
55   job_name = "";
56   job_type = YACS;
57   yacs_file = "";
58   command = "";
59   python_salome_file = "";
60   env_file = "";
61   pre_command = "";
62   batch_directory = "";
63
64   // For COORM
65   coorm_batch_directory = "";
66
67   maximum_duration = "";
68   mem_limit = 0;
69   mem_req_type = BL::Job::MEM_PER_NODE;
70   nb_proc = 1;
71   nb_node = 0;
72
73   // Parameters for COORM
74   launcher_file = "";
75   launcher_args = "";
76
77   result_directory = "";
78
79   resource_choosed = "";
80   batch_queue = "";
81   batch_partition = "";
82
83   start_job = false;
84   dump_yacs_state = -1;
85   yacs_driver_options = "";
86   ll_jobtype = "";
87
88   setOptions(QWizard::NoBackButtonOnStartPage);
89
90   // Common pages
91   _job_name_page = new BL::JobNamePage(this, _jobs_manager);
92   _batch_parameters_page = new BL::BatchParametersPage(this, salome_services);
93
94   setPage(Page_JobName, _job_name_page);
95   setPage(Page_BatchParameters, _batch_parameters_page);
96
97   // For COORM
98   setPage(Page_COORM_BatchParameters, new BL::COORM_BatchParametersPage(this, salome_services));
99
100   setPage(Page_Files, new BL::FilesPage(this, salome_services));
101   setPage(Page_Resource, new BL::ResourcePage(this, salome_services));
102   setPage(Page_Advanced, new BL::AdvancedParametersPage(this));
103   setPage(Page_Conclusion, new BL::ConclusionPage(this));
104
105   // Specific pages
106   setPage(Page_YACSSchema, new BL::YACSSchemaPage(this));
107   setPage(Page_Command_Main_Definitions, new BL::CommandMainPage(this));
108   setPage(Page_PythonSalome_Main_Definitions, new BL::PythonSalomeMainPage(this));
109
110   setWindowTitle("Create Job Wizard");
111   connect(this, SIGNAL(finished(int)), this, SLOT(end(int)));
112 }
113
114 BL::CreateJobWizard::~CreateJobWizard()
115 {
116   DEBTRACE("Destroying BL::CreateJobWizard");
117 }
118
119 void
120 BL::CreateJobWizard::clone(const std::string & name)
121 {
122   if (_jobs_manager->job_already_exist(name) == true)
123   {
124     BL::Job * job = _jobs_manager->getJob(name);
125
126     // We can only edit a job in CREATED, ERROR, FAILED and NOT_CREATED
127     if (job->getState() == BL::Job::CREATED ||
128         job->getState() == BL::Job::ERROR   ||
129         job->getState() == BL::Job::FAILED  ||
130         job->getState() == BL::Job::NOT_CREATED)
131     { 
132       setField("job_name", QString(name.c_str()));
133       _job_name_page->_check_name = false;
134     }
135
136     if (job->getType() == BL::Job::YACS_SCHEMA)
137     {
138       setField("yacs_file", QString(job->getJobFile().c_str()));
139       setField("job_type_yacs", true);
140       setField("env_yacs_file", QString(job->getEnvFile().c_str()));
141       setField("pre_yacs_file", QString(job->getPreCommand().c_str()));
142       if (job->getDumpYACSState() != -1)
143       {
144         QString value;
145         value.setNum(job->getDumpYACSState());
146         setField("dump_yacs_state", value);
147       }
148       if (!job->getYacsDriverOptions().empty())
149       {
150         setField("yacs_driver_options", job->getYacsDriverOptions().c_str());
151       }
152     }
153     else if (job->getType() == BL::Job::COMMAND)
154     {
155       setField("command", QString(job->getJobFile().c_str()));
156       setField("job_type_command", true);
157       setField("env_command_file", QString(job->getEnvFile().c_str()));
158       setField("pre_command_file", QString(job->getPreCommand().c_str()));
159     }
160     else if (job->getType() == BL::Job::COMMAND_SALOME)
161     {
162       setField("command", QString(job->getJobFile().c_str()));
163       setField("job_type_command_salome", true);
164       setField("env_command_file", QString(job->getEnvFile().c_str()));
165       setField("pre_command_file", QString(job->getPreCommand().c_str()));
166     }
167     else if (job->getType() == BL::Job::PYTHON_SALOME)
168     {
169       setField("PythonSalome", QString(job->getJobFile().c_str()));
170       setField("job_type_python_salome", true);
171       setField("env_PythonSalome_file", QString(job->getEnvFile().c_str()));
172       setField("pre_PythonSalome_file", QString(job->getPreCommand().c_str()));
173     }
174
175
176     // For COORM
177     BL::Job::BatchParam batch_params = job->getBatchParameters();
178     BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(job->getResource().c_str());
179     std::string batch = resource_descr.batch.c_str();
180     if (batch == "coorm")
181     {
182       setField("coorm_batch_directory", QString(batch_params.batch_directory.c_str()));
183       setField("launcher_file", QString(batch_params.launcher_file.c_str()));
184       setField("launcher_args", QString(batch_params.launcher_args.c_str()));
185     }
186     else
187     {
188       setField("batch_directory", QString(batch_params.batch_directory.c_str()));
189     }
190
191     QString proc_value;
192     proc_value.setNum(batch_params.nb_proc);
193     setField("proc_value", proc_value);
194
195     QString node_value;
196     node_value.setNum(batch_params.nb_node);
197     setField("node_value", node_value);
198
199     setField("exclusive", batch_params.exclusive);
200
201     if (batch_params.maximum_duration == "")
202     {
203       setField("default_time", true);
204       setField("duration_hour", 0);
205       setField("duration_min", 0);
206     }
207     else
208     {
209       setField("user_time", true);
210       std::size_t pos = batch_params.maximum_duration.find(":");
211       std::string hour_str = batch_params.maximum_duration.substr(0, pos);
212       int hour; 
213       std::istringstream iss_hour(hour_str);
214       iss_hour >> hour;
215       setField("duration_hour", hour);
216
217       std::string min_str = batch_params.maximum_duration.substr(pos + 1, batch_params.maximum_duration.npos);
218       int min; 
219       std::istringstream iss_min(min_str);
220       iss_min >> min;
221       setField("duration_min", min);
222     }
223
224     long long mem_mb = batch_params.mem_limit;
225     if (mem_mb < 1)
226     {
227       setField("default_mem", true);
228     }
229     else
230     {
231       setField("user_mem", true);
232       if (mem_mb % 1024 == 0)
233       {
234         setField("mem_value", mem_mb / 1024);
235         _batch_parameters_page->setMemUnit(BatchParametersPage::GB);
236       }
237       else
238       {
239         setField("mem_value", mem_mb);
240         _batch_parameters_page->setMemUnit(BatchParametersPage::MB);
241       }
242       _batch_parameters_page->setMemReqType(batch_params.mem_req_type);
243     }
244
245     BL::Job::FilesParam files_params = job->getFilesParameters();
246
247     std::list<std::string>::iterator it = files_params.input_files_list.begin();
248     for (; it != files_params.input_files_list.end(); it++)
249       _input_files_list->addItem(QString((*it).c_str()));
250     it = files_params.output_files_list.begin();
251     for (; it != files_params.output_files_list.end(); it++)
252       _output_files_list->addItem(QString((*it).c_str()));
253
254     setField("result_directory", QString(files_params.result_directory.c_str()));
255     setField("resource_choosed", QString(job->getResource().c_str()));
256     setField("batch_queue", QString(job->getBatchQueue().c_str()));
257     setField("batch_partition", QString(job->getBatchPartition().c_str()));
258     setField("ll_jobtype", QString(job->getLoadLevelerJobType().c_str()));
259     setField("wckey", QString(job->getWCKey().c_str()));
260     setField("extra_params", QString(job->getExtraParams().c_str()));
261   }
262 }
263
264 void
265 BL::CreateJobWizard::setFilesList(QListWidget * input_files_list, QListWidget * output_files_list)
266 {
267   _input_files_list = input_files_list;
268   _output_files_list = output_files_list;
269 }
270
271 void
272 BL::CreateJobWizard::end(int result)
273 {
274   DEBTRACE("End of BL::CreateJobWizard");
275   if (result)
276   {
277     // Job Name Panel
278     QString f_job_name = field("job_name").toString();
279     job_name = f_job_name.trimmed().toUtf8().constData();
280     if (field("job_type_yacs").toBool())
281       job_type = YACS;
282     else if (field("job_type_command").toBool())
283       job_type = COMMAND;
284     else if (field("job_type_command_salome").toBool())
285       job_type = COMMAND_SALOME;
286     else
287       job_type = PYTHON_SALOME;
288
289     // YACS Schema Panel
290     QString f_yacs_file = field("yacs_file").toString();
291     yacs_file = f_yacs_file.trimmed().toUtf8().constData();
292     dump_yacs_state = field("dump_yacs_state").toInt();
293     yacs_driver_options = field("yacs_driver_options").toString().trimmed().toUtf8().constData();
294
295     // Command Panel
296     QString f_command = field("command").toString();
297     command = f_command.trimmed().toUtf8().constData();
298
299     // Command Panel
300     QString f_python_salome_file = field("PythonSalome").toString();
301     python_salome_file = f_python_salome_file.trimmed().toUtf8().constData();
302
303     QString f_env_file;
304     if (job_type == YACS)
305       f_env_file = field("env_yacs_file").toString();
306     else if (job_type == COMMAND || job_type == COMMAND_SALOME)
307       f_env_file = field("env_command_file").toString();
308     else if (job_type == PYTHON_SALOME)
309       f_env_file = field("env_PythonSalome_file").toString();
310     env_file = f_env_file.trimmed().toUtf8().constData();
311
312     QString f_pre_command_file;
313     if (job_type == YACS)
314       f_pre_command_file = field("pre_yacs_file").toString();
315     else if (job_type == COMMAND || job_type == COMMAND_SALOME)
316       f_pre_command_file = field("pre_command_file").toString();
317     else if (job_type == PYTHON_SALOME)
318       f_pre_command_file = field("pre_PythonSalome_file").toString();
319     pre_command = f_pre_command_file.trimmed().toUtf8().constData();
320
321     // Batch Panel
322     QString f_batch_directory = field("batch_directory").toString();
323     batch_directory = f_batch_directory.trimmed().toUtf8().constData();
324
325     // For COORM
326     QString f_coorm_batch_directory = field("coorm_batch_directory").toString();
327     coorm_batch_directory = f_coorm_batch_directory.toUtf8().constData();
328
329         // For COORM
330     QString f_launcher_file = field("launcher_file").toString();
331     launcher_file = f_launcher_file.toUtf8().constData();
332     QString f_launcher_args = field("launcher_args").toString();
333     launcher_args = f_launcher_args.toUtf8().constData();
334
335     QString time_hour;
336     QString time_min;
337     if (field("default_time").toBool() ||
338         (field("duration_hour").toInt() == 0 && field("duration_min").toInt() == 0))
339     {
340       maximum_duration = "";
341     }
342     else
343     {
344       if (field("duration_hour").toInt() < 10)
345         time_hour = "0" + field("duration_hour").toString().trimmed();
346       else
347         time_hour = field("duration_hour").toString().trimmed();
348       if (field("duration_min").toInt() < 10)
349         time_min = "0" + field("duration_min").toString().trimmed();
350       else
351         time_min = field("duration_min").toString().trimmed();
352       maximum_duration = time_hour.toStdString() + ":" + time_min.toStdString();
353     }
354
355     if(field("default_mem").toBool())
356     {
357       mem_limit = -1;
358     }
359     else
360     {
361       unsigned long mem = field("mem_value").toULongLong();
362       BatchParametersPage::MemUnit mem_unit = _batch_parameters_page->getMemUnit();
363       switch (mem_unit)
364       {
365       case BatchParametersPage::MB:
366         mem_limit = mem;
367         break;
368       case BatchParametersPage::GB:
369         mem_limit = mem * 1024;
370         break;
371       default:
372         throw Exception("Invalid memory unit");
373       }
374       mem_req_type = _batch_parameters_page->getMemReqType();
375     }
376
377     nb_proc = field("proc_value").toInt();
378     nb_node = field("node_value").toInt();
379     exclusive = field("exclusive").toBool();
380
381     // Files Panel
382     QString f_result_directory = field("result_directory").toString();
383     result_directory = f_result_directory.trimmed().toUtf8().constData();
384     for (int i = 0; i < _input_files_list->count(); ++i)
385     {
386       QListWidgetItem * item = _input_files_list->item(i);
387       QString item_text = item->text();
388       input_files_list.push_back(item_text.trimmed().toUtf8().constData());
389     }
390     for (int i = 0; i < _output_files_list->count(); ++i)
391     {
392       QListWidgetItem * item = _output_files_list->item(i);
393       QString item_text = item->text();
394       output_files_list.push_back(item_text.trimmed().toUtf8().constData());
395     }
396
397     // Resource list
398     QString f_resource_choosed = field("resource_choosed").toString();
399     resource_choosed = f_resource_choosed.trimmed().toUtf8().constData();
400
401     // Batch Queue
402     QString f_batch_queue = field("batch_queue").toString();
403     batch_queue = f_batch_queue.trimmed().toUtf8().constData();
404
405     // Batch Partition
406     QString f_batch_partition = field("batch_partition").toString();
407     batch_partition = f_batch_partition.trimmed().toUtf8().constData();
408
409     // LoadLeveler JobType
410     BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
411     std::string batch = resource_descr.batch.c_str();
412     if (batch == "ll")
413     {
414       QString f_ll_jobtype = field("ll_jobtype").toString();
415       ll_jobtype = f_ll_jobtype.trimmed().toStdString();
416     }
417     else
418     {
419       ll_jobtype = "";
420     }
421
422     // WC Key
423     QString f_wckey = field("wckey").toString();
424     wckey = f_wckey.trimmed().toUtf8().constData();
425
426     // Extra params
427     QString f_extra_params = field("extra_params").toString();
428     extra_params = f_extra_params.trimmed().toUtf8().constData();
429
430     start_job = field("start_job").toBool();
431   }
432 }
433
434 // Job Name Page
435 BL::JobNamePage::JobNamePage(QWidget * parent, BL::JobsManager_QT * jobs_manager)
436 : QWizardPage(parent)
437 {
438   _jobs_manager = jobs_manager;
439   _check_name = true;
440   setTitle("Create a new job");
441
442   QLabel *label = new QLabel("Enter Job name, you cannot add two jobs with the same name");
443   label->setWordWrap(true);
444   QLabel * nameLabel = new QLabel("Job Name:");
445   QLineEdit * _nameLineEdit = new QLineEdit(this);
446   registerField("job_name", _nameLineEdit);
447
448   QLabel * label_type = new QLabel("Choose type of batch job:");
449   QGroupBox *groupBox = new QGroupBox("Type of job");
450   QRadioButton * _yacs_schema_button = new QRadioButton(tr("YACS Schema"));
451   _yacs_schema_button->setChecked(true);
452   QRadioButton * _command_button = new QRadioButton(tr("Command"));
453   QRadioButton * _command_salome_button = new QRadioButton(tr("Command in salome shell"));
454   QRadioButton * _python_salome_button = new QRadioButton(tr("Python script in SALOME"));
455   QVBoxLayout *vbox = new QVBoxLayout;
456   vbox->addWidget(_yacs_schema_button);
457   vbox->addWidget(_command_button);
458   vbox->addWidget(_command_salome_button);
459   vbox->addWidget(_python_salome_button);
460   vbox->addStretch(1);
461   groupBox->setLayout(vbox);
462   registerField("job_type_yacs", _yacs_schema_button);
463   registerField("job_type_command", _command_button);
464   registerField("job_type_command_salome", _command_salome_button);
465   registerField("job_type_python_salome", _python_salome_button);
466
467   QGroupBox * explanationBox = new QGroupBox("Explanation");
468   QVBoxLayout *explanationvbox = new QVBoxLayout;
469   _explanation = new QLabel();
470   _explanation->setWordWrap(true);
471   explanationvbox->addWidget(_explanation);
472   explanationvbox->addStretch(1);
473   explanationBox->setLayout(explanationvbox);
474
475   // Layouts
476   QVBoxLayout * main_layout = new QVBoxLayout;
477   main_layout->addWidget(label);
478   QGridLayout *layout = new QGridLayout;
479   layout->addWidget(nameLabel, 0, 0);
480   layout->addWidget(_nameLineEdit, 0, 1);
481   main_layout->insertLayout(-1, layout);
482   layout->addWidget(label_type, 2, 0);
483   layout->addWidget(groupBox, 3, 0, 1, -1);
484   layout->addWidget(explanationBox, 4, 0, 1, -1);
485   setLayout(main_layout);
486
487   connect(_yacs_schema_button, SIGNAL(toggled(bool)), this, SLOT(yacs_schema_button(bool)));
488   connect(_command_button, SIGNAL(toggled(bool)), this, SLOT(command_button(bool)));
489   connect(_command_salome_button, SIGNAL(toggled(bool)), this, SLOT(command_salome_button(bool)));
490   connect(_python_salome_button, SIGNAL(toggled(bool)), this, SLOT(python_salome_button(bool)));
491
492   // Default button
493   yacs_schema_button(true);
494 }
495
496 BL::JobNamePage::~JobNamePage()
497 {}
498
499 void
500 BL::JobNamePage::yacs_schema_button(bool checked)
501 {
502   if (checked)
503   {
504     _explanation->setText("Launch a YACS schema.");
505     setField("exclusive", true);
506   }
507 }
508
509 void
510 BL::JobNamePage::command_button(bool checked)
511 {
512   if (checked)
513   {
514     _explanation->setText("Launch a script on a remote resource without using "
515                           "SALOME environment.");
516     setField("exclusive", false);
517   }
518 }
519
520 void
521 BL::JobNamePage::command_salome_button(bool checked)
522 {
523   if (checked)
524   {
525     _explanation->setText("Launch a script on a remote resource within SALOME "
526                           "environment but whitout the SALOME application.");
527     setField("exclusive", false);
528   }
529 }
530
531 void
532 BL::JobNamePage::python_salome_button(bool checked)
533 {
534   if (checked)
535   {
536     _explanation->setText("Launch a python script into a SALOME application.");
537     setField("exclusive", true);
538   }
539 }
540
541 bool
542 BL::JobNamePage::validatePage()
543 {
544   DEBTRACE("Calling validatePage of BL::JobNamePage");
545   bool return_value;
546   QString job_name = field("job_name").toString();
547
548   // Check if job name is empty
549   if (job_name == "")
550   {
551     QMessageBox::warning(NULL, "Job Name Error", "Job name entered is empty, enter a job name or cancel the wizard");
552     return_value = false;
553   }
554
555   // Check if job name already exists
556   else {
557     if (_jobs_manager->job_already_exist(job_name.toUtf8().constData()) == false || _check_name == false)
558     {
559       return_value = true;
560     }
561     else
562     {
563       QMessageBox::critical(NULL, "Job Name Error", "Job name entered is already used");
564       QString value("");
565       setField("job_name", value);
566       return_value = false;
567     }
568   }
569
570   return return_value;
571 }
572
573 int
574 BL::JobNamePage::nextId() const
575 {
576   if (field("job_type_yacs").toBool())
577   {
578     return BL::CreateJobWizard::Page_YACSSchema;
579   } 
580   else if (field("job_type_command").toBool() ||
581            field("job_type_command_salome").toBool())
582   {
583     return BL::CreateJobWizard::Page_Command_Main_Definitions;
584   }
585   else
586   {
587     return BL::CreateJobWizard::Page_PythonSalome_Main_Definitions;
588   }
589 }
590
591 BL::YACSSchemaPage::YACSSchemaPage(QWidget * parent)
592 : QWizardPage(parent)
593 {
594   setTitle("Configure YACS Execution");
595
596   QLabel *label = new QLabel("In this step you have to configure your YACS execution");
597   label->setWordWrap(true);
598
599   QGroupBox * files_param_box = new QGroupBox("YACS job files");
600   QPushButton * yacs_file_button = new QPushButton(tr("Choose YACS Schema file"));
601   connect(yacs_file_button, SIGNAL(clicked()), this, SLOT(choose_file()));
602   _yacs_file_text = new QLineEdit(this);
603   _yacs_file_text->setText("");
604   registerField("yacs_file", _yacs_file_text);
605   _yacs_file_text->setReadOnly(true);
606   QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
607   connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
608   _line_env_file = new QLineEdit(this);
609   registerField("env_yacs_file", _line_env_file);
610   _line_env_file->setReadOnly(true);
611   QPushButton * command_pre_command_button = new QPushButton(tr("Choose a pre processing script"));
612   connect(command_pre_command_button, SIGNAL(clicked()),
613           this, SLOT(choose_pre_command_file()));
614   _line_pre_command = new QLineEdit(this);
615   registerField("pre_yacs_file", _line_pre_command);
616   _line_pre_command->setReadOnly(true);
617   QGridLayout * files_layout = new QGridLayout;
618   files_layout->addWidget(yacs_file_button, 0, 0);
619   files_layout->addWidget(_yacs_file_text, 0, 1);
620   files_layout->addWidget(command_env_file_button, 1, 0);
621   files_layout->addWidget(_line_env_file, 1, 1);
622   files_layout->addWidget(command_pre_command_button, 2, 0);
623   files_layout->addWidget(_line_pre_command, 2, 1);
624   files_param_box->setLayout(files_layout);
625
626   QGroupBox * spec_param_box = new QGroupBox("YACS specific parameters");
627   QLabel * label_dump =  new QLabel("Dump YACS state each secs (0 disable this feature)");
628   QLabel * label_driver_options = new QLabel("YACS driver options - see YACS driver documentation.");
629   QSpinBox * spin_dump = new QSpinBox(this);
630   spin_dump->setMinimum(0);
631   spin_dump->setMaximum(1000000);
632   registerField("dump_yacs_state", spin_dump);
633   QLineEdit* edit_yacs_driver_options = new QLineEdit(this);
634   registerField("yacs_driver_options", edit_yacs_driver_options);
635   QGridLayout * specific_layout = new QGridLayout;
636   specific_layout->addWidget(label_dump, 0, 0);
637   specific_layout->addWidget(spin_dump, 0, 1);
638   specific_layout->addWidget(label_driver_options, 1, 0);
639   specific_layout->addWidget(edit_yacs_driver_options, 1, 1);
640   spec_param_box->setLayout(specific_layout);
641
642   QVBoxLayout * main_layout = new QVBoxLayout;
643   main_layout->addWidget(label);
644   main_layout->addWidget(files_param_box);
645   main_layout->addWidget(spec_param_box);
646
647   setLayout(main_layout);
648 };
649
650 BL::YACSSchemaPage::~YACSSchemaPage()
651 {}
652
653 bool
654 BL::YACSSchemaPage::validatePage()
655 {
656   bool return_value;
657   QString yacs_file = field("yacs_file").toString();
658   if (yacs_file != "")
659   {
660     return_value = true;
661   }
662   else
663   {
664     QMessageBox::warning(NULL, "YACS File Error", "Please choose a YACS File");
665     return_value = false;
666   }
667   return return_value;
668 }
669
670 void
671 BL::YACSSchemaPage::choose_file()
672 {
673   QString yacs_file = QFileDialog::getOpenFileName(this,
674                                                    tr("Open YACS files"), "",
675                                                    tr("XML (*.xml);;All Files (*)"));
676   _yacs_file_text->setReadOnly(false);
677   _yacs_file_text->setText(yacs_file);
678   _yacs_file_text->setReadOnly(true);
679 }
680
681 void
682 BL::YACSSchemaPage::choose_env_file()
683 {
684   QString env_file = QFileDialog::getOpenFileName(this,
685                                                   tr("Open environnement file"), "",
686                                                   tr("sh (*.sh);;All Files (*)"));
687   _line_env_file->setReadOnly(false);
688   _line_env_file->setText(env_file);
689   _line_env_file->setReadOnly(true);
690 }
691
692 void
693 BL::YACSSchemaPage::choose_pre_command_file()
694 {
695   QString pre_command_file = QFileDialog::getOpenFileName(this,
696                                                     tr("Open script file"), "",
697                                                     tr("All Files (*)"));
698   _line_pre_command->setReadOnly(false);
699   _line_pre_command->setText(pre_command_file);
700   _line_pre_command->setReadOnly(true);
701 }
702
703 int 
704 BL::YACSSchemaPage::nextId() const
705 {
706   return BL::CreateJobWizard::Page_Resource;
707 }
708
709 BL::CommandMainPage::CommandMainPage(QWidget * parent)
710 : QWizardPage(parent)
711 {
712   setTitle("Define command job");
713   QLabel *label = new QLabel("Enter the command that will be executed into the resource");
714   label->setWordWrap(true);
715
716   // command
717   QPushButton * command_file_button = new QPushButton(tr("Choose a command file"));
718   connect(command_file_button, SIGNAL(clicked()), this, SLOT(choose_command_file()));
719   _line_command = new QLineEdit(this);
720   registerField("command", _line_command);
721   _line_command->setReadOnly(true);
722
723   QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
724   connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
725   _line_env_file = new QLineEdit(this);
726   registerField("env_command_file", _line_env_file);
727   _line_env_file->setReadOnly(true);
728
729   QPushButton * command_pre_command_button = new QPushButton(tr("Choose a pre processing script"));
730   connect(command_pre_command_button, SIGNAL(clicked()),
731           this, SLOT(choose_pre_command_file()));
732   _line_pre_command = new QLineEdit(this);
733   registerField("pre_command_file", _line_pre_command);
734   _line_pre_command->setReadOnly(true);
735
736   QGridLayout *layout = new QGridLayout;
737   layout->addWidget(command_file_button, 0, 0);
738   layout->addWidget(_line_command, 0, 1);
739   layout->addWidget(command_env_file_button, 1, 0);
740   layout->addWidget(_line_env_file, 1, 1);
741   layout->addWidget(command_pre_command_button, 2, 0);
742   layout->addWidget(_line_pre_command, 2, 1);
743
744   QVBoxLayout * main_layout = new QVBoxLayout;
745   main_layout->addWidget(label);
746   main_layout->insertLayout(-1, layout);
747   setLayout(main_layout);
748 };
749
750 BL::CommandMainPage::~CommandMainPage()
751 {}
752
753 void
754 BL::CommandMainPage::choose_command_file()
755 {
756   QString command_file = QFileDialog::getOpenFileName(this,
757                                                       tr("Open command file"), "",
758                                                       tr("sh (*.sh);;All Files (*)"));
759   _line_command->setReadOnly(false);
760   _line_command->setText(command_file);
761   _line_command->setReadOnly(true);
762 }
763
764 void
765 BL::CommandMainPage::choose_env_file()
766 {
767   QString env_file = QFileDialog::getOpenFileName(this,
768                                                   tr("Open environnement file"), "",
769                                                   tr("sh (*.sh);;All Files (*)"));
770   _line_env_file->setReadOnly(false);
771   _line_env_file->setText(env_file);
772   _line_env_file->setReadOnly(true);
773 }
774
775 void
776 BL::CommandMainPage::choose_pre_command_file()
777 {
778   QString pre_command_file = QFileDialog::getOpenFileName(this,
779                                                     tr("Open script file"), "",
780                                                     tr("All Files (*)"));
781   _line_pre_command->setReadOnly(false);
782   _line_pre_command->setText(pre_command_file);
783   _line_pre_command->setReadOnly(true);
784 }
785
786 bool
787 BL::CommandMainPage::validatePage()
788 {
789   QString command = field("command").toString();
790   if (command == "")
791   {
792     QMessageBox::warning(NULL, "Command Error", "Please enter a command");
793     return false;
794   }
795
796   return true;
797 }
798
799 int 
800 BL::CommandMainPage::nextId() const
801 {
802   return BL::CreateJobWizard::Page_Resource;
803 }
804
805 BatchParametersPage::BatchParametersPage(QWidget * parent, SALOMEServices * salome_services)
806 : QWizardPage(parent),
807   ui(new Ui::ResourceRequirementsWizardPage),
808   _salome_services(salome_services),
809   resource_choosed()
810 {
811   ui->setupUi(this);
812
813   registerField("duration_hour", ui->spin_duration_hour);
814   registerField("duration_min", ui->spin_duration_min);
815   registerField("mem_value", ui->spin_memory);
816   registerField("proc_value", ui->spin_proc);
817   registerField("node_value", ui->spin_node);
818   registerField("exclusive", ui->check_exclusive);
819   registerField("default_time", ui->rb_default_time);
820   registerField("user_time", ui->rb_user_time);
821   registerField("default_mem", ui->rb_default_mem);
822   registerField("user_mem", ui->rb_user_mem);
823
824   ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "MB", MB);
825   ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "GB", GB);
826   setMemUnit(GB);
827
828   ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
829                                         "per node", Job::MEM_PER_NODE);
830   ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
831                                         "per core", Job::MEM_PER_CPU);
832
833   connect(ui->spin_duration_hour, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
834   connect(ui->spin_duration_min, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
835   connect(ui->spin_memory, SIGNAL(valueChanged(int)), this, SLOT(memChanged()));
836   connect(ui->combo_memory_unit, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
837   connect(ui->combo_memory_req_type, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
838 };
839
840 BatchParametersPage::~BatchParametersPage()
841 {
842   delete ui;
843 }
844
845 void
846 BatchParametersPage::initializePage()
847 {
848   string f_resource_choosed = field("resource_choosed").toString().toUtf8().constData();
849   if (f_resource_choosed != resource_choosed)
850   {
851     resource_choosed = f_resource_choosed;
852     // If choosed resource has a SLURM batch manager, activate option "memory per cpu"
853     ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
854     if (resource_descr.batch == "slurm")
855     {
856       ui->combo_memory_req_type->setEnabled(true);
857     }
858     else
859     {
860       ui->combo_memory_req_type->setEnabled(false);
861       setMemReqType(Job::MEM_PER_NODE);
862     }
863   }
864 }
865
866 BatchParametersPage::MemUnit
867 BatchParametersPage::getMemUnit() const
868 {
869   int idx = ui->combo_memory_unit->currentIndex();
870   return (MemUnit)(ui->combo_memory_unit->itemData(idx).toInt());
871 }
872
873 void
874 BatchParametersPage::setMemUnit(MemUnit mem_unit)
875 {
876   ui->combo_memory_unit->setCurrentIndex(ui->combo_memory_unit->findData(mem_unit));
877 }
878
879 Job::MemReqType
880 BatchParametersPage::getMemReqType() const
881 {
882   int idx = ui->combo_memory_req_type->currentIndex();
883   return (Job::MemReqType)(ui->combo_memory_req_type->itemData(idx).toInt());
884 }
885
886 void
887 BatchParametersPage::setMemReqType(Job::MemReqType mem_req_type)
888 {
889   ui->combo_memory_req_type->setCurrentIndex(ui->combo_memory_req_type->findData(mem_req_type));
890 }
891
892 void
893 BatchParametersPage::timeChanged()
894 {
895   if (ui->spin_duration_hour->value() == 0 && ui->spin_duration_min->value() == 0)
896     ui->rb_default_time->setChecked(true);
897   else
898     ui->rb_user_time->setChecked(true);
899 }
900
901 void
902 BatchParametersPage::memChanged()
903 {
904   ui->rb_user_mem->setChecked(true);
905 }
906
907 void
908 BatchParametersPage::cleanupPage()
909 {
910 }
911
912 int 
913 BatchParametersPage::nextId() const
914 {
915   return CreateJobWizard::Page_Files;
916 }
917
918 BL::COORM_BatchParametersPage::COORM_BatchParametersPage(QWidget * parent, BL::SALOMEServices * salome_services)
919 : QWizardPage(parent)
920 {
921   setTitle("Enter COORM Parameters");
922   resource_choosed = "";
923
924   _salome_services = salome_services;
925
926   QLabel *label = new QLabel("In this step you define the parameters for COORM");
927   label->setWordWrap(true);
928   QVBoxLayout * main_layout = new QVBoxLayout;
929   main_layout->addWidget(label);
930
931   // coorm_batch_directory
932   QLabel * label_directory = new QLabel("Remote work directory: ");
933   QLineEdit * line_directory = new QLineEdit(this);
934   registerField("coorm_batch_directory", line_directory);
935
936   // launcher_file
937   QPushButton * launcher_file_button = new QPushButton(tr("Choose a launcher file"));
938   connect(launcher_file_button, SIGNAL(clicked()), this, SLOT(choose_launcher_file()));
939   _launcher_file_text = new QLineEdit(this);
940   _launcher_file_text->setText("");
941   registerField("launcher_file", _launcher_file_text);
942   _launcher_file_text->setReadOnly(true);
943
944   // launcher_args
945   QLabel * launcher_args_label = new QLabel("Launcher args:");
946   QLineEdit * launcher_args_text = new QLineEdit(this);
947   registerField("launcher_args", launcher_args_text);
948
949   QGridLayout * layout = new QGridLayout;
950   layout->addWidget(label_directory, 0, 0);
951   layout->addWidget(line_directory, 0, 1);
952   layout->addWidget(launcher_file_button, 1, 0);
953   layout->addWidget(_launcher_file_text, 1, 1);
954   layout->addWidget(launcher_args_label, 2, 0);
955   layout->addWidget(launcher_args_text, 2, 1);
956
957   main_layout->insertLayout(-1, layout);
958
959   setLayout(main_layout);
960 };
961
962 BL::COORM_BatchParametersPage::~COORM_BatchParametersPage()
963 {}
964
965 bool
966 BL::COORM_BatchParametersPage::validatePage()
967 {
968   QString coorm_batch_directory = field("coorm_batch_directory").toString();
969   if (coorm_batch_directory == "")
970   {
971     QMessageBox::warning(NULL, "Batch Directory Error", "Please enter a batch directory");
972     return false;
973   }
974
975   QString launcher_file = field("launcher_file").toString();
976   if (launcher_file == "")
977   {
978     QMessageBox::warning(NULL, "Launcher File Error", "Please enter a launcher file");
979     return false;
980   }
981
982   return true;
983 }
984
985 int
986 BL::COORM_BatchParametersPage::nextId() const
987 {
988   return BL::CreateJobWizard::Page_Files;
989 }
990
991 void
992 BL::COORM_BatchParametersPage::choose_launcher_file()
993 {
994   QString launcher_file = QFileDialog::getOpenFileName(this,
995                                                    tr("Open launcher files"), "",
996                                                    tr("Py (*.py);;All Files (*)"));
997   _launcher_file_text->setReadOnly(false);
998   _launcher_file_text->setText(launcher_file);
999   _launcher_file_text->setReadOnly(true);
1000 }
1001
1002 void BL::COORM_BatchParametersPage::cleanupPage()
1003 {}
1004
1005 void
1006 BL::COORM_BatchParametersPage::initializePage()
1007 {
1008   QString f_resource_choosed = field("resource_choosed").toString();
1009   if (f_resource_choosed != resource_choosed)
1010   {
1011     resource_choosed = f_resource_choosed;
1012     // If choosed resource has a working_directory set
1013     // Generates a default remote working directory
1014     BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1015     QString res_work_dir = resource_descr.working_directory.c_str();
1016     if (res_work_dir != "")
1017     {
1018       time_t rawtime;
1019       time(&rawtime);
1020       std::string launch_date = ctime(&rawtime);
1021       for (int i = 0; i < launch_date.size(); i++)
1022         if (launch_date[i] == '/' ||
1023             launch_date[i] == '-' ||
1024             launch_date[i] == ':' ||
1025             launch_date[i] == ' ')
1026           launch_date[i] = '_';
1027       launch_date.erase(--launch_date.end()); // Last caracter is a \n
1028       QString date = launch_date.c_str();
1029       setField("coorm_batch_directory", res_work_dir + "/" + date);
1030     }
1031   }
1032 }
1033
1034 FilesPage::FilesPage(CreateJobWizard * parent, SALOMEServices * salome_services)
1035 : QWizardPage(parent),
1036   ui(new Ui::FilesWizardPage)
1037 {
1038   ui->setupUi(this);
1039
1040   resource_choosed = "";
1041   _salome_services = salome_services;
1042
1043   connect(ui->add_input_files_button, SIGNAL(clicked()), this, SLOT(choose_input_files()));
1044   connect(ui->remove_input_files_button, SIGNAL(clicked()), this, SLOT(remove_input_files()));
1045   connect(ui->input_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(input_itemSelectionChanged()));
1046   connect(ui->add_output_files_button, SIGNAL(clicked()), this, SLOT(add_output_file()));
1047   connect(ui->remove_output_files_button, SIGNAL(clicked()), this, SLOT(remove_output_files()));
1048   connect(ui->output_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(output_itemSelectionChanged()));
1049   connect(ui->button_choose_result_dir, SIGNAL(clicked()), this, SLOT(choose_local_directory()));
1050
1051   registerField("batch_directory", ui->line_remote_working_dir);
1052   registerField("result_directory", ui->line_result_dir);
1053
1054   // Default result directory is home directory (if we found it)
1055   ui->line_result_dir->setText(QDir::homePath());
1056
1057   parent->setFilesList(ui->input_files_list, ui->output_files_list);
1058
1059   // Check for warning messages
1060   ui->label_warning_icon->setPixmap(QIcon::fromTheme("dialog-error").pixmap(16, 16));
1061   connect(ui->line_remote_working_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
1062   connect(ui->line_result_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
1063 };
1064
1065 FilesPage::~FilesPage()
1066 {
1067   delete ui;
1068 }
1069
1070 void
1071 FilesPage::initializePage()
1072 {
1073   QString f_resource_choosed = field("resource_choosed").toString();
1074   if (f_resource_choosed != resource_choosed)
1075   {
1076     resource_choosed = f_resource_choosed;
1077     // If choosed resource has a working_directory set
1078     // Generates a default remote working directory
1079     BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1080     QString res_work_dir = resource_descr.working_directory.c_str();
1081     if (res_work_dir != "")
1082     {
1083       time_t rawtime;
1084       time(&rawtime);
1085       std::string launch_date = ctime(&rawtime);
1086       for (int i = 0; i < launch_date.size(); i++)
1087         if (launch_date[i] == '/' ||
1088             launch_date[i] == '-' ||
1089             launch_date[i] == ':' ||
1090             launch_date[i] == ' ')
1091           launch_date[i] = '_';
1092       launch_date.erase(--launch_date.end()); // Last caracter is a \n
1093       QString date = launch_date.c_str();
1094       setField("batch_directory", res_work_dir + "/" + date);
1095     }
1096   }
1097 }
1098
1099 bool
1100 FilesPage::isComplete() const
1101 {
1102   QString warn_msg;
1103   if (field("batch_directory").toString().isEmpty())
1104     warn_msg = "Remote working directory is mandatory.";
1105   if (field("result_directory").toString().isEmpty() && ui->output_files_list->count() != 0)
1106   {
1107     if (!warn_msg.isEmpty()) warn_msg += "\n";
1108     warn_msg += "Result directory is mandatory if there are output files.";
1109   }
1110
1111   ui->label_warning_text->setText(warn_msg);
1112   if (warn_msg.isEmpty())
1113   {
1114     ui->label_warning_icon->hide();
1115     return true;
1116   }
1117   else
1118   {
1119     ui->label_warning_icon->show();
1120     return false;
1121   }
1122 }
1123
1124 void
1125 FilesPage::choose_input_files()
1126 {
1127   // We need to be able to select both files and folders.
1128   // Standard QFileDialog cannot do it.
1129   QFileDialog w(this, tr("Select input files"),
1130               "", tr("All files and folders(*)")) ;
1131   w.setOption(QFileDialog::DontUseNativeDialog,true);
1132   QListView *l = w.findChild<QListView*>("listView");
1133   if (l)
1134   {
1135     l->setSelectionMode(QAbstractItemView::MultiSelection);
1136   }
1137   QTreeView *t = w.findChild<QTreeView*>();
1138   if (t)
1139   {
1140     t->setSelectionMode(QAbstractItemView::MultiSelection);
1141   }
1142   if(w.exec())
1143   {
1144     QStringList files = w.selectedFiles();
1145     for (int i = 0; i < files.size(); ++i)
1146     {
1147       if (ui->input_files_list->findItems(files.at(i), Qt::MatchFixedString).size() == 0)
1148         ui->input_files_list->addItem(files.at(i));
1149     }
1150   }
1151 }
1152
1153 void
1154 FilesPage::choose_local_directory()
1155 {
1156   QString dir = QFileDialog::getExistingDirectory(this, tr("Choose local result directory"),
1157                                                  "",
1158                                                  QFileDialog::ShowDirsOnly
1159                                                  | QFileDialog::DontResolveSymlinks);
1160
1161   if (dir != "")
1162     ui->line_result_dir->setText(dir);
1163 }
1164
1165 void 
1166 FilesPage::remove_input_files()
1167 {
1168   QList<QListWidgetItem *> list = ui->input_files_list->selectedItems();
1169   for (int i = 0; i < list.size(); ++i)
1170   {
1171     int row = ui->input_files_list->row( list.at(i) );
1172     delete ui->input_files_list->takeItem(row);
1173   }
1174 }
1175
1176 void 
1177 FilesPage::input_itemSelectionChanged()
1178 {
1179   if (ui->input_files_list->selectedItems().size() > 0)
1180     ui->remove_input_files_button->setEnabled(true);
1181   else
1182     ui->remove_input_files_button->setEnabled(false);
1183 }
1184
1185 void
1186 FilesPage::add_output_file()
1187 {
1188   QListWidgetItem * new_item = new QListWidgetItem("TO EDIT!");
1189   new_item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
1190   ui->output_files_list->addItem(new_item);
1191   emit completeChanged();
1192 }
1193
1194 void 
1195 FilesPage::remove_output_files()
1196 {
1197   QList<QListWidgetItem *> list = ui->output_files_list->selectedItems();
1198   for (int i = 0; i < list.size(); ++i)
1199   {
1200     int row = ui->output_files_list->row( list.at(i) );
1201     delete ui->output_files_list->takeItem(row);
1202   }
1203   emit completeChanged();
1204 }
1205
1206 void 
1207 FilesPage::output_itemSelectionChanged()
1208 {
1209   if (ui->output_files_list->selectedItems().size() > 0)
1210     ui->remove_output_files_button->setEnabled(true);
1211   else
1212     ui->remove_output_files_button->setEnabled(false);
1213 }
1214
1215 int 
1216 FilesPage::nextId() const
1217 {
1218   return BL::CreateJobWizard::Page_Advanced;
1219 }
1220
1221 BL::ConclusionPage::ConclusionPage(QWidget * parent)
1222 : QWizardPage(parent)
1223 {
1224   setTitle("Job definition is finished");
1225   QCheckBox * check_box =  new QCheckBox("Start job after creation");
1226   registerField("start_job", check_box);
1227   QVBoxLayout * main_layout = new QVBoxLayout;
1228   main_layout->addWidget(check_box);
1229   setLayout(main_layout);
1230 };
1231
1232 BL::ConclusionPage::~ConclusionPage()
1233 {}
1234
1235 bool
1236 BL::ConclusionPage::validatePage()
1237 {
1238   return true;
1239 }
1240
1241 int 
1242 BL::ConclusionPage::nextId() const
1243 {
1244   return -1;
1245 }
1246
1247 BL::ResourcePage::ResourcePage(BL::CreateJobWizard * parent, BL::SALOMEServices * salome_services)
1248 : QWizardPage(parent)
1249 {
1250   _salome_services = salome_services;
1251   setTitle("Select a Resource");
1252
1253   QLabel * main_label = new QLabel("In this step you select the resource of your job");
1254   main_label->setWordWrap(true);
1255
1256   // input_Resource
1257   QGroupBox * resource_group_box = new QGroupBox("Resource List");
1258   _resource_list = new JM::ResourceCatalog(this, _salome_services, true);
1259   connect(_resource_list->getQListWidget(), SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemSelected(QListWidgetItem*)));
1260
1261   QVBoxLayout * resource_list_layout = new QVBoxLayout();
1262   resource_list_layout->addWidget(_resource_list);
1263   resource_group_box->setLayout(resource_list_layout);
1264
1265   QLabel * resource_label = new QLabel("Resource selected: ");
1266   _resource_choosed = new QLineEdit();
1267   _resource_choosed->setText("");
1268   _resource_choosed->setReadOnly(true);
1269   registerField("resource_choosed", _resource_choosed);
1270
1271   QLabel * bqLabel = new QLabel("Batch Queue (could be optional):");
1272   QLineEdit * _bqLineEdit = new QLineEdit(this);
1273   registerField("batch_queue", _bqLineEdit);
1274
1275   QLabel * bpLabel = new QLabel("Batch Partition (could be optional):");
1276   QLineEdit * _bpLineEdit = new QLineEdit(this);
1277   registerField("batch_partition", _bpLineEdit);
1278
1279   _ll_label = new QLabel("LoadLeveler JobType:", this);
1280   _ll_value = new QLineEdit(this);
1281   registerField("ll_jobtype", _ll_value);
1282   _ll_label->hide();
1283   _ll_value->hide();
1284
1285   _main_layout = new QGridLayout;
1286   _main_layout->addWidget(resource_group_box, 0, 0, 1, -1);
1287   _main_layout->addWidget(resource_label, 1, 0);
1288   _main_layout->addWidget(_resource_choosed, 1, 1);
1289   _main_layout->addWidget(bqLabel, 2, 0);
1290   _main_layout->addWidget(_bqLineEdit, 2, 1);
1291   _main_layout->addWidget(bpLabel, 3, 0);
1292   _main_layout->addWidget(_bpLineEdit, 3, 1);
1293   setLayout(_main_layout);
1294
1295 };
1296
1297 BL::ResourcePage::~ResourcePage()
1298 {}
1299
1300 void
1301 BL::ResourcePage::initializePage()
1302 {
1303   if (field("ll_jobtype").toString() != "")
1304   {
1305     _main_layout->addWidget(_ll_label, 3, 0);
1306     _main_layout->addWidget(_ll_value, 3, 1);
1307     _ll_label->show();
1308     _ll_value->show();
1309   }
1310
1311   // Initialize resource_choosed with first resource in resource list
1312   if (field("resource_choosed").toString() == "")
1313   {
1314     std::list<std::string> resource_list = _salome_services->getResourceList(true);
1315     std::list<std::string>::iterator it = resource_list.begin();
1316     if (it != resource_list.end())
1317     {
1318       QString first_resource((*it).c_str());
1319       setField("resource_choosed", first_resource);
1320     }
1321   }
1322 }
1323
1324 bool
1325 BL::ResourcePage::validatePage()
1326 {
1327   QString resource_choosed = field("resource_choosed").toString();
1328   if (resource_choosed == "")
1329   {
1330     QMessageBox::warning(NULL, "Resource Error", "Please choose a resource");
1331     return false;
1332   }
1333
1334   BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1335   std::string batch = resource_descr.batch.c_str();
1336   if (batch == "ll")
1337   {
1338     QString ll_jobtype = field("ll_jobtype").toString();
1339     if (ll_jobtype == "")
1340     {
1341       QMessageBox::warning(NULL, "LoadLeveler Error", "Please define a LoadLeveler JobType");
1342       return false;
1343     }
1344   }
1345   return true;
1346 }
1347
1348 void 
1349 BL::ResourcePage::itemSelected(QListWidgetItem * item)
1350 {
1351   _resource_choosed->setReadOnly(false);
1352   _resource_choosed->setText(item->text());
1353   _resource_choosed->setReadOnly(true);
1354
1355   //Specific parameters for LoadLeveler
1356   BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(item->text().toUtf8().constData());
1357   std::string batch = resource_descr.batch.c_str();
1358   if (batch == "ll")
1359   {
1360     _main_layout->addWidget(_ll_label, 3, 0);
1361     _main_layout->addWidget(_ll_value, 3, 1);
1362     _ll_label->show();
1363     _ll_value->show();
1364   }
1365   else
1366   {
1367     _main_layout->removeWidget(_ll_value);
1368     _main_layout->removeWidget(_ll_label);
1369     _ll_label->hide();
1370     _ll_value->hide();
1371   }
1372 }
1373
1374 int 
1375 BL::ResourcePage::nextId() const
1376 {
1377   BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_choosed->text().toUtf8().constData());
1378   std::string batch = resource_descr.batch.c_str();
1379   if (batch == "coorm")
1380   {
1381           return BL::CreateJobWizard::Page_COORM_BatchParameters;
1382   }
1383   else
1384   {
1385           return BL::CreateJobWizard::Page_BatchParameters;
1386   }
1387 }
1388
1389 BL::PythonSalomeMainPage::PythonSalomeMainPage(QWidget * parent)
1390 : QWizardPage(parent)
1391 {
1392   setTitle("Define a Python script in SALOME job");
1393   QLabel *label = new QLabel("Enter the Python script that will be executed into the resource");
1394   label->setWordWrap(true);
1395
1396   // PythonSalome
1397   QPushButton * PythonSalome_file_button = new QPushButton(tr("Choose a Python file"));
1398   connect(PythonSalome_file_button, SIGNAL(clicked()), this, SLOT(choose_PythonSalome_file()));
1399   _line_PythonSalome = new QLineEdit(this);
1400   registerField("PythonSalome", _line_PythonSalome);
1401   _line_PythonSalome->setReadOnly(true);
1402
1403   QPushButton * PythonSalome_env_file_button = new QPushButton(tr("Choose an environnement file"));
1404   connect(PythonSalome_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
1405   _line_env_file = new QLineEdit(this);
1406   registerField("env_PythonSalome_file", _line_env_file);
1407   _line_env_file->setReadOnly(true);
1408
1409   QPushButton * command_pre_command_button = new QPushButton(tr("Choose a pre processing script"));
1410   connect(command_pre_command_button, SIGNAL(clicked()),
1411           this, SLOT(choose_pre_command_file()));
1412   _line_pre_command = new QLineEdit(this);
1413   registerField("pre_PythonSalome_file", _line_pre_command);
1414   _line_pre_command->setReadOnly(true);
1415
1416   QGridLayout *layout = new QGridLayout;
1417   layout->addWidget(PythonSalome_file_button, 0, 0);
1418   layout->addWidget(_line_PythonSalome, 0, 1);
1419   layout->addWidget(PythonSalome_env_file_button, 1, 0);
1420   layout->addWidget(_line_env_file, 1, 1);
1421   layout->addWidget(command_pre_command_button, 2, 0);
1422   layout->addWidget(_line_pre_command, 2, 1);
1423
1424   QVBoxLayout * main_layout = new QVBoxLayout;
1425   main_layout->addWidget(label);
1426   main_layout->insertLayout(-1, layout);
1427   setLayout(main_layout);
1428 };
1429
1430 BL::PythonSalomeMainPage::~PythonSalomeMainPage()
1431 {}
1432
1433 void
1434 BL::PythonSalomeMainPage::choose_PythonSalome_file()
1435 {
1436   QString PythonSalome_file = QFileDialog::getOpenFileName(this,
1437                                                       tr("Open Python script file"), "",
1438                                                       tr("py (*.py);;All Files (*)"));
1439   _line_PythonSalome->setReadOnly(false);
1440   _line_PythonSalome->setText(PythonSalome_file);
1441   _line_PythonSalome->setReadOnly(true);
1442 }
1443
1444 void
1445 BL::PythonSalomeMainPage::choose_env_file()
1446 {
1447   QString env_file = QFileDialog::getOpenFileName(this,
1448                                                       tr("Open environnement file"), "",
1449                                                       tr("sh (*.sh);;All Files (*)"));
1450   _line_env_file->setReadOnly(false);
1451   _line_env_file->setText(env_file);
1452   _line_env_file->setReadOnly(true);
1453 }
1454
1455 void
1456 BL::PythonSalomeMainPage::choose_pre_command_file()
1457 {
1458   QString pre_command_file = QFileDialog::getOpenFileName(this,
1459                                                     tr("Open script file"), "",
1460                                                     tr("All Files (*)"));
1461   _line_pre_command->setReadOnly(false);
1462   _line_pre_command->setText(pre_command_file);
1463   _line_pre_command->setReadOnly(true);
1464 }
1465
1466 bool
1467 BL::PythonSalomeMainPage::validatePage()
1468 {
1469   QString PythonSalome = field("PythonSalome").toString();
1470   if (PythonSalome == "")
1471   {
1472     QMessageBox::warning(NULL, "Python script in SALOME Error", "Please enter a Python script");
1473     return false;
1474   }
1475
1476   return true;
1477 }
1478
1479 int 
1480 BL::PythonSalomeMainPage::nextId() const
1481 {
1482   return BL::CreateJobWizard::Page_Resource;
1483 }
1484
1485
1486
1487 AdvancedParametersPage::AdvancedParametersPage(CreateJobWizard * parent)
1488 : QWizardPage(parent),
1489   ui(new Ui::AdvancedParametersWizardPage)
1490 {
1491   ui->setupUi(this);
1492   registerField("wckey", ui->line_wckey);
1493   registerField("extra_params", ui->text_extra_params, "plainText", "textChanged()");
1494 };
1495
1496 AdvancedParametersPage::~AdvancedParametersPage()
1497 {
1498   delete ui;
1499 }
1500
1501 int
1502 AdvancedParametersPage::nextId() const
1503 {
1504   return BL::CreateJobWizard::Page_Conclusion;
1505 }