1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
// --------------------------------------------------------------------------
24
// $Maintainer: Johannes Junker $
25
// $Authors: Johannes Junker $
26
// --------------------------------------------------------------------------
29
#include <OpenMS/VISUAL/DIALOGS/TOPPASToolConfigDialog.h>
30
#include <OpenMS/VISUAL/ParamEditor.h>
31
#include <OpenMS/APPLICATIONS/TOPPBase.h>
32
#include <OpenMS/SYSTEM/File.h>
33
#include <QtCore/QStringList>
34
#include <QtGui/QPushButton>
35
#include <QtGui/QHBoxLayout>
36
#include <QtGui/QGridLayout>
37
#include <QtGui/QLabel>
38
#include <QtGui/QMessageBox>
39
#include <QtGui/QRadioButton>
40
#include <QtGui/QFileDialog>
41
#include <QtGui/QCheckBox>
47
TOPPASToolConfigDialog::TOPPASToolConfigDialog( QWidget * parent, Param& param, String default_dir, String tool_name, String tool_type, QVector<String> hidden_entries)
50
default_dir_(default_dir),
51
tool_name_(tool_name),
52
tool_type_(tool_type),
53
hidden_entries_(hidden_entries)
55
QGridLayout *main_grid = new QGridLayout(this);
57
//Add advanced mode check box
58
editor_ = new ParamEditor(this);
59
main_grid->addWidget(editor_,0,0,1,1);
61
QHBoxLayout* hbox = new QHBoxLayout;
62
QPushButton* load_button = new QPushButton(tr("&Load"));
63
connect(load_button,SIGNAL(clicked()),this,SLOT(loadINI_()));
64
hbox->addWidget(load_button);
65
QPushButton* store_button = new QPushButton(tr("&Store"));
66
connect(store_button,SIGNAL(clicked()),this,SLOT(storeINI_()));
67
hbox->addWidget(store_button);
71
QPushButton* cancel_button = new QPushButton(tr("&Cancel"));
72
connect(cancel_button,SIGNAL(clicked()),this,SLOT(reject()));
73
hbox->addWidget(cancel_button);
76
QPushButton* ok_button_ = new QPushButton(tr("&Ok"));
77
connect(ok_button_, SIGNAL(clicked()),this,SLOT(ok_()));
78
hbox->addWidget(ok_button_);
80
main_grid->addLayout(hbox,1,0,1,1);
84
editor_->load(*param_);
88
editor_->setFocus(Qt::MouseFocusReason);
90
setWindowTitle(tool_name.toQString() + " " + tr("configuration"));
93
TOPPASToolConfigDialog::~TOPPASToolConfigDialog()
98
void TOPPASToolConfigDialog::ok_()
105
void TOPPASToolConfigDialog::loadINI_()
108
filename_=QFileDialog::getOpenFileName(this,tr("Open ini file"),default_dir_.c_str(),tr("ini files (*.ini);; all files (*.*)"));
110
if(filename_.isEmpty())
114
if(!arg_param_.empty())
122
arg_param_.load(filename_.toStdString());
124
catch(Exception::BaseException& e)
126
QMessageBox::critical(this,"Error",(String("Error loading INI file: ")+e.getMessage()).c_str());
130
//Extract the required parameters
131
*param_=arg_param_.copy(tool_name_ + ":1:", true);
132
//param_->remove("log");
133
//param_->remove("no_progress");
134
//param_->remove("debug");
136
//remove parameters already explained by edges and the "type" parameter
137
foreach (const String& name, hidden_entries_)
139
param_->remove(name);
142
//load data into editor
143
editor_->load(*param_);
146
void TOPPASToolConfigDialog::storeINI_()
149
if (param_->empty()) return;
150
filename_=QFileDialog::getSaveFileName(this,tr("Save ini file"),default_dir_.c_str(),tr("ini files (*.ini)"));
152
if(filename_.isEmpty())
156
if(!filename_.endsWith(".ini")) filename_.append(".ini");
158
arg_param_.insert(tool_name_ + ":1:", *param_);
161
QString tmp_ini_file = File::getTempDirectory().toQString() + QDir::separator() + "TOPPAS_" + tool_name_.toQString() + "_";
162
if (tool_type_ != "")
164
tmp_ini_file += tool_type_.toQString() + "_";
166
tmp_ini_file += File::getUniqueName().toQString() + "_tmp.ini";
167
//store current parameters
168
arg_param_.store(tmp_ini_file.toStdString());
169
//restore other parameters that might be missing
170
String call = String("\"") + File::getExecutablePath() + tool_name_ + "\"" + " -write_ini " + String(filename_) + " -ini " + String(tmp_ini_file);
171
if (tool_type_ != "")
173
call += " -type " + tool_type_;
176
if (system(call.c_str()) != 0)
178
QMessageBox::critical(0, "Error", (String("Could not execute '") + call + "'!\n\nMake sure the TOPP tools are present in '" + File::getExecutablePath() + "', that you have permission to write to the temporary file path, and that there is space left in the temporary file path.").c_str());
182
catch(Exception::BaseException& e)
184
QMessageBox::critical(this,"Error",(String("Error storing INI file: ")+e.getMessage()).c_str());