| 1 | #include "soundpage2.h" | 
 
 
 
 
 | 2 | #include "ui_soundpage2.h" | 
 
 
 
 
 | 3 |  | 
 
 
 
 
 | 4 | const QStringList SoundPage2::allowedFiles = QStringList() << "*.wav" <<  "*.aif" <<  "*.aifc" << "*.afc"; | 
 
 
 
 
 | 5 | const QString SoundPage2::codecLocalHelpFile=GlobalVars::HelpLocation + "/XMLSNDD.html#Source_file_creation"; | 
 
 
 
 
 | 6 |  | 
 
 
 
 
 | 7 | SoundPage2::SoundPage2(QWidget *parent) : | 
 
 
 
 
 | 8 | QWizardPage(parent), | 
 
 
 
 
 | 9 | ui(new Ui::soundpage2) | 
 
 
 
 
 | 10 | { | 
 
 
 
 
 | 11 | ui->setupUi(this); | 
 
 
 
 
 | 12 | this->soundTable=ui->twSoundFiles; | 
 
 
 
 
 | 13 | ui->twSoundFiles->removeColumn(2); // Only two columns | 
 
 
 
 
 | 14 |  | 
 
 
 
 
 | 15 | // Drop signal for Packages table | 
 
 
 
 
 | 16 | connect(ui->twSoundFiles, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addResourcesSounds(DropTableWidget*,QStringList))); | 
 
 
 
 
 | 17 | // Signal for click in label (display local help) | 
 
 
 
 
 | 18 | connect(ui->label, SIGNAL(linkActivated(const QString & )), this, SLOT(openCodecLocalHelp())); | 
 
 
 
 
 | 19 |  | 
 
 
 
 
 | 20 | //Register fields to be accessible in another pages | 
 
 
 
 
 | 21 | registerField("rbOther", ui->rbOther); | 
 
 
 
 
 | 22 | registerField("leOtherLocation", ui->leOtherLocation); | 
 
 
 
 
 | 23 | } | 
 
 
 
 
 | 24 |  | 
 
 
 
 
 | 25 | SoundPage2::~SoundPage2() | 
 
 
 
 
 | 26 | { | 
 
 
 
 
 | 27 | delete ui; | 
 
 
 
 
 | 28 | } | 
 
 
 
 
 | 29 |  | 
 
 
 
 
 | 30 | void SoundPage2::on_rbOther_toggled(bool checked) | 
 
 
 
 
 | 31 | { | 
 
 
 
 
 | 32 | if(checked){ | 
 
 
 
 
 | 33 | ui->leOtherLocation->setEnabled(true); | 
 
 
 
 
 | 34 | ui->pbBrowserOtherLocation->setEnabled(true); | 
 
 
 
 
 | 35 | return; | 
 
 
 
 
 | 36 | } | 
 
 
 
 
 | 37 |  | 
 
 
 
 
 | 38 | ui->leOtherLocation->setEnabled(false); | 
 
 
 
 
 | 39 | ui->pbBrowserOtherLocation->setEnabled(false); | 
 
 
 
 
 | 40 | } | 
 
 
 
 
 | 41 |  | 
 
 
 
 
 | 42 | void SoundPage2::on_tbAddFiles_clicked() | 
 
 
 
 
 | 43 | { | 
 
 
 
 
 | 44 | addResourcesSounds(ui->twSoundFiles,QFileDialog::getOpenFileNames(this,"Choose the sound files...","./" , "Audio (" + this->allowedFiles.join(" ") + ")")); | 
 
 
 
 
 | 45 | } | 
 
 
 
 
 | 46 |  | 
 
 
 
 
 | 47 | void SoundPage2::on_tbRemoveFiles_clicked() | 
 
 
 
 
 | 48 | { | 
 
 
 
 
 | 49 | int size = ui->twSoundFiles->selectionModel()->selectedRows().size(); | 
 
 
 
 
 | 50 |  | 
 
 
 
 
 | 51 | if(size==0){ | 
 
 
 
 
 | 52 | Util::showPopUp("Select a row first."); | 
 
 
 
 
 | 53 | return; | 
 
 
 
 
 | 54 | } | 
 
 
 
 
 | 55 |  | 
 
 
 
 
 | 56 | if(Util::showQuestionPopUp(this,"Are you sure you want to delete the selected rows?")){ | 
 
 
 
 
 | 57 | for(int i=0; i<size; i++){ | 
 
 
 
 
 | 58 | ui->twSoundFiles->removeRow(ui->twSoundFiles->selectionModel()->selectedRows().at(size-i-1).row()); | 
 
 
 
 
 | 59 | } | 
 
 
 
 
 | 60 | } | 
 
 
 
 
 | 61 | } | 
 
 
 
 
 | 62 |  | 
 
 
 
 
 | 63 | void SoundPage2::addResourcesSounds(DropTableWidget *myTable, QStringList resources){ | 
 
 
 
 
 | 64 |  | 
 
 
 
 
 | 65 | bool fileExtValid=false; | 
 
 
 
 
 | 66 |  | 
 
 
 
 
 | 67 | //Pre-processing (check if received only folders) | 
 
 
 
 
 | 68 | foreach(QString myFile, resources){ | 
 
 
 
 
 | 69 | QString currFileExt=QFileInfo(myFile).completeSuffix(); | 
 
 
 
 
 | 70 | if(QDir(myFile).exists()){ | 
 
 
 
 
 | 71 | Util::showErrorPopUp("Only files are allowed for this operation."); | 
 
 
 
 
 | 72 | return; | 
 
 
 
 
 | 73 | } | 
 
 
 
 
 | 74 |  | 
 
 
 
 
 | 75 | foreach(QString vext, this->allowedFiles){ | 
 
 
 
 
 | 76 | vext.remove("*."); | 
 
 
 
 
 | 77 | if(vext==currFileExt){ | 
 
 
 
 
 | 78 | fileExtValid=true; | 
 
 
 
 
 | 79 | break; | 
 
 
 
 
 | 80 | } | 
 
 
 
 
 | 81 | } | 
 
 
 
 
 | 82 |  | 
 
 
 
 
 | 83 | if(!fileExtValid){ | 
 
 
 
 
 | 84 | Util::showErrorPopUp("Files must be in the follow formats:\n" + | 
 
 
 
 
 | 85 | this->allowedFiles.join(" ")); | 
 
 
 
 
 | 86 | return; | 
 
 
 
 
 | 87 | } | 
 
 
 
 
 | 88 | } | 
 
 
 
 
 | 89 |  | 
 
 
 
 
 | 90 | foreach(QString currentFile, resources){ | 
 
 
 
 
 | 91 |  | 
 
 
 
 
 | 92 | //Get actual number rows | 
 
 
 
 
 | 93 | int twSize=myTable->rowCount(); | 
 
 
 
 
 | 94 |  | 
 
 
 
 
 | 95 | //increase the rows for the new item | 
 
 
 
 
 | 96 | myTable->setRowCount(twSize+1); | 
 
 
 
 
 | 97 |  | 
 
 
 
 
 | 98 | //Add to table and list to | 
 
 
 
 
 | 99 | QTableWidgetItem *newName = new QTableWidgetItem(QFileInfo(currentFile).baseName()); | 
 
 
 
 
 | 100 | QTableWidgetItem *newFileLocation = new QTableWidgetItem(Util::normalizePath(currentFile)); | 
 
 
 
 
 | 101 |  | 
 
 
 
 
 | 102 | myTable->setItem(twSize,0,newName); | 
 
 
 
 
 | 103 | myTable->setItem(twSize,1,newFileLocation); | 
 
 
 
 
 | 104 | myTable->updateTableToolTips(twSize); //Update tool tips | 
 
 
 
 
 | 105 | } | 
 
 
 
 
 | 106 | } | 
 
 
 
 
 | 107 |  | 
 
 
 
 
 | 108 | void SoundPage2::on_pbBrowserOtherLocation_clicked() | 
 
 
 
 
 | 109 | { | 
 
 
 
 
 | 110 | ui->leOtherLocation->setText(QFileDialog::getExistingDirectory(this,"Choose output folder...")); | 
 
 
 
 
 | 111 | } | 
 
 
 
 
 | 112 |  | 
 
 
 
 
 | 113 | void SoundPage2::openCodecLocalHelp(){ | 
 
 
 
 
 | 114 | QDesktopServices::openUrl(QUrl("file:///"+this->codecLocalHelpFile)); | 
 
 
 
 
 | 115 | } | 
 
 
 
 
 | 116 |  | 
 
 
 
 
 | 117 | bool SoundPage2::validatePage(){ | 
 
 
 
 
 | 118 |  | 
 
 
 
 
 | 119 | QStringList namesList; | 
 
 
 
 
 | 120 |  | 
 
 
 
 
 | 121 | if(ui->twSoundFiles->rowCount()==0){ | 
 
 
 
 
 | 122 | Util::showErrorPopUp("You need to add some sound files first!"); | 
 
 
 
 
 | 123 | return false; | 
 
 
 
 
 | 124 | } | 
 
 
 
 
 | 125 |  | 
 
 
 
 
 | 126 | for(int i=0; i<ui->twSoundFiles->rowCount(); i++){ | 
 
 
 
 
 | 127 | namesList << ui->twSoundFiles->item(i,0)->text(); | 
 
 
 
 
 | 128 | } | 
 
 
 
 
 | 129 |  | 
 
 
 
 
 | 130 | if(ui->rbOther->isChecked() && Util::checkEmptySpaces(QStringList() << ui->leOtherLocation->text())){ | 
 
 
 
 
 | 131 | Util::showErrorPopUp("Please input a directory to output the files."); | 
 
 
 
 
 | 132 | return false; | 
 
 
 
 
 | 133 | } | 
 
 
 
 
 | 134 |  | 
 
 
 
 
 | 135 | if(ui->rbOther->isChecked() && !QDir(ui->leOtherLocation->text()).exists()){ | 
 
 
 
 
 | 136 | Util::showErrorPopUp("Invalid directory specified in other location. Please fix it."); | 
 
 
 
 
 | 137 | return false; | 
 
 
 
 
 | 138 | } | 
 
 
 
 
 | 139 |  | 
 
 
 
 
 | 140 | return true; | 
 
 
 
 
 | 141 | } |