RioCopy Class Reference

#include <RioCopy.h>

Public Member Functions

 RioCopy (RioQt *, RioExplorer *, CRioSession *, CRioSession *, QStringList *, QString, FileWindow *)
 If the you use this constructor this class will show a progress dialog and the destination fileWindow will be refreshed after termination.
bool doCopy (void)
 Call RioExplorer::cp function Returns true if the copy was performed with success, and false otherwise.
void updateProgress (void)

Private Slots

virtual bool userCancel (void)
 Ask user to confirm if really want to cancel the current copy If he confirms, cancel the thread execution.

Private Member Functions

QString truncateFileName (string)
 This function truncates the current file name if it is greater than CURRENT_FILE_MAX_LENGTH.
void closeEvent (QCloseEvent *)
 Reimplements the closeEvent.

Private Attributes

QLabel * lbl_copying_file
QLabel * lbl_current_file
QLabel * lbl_overall
QProgressBar * pb_current_file
QProgressBar * pb_overall
RioQtrioQt
RioExplorerrioExplorer
CRioSessionsrc_session
CRioSessiondest_session
QStringList * source_list
string dest_file
bool copy_running
bool copy_allowed
FileWindowdestFileWindow
pthread_t thread
string current_file
RioObjectSize current_file_completed
RioObjectSize current_file_size
RioObjectSize total_completed
RioObjectSize total_size

Static Private Attributes

static const unsigned int CURRENT_FILE_MAX_LENGTH = 25

Detailed Description

Definition at line 34 of file RioCopy.h.


Constructor & Destructor Documentation

RioCopy::RioCopy ( RioQt rioQt,
RioExplorer rioExplorer,
CRioSession src_session,
CRioSession dest_session,
QStringList *  source_list,
QString  dest_file,
FileWindow destFileWindow 
)

If the you use this constructor this class will show a progress dialog and the destination fileWindow will be refreshed after termination.

This option can be used when a user drag an object for copy

Definition at line 40 of file RioCopy.cpp.

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     // Necess�rio para compilar na Qt 3.1 (usada na GRID).
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     // This dialog cannot be resized
00086     lbl_current_file->setFixedWidth( 200 );
00087 
00088     // Signal and slots
00089     connect( bt_cancel, SIGNAL( clicked() ), this, SLOT( userCancel() ) );
00090 
00091     // Show window
00092     show();
00093 
00094     // Set attributes
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 }


Member Function Documentation

void RioCopy::closeEvent ( QCloseEvent *   )  [private]

Reimplements the closeEvent.

Definition at line 195 of file RioCopy.cpp.

00196 {
00197     // Copy is terminated or
00198     // User agrees to cancel the running copy
00199     if( !copy_running )
00200     {
00201         // Refresh the destination fileWindow, to show its new contents
00202         destFileWindow->refreshDirectory( destFileWindow->getCurrentDir() );
00203 
00204         accept();
00205     }
00206 }

bool RioCopy::doCopy ( void   ) 

Call RioExplorer::cp function Returns true if the copy was performed with success, and false otherwise.

Definition at line 109 of file RioCopy.cpp.

00110 {
00111     bool copy_status;
00112     #ifdef RIO_DEBUG2
00113     struct timeval start, end;
00114     #endif
00115 
00116     // Initialize variables
00117     total_completed = 0;
00118     total_size      = 0;
00119     copy_running    = true;
00120     copy_status     = true;
00121 
00122     // Calculates the total amount of bytes
00123     // For each source file
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             // Do not include directories into the sums
00140             if( !src_files[i].isDir() )
00141                 total_size += src_files[i].getSize();
00142         }
00143     }
00144 
00145     // Copy each source file, in sequence
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     // Call cp function
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                                        &copy_allowed,
00171                                        &current_file,
00172                                        &current_file_completed,
00173                                        &current_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 }

QString RioCopy::truncateFileName ( string  file_name  )  [private]

This function truncates the current file name if it is greater than CURRENT_FILE_MAX_LENGTH.

Definition at line 242 of file RioCopy.cpp.

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 }

void RioCopy::updateProgress ( void   ) 

Definition at line 255 of file RioCopy.cpp.

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 }

bool RioCopy::userCancel ( void   )  [private, virtual, slot]

Ask user to confirm if really want to cancel the current copy If he confirms, cancel the thread execution.

Definition at line 212 of file RioCopy.cpp.

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 }


Field Documentation

bool RioCopy::copy_allowed [private]

Definition at line 53 of file RioCopy.h.

bool RioCopy::copy_running [private]

Definition at line 52 of file RioCopy.h.

string RioCopy::current_file [private]

Definition at line 58 of file RioCopy.h.

Definition at line 59 of file RioCopy.h.

const unsigned int RioCopy::CURRENT_FILE_MAX_LENGTH = 25 [static, private]

Definition at line 67 of file RioCopy.h.

Definition at line 60 of file RioCopy.h.

string RioCopy::dest_file [private]

Definition at line 50 of file RioCopy.h.

Definition at line 48 of file RioCopy.h.

Definition at line 54 of file RioCopy.h.

QLabel* RioCopy::lbl_copying_file [private]

Definition at line 39 of file RioCopy.h.

QLabel* RioCopy::lbl_current_file [private]

Definition at line 40 of file RioCopy.h.

QLabel* RioCopy::lbl_overall [private]

Definition at line 41 of file RioCopy.h.

QProgressBar* RioCopy::pb_current_file [private]

Definition at line 42 of file RioCopy.h.

QProgressBar* RioCopy::pb_overall [private]

Definition at line 43 of file RioCopy.h.

Definition at line 46 of file RioCopy.h.

RioQt* RioCopy::rioQt [private]

Definition at line 45 of file RioCopy.h.

QStringList* RioCopy::source_list [private]

Definition at line 49 of file RioCopy.h.

Definition at line 47 of file RioCopy.h.

pthread_t RioCopy::thread [private]

Definition at line 56 of file RioCopy.h.

Definition at line 61 of file RioCopy.h.

Definition at line 62 of file RioCopy.h.


The documentation for this class was generated from the following files:
Generated on Wed Jul 4 16:03:35 2012 for RIO by  doxygen 1.6.3