#include "mainwnd.h" #include "clientwidget.h" #include "proxywidget.h" #include "filewidget.h" #include "connectdlg.h" #include "setupproxydlg.h" #include #include MainWnd::MainWnd() { setupUi( this ); pMode = new QLabel( "Idle", this ); statusBar()->addPermanentWidget( pMode ); } MainWnd::~MainWnd() { } void MainWnd::connect() { ConnectDlg dlg( this ); if( dlg.exec() == QDialog::Accepted ) { sCurFile.clear(); setCentralWidget( new ClientWidget( this, dlg.getHostname(), dlg.getPort() ) ); pMode->setText( QString("Client Mode: %1:%2").arg( QString(dlg.getHostname()) ). arg( dlg.getPort() ) ); } } void MainWnd::proxy() { SetupProxyDlg dlg( this ); if( dlg.exec() == QDialog::Accepted ) { sCurFile.clear(); setCentralWidget( new ProxyWidget( this, dlg.getPortIn(), dlg.getHostOut(), dlg.getPortOut() ) ); pMode->setText( QString("Proxy Mode: :%1 -> %2:%3").arg( dlg.getPortIn() ). arg( QString(dlg.getHostOut()) ). arg( dlg.getPortOut() ) ); } } void MainWnd::open() { QString sFile = QFileDialog::getOpenFileName( this, "Gats Console - open gats file" ); if( sFile.isEmpty() ) return; sCurFile = sFile; setCentralWidget( new FileWidget( this, sFile ) ); pMode->setText( QString("File mode: %1").arg( sCurFile ) ); } void MainWnd::newFile() { sCurFile.clear(); setCentralWidget( new FileWidget( this ) ); pMode->setText( QString("File mode: ") ); } void MainWnd::save() { if( sCurFile.isEmpty() ) { saveAs(); } else { IoBase *pIo = dynamic_cast(centralWidget()); if( !pIo ) return; pIo->saveTo( sCurFile ); } } void MainWnd::saveAs() { IoBase *pIo = dynamic_cast(centralWidget()); if( !pIo ) return; QString sFile = QFileDialog::getSaveFileName( this, "Gats Console - save gats file" ); if( sFile.isEmpty() ) return; pIo->saveTo( sFile ); sCurFile = sFile; }