00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <sys/types.h>
00019 #include <sys/stat.h>
00020
00021 #include <iostream>
00022
00023 using namespace std;
00024
00025 #include <qevent.h>
00026 #include <qstring.h>
00027 #include <qstringlist.h>
00028 #include <qinputdialog.h>
00029 #include <qmessagebox.h>
00030 #include <qfiledialog.h>
00031 #include <signal.h>
00032
00033 #include "RioMMInterface.h"
00034 #include "RioMMSync.h"
00035 #include "common.h"
00036
00037 #include "images/play.xpm"
00038 #include "images/pause.xpm"
00039 #include "images/info.xpm"
00040 #include "images/stop.xpm"
00041 #include "images/fast_frwd.xpm"
00042 #include "images/fast_rewd.xpm"
00043 #include "images/topic.xpm"
00044 #include "images/sync.xpm"
00045 #include "images/quit.xpm"
00046 #include "images/warning.xpm"
00047
00048 RioMMInterface::RioMMInterface( ConfigData *config )
00049 : QMainWindow()
00050 {
00051 unsigned int ind;
00052 this->config = config;
00053 string title = config->getRioMMServer();
00054 progressLatch = false;
00055 totalSize = 0;
00056 syncOn = config->getRioMMSync();
00057 syncType = SYNC_NONE;
00058 parentID = config->getRioMMMainWindow();
00059 this->p_MMObject = NULL;
00060 pos = 0;
00061 topics = NULL;
00062 pressBar = false;
00063
00064
00065 keywords_dialog = NULL;
00066
00067 if( ( ind = title.find_last_of(":") ) <= title.length() )
00068 {
00069 ind++;
00070 movieName = title.substr( ind, title.length() - ind );
00071
00072 if( ( ind = movieName.find_last_of("/") ) <= title.length() )
00073 {
00074 ind++;
00075 movieName = movieName.substr( ind, movieName.length() - ind );
00076 }
00077
00078 if( ( ind = movieName.find_last_of(".") ) <= movieName.length() )
00079 movieName = movieName.substr( 0, ind );
00080 }
00081
00082 if( ( ind = title.find_last_of(".") ) <= title.length() )
00083 moviePath = title.substr( 0, ind );
00084
00085 initComponents();
00086
00087 formTitle = "RioMMClient - " + title;
00088 setCaption( formTitle.c_str() );
00089
00090 sli_progress->setRange( 0, totalSize );
00091 sli_progress->setValue( 0 );
00092 sli_progress->setTracking( false );
00093
00094 slideNumber = 1;
00095
00096 lastJump = 0;
00097
00098
00099 startTimer( 500 );
00100
00101
00102
00103 b_finalize = false;
00104
00105
00106
00107 pthread_mutex_init( &m_finalize, NULL );
00108 }
00109
00110
00111
00112
00113 RioMMInterface::~RioMMInterface()
00114 {
00115
00116
00117
00118
00119 pthread_mutex_destroy( &m_finalize );
00120 }
00121
00122 void RioMMInterface::selectBar()
00123 {
00124 pressBar = true;
00125 }
00126
00127 void RioMMInterface::releaseBar()
00128 {
00129 pressBar = false;
00130 }
00131
00132
00133
00134
00135 void RioMMInterface::progressChange( int value )
00136 {
00137 #ifdef RIO_DEBUG2
00138 RioErr << "Moved progress bar, called progressChange" << endl;
00139 #endif
00140 ldiv_t result = ldiv( value * 100, totalSize );
00141 QString temp = QString( "%1%" ).arg( result.quot );
00142
00143 if( lab_percentage->text() != temp )
00144 lab_percentage->setText( temp );
00145
00146 if( syncOn )
00147 {
00148 #ifdef RIO_DEBUG2
00149 RioErr << "sync mode activated" << endl;
00150 #endif
00151 temp = QString( "%1/%2" ).arg( value ).arg( totalSize );
00152 lab_block_number->setText( temp );
00153 }
00154
00155 if( topics != NULL )
00156 {
00157 #ifdef RIO_DEBUG2
00158 RioErr << "topics != NULL" << endl;
00159 #endif
00160 QListViewItemIterator it( topics );
00161 while( it.current() && ( it.current()->text( 1 ).toInt() <= value ) )
00162 it++;
00163
00164 if( it.current() )
00165 {
00166 #ifdef RIO_DEBUG2
00167 RioErr << "topic found" << endl;
00168 #endif
00169 it--;
00170 if( !topics->isSelected( it.current() ) && !pressBar )
00171 topics->ensureItemVisible( it.current() );
00172
00173 topics->setSelected( it.current(), 1 );
00174 }
00175 else
00176 {
00177 #ifdef RIO_DEBUG2
00178 RioErr << "topic not found - select last" << endl;
00179 #endif
00180 if( !topics->isSelected( topics->lastItem() ) && !pressBar )
00181 topics->ensureItemVisible( topics->lastItem() );
00182
00183 topics->setSelected( topics->lastItem(), 1 );
00184 }
00185 }
00186
00187
00188
00189 pos = value;
00190 #ifdef RIO_DEBUG2
00191 RioErr << "Finished progressChange" << endl;
00192 #endif
00193 }
00194
00195
00196
00197 void RioMMInterface::jumpTo()
00198 {
00199 #ifdef RIO_DEBUG2
00200 RioErr << "entered jumpTo" << endl;
00201 #endif
00202 lastJump = sli_progress->value();
00203
00204
00205 p_MMObject->inputLog( JUMPBAR, lastJump );
00206
00207 #ifndef RIO_EMUL
00208 if( lastJump < (unsigned int)totalSize )
00209 p_MMObject->GoTo( lastJump );
00210 else
00211 stop();
00212 #endif
00213
00214 #ifdef RIO_DEBUG2
00215 RioErr << "[Interface]: jumping = " << sli_progress->value()
00216 << ", totalSize = " << totalSize << endl;
00217 #endif
00218 }
00219
00220 void RioMMInterface::play()
00221 {
00222
00223 p_MMObject->inputLog( BPLAY, p_MMObject->getCurrentPlayingBlock() );
00224
00225 but_play->setEnabled( false );
00226 but_stop->setEnabled( true );
00227 but_pause->setEnabled( true );
00228 but_fast_forward->setEnabled( true );
00229 but_fast_rewind->setEnabled( true );
00230
00231 if( topics != NULL )
00232 topics->setEnabled( true );
00233
00234
00235
00236 if( keywords_dialog != NULL )
00237 but_keywords->setEnabled( true );
00238
00239 if( syncOn )
00240 but_sync->setEnabled( true );
00241
00242 sli_progress->setEnabled( true );
00243
00244 if( parentID == 0 )
00245 but_quit->setEnabled( false );
00246
00247 setCaption( QString( formTitle.c_str() ) );
00248
00249 lastJump = 0;
00250 p_MMObject->Play();
00251 }
00252
00253 void RioMMInterface::pause()
00254 {
00255
00256 p_MMObject->inputLog( BPAUSE, p_MMObject->getCurrentPlayingBlock() );
00257
00258 but_play->setEnabled( true );
00259 but_stop->setEnabled( true );
00260 but_pause->setEnabled( false );
00261 but_fast_forward->setEnabled( false );
00262 but_fast_rewind->setEnabled( false );
00263
00264 if( topics != NULL )
00265 topics->setEnabled( false );
00266
00267
00268
00269 if( keywords_dialog != NULL )
00270 but_keywords->setEnabled( false );
00271
00272 sli_progress->setEnabled( false );
00273
00274 setCaption( "Paused" );
00275
00276 p_MMObject->Pause();
00277 }
00278
00279 void RioMMInterface::stop()
00280 {
00281 #ifdef RIO_DEBUG2
00282 RioErr << "[RioMMInterface] Entrei na stop()..." << endl;
00283 #endif
00284
00285 if( !but_stop->isEnabled() )
00286 return;
00287
00288
00289 p_MMObject->inputLog( STOP, p_MMObject->getCurrentPlayingBlock() );
00290
00291 but_play->setEnabled( true );
00292 but_stop->setEnabled( false );
00293 but_pause->setEnabled( false );
00294 but_fast_forward->setEnabled( false );
00295 but_fast_rewind->setEnabled( false );
00296
00297 if( topics != NULL )
00298 {
00299 topics->setEnabled( false );
00300 topics->clearSelection();
00301 }
00302
00303
00304
00305 if( keywords_dialog != NULL )
00306 but_keywords->setEnabled( false );
00307
00308 if( syncOn )
00309 but_sync->setEnabled( false );
00310
00311 sli_progress->setEnabled( false );
00312
00313 if( parentID == 0 )
00314 but_quit->setEnabled( true );
00315
00316 setCaption( QString( formTitle.c_str() ) );
00317
00318 p_MMObject->Stop();
00319
00320
00321 updateProgressBar( 0 );
00322
00323 if( config->getRioMMAutoPlay() )
00324 {
00325 close();
00326 }
00327
00328 #ifdef RIO_DEBUG2
00329 RioErr << "[RioMMInterface] Saindo da stop()..." << endl;
00330 #endif
00331 }
00332
00333 void RioMMInterface::fastForward()
00334 {
00335 #ifndef RIO_EMUL
00336
00337
00338
00339
00340 but_fast_forward->setAutoRepeat( false );
00341
00342 lastJump = p_MMObject->getCurrentPlayingBlock() + JUMPBLOCKS;
00343
00344 if( lastJump >= (unsigned int)totalSize )
00345 {
00346 lastJump = totalSize;
00347 p_MMObject->Stop();
00348 }
00349 else
00350 {
00351
00352
00353
00354
00355
00356
00357
00358 updateProgressBar( lastJump );
00359
00360
00361 p_MMObject->inputLog( BFFORWARD, lastJump );
00362
00363 p_MMObject->GoTo( lastJump );
00364 }
00365 #endif
00366 }
00367
00368 void RioMMInterface::fastRewind()
00369 {
00370 #ifndef RIO_EMUL
00371
00372
00373
00374
00375 but_fast_rewind->setAutoRepeat( false );
00376
00377 if( (signed int) p_MMObject->getCurrentPlayingBlock() - JUMPBLOCKS < 0 )
00378 lastJump = 0;
00379 else
00380 lastJump = p_MMObject->getCurrentPlayingBlock() - JUMPBLOCKS;
00381
00382
00383
00384
00385
00386
00387
00388 updateProgressBar( lastJump );
00389
00390
00391 p_MMObject->inputLog( BFREWIND, lastJump );
00392
00393 p_MMObject->GoTo( lastJump );
00394 #endif
00395 }
00396
00397 void RioMMInterface::info()
00398 {
00399 QString aux( "" );
00400 aux.sprintf( "Version %s\n%s", VERSION, STR_TXT_ABOUT );
00401 QMessageBox::information( this, STR_TTL_ABOUT, aux );
00402 }
00403
00404 void RioMMInterface::sync()
00405 {
00406 QString sFileName;
00407 QStringList slSyncTypes;
00408 bool ok;
00409
00410 RioMMSync *SyncWindow = new RioMMSync( this, "SyncWindow", 0 );
00411
00412
00413 pause();
00414
00415 sFileName = movieName.c_str();
00416
00417 if( syncType == SYNC_NONE )
00418 {
00419 fiSyncFile.setFile( sFileName + ".browser" );
00420 if( fiSyncFile.exists() )
00421 {
00422 syncType = SYNC_BROWSER;
00423 }
00424 else
00425 {
00426 fiSyncFile.setFile( sFileName + ".tgif" );
00427 if( fiSyncFile.exists() )
00428 {
00429 syncType = SYNC_TGIF;
00430 }
00431 }
00432
00433 if( syncType == SYNC_NONE )
00434 {
00435 slSyncTypes.append( "Browser" );
00436 slSyncTypes.append( "Tgif" );
00437 slSyncTypes.append( "Choose ..." );
00438 QString aux = QInputDialog::getItem( "Choosing sync file type",
00439 "Choose sync file type:",
00440 slSyncTypes, 0, false, &ok,
00441 this, "choose_sync" );
00442 if( ok )
00443 if( aux == "Browser" )
00444 {
00445 syncType = SYNC_BROWSER;
00446 fiSyncFile.setFile( (QString)getenv("HOME") + "/"
00447 + sFileName + ".browser" );
00448 }
00449 else if( aux == "Tgif" )
00450 {
00451 syncType = SYNC_TGIF;
00452 fiSyncFile.setFile( (QString)getenv("HOME") + "/"
00453 + sFileName + ".tgif" );
00454 }
00455 else
00456 {
00457 QFileDialog fdSync( NULL, NULL, 0, NULL, false );
00458 fdSync.setCaption( "Choose sync file" );
00459 fdSync.addFilter( "Tgif sync files (*.tgif)" );
00460 fdSync.addFilter( "Html sync files (*.browser)" );
00461 fdSync.setViewMode( QFileDialog::Detail );
00462 fdSync.setMode( QFileDialog::ExistingFile );
00463
00464 if( fdSync.exec() == QDialog::Accepted )
00465 {
00466 fiSyncFile.setFile( fdSync.selectedFile() );
00467 if( fiSyncFile.extension() == "browser" )
00468 syncType = SYNC_BROWSER;
00469 else if( fiSyncFile.extension() == "tgif" )
00470 syncType = SYNC_TGIF;
00471 }
00472 else
00473 return;
00474
00475 }
00476 else
00477 return;
00478 }
00479 }
00480 fiSyncFile.setCaching( false );
00481 fiSyncFile.convertToAbs();
00482 if( SyncWindow->Initialize( fiSyncFile, syncType, pos ) )
00483 SyncWindow->exec();
00484
00485
00486 play();
00487 }
00488
00489 void RioMMInterface::topicSelected( QListViewItem *i )
00490 {
00491 if( !i )
00492 return;
00493
00494 but_play->setEnabled( false );
00495 but_stop->setEnabled( true );
00496 but_pause->setEnabled( true );
00497 but_fast_forward->setEnabled( true );
00498 but_fast_rewind->setEnabled( true );
00499 if( syncOn )
00500 but_sync->setEnabled( true );
00501
00502 sli_progress->setEnabled( true );
00503
00504 if( parentID == 0 )
00505 but_quit->setEnabled( false );
00506
00507 lastJump = atoi( i->text( 1 ) );
00508 #ifndef RIO_EMUL
00509 if( lastJump <= (unsigned int)totalSize )
00510 {
00511
00512 p_MMObject->inputLog( JUMPTOPIC, lastJump );
00513
00514 updateProgressBar( lastJump );
00515 p_MMObject->GoTo( lastJump );
00516
00517
00518
00519 pos = lastJump;
00520 }
00521 else
00522 {
00523 QString message = "T�pico pressionado: \n";
00524 message += i->text( 0 );
00525 message += tr( "\nImposs�vel exibir bloco " );
00526 message += i->text( 1 );
00527 message += tr( "." );
00528 QMessageBox::critical( 0, "RioMMClient", message );
00529 }
00530 #endif
00531 }
00532
00533 void RioMMInterface::resetIndex()
00534 {
00535 QListViewItemIterator indexit( topics );
00536 RioMMQListViewItem *listitem;
00537
00538
00539
00540
00541 while( ( listitem = (RioMMQListViewItem *) indexit.current() ) != 0 )
00542 {
00543 listitem->setBold( false );
00544 listitem->setColor( QColor::QColor( 0, 0, 0 ) );
00545 listitem->repaint();
00546 indexit++;
00547 }
00548
00549 }
00550
00551 bool RioMMInterface::boldIndexes(QString indexes)
00552 {
00553 int i;
00554 int nindexes;
00555 int posindex;
00556 bool *flagindexes;
00557 bool ok;
00558 RioMMQListViewItem *item;
00559 QListViewItemIterator indexit( topics );
00560
00561
00562
00563 flagindexes = new bool[ readtopics ];
00564
00565 if( flagindexes == 0 )
00566 return false;
00567
00568 for( i = 0; i < readtopics; i++ )
00569 flagindexes[ i ] = false;
00570
00571
00572 nindexes = indexes.contains( ',' ) + 1;
00573
00574
00575
00576
00577 for( i = 0; i < nindexes; i++ )
00578 {
00579 posindex = indexes.section( ',', i, i ).toInt( &ok ) - 1;
00580
00581 if( !ok )
00582 {
00583 QMessageBox::critical( 0, "RioMMClient",
00584 "Erro ao converter um dos indices" );
00585 delete[] flagindexes;
00586 return false;
00587 }
00588
00589 flagindexes[ posindex ] = true;
00590 }
00591
00592
00593
00594
00595 posindex = 0;
00596
00597 while( ( item = (RioMMQListViewItem *) indexit.current() ) != 0 ) {
00598
00599 if( flagindexes[ posindex ] )
00600 {
00601 item->setBold( true );
00602 item->setColor( QColor::QColor( 255, 0, 0 ) );
00603 item->repaint();
00604 }
00605
00606 posindex++;
00607 indexit++;
00608 }
00609
00610 delete[] flagindexes;
00611 return true ;
00612 }
00613
00614 void RioMMInterface::keywords()
00615 {
00616 QString indexes;
00617
00618
00619 if( keywords_dialog->exec() == QDialog::Accepted )
00620
00621 {
00622
00623
00624 but_clean->setEnabled( true );
00625
00626 resetIndex();
00627
00628
00629 indexes = keywords_dialog->indexPositions();
00630
00631 if( !boldIndexes( indexes ) )
00632 QMessageBox::critical( this, "Keywords button", "Internal error" );
00633
00634 }
00635
00636 }
00637
00638 void RioMMInterface::clean()
00639 {
00640
00641 resetIndex();
00642
00643
00644 but_clean->setEnabled( false );
00645 }
00646
00647 void RioMMInterface::buildKeyword( QDomDocument domTree )
00648 {
00649
00650 but_keywords = new QPushButton( centralWidget() );
00651
00652 but_clean = new QPushButton( centralWidget() );
00653
00654 but_keywords->setText( "Busca por assunto" );
00655 but_clean->setText( "Limpar" );
00656 main_layout->addMultiCellWidget( but_keywords, 3, 3, 0, n_buttons - 3 );
00657 main_layout->addMultiCellWidget( but_clean, 3, 3, n_buttons - 2,
00658 n_buttons - 1 );
00659
00660
00661 connect( but_clean, SIGNAL( clicked() ), this, SLOT( clean() ) );
00662 connect( but_keywords, SIGNAL( clicked() ), this, SLOT( keywords() ) );
00663
00664 but_keywords->setEnabled( false );
00665 but_clean->setEnabled( false );
00666 but_keywords->show();
00667 but_clean->show();
00668
00669
00670
00671 keywords_dialog = new RioMMKeywordsDialog( this, "KeywordsWindow", 0 );
00672 keywords_dialog->Initialize( domTree );
00673 }
00674
00675 void RioMMInterface::buildIndex( QDomDocument domTree )
00676 {
00677 readtopics = 0;
00678
00679 topics = new QListView( centralWidget() );
00680 topics->setFixedWidth( width() - MARGIN * 2 );
00681
00682 main_layout->addMultiCellWidget( topics, 2, 2, 0, n_buttons - 1 );
00683
00684 connect( topics, SIGNAL( pressed( QListViewItem* ) ), this,
00685 SLOT( topicSelected( QListViewItem* ) ) );
00686 connect( topics, SIGNAL( verticalSliderPressed() ), this,
00687 SLOT( selectBar() ) );
00688 connect( topics, SIGNAL( verticalSliderReleased() ), this,
00689 SLOT( releaseBar() ) );
00690
00691
00692 topics->addColumn( "", 1 );
00693 topics->setSorting( -1 );
00694
00695
00696 topics->setEnabled( false );
00697
00698 if( syncOn )
00699 topics->addColumn( "Block", 1 );
00700
00701
00702
00703
00704 QDomElement root = domTree.documentElement();
00705 QDomNode node;
00706
00707
00708 QPtrStack<RioMMQListViewItem> stack;
00709
00710 stack.setAutoDelete( false );
00711 stack.clear();
00712 readtopics = buildTree( 0, root, &stack );
00713 stack.clear();
00714
00715
00716 if( syncOn )
00717 {
00718
00719 #ifndef USE_QT_GRID
00720
00721
00722 topics->adjustColumn( 1 );
00723 #endif
00724
00725 int tmp = ( readtopics < MAX_TOPICS_VIEW )? 0:1;
00726
00727 topics->setColumnWidth( 0, width() - 2 * SPACING - tmp *
00728 topics->verticalScrollBar()->sizeHint().width()
00729 - topics->columnWidth( 1 ) - ADJUST_SCROLL );
00730 }
00731 else
00732 {
00733 int tmp = ( readtopics < MAX_TOPICS_VIEW )? 0:1;
00734
00735 topics->setColumnWidth( 0, width() - 2 * SPACING - tmp *
00736 topics->verticalScrollBar()->sizeHint().width()
00737 - ADJUST_SCROLL );
00738 }
00739
00740
00741 if( parentID == 0 )
00742 {
00743 if( readtopics < 3 )
00744 readtopics = 3;
00745
00746
00747 if( readtopics < MAX_TOPICS_VIEW )
00748 setFixedSize( CLIENT_WIDTH, CLIENT_HEIGHT + TOPICS_VBORDER +
00749 TOPIC_HEIGHT * readtopics );
00750 else
00751 setFixedSize( CLIENT_WIDTH, CLIENT_HEIGHT + TOPICS_VBORDER +
00752 TOPIC_HEIGHT * MAX_TOPICS_VIEW );
00753 }
00754 else
00755 {
00756
00757 XGetWindowAttributes( qt_xdisplay(), parentID, &window_attributes );
00758
00759
00760 setFixedSize( window_attributes.width, window_attributes.height - 25 );
00761 }
00762
00763 topics->setHScrollBarMode( QScrollView::Auto );
00764 topics->show();
00765 topics->setFixedHeight( height() - MARGIN * 2 - 2 * SPACING -
00766 but_play->sizeHint().height() -
00767 sli_progress->sizeHint().height() );
00768
00769 }
00770
00771 int RioMMInterface::buildTree( RioMMQListViewItem *parentItem,
00772 const QDomElement &parentElement,
00773 QPtrStack<RioMMQListViewItem> *stack )
00774 {
00775
00776
00777 RioMMQListViewItem *thisItem = 0;
00778 RioMMQListViewItem *previousItem;
00779 QDomNode node = parentElement.firstChild();
00780 QString block;
00781 int readtopics = 0;
00782 int recreadtopics = 0;
00783
00784 while( !node.isNull() )
00785 {
00786 if( node.isElement() && ( node.nodeName() == "main_title" ) )
00787 topics->setColumnText( 0, node.toElement().text() );
00788
00789 else if( node.isElement() && ( node.nodeName() == "block" ) )
00790 {
00791 block = node.toElement().text();
00792 readtopics++;
00793
00794
00795 node = node.nextSibling();
00796
00797 if( stack->isEmpty() )
00798 previousItem = parentItem;
00799 else
00800 previousItem = stack->top();
00801
00802
00803
00804
00805
00806 if( parentItem == 0 )
00807 thisItem = new RioMMQListViewItem( topics, previousItem,
00808 QColor::QColor( 0, 0, 0 ) );
00809 else
00810 thisItem = new RioMMQListViewItem( parentItem, previousItem,
00811 QColor::QColor( 0, 0, 0 ) );
00812
00813 thisItem->setPixmap( 0, QPixmap( (const char **) topic ) );
00814 thisItem->setOpen( TRUE );
00815 thisItem->setText( 0,
00816 node.toElement().text().simplifyWhiteSpace() );
00817 thisItem->setText( 1, block );
00818 stack->push( thisItem );
00819 }
00820
00821 else if( node.isElement() && ( node.nodeName() == "ind_item" ) )
00822 recreadtopics += buildTree( thisItem, node.toElement(), stack );
00823
00824 node = node.nextSibling();
00825 }
00826
00827
00828 while( stack->top() != thisItem )
00829 stack->pop();
00830
00831 return readtopics + recreadtopics;
00832 }
00833
00834 void RioMMInterface::initComponents()
00835 {
00836 QWidget *principal_widget = new QWidget( this );
00837
00838 n_buttons = 0;
00839
00840 #ifdef USE_GRID
00841
00842
00843 mb_Wait = new QMessageBox( QString( "" ), QString( "" ),
00844 QMessageBox::Information, QMessageBox::NoButton,
00845 QMessageBox::NoButton, QMessageBox::NoButton,
00846 this, "ModelessMessageBox", true,
00847 Qt::WStyle_StaysOnTop +
00848 Qt::WStyle_DialogBorder );
00849 #endif
00850
00851 main_layout = new QGridLayout( principal_widget, 1, 1, MARGIN, SPACING,
00852 "main_layout" );
00853
00854 setCentralWidget( principal_widget );
00855
00856 lab_percentage = new QLabel( centralWidget() );
00857 lab_percentage->setText( "0%" );
00858 main_layout->addMultiCellWidget( lab_percentage, 0, 0, 0, 1 );
00859
00860 sli_progress = new QSlider( centralWidget() );
00861 sli_progress->setOrientation( QSlider::Horizontal );
00862 sli_progress->setFocusPolicy( QSlider::NoFocus );
00863 sli_progress->setEnabled( false );
00864
00865 but_play = new QPushButton( centralWidget() );
00866 but_play->setPixmap( QPixmap( (const char **)play_pixmap_data ) );
00867 main_layout->addWidget( but_play, 1, n_buttons++ );
00868
00869 but_pause = new QPushButton( centralWidget() );
00870 but_pause->setPixmap( QPixmap( (const char **)pause_pixmap_data ) );
00871 main_layout->addWidget( but_pause, 1, n_buttons++ );
00872
00873 but_stop = new QPushButton( centralWidget() );
00874 but_stop->setPixmap( QPixmap( (const char **)stop_pixmap_data ) );
00875 main_layout->addWidget( but_stop, 1, n_buttons++ );
00876
00877 but_fast_rewind = new QPushButton( centralWidget() );
00878 but_fast_rewind->setPixmap( QPixmap(
00879 (const char **)fast_rewd_pixmap_data ) );
00880 main_layout->addWidget( but_fast_rewind, 1, n_buttons++ );
00881
00882 but_fast_forward = new QPushButton( centralWidget() );
00883 but_fast_forward->setPixmap( QPixmap(
00884 (const char **)fast_frwd_pixmap_data ) );
00885 main_layout->addWidget( but_fast_forward, 1, n_buttons++ );
00886
00887 but_info = new QPushButton( centralWidget() );
00888 but_info->setPixmap( QPixmap( (const char **)info_pixmap_data ) );
00889 main_layout->addWidget( but_info, 1, n_buttons++ );
00890
00891
00892 if( parentID == 0 )
00893 {
00894 but_quit = new QPushButton( centralWidget() );
00895 but_quit->setPixmap( QPixmap( (const char **)quit_pixmap_data ) );
00896 main_layout->addWidget( but_quit, 1, n_buttons++ );
00897
00898 connect( but_quit, SIGNAL( clicked() ), this, SLOT( close() ) );
00899 }
00900
00901 status_bar = new QHBox( centralWidget() );
00902 status_bar->setFrameStyle( QFrame::ToolBarPanel );
00903 main_layout->addMultiCellWidget( status_bar, 3, 3, 0, n_buttons - 1 );
00904
00905 status_bar_text = new QLabel( status_bar );
00906 status_bar_text->setText( "" );
00907 status_bar_text->setAlignment( Qt::AlignLeft );
00908 status_bar_text->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
00909 status_bar_icon = new QLabel( status_bar );
00910 status_bar_icon->setPixmap( QPixmap( "" ) );
00911 status_bar_icon->setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );
00912
00913 status_bar_timer = new QTimer();
00914 status_bar_dot_counter = MAX_MESSAGE_DOTS;
00915
00916 setFixedSize( CLIENT_WIDTH, CLIENT_HEIGHT );
00917
00918
00919 if( syncOn )
00920 {
00921 QString temp = QString( "0/%1" ).arg( totalSize );
00922
00923 but_sync = new QPushButton( centralWidget() );
00924 but_sync->setPixmap( QPixmap( (const char **)sync_pixmap_data ) );
00925
00926 main_layout->addWidget( but_sync, 1, n_buttons++ );
00927
00928 connect( but_sync, SIGNAL( clicked() ), this, SLOT( sync() ) );
00929
00930 lab_block_number = new QLabel( centralWidget() );
00931 lab_block_number->setText( temp );
00932 lab_block_number->setAlignment( AlignRight );
00933 main_layout->addMultiCellWidget( lab_block_number, 0, 0,
00934 n_buttons - 2, n_buttons - 1 );
00935
00936 main_layout->addMultiCellWidget( sli_progress, 0, 0, 1,
00937 n_buttons - 3 );
00938 }
00939 else
00940 {
00941 main_layout->addMultiCellWidget( sli_progress, 0, 0, 1,
00942 n_buttons - 1 );
00943 }
00944
00945
00946 connect( but_play, SIGNAL( clicked() ), this, SLOT( play() ) );
00947 connect( but_pause, SIGNAL( clicked() ), this, SLOT( pause() ) );
00948 connect( but_stop, SIGNAL( clicked() ), this, SLOT( stop() ) );
00949 connect( but_fast_forward, SIGNAL( clicked() ), this,
00950 SLOT( fastForward() ) );
00951 connect( but_fast_rewind, SIGNAL( clicked() ), this,
00952 SLOT( fastRewind() ) );
00953 connect( but_info, SIGNAL( clicked() ), this, SLOT( info() ) );
00954 connect( sli_progress, SIGNAL( sliderMoved( int ) ), this,
00955 SLOT( progressChange( int ) ) );
00956 connect( sli_progress, SIGNAL( sliderPressed() ), this,
00957 SLOT( progressHold() ) );
00958 connect( sli_progress, SIGNAL( sliderReleased() ), this,
00959 SLOT( progressUnHold() ) );
00960
00961
00962
00963 but_fast_forward->setAutoRepeat( true );
00964 but_fast_rewind->setAutoRepeat( true );
00965
00966
00967 setTabOrder( but_play, but_pause );
00968 setTabOrder( but_pause, but_stop );
00969 setTabOrder( but_stop, but_fast_rewind );
00970 setTabOrder( but_fast_rewind, but_fast_forward );
00971 setTabOrder( but_fast_forward, but_info );
00972 if( !syncOn && parentID == 0 )
00973 setTabOrder( but_info, but_quit );
00974 else if( syncOn && parentID == 0 )
00975 {
00976 setTabOrder( but_info, but_quit );
00977 setTabOrder( but_quit, but_sync );
00978 }
00979 else if( syncOn && parentID > 0 )
00980 setTabOrder( but_info, but_sync );
00981
00982 but_play->setEnabled( false );
00983 but_stop->setEnabled( false );
00984 but_pause->setEnabled( false );
00985 but_fast_forward->setEnabled( false );
00986 but_fast_rewind->setEnabled( false );
00987
00988
00989 int total_width = n_buttons * but_play->sizeHint().width() +
00990 ( n_buttons - 1 ) * SPACING + 2 * MARGIN;
00991 if( total_width > width() )
00992 {
00993 int but_width = ( width() - 2 * MARGIN - ( n_buttons - 1 ) * SPACING )
00994 / n_buttons;
00995
00996 but_play->setFixedWidth( but_width );
00997 but_stop->setFixedWidth( but_width );
00998 but_pause->setFixedWidth( but_width );
00999 but_fast_forward->setFixedWidth( but_width );
01000 but_fast_rewind->setFixedWidth( but_width );
01001 but_info->setFixedWidth( but_width );
01002
01003 if( syncOn )
01004 but_sync->setFixedWidth( but_width );
01005
01006 if( parentID == 0 )
01007 but_quit->setFixedWidth( but_width );
01008 }
01009 }
01010
01011 void RioMMInterface::closeEvent( QCloseEvent * e )
01012 {
01013 QString aux;
01014 QFile fSyncFile;
01015 QTextStream *tsSyncFile;
01016
01017 signal( SIGCHLD, SIG_IGN );
01018 signal( SIGINT, SIG_IGN );
01019 signal( SIGTERM, SIG_IGN );
01020 signal( SIGHUP, SIG_IGN );
01021
01022 if( p_MMObject )
01023 {
01024 if( !but_play->isEnabled() )
01025 p_MMObject->Stop();
01026
01027 p_MMObject->Close();
01028
01029
01030
01031 if( syncType != SYNC_NONE )
01032 {
01033 switch( syncType )
01034 {
01035 case SYNC_BROWSER:
01036 aux = "";
01037 break;
01038 case SYNC_TGIF:
01039 aux = "}\n";
01040 break;
01041 }
01042 fSyncFile.setName( fiSyncFile.filePath() );
01043 if( fSyncFile.open( IO_WriteOnly | IO_Append ) )
01044 {
01045 tsSyncFile = new QTextStream( &fSyncFile );
01046 (*tsSyncFile) << aux;
01047 fSyncFile.close();
01048 }
01049 else
01050 QMessageBox::warning( 0, "riommclient",
01051 "Could not open/write file\n"
01052 + fiSyncFile.filePath() );
01053 }
01054 }
01055 e->accept();
01056 }
01057
01058
01059 void RioMMInterface::timerEvent( QTimerEvent * e )
01060 {
01061 if( !but_play->isEnabled() )
01062 {
01063 sli_progress->update();
01064 lab_percentage->update();
01065
01066 if( topics )
01067 topics->update();
01068
01069 if( syncOn )
01070 lab_block_number->update();
01071 }
01072 }
01073
01074 void RioMMInterface::progressHold()
01075 {
01076 progressLatch = true;
01077 }
01078
01079 void RioMMInterface::progressUnHold()
01080 {
01081 progressLatch = false;
01082 jumpTo();
01083 }
01084
01085 bool RioMMInterface::isProgressLatch()
01086 {
01087 return progressLatch;
01088 }
01089
01090 void RioMMInterface::setWaitMessage()
01091 {
01092 QString message = "Loading ";
01093 for( int i = 0; i < status_bar_dot_counter; i++ )
01094 message += ".";
01095 status_bar_dot_counter++;
01096 if( status_bar_dot_counter > MAX_MESSAGE_DOTS )
01097 status_bar_dot_counter = 1;
01098 status_bar_text->setText( message );
01099 }
01100
01101
01102
01103 void RioMMInterface::updateProgressBar( int progress )
01104 {
01105 sli_progress->setValue( progress );
01106 progressChange( progress );
01107 }
01108
01109 bool RioMMInterface::event( QEvent *e )
01110 {
01111 bool status;
01112 int *progress;
01113 PLAYDATA *data;
01114 QCustomEvent *ce = (QCustomEvent *)e;
01115
01116 bool ok;
01117 QString text;
01118 pthread_t tid;
01119
01120 status = false;
01121 switch( ce->type() )
01122 {
01123
01124
01125 case QEvent::User:
01126 #ifdef RIO_DEBUG2
01127 RioErr << "event User: played a block" << endl;
01128 #endif
01129 progress = (int *)ce->data();
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139 but_fast_forward->setAutoRepeat( true );
01140 but_fast_rewind->setAutoRepeat( true );
01141
01142
01143
01144 if( progressLatch == false )
01145 updateProgressBar( (int)*progress );
01146
01147 #ifdef RIO_DEBUG2
01148 RioErr << "Finished User event" << endl;
01149 #endif
01150 status = true;
01151 break;
01152
01153 case QEvent::User + 1:
01154 data = (PLAYDATA *)ce->data();
01155 switch( data->id )
01156 {
01157
01158 case 0:
01159
01160 p_MMObject = data->object;
01161 totalSize = data->size;
01162 sli_progress->setRange( 0, totalSize );
01163 but_play->setEnabled( true );
01164 break;
01165
01166
01167 case 1:
01168
01169
01170
01171
01172
01173 QMessageBox::critical( 0, *(data->title), *(data->msg) );
01174
01175
01176
01177
01178
01179 break;
01180 }
01181 status = true;
01182 break;
01183
01184 case QEvent::User + 2:
01185
01186 #ifdef RIO_DEBUG2
01187 RioErr << "\t[RioMMInterface] Evento stop() recebido de fora!"
01188 << endl;
01189 #endif
01190
01191 if( p_MMObject )
01192 stop();
01193 break;
01194
01195
01196 case QEvent::User + 3:
01197 buildIndex( *((QDomDocument *)(ce->data())) );
01198 break;
01199
01200
01201
01202 case QEvent::User + 4:
01203 play();
01204 break;
01205
01206
01207
01208 case QEvent::User + 5:
01209
01210 if( strcmp( config->getRioMMUser(), DEFAULTUSER ) == 0)
01211 {
01212 config->setRioMMPassword( encryptPassword( DEFAULTUSER ) );
01213 }
01214 else
01215 {
01216 do
01217 {
01218 text = QInputDialog::getText( "RioMMClient",
01219 QString( "User: %1\nPassword:" ).
01220 arg( config->getRioMMUser() ),
01221 QLineEdit::Password,
01222 QString::null, &ok );
01223
01224 if( ok && !text.isEmpty() )
01225 {
01226 config->setRioMMPassword( encryptPassword(
01227 text.ascii() ) );
01228 }
01229 else
01230 {
01231
01232 if( !ok )
01233 exit( -1 );
01234
01235
01236 if( text.isEmpty() )
01237 QMessageBox::information( this,
01238 "RioMMClient", "You must enter a password." );
01239 }
01240
01241
01242
01243 }while( text.isEmpty() );
01244 }
01245
01246
01247
01248 if( pthread_create( &tid, NULL, (func_t)ce->data(),
01249 (void *)config ) != 0 )
01250 {
01251 qWarning( "[RioMMClient]: Could not create initialize thread" );
01252 exit( -1 );
01253 }
01254
01255 break;
01256
01257
01258
01259 case QEvent::User + 6:
01260 buildKeyword( *((QDomDocument *)( ce->data())) );
01261 break;
01262
01263 #ifdef USE_GRID
01264
01265
01266
01267 case QEvent::User + 8:
01268 data = (PLAYDATA *)ce->data();
01269 switch( data->id )
01270 {
01271 case 0:
01272 mb_Wait->setCaption( *(data->title) );
01273 mb_Wait->setText( *(data->msg) );
01274 mb_Wait->show();
01275 break;
01276
01277 case 1:
01278 mb_Wait->hide();
01279 break;
01280 }
01281 break;
01282 #endif
01283
01284
01285 case QEvent::User + 9:
01286
01287
01288
01289
01290
01291 pthread_mutex_lock( &m_finalize );
01292 b_finalize = true;
01293 pthread_mutex_unlock( &m_finalize );
01294 break;
01295
01296
01297 case QEvent::User + 10:
01298 status_bar_dot_counter = 0;
01299 setWaitMessage();
01300 status_bar_icon->setPixmap( QPixmap( (const char **)warning_pixmap ) );
01301 connect( status_bar_timer, SIGNAL(timeout()), this, SLOT(setWaitMessage()));
01302 status_bar_timer->start( (int)(1500/MAX_MESSAGE_DOTS ));
01303 break;
01304
01305
01306 case QEvent::User + 11:
01307 status_bar_text->setText( "" );
01308 status_bar_icon->setPixmap( QPixmap( "" ) );
01309 status_bar_timer->stop();
01310 break;
01311
01312 default:
01313 status = QMainWindow::event( e );
01314 }
01315
01316
01317
01318
01319 if( ce->type() == ( QEvent::User + 1 ) )
01320 {
01321 pthread_mutex_lock( &m_finalize );
01322 if( b_finalize )
01323 {
01324 QApplication::exit( 1 );
01325 b_finalize = false;
01326 }
01327 pthread_mutex_unlock( &m_finalize );
01328 }
01329
01330 return status;
01331 }