00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "FileWindow.h"
00019
00020 #include <qfile.h>
00021 #include <qdir.h>
00022 #include <qapplication.h>
00023 #include <qsplitter.h>
00024 #include <qinputdialog.h>
00025 #include <qmessagebox.h>
00026 #include <qtoolbutton.h>
00027 #include <qtoolbar.h>
00028 #include <qstatusbar.h>
00029 #include <qcursor.h>
00030 #include <errno.h>
00031
00032 #include <vector>
00033
00034 #include "DragDropListView.h"
00035 #include "Events.h"
00036 #include "DfRioWindow.h"
00037 #include "RioXmlInput.h"
00038 #include "RioError.h"
00039 #include "CommonLibraries.h"
00040
00041 #include "images/up.xpm"
00042 #include "images/gohome.xpm"
00043 #include "images/folder_new.xpm"
00044 #include "images/refresh.xpm"
00045 #include "images/remove.xpm"
00046 #include "images/key_enter.xpm"
00047 #include "images/locationbar_erase.xpm"
00048
00049 FileWindow::FileWindow( QWidget *parent, RioQt *rioQt, int type )
00050 : QMainWindow( parent, 0, 0 )
00051 {
00052 string message;
00053
00054 setCentralWidget( new QSplitter( Qt::Horizontal, this ) );
00055
00056 this->rioQt = rioQt;
00057 this->type = type;
00058
00059
00060
00061
00062
00063
00064 UseVideoRate = false;
00065
00066
00067
00068
00069 dirTree = new DragDropListView( centralWidget(), rioQt, this );
00070 dirTree->addColumn( tr( "Directory Name" ) );
00071 dirTree->setRootIsDecorated( true );
00072 dirTree->setSelectionMode( QListView::Single );
00073
00074 fileList = new DragDropListView( centralWidget(), rioQt, this );
00075 fileList->addColumn( tr( "File Name" ) );
00076 fileList->addColumn( tr( "Size" ) );
00077 fileList->addColumn( tr( "Date" ) );
00078 fileList->addColumn( tr( "Owner" ) );
00079 fileList->addColumn( tr( "Group" ) );
00080 fileList->addColumn( tr( "Permission" ) );
00081 fileList->setSelectionMode( QListView::Extended );
00082 fileList->setColumnAlignment( FileItem::COLUMN_SIZE, Qt::AlignRight );
00083 fileList->setShowSortIndicator( true );
00084
00085
00086 QToolBar * toolbarButtons = new QToolBar( this );
00087 tbUpDir = new QToolButton( QIconSet( (const char **) image_up ),
00088 "Up Directory (Ctrl+U)", QString::null, this,
00089 SLOT(upDir()), toolbarButtons, "up" );
00090 tbUpDir->setAccel( CTRL+Key_U );
00091
00092 tbHomeDir = new QToolButton( QIconSet( QPixmap( (const char **) image_gohome ) ),
00093 "Home (Ctrl+Home)", QString::null, this,
00094 SLOT(goHomeDir()), toolbarButtons, "home" );
00095 tbHomeDir->setAccel( CTRL+Key_Home );
00096
00097 toolbarButtons->addSeparator();
00098
00099 tbRefresh = new QToolButton( QIconSet( QPixmap( (const char **) image_refresh ) ),
00100 "Refresh (F5)", QString::null, this,
00101 SLOT(toolbarRefresh()),
00102 toolbarButtons, "refresh" );
00103 tbRefresh->setAccel( Key_F5 );
00104
00105 tbEraseFile = new QToolButton( QIconSet( QPixmap( (const char **) image_remove ) ),
00106 "Remove (Del)", QString::null, this,
00107 SLOT(toolbarEraseFile()),
00108 toolbarButtons, "erase" );
00109 tbEraseFile->setAccel( Key_Delete );
00110
00111 tbCreateDir = new QToolButton( QIconSet( QPixmap( (const char **) image_folder_new ) ),
00112 "Create Directory (Ctrl+N)", QString::null, this,
00113 SLOT(toolbarCreateDir()),
00114 toolbarButtons, "create" );
00115 tbCreateDir->setAccel( CTRL+Key_N );
00116
00117 QToolBar * toolbarLocation = new QToolBar( this );
00118 QLabel * labelLocation = new QLabel( toolbarLocation );
00119 labelLocation->setText( "Location:" );
00120 tbEraseLocation = new QToolButton( QIconSet( QPixmap( (const char **) image_locationbar_erase ) ),
00121 "Clear location bar (Ctrl+L)",
00122 QString::null, this,
00123 SLOT(clearLocation()),
00124 toolbarLocation, "clear location bar" );
00125 tbEraseLocation->setAccel( CTRL+Key_L );
00126
00127 comboLocation = new QComboBox( toolbarLocation );
00128 comboLocation->setMinimumWidth( 500 );
00129 comboLocation->setEditable( true );
00130 comboLocation->setAutoCompletion( true );
00131 comboLocation->setDuplicatesEnabled( false );
00132 tbGoLocation = new QToolButton( QIconSet( QPixmap( (const char **) image_key_enter ) ),
00133 "Go", QString::null, this,
00134 SLOT(goLocation()),
00135 toolbarLocation, "go" );
00136
00137
00138 connect( dirTree, SIGNAL( rightButtonPressed( QListViewItem *,
00139 const QPoint &, int ) ),
00140 this, SLOT( runPopupDirTree( QListViewItem *,
00141 const QPoint &, int ) ) );
00142 connect( dirTree, SIGNAL( selectionChanged( QListViewItem * ) ),
00143 this, SLOT( showDirContents( QListViewItem * ) ) );
00144 connect( dirTree, SIGNAL( doubleClicked( QListViewItem * ) ),
00145 this, SLOT( openDirectory( QListViewItem * ) ) );
00146 connect( dirTree, SIGNAL( returnPressed( QListViewItem * ) ),
00147 this, SLOT( openDirectory( QListViewItem * ) ) );
00148
00149
00150 connect( fileList, SIGNAL( rightButtonPressed( QListViewItem *,
00151 const QPoint &, int ) ),
00152 this, SLOT( runPopupFileList( QListViewItem *,
00153 const QPoint &, int ) ) );
00154 connect( fileList, SIGNAL( doubleClicked( QListViewItem * ) ),
00155 this, SLOT( openFile( QListViewItem * ) ) );
00156 connect( fileList, SIGNAL( returnPressed( QListViewItem * ) ),
00157 this, SLOT( openFile( QListViewItem * ) ) );
00158
00159
00160 connect( comboLocation, SIGNAL( activated ( int ) ),
00161 this, SLOT( goLocation( int ) ) );
00162
00163
00164 currentDir = NULL;
00165 session = NULL;
00166
00167 pendingCopiesList.setAutoDelete( true );
00168
00169 if( type == LOCAL )
00170 {
00171 if( !getBlockSize( &blockSize, NULL ) )
00172 {
00173 message = "Could not get local system block size.\n";
00174 showMessage( ERROR_MSG, message );
00175 }
00176
00177 homeDir = QDir::homeDirPath();
00178 setCaption( tr( "Local host" ) );
00179 type = LOCAL;
00180
00181 locationList.append( homeDir );
00182 goHomeDir();
00183 }
00184 md5Box = new QMessageBox( "MD5Sum", "", QMessageBox::Information, QMessageBox::NoButton,
00185 QMessageBox::NoButton, QMessageBox::NoButton, this, "", false );
00186 md5Box->hide();
00187 }
00188
00189
00190
00191
00192
00193
00194 void FileWindow::closeEvent( QCloseEvent * closeEvent )
00195 {
00196 if( rioQt->hasPendingEditor( this ) )
00197 {
00198 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::WARNING,
00199 tr( "There are files being edited in this window.\nFinalize these editors before closing it." ) );
00200 QApplication::postEvent( rioQt, event );
00201 }
00202 else if( hasPendingCopies() )
00203 {
00204 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::WARNING,
00205 tr( "There are copies that involves this window being performed.\nWait for these copies to finish or cancel them before closing this window." ) );
00206 QApplication::postEvent( rioQt, event );
00207 }
00208 else
00209 {
00210 WindowClosedEvent * event;
00211
00212 event = new WindowClosedEvent( this );
00213 QApplication::postEvent( rioQt, event );
00214
00215 closeEvent->accept();
00216 }
00217 }
00218
00219
00220
00221
00222 void FileWindow::showDirContents( QListViewItem * item )
00223 {
00224
00225 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
00226
00227 if( checkConnection() )
00228 {
00229 FileItem * fileItem = (FileItem *)item;
00230
00231 currentDir = fileItem;
00232 fileList->clear();
00233 if( fileItem->canRead() )
00234 {
00235 getDirContents( fileItem->getPath() );
00236 }
00237
00238 comboLocation->setCurrentText( fileItem->getPath() );
00239 }
00240
00241
00242 QApplication::restoreOverrideCursor();
00243 }
00244
00245
00246
00247
00248 FileItem * FileWindow::getItemDirTree( QString path )
00249 {
00250 if( currentDir->childCount() == 0 )
00251 {
00252 readDirectory( currentDir );
00253 currentDir->setOpen( true );
00254 }
00255
00256 FileItem * child = FileWindow::findDirectoryInto( currentDir,
00257 path );
00258 return child;
00259 }
00260
00261
00262
00263
00264 void FileWindow::exploreDirectory( FileItem *fileItem )
00265 {
00266 if( fileItem->canRead() )
00267 {
00268 currentDir = getItemDirTree( fileItem->getPath() );
00269
00270 dirTree->setSelected( currentDir, true );
00271 dirTree->ensureItemVisible( currentDir );
00272 }
00273 else
00274 {
00275 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::WARNING,
00276 tr( "Permission denied." ) );
00277 QApplication::postEvent( rioQt, event );
00278 }
00279 }
00280
00281
00282
00283
00284 void FileWindow::openDirectory( QListViewItem * item )
00285 {
00286 if( checkConnection() )
00287 {
00288 FileItem * fileItem = (FileItem *)item;
00289
00290 currentDir = fileItem;
00291 if( fileItem->canRead() )
00292 {
00293 refreshDirectory( fileItem );
00294
00295 if( !fileItem->isOpen() )
00296 fileItem->setOpen( true );
00297
00298 updateStatus();
00299 }
00300 else
00301 {
00302 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::WARNING,
00303 tr( "Permission denied." ) );
00304 QApplication::postEvent( rioQt, event );
00305 }
00306 }
00307 }
00308
00309
00310
00311
00312 void FileWindow::openFile( QListViewItem * item )
00313 {
00314 if( checkConnection() )
00315 {
00316
00317 QPtrList<FileItem> selected_list = ( (DragDropListView *)item->listView())->getSelectedFileItems();
00318
00319 for( unsigned int i = 0; i < selected_list.count(); i++ )
00320 {
00321 openFileItem( selected_list.at( i ) );
00322 }
00323 }
00324 }
00325
00326
00327
00328
00329 void FileWindow::openFileItem( FileItem * fileItem )
00330 {
00331 if( fileItem->isDir() )
00332 {
00333 exploreDirectory( fileItem );
00334 }
00335 else
00336 {
00337 unsigned int file_type = fileItem->getExtType();
00338
00339
00340 if( file_type == FileItem::ICONID_MPG )
00341 {
00342 invokeVideoPlayer( fileItem );
00343 }
00344
00345 else if( file_type == FileItem::ICONID_ZIP_FILE )
00346 {
00347 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::WARNING,
00348 tr( "Cannot open a ZIP file." ) );
00349 QApplication::postEvent( rioQt, event );
00350 }
00351
00352 else if( file_type == FileItem::ICONID_XML ||
00353 file_type == FileItem::ICONID_BROWSER ||
00354 file_type == FileItem::ICONID_INDEX ||
00355 file_type == FileItem::ICONID_TGIF )
00356 {
00357 invokeFileEditor( fileItem );
00358 }
00359
00360 else if( file_type == FileItem::ICONID_BROKEN_LINK )
00361 {
00362 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::WARNING,
00363 tr( "This file is a broken link. Cannot open it." ) );
00364 QApplication::postEvent( rioQt, event );
00365 }
00366
00367 else
00368 {
00369 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::WARNING,
00370 tr( "Unknown file type." ) );
00371 QApplication::postEvent( rioQt, event );
00372 }
00373 }
00374 }
00375
00376
00377
00378
00379
00380
00381
00382 void FileWindow::startEditor( QString file_name,
00383 QString remote_file_name )
00384 {
00385 pid_t editorPID;
00386
00387
00388 if( ( editorPID = fork() ) != 0 )
00389 {
00390 if( editorPID == -1 )
00391 {
00392 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00393 tr( "Could not start editor." ) );
00394 QApplication::postEvent( rioQt, event );
00395 }
00396 else
00397 {
00398 Editor *editor = new Editor( editorPID , file_name,
00399 remote_file_name, this );
00400
00401 rioQt->appendEditor( editor );
00402 }
00403 }
00404
00405 else
00406 {
00407 char **argv;
00408 int argc = 0;
00409
00410 QString editor = rioQt->getConfig()->getEditor();
00411 QString editorArgs = rioQt->getConfig()->getEditorArguments();
00412
00413
00414 argv = (char **)malloc( sizeof(char *) * 4 );
00415 argv[ argc++ ] = strdup( editor.ascii() );
00416
00417
00418 if( editorArgs.stripWhiteSpace().isEmpty() )
00419 {
00420 argv[ argc++ ] = strdup( file_name.ascii() );
00421 }
00422 else
00423 {
00424 argv[ argc++ ] = strdup( editorArgs.ascii() );
00425 argv[ argc++ ] = strdup( file_name.ascii() );
00426 }
00427 argv[ argc++ ] = NULL;
00428
00429
00430 if( execvp( argv[0], argv ) < 0 )
00431 {
00432
00433 exit( -1 );
00434 }
00435 }
00436 }
00437
00438
00439
00440
00441
00442 void *FileWindow::playVideo( void * command )
00443 {
00444 int erro, errolib;
00445
00446 erro = system( ( char * ) command );
00447 errolib = errno;
00448
00449 if( ( erro == -1 ) && ( errolib != ECHILD ) )
00450 {
00451 RioErr << "FileWindow::playVideo system falhou em executar o comando "
00452 << ( char * ) command << " e gerou o erro " << errolib << " ("
00453 << strerror( errolib ) << ")." << endl;
00454 }
00455 else if( ( WIFEXITED( erro ) ) && ( WEXITSTATUS( erro ) != 0 ) )
00456 {
00457 RioErr << "FileWindow::playVideo o comando " << ( char * ) command
00458 << " executou corretamente, mas retornou um valor "
00459 << WEXITSTATUS( erro ) << " diferente de 0." << endl;
00460 }
00461
00462 free( command );
00463
00464 return NULL;
00465 }
00466
00467
00468
00469
00470 void FileWindow::createDirTree( QString destPath )
00471 {
00472 FileItem *currentDirectory;
00473 QString path;
00474
00475 dirTree->clear();
00476 fileList->clear();
00477
00478 currentDirectory = new FileItem( dirTree, "/", ObjectInfo::FILE_TYPE_DIRECTORY, UseVideoRate );
00479
00480 readDirectory( currentDirectory );
00481 for( int i = 1; FileItem::getPathUntil( i, destPath, &path ); i++ )
00482 {
00483 currentDirectory->setOpen( true );
00484 if( path == currentDirectory->getPath() )
00485 break;
00486
00487 currentDirectory = FileWindow::findDirectoryInto( currentDirectory,
00488 path );
00489 readDirectory( currentDirectory );
00490 }
00491 currentDir = currentDirectory;
00492 showDirContents( currentDirectory );
00493
00494 if( !(FileItem *)dirTree->selectedItem() )
00495 dirTree->setSelected( currentDir, true );
00496
00497 updateStatus();
00498 }
00499
00500
00501
00502
00503 void FileWindow::runPopupDirTree( QListViewItem * item,
00504 const QPoint &pos, int )
00505 {
00506 if( checkConnection() )
00507 {
00508
00509 QPopupMenu *menuItemDirTree = new QPopupMenu( dirTree );
00510 menuItemDirTree->insertItem( tr( "Create directory" ), PMID_MKDIR );
00511
00512 if( type == RIO )
00513 menuItemDirTree->insertItem( tr( "Create object" ), PMID_MKOBJ );
00514
00515 menuItemDirTree->insertItem( tr( "Remove directory" ), PMID_RMFILE );
00516 menuItemDirTree->insertSeparator();
00517
00518 if( type == RIO )
00519 {
00520 menuItemDirTree->insertItem( tr( "Disk information" ), PMID_DF );
00521 menuItemDirTree->insertSeparator();
00522 }
00523
00524 menuItemDirTree->insertItem( tr( "Refresh" ), PMID_REFRESHD );
00525
00526 if( item != NULL )
00527 popupOptLoad( menuItemDirTree->exec( pos ), item );
00528
00529 delete menuItemDirTree;
00530 }
00531 }
00532
00533
00534
00535
00536 void FileWindow::runPopupFileList( QListViewItem * item,
00537 const QPoint &pos, int )
00538 {
00539 if( checkConnection() )
00540 {
00541 FileItem *fileItem = (FileItem *)item;
00542
00543
00544 QPopupMenu *menuFileList = new QPopupMenu( fileList );
00545 menuFileList->insertItem( tr( "Create directory" ), PMID_MKDIR );
00546
00547 if( type == RIO )
00548 menuFileList->insertItem( tr( "Create object" ), PMID_MKOBJ );
00549
00550 menuFileList->insertSeparator();
00551
00552 if( type == RIO )
00553 {
00554 menuFileList->insertItem( tr( "Disk information" ), PMID_DF );
00555 menuFileList->insertSeparator();
00556 }
00557
00558 menuFileList->insertItem( tr( "Refresh" ), PMID_REFRESHD );
00559
00560
00561 QPopupMenu *menuItemFileList = new QPopupMenu( fileList );
00562 menuItemFileList->insertItem( tr( "Open" ), PMID_OPEN );
00563 menuItemFileList->insertItem( tr( "Remove" ), PMID_RMFILE );
00564 menuItemFileList->insertItem( tr( "Rename" ), PMID_RENAMEFILE );
00565 menuItemFileList->insertItem( tr( "Properties" ), PMID_PROPERTIES );
00566
00567 menuItemFileList->insertSeparator();
00568 menuItemFileList->insertItem( tr( "Refresh" ), PMID_REFRESHD );
00569
00570 if( fileItem != NULL &&
00571 !fileItem->isDir() &&
00572 fileItem->getExtType() == FileItem::ICONID_MPG
00573 )
00574 {
00575 menuItemFileList->insertSeparator();
00576 menuItemFileList->insertItem( tr( "Create XML file" ), PMID_CREATEXML );
00577
00578
00579
00580 if( UseVideoRate )
00581 menuItemFileList->insertItem( tr( "Change video rate" ),
00582 PMID_VIDEORATE );
00583
00584 }
00585
00586
00587 QPtrList<FileItem> selected_list = ( (DragDropListView *)fileList )->getSelectedFileItems();
00588
00589 if( selected_list.count() == 0 )
00590 {
00591 popupOptLoad( menuFileList->exec( pos ), currentDir );
00592 }
00593 else
00594 {
00595 int id = menuItemFileList->exec( pos );
00596
00597
00598 if( id == PMID_REFRESHD )
00599 {
00600 popupOptLoad( id, currentDir );
00601 }
00602 else if( id == PMID_RMFILE )
00603 {
00604 removeFileList( fileList );
00605 }
00606 else if( id == PMID_PROPERTIES )
00607 {
00608 popupOptLoad( id, selected_list.at( 0 ), false );
00609 }
00610 else
00611 {
00612 for( unsigned int i = 0; i < selected_list.count(); i++ )
00613 {
00614 popupOptLoad( id, selected_list.at( i ), false );
00615 }
00616
00617
00618 popupOptLoad( PMID_REFRESHD, currentDir );
00619 }
00620 }
00621
00622 delete menuFileList;
00623 delete menuItemFileList;
00624 }
00625 }
00626
00627
00628
00629
00630 void FileWindow::popupOptLoad( int id, QListViewItem * item, bool autorefresh )
00631 {
00632 FileItem *fileItem = (FileItem *)item;
00633
00634 switch( id )
00635 {
00636 case PMID_MKDIR:
00637 {
00638 createDirectory();
00639
00640 break;
00641 }
00642
00643 case PMID_REFRESHD:
00644 {
00645 refreshDirectory( fileItem );
00646
00647 break;
00648 }
00649
00650 case PMID_RENAMEFILE:
00651 {
00652 bool ok;
00653 ObjectInfo fileInfo;
00654 ObjectInfo newFileInfo;
00655 QString new_file_name;
00656 QString path;
00657
00658 getObjectInfo( (char *)fileItem->getFileName().latin1(), session,
00659 &fileInfo );
00660
00661 new_file_name = QInputDialog::getText( "Rename file",
00662 "Enter the new file name:",
00663 QLineEdit::Normal,
00664 fileInfo.getName(),
00665 &ok, this );
00666 if( !fileItem->isDir() )
00667 {
00668 new_file_name = fileItem->getPath() + '/' + new_file_name;
00669 }
00670 else
00671 {
00672 int index = fileItem->getPath().findRev( '/' );
00673 path = fileItem->getPath().left( index );
00674 new_file_name = path + '/' + new_file_name;
00675 }
00676
00677 if( ok &&
00678 !new_file_name.isEmpty() &&
00679 ( new_file_name != fileItem->getFileName() )
00680 )
00681 {
00682
00683 if( !getObjectInfo( (char *)new_file_name.latin1(),
00684 session, &newFileInfo, false )
00685 )
00686 {
00687 renameFile( fileItem, new_file_name );
00688 if( autorefresh )
00689 refreshDirectory( getParentDir( fileItem ) );
00690 }
00691 else
00692 {
00693 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::INFO,
00694 tr( "The name already exists" ) );
00695 QApplication::postEvent( rioQt, event );
00696 }
00697 }
00698
00699 break;
00700 }
00701
00702 case PMID_PROPERTIES:
00703 {
00704 showProperties( item->listView() );
00705
00706 break;
00707 }
00708
00709 case PMID_OPEN:
00710 {
00711 openFileItem( fileItem );
00712
00713 break;
00714 }
00715
00716 case PMID_CREATEXML:
00717 {
00718 createXmlFile( fileItem );
00719 if( autorefresh )
00720 refreshDirectory( getParentDir( fileItem ) );
00721
00722 break;
00723 }
00724
00725
00726
00727 case PMID_RMFILE:
00728 {
00729 removeFileList( item->listView() );
00730
00731 break;
00732 }
00733
00734
00735
00736 case PMID_VIDEORATE:
00737 {
00738 CRioStream *stream;
00739 CRioObject *object;
00740 RioResult result;
00741 unsigned int VideoRate;
00742 bool ChangeVideoRate;
00743
00744
00745 stream = createNRTStream( session );
00746 if( stream == NULL )
00747 {
00748 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00749 tr( "Stream creation error" ) );
00750 QApplication::postEvent( rioQt, event );
00751 }
00752 else
00753 {
00754
00755
00756
00757 object = new CRioObject;
00758 if( object == NULL)
00759 {
00760 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00761 tr( "Object creation error" ) );
00762 QApplication::postEvent( rioQt, event );
00763 break;
00764 }
00765 result = object->Open( fileItem->getFileName(), RIO_RW_ACCESS,
00766 stream );
00767 if( FAILED( result ) ){
00768 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00769 tr( "Open object error" ) );
00770 QApplication::postEvent( rioQt, event );
00771 break;
00772 }
00773
00774 result = object->GetVideoRate( &VideoRate );
00775 if( FAILED( result ) ){
00776 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00777 tr( "Transmission rate read error" ) );
00778 QApplication::postEvent( rioQt, event );
00779 break;
00780 }
00781
00782
00783 VideoRate = QInputDialog::getInteger( "Change video rate",
00784 "New video rate",
00785 VideoRate, 0, 2147483647,
00786 1, &ChangeVideoRate, this,
00787 "ChangeVideoRateDialog" );
00788 if( ChangeVideoRate )
00789 {
00790
00791 result = object->SetVideoRate( VideoRate );
00792 if( FAILED( result ) ){
00793 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00794 tr( "Transmission rate write error" ) );
00795 QApplication::postEvent( rioQt, event );
00796 break;
00797 }
00798 refreshDirectory( getParentDir( fileItem ) );
00799 }
00800 delete object;
00801 delete stream;
00802 }
00803 break;
00804 }
00805
00806 default:
00807 {
00808
00809 popupExtraOption( id, item );
00810 }
00811 }
00812
00813
00814 updateStatus();
00815 }
00816
00817
00818
00819
00820 FileItem *FileWindow::findDirectoryInto( FileItem * directory, QString path )
00821 {
00822 FileItem * child;
00823
00824 child = ( FileItem * )directory->firstChild();
00825 while( child )
00826 {
00827 if( path == child->getPath() )
00828 break;
00829
00830 child = ( FileItem * ) child->nextSibling();
00831 }
00832
00833 return child;
00834 }
00835
00836
00837
00838
00839 void FileWindow::refreshDirectory( FileItem * directory )
00840 {
00841 if( directory == NULL )
00842 directory = currentDir;
00843 showDirContents( directory );
00844
00845 int count = directory->childCount();
00846 for( int i = 0; i < count; i++ )
00847 delete directory->firstChild();
00848
00849 readDirectory( directory );
00850 }
00851
00852
00853
00854
00855 RioQt *FileWindow::getRioQt( void )
00856 {
00857 return rioQt;
00858 }
00859
00860
00861
00862
00863 int FileWindow::getType( void )
00864 {
00865 return type;
00866 }
00867
00868
00869
00870
00871 FileItem *FileWindow::getParentDir( FileItem *child )
00872 {
00873 FileItem *parentDir;
00874
00875
00876 if( child->parent() == NULL )
00877 parentDir = currentDir;
00878 else
00879 parentDir = (FileItem *)child->parent();
00880
00881 return parentDir;
00882 }
00883
00884
00885
00886
00887 FileItem *FileWindow::getCurrentDir( void )
00888 {
00889 return currentDir;
00890 }
00891
00892
00893
00894
00895 void FileWindow::removeFileList( QListView *list_view )
00896 {
00897 QPtrList<FileItem> selected_list = ( (DragDropListView *)list_view )->getSelectedFileItems();
00898
00899
00900
00901 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::QUESTION,
00902 tr( "Are you sure you want to remove the selected item(s)?" ),
00903 tr( "Remove files" ) );
00904 QApplication::sendEvent( rioQt, event );
00905 int result = event->getResult();
00906 delete event;
00907
00908
00909 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
00910
00911 if( ( selected_list.count() > 0 ) && ( result == QMessageBox::Yes ) )
00912 {
00913 for( unsigned int i = 0; i < selected_list.count(); i++ )
00914 {
00915 if( !removeFile( selected_list.at( i ) ) )
00916 {
00917 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00918 tr( "Error while removing file ")
00919 + selected_list.at( i )->getFileName() );
00920 QApplication::postEvent( rioQt, event );
00921 break;
00922 }
00923 }
00924
00925 refreshDirectory( getParentDir( selected_list.at(0) ) );
00926 }
00927
00928
00929 updateStatus();
00930
00931
00932 QApplication::restoreOverrideCursor();
00933 }
00934
00935
00936
00937
00938
00939
00940 void FileWindow::showProperties( QListView *list_view )
00941 {
00942 QString message;
00943
00944
00945 vector<DfInfo> dfInfo;
00946 RioObjectSize free_size = 0;
00947 unsigned int total_blocks = 0;
00948 unsigned int free_blocks = 0;
00949 float percent_free = 0;
00950 string free_size_str;
00951 string percent_free_str;
00952
00953
00954 vector<DuInfo> info;
00955 RioObjectSize size = 0;
00956 unsigned int nBlocks = 0;
00957 float percent_files_disk = 0;
00958 string size_str;
00959 string nBlocks_str;
00960 string percent_files_disk_str;
00961
00962
00963 char md5[MD5SIZE];
00964 memset( md5, 0, sizeof( md5 ) );
00965
00966
00967
00968 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
00969
00970 if( type == RIO )
00971 {
00972
00973 df( &dfInfo );
00974
00975 for( unsigned int node = 0; node < dfInfo.size(); node++ )
00976 {
00977
00978 free_size += dfInfo[node].free_size;
00979 total_blocks += dfInfo[node].total_blocks_of_all_disks;
00980 free_blocks += dfInfo[node].free_blocks_of_all_disks;
00981 }
00982
00983 free_size_str = RioExplorer::formatSize( (RioObjectSize) free_size );
00984 percent_free = free_blocks * 100.0 / total_blocks;
00985 }
00986
00987 QPtrList<FileItem> selected_list = ( (DragDropListView *)list_view )->getSelectedFileItems();
00988
00989 if( selected_list.count() > 0 )
00990 {
00991 for( unsigned int i = 0; i < selected_list.count(); i++ )
00992 {
00993 if( !du( &info, (char *)selected_list.at( i )->getFileName().latin1(), session, true ) )
00994 {
00995 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00996 tr( "Error executing du" )
00997 + selected_list.at( i )->getFileName() );
00998 QApplication::postEvent( rioQt, event );
00999 break;
01000 }
01001 else
01002 {
01003 if( info.empty() )
01004 {
01005 nBlocks = 0;
01006 size = 0;
01007 }
01008 else
01009 {
01010 nBlocks += info[info.size() - 1].nBlocks;
01011 size += info[info.size() - 1].size;
01012 }
01013 }
01014 }
01015
01016
01017 percent_files_disk = nBlocks * 100.0 / total_blocks;
01018
01019
01020 percent_files_disk *= 100;
01021 percent_files_disk = (int)percent_files_disk;
01022 percent_files_disk /= 100.0;
01023
01024
01025 size_str = RioExplorer::formatSize( size );
01026
01027
01028 percent_free_str = float2string( percent_free );
01029 percent_files_disk_str = float2string( percent_files_disk );
01030 nBlocks_str = int2string( nBlocks );
01031
01032 #ifdef USE_QT_GRID
01033
01034 message += " O(s) arquivo(s) selecionado(s) tem " + nBlocks_str +
01035 " blocos\n";
01036 #else
01037 message = " O(s) arquivo(s) selecionado(s) tem " + nBlocks_str +
01038 "blocos\n";
01039 #endif
01040
01041 message += " Tamanho total do(s) arquivo(s) = " + size_str + "\n";
01042
01043
01044 if( ( selected_list.count() != 1 ) || ( selected_list.at( 0 )->isDir() ) )
01045 {
01046 message += " O Md5sum n�o � aplic�vel nesse caso.\n\n";
01047 }
01048 else
01049 {
01050 if( ( type == LOCAL ) && ( rioQt->getConfig()->getRioshShowMd5sumLocal() ) )
01051 {
01052
01053
01054 getObjectMd5Sum( (char *) selected_list.at( 0 )->getFileName().latin1(), session, md5 );
01055 message += " O Md5sum do arquivo �: " + (QString)md5 + "\n\n";
01056 }
01057 else
01058 {
01059 if( ( type == RIO ) && ( rioQt->getConfig()->getRioshShowMd5sumRIO() ) )
01060 {
01061 getObjectMd5Sum( (char *) selected_list.at( 0 )->getFileName().latin1(), session, md5 );
01062 message += " O Md5sum do arquivo �: " + (QString)md5 + "\n\n";
01063 }
01064 }
01065 }
01066
01067
01068 if( type == RIO )
01069 {
01070 message += " Espa�o livre em disco: " + free_size_str + "\n";
01071 message += " Porcentagem livre no disco: " + percent_free_str + " %\n";
01072 message += " Porcentagem do(s) arquivo(s) em rela��o ao disco: " + percent_files_disk_str + " %\n";
01073 }
01074
01075 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::INFO,
01076 tr( message ) );
01077 QApplication::postEvent( rioQt, event );
01078 }
01079
01080
01081 QApplication::restoreOverrideCursor();
01082 }
01083
01084
01085
01086
01087 void FileWindow::upDir( void )
01088 {
01089 refreshDirectory( getParentDir( currentDir ) );
01090 }
01091
01092
01093
01094
01095 void FileWindow::goHomeDir( void )
01096 {
01097 comboLocation->setCurrentText( homeDir );
01098 goLocation();
01099 }
01100
01101
01102
01103
01104 void FileWindow::toolbarRefresh( void )
01105 {
01106 refreshDirectory( currentDir );
01107 }
01108
01109
01110
01111
01112 void FileWindow::toolbarEraseFile( void )
01113 {
01114 QListView *list = NULL;
01115
01116 if( dirTree->hasFocus() )
01117 list = dirTree;
01118 else
01119 list = fileList;
01120
01121 if( list != NULL )
01122 removeFileList( list );
01123 }
01124
01125
01126
01127
01128 void FileWindow::toolbarCreateDir( void )
01129 {
01130 createDirectory();
01131 }
01132
01133
01134
01135
01136 bool FileWindow::connectRioServer( char *hostName, char *user, char *passwd )
01137 {
01138 char home[ MAXLEN_FILE + 1 ];
01139 bool status = true;
01140 string message;
01141
01142 RioResult result;
01143
01144 session = createSession( hostName, user, passwd );
01145
01146 if( session != NULL )
01147 {
01148 session->GetCurrentDir( home, MAXLEN_FILE );
01149
01150 homeDir = home;
01151 if( !getBlockSize( &blockSize, session ) )
01152 {
01153 message = "Erro ao tentar obter tamanho de bloco da sess�o RIO ";
01154 message += hostName;
01155 message += ".\n";
01156 showMessage( ERROR_MSG, message );
01157 status = false;
01158 }
01159
01160 host = session->GetServerName();
01161 setCaption( QString( user ) + "@" + host );
01162
01163
01164
01165
01166
01167
01168
01169 result = session->CheckStreamControl( &UseVideoRate );
01170 if( FAILED(result) ) {
01171 message = "Could not check stream control implementation.\n";
01172 showMessage( ERROR_MSG, message );
01173 UseVideoRate = false;
01174 }
01175 else if( UseVideoRate )
01176 {
01177
01178
01179 fileList->addColumn( tr( "File Transmission Rate" ) );
01180 }
01181
01182 userName = user;
01183 locationList.append( homeDir );
01184 goHomeDir();
01185 }
01186 else
01187 status = false;
01188
01189 return status;
01190 }
01191
01192
01193
01194
01195 QString FileWindow::getHost( void )
01196 {
01197 return QString( host );
01198 }
01199
01200
01201
01202
01203
01204 void FileWindow::createDirectory()
01205 {
01206 bool ok;
01207 string message;
01208
01209 QString text = QInputDialog::getText( "Creating Directory ",
01210 "Enter the new Directory Name:",
01211 QLineEdit::Normal,
01212 QString::null, &ok, this );
01213
01214
01215
01216 if( text.isEmpty() || ( text.contains( '/' ) == ( int )text.length() ) )
01217 {
01218 message = "mkdir: Nome inv�lido para diret�rio";
01219
01220 showMessage( ERROR_MSG, message );
01221 }
01222 else if( ok )
01223 {
01224 QString directory = currentDir->getPath() + "/" + text;
01225 mkdir( (char *)directory.latin1(), session );
01226 }
01227 refreshDirectory( currentDir );
01228 }
01229
01230
01231
01232
01233 bool FileWindow::createObject( QString fileName, unsigned int size )
01234 {
01235 return RioExplorer::createObject( (char *)fileName.latin1(), size );
01236 }
01237
01238
01239
01240
01241
01242 void FileWindow::openDiskInfo( void )
01243 {
01244 WindowOpenedEvent *event;
01245 DfRioWindow *df_window;
01246
01247
01248 df_window = new DfRioWindow( ( QWidget * ) parent()->parent(), this, "DfRioWindow" );
01249
01250
01251 if( df_window->getDiskStatus() )
01252 {
01253 df_window->show();
01254
01255 event = new WindowOpenedEvent();
01256 QApplication::postEvent( rioQt, event );
01257 }
01258 else
01259 delete df_window;
01260 }
01261
01262
01263
01264
01265 CRioSession *FileWindow::getSession( void )
01266 {
01267 return session;
01268 }
01269
01270
01271
01272
01273 QString FileWindow::getUserName( void )
01274 {
01275 return userName;
01276 }
01277
01278 void FileWindow::getDirContents( QString path )
01279 {
01280 vector<ObjectInfo> objectsInfo;
01281 ObjectInfo fileInfo;
01282 string message;
01283
01284 if( !getObjectInfo( (char *)path.latin1(), session, &fileInfo, false ) )
01285 {
01286 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
01287 tr( "Imposs�vel pegar informa��es de \"" ) +
01288 path.latin1() + "\".\n" );
01289 QApplication::postEvent( rioQt, event );
01290 }
01291 else if( ls( &fileInfo, &objectsInfo, session,
01292 rioQt->getConfig()->getRioshShowHiddenFiles(), false ) )
01293 {
01294 for( unsigned int i = 0; i < objectsInfo.size(); i++ )
01295 {
01296 FileItem *flFI;
01297
01298 QString fullPath = QString::fromUtf8( objectsInfo[i].getFullPath().c_str() );
01299
01300 flFI = new FileItem( fileList, fullPath, objectsInfo[i].getType(), UseVideoRate );
01301
01302 QDate date;
01303 date.setYMD( (int) objectsInfo[i].getTime().Year,
01304 (int) objectsInfo[i].getTime().Month,
01305 (int) objectsInfo[i].getTime().Day );
01306 QTime time;
01307 time.setHMS( (int) objectsInfo[i].getTime().Hour,
01308 (int) objectsInfo[i].getTime().Minute, 0 );
01309
01310 QDateTime dateTime( date, time );
01311
01312 flFI->setProperties( QString( objectsInfo[i].getOwner() ),
01313 QString( objectsInfo[i].getGroup() ),
01314 QString( short2Permission( objectsInfo[i].getPermission() ) ),
01315 objectsInfo[i].getSize(), dateTime,
01316 objectsInfo[i].getVideoRate() );
01317 }
01318 }
01319 else
01320 {
01321 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
01322 tr( "Erro ao listar conte�do de\"" ) +
01323 fileInfo.getFullName() + "\".\n" );
01324 QApplication::postEvent( rioQt, event );
01325 }
01326 }
01327
01328
01329
01330
01331 void FileWindow::readDirectory( FileItem *directory )
01332 {
01333 vector<ObjectInfo> objectsInfo;
01334 ObjectInfo fileInfo;
01335 string message;
01336
01337 if( !getObjectInfo( (char *)directory->getPath().latin1(), session, &fileInfo ) )
01338 {
01339 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
01340 tr( "Imposs�vel pegar informa��es de \"" ) +
01341 directory->getPath().latin1() +
01342 "\".\n" );
01343 QApplication::postEvent( rioQt, event );
01344
01345 }
01346 else if( ls( &fileInfo, &objectsInfo, session,
01347 rioQt->getConfig()->getRioshShowHiddenFiles(), false ) )
01348 {
01349 for( unsigned int i = 0; i < objectsInfo.size(); i++ )
01350 {
01351 if( objectsInfo[i].isDir() )
01352 {
01353 FileItem *dirFI;
01354
01355 dirFI = new FileItem( directory, objectsInfo[i].getFullPath(), objectsInfo[i].getType(), UseVideoRate );
01356 }
01357 }
01358 }
01359 else
01360 {
01361 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
01362 tr( "Erro ao listar conte�do de\"" ) +
01363 fileInfo.getFullName() +
01364 "\".\n" );
01365 QApplication::postEvent( rioQt, event );
01366 }
01367 }
01368
01369
01370
01371
01372 void FileWindow::updateStatus( void )
01373 {
01374 if( type == RIO )
01375 {
01376 QString statusMessage;
01377 vector<DfInfo> dfInfo;
01378 SessionsInfo sessionsInfo;
01379 RioObjectSize free_size;
01380 unsigned int total_blocks,
01381 free_blocks;
01382 float percent_free;
01383 string free_size_str;
01384
01385
01386 sessions( &sessionsInfo );
01387 df( &dfInfo );
01388
01389
01390 free_size = 0;
01391 total_blocks = 0;
01392 free_blocks = 0;
01393
01394 for( unsigned int node = 0; node < dfInfo.size(); node++ )
01395 {
01396 free_size += dfInfo[node].free_size;
01397 total_blocks += dfInfo[node].total_blocks_of_all_disks;
01398 free_blocks += dfInfo[node].free_blocks_of_all_disks;
01399 }
01400
01401 free_size_str = RioExplorer::formatSize( (RioObjectSize) free_size );
01402 percent_free = free_blocks * 100.0 / total_blocks;
01403
01404 statusMessage.sprintf( tr( "Sessions: %li/%li \tFree Space: %s (%.2f%%) " ),
01405 sessionsInfo.number_of_active_sessions,
01406 sessionsInfo.number_of_max_sessions,
01407 free_size_str.c_str(), percent_free );
01408
01409 statusBar()->message( statusMessage );
01410 }
01411 }
01412
01413
01414
01415
01416 void FileWindow::invokeVideoPlayer( FileItem *fileItem )
01417 {
01418 pthread_t thread;
01419 char *command = (char *) malloc( (MAXLEN_MESSAGE + 1)*sizeof(char));
01420 pthread_attr_t attrib;
01421 pthread_attr_init( &attrib );
01422 pthread_attr_setstacksize( &attrib, 2*PTHREAD_STACK_MIN );
01423
01424 memset( command, 0, (MAXLEN_MESSAGE + 1)*sizeof(char) );
01425
01426
01427 if( type == RIO )
01428 {
01429 strcpy( command, "riommclient " );
01430 strcat( command, host );
01431 strcat( command, ":" );
01432 strcat( command, fileItem->getFileName().ascii() );
01433 }
01434 else
01435 {
01436 strcpy( command, "mplayer " );
01437 strcat( command, fileItem->getFileName().ascii() );
01438 strcat( command, " > /dev/null 2>&1" );
01439 }
01440
01441 pthread_create( &thread, &attrib, playVideo, command );
01442 }
01443
01444
01445
01446
01447 bool FileWindow::editXmlFile( QString fileName )
01448 {
01449 bool status = false;
01450
01451
01452 RioXmlInput *xmlInput = new RioXmlInput( this, fileName );
01453
01454
01455 if( xmlInput->isValidXml() &&
01456 xmlInput->exec() == QDialog::Accepted )
01457 {
01458
01459 QFile *localFile = new QFile( fileName );
01460 QTextStream stream;
01461
01462 if( !localFile->open( IO_WriteOnly ) )
01463 {
01464 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
01465 tr( "Could open XML file" ) );
01466 QApplication::postEvent( rioQt, event );
01467 }
01468 else
01469 {
01470 stream.setDevice( localFile );
01471
01472 stream << xmlInput->getXmlCode();
01473 localFile->close();
01474
01475 status = true;
01476 }
01477 }
01478
01479 delete xmlInput;
01480
01481 return status;
01482
01483 }
01484
01485
01486
01487
01488 bool FileWindow::downloadFromRio( FileItem *fileItem, QString * fileName )
01489 {
01490 bool status = true;
01491
01492
01493 ObjectInfo fileInfo;
01494 char local_file[256];
01495
01496 strcpy( local_file, "RIO_temp_file_XXXXXXXXXXXXXXXX" );
01497 if( RIOmktemp( local_file ) )
01498 {
01499 *fileName = QString( local_file );
01500
01501 if( getObjectInfo( (char *)fileItem->getFileName().latin1(),
01502 session, &fileInfo ) )
01503 {
01504
01505 bool copy_allowed = true;
01506
01507 if( !cp( session, NULL, &fileInfo, local_file, false, true, ©_allowed ) )
01508 {
01509 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
01510 tr( "Could not copy file from RIO server." ) );
01511 QApplication::postEvent( rioQt, event );
01512
01513 status = false;
01514 }
01515 }
01516 }
01517 else
01518 {
01519 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
01520 tr( "Could not create temporary file." ) );
01521 QApplication::postEvent( rioQt, event );
01522
01523 status = false;
01524 }
01525
01526 return status;
01527 }
01528
01529
01530
01531
01532 bool FileWindow::uploadToRio( QString rioFileName, QString localFileName )
01533 {
01534 bool status = true;
01535
01536 ObjectInfo fileInfo;
01537
01538 if( getObjectInfo( (char *)localFileName.latin1(),
01539 NULL, &fileInfo ) )
01540 {
01541
01542 bool copy_allowed = true;
01543
01544 if( !cp( NULL, session, &fileInfo, (char *)rioFileName.latin1(), false,
01545 true, ©_allowed ) )
01546 {
01547 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
01548 tr( "Could not copy file to RIO server." ) );
01549 QApplication::postEvent( rioQt, event );
01550
01551 status = false;
01552 }
01553 }
01554
01555
01556 rm( &fileInfo, NULL, false, false );
01557
01558 return status;
01559 }
01560
01561
01562
01563
01564
01565
01566
01567 void FileWindow::invokeFileEditor( FileItem *fileItem )
01568 {
01569 bool status = true;
01570 QString fileName;
01571
01572
01573 if( type == RIO )
01574 {
01575 status = downloadFromRio( fileItem, &fileName );
01576 }
01577 else
01578 {
01579 fileName = fileItem->getFileName();
01580 }
01581
01582 if( status )
01583 {
01584
01585
01586 if( fileItem->getExtType() == FileItem::ICONID_XML )
01587 {
01588 if( editXmlFile( fileName ) )
01589 {
01590
01591 if( type == RIO )
01592 uploadToRio( fileItem->getFileName(), fileName );
01593 }
01594 }
01595
01596
01597 else
01598 {
01599
01600
01601
01602 startEditor( fileName, fileItem->getFileName() );
01603 }
01604 }
01605 else
01606 {
01607 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
01608 tr( "Could not copy file from RIO server." ) );
01609 QApplication::postEvent( rioQt, event );
01610 }
01611 }
01612
01613
01614
01615
01616 bool FileWindow::removeFile( FileItem *file )
01617 {
01618 ObjectInfo fileInfo;
01619 bool status = true;
01620 string message;
01621
01622 if( !getObjectInfo( (char *)file->getFileName().latin1(), session, &fileInfo ) )
01623 {
01624 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
01625 tr( "Imposs�vel pegar informa��es de \"" ) +
01626 file->getFileName().latin1() +
01627 "\".\n" );
01628 QApplication::postEvent( rioQt, event );
01629
01630 status = false;
01631 }
01632 else
01633 status = rm( &fileInfo, session, false, true );
01634
01635 return status;
01636 }
01637
01638
01639
01640
01641 void FileWindow::createXmlFile( FileItem *fileItem )
01642 {
01643 bool already_exists;
01644 QFile auxFile;
01645 QString tempName;
01646 QString auxFileName( fileItem->getFileName() );
01647
01648 tempName = auxFileName;
01649
01650 QString xmlFileName = auxFileName.remove( ".mpg" ) + ".xml";
01651
01652
01653 already_exists = false;
01654 QListViewItemIterator it( fileList );
01655 while( it.current() )
01656 {
01657 if( !( (FileItem *)it.current() )->getFileName().compare( xmlFileName ) )
01658 {
01659 already_exists = true;
01660 break;
01661 }
01662
01663 it++;
01664 }
01665
01666 if( already_exists )
01667 {
01668 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::WARNING,
01669 tr( "The file " ) + xmlFileName +
01670 tr( " already exists." ) );
01671 QApplication::postEvent( rioQt, event );
01672 }
01673 else
01674 {
01675 auxFileName = tempName;
01676
01677 if( !fileItem->isDir() && fileItem->getExtType() == FileItem::ICONID_MPG )
01678 {
01679
01680 RioXmlInput *xmlInput = new RioXmlInput( this,
01681 fileItem->getFileName(),
01682 fileItem->getSize() );
01683
01684
01685
01686 if( xmlInput->isValidXml() &&
01687 xmlInput->exec() == QDialog::Accepted )
01688 {
01689
01690 char local_file[256];
01691 strcpy( local_file, "RIO_tmp_file_XXXXXXXXXXXXXXXX" );
01692
01693 if( RIOmktemp( local_file ) )
01694 {
01695 QTextStream stream;
01696 QFile *tmp_file;
01697 tmp_file = new QFile( QString( local_file ) );
01698 if( !tmp_file->open( IO_WriteOnly ) )
01699 {
01700 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
01701 tr( "Could not open XML fileItem" ) );
01702 QApplication::postEvent( rioQt, event );
01703 }
01704 else
01705 {
01706 stream.setDevice( tmp_file );
01707
01708 stream << xmlInput->getXmlCode();
01709 tmp_file->close();
01710 }
01711
01712
01713 uploadToRio( xmlFileName, QString( local_file ) );
01714
01715 }
01716 else
01717 {
01718 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
01719 tr( "Could not open XML fileItem. " ) +
01720 tr( "Error creating temporary file.") );
01721 QApplication::postEvent( rioQt, event );
01722 }
01723
01724
01725 }
01726
01727 delete xmlInput;
01728 }
01729 else
01730 {
01731 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::WARNING,
01732 tr( "The file " ) + auxFileName +
01733 tr( " is not a MPEG video." ) );
01734 QApplication::postEvent( rioQt, event );
01735 }
01736 }
01737 }
01738
01739
01740
01741
01742 void FileWindow::popupExtraOption( int id, QListViewItem * item )
01743 {
01744 FileItem * fileItem =(FileItem *)item;
01745
01746 switch( id )
01747 {
01748 case PMID_MKOBJ:
01749 {
01750 bool ok;
01751 QString size;
01752 QString text = QInputDialog::getText( tr( "Create object" ),
01753 tr( "Enter the new object name:" ),
01754 QLineEdit::Normal,
01755 QString::null, &ok, this );
01756
01757 if( ok && !text.isEmpty() )
01758 {
01759 size = QInputDialog::getText( tr( "Create object" ),
01760 tr( "Enter the new object size (in blocks):" ),
01761 QLineEdit::Normal,
01762 QString::null, &ok, this );
01763 if( ok && !text.isEmpty() )
01764 {
01765 createObject( fileItem->getPath() + "/" + text,
01766 (unsigned int)atol( size ) );
01767 }
01768 }
01769
01770 refreshDirectory( ( FileItem * ) fileItem );
01771 }
01772 break;
01773
01774 case PMID_DF:
01775 openDiskInfo();
01776 break;
01777 }
01778 }
01779
01780
01781
01782
01783 bool FileWindow::renameFile( FileItem *fileItem, QString new_file_name )
01784 {
01785 return mv( (char *)fileItem->getFileName().ascii(),
01786 (char *)new_file_name.ascii(),
01787 session, true );
01788 }
01789
01790 bool FileWindow::showMessage( int type, string message, string title )
01791 {
01792 bool status = true;
01793 ShowMessageEvent * event;
01794 if( title == "" )
01795 event = new ShowMessageEvent( type, message );
01796 else
01797 event = new ShowMessageEvent( type, message, title );
01798 if( type == RioExplorer::QUESTION_MSG )
01799 {
01800 QApplication::sendEvent( rioQt, event );
01801
01802 if( event->getResult() == QMessageBox::No )
01803 status = false;
01804 delete event;
01805 }
01806 else
01807 QApplication::postEvent( rioQt, event );
01808
01809 return status;
01810 }
01811
01812 void FileWindow::clearLocation( void )
01813 {
01814 comboLocation->clearEdit();
01815 }
01816
01817
01818 void FileWindow::goLocation( int )
01819 {
01820 QString location = comboLocation->currentText();
01821 int index = locationList.findIndex( location );
01822 ObjectInfo fileInfo;
01823
01824 if( location != "" )
01825 {
01826 if( !getObjectInfo( (char *)location.latin1(), session, &fileInfo, false ) )
01827 {
01828 showMessage( ShowMessageEvent::ERROR, tr( "The file or folder " ) +
01829 location + tr( " does not exist" ) );
01830 }
01831 else
01832 {
01833 if( index == -1 )
01834 locationList.append( location );
01835
01836 if( fileInfo.isDir() )
01837 createDirTree( QString( fileInfo.getFullPath() ) );
01838 else
01839 {
01840 createDirTree( QString( fileInfo.getPath() ) );
01841
01842
01843 QListViewItem * item = fileList->findItem( QString( fileInfo.getName() ),
01844 FileItem::COLUMN_FILENAME );
01845 fileList->setSelected( item, true );
01846 }
01847 }
01848
01849 comboLocation->clear();
01850 comboLocation->insertStringList( locationList );
01851 comboLocation->setCurrentText( location );
01852 }
01853 else
01854 {
01855 showMessage( ShowMessageEvent::WARNING,
01856 tr( "Please, type the location you want to go." ) );
01857 }
01858 }
01859
01860 void FileWindow::updateCopyProgress( void )
01861 {
01862 for( unsigned int i = 0; i < pendingCopiesList.count(); i++ )
01863 {
01864 RioCopy * rioCopy = ( (RioCopy *)pendingCopiesList.at( i ) );
01865 rioCopy->updateProgress();
01866 }
01867 }
01868
01869 void FileWindow::setMD5Calculation( char *object, bool finished )
01870 {
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882
01883
01884
01885
01886 }
01887
01888 void FileWindow::setSyncCheck( char *object, bool finished )
01889 {
01890
01891
01892 }
01893
01894
01895
01896
01897
01898 bool FileWindow::checkConnection( void )
01899 {
01900 bool status = true;
01901
01902 if( !checkSession() )
01903 {
01904 WindowConnectionLostEvent * event;
01905
01906 event = new WindowConnectionLostEvent( this );
01907 QApplication::postEvent( rioQt, event );
01908
01909 status = false;
01910 }
01911 return status;
01912 }
01913
01914
01915
01916
01917 void FileWindow::appendCopy( RioCopy *copy )
01918 {
01919 pendingCopiesList.append( copy );
01920 }
01921
01922
01923
01924
01925 void FileWindow::removeCopy( RioCopy * copy )
01926 {
01927 for( unsigned int i = 0; i < pendingCopiesList.count(); i++ )
01928 {
01929 RioCopy * item = ( (RioCopy *)pendingCopiesList.at( i ) );
01930
01931 if( item == copy )
01932 {
01933 pendingCopiesList.remove( i );
01934 break;
01935 }
01936 }
01937 }
01938
01939
01940
01941
01942 bool FileWindow::hasPendingCopies( void )
01943 {
01944 return( pendingCopiesList.count() > 0 );
01945 }