RioXmlInput Class Reference

#include <RioXmlInput.h>

Public Member Functions

 RioXmlInput (QWidget *parent, QString fileName)
 RioXmlInput (QWidget *parent, QString objectName, unsigned long long int objectSize)
QString getXmlCode (void)
 Returns the complete and correct XML code.
bool isValidXml (void)
 Returns true if the XML is in a valid format.

Static Public Attributes

static const int RM_TYPE_BROWSER = 0
static const int RM_TYPE_TGIF = 1
static const int RM_TYPE_SLIDES = 2
static const int RM_TYPE_INDEX = 3

Private Slots

void addRelatedMedia ()
 Allow the user to choose related media files Fill up the class relatedMediaList struct with media file info.
void removeRelatedMedia ()
 Remove selected media file from the list view and from the struct relatedMediaList.
void processInput ()
void loadXmlFile (void)
 Asks user for a XML file and uses it to fill form fields.
void chooseRelatedMedia (const QString &)
void enableRemoveButton ()
void enableOKButton (const QString &)
void enableOKButton (bool)

Private Member Functions

void initialize (void)
 Initialize interface.
void fillXmlTemplate (void)
 Fill XML template with data supplied by the user.
bool fillXmlForm (QString, bool=false)
 Fill form fields with data from given file.
bool verifyInput (void)
 Verifies the user input if something is wrong shows a pop-up warnig.
bool validateObjectDTD (QString)
 Validates a file that is quite to be loaded against a DTD format specification.
int findMediaItem (QString)
QPtrList< QListViewItem > getSelectedRelatedMedia (void)
 Returns the selected related media.
void removeFromRelatedMediaList (int)
 Removes media of a given type from relatedMediaList.

Private Attributes

RioQtrioQt
QLineEdit * leTitle
QLineEdit * leProfessor
QLineEdit * leCourse
QLineEdit * leGradProgram
QLineEdit * leSource
QLineEdit * leResolutionX
QLineEdit * leResolutionY
QLineEdit * leBitrate
QLineEdit * leDuration
QLineEdit * leFileName
QLineEdit * leCourseCode
QLineEdit * leFileSize
QComboBox * cbObjectType
QComboBox * cbMediaList
QWidget * widget
QListView * lvRMList
QPushButton * pbAddMedia
QPushButton * pbRemoveMedia
QPushButton * pbOK
QString xmlCode
bool is_valid_xml
QString fileName
QPtrList< RelatedMediarelatedMediaList

Detailed Description

Definition at line 34 of file RioXmlInput.h.


Constructor & Destructor Documentation

RioXmlInput::RioXmlInput ( QWidget *  parent,
QString  fileName 
)

Definition at line 47 of file RioXmlInput.cpp.

00049             : QDialog( parent, "RioXmlInput", true )
00050 {
00051     this->fileName = fileName;
00052 
00053     relatedMediaList.setAutoDelete( true );
00054 
00055     // Build interface
00056     initialize();
00057 
00058     // Check XML data and fill form
00059     if( fillXmlForm( fileName ) )
00060         is_valid_xml = true;
00061     else
00062     {
00063         is_valid_xml = false;
00064         hide();
00065     }
00066 }

RioXmlInput::RioXmlInput ( QWidget *  parent,
QString  objectName,
unsigned long long int  objectSize 
)

Definition at line 74 of file RioXmlInput.cpp.

00077             : QDialog( parent, "RioXmlInput", true )
00078 {
00079     relatedMediaList.setAutoDelete( true );
00080 
00081     // Build interface
00082     initialize();
00083 
00084     // As the XML file is new, the correctness is guaranteed by the function
00085     // verifyInput(), that will be invoked when user press 'Ok'
00086     is_valid_xml = true;
00087 
00088     // File name filled only with the name of the MPEG file
00089     leFileName->setText( objectName.section( '/', -1 ) );
00090 
00091     #ifdef USE_QT_GRID
00092     // Adapta��o para a Qt 3.1 (usada na GRID).
00093     leFileSize->setText( QString().sprintf( "%-1lli", objectSize ) );
00094     #else
00095     leFileSize->setText( QString( "%1" ).arg( objectSize, -1 ) );
00096     #endif
00097 
00098 }


Member Function Documentation

void RioXmlInput::addRelatedMedia ( void   )  [private, slot]

Allow the user to choose related media files Fill up the class relatedMediaList struct with media file info.

Definition at line 320 of file RioXmlInput.cpp.

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     // Discover file name (still without extension)
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     // Discover file type and append extension accotdingly
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     // Fill listview
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     // User must choose one of TGIF or HTML sync file
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 }

void RioXmlInput::chooseRelatedMedia ( const QString &  chosenMedia  )  [private, slot]

Definition at line 981 of file RioXmlInput.cpp.

00982 {
00983     if( chosenMedia == "Select Media" )
00984         pbAddMedia->setEnabled( false );
00985     else
00986         pbAddMedia->setEnabled( true );
00987 }

void RioXmlInput::enableOKButton ( bool  b  )  [private, slot]

Definition at line 994 of file RioXmlInput.cpp.

00995 {
00996     pbOK->setEnabled( true );
00997 }

void RioXmlInput::enableOKButton ( const QString &  s  )  [private, slot]

Definition at line 989 of file RioXmlInput.cpp.

00990 {
00991     pbOK->setEnabled( true );
00992 }

void RioXmlInput::enableRemoveButton (  )  [private, slot]

Definition at line 999 of file RioXmlInput.cpp.

01000 {
01001     pbRemoveMedia->setEnabled( true );
01002 }

bool RioXmlInput::fillXmlForm ( QString  fileName,
bool  keep_mpeg_name_and_size = false 
) [private]

Fill form fields with data from given file.

Definition at line 707 of file RioXmlInput.cpp.

00708 {
00709     RelatedMedia *rm;
00710     bool status;
00711     QDomDocument domTree;
00712 
00713     // First, validate against DTD
00714     status = validateObjectDTD( fileName );
00715 
00716     // read the XML file and create DOM tree
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         // get the header information from the DOM
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 }

void RioXmlInput::fillXmlTemplate ( void   )  [private]

Fill XML template with data supplied by the user.

Definition at line 625 of file RioXmlInput.cpp.

00626 {
00627     QString newMediaItem,
00628             relatedMediaSet;
00629 
00630     // Assembly a new XML file
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     // Assembly a related media list
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     // Warn user about relatedMedias
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     // Adds related media list to XML code
00686     xmlCode.replace( "${RELATED_MEDIA_ITEMS}", relatedMediaSet );
00687 }

int RioXmlInput::findMediaItem ( QString  media_type  )  [private]

Definition at line 1004 of file RioXmlInput.cpp.

01005 {
01006     int item = 0;
01007 
01008     while( ( cbMediaList->text( item ) != media_type ) &&
01009            ( item < cbMediaList->count() ) )
01010         item++;
01011 
01012     return item;
01013 }

QPtrList< QListViewItem > RioXmlInput::getSelectedRelatedMedia ( void   )  [private]

Returns the selected related media.

Definition at line 474 of file RioXmlInput.cpp.

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 }

QString RioXmlInput::getXmlCode ( void   ) 

Returns the complete and correct XML code.

Definition at line 1018 of file RioXmlInput.cpp.

01019 {
01020     return xmlCode;
01021 }

void RioXmlInput::initialize ( void   )  [private]

Initialize interface.

Definition at line 103 of file RioXmlInput.cpp.

00104 {
00105     int line;
00106 
00107     // Set this widget's caption
00108     setCaption( tr( "RIO object properties" ) );
00109 
00110     widget = new QWidget( this );
00111 
00112     // Create grid Layouts
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     // Build fields layout
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     // Build related media layout
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     // Build buttons layout
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     // Join individual layouts
00244     mainLayout->addLayout( fieldLayout );
00245     mainLayout->addLayout( relatedMediaExternalLayout );
00246     mainLayout->addLayout( buttonLayout );
00247 
00248     // The widget must be as small as possible
00249     widget->setFixedSize( widget->minimumSizeHint() );
00250     setFixedSize( widget->minimumSizeHint() );
00251 
00252     // Setting Tab Order
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     // Connecting button signals to slots
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     // Pointer to RioQt
00313     rioQt = ((FileWindow *)parent())->getRioQt();
00314 }

bool RioXmlInput::isValidXml ( void   ) 

Returns true if the XML is in a valid format.

Definition at line 1026 of file RioXmlInput.cpp.

01027 {
01028     return is_valid_xml;
01029 }

void RioXmlInput::loadXmlFile ( void   )  [private, slot]

Asks user for a XML file and uses it to fill form fields.

Definition at line 888 of file RioXmlInput.cpp.

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         // Setup combobox and qlistview
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         // Fill XML form, keeping the MPEG file name and size
00910         fillXmlForm( fdXmlLoad.selectedFile(), true );
00911     }
00912 }

void RioXmlInput::processInput (  )  [private, slot]

Definition at line 693 of file RioXmlInput.cpp.

00694 {
00695     // Check data correctness
00696     if( verifyInput() )
00697     {
00698         fillXmlTemplate();
00699 
00700         accept();
00701     }
00702 }

void RioXmlInput::removeFromRelatedMediaList ( int  type  )  [private]

Removes media of a given type from relatedMediaList.

Definition at line 459 of file RioXmlInput.cpp.

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 }

void RioXmlInput::removeRelatedMedia (  )  [private, slot]

Remove selected media file from the list view and from the struct relatedMediaList.

Definition at line 416 of file RioXmlInput.cpp.

00417 {
00418     enableOKButton( "" );
00419 
00420     // Iterate on all selected items
00421     QPtrList<QListViewItem> selected_list = getSelectedRelatedMedia();
00422     for( unsigned int i = 0; i < selected_list.count(); i++ )
00423     {
00424         // Discover media type, insert option to readd it and remove
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 }

bool RioXmlInput::validateObjectDTD ( QString  file_name  )  [private]

Validates a file that is quite to be loaded against a DTD format specification.

Definition at line 918 of file RioXmlInput.cpp.

00919 {
00920     bool status = true;
00921 
00922     // Get directory where 'file_name' lives
00923     int index = file_name.findRev( '/' );
00924     QString directory = file_name.left( index );
00925 
00926     // Copy DTD template to file system
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     // Parse XML file against the dtd
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     // Remove DTD copy from filesystem and dispose memory
00975     dtd_file->remove();
00976     delete dtd_file;
00977 
00978     return status;
00979 }

bool RioXmlInput::verifyInput ( void   )  [private]

Verifies the user input if something is wrong shows a pop-up warnig.

Definition at line 494 of file RioXmlInput.cpp.

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 }


Field Documentation

QComboBox* RioXmlInput::cbMediaList [private]

Definition at line 55 of file RioXmlInput.h.

QComboBox* RioXmlInput::cbObjectType [private]

Definition at line 54 of file RioXmlInput.h.

QString RioXmlInput::fileName [private]

Definition at line 68 of file RioXmlInput.h.

bool RioXmlInput::is_valid_xml [private]

Definition at line 66 of file RioXmlInput.h.

QLineEdit* RioXmlInput::leBitrate [private]

Definition at line 48 of file RioXmlInput.h.

QLineEdit* RioXmlInput::leCourse [private]

Definition at line 44 of file RioXmlInput.h.

QLineEdit* RioXmlInput::leCourseCode [private]

Definition at line 51 of file RioXmlInput.h.

QLineEdit* RioXmlInput::leDuration [private]

Definition at line 49 of file RioXmlInput.h.

QLineEdit* RioXmlInput::leFileName [private]

Definition at line 50 of file RioXmlInput.h.

QLineEdit* RioXmlInput::leFileSize [private]

Definition at line 52 of file RioXmlInput.h.

QLineEdit* RioXmlInput::leGradProgram [private]

Definition at line 45 of file RioXmlInput.h.

QLineEdit* RioXmlInput::leProfessor [private]

Definition at line 43 of file RioXmlInput.h.

QLineEdit* RioXmlInput::leResolutionX [private]

Definition at line 47 of file RioXmlInput.h.

QLineEdit * RioXmlInput::leResolutionY [private]

Definition at line 47 of file RioXmlInput.h.

QLineEdit* RioXmlInput::leSource [private]

Definition at line 46 of file RioXmlInput.h.

QLineEdit* RioXmlInput::leTitle [private]

Definition at line 42 of file RioXmlInput.h.

QListView* RioXmlInput::lvRMList [private]

Definition at line 58 of file RioXmlInput.h.

QPushButton* RioXmlInput::pbAddMedia [private]

Definition at line 60 of file RioXmlInput.h.

QPushButton* RioXmlInput::pbOK [private]

Definition at line 62 of file RioXmlInput.h.

QPushButton* RioXmlInput::pbRemoveMedia [private]

Definition at line 61 of file RioXmlInput.h.

Definition at line 70 of file RioXmlInput.h.

Definition at line 39 of file RioXmlInput.h.

const int RioXmlInput::RM_TYPE_BROWSER = 0 [static]

Definition at line 93 of file RioXmlInput.h.

const int RioXmlInput::RM_TYPE_INDEX = 3 [static]

Definition at line 96 of file RioXmlInput.h.

const int RioXmlInput::RM_TYPE_SLIDES = 2 [static]

Definition at line 95 of file RioXmlInput.h.

const int RioXmlInput::RM_TYPE_TGIF = 1 [static]

Definition at line 94 of file RioXmlInput.h.

QWidget* RioXmlInput::widget [private]

Definition at line 57 of file RioXmlInput.h.

QString RioXmlInput::xmlCode [private]

Definition at line 65 of file RioXmlInput.h.


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