00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "RioCopy.h"
00019
00020 #include <qlayout.h>
00021 #include <qpushbutton.h>
00022 #include <qmessagebox.h>
00023 #include <qapplication.h>
00024
00025 #include <qprogressdialog.h>
00026
00027 #include "Events.h"
00028
00029
00030 #include <sys/time.h>
00031 #include <time.h>
00032 #include "RioError.h"
00033
00034
00035
00036
00037
00038
00039
00040 RioCopy::RioCopy( RioQt *rioQt,
00041 RioExplorer *rioExplorer,
00042 CRioSession *src_session,
00043 CRioSession *dest_session,
00044 QStringList *source_list,
00045 QString dest_file,
00046 FileWindow *destFileWindow )
00047 #ifdef USE_QT_GRID
00048
00049 : QDialog( rioQt, NULL, true )
00050 #else
00051 : QDialog( rioQt )
00052 #endif
00053 {
00054 setCaption( tr( "Copy in progress..." ) );
00055
00056 #ifndef USE_QT_GRID
00057
00058 setModal( true );
00059 #endif
00060
00061 QVBoxLayout *main_layout = new QVBoxLayout( this, 5 );
00062 QHBoxLayout *current_file_layout = new QHBoxLayout( main_layout, 5 );
00063 QVBoxLayout *middle_layout = new QVBoxLayout( main_layout, 5 );
00064 QGridLayout *button_layout = new QGridLayout( main_layout, 1, 3, 5 );
00065
00066 lbl_copying_file = new QLabel( tr( "Copying file: " ), this );
00067 lbl_current_file = new QLabel( this );
00068 lbl_current_file->setAlignment( Qt::AlignLeft );
00069 lbl_overall = new QLabel( tr( "Overall progress:" ), this );
00070
00071 pb_current_file = new QProgressBar( 100, this );
00072 pb_overall = new QProgressBar( 100, this );
00073
00074 QPushButton *bt_cancel = new QPushButton( this );
00075 bt_cancel->setText( tr( "Cancel" ) );
00076 bt_cancel->setFixedWidth( 100 );
00077
00078 current_file_layout->addWidget( lbl_copying_file );
00079 current_file_layout->addWidget( lbl_current_file );
00080 middle_layout->addWidget( pb_current_file );
00081 middle_layout->addWidget( lbl_overall );
00082 middle_layout->addWidget( pb_overall );
00083 button_layout->addWidget( bt_cancel, 0, 1 );
00084
00085
00086 lbl_current_file->setFixedWidth( 200 );
00087
00088
00089 connect( bt_cancel, SIGNAL( clicked() ), this, SLOT( userCancel() ) );
00090
00091
00092 show();
00093
00094
00095 this->rioQt = rioQt;
00096 this->rioExplorer = rioExplorer;
00097 this->src_session = src_session;
00098 this->dest_session = dest_session;
00099 this->source_list = source_list;
00100 this->dest_file = strdup( dest_file.ascii() );
00101 this->destFileWindow = destFileWindow;
00102 copy_allowed = true;
00103 }
00104
00105
00106
00107
00108
00109 bool RioCopy::doCopy( void )
00110 {
00111 bool copy_status;
00112 #ifdef RIO_DEBUG2
00113 struct timeval start, end;
00114 #endif
00115
00116
00117 total_completed = 0;
00118 total_size = 0;
00119 copy_running = true;
00120 copy_status = true;
00121
00122
00123
00124 for( QStringList::Iterator it = source_list->begin();
00125 it != source_list->end();
00126 ++it )
00127 {
00128 vector<ObjectInfo> src_files;
00129 ObjectInfo fileInfo;
00130
00131 rioExplorer->getObjectInfo( (char *)(*it).ascii(), src_session, &fileInfo );
00132 copy_status = rioExplorer->ls( &fileInfo, &src_files,
00133 src_session, true, true );
00134
00135 for( unsigned int i = 0;
00136 copy_status && ( i < (unsigned int)src_files.size() );
00137 i++ )
00138 {
00139
00140 if( !src_files[i].isDir() )
00141 total_size += src_files[i].getSize();
00142 }
00143 }
00144
00145
00146 vector<ObjectInfo> fileInfo_list;
00147 ObjectInfo *fileInfo;
00148
00149 for( QStringList::Iterator it = source_list->begin();
00150 it != source_list->end();
00151 ++it )
00152 {
00153 fileInfo = new ObjectInfo;
00154 rioExplorer->getObjectInfo( (char *)(*it).ascii(), src_session, fileInfo );
00155
00156 fileInfo_list.push_back( *fileInfo );
00157 }
00158
00159
00160 copy_running = true;
00161 for( unsigned int i = 0 ; copy_allowed && ( i < fileInfo_list.size() ) ; i++ )
00162 {
00163 #ifdef RIO_DEBUG2
00164 gettimeofday( &start, NULL );
00165 #endif
00166 copy_status = rioExplorer->cp( src_session, dest_session,
00167 &fileInfo_list[i],
00168 (char *)dest_file.c_str(),
00169 true, true,
00170 ©_allowed,
00171 ¤t_file,
00172 ¤t_file_completed,
00173 ¤t_file_size,
00174 &total_completed );
00175 #ifdef RIO_DEBUG2
00176 gettimeofday( &end, NULL );
00177 RioErr << "RioCopy::doCopy Tempo para copiar o arquivo "
00178 << fileInfo_list[i].getFullName() << ": "
00179 << ( ( (double) ( end.tv_sec - start.tv_sec ) ) * 1000000.0 +
00180 ( (double) ( end.tv_usec - start.tv_usec ) ) ) / 1000000.0
00181 << " segundos " << endl;
00182 #endif
00183 }
00184
00185 copy_running = false;
00186 close();
00187
00188 return copy_status;
00189 }
00190
00191
00192
00193
00194
00195 void RioCopy::closeEvent( QCloseEvent * )
00196 {
00197
00198
00199 if( !copy_running )
00200 {
00201
00202 destFileWindow->refreshDirectory( destFileWindow->getCurrentDir() );
00203
00204 accept();
00205 }
00206 }
00207
00208
00209
00210
00211
00212 bool RioCopy::userCancel( void )
00213 {
00214 bool status;
00215 ShowMessageEvent *event;
00216
00217 status = true;
00218 event = new ShowMessageEvent( ShowMessageEvent::QUESTION,
00219 tr( "Do you really want to cancel this copy?" ),
00220 tr( "Cancel copy in progress" ) );
00221 QApplication::sendEvent( rioQt, event );
00222
00223 int result = event->getResult();
00224 delete event;
00225
00226 if( result == QMessageBox::Yes )
00227 {
00228 copy_allowed = false;
00229 }
00230 else
00231 {
00232 status = false;
00233 }
00234
00235 return status;
00236 }
00237
00238
00239
00240
00241
00242 QString RioCopy::truncateFileName( string file_name )
00243 {
00244 QString new_file_name = QString( file_name );
00245
00246 if( new_file_name.length() > CURRENT_FILE_MAX_LENGTH )
00247 {
00248 new_file_name = new_file_name.right( CURRENT_FILE_MAX_LENGTH - 3 );
00249 new_file_name = "..." + new_file_name;
00250 }
00251
00252 return new_file_name;
00253 }
00254
00255 void RioCopy::updateProgress( void )
00256 {
00257 int current_file_percent, total_percent;
00258
00259 if( current_file_size > 0 )
00260 current_file_percent = (int)( current_file_completed * 100 /
00261 current_file_size );
00262 else
00263 current_file_percent = 0;
00264
00265 if( total_size > 0 )
00266 total_percent = (int)( total_completed * 100 / total_size );
00267 else
00268 total_percent = 0;
00269
00270 lbl_current_file->setText(truncateFileName( current_file ) );
00271 pb_current_file->setProgress( current_file_percent );
00272 pb_overall->setProgress( total_percent );
00273
00274 qApp->processEvents();
00275 }
00276