RESULT
ParticleManager::Init( IN const string& settingsFilename )
{
    RETAILMSG(ZONE_PARTICLES, "ParticleManager::Init( %s )", settingsFilename.c_str());

    RESULT rval = S_OK;
    char   path[MAX_PATH];
    
    //
    // Create a Settings object and load the file.
    //
    Settings mySettings;
    if ( FAILED(mySettings.Read( settingsFilename )) )
    {
        RETAILMSG(ZONE_ERROR, "ERROR: ParticleManager::Init( %s ): failed to load settings file", settingsFilename.c_str() );
        return E_UNEXPECTED;
    }
    

    //
    // Create each ParticleEmitter.
    //
    UINT32 numParticleEmitters = mySettings.GetInt("/ParticleEmitters.NumParticleEmitters");

    for (int i = 0; i < numParticleEmitters; ++i)
    {
        sprintf(path, "/ParticleEmitters/ParticleEmitter%d", i);

        ParticleEmitter *pParticleEmitter = new ParticleEmitter();
        CPR(pParticleEmitter);

        string name             = mySettings.GetString( string(path) + ".Name" );
        string filename         = mySettings.GetString( string(path) + ".Filename" );
        bool   deleteOnFinish   = mySettings.GetBool  ( string(path) + ".DeleteOnFinish", false );

        pParticleEmitter->SetDeleteOnFinish( deleteOnFinish );
        if ( FAILED(pParticleEmitter->InitFromFile( filename )))
        {
            RETAILMSG(ZONE_ERROR, "ERROR: ParticleManager::Init( %s ): failed to init ParticleEmitter from file %s", filename.c_str());
            // Continue loading other ParticleEmitters rather than aborting.
            continue;
        }
            
        
        RETAILMSG(ZONE_INFO, "ParticleEmitter[%4d]: \"%-32s\"", pParticleEmitter->GetID(), pParticleEmitter->GetName().c_str());

        CHR(Add(name, pParticleEmitter));
    }
    
Exit:
    return rval;
}
std::string ConfigManager::get_value<std::string>(const Settings settings, const char* key) const
{
  if (key != nullptr)
  {
    if (settings.HasMember(key) && settings[key].IsString())
    {
      return settings[key].GetString();
    }
    else
      throw ConfigException("Configuration Manager: Parse error.");
  }
  else
  {
    if (settings.IsString())
      return settings.GetString();
    else
      throw ConfigException("Configuration Manager: Parse error.");
  }
}
Exemple #3
0
void BrowserWindow::HandleMessage( Message * pcMsg )
{
	BrowserWebView *pcWebView = GetCurrentWebView();

	switch( pcMsg->GetCode() )
	{
		case ID_URL_CHANGED:
		{
			bool bFinal = false;
			pcMsg->FindBool( "final", &bFinal );

			if( bFinal )
			{
				String cURL = "";
				int nSelection = -1;
				if( pcMsg->FindInt32( "selection", &nSelection ) == EOK )
					cURL = m_pcUrlEdit->GetItem( nSelection );
				else
				{
					cURL = m_pcUrlEdit->GetCurrentString();
					m_pcUrlEdit->AppendItem( cURL );
				}

				OpenURL( cURL );
			}
			break;
		}
		case ID_SET_STATUS_BAR_TEXT:
		{
			String cText;
			if( pcMsg->FindString( "text", &cText ) == EOK )
				m_pcStatusBar->SetText( "text", cText );
			break;
		}
		case ID_CLEAR_STATUS_BAR_TEXT:
		{
			m_pcStatusBar->SetText( "text", "" );
			break;
		}
		case ID_CREATE_WINDOW:
		{
			BrowserWindow *pcWindow;
			String cURL;
			Rect cFrame;

			/* Use the supplied dimensions if they've been provided, otherwise
			   clone the current Window */
			if( pcMsg->FindRect( "frame", &cFrame ) != EOK )
				cFrame = GetFrame();

			pcWindow = new BrowserWindow( cFrame );

			if( pcMsg->FindString( "url", &cURL ) == EOK )
				pcWindow->OpenURL( cURL );

			pcWindow->Show();
			pcWindow->MakeFocus();

			/* Tell BrowserApp about the new window */
			Application::GetInstance()->PostMessage( ID_WINDOW_OPENED );

			if( pcMsg->IsSourceWaiting() )
			{
				WebCore::Page *pcPage;
				View *pcTab;

				/* The new window will only have one tab at this stage so it's safe to always get tab #0 */
				pcTab = pcWindow->m_pcTabView->GetTabView( 0 );
				pcPage = static_cast<BrowserWebView*>( pcTab )->GetWebCoreFrame()->page();

				Message cReply( ID_CREATE_WINDOW_REPLY );
				cReply.AddPointer( "page", pcPage );

				pcMsg->SendReply( &cReply );
			}

			break;
		}
		case ID_CREATE_TAB:
		{
			String cURL;
			if( pcMsg->FindString( "url", &cURL ) == EOK )
			{
				uint nTabIndex;

				nTabIndex = CreateTab( cURL );

				if( pcMsg->IsSourceWaiting() )
				{
					WebCore::Page *pcPage;
					View *pcTab;

					pcTab = m_pcTabView->GetTabView( nTabIndex );
					pcPage = static_cast<BrowserWebView*>( pcTab )->GetWebCoreFrame()->page();

					Message cReply( ID_CREATE_WINDOW_REPLY );
					cReply.AddPointer( "page", pcPage );

					pcMsg->SendReply( &cReply );
				}
			}

			break;
		}
		case ID_BUTTON_BACK:
		{
			pcWebView->GoBack();

			UpdateButtonState( false );
			break;
		}
		case ID_BUTTON_FORWARD:
		{
			pcWebView->GoForward();

			UpdateButtonState( false );
			break;
		}
		case ID_BUTTON_RELOAD:
		{
			pcWebView->Reload();
			break;
		}
		case ID_BUTTON_STOP:
		{
			pcWebView->Stop();

			UpdateButtonState( false );
			break;
		}
		case ID_BUTTON_HOME:
		{
			OpenURL( m_pcSettings->GetString( "homepage", "about:blank" ) );
			break;
		}
		case ID_MENU_APP_ABOUT:
		{
			Alert* pcAbout = new Alert( "About Webster",
										"Webster " WEBSTER_VERSION " (Alpha)\nA WebCore based web browser\n\n© Copyright Kristian Van Der Vliet, 2008\nArno Klenke, 2004-2007\nKurt Skauen, 2001\n"
										"\nWebster is released under the Gnu Public License (GPL)\n",
										Alert::ALERT_INFO, 0x00, "Ok", NULL );
			pcAbout->Go( NULL );

			break;
		}
		case ID_MENU_WIN_NEW_TAB:
		{
			CreateTab( "" );
			break;
		}
		case ID_MENU_WIN_CLOSE_TAB:
		{
			DestroyTab( m_pcTabView->GetSelection() );
			break;
		}
		case ID_MENU_EDIT_CUT:
		{
			pcWebView->Cut();
			break;
		}
		case ID_MENU_EDIT_COPY:
		{
			pcWebView->Copy();
			break;
		}
		case ID_MENU_EDIT_PASTE:
		{
			pcWebView->Paste();
			break;
		}
		case ID_MENU_EDIT_DELETE:
		{
			pcWebView->Delete();
			break;
		}
		case ID_MENU_SETTINGS_CONFIGURE:
		{
			Rect cSettingsFrame = m_pcGuiSettings->GetRect( "settings", m_cSettingsFrame );
			SettingsWindow *pcSettingsWindow = new SettingsWindow( cSettingsFrame, "Webster settings", this, m_pcWebSettings, m_pcSettings, m_pcGuiSettings );
			pcSettingsWindow->Show();
			pcSettingsWindow->MakeFocus();

			break;
		}
		case ID_SETTINGS_SAVE:
		{
			Settings *pcSettings;
			if( pcMsg->FindPointer( "settings", (void**)&pcSettings ) == EOK )
			{
				delete m_pcSettings;
				m_pcSettings = pcSettings;

				m_pcSettings->Save();
			}

			WebSettings *pcWebSettings;
			if( pcMsg->FindPointer( "web_settings", (void**)&pcWebSettings ) == EOK )
			{
				delete m_pcWebSettings;
				m_pcWebSettings = pcWebSettings;
			}

			break;
		}
		case ID_SETTINGS_APPLY:
		{
			Settings *pcSettings;
			if( pcMsg->FindPointer( "settings", (void**)&pcSettings ) == EOK )
			{
				delete m_pcSettings;
				m_pcSettings = pcSettings;
			}

			WebSettings *pcWebSettings;
			if( pcMsg->FindPointer( "web_settings", (void**)&pcWebSettings ) == EOK )
			{
				delete m_pcWebSettings;
				m_pcWebSettings = pcWebSettings;
			}

			break;
		}
		case ID_MENU_BOOKMARKS_ADD:
		{
			String cShortTitle, cLongTitle, cURL;

			pcWebView->GetTitle( cShortTitle, cLongTitle );
			cURL = pcWebView->GetCurrentURL();

			m_pcBookmarksManager->AddBookmark( cLongTitle, cURL );

			break;
		}
		case ID_MENU_BOOKMARKS_MANAGE:
		{
			String cPath;
			if( pcMsg->FindString( "path", &cPath ) != EOK )
				break;

			/* XXXKV: This is a really rubbish way to manage bookmarks: we should have
			   a proper in-application dialog to do it */

			/* Open a filebrowser window */
			if( fork() == 0 )
			{
				set_thread_priority( -1, 0 );
				execlp( "/system/bin/FileBrowser", "/system/bin/FileBrowser", cPath.c_str(), NULL );
			}
			break;
		}
		case ID_BOOKMARK_GO:
		{
			String cURL;

			if( pcMsg->FindString( "url", &cURL ) == EOK )
				OpenURL( cURL );

			break;
		}
		case ID_TAB_CHANGED:
		{
			ChangeTab( m_pcTabView->GetSelection() );
			break;
		}
		case ID_WEBVIEW_SET_TITLE:
		{
			String cShortTitle, cLongTitle;
			uint nTabIndex;

			if( pcMsg->FindString( "short", &cShortTitle ) == EOK &&
				pcMsg->FindString( "long", &cLongTitle ) == EOK &&
				pcMsg->FindInt32( "index", (int32*)&nTabIndex ) == EOK )
			{
				m_pcTabView->SetTabTitle( nTabIndex, cShortTitle );

				/* If this is the currently selected tab, set the Window title to the full page title */
				if( nTabIndex == m_pcTabView->GetSelection() )
					SetTitle( cLongTitle );
			}

			break;
		}
		case ID_WEBVIEW_LOAD_STARTED:
		{
			String cURL;
			uint nTabIndex;

			if( pcMsg->FindString( "url", &cURL ) == EOK &&
				pcMsg->FindInt32( "index", (int32*)&nTabIndex ) == EOK )
			{
				if( nTabIndex == m_pcTabView->GetSelection() )
				{
					m_pcUrlEdit->SetCurrentString( cURL.c_str() );
					UpdateButtonState( true );
				}
			}
			break;
		}
		case ID_WEBVIEW_LOAD_FINISHED:
		{
			uint nTabIndex;
			if( pcMsg->FindInt32( "index", (int32*)&nTabIndex ) == EOK )
				if( nTabIndex == m_pcTabView->GetSelection() )
					UpdateButtonState( false );
			break;
		}
		default:
		{
			fprintf( stderr, "Unknown message with code #%d\n", pcMsg->GetCode() );
			Window::HandleMessage( pcMsg );
			break;
		}
	}
}