Skip to content

Commit

Permalink
added critical error signal and messagebox for the applicationinterface
Browse files Browse the repository at this point in the history
  • Loading branch information
weschristiansen committed Jan 12, 2011
1 parent 081357f commit 5d17a0a
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 101 deletions.
187 changes: 95 additions & 92 deletions src/Application/ProjectManager/ProjectManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ ProjectManager::ProjectManager() :

this->current_project_ = ProjectHandle( new Project( "untitled_project" ) );

// Connect the signals from the LayerManager to the GUI
this->add_connection( this->current_project_->project_name_state_->value_changed_signal_.connect(
boost::bind( &ProjectManager::rename_project, this, _1, _2 ) ) );
// // Connect the signals from the LayerManager to the GUI
// this->add_connection( this->current_project_->project_name_state_->value_changed_signal_.connect(
// boost::bind( &ProjectManager::rename_project, this, _1, _2 ) ) );

this->set_last_saved_session_time_stamp();
AutoSave::Instance()->start();
Expand Down Expand Up @@ -138,91 +138,91 @@ void ProjectManager::save_projectmanager_state()
stateio.export_to_file( this->local_projectmanager_path_ / "projectmanager.xml" );
}

void ProjectManager::rename_project( const std::string& new_name, Core::ActionSource source )
{

// If this is the first time the name has been set, then we set it, and return
if( !this->current_project_->is_valid() )
{
this->current_project_->set_valid( true );
return;
}

// return if rename gets called while we are in the middle of changing a project
if( changing_projects_ )
{
return;
}

std::vector< std::string > old_name_vector =
Core::SplitString( this->recent_projects_state_->get()[ 0 ], "|" );

// If the vector made from the old name, is less than 2, then we return
if( old_name_vector.size() < 2 )
return;

std::string old_name = old_name_vector[ 1 ];

// If the new name is the same as the old name we return
if( old_name == new_name )
return;

// If the old name is empty then something is wrong and we return
if( old_name == "" )
{
return;
}

boost::filesystem::path path = complete( boost::filesystem::path( this->
current_project_path_state_->get().c_str(), boost::filesystem::native ) );
try
{
boost::filesystem::rename( ( path / old_name ), ( path / new_name ) );
boost::filesystem::rename( ( path / new_name / ( old_name + ".s3d" ) ),
( path / new_name / ( new_name + ".s3d" ) ) );
}
catch ( std::exception& e )
{
CORE_LOG_ERROR( e.what() );
}

this->current_project_->project_name_state_->set( new_name );

std::vector< std::string > temp_projects_vector = this->recent_projects_state_->get();

// first we are going to remove this project from the list if its in there.
for( size_t i = 0; i < temp_projects_vector.size(); ++i )
{
if( temp_projects_vector[ i ] != "" )
{
std::string from_project_list = ( ( Core::SplitString( temp_projects_vector[ i ], "|" ) )[ 0 ]
+ "|" + ( Core::SplitString( temp_projects_vector[ i ], "|" ) )[ 1 ] );
std::string from_path_and_name = ( path.string() + "|" + old_name );

if( from_project_list == from_path_and_name )
{
temp_projects_vector.erase( temp_projects_vector.begin() + i );
}
}
}
this->recent_projects_state_->set( temp_projects_vector );

if( this->save_project_only( this->current_project_path_state_->get(), new_name ) )
{
this->add_to_recent_projects( this->current_project_path_state_->get(), new_name );

//this->current_project_->set_project_path( path / new_name );
this->set_project_path( path / new_name );

CORE_LOG_SUCCESS( "The project name has been successfully changed to: '" + new_name + "'" );
}
else
{
CORE_LOG_ERROR(
"There has been a problem setting the name of the project to: '" + new_name + "'" );
}

}
// void ProjectManager::rename_project( const std::string& new_name, Core::ActionSource source )
// {
//
// // If this is the first time the name has been set, then we set it, and return
// if( !this->current_project_->is_valid() )
// {
// this->current_project_->set_valid( true );
// return;
// }
//
// // return if rename gets called while we are in the middle of changing a project
// if( changing_projects_ )
// {
// return;
// }
//
// std::vector< std::string > old_name_vector =
// Core::SplitString( this->recent_projects_state_->get()[ 0 ], "|" );
//
// // If the vector made from the old name, is less than 2, then we return
// if( old_name_vector.size() < 2 )
// return;
//
// std::string old_name = old_name_vector[ 1 ];
//
// // If the new name is the same as the old name we return
// if( old_name == new_name )
// return;
//
// // If the old name is empty then something is wrong and we return
// if( old_name == "" )
// {
// return;
// }
//
// boost::filesystem::path path = complete( boost::filesystem::path( this->
// current_project_path_state_->get().c_str(), boost::filesystem::native ) );
// try
// {
// boost::filesystem::rename( ( path / old_name ), ( path / new_name ) );
// boost::filesystem::rename( ( path / new_name / ( old_name + ".s3d" ) ),
// ( path / new_name / ( new_name + ".s3d" ) ) );
// }
// catch ( std::exception& e )
// {
// CORE_LOG_ERROR( e.what() );
// }
//
// this->current_project_->project_name_state_->set( new_name );
//
// std::vector< std::string > temp_projects_vector = this->recent_projects_state_->get();
//
// // first we are going to remove this project from the list if its in there.
// for( size_t i = 0; i < temp_projects_vector.size(); ++i )
// {
// if( temp_projects_vector[ i ] != "" )
// {
// std::string from_project_list = ( ( Core::SplitString( temp_projects_vector[ i ], "|" ) )[ 0 ]
// + "|" + ( Core::SplitString( temp_projects_vector[ i ], "|" ) )[ 1 ] );
// std::string from_path_and_name = ( path.string() + "|" + old_name );
//
// if( from_project_list == from_path_and_name )
// {
// temp_projects_vector.erase( temp_projects_vector.begin() + i );
// }
// }
// }
// this->recent_projects_state_->set( temp_projects_vector );
//
// if( this->save_project_only( this->current_project_path_state_->get(), new_name ) )
// {
// this->add_to_recent_projects( this->current_project_path_state_->get(), new_name );
//
// //this->current_project_->set_project_path( path / new_name );
// this->set_project_path( path / new_name );
//
// CORE_LOG_SUCCESS( "The project name has been successfully changed to: '" + new_name + "'" );
// }
// else
// {
// CORE_LOG_ERROR(
// "There has been a problem setting the name of the project to: '" + new_name + "'" );
// }
//
// }

void ProjectManager::new_project( const std::string& project_name, const std::string& project_path,
bool save_on_creation )
Expand Down Expand Up @@ -341,13 +341,15 @@ bool ProjectManager::save_project( bool autosave /*= false*/, std::string sessio
{
if( autosave )
{
CORE_LOG_ERROR( "Autosave FAILED for project: '"
+ this->current_project_->project_name_state_->get() + "'" );
CORE_LOG_CRITICAL_ERROR( "Autosave FAILED for project: '"
+ this->current_project_->project_name_state_->get() + "'. Please perform a "
"'Save As' as soon as possible to preserve your data." );
}
else
{
CORE_LOG_ERROR( "Save FAILED for project: '"
+ this->current_project_->project_name_state_->get() + "'" );
CORE_LOG_CRITICAL_ERROR( "Save FAILED for project: '"
+ this->current_project_->project_name_state_->get() + "'. Please perform a "
"'Save As' as soon as possible to preserve your data." );
}
}
return save_success;
Expand Down Expand Up @@ -624,6 +626,7 @@ void ProjectManager::set_project_path( boost::filesystem::path path )
this->current_project_path_state_->set( path.parent_path().string() );
}


Seg3D::ProjectHandle ProjectManager::get_current_project() const
{
return this->current_project_;
Expand Down
6 changes: 3 additions & 3 deletions src/Application/ProjectManager/ProjectManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ class ProjectManager : public Core::StateHandler
// this will try and create the project folders and if is successfull return true
bool create_project_folders( boost::filesystem::path& path, const std::string& project_name );

// RENAME_PROJECT_FOLDER
// this function is triggered when a user changes the folder name
void rename_project( const std::string& new_name, Core::ActionSource source );
// // RENAME_PROJECT_FOLDER
// // this function is triggered when a user changes the folder name
// void rename_project( const std::string& new_name, Core::ActionSource source );

// SAVE_PROJECT_ONLY:
// this function saves only the project and is used internally only. It returns if it was
Expand Down
8 changes: 8 additions & 0 deletions src/Core/Utils/Log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ std::string Log::header( const int line, const char* file ) const
return header_string;
}

void Log::post_critical_error( std::string message, const int line, const char* file )
{
std::string str = this->header( line, file ) + std::string( " ERROR: " ) + message;
post_log_signal_( LogMessageType::ERROR_E, str );
post_status_signal_( LogMessageType::ERROR_E, message );
post_critical_signal_( LogMessageType::CRITICAL_ERROR_E, message );
}

void Log::post_error( std::string message, const int line, const char* file )
{
std::string str = this->header( line, file ) + std::string( " ERROR: " ) + message;
Expand Down
19 changes: 13 additions & 6 deletions src/Core/Utils/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ CORE_ENUM_CLASS
MESSAGE_E = 0x04,
DEBUG_E = 0x08,
SUCCESS_E = 0x16,
CRITICAL_ERROR_E = 0x32,
NODEBUG_E = ERROR_E | WARNING_E | MESSAGE_E,
ALL_E = ERROR_E | WARNING_E | MESSAGE_E | DEBUG_E,
STATUS_BAR_E = ERROR_E | SUCCESS_E
STATUS_BAR_E = ERROR_E | SUCCESS_E | CRITICAL_ERROR_E
)

// Class definition
Expand All @@ -79,29 +80,28 @@ class Log : public boost::noncopyable
// -- functions for logging --
public:

// POST_CRITICAL_ERROR:
// Post an error onto the log signal !!THIS WILL CAUSE AN ERROR DIALOG TO DISPLAY FOR THE USER!!
void post_critical_error( std::string message, const int line, const char* file );

// POST_ERROR:
// Post an error onto the log signal

void post_error( std::string message, const int line, const char* file );

// POST_WARNING:
// Post a warning onto the log signal

void post_warning( std::string message, const int line, const char* file );

// POST_MESSAGE:
// Post a message onto the log signal

void post_message( std::string message, const int line, const char* file );

// POST_SUCCESS:
// Post a message onto the log signal

void post_success( std::string message, const int line, const char* file );

// POST_DEBUG:
// Post debug information onto the log signal

void post_debug( std::string message, const int line, const char* file );

private:
Expand All @@ -120,12 +120,19 @@ class Log : public boost::noncopyable
// POST_STATUS_SIGNAL
// Signal indicating that a message needs to be written to the status bar
post_log_signal_type post_status_signal_;

// POST_CRITICAL_SIGNAL
// Signal indicating that a message needs to be written to the status bar
post_log_signal_type post_critical_signal_;

};

// MACROS FOR AUTOMATICALLY INCLUDING LINE NUMBER AND FILE IN THE
// LOG FILE

#define CORE_LOG_CRITICAL_ERROR(message)\
Core::Log::Instance()->post_critical_error(message,__LINE__,__FILE__)

#define CORE_LOG_ERROR(message)\
Core::Log::Instance()->post_error(message,__LINE__,__FILE__)

Expand Down
22 changes: 22 additions & 0 deletions src/Interface/Application/ApplicationInterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ ApplicationInterface::ApplicationInterface( std::string file_to_view_on_open ) :
this->add_connection( Core::ActionDispatcher::Instance()->report_progress_signal_.connect(
boost::bind( &ApplicationInterface::HandleReportProgress, qpointer_type( this ), _1 ) ) );

this->add_connection( Core::Log::Instance()->post_critical_signal_.connect(
boost::bind( &ApplicationInterface::HandleCriticalErrorMessage, qpointer_type( this ), _1, _2 ) ) );


// NOTE: Connect state and reflect the current state (needs to be atomic, hence the lock)
{
Expand Down Expand Up @@ -535,4 +538,23 @@ void ApplicationInterface::SetProjectName( qpointer_type qpointer, std::string p
&ApplicationInterface::set_project_name, qpointer.data(), project_name ) ) );
}

void ApplicationInterface::raise_error_messagebox( int msg_type, std::string message )
{
int ret = QMessageBox::critical( this, "CRITICAL ERROR!!",
QString::fromStdString( message ) );

// if( ret == QMessageBox::Ok )
// {
//
// }
}

void ApplicationInterface::HandleCriticalErrorMessage( qpointer_type qpointer, int msg_type, std::string message )
{
Core::Interface::PostEvent( QtUtils::CheckQtPointer( qpointer,
boost::bind( &ApplicationInterface::raise_error_messagebox, qpointer.data(), msg_type, message ) ) );
}



} // end namespace Seg3D
5 changes: 5 additions & 0 deletions src/Interface/Application/ApplicationInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ Q_OBJECT
// on top of each other
void addDockWidget( Qt::DockWidgetArea area, QDockWidget* dock_widget );

// RAISE_ERROR_MESSAGEBOX:
void raise_error_messagebox( int msg_type, std::string message );

// NOTE:
// We need to override these events for the progress widget that draws an transparent layer
// over the full GUI.
Expand Down Expand Up @@ -139,6 +142,8 @@ Q_OBJECT
static void HandleReportProgress( qpointer_type qpointer, Core::ActionProgressHandle handle);

static void HandlePreferencesManagerSave( qpointer_type qpointer, bool visible );

static void HandleCriticalErrorMessage( qpointer_type qpointer, int msg_type, std::string message );

// SETFULLSCREEN:
// Set full screen mode of the Main Window
Expand Down
5 changes: 5 additions & 0 deletions src/Interface/Application/SaveProjectAsWizard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ bool SaveAsInfoPage::validatePage()
this->warning_message_->show();
return false;
}
else
{
boost::filesystem::file_status fs = boost::filesystem::status( new_path.parent_path() );
}

this->warning_message_->hide();
return true;
}
Expand Down

0 comments on commit 5d17a0a

Please sign in to comment.