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: Timo Sachsenberg $
25
// $Authors: Marc Sturm $
26
// --------------------------------------------------------------------------
28
#include <OpenMS/VISUAL/APPLICATIONS/INIFileEditorWindow.h>
29
#include <OpenMS/CONCEPT/LogStream.h>
30
#include <OpenMS/SYSTEM/File.h>
32
#include <QtGui/QToolBar>
33
#include <QtCore/QString>
34
#include <QtGui/QFileDialog>
35
#include <QtGui/QMenu>
36
#include <QtGui/QMenuBar>
37
#include <QtGui/QMessageBox>
38
#include <QtGui/QCloseEvent>
39
#include <QtGui/QGridLayout>
40
#include <QtGui/QCheckBox>
47
INIFileEditorWindow::INIFileEditorWindow(QWidget *parent)
48
: QMainWindow(parent),
51
setWindowTitle("INIFileEditor");
52
setWindowIcon(QIcon(":/INIFileEditor.png"));
54
//create central widget and layout
55
QWidget* central_widget = new QWidget;
56
setCentralWidget(central_widget);
57
QGridLayout* layout = new QGridLayout(central_widget);
59
//create advanced check box and ParamEditor and connect them
60
editor_=new ParamEditor(central_widget);
61
layout->addWidget(editor_,0,0,1,2);
63
QMenu* file = new QMenu("&File",this);
64
menuBar()->addMenu(file);
65
file->addAction("&Open",this,SLOT(openFile()), Qt::CTRL+Qt::Key_O);
67
file->addAction("&Save",this,SLOT(saveFile()), Qt::CTRL+Qt::Key_S);
68
file->addAction("Save &As",this,SLOT(saveFileAs()));
70
file->addAction("&Quit",this,SLOT(close()));
72
// we connect the "changes state"(changes made/no changes) signal from the ParamEditor to the window title updating slot
73
connect(editor_,SIGNAL(modified(bool)),this,SLOT(updateWindowTitle(bool)));
75
setMinimumSize(600,600);
78
bool INIFileEditorWindow::openFile(const String& filename)
82
filename_=QFileDialog::getOpenFileName(this,tr("Open ini file"),current_path_.toQString(),tr("ini files (*.ini);; all files (*.*)"));
86
filename_ = filename.c_str();
89
if(!filename_.isEmpty())
91
if (File::readable(filename_.toStdString()))
96
param_.load(filename_.toStdString());
97
editor_->load(param_);
98
updateWindowTitle(editor_->isModified());
101
catch (Exception::BaseException &e)
103
LOG_ERROR << "Error while parsing file '" << filename_.toStdString() << "'\n";
104
LOG_ERROR << e << "\n";
108
QMessageBox::critical(this,"Error opening file",("The file '"+filename_.toStdString()+"' does not exist, is not readable or not a proper INI file!").c_str());
114
bool INIFileEditorWindow::saveFile()
116
if(filename_.isEmpty())
123
param_.store(filename_.toStdString());
124
updateWindowTitle(editor_->isModified());
129
bool INIFileEditorWindow::saveFileAs()
131
filename_=QFileDialog::getSaveFileName(this,tr("Save ini file"),current_path_.toQString(),tr("ini files (*.ini)"));
132
if(!filename_.isEmpty())
134
if(!filename_.endsWith(".ini")) filename_.append(".ini");
138
param_.store(filename_.toStdString());
139
updateWindowTitle(editor_->isModified());
145
void INIFileEditorWindow::closeEvent(QCloseEvent* event)
147
if(editor_->isModified())
149
QMessageBox::StandardButton result=QMessageBox::question(this,"Save?","Do you want to save your changes?",QMessageBox::Ok|QMessageBox::Cancel|QMessageBox::Discard);
150
if (result==QMessageBox::Ok)
161
else if(result==QMessageBox::Cancel)
176
void INIFileEditorWindow::updateWindowTitle(bool update)
178
//update window title
181
setWindowTitle((File::basename(filename_) + " * - INIFileEditor").toQString());
185
setWindowTitle((File::basename(filename_) + " - INIFileEditor").toQString());
188
//update last path as well
189
current_path_ = File::path(filename_);