ATTunnelConnector_c::ATTunnelConnector_c( ATSkeletonWindow *pParent, Tunnel_c *pTunnel ) : QObject(), m_pParent( pParent ), m_pTunnel( pTunnel ) { ATASSERT( m_pParent ); ATASSERT( m_pTunnel ); }
bool ATMainWindow_c::InitMenusAndActions() { QAction *pAction; QMenu *pFileMenu = new QMenu(this); pAction = new QAction(QObject::tr("&Quit"), this); pAction->setShortcut(QObject::tr("CTRL+Q")); bool bRet = QObject::connect(pAction, SIGNAL(triggered()), this, SLOT(slotTentativeQuit())); ATASSERT( bRet ); pFileMenu->addAction( pAction ); QMenu *pStyleMenu = new QMenu(this); QStringList styleList = QStyleFactory::keys(); for( int i=0; i<styleList.count(); i++ ) { ATNamedAction *pNamedAction = new ATNamedAction( styleList.at(i), this ); ATASSERT( connect( pNamedAction, SIGNAL( signalTriggerNamed(QString) ), this, SLOT(slotChangeStyle(QString))) ); pStyleMenu->addAction(pNamedAction); } QMenu *pHelpMenu = new QMenu(this); pAction = new QAction(QObject::tr("&About..."), this); // pAction->setShortcut(QObject::tr("F1")); ATASSERT( QObject::connect(pAction, SIGNAL(triggered()), this, SLOT(slotShowAbout())) ); pHelpMenu->addAction(pAction); menuBar()->addMenu(pFileMenu)->setText(QObject::tr("File")); menuBar()->addMenu(pStyleMenu)->setText(QObject::tr("Style")); menuBar()->addMenu(pHelpMenu)->setText(QObject::tr("Help")); return true; }
void ATSkeletonWindow::slotDuplicateTunnel() { QTreeWidgetItem *twi = ui.treeTunnels->currentItem(); ATASSERT( twi ); if ( twi == NULL ) return; Tunnel_c *pt = getTunnelFromTreeItem( twi ); ATASSERT( pt ); if ( pt == NULL ) return; Tunnel_c tunnel; tunnel.copyFrom( pt ); twi = new QTreeWidgetItem( ui.treeTunnels ); twi->setText( 0, tunnel.strName ); twi->setIcon( 0, QPixmap( ":disconnected.png" ) ); tunnel.twi = twi; m_listTunnels.push_back( tunnel ); ui.treeTunnels->setCurrentItem( twi ); ui.tabWidget->setCurrentIndex( PAGE_EDIT ); ui.editTunnelName->setFocus(); qApp->processEvents(); ui.editTunnelName->selectAll(); }
void ATSkeletonWindow::slotDeleteTunnel() { QTreeWidgetItem *twi = ui.treeTunnels->currentItem(); ATASSERT( twi ); if ( twi == NULL ) return; Tunnel_c *pt = getTunnelFromTreeItem( twi ); ATASSERT( pt ); if ( pt == NULL ) return; QString strQuestion = QString( "Do you want to delete the tunnel \"%1\"?" ).arg( twi->text( 0 ) ); QMessageBox::StandardButton iRet = QMessageBox::question( this, APP_NICE_NAME, strQuestion, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes ); if ( iRet == QMessageBox::Yes ) { m_bDisableChanges = true; delete twi; disconnectTunnel( *pt ); for ( TunnelInterator it = m_listTunnels.begin(); it != m_listTunnels.end(); ++it ) { if ( it->twi == twi ) { m_listTunnels.erase( it ); break; } } } }
void ATSkeletonWindow::slotConnect() { QTreeWidgetItem *twi = ui.treeTunnels->currentItem(); ATASSERT( twi ); if ( twi == NULL ) return; Tunnel_c *pt = getTunnelFromTreeItem( twi ); ATASSERT( twi ); connectTunnel( *pt ); }
void ATTunnelConnector_c::slotProcessFinished(int exitCode, QProcess::ExitStatus /*exitStatus*/) { ATASSERT( m_pParent ); ATASSERT( m_pTunnel ); Tunnel_c *pt = m_pTunnel; ATASSERT( pt ); m_pParent->AddToLog( *pt, "Process exit: %d", exitCode ); emit finished( pt ); }
void ATTunnelConnector_c::slotProcessError(QProcess::ProcessError error) { ATASSERT( m_pParent ); ATASSERT( m_pTunnel ); Tunnel_c *pt = m_pTunnel; ATASSERT( pt ); m_pParent->AddToLog( *pt, "Process error: %d", error ); emit finished( pt ); }
/** * operator[] * [0]: x-coodinate, [1]: y-coodinate * * @param index * @return value */ float ATVector2::operator[](int index) { ATASSERT(index >= 0 && index <= 1); if (index == 0) { return x; } else { return y; } }
/** * operator[] * [0]: x-coodinate, [1]: y-coodinate, [2]: z-coodinate, [3]: w-coodinate * * @param index * @return value */ float ATVector4::operator[](int index) { ATASSERT(index >= 0 && index <= 3); if (index == 0) { return x; } else if (index == 1){ return y; } else if (index == 2){ return z; } else { return w; } }
void ATTunnelConnector_c::slotProcessReadStandardError() { ATASSERT( m_pParent ); ATASSERT( m_pTunnel ); Tunnel_c *pt = m_pTunnel; ATASSERT( pt ); QByteArray b = pt->pProcess->readAllStandardError(); char *ptrb = b.data(); char *context; context = NULL; char *ptr = strtok_s( ptrb, "\r\n", &context ); while ( ptr ) { m_pParent->AddToLog( *pt, "2> %s", ptr ); processPlinkOutput( ptr ); ptr = strtok_s( NULL, "\r\n", &context ); } }
ATSkeletonWindow::~ATSkeletonWindow() { writeSettings(); // Make sure we won't try to reconnect ATVERIFY( disconnect( this, SIGNAL( signalAutoConnect(Tunnel_c*) ), 0, 0 ) ); for ( TunnelInterator it = m_listTunnels.begin(); it != m_listTunnels.end(); ++it ) { disconnectTunnel( *it ); ATASSERT( it->pProcess == NULL ); } }
void ATSkeletonWindow::slotItemActivated() { QTreeWidgetItem *twi = ui.treeTunnels->currentItem(); if ( twi == NULL ) return; ui.tabWidget->setCurrentIndex( PAGE_CONNECT ); const Tunnel_c *pt = getTunnelFromTreeItem( twi ); ATASSERT( pt ); if (pt->pProcess) slotDisconnect(); else slotConnect(); }
Tunnel_c::~Tunnel_c() { // The process should be terminated before a tunnel is destroyed ATASSERT( pProcess == NULL ); ATASSERT( pConnector == NULL ); }
void ATSkeletonWindow::connectTunnel( Tunnel_c &tunnel ) { Tunnel_c *pt = &tunnel; AddToLog( tunnel, "Connecting tunnel %s...", qPrintable( pt->strName ) ); AddToLog( tunnel, "Host: %s - Tunnel: %d:%s:%d", qPrintable( pt->strSSHHost ), pt->iLocalPort, qPrintable( pt->strRemoteHost ), pt->iRemotePort ); if ( pt->strSSHHost.isEmpty() ) { AddToLog( tunnel, "Error: Tunnel %s has no host, please check the settings.", qPrintable( pt->strName ) ); return; } #ifdef WIN32 QString strPlink = "plink.exe"; // Check that the executable is found { QDir dir( argv0 ); dir.cdUp(); if ( !dir.exists( strPlink ) ) { const char *ptr = argv0, *ptr2 = argv0; while ( *ptr2 ) { if ( *ptr2 == '\\' ) ptr = ptr2+1; ptr2++; } AddToLog( tunnel, "Error: Could not find %s, please check that it is in the same directory as %s.", qPrintable( strPlink ), ptr ); return; } } #else QString strPlink = "ssh"; #endif if ( pt->pProcess != NULL ) return; // already connected? if ( tunnel.twi ) tunnel.twi->setIcon( 0, QPixmap( ":connecting.png" ) ); //QTreeWidgetItem *twi = getTreeItemFromTunnelIndex( iTunnelIndex ); //if ( twi ) twi->setIcon( 0, QPixmap( ":connecting.png" ) ); ATASSERT( pt->pConnector == NULL ); pt->pConnector = new ATTunnelConnector_c( this, &tunnel ); pt->pProcess = new QProcess; pt->pProcess->setProcessChannelMode( QProcess::MergedChannels ); QString strCommand; strCommand += strPlink + " "; strCommand += "-v "; #ifdef _WIN32 QStringList strListSSHHost = pt->strSSHHost.split( ':', QString::SkipEmptyParts ); if ( strListSSHHost.count() == 1 ) strListSSHHost << "22"; strCommand += strListSSHHost.at(0) + " -P " + strListSSHHost.at(1) + " "; #else strCommand += pt->strSSHHost + " "; #endif if ( !pt->strUsername.isEmpty() ) strCommand += QString( "-l %1 " ).arg( pt->strUsername ); if ( pt->bCompression ) strCommand += "-C "; strCommand += ( pt->iSSH1or2 == 1 ) ? "-1 " : "-2 "; if ( pt->iDirection == 0 ) // Local -> Remote { IF_NWIN32( strCommand += "-g " ); strCommand += QString( "-L %1:%2:%3 " ).arg( pt->iLocalPort ).arg( pt->strRemoteHost).arg( pt->iRemotePort ); } else // Remote -> Local { strCommand += QString( "-R %1:%2:%3 " ).arg( pt->iLocalPort ).arg( pt->strRemoteHost).arg( pt->iRemotePort ); } if ( !pt->strSSHKeyFile.isEmpty() ) strCommand += QString( "-i %1 " ).arg( pt->strSSHKeyFile ); strCommand += pt->strExtraArguments; ATVERIFY( connect( pt->pProcess, SIGNAL( readyReadStandardOutput() ), pt->pConnector, SLOT( slotProcessReadStandardOutput() ) ) ); ATVERIFY( connect( pt->pProcess, SIGNAL( readyReadStandardError() ), pt->pConnector, SLOT( slotProcessReadStandardError() ) ) ); ATVERIFY( connect( pt->pProcess, SIGNAL( error(QProcess::ProcessError) ), pt->pConnector, SLOT( slotProcessError(QProcess::ProcessError) ) ) ); ATVERIFY( connect( pt->pProcess, SIGNAL( finished(int, QProcess::ExitStatus) ), pt->pConnector, SLOT( slotProcessFinished(int, QProcess::ExitStatus) ) ) ); ATVERIFY( connect( pt->pConnector, SIGNAL( finished(Tunnel_c*) ), this, SLOT( slotConnectorFinished(Tunnel_c*) ), Qt::QueuedConnection ) ); AddToLog( tunnel, "%s", qPrintable( strCommand ) ); pt->pProcess->start( strCommand ); }