Files
itgmania212121/stepmania/src/arch/Dialog/Dialog.cpp
T

237 lines
5.8 KiB
C++
Raw Normal View History

#include "global.h"
#include "Dialog.h"
#include "DialogDriver.h"
#if !defined(SMPACKAGE)
#include "PrefsManager.h"
#endif
#include "RageUtil.h"
#include "RageLog.h"
#include "arch/arch.h"
#include "RageThreads.h"
#if !defined(SMPACKAGE)
2006-01-06 17:57:03 +00:00
static Preference<RString> g_sIgnoredDialogs( "IgnoredDialogs", "" );
#endif
#include "Selector_Dialog.h"
DialogDriver *MakeDialogDriver()
{
2006-01-06 17:57:03 +00:00
RString sDrivers = "win32,cocoa,null";
vector<RString> asDriversToTry;
2005-06-03 23:42:07 +00:00
split( sDrivers, ",", asDriversToTry, true );
2005-06-03 23:42:07 +00:00
ASSERT( asDriversToTry.size() != 0 );
2006-01-06 17:57:03 +00:00
RString sDriver;
2005-06-03 23:42:07 +00:00
DialogDriver *pRet = NULL;
2005-06-03 23:42:07 +00:00
for( unsigned i = 0; pRet == NULL && i < asDriversToTry.size(); ++i )
{
2005-06-03 23:42:07 +00:00
sDriver = asDriversToTry[i];
#ifdef USE_DIALOG_DRIVER_COCOA
2005-06-03 23:42:07 +00:00
if( !asDriversToTry[i].CompareNoCase("Cocoa") ) pRet = new DialogDriver_Cocoa;
#endif
#ifdef USE_DIALOG_DRIVER_NULL
2005-06-03 23:42:07 +00:00
if( !asDriversToTry[i].CompareNoCase("Null") ) pRet = new DialogDriver_Null;
#endif
#ifdef USE_DIALOG_DRIVER_WIN32
2005-06-03 23:42:07 +00:00
if( !asDriversToTry[i].CompareNoCase("Win32") ) pRet = new DialogDriver_Win32;
#endif
2005-06-03 23:42:07 +00:00
if( pRet == NULL )
{
continue;
}
2006-01-06 17:57:03 +00:00
RString sError = pRet->Init();
if( sError != "" )
{
if( LOG )
2005-06-03 23:42:07 +00:00
LOG->Info( "Couldn't load driver %s: %s", asDriversToTry[i].c_str(), sError.c_str() );
SAFE_DELETE( pRet );
}
}
2005-06-03 23:42:07 +00:00
return pRet;
}
static DialogDriver *g_pImpl = NULL;
2004-09-05 01:22:09 +00:00
static DialogDriver_Null g_NullDriver;
static bool g_bWindowed = true; // Start out true so that we'll show errors before DISPLAY is init'd.
2006-03-09 10:47:46 +00:00
static bool DialogsEnabled()
{
return !g_bWindowed;
}
void Dialog::Init()
{
if( g_pImpl != NULL )
return;
g_pImpl = MakeDialogDriver();
2004-09-05 01:20:55 +00:00
/* DialogDriver_Null should have worked, at least. */
ASSERT( g_pImpl != NULL );
}
void Dialog::Shutdown()
{
2004-06-16 01:08:38 +00:00
delete g_pImpl;
g_pImpl = NULL;
}
2006-01-06 17:57:03 +00:00
static bool MessageIsIgnored( RString sID )
{
#if !defined(SMPACKAGE)
2006-01-06 17:57:03 +00:00
vector<RString> asList;
split( g_sIgnoredDialogs, ",", asList );
2005-06-03 23:42:07 +00:00
for( unsigned i = 0; i < asList.size(); ++i )
if( !sID.CompareNoCase(asList[i]) )
return true;
#endif
return false;
}
2006-01-06 17:57:03 +00:00
void Dialog::IgnoreMessage( RString sID )
{
/* We can't ignore messages before PREFSMAN is around. */
#if !defined(SMPACKAGE)
if( PREFSMAN == NULL )
{
2005-06-03 23:42:07 +00:00
if( sID != "" && LOG )
LOG->Warn( "Dialog: message \"%s\" set ID too early for ignorable messages", sID.c_str() );
return;
}
2005-06-03 23:42:07 +00:00
if( sID == "" )
2004-06-16 01:08:38 +00:00
return;
2005-06-03 23:42:07 +00:00
if( MessageIsIgnored(sID) )
return;
2006-01-06 17:57:03 +00:00
vector<RString> asList;
split( g_sIgnoredDialogs, ",", asList );
2005-06-03 23:42:07 +00:00
asList.push_back( sID );
g_sIgnoredDialogs.Set( join(",",asList) );
2005-10-27 12:46:05 +00:00
PREFSMAN->SavePrefsToDisk();
#endif
}
2006-01-06 17:57:03 +00:00
void Dialog::Error( RString sMessage, RString sID )
{
Dialog::Init();
2005-01-28 03:43:47 +00:00
if( LOG )
2005-06-03 23:42:07 +00:00
LOG->Trace( "Dialog: \"%s\" [%s]", sMessage.c_str(), sID.c_str() );
2005-01-16 20:32:53 +00:00
2005-06-03 23:42:07 +00:00
if( sID != "" && MessageIsIgnored(sID) )
return;
RageThread::SetIsShowingDialog( true );
2005-06-03 23:42:07 +00:00
g_pImpl->Error( sMessage, sID );
RageThread::SetIsShowingDialog( false );
}
void Dialog::SetWindowed( bool bWindowed )
{
g_bWindowed = bWindowed;
}
2006-01-06 17:57:03 +00:00
void Dialog::OK( RString sMessage, RString sID )
{
Dialog::Init();
2005-02-01 06:05:26 +00:00
if( LOG )
2005-06-03 23:42:07 +00:00
LOG->Trace( "Dialog: \"%s\" [%s]", sMessage.c_str(), sID.c_str() );
2005-01-16 20:32:53 +00:00
2005-06-03 23:42:07 +00:00
if( sID != "" && MessageIsIgnored(sID) )
return;
RageThread::SetIsShowingDialog( true );
// only show Dialog if windowed
2006-03-09 10:47:46 +00:00
if( DialogsEnabled() )
2005-06-03 23:42:07 +00:00
g_pImpl->OK( sMessage, sID ); // call derived version
2006-03-10 20:01:25 +00:00
else
g_NullDriver.OK( sMessage, sID );
RageThread::SetIsShowingDialog( false );
}
2006-01-06 17:57:03 +00:00
Dialog::Result Dialog::AbortRetryIgnore( RString sMessage, RString sID )
{
Dialog::Init();
2005-01-28 03:43:47 +00:00
if( LOG )
2005-06-03 23:42:07 +00:00
LOG->Trace( "Dialog: \"%s\" [%s]", sMessage.c_str(), sID.c_str() );
2005-01-16 20:32:53 +00:00
2005-06-03 23:42:07 +00:00
if( sID != "" && MessageIsIgnored(sID) )
return g_NullDriver.AbortRetryIgnore( sMessage, sID );
RageThread::SetIsShowingDialog( true );
// only show Dialog if windowed
2004-08-09 19:50:09 +00:00
Dialog::Result ret;
2006-03-09 10:47:46 +00:00
if( DialogsEnabled() )
2005-06-03 23:42:07 +00:00
ret = g_pImpl->AbortRetryIgnore( sMessage, sID ); // call derived version
2006-03-10 20:01:25 +00:00
else
ret = g_NullDriver.AbortRetryIgnore( sMessage, sID );
RageThread::SetIsShowingDialog( false );
2004-08-09 19:50:09 +00:00
return ret;
}
2006-01-06 17:57:03 +00:00
Dialog::Result Dialog::AbortRetry( RString sMessage, RString sID )
{
Dialog::Init();
2005-01-28 03:43:47 +00:00
if( LOG )
2005-06-03 23:42:07 +00:00
LOG->Trace( "Dialog: \"%s\" [%s]", sMessage.c_str(), sID.c_str() );
2005-01-16 20:32:53 +00:00
2005-06-03 23:42:07 +00:00
if( sID != "" && MessageIsIgnored(sID) )
return g_NullDriver.AbortRetry( sMessage, sID );
RageThread::SetIsShowingDialog( true );
// only show Dialog if windowed
2004-08-09 19:50:09 +00:00
Dialog::Result ret;
2006-03-09 10:47:46 +00:00
if( DialogsEnabled() )
2005-06-03 23:42:07 +00:00
ret = g_pImpl->AbortRetry( sMessage, sID ); // call derived version
2006-03-10 20:01:25 +00:00
else
ret = g_NullDriver.AbortRetry( sMessage, sID );
RageThread::SetIsShowingDialog( false );
2004-08-09 19:50:09 +00:00
return ret;
}
/*
* (c) 2003-2004 Glenn Maynard, Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/