00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "RioQt.h"
00019
00020 #include <qmenubar.h>
00021 #include <qmessagebox.h>
00022 #include <qfile.h>
00023 #include <qapplication.h>
00024
00025 #include "RioExplorer.h"
00026 #include "ConnectWindow.h"
00027 #include "ConfigureWindow.h"
00028 #include "FileWindow.h"
00029 #include "MonitorWindow.h"
00030 #include "Events.h"
00031 #include "common.h"
00032 #include "DragDropListView.h"
00033 #include "DfRioWindow.h"
00034
00035 #include "images/view_left_right.xpm"
00036 #include "images/view_top_bottom.xpm"
00037 #include "images/view_cascade.xpm"
00038
00039
00040 RioQt::RioQt()
00041 : QMainWindow()
00042 {
00043 QString title = "Riosh ";
00044 title += VERSION;
00045 setCaption( title );
00046
00047
00048 config = new ConfigData();
00049
00050 config->readSettings();
00051
00052
00053 UpIntMonConnection = config->getUpIntMonConnection();
00054
00055 workspace = new QWorkspace( this, "workspace" );
00056 setCentralWidget( workspace );
00057
00058
00059 FileWindow *local = new FileWindow( workspace, this, FileWindow::LOCAL );
00060 local->show();
00061
00062
00063 QPopupMenu *menuConnection = new QPopupMenu();
00064 menuConnection->insertItem( tr( "&Open new connection" ), this,
00065 SLOT( createConnectionWindow() ), CTRL+Key_O );
00066 menuConnection->insertSeparator();
00067 menuConnection->insertItem( tr( "&Quit" ), this,
00068 SLOT( close() ), CTRL+Key_Q );
00069
00070 QPopupMenu *menuEdit = new QPopupMenu();
00071 menuEdit->insertItem( tr( "&Preferences" ), this,
00072 SLOT( createConfigureWindow() ), CTRL+Key_P );
00073
00074 QPopupMenu *menuWindow = new QPopupMenu();
00075 menuWindow->insertItem( tr( "&Tile vertically" ), this,
00076 SLOT( arrangeVertically() ), CTRL+Key_T );
00077 menuWindow->insertItem( tr( "Tile &horizontally" ), this,
00078 SLOT( arrangeHorizontally() ), CTRL+Key_H );
00079 menuWindow->insertItem( tr( "Cascad&e" ), this,
00080 SLOT( arrangeCascade() ), CTRL+Key_E );
00081
00082 QPopupMenu *menuHelp = new QPopupMenu();
00083 menuHelp->insertItem( tr( "A&bout" ), this,
00084 SLOT( about() ), CTRL+Key_B );
00085
00086 this->menuBar()->setSeparator( QMenuBar::InWindowsStyle );
00087 this->menuBar()->insertItem( tr( "&Connection" ), menuConnection );
00088 this->menuBar()->insertItem( tr( "&Edit" ), menuEdit );
00089 this->menuBar()->insertItem( tr( "&Window" ), menuWindow );
00090 this->menuBar()->insertSeparator();
00091 this->menuBar()->insertItem( tr( "&Help" ), menuHelp );
00092
00093
00094 QToolBar * toolbar = new QToolBar( this, "file operations" );
00095
00096 tbTileHorizontally = new QToolButton( QIconSet( (const char **) image_view_top_bottom ),
00097 "Tile horizontally", QString::null,
00098 this, SLOT(arrangeHorizontally()),
00099 toolbar, "tile horizontally" );
00100 tbTileVertically = new QToolButton( QIconSet( (const char **) image_view_left_right ),
00101 "Tile vertically", QString::null,
00102 this, SLOT(arrangeVertically()),
00103 toolbar, "tile vertically" );
00104 tbCascade = new QToolButton( QIconSet( (const char **) image_view_cascade ),
00105 "Cascade", QString::null,
00106 this, SLOT(arrangeCascade()),
00107 toolbar, "cascade" );
00108 show();
00109
00110 editorList.setAutoDelete( true );
00111
00112
00113 windows_arrangement = getConfig()->getRioshWindowArrangement();
00114 arrangeWindows();
00115 }
00116
00117
00118
00119
00120
00121 void RioQt::createConnectionWindow( void )
00122 {
00123 ConnectWindow *dlg = new ConnectWindow( this, workspace );
00124
00125
00126
00127 dlg->changeUpdateInterval( UpIntMonConnection );
00128
00129 if( dlg->exec() == QDialog::Accepted )
00130 {
00131 arrangeWindows();
00132 }
00133
00134 delete dlg;
00135 }
00136
00137 void RioQt::createConfigureWindow( void )
00138 {
00139 ConfigureWindow *dlg = new ConfigureWindow( this, config );
00140
00141 if( dlg->exec() == QDialog::Accepted )
00142 {
00143 arrangeWindows();
00144
00145 #ifdef USE_QT_GRID
00146
00147 QWidgetList list = workspace->windowList();
00148 #else
00149 QWidgetList list = workspace->windowList( QWorkspace::CreationOrder );
00150 #endif
00151
00152
00153
00154 windows_arrangement = getConfig()->getRioshWindowArrangement();
00155
00156 UpIntMonConnection = getConfig()->getUpIntMonConnection();
00157
00158
00159
00160 QPtrListIterator <QWidget> it ( list );
00161 while ( it.current() != 0 )
00162 {
00163
00164
00165 if( ( *it )->inherits( "FileWindow" ) )
00166 {
00167 FileWindow *w = ( FileWindow * ) * it;
00168 ++it;
00169 w->refreshDirectory();
00170 }
00171
00172 else if( ( *it )->inherits( "MonitorWindow" ) )
00173 {
00174 MonitorWindow *w = ( MonitorWindow * ) * it;
00175 ++it;
00176 w->setUpdateInterval( UpIntMonConnection );
00177 }
00178 else if( ( *it )->inherits( "DfRioWindow" ) )
00179 {
00180 DfRioWindow *w = ( DfRioWindow * ) * it;
00181 ++it;
00182 w->getDiskInfo();
00183 }
00184 else
00185 ++it;
00186 }
00187 }
00188 }
00189
00190
00191
00192
00193
00194 void RioQt::arrangeWindows( void )
00195 {
00196 switch( windows_arrangement )
00197 {
00198 case VERTICAL:
00199 arrangeVertically();
00200 break;
00201
00202 case HORIZONTAL:
00203 arrangeHorizontally();
00204 break;
00205
00206 case CASCADE:
00207 arrangeCascade();
00208 break;
00209 }
00210 }
00211
00212
00213
00214
00215 void RioQt::arrangeVertically( void )
00216 {
00217 int x;
00218 int count;
00219 int widthForEach;
00220 int preferredWidth;
00221 int actWidth;
00222
00223 windows_arrangement = VERTICAL;
00224
00225
00226 count = workspace->windowList().count();
00227
00228 if( count > 0 )
00229 {
00230 widthForEach = workspace->width() / count;
00231 x = 0;
00232 for( int i = 0; i < count; i++ )
00233 {
00234 QWidget *window = workspace->windowList().at( i );
00235 if( window->testWState( WState_Maximized ) )
00236 {
00237
00238 window->hide();
00239 window->showNormal();
00240 }
00241 preferredWidth = window->minimumWidth()
00242 + window->parentWidget()->baseSize().width();
00243 actWidth = QMAX( widthForEach, preferredWidth );
00244
00245 window->parentWidget()->setGeometry( x, 0,
00246 actWidth,
00247 workspace->height() );
00248 x += actWidth;
00249 }
00250 }
00251 }
00252
00253
00254
00255
00256 void RioQt::arrangeCascade( void )
00257 {
00258 windows_arrangement = CASCADE;
00259
00260 workspace->cascade();
00261 }
00262
00263
00264
00265
00266 void RioQt::arrangeHorizontally( void )
00267 {
00268 int y;
00269 int count;
00270 int heightForEach;
00271 int preferredHeight;
00272 int actHeight;
00273
00274 windows_arrangement = HORIZONTAL;
00275
00276
00277 count = workspace->windowList().count();
00278
00279 if( count > 0 )
00280 {
00281 heightForEach = workspace->height() / count;
00282 y = 0;
00283 for( int i = 0; i < count; i++ )
00284 {
00285 QWidget *window = workspace->windowList().at( i );
00286 if( window->testWState( WState_Maximized ) )
00287 {
00288
00289 window->hide();
00290 window->showNormal();
00291 }
00292 preferredHeight = window->minimumHeight()
00293 + window->parentWidget()->baseSize().height();
00294 actHeight = QMAX( heightForEach, preferredHeight );
00295
00296 window->parentWidget()->setGeometry( 0, y,
00297 workspace->width(), actHeight );
00298 y += actHeight;
00299 }
00300 }
00301 }
00302
00303
00304
00305
00306 void RioQt::about( void )
00307 {
00308 QString aboutText = tr( "Version " ) + QString( VERSION ) + "\n" + QString( STR_TXT_ABOUT );
00309 QMessageBox::about( this, STR_TTL_ABOUT, aboutText );
00310 }
00311
00312
00313
00314
00315
00316 void RioQt::closeEvent( QCloseEvent *event )
00317 {
00318 bool can_close = true;
00319
00320 #ifdef USE_QT_GRID
00321
00322 QWidgetList windows_list = workspace->windowList();
00323 #else
00324 QWidgetList windows_list = workspace->windowList( QWorkspace::CreationOrder );
00325 #endif
00326
00327
00328 for( unsigned int i = 0; i < windows_list.count(); i++ )
00329 {
00330 if( hasPendingEditor( (FileWindow *)windows_list.at( i ) ) )
00331 {
00332 can_close = false;
00333
00334 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::WARNING,
00335 tr( "There are files being edited in this window. Finalize these editors before closing it." ) );
00336 QApplication::postEvent( this, event );
00337
00338 break;
00339 }
00340 }
00341
00342
00343 for( unsigned int i = 0; i < windows_list.count(); i++ )
00344 {
00345
00346
00347 if( ( windows_list.at( i )->name() != (QCString)"DfRioWindow" ) &&
00348 ( windows_list.at( i )->name() != (QCString)"MonitorWindow" ) )
00349 {
00350 FileWindow * fileWindow = (FileWindow *)windows_list.at( i );
00351 if( fileWindow->hasPendingCopies() )
00352 {
00353 can_close = false;
00354
00355 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::WARNING,
00356 tr( "There are copies that involves this window being performed.\nWait for these copies to finish or cancel them before closing this window." ) );
00357 QApplication::postEvent( this, event );
00358 break;
00359 }
00360 }
00361 }
00362
00363
00364 if( can_close )
00365 {
00366
00367 delete workspace;
00368
00369 event->accept();
00370 }
00371 }
00372
00373
00374
00375
00376
00377 void RioQt::resizeEvent( QResizeEvent * )
00378 {
00379 arrangeWindows();
00380 }
00381
00382
00383
00384
00385 void RioQt::customEvent( QCustomEvent * event )
00386 {
00387 if( event->type() == WINDOW_CLOSED_EVENT )
00388 {
00389
00390 WindowClosedEvent *windowClosedEvent = (WindowClosedEvent *)event;
00391 workspace->windowList().remove( windowClosedEvent->getWindow() );
00392
00393 delete windowClosedEvent->getWindow();
00394
00395
00396 arrangeWindows();
00397 }
00398 else if( event->type() == SHOW_MESSAGE_EVENT )
00399 {
00400 ShowMessageEvent *showMessageEvent = (ShowMessageEvent *)event;
00401 int result = showMessage( showMessageEvent->getType(),
00402 showMessageEvent->getMessage(),
00403 showMessageEvent->getTitle() );
00404 showMessageEvent->setResult( result );
00405 }
00406 else if( event->type() == WINDOW_OPENED_EVENT )
00407 {
00408 arrangeWindows();
00409 }
00410 else if( event->type() == PROGRESS_STATUS_EVENT )
00411 {
00412 ProgressStatusEvent *progressStatusEvent = (ProgressStatusEvent *)event;
00413
00414 progressStatusEvent->updateProgress();
00415 }
00416 else if( event->type() == WINDOW_CONNECTION_LOST_EVENT )
00417 {
00418 WindowConnectionLostEvent * connectionLostEvent =
00419 (WindowConnectionLostEvent *)event;
00420 FileWindow *window = (FileWindow *)connectionLostEvent->getWindow();
00421
00422 FileItem *currentDir = window->getCurrentDir();
00423 QString currentHost = window->getUserName();
00424 CRioSession * currentSession = window->getSession();
00425 QString currentServer = (QString) currentSession->GetServerName();
00426
00427 showMessage( ShowMessageEvent::ERROR, "Conex�o com " + currentHost +
00428 "@" + currentServer + " no diret�rio " +
00429 currentDir->getFileName() + " perdida.\n" +
00430 "A janela ser� fechada.", "ERROR" );
00431
00432 window->close();
00433 }
00434 else if( event->type() == SEARCH_LOGS_EVENT )
00435 {
00436
00437 SearchLogsEvent *SearchEvent = ( SearchLogsEvent * ) event;
00438
00439 MonitorWindow *Monitor = SearchEvent->getMonitorWindow();
00440
00441 Monitor->processSearchLogsEvent( SearchEvent );
00442 }
00443 }
00444
00445
00446
00447
00448 int RioQt::showMessage( int type, string message, string title )
00449 {
00450 int status = 0;
00451
00452 switch( type )
00453 {
00454 case ShowMessageEvent::ERROR:
00455 QMessageBox::critical( this, title, message,
00456 QMessageBox::Ok, QMessageBox::NoButton );
00457 break;
00458 case ShowMessageEvent::INFO:
00459 QMessageBox::information( this, title, message,
00460 QMessageBox::Ok, QMessageBox::NoButton );
00461 break;
00462 case ShowMessageEvent::QUESTION:
00463
00464 #ifdef USE_QT_GRID
00465
00466
00467 status = QMessageBox(title, message, QMessageBox::NoIcon,
00468 QMessageBox::Yes, QMessageBox::No,
00469 QMessageBox::NoButton, this).exec();
00470
00471 #else
00472 status = QMessageBox::question( this, title, message,
00473 QMessageBox::Yes, QMessageBox::No );
00474 #endif
00475
00476 break;
00477 case ShowMessageEvent::WARNING:
00478 QMessageBox::warning( this, title, message,
00479 QMessageBox::Ok, QMessageBox::NoButton );
00480 break;
00481 }
00482
00483 return status;
00484 }
00485
00486
00487
00488
00489 ConfigData *RioQt::getConfig( void )
00490 {
00491 return config;
00492 }
00493
00494
00495
00496
00497
00498
00499 void RioQt::handle_SIGCHLD( pid_t editorPID, int exit_status )
00500 {
00501 Editor *editor;
00502 int editor_type;
00503
00504 for( unsigned int i = 0; i < editorList.count(); i++ )
00505 {
00506 editor = ( (Editor *)editorList.at( i ) );
00507 editor_type = editor->fileWindow->getType();
00508
00509
00510 if( editor->editorPID == editorPID )
00511 {
00512
00513 if( exit_status == 0 )
00514 {
00515
00516
00517 FileWindow *fileWindow = (FileWindow *)editor->fileWindow;
00518 if( editor_type == FileWindow::RIO )
00519 {
00520
00521 fileWindow->uploadToRio( editor->remoteFile, editor->file );
00522 }
00523 fileWindow->refreshDirectory();
00524 }
00525
00526 else
00527 {
00528
00529 if( editor_type == FileWindow::RIO )
00530 {
00531 FileWindow *fileWindow = (FileWindow *)editor->fileWindow;
00532 ObjectInfo fileInfo;
00533 if( fileWindow->getObjectInfo( (char *)editor->file.latin1(),
00534 NULL, &fileInfo ) )
00535 {
00536 fileWindow->rm( &fileInfo, NULL, false );
00537 }
00538 }
00539
00540 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00541 tr( "Could not start editor." ) );
00542 QApplication::postEvent( this, event );
00543 }
00544
00545
00546 editorList.remove( i );
00547 break;
00548 }
00549 }
00550 }
00551
00552
00553
00554
00555 void RioQt::appendEditor( Editor *editor )
00556 {
00557 editorList.append( editor );
00558 }
00559
00560
00561
00562
00563 bool RioQt::hasPendingEditor( FileWindow *file_window )
00564 {
00565 Editor *editor;
00566
00567 for( unsigned int i = 0; i < editorList.count(); i++ )
00568 {
00569 editor = ( (Editor *)editorList.at( i ) );
00570
00571 if( editor->fileWindow == file_window )
00572 return true;
00573 }
00574
00575 return false;
00576 }
00577
00578 Editor::Editor( pid_t editorPID,
00579 QString file,
00580 QString remoteFile,
00581 FileWindow *fileWindow )
00582 {
00583 this->editorPID = editorPID;
00584 this->file = file;
00585 this->remoteFile = remoteFile;
00586 this->fileWindow = fileWindow;
00587 }