00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <qlayout.h>
00019 #include <qlabel.h>
00020 #include <qpushbutton.h>
00021 #include <qmessagebox.h>
00022 #include <qgroupbox.h>
00023 #include <qfileinfo.h>
00024 #include <qtextstream.h>
00025 #include <qfiledialog.h>
00026 #include <qlistview.h>
00027 #include <qapplication.h>
00028
00029 #include <string.h>
00030
00031 #include "RioXmlInput.h"
00032
00033 #include "common.h"
00034 #include "FileItem.h"
00035 #include "Events.h"
00036
00037
00038 #include "images/related_media.xpm"
00039 #include "images/zip_file.xpm"
00040 #include "images/browser.xpm"
00041
00042
00043
00044
00045
00046
00047 RioXmlInput::RioXmlInput( QWidget *parent,
00048 QString fileName )
00049 : QDialog( parent, "RioXmlInput", true )
00050 {
00051 this->fileName = fileName;
00052
00053 relatedMediaList.setAutoDelete( true );
00054
00055
00056 initialize();
00057
00058
00059 if( fillXmlForm( fileName ) )
00060 is_valid_xml = true;
00061 else
00062 {
00063 is_valid_xml = false;
00064 hide();
00065 }
00066 }
00067
00068
00069
00070
00071
00072
00073
00074 RioXmlInput::RioXmlInput( QWidget *parent,
00075 QString objectName,
00076 unsigned long long int objectSize )
00077 : QDialog( parent, "RioXmlInput", true )
00078 {
00079 relatedMediaList.setAutoDelete( true );
00080
00081
00082 initialize();
00083
00084
00085
00086 is_valid_xml = true;
00087
00088
00089 leFileName->setText( objectName.section( '/', -1 ) );
00090
00091 #ifdef USE_QT_GRID
00092
00093 leFileSize->setText( QString().sprintf( "%-1lli", objectSize ) );
00094 #else
00095 leFileSize->setText( QString( "%1" ).arg( objectSize, -1 ) );
00096 #endif
00097
00098 }
00099
00100
00101
00102
00103 void RioXmlInput::initialize( void )
00104 {
00105 int line;
00106
00107
00108 setCaption( tr( "RIO object properties" ) );
00109
00110 widget = new QWidget( this );
00111
00112
00113 QVBoxLayout *mainLayout = new QVBoxLayout( widget );
00114 mainLayout->setMargin( 10 );
00115 mainLayout->setSpacing( 0 );
00116
00117 QGridLayout *fieldLayout = new QGridLayout( 12, 3 );
00118 fieldLayout->setSpacing( 10 );
00119 fieldLayout->setMargin( 0 );
00120
00121 QHBoxLayout *relatedMediaExternalLayout = new QHBoxLayout();
00122
00123 QHBoxLayout *buttonLayout = new QHBoxLayout();
00124
00125
00126 leTitle = new QLineEdit( this );
00127 leTitle->setFocus();
00128 leProfessor = new QLineEdit( this );
00129 leCourse = new QLineEdit( this );
00130 leCourseCode = new QLineEdit( this );
00131 leGradProgram = new QLineEdit( this );
00132 leSource = new QLineEdit( this );
00133 leResolutionX = new QLineEdit( this );
00134 leResolutionY = new QLineEdit( this );
00135 leBitrate = new QLineEdit( this );
00136 leDuration = new QLineEdit( this );
00137 leFileName = new QLineEdit( this );
00138 leFileName->setReadOnly( true );
00139 leFileSize = new QLineEdit( this );
00140 leFileSize->setReadOnly( true );
00141
00142 cbObjectType = new QComboBox( this );
00143 cbObjectType->insertItem( "MPEG1 VIDEO" );
00144 cbObjectType->insertItem( "MPEG2 VIDEO" );
00145
00146 QGridLayout *resolutionLayout = new QGridLayout( 1, 3 );
00147
00148 resolutionLayout->addWidget( leResolutionX, 0, 0 );
00149 resolutionLayout->addWidget( new QLabel( "x", this ), 0, 1,
00150 Qt::AlignHCenter );
00151 resolutionLayout->addWidget( leResolutionY, 0, 2 );
00152
00153 line = 0;
00154 fieldLayout->addWidget( new QLabel( tr( "File:" ), this ),
00155 line, 0 );
00156 fieldLayout->addMultiCellWidget( leFileName, line, line, 1, 2, 0 );
00157 fieldLayout->addWidget( new QLabel( tr( "File size:" ), this ),
00158 ++line, 0 );
00159 fieldLayout->addWidget( leFileSize, line, 1 );
00160 fieldLayout->addWidget( new QLabel( tr( "bytes" ), this ),
00161 line, 2 );
00162 fieldLayout->addWidget( new QLabel( tr( "Title:" ), this ),
00163 ++line, 0 );
00164 fieldLayout->addWidget( leTitle, line, 1 );
00165 fieldLayout->addWidget( new QLabel( tr( "Professor:" ), this ),
00166 ++line, 0 );
00167 fieldLayout->addWidget( leProfessor, line, 1 );
00168 fieldLayout->addWidget( new QLabel( tr( "Course" ), this ),
00169 ++line, 0 );
00170 fieldLayout->addWidget( leCourse, line, 1 );
00171 fieldLayout->addWidget( new QLabel( tr( "Course code:" ), this ),
00172 ++line, 0 );
00173 fieldLayout->addWidget( leCourseCode, line, 1 );
00174 fieldLayout->addWidget( new QLabel( tr( "Program:" ), this ),
00175 ++line, 0 );
00176 fieldLayout->addWidget( leGradProgram, line, 1 );
00177 fieldLayout->addWidget( new QLabel( tr( "Object type:" ), this ),
00178 ++line, 0 );
00179 fieldLayout->addWidget( cbObjectType, line, 1 );
00180 fieldLayout->addWidget( new QLabel( tr( "Source:" ), this ),
00181 ++line, 0 );
00182 fieldLayout->addWidget( leSource, line, 1 );
00183 fieldLayout->addWidget( new QLabel( tr( "Bitrate:" ), this ),
00184 ++line, 0 );
00185 fieldLayout->addWidget( leBitrate, line, 1 );
00186 fieldLayout->addWidget( new QLabel( tr( "Kbps" ), this ),
00187 line, 2 );
00188 fieldLayout->addWidget( new QLabel( tr( "Duration:" ), this ),
00189 ++line, 0 );
00190 fieldLayout->addWidget( leDuration, line, 1 );
00191 fieldLayout->addWidget( new QLabel( tr( "hh:mm:ss" ), this ),
00192 line, 2 );
00193 fieldLayout->addWidget( new QLabel( tr( "Resolution:" ), this ),
00194 ++line, 0 );
00195 fieldLayout->addMultiCellLayout( resolutionLayout, line, line, 1, 1,
00196 Qt::AlignLeft );
00197
00198
00199 QGroupBox *gb_relatedMedia = new QGroupBox( 4, Qt::Vertical,
00200 tr( "Related media" ), this );
00201
00202 relatedMediaExternalLayout->addWidget( gb_relatedMedia, 0, 0 );
00203
00204 QFrame *frm_relatedMedia = new QFrame( gb_relatedMedia );
00205 QGridLayout *relatedMediaLayout = new QGridLayout( frm_relatedMedia, 3, 3 );
00206 relatedMediaLayout->setSpacing( 5 );
00207
00208 lvRMList = new QListView( frm_relatedMedia );
00209 lvRMList->addColumn( tr( "Media file" ) );
00210 lvRMList->addColumn( tr( "Media type" ) );
00211 lvRMList->setSelectionMode( QListView::Extended );
00212
00213 cbMediaList = new QComboBox( frm_relatedMedia );
00214 cbMediaList->insertItem( tr( "Select" ) );
00215 cbMediaList->insertItem( "TGIF sync" );
00216 cbMediaList->insertItem( "HTML sync" );
00217 cbMediaList->insertItem( "Zip" );
00218 cbMediaList->insertItem( "Index" );
00219
00220 pbAddMedia = new QPushButton( tr( "Add" ),
00221 frm_relatedMedia );
00222 pbRemoveMedia = new QPushButton( tr( "Remove" ),
00223 frm_relatedMedia );
00224 pbRemoveMedia->setEnabled( false );
00225 pbAddMedia->setEnabled( false );
00226
00227 relatedMediaLayout->addWidget( cbMediaList, 0, 0 );
00228 relatedMediaLayout->addWidget( pbAddMedia, 1, 0 );
00229 relatedMediaLayout->addWidget( pbRemoveMedia, 2, 0 );
00230 relatedMediaLayout->addMultiCellWidget( lvRMList, 0, 2, 1, 2 );
00231
00232
00233 pbOK = new QPushButton( tr( "Ok" ), this );
00234 pbOK->setDefault( true );
00235 pbOK->setEnabled( false );
00236 QPushButton *pbCancel = new QPushButton( tr( "Cancel" ), this );
00237 QPushButton *pbLoad = new QPushButton( tr( "Load XML" ), this );
00238
00239 buttonLayout->addWidget( pbOK, 0 );
00240 buttonLayout->addWidget( pbLoad, 0 );
00241 buttonLayout->addWidget( pbCancel, 0 );
00242
00243
00244 mainLayout->addLayout( fieldLayout );
00245 mainLayout->addLayout( relatedMediaExternalLayout );
00246 mainLayout->addLayout( buttonLayout );
00247
00248
00249 widget->setFixedSize( widget->minimumSizeHint() );
00250 setFixedSize( widget->minimumSizeHint() );
00251
00252
00253 setTabOrder( leFileName, leTitle );
00254 setTabOrder( leTitle, leProfessor );
00255 setTabOrder( leProfessor, leCourse );
00256 setTabOrder( leCourse, leCourseCode );
00257 setTabOrder( leCourseCode, leGradProgram );
00258 setTabOrder( leGradProgram, cbObjectType );
00259 setTabOrder( cbObjectType, leSource );
00260 setTabOrder( leSource, leBitrate );
00261 setTabOrder( leBitrate, leDuration );
00262 setTabOrder( leDuration, leResolutionX );
00263 setTabOrder( leResolutionX, leResolutionY );
00264 setTabOrder( leResolutionY, pbAddMedia );
00265 setTabOrder( pbAddMedia, pbRemoveMedia);
00266 setTabOrder( pbRemoveMedia, pbOK );
00267 setTabOrder( pbOK, pbLoad );
00268 setTabOrder( pbLoad, pbCancel );
00269
00270
00271 connect( cbMediaList, SIGNAL( activated( const QString& ) ),
00272 this, SLOT( chooseRelatedMedia( const QString& ) ) );
00273 connect( pbAddMedia, SIGNAL( clicked() ),
00274 this, SLOT( addRelatedMedia() ) );
00275 connect( pbRemoveMedia, SIGNAL( clicked() ),
00276 this, SLOT( removeRelatedMedia() ) );
00277 connect( pbOK, SIGNAL( clicked() ),
00278 this, SLOT( processInput() ) );
00279 connect( pbLoad, SIGNAL( clicked() ),
00280 this, SLOT( loadXmlFile() ) );
00281 connect( pbCancel, SIGNAL( clicked() ),
00282 this, SLOT( reject() ) );
00283 connect( lvRMList, SIGNAL( selectionChanged() ),
00284 this, SLOT( enableRemoveButton() ) );
00285 connect( leTitle, SIGNAL( textChanged( const QString& ) ),
00286 this, SLOT( enableOKButton( const QString& ) ) );
00287 connect( leProfessor, SIGNAL( textChanged( const QString& ) ),
00288 this, SLOT( enableOKButton( const QString& ) ) );
00289 connect( leCourse, SIGNAL( textChanged( const QString& ) ),
00290 this, SLOT( enableOKButton( const QString& ) ) );
00291 connect( leCourseCode, SIGNAL( textChanged( const QString& ) ),
00292 this, SLOT( enableOKButton( const QString& ) ) );
00293 connect( leGradProgram, SIGNAL( textChanged( const QString& ) ),
00294 this, SLOT( enableOKButton( const QString& ) ) );
00295 connect( leSource, SIGNAL( textChanged( const QString& ) ),
00296 this, SLOT( enableOKButton( const QString& ) ) );
00297 connect( leResolutionX, SIGNAL( textChanged( const QString& ) ),
00298 this, SLOT( enableOKButton( const QString& ) ) );
00299 connect( leResolutionY, SIGNAL( textChanged( const QString& ) ),
00300 this, SLOT( enableOKButton( const QString& ) ) );
00301 connect( leBitrate, SIGNAL( textChanged( const QString& ) ),
00302 this, SLOT( enableOKButton( const QString& ) ) );
00303 connect( leDuration, SIGNAL( textChanged( const QString& ) ),
00304 this, SLOT( enableOKButton( const QString& ) ) );
00305 connect( leFileName, SIGNAL( textChanged( const QString& ) ),
00306 this, SLOT( enableOKButton( const QString& ) ) );
00307 connect( leFileSize, SIGNAL( textChanged( const QString& ) ),
00308 this, SLOT( enableOKButton( const QString& ) ) );
00309 connect( cbObjectType, SIGNAL( activated( const QString& ) ),
00310 this, SLOT( enableOKButton( const QString& ) ) );
00311
00312
00313 rioQt = ((FileWindow *)parent())->getRioQt();
00314 }
00315
00316
00317
00318
00319
00320 void RioXmlInput::addRelatedMedia( void )
00321 {
00322 enableOKButton( "" );
00323
00324 QFileInfo fiRMFile;
00325 QListViewItem *lviItem = new QListViewItem( lvRMList );
00326
00327 int i, ind, l;
00328 QString sFileName;
00329
00330 RelatedMedia *rm = new RelatedMedia();
00331
00332
00333 i = 0;
00334 ind = -1;
00335 while( i > ind )
00336 {
00337 ind = i;
00338 i = leFileName->text().find( '.', ind + 1 );
00339 }
00340
00341 if( ind > 0 )
00342 {
00343 l = leFileName->text().length() - ind;
00344 sFileName = leFileName->text().remove( ind, l );
00345 }
00346 else
00347 sFileName = leFileName->text();
00348
00349
00350 if( cbMediaList->currentText() == "HTML sync" )
00351 {
00352 rm->fileType = RM_TYPE_BROWSER;
00353 sFileName += ".browser";
00354 }
00355 else if( cbMediaList->currentText() == "TGIF sync" )
00356 {
00357 rm->fileType = RM_TYPE_TGIF;
00358 sFileName += ".tgif";
00359 }
00360 else if( cbMediaList->currentText() == "Index" )
00361 {
00362 rm->fileType = RM_TYPE_INDEX;
00363 sFileName += ".index";
00364 }
00365 else if( cbMediaList->currentText() == "Zip" )
00366 {
00367 rm->fileType = RM_TYPE_SLIDES;
00368 sFileName += ".zip";
00369 }
00370
00371 rm->fileName = sFileName;
00372
00373
00374 lviItem->setText( 0, rm->fileName );
00375
00376 switch( rm->fileType )
00377 {
00378 case RM_TYPE_BROWSER:
00379 lviItem->setText( 1, "browser" );
00380 lviItem->setPixmap( 0, QPixmap( (const char **) image_browser ) );
00381 break;
00382 case RM_TYPE_TGIF:
00383 lviItem->setText( 1, "tgif" );
00384 lviItem->setPixmap( 0, QPixmap( (const char **) image_related_media ) );
00385 break;
00386 case RM_TYPE_INDEX:
00387 lviItem->setText( 1, "index" );
00388 lviItem->setPixmap( 0, QPixmap( (const char **) image_related_media ) );
00389 break;
00390 case RM_TYPE_SLIDES:
00391 lviItem->setText( 1, "slides" );
00392 lviItem->setPixmap( 0, QPixmap( (const char **) image_zip_file ) );
00393 break;
00394 }
00395
00396
00397 if( ( cbMediaList->currentText() == "TGIF sync" ) ||
00398 ( cbMediaList->currentText() == "HTML sync" ) )
00399 {
00400 cbMediaList->removeItem( findMediaItem( "TGIF sync" ) );
00401 cbMediaList->removeItem( findMediaItem( "HTML sync" ) );
00402 }
00403 else
00404 cbMediaList->removeItem( cbMediaList->currentItem() );
00405
00406 cbMediaList->setCurrentItem( 0 );
00407 pbAddMedia->setEnabled( false );
00408
00409 relatedMediaList.append( rm );
00410 }
00411
00412
00413
00414
00415
00416 void RioXmlInput::removeRelatedMedia()
00417 {
00418 enableOKButton( "" );
00419
00420
00421 QPtrList<QListViewItem> selected_list = getSelectedRelatedMedia();
00422 for( unsigned int i = 0; i < selected_list.count(); i++ )
00423 {
00424
00425 if( ( selected_list.at( i )->text( 1 ) == "index" ) )
00426 {
00427 cbMediaList->insertItem( "Index" );
00428 lvRMList->takeItem( selected_list.at( i ) );
00429 removeFromRelatedMediaList( RM_TYPE_INDEX );
00430 }
00431 else if( selected_list.at( i )->text( 1 ) == "browser" )
00432 {
00433 cbMediaList->insertItem( "HTML sync" );
00434 cbMediaList->insertItem( "TGIF sync" );
00435 lvRMList->takeItem( selected_list.at( i ) );
00436 removeFromRelatedMediaList( RM_TYPE_BROWSER );
00437 }
00438 else if( selected_list.at( i )->text( 1 ) == "tgif" )
00439 {
00440 cbMediaList->insertItem( "HTML sync" );
00441 cbMediaList->insertItem( "TGIF sync" );
00442 lvRMList->takeItem( selected_list.at( i ) );
00443 removeFromRelatedMediaList( RM_TYPE_TGIF );
00444 }
00445 else if( ( selected_list.at( i )->text( 1 ) == "slides" ) )
00446 {
00447 cbMediaList->insertItem( "Zip" );
00448 lvRMList->takeItem( selected_list.at( i ) );
00449 removeFromRelatedMediaList( RM_TYPE_SLIDES );
00450 }
00451 }
00452
00453 pbRemoveMedia->setEnabled( false );
00454 }
00455
00456
00457
00458
00459 void RioXmlInput::removeFromRelatedMediaList( int type )
00460 {
00461 for( unsigned int i = 0; i < relatedMediaList.count(); i++ )
00462 {
00463 if( relatedMediaList.at( i )->fileType == type )
00464 {
00465 relatedMediaList.remove( i );
00466 break;
00467 }
00468 }
00469 }
00470
00471
00472
00473
00474 QPtrList<QListViewItem> RioXmlInput::getSelectedRelatedMedia( void )
00475 {
00476 QPtrList<QListViewItem> selected_list;
00477 selected_list.clear();
00478
00479 QListViewItemIterator it( lvRMList );
00480 while( it.current() )
00481 {
00482 if( lvRMList->isSelected( it.current() ) )
00483 selected_list.append( (FileItem *)it.current() );
00484
00485 it++;
00486 }
00487
00488 return selected_list;
00489 }
00490
00491
00492
00493
00494 bool RioXmlInput::verifyInput()
00495 {
00496 bool ok;
00497
00498 if( leFileName->text().stripWhiteSpace() == "" )
00499 {
00500 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00501 tr( "You must enter File name!" ) );
00502 QApplication::postEvent( rioQt, event );
00503 return false;
00504 }
00505
00506 if( leTitle->text().stripWhiteSpace() == "" )
00507 {
00508 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00509 tr( "You must enter object Title!" ) );
00510 QApplication::postEvent( rioQt, event );
00511 return false;
00512 }
00513
00514 if( leProfessor->text().stripWhiteSpace() == "" )
00515 {
00516 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00517 tr( "You must enter Professor!" ) );
00518 QApplication::postEvent( rioQt, event );
00519 return false;
00520 }
00521
00522 if( leCourse->text().stripWhiteSpace() == "" )
00523 {
00524 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00525 tr( "You must enter Course!" ) );
00526 QApplication::postEvent( rioQt, event );
00527 return false;
00528 }
00529
00530 if( leCourseCode->text().stripWhiteSpace() == "" )
00531 {
00532 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00533 tr( "You must enter course code!" ) );
00534 QApplication::postEvent( rioQt, event );
00535 return false;
00536 }
00537
00538 if( leGradProgram->text().stripWhiteSpace() == "" )
00539 {
00540 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00541 tr( "You must enter Program!" ) );
00542 QApplication::postEvent( rioQt, event );
00543 return false;
00544 }
00545
00546 if( leSource->text().stripWhiteSpace() == "" )
00547 {
00548 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00549 tr( "You must enter object Source!" ) );
00550 QApplication::postEvent( rioQt, event );
00551 return false;
00552 }
00553
00554 if( leBitrate->text().stripWhiteSpace() == "" )
00555 {
00556 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00557 tr( "You must enter object BitRate!" ) );
00558 QApplication::postEvent( rioQt, event );
00559 return false;
00560 }
00561 else
00562 {
00563 leBitrate->text().toFloat( &ok );
00564 if( ! ok )
00565 {
00566 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00567 tr( "Bitrate must be a number!" ) );
00568 QApplication::postEvent( rioQt, event );
00569 return false;
00570 }
00571 }
00572
00573 if( leDuration->text().stripWhiteSpace() == "" )
00574 {
00575 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00576 tr( "You must enter video Duration!" ) );
00577 QApplication::postEvent( rioQt, event );
00578 return false;
00579 }
00580
00581 if( (
00582 ( cbObjectType->currentText() == "MPEG1 VIDEO") ||
00583 ( cbObjectType->currentText() == "MPEG2 VIDEO")
00584 )
00585 &&
00586 (
00587 ( leResolutionX->text().stripWhiteSpace() == "" ) ||
00588 ( leResolutionY->text().stripWhiteSpace() == "" )
00589 ) )
00590 {
00591 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00592 tr( "You must enter video resolution!" ) );
00593 QApplication::postEvent( rioQt, event );
00594 return false;
00595 }
00596 else if( ( cbObjectType->currentText() == "MPEG1 VIDEO" ) ||
00597 ( cbObjectType->currentText() == "MPEG2 VIDEO" ) )
00598 {
00599 leResolutionX->text().toInt( &ok );
00600 if( ! ok )
00601 {
00602 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00603 tr( "Video resolution is composed by integers numbers!" ) );
00604 QApplication::postEvent( rioQt, event );
00605 return false;
00606 }
00607
00608 leResolutionY->text().toInt( &ok );
00609
00610 if( ! ok )
00611 {
00612 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00613 tr( "Video resolution is composed by integers numbers!" ) );
00614 QApplication::postEvent( rioQt, event );
00615 return false;
00616 }
00617 }
00618
00619 return true;
00620 }
00621
00622
00623
00624
00625 void RioXmlInput::fillXmlTemplate( void )
00626 {
00627 QString newMediaItem,
00628 relatedMediaSet;
00629
00630
00631 xmlCode = xmlTemplate;
00632 xmlCode.replace( "${OBJECT_NAME}", leFileName->text() );
00633 xmlCode.replace( "${OBJECT_SIZE}", leFileSize->text() );
00634 xmlCode.replace( "${OBJECT_TITLE}", leTitle->text() );
00635 xmlCode.replace( "${OBJECT_TYPE}", cbObjectType->currentText() );
00636 xmlCode.replace( "${PROFESSOR}", leProfessor->text() );
00637 xmlCode.replace( "${COURSE}", leCourse->text() );
00638 xmlCode.replace( "${COURSE_CODE}", leCourseCode->text() );
00639 xmlCode.replace( "${PROGRAM}", leGradProgram->text() );
00640 xmlCode.replace( "${SOURCE}", leSource->text() );
00641 xmlCode.replace( "${BIT_RATE}", leBitrate->text() );
00642 xmlCode.replace( "${DURATION}", leDuration->text() );
00643 xmlCode.replace( "${RESOLUTION_X}", leResolutionX->text() );
00644 xmlCode.replace( "${RESOLUTION_Y}", leResolutionY->text() );
00645
00646
00647 relatedMediaSet = "";
00648 for( uint i = 0; i < relatedMediaList.count(); i++ )
00649 {
00650 newMediaItem = mediaItemTemplate;
00651 newMediaItem.replace( "${FILE_NAME}",
00652 relatedMediaList.at( i )->fileName );
00653
00654 switch ( relatedMediaList.at( i )->fileType )
00655 {
00656 case RM_TYPE_BROWSER:
00657 newMediaItem.replace( "${FILE_TYPE}",
00658 "browser" );
00659 break;
00660 case RM_TYPE_TGIF:
00661 newMediaItem.replace( "${FILE_TYPE}",
00662 "tgif" );
00663 break;
00664 case RM_TYPE_INDEX:
00665 newMediaItem.replace( "${FILE_TYPE}",
00666 "index" );
00667 break;
00668 case RM_TYPE_SLIDES:
00669 newMediaItem.replace( "${FILE_TYPE}",
00670 "slides" );
00671 break;
00672 }
00673
00674 relatedMediaSet += newMediaItem;
00675 }
00676
00677
00678 if( relatedMediaList.count() > 0 )
00679 {
00680 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::WARNING,
00681 tr( "You must be sure that the chosen related media are in the same directory as the MPEG video!" ) );
00682 QApplication::postEvent( rioQt, event );
00683 }
00684
00685
00686 xmlCode.replace( "${RELATED_MEDIA_ITEMS}", relatedMediaSet );
00687 }
00688
00689
00690
00691
00692
00693 void RioXmlInput::processInput()
00694 {
00695
00696 if( verifyInput() )
00697 {
00698 fillXmlTemplate();
00699
00700 accept();
00701 }
00702 }
00703
00704
00705
00706
00707 bool RioXmlInput::fillXmlForm( QString fileName, bool keep_mpeg_name_and_size )
00708 {
00709 RelatedMedia *rm;
00710 bool status;
00711 QDomDocument domTree;
00712
00713
00714 status = validateObjectDTD( fileName );
00715
00716
00717 QFile opmlFile( fileName );
00718
00719 if( status )
00720 {
00721 if( !opmlFile.open( IO_ReadOnly ) )
00722 {
00723 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00724 tr( "Cannot open file %1" ).arg( fileName ) );
00725 QApplication::postEvent( rioQt, event );
00726
00727 status = false;
00728 }
00729 }
00730
00731 if( status )
00732 {
00733 if( !domTree.setContent( &opmlFile ) )
00734 {
00735 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00736 tr( "Parsing error for file %1" ).arg( fileName ) );
00737 QApplication::postEvent( rioQt, event );
00738 opmlFile.close();
00739
00740 status = false;
00741 }
00742
00743 opmlFile.close();
00744 }
00745
00746 if( status )
00747 {
00748
00749 QDomElement root = domTree.documentElement();
00750 QDomNode node = root.firstChild();
00751
00752 while( !node.isNull() )
00753 {
00754 if( node.isElement() && ( node.nodeName() == "obj_filename" ) )
00755 {
00756 if( !keep_mpeg_name_and_size )
00757 leFileName->setText( node.toElement().text() );
00758 }
00759
00760 else if( node.isElement() && ( node.nodeName() == "obj_filesize" ) )
00761 {
00762 if( !keep_mpeg_name_and_size )
00763 leFileSize->setText( node.toElement().text() );
00764 }
00765
00766 else if( node.isElement() && ( node.nodeName() == "obj_title" ) )
00767 leTitle->setText( node.toElement().text() );
00768
00769 else if( node.isElement() && ( node.nodeName() == "obj_type" ) )
00770 cbObjectType->setCurrentText( node.toElement().text() );
00771
00772 else if( node.isElement() && ( node.nodeName() == "professor" ) )
00773 leProfessor->setText( node.toElement().text() );
00774
00775 else if( node.isElement() && ( node.nodeName() == "course" ) )
00776 leCourse->setText( node.toElement().text() );
00777
00778 else if( node.isElement() && ( node.nodeName() == "coursecode" ) )
00779 leCourseCode->setText( node.toElement().text() );
00780
00781 else if( node.isElement() && ( node.nodeName() == "grad_program" ) )
00782 leGradProgram->setText( node.toElement().text() );
00783
00784 else if( node.isElement() && ( node.nodeName() == "source" ) )
00785 leSource->setText( node.toElement().text() );
00786
00787 else if( node.isElement() && ( node.nodeName() == "bitrate" ) )
00788 leBitrate->setText( node.toElement().text() );
00789
00790 else if( node.isElement() && ( node.nodeName() == "duration" ) )
00791 leDuration->setText( node.toElement().text() );
00792
00793 else if( node.isElement() && ( node.nodeName() == "resolution" ) )
00794 {
00795 QDomNode nodechild = node.toElement().firstChild();
00796
00797 if( nodechild.isElement() && ( nodechild.nodeName() == "r_x" ) )
00798 leResolutionX->setText( nodechild.toElement().text() );
00799
00800 nodechild = nodechild.nextSibling();
00801
00802 if( nodechild.isElement() && ( nodechild.nodeName() == "r_y" ) )
00803 leResolutionY->setText( nodechild.toElement().text() );
00804 }
00805
00806 else if( node.isElement() && ( node.nodeName() == "related_media" ) )
00807 {
00808 QDomNode nodechild = node.toElement().firstChild();
00809 QDomNode nodegrandson;
00810 QListViewItem *previous = 0, *thisItem;
00811
00812 while( !nodechild.isNull() )
00813 {
00814 nodegrandson = nodechild.toElement().firstChild();
00815 thisItem = new QListViewItem( lvRMList, previous );
00816 rm = new RelatedMedia();
00817
00818 if( ( nodegrandson.isElement() ) &&
00819 ( nodegrandson.nodeName() == "rm_filename" ) )
00820 {
00821 thisItem->setText( 0, nodegrandson.toElement().text() );
00822 rm->fileName = nodegrandson.toElement().text();
00823 }
00824
00825 nodegrandson = nodegrandson.nextSibling();
00826
00827 if( ( nodegrandson.isElement() ) &&
00828 ( nodegrandson.nodeName() == "rm_type" ) )
00829 thisItem->setText( 1, nodegrandson.toElement().text() );
00830
00831 if( thisItem->text(0).section('.',1,1 ) == "browser" )
00832 {
00833 thisItem->setPixmap( 0, QPixmap( (const char **) image_browser ) );
00834 rm->fileType = RM_TYPE_BROWSER;
00835 cbMediaList->removeItem( findMediaItem( "HTML sync" ) );
00836 cbMediaList->removeItem( findMediaItem( "TGIF sync" ) );
00837 }
00838 else if( thisItem->text(0).section('.',1,1 ) == "tgif" )
00839 {
00840 thisItem->setPixmap( 0, QPixmap( (const char **) image_related_media ) );
00841 rm->fileType = RM_TYPE_TGIF;
00842 cbMediaList->removeItem( findMediaItem( "TGIF sync" ) );
00843 cbMediaList->removeItem( findMediaItem( "HTML sync" ) );
00844 }
00845 else if( thisItem->text(0).section('.',1,1) == "index" )
00846 {
00847 thisItem->setPixmap( 0, QPixmap( (const char **) image_related_media ) );
00848 rm->fileType = RM_TYPE_INDEX;
00849 cbMediaList->removeItem( findMediaItem( "Index" ) );
00850 }
00851 else if( thisItem->text(0).section('.',1,1) == "zip" )
00852 {
00853 thisItem->setPixmap( 0, QPixmap( (const char **) image_zip_file ) );
00854 rm->fileType = RM_TYPE_SLIDES;
00855 cbMediaList->removeItem( findMediaItem( "Zip" ) );
00856 }
00857 else
00858 {
00859 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00860 tr( "This XML file contains an invalid item (" ) +
00861 thisItem->text(0) +
00862 tr( ") and it will be ignored!" ) );
00863 QApplication::postEvent( rioQt, event );
00864 delete thisItem;
00865 delete rm;
00866 nodechild = nodechild.nextSibling();
00867 continue;
00868 }
00869
00870 previous = thisItem;
00871 nodechild = nodechild.nextSibling();
00872 relatedMediaList.append( rm );
00873 }
00874 }
00875
00876 node = node.nextSibling();
00877 }
00878 }
00879
00880 pbOK->setEnabled( status );
00881
00882 return status;
00883 }
00884
00885
00886
00887
00888 void RioXmlInput::loadXmlFile( void )
00889 {
00890 QFileDialog fdXmlLoad( fileName );
00891
00892 fdXmlLoad.setCaption( tr( "Load XML file" ) );
00893 fdXmlLoad.addFilter( "Xml files (*.xml)" );
00894 fdXmlLoad.setViewMode( QFileDialog::Detail );
00895 fdXmlLoad.setMode( QFileDialog::ExistingFile );
00896
00897 if( fdXmlLoad.exec() == QDialog::Accepted )
00898 {
00899
00900 lvRMList->clear();
00901
00902 cbMediaList->clear();
00903 cbMediaList->insertItem( "Select Media" );
00904 cbMediaList->insertItem( "TGIF sync" );
00905 cbMediaList->insertItem( "HTML sync" );
00906 cbMediaList->insertItem( "Zip" );
00907 cbMediaList->insertItem( "Index" );
00908
00909
00910 fillXmlForm( fdXmlLoad.selectedFile(), true );
00911 }
00912 }
00913
00914
00915
00916
00917
00918 bool RioXmlInput::validateObjectDTD( QString file_name )
00919 {
00920 bool status = true;
00921
00922
00923 int index = file_name.findRev( '/' );
00924 QString directory = file_name.left( index );
00925
00926
00927 QString dtd_file_name = directory + "/object.dtd";
00928 QTextStream stream;
00929 QFile *dtd_file;
00930
00931 dtd_file = new QFile( dtd_file_name );
00932 if( !dtd_file->open( IO_WriteOnly ) )
00933 {
00934 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00935 tr( "Could not write DTD template to filesystem." ) );
00936 QApplication::postEvent( rioQt, event );
00937 status = false;
00938 }
00939 else
00940 {
00941 stream.setDevice( dtd_file );
00942
00943 stream << objectDTD;
00944 dtd_file->close();
00945 }
00946
00947
00948 if( status )
00949 {
00950 xmlDoValidityCheckingDefaultValue = 1;
00951 xmlDocPtr doc = xmlParseFile( file_name.ascii() );
00952
00953 xmlValidCtxt cvp;
00954 cvp.userData = NULL;
00955 cvp.error = (xmlValidityErrorFunc) doNothing;
00956 cvp.warning = (xmlValidityWarningFunc) doNothing;
00957
00958 if( !xmlValidateDocument( &cvp, doc ) )
00959 {
00960 ShowMessageEvent * event = new ShowMessageEvent( ShowMessageEvent::ERROR,
00961 tr( "This file is in a wrong format." ) );
00962 QApplication::postEvent( rioQt, event );
00963 pbOK->setEnabled( true );
00964
00965 status = false;
00966 }
00967
00968 xmlXIncludeProcess( doc );
00969 xmlFreeDoc( doc );
00970 xmlCleanupParser();
00971 xmlMemoryDump();
00972 }
00973
00974
00975 dtd_file->remove();
00976 delete dtd_file;
00977
00978 return status;
00979 }
00980
00981 void RioXmlInput::chooseRelatedMedia( const QString &chosenMedia )
00982 {
00983 if( chosenMedia == "Select Media" )
00984 pbAddMedia->setEnabled( false );
00985 else
00986 pbAddMedia->setEnabled( true );
00987 }
00988
00989 void RioXmlInput::enableOKButton( const QString &s )
00990 {
00991 pbOK->setEnabled( true );
00992 }
00993
00994 void RioXmlInput::enableOKButton( bool b )
00995 {
00996 pbOK->setEnabled( true );
00997 }
00998
00999 void RioXmlInput::enableRemoveButton()
01000 {
01001 pbRemoveMedia->setEnabled( true );
01002 }
01003
01004 int RioXmlInput::findMediaItem( QString media_type )
01005 {
01006 int item = 0;
01007
01008 while( ( cbMediaList->text( item ) != media_type ) &&
01009 ( item < cbMediaList->count() ) )
01010 item++;
01011
01012 return item;
01013 }
01014
01015
01016
01017
01018 QString RioXmlInput::getXmlCode( void )
01019 {
01020 return xmlCode;
01021 }
01022
01023
01024
01025
01026 bool RioXmlInput::isValidXml( void )
01027 {
01028 return is_valid_xml;
01029 }
01030
01031
01032
01033
01034
01035 void doNothing( void )
01036 {
01037 }