Commit fb4b3f35 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[CHANGE] - save button now catches exception an shows dialog

parent 17c69554
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include "WFileOpenFailed.h"
WFileOpenFailed::WFileOpenFailed( const std::string& msg )
: WException( msg )
{
// init members
}
WFileOpenFailed::~WFileOpenFailed() throw()
{
// clean up
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WFILEOPENFAILED_H
#define WFILEOPENFAILED_H
#include <string>
#include "../WException.h"
/**
* Thrown whenever a file could not be opened.
*/
class WFileOpenFailed : public WException
{
public:
/**
* Default constructor.
* \param msg the exception message.
*/
explicit WFileOpenFailed( const std::string& msg = "The file could not be opened." );
/**
* Destructor.
*/
virtual ~WFileOpenFailed() throw();
protected:
private:
};
#endif // WFILEOPENFAILED_H
......@@ -401,8 +401,19 @@ void WMainWindow::projectSave()
new WProjectFile( ( *constIterator ).toStdString() )
);
// This call is synchronous.
proj->save();
try
{
// This call is synchronous.
proj->save();
}
catch( const std::exception& e )
{
QString title = "Problem while saving project file.";
QString message = "<b>Problem while saving project file.</b><br/><br/><b>File: </b>" + ( *constIterator ) +
"<br/><b>Message: </b>" + QString::fromStdString( e.what() );
QMessageBox::critical( this, title, message );
}
}
}
......
......@@ -31,6 +31,7 @@
#include "WKernel.h"
#include "combiner/WModuleProjectFileCombiner.h"
#include "../common/exceptions/WFileNotFound.h"
#include "../common/exceptions/WFileOpenFailed.h"
#include "WProjectFile.h"
......@@ -68,7 +69,21 @@ void WProjectFile::load()
void WProjectFile::save()
{
wlog::info( "Project File" ) << "Saving project file \"" << m_project.file_string() << "\".";
wlog::info( "Project File" ) << "SORRY. Not yet implemented.";
// open the file for write
std::ofstream output( m_project.file_string().c_str() );
if ( !output.is_open() )
{
throw WFileOpenFailed( "The project file \"" + m_project.file_string() + "\" could not be opened for write access." );
}
// allow each parser to handle save request
for ( std::vector< WProjectFileParser* >::const_iterator iter = m_parsers.begin(); iter != m_parsers.end(); ++iter )
{
( *iter )->save( output );
}
output.close();
}
void WProjectFile::threadMain()
......
......@@ -25,6 +25,7 @@
#ifndef WPROJECTFILEPARSER_H
#define WPROJECTFILEPARSER_H
#include <ostream>
#include <string>
/**
......@@ -61,6 +62,13 @@ public:
*/
virtual void done();
/**
* Saves the state to the specified stream.
*
* \param output the stream to print the state to.
*/
virtual void save( std::ostream& output ) = 0;
protected:
private:
......
......@@ -289,3 +289,8 @@ void WModuleProjectFileCombiner::done()
apply();
}
void WModuleProjectFileCombiner::save( std::ostream& output )
{
}
......@@ -25,6 +25,7 @@
#ifndef WMODULEPROJECTFILECOMBINER_H
#define WMODULEPROJECTFILECOMBINER_H
#include <ostream>
#include <list>
#include <map>
#include <string>
......@@ -89,6 +90,13 @@ public:
*/
virtual void done();
/**
* Saves the state to the specified stream.
*
* \param output the stream to print the state to.
*/
virtual void save( std::ostream& output );
protected:
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment