📄 ftpmainwindow.cpp.bak
字号:
// finally read the directory on the ftp server remoteOperator.listChildren();}void FtpMainWindow::slotUpload(){ // the user pressed the upload button // if files have been selected on the left side (local filesystem) QValueList<QUrlInfo> files = leftView->selectedItems(); if ( files.isEmpty() ) return; // create a list of the URLs which should be copied QStringList lst; QValueList<QUrlInfo>::Iterator it = files.begin(); for ( ; it != files.end(); ++it ) lst << QUrl( localOperator, ( *it ).name() ); // copy the list of selected files to the directory in which the // remoteOperator currently is (upload) remoteOperator.copy( lst, remoteOperator, FALSE );}void FtpMainWindow::slotDownload(){ // if the user pressed the download button // if files have been selected on the right side (remote filesystem) QValueList<QUrlInfo> files = rightView->selectedItems(); if ( files.isEmpty() ) return; // create a list of the URLs which should be downloaded QStringList lst; QValueList<QUrlInfo>::Iterator it = files.begin(); for ( ; it != files.end(); ++it ) lst << QUrl( remoteOperator, ( *it ).name() ); // copy the list of selected files to the directory in which the // localOperator currently is (download) localOperator.copy( lst, localOperator, FALSE );}void FtpMainWindow::slotLocalStart( QNetworkOperation *op ){ // this slot is always called if the local QUrlOperator starts // listing a directory or dowloading a file if ( !op ) return; if ( op->operation() == QNetworkProtocol::OpListChildren ) { // start listing a dir? clear the left view! leftView->clear(); } else if ( op->operation() == QNetworkProtocol::OpGet ) { // start downloading a file? reset the progress bar! progressBar1->setTotalSteps( 0 ); progressBar1->reset(); }}void FtpMainWindow::slotLocalFinished( QNetworkOperation *op ){ // this slot is always called if the local QUrlOperator finished // an operation if ( !op ) return; if ( op && op->state() == QNetworkProtocol::StFailed ) { // an error happend, let the user know that QMessageBox::critical( this, tr( "ERROR" ), op->protocolDetail() ); // do something depending in the error code int ecode = op->errorCode(); if ( ecode == QNetworkProtocol::ErrListChlidren || ecode == QNetworkProtocol::ErrParse || ecode == QNetworkProtocol::ErrUnknownProtocol || ecode == QNetworkProtocol::ErrLoginIncorrect || ecode == QNetworkProtocol::ErrValid || ecode == QNetworkProtocol::ErrHostNotFound || ecode == QNetworkProtocol::ErrFileNotExisting ) { localOperator = oldLocal; localCombo->setEditText( localOperator.path() ); localOperator.listChildren(); } } else if ( op->operation() == QNetworkProtocol::OpPut ) { // finished saving the downloaded file? reread the dir and hide the progress bar localOperator.listChildren(); progressLabel1->hide(); progressBar1->hide(); } else if ( op->operation() == QNetworkProtocol::OpGet ) { // finished reading a file from the ftp server? reset the progress bar progressBar1->setTotalSteps( 0 ); progressBar1->reset(); }}void FtpMainWindow::slotRemoteStart( QNetworkOperation *op ){ // this slot is always called if the remote QUrlOperator starts // listing a directory or uploading a file if ( !op ) return; if ( op->operation() == QNetworkProtocol::OpListChildren ) { // start listing a dir? clear the right view! rightView->clear(); } else if ( op->operation() == QNetworkProtocol::OpGet ) { // start downloading a file? reset the progress bar! progressBar2->setTotalSteps( 0 ); progressBar2->reset(); }}void FtpMainWindow::slotRemoteFinished( QNetworkOperation *op ){ // this slot is always called if the remote QUrlOperator finished // an operation if ( !op ) return; if ( op && op->state() == QNetworkProtocol::StFailed ) { // an error happend, let the user know that QMessageBox::critical( this, tr( "ERROR" ), op->protocolDetail() ); // do something depending in the error code int ecode = op->errorCode(); if ( ecode == QNetworkProtocol::ErrListChlidren || ecode == QNetworkProtocol::ErrParse || ecode == QNetworkProtocol::ErrUnknownProtocol || ecode == QNetworkProtocol::ErrLoginIncorrect || ecode == QNetworkProtocol::ErrValid || ecode == QNetworkProtocol::ErrHostNotFound || ecode == QNetworkProtocol::ErrFileNotExisting ) { remoteOperator = oldRemote; remoteHostCombo->setEditText( remoteOperator.host() ); remotePathCombo->setEditText( remoteOperator.path() ); passLined->setText( remoteOperator.password() ); userCombo->setEditText( remoteOperator.user() ); portSpin->setValue( remoteOperator.port() ); remoteOperator.listChildren(); } } else if ( op->operation() == QNetworkProtocol::OpListChildren ) { // finished reading a dir? set the correct path to the pth combo of the right view remotePathCombo->setEditText( remoteOperator.path() ); } else if ( op->operation() == QNetworkProtocol::OpPut ) { // finished saving the uploaded file? reread the dir and hide the progress bar remoteOperator.listChildren(); progressLabel2->hide(); progressBar2->hide(); } else if ( op->operation() == QNetworkProtocol::OpGet ) { // finished reading a file from the local filesystem? reset the progress bar progressBar2->setTotalSteps( 0 ); progressBar2->reset(); }}void FtpMainWindow::slotLocalDataTransferProgress( int bytesDone, int bytesTotal, QNetworkOperation *op ){ // Show the progress here of the local QUrlOperator reads or writes data if ( !op ) return; if ( !progressBar1->isVisible() ) { if ( bytesDone < bytesTotal) { progressLabel1->show(); progressBar1->show(); progressBar1->setTotalSteps( bytesTotal ); progressBar1->setProgress( 0 ); progressBar1->reset(); } else return; } if ( progressBar1->totalSteps() == bytesTotal ) progressBar1->setTotalSteps( bytesTotal ); if ( op->operation() == QNetworkProtocol::OpGet ) progressLabel1->setText( tr( "Read: %1" ).arg( op->arg( 0 ) ) ); else if ( op->operation() == QNetworkProtocol::OpPut ) progressLabel1->setText( tr( "Write: %1" ).arg( op->arg( 0 ) ) ); else return; progressBar1->setProgress( bytesDone );}void FtpMainWindow::slotRemoteDataTransferProgress( int bytesDone, int bytesTotal, QNetworkOperation *op ){ // Show the progress here of the remote QUrlOperator reads or writes data if ( !op ) return; if ( !progressBar2->isVisible() ) { if ( bytesDone < bytesTotal) { progressLabel2->show(); progressBar2->show(); progressBar2->setTotalSteps( bytesTotal ); progressBar2->setProgress( 0 ); progressBar2->reset(); } else return; } if ( progressBar2->totalSteps() != bytesTotal ) progressBar2->setTotalSteps( bytesTotal ); if ( op->operation() == QNetworkProtocol::OpGet ) progressLabel2->setText( tr( "Read: %1" ).arg( op->arg( 0 ) ) ); else if ( op->operation() == QNetworkProtocol::OpPut ) progressLabel2->setText( tr( "Write: %1" ).arg( op->arg( 0 ) ) ); else return; progressBar2->setProgress( bytesDone );}void FtpMainWindow::slotLocalMkdir(){ // create a dir on the local filesystem bool ok = FALSE; QString name = QInputDialog::getText( tr( "Directory Name:" ), tr( "OKOK" ),QLineEdit::Normal, QString::null, 0, this ,0); if ( !name.isEmpty() && ok ) localOperator.mkdir( name );}void FtpMainWindow::slotLocalRemove(){ bool removeRequested = FALSE; QValueList<QUrlInfo> selected = leftView->selectedItems(); for ( QValueList<QUrlInfo>::Iterator it = selected.begin(); it != selected.end(); ++it ) if ( (*it).isFile() ) { localOperator.remove( (*it).name() ); removeRequested = TRUE; } if ( removeRequested ) localOperator.listChildren();}void FtpMainWindow::slotRemoteMkdir(){ // create a dir on the remote filesystem (FTP server) bool ok = FALSE; QString name = QInputDialog::getText( tr( "Directory Name:" ), QString::null, QString::null, &ok, this ); if ( !name.isEmpty() && ok ) remoteOperator.mkdir( name );}void FtpMainWindow::slotRemoteRemove(){ bool removeRequested = FALSE; QValueList<QUrlInfo> remoteSelected = rightView->selectedItems(); for ( QValueList<QUrlInfo>::Iterator it = remoteSelected.begin(); it != remoteSelected.end(); ++it ) if ( (*it).isFile() ) { remoteOperator.remove( (*it).name() ); removeRequested = TRUE; } if ( removeRequested ) remoteOperator.listChildren();}void FtpMainWindow::slotConnectionStateChanged( int, const QString &msg ){ statusBar()->message( msg );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -