Пример #1
0
void BrowserWindow::GoHistory( int nStep )
{

//	if ( nStep != 0 ) {
//	UpdateHistory();
//	}
	m_nCurHistoryPos += nStep;
	HistoryEntry* pcCurrent = HistoryCurrent();
	if ( pcCurrent != NULL ) {
		GlobalMutex::PushLooper( this );
		m_pcHTMLPart->browserExtension()->restoreState( pcCurrent->m_cState );
		m_pcURLView->Set( pcCurrent->m_cURL.c_str(), false );
		GlobalMutex::PopLooper();
	}
	if ( m_nCurHistoryPos == 0 ) {
	m_pcToolBar->EnableButton( BI_BACK, false );
	} else {
	m_pcToolBar->EnableButton( BI_BACK, true );
	}
	if ( m_nCurHistoryPos >= int(m_cHistory.size()) - 1 ) {
	m_pcToolBar->EnableButton( BI_FORWARD, false );
	} else {
	m_pcToolBar->EnableButton( BI_FORWARD, true );
	}
}
Пример #2
0
void BrowserWindow::MessageReceived( BMessage* pcMsg )
{
	switch( pcMsg->what )
	{
	case ID_URL_CHANGED:
	{

		std::string cURL = m_pcURLView->Text();

		for ( uint i = 0 ; i <= cURL.size() ; ++i ) {
			if ( i == cURL.size() || isalnum( cURL[i] ) == false ) {
				if ( i == cURL.size() || cURL[i] != ':' ) {
					std::string cTmp = cURL;
					cURL = "http://";
					for ( uint j = 0 ; j < cTmp.size() ; ++j ) {
						if ( cTmp[j] != '/' ) {
							cURL.insert( cURL.end(), cTmp.begin() + j, cTmp.end() );
							break;
						}
					}
				}
				break;
			}
		}
		m_pcHTMLPart->view()->MakeFocus();
		OpenURL( cURL, KParts::URLArgs() );
//----------------------------------------------
#if 0
		uint32 nEvents = 0;
		pcMsg->FindInt( "events", &nEvents );
		
		if ( nEvents & os::TextView::EI_ESC_PRESSED ) {
			m_pcURLView->Set( m_pcHTMLPart->url().prettyURL().utf8().data() );
			m_pcHTMLPart->view()->MakeFocus();
		break;
		}
		if ( nEvents & os::TextView::EI_ENTER_PRESSED ) {
		std::string cURL = m_pcURLView->GetBuffer()[0];

		for ( uint i = 0 ; i <= cURL.size() ; ++i ) {
			if ( i == cURL.size() || isalnum( cURL[i] ) == false ) {
				if ( i == cURL.size() || cURL[i] != ':' ) {
					std::string cTmp = cURL;
					cURL = "http://";
					for ( uint j = 0 ; j < cTmp.size() ; ++j ) {
						if ( cTmp[j] != '/' ) {
							cURL.insert( cURL.end(), cTmp.begin() + j, cTmp.end() );
							break;
						}
					}
				}
				break;
			}
		}
		UpdateHistory();
		AddHistoryEntry();
		m_pcHTMLPart->view()->MakeFocus();
		OpenURL( cURL, KParts::URLArgs() );
		UpdateHistory();
		}
#endif
		break;
	}
	case ID_ACTIVATE_URLEDIT:
		m_pcURLView->MakeFocus( true );
#if 0
		m_pcURLView->SetCursor( -1, 0 );
#endif
		m_pcURLView->TextView()->SelectAll();
		break;
	case ID_RELOAD:
	{
		KParts::URLArgs cArgs;
		cArgs.reload = true;
		cArgs.xOffset = m_pcHTMLPart->browserExtension()->xOffset();
		cArgs.yOffset = m_pcHTMLPart->browserExtension()->yOffset();
#if 0
		OpenURL( m_pcURLView->GetBuffer()[0], cArgs );
#endif
		OpenURL( m_pcURLView->Text(), cArgs );
		break;
	}
	case ID_NEW_WINDOW:
	{
		BrowserWindow* pcNewWindow = new BrowserWindow( Frame().OffsetByCopy( 30.0f, 30.0f ), false );
		pcNewWindow->Show();
#if 0
		UpdateHistory();
		std::vector<HistoryEntry*> cHistory = m_cHistory;
		cHistory.resize( m_nCurHistoryPos + 1 );
		BrowserWindow* pcNewWindow = new BrowserWindow( GetFrame() + os::Point( 30.0f, 30.0f ), &cHistory, false );
		pcNewWindow->GoHistory(0);
		pcNewWindow->Show( true );
		pcNewWindow->MakeFocus( true );	
#endif
		break;
	}
	case ID_OPEN_LINK:
	{
		BString cURL;
		pcMsg->FindString( "url", &cURL );
		BrowserWindow* pcNewWindow = new BrowserWindow( Frame().OffsetByCopy( 30.0f, 30.0f ), false  );
		pcNewWindow->OpenURL( cURL.String(), KParts::URLArgs() );
		pcNewWindow->Show();
#if 0
		std::string cURL;
		pcMsg->FindString( "url", &cURL );
		std::vector<HistoryEntry*> cHistory = m_cHistory;
		cHistory.resize( m_nCurHistoryPos + 1 );
		BrowserWindow* pcNewWindow = new BrowserWindow( GetFrame() + os::Point( 30.0f, 30.0f ), &cHistory, false );
		pcNewWindow->OpenURL( cURL, KParts::URLArgs() );
		pcNewWindow->AddHistoryEntry();
		pcNewWindow->Show( true );
		pcNewWindow->MakeFocus( true );	
#endif
		break;
	}
	case ID_SAVE_LINK:
	{
		BString cURL;
		pcMsg->FindString( "url", &cURL );

		m_pcHTMLPart->browserExtension()->SaveURL( cURL.String(), "Save link as..." );
		break;
	}
	case ID_COPY_LINK_LOCATION:
	{
#if 0
		std::string cURL;
		pcMsg->FindString( "url", &cURL );

		os::Clipboard cClipboard;
		cClipboard.Lock();
		cClipboard.Clear();
		os::Message* pcData = cClipboard.GetData();
		pcData->AddString( "text/plain", cURL );
		cClipboard.Commit();
		cClipboard.Unlock();
#endif
		break;
	}
	case ID_COPY:
	{
#if 0
		if ( m_cSelectedText.empty() ) {
			break;
		}
		os::Clipboard cClipboard;
		cClipboard.Lock();
		cClipboard.Clear();
		os::Message* pcData = cClipboard.GetData();
		pcData->AddString( "text/plain", m_cSelectedText );
		cClipboard.Commit();
		cClipboard.Unlock();
#endif
		break;
	}
	case ID_FIND:
#if 0
		if ( m_pcSearchDialog == NULL ) {
		m_pcHTMLPart->findTextBegin();
		m_pcSearchDialog = new FindDialog( os::Messenger(this), os::Message(ID_DO_SEARCH), os::Message(ID_SEARCH_CLOSED) );
		m_pcSearchDialog->Show();
		m_pcSearchDialog->MakeFocus();
		}
#endif
		break;
	case ID_DO_SEARCH:
	{
#if 0
		bool bFromTop = false;
		pcMsg->FindBool( "from_top", &bFromTop );
		pcMsg->FindBool( "case_sensitive", &m_bSearchCaseSensitive );
		pcMsg->FindString( "string", &m_cLastSearchStr );

		KHTMLView* pcActiveView = dynamic_cast<KHTMLView*>(GetFocusChild());
		
		KHTMLPart* pcPart = m_pcHTMLPart;
		if ( pcActiveView != NULL ) {
		pcPart = pcActiveView->part();
		}
		if ( bFromTop ) {
		pcPart->findTextBegin();
		}
		pcPart->findTextNext( m_cLastSearchStr.c_str(), true, m_bSearchCaseSensitive );
		break;
#endif
	}
	case ID_REPEAT_FIND:
#if 0
		if ( m_cLastSearchStr.empty() == false ) {
		KHTMLView* pcActiveView = dynamic_cast<KHTMLView*>(GetFocusChild());
		
		KHTMLPart* pcPart = m_pcHTMLPart;
		if ( pcActiveView != NULL ) {
			pcPart = pcActiveView->part();
		}		
		pcPart->findTextNext( m_cLastSearchStr.c_str(), true, m_bSearchCaseSensitive );
		} else if ( m_pcSearchDialog == NULL ) {
		m_pcHTMLPart->findTextBegin();
		m_pcSearchDialog = new FindDialog( os::Messenger(this), os::Message(ID_DO_SEARCH), os::Message(ID_SEARCH_CLOSED) );
		m_pcSearchDialog->Show();
		m_pcSearchDialog->MakeFocus();
		}
		break;
	case ID_SEARCH_CLOSED:
		m_pcSearchDialog = NULL;
		break;
#endif
	case ID_GOHOME:
		OpenURL( "http://www.openbeos.org/", KParts::URLArgs() );
#if 0
		UpdateHistory();
		AddHistoryEntry();
		OpenURL( "http://www.atheos.cx/", KParts::URLArgs() );
		UpdateHistory();
#endif
		break;
#if 0
	case ID_PREV_URL:
		GoHistory( -1 );
		break;
	case ID_NEXT_URL:
		GoHistory( 1 );
		break;
#endif
	case ID_START_DOWNLOAD:
	{
#if 0
		DownloadNode* psNode = NULL;
		std::string   cPath;
		pcMsg->FindPointer( "node", (void**) &psNode );
		pcMsg->FindString( "path", &cPath );

		
		if ( psNode == NULL ) {
		break; // Should never happen
		}
		psNode->m_cPath = cPath;
		const std::string cDstDir = os::Path( cPath.c_str() ).GetDir();

		try {
		os::FSNode cDirNode( cDstDir );
		if ( cDirNode.GetDev() == psNode->m_pcTmpFile->GetDev() ) {
			rename( psNode->m_pcTmpFile->GetPath().c_str(), cPath.c_str() );
			psNode->m_pcTmpFile->Detatch(); // Make sure the destructor don't do anything silly.
		} else {
			psNode->m_pcFile = new os::File( cPath, O_WRONLY | O_CREAT );
			psNode->m_pcTmpFile->Seek( 0, SEEK_SET );
			char anBuffer[32*1024];
			for (;;) {
			int nLen = psNode->m_pcTmpFile->Read( anBuffer, sizeof(anBuffer) );
			if ( nLen < 0 ) {
				throw os::errno_exception( "Failed to copy temporary file" );
			}
			if ( psNode->m_pcFile->Write( anBuffer, nLen ) != nLen ) {
				throw os::errno_exception( "Failed to copy temporary file" );
			}
			if ( nLen < int(sizeof(anBuffer)) ) {
				break;
			}
			}
			delete psNode->m_pcTmpFile;
			psNode->m_pcTmpFile = NULL;
		}
		} catch(...) {
		(new os::Alert( "Error: Failed to create file!",
				os::String().Format( "Failed to create '%s'", cPath.c_str() ), 0,
				"Sorry!", NULL ))->Go(NULL);
		}
		
		psNode->m_pcRequester = NULL;

		if ( psNode->m_bDone == false ) {
		Message cCancelMsg( ID_CANCEL_DOWNLOAD );
		cCancelMsg.AddPointer( "node", psNode );
		
		psNode->m_pcProgressDlg = new DownloadProgress( os::Rect( 100, 100, 449, 349 ), os::String().Format( "Download: %s", cPath.c_str() ),
								psNode->m_cURL,
								cPath,
								psNode->m_nContentSize,
								psNode->m_nStartTime,
								os::Messenger( this ),
								cCancelMsg );

		psNode->m_pcProgressDlg->Show();
		} else {
		delete psNode->m_pcTmpFile;
		delete psNode->m_pcFile;
		delete psNode;
		}
#endif
		break;
	}
	case ID_CANCEL_DOWNLOAD:
	{
#if 0
		DownloadNode* psNode = NULL;
		pcMsg->FindPointer( "node", (void**) &psNode );
		
		if ( psNode == NULL ) {
		break; // Should never happen
		}
		if ( psNode->m_pcProgressDlg != NULL ) {
		psNode->m_pcProgressDlg->Terminate();
		psNode->m_pcProgressDlg = NULL;
		}
		if ( psNode->m_cPath.empty() == false ) {
		unlink( psNode->m_cPath.c_str() );
		}
		if ( psNode->m_bDone == false ) {
		psNode->m_pcRequester = NULL;
		psNode->m_bCanceled = true;
		delete psNode->m_pcTmpFile;
		psNode->m_pcTmpFile = NULL;
		delete psNode->m_pcFile;
		psNode->m_pcFile = NULL;
		} else {
		delete psNode->m_pcTmpFile;
		delete psNode->m_pcFile;
		delete psNode;		
		}
#endif
		break;
	}
	default:
		BWindow::MessageReceived( pcMsg );
		break;
	}
}