source: s10k/Vago/soundWizard/soundpage2.cpp@ 1174

Last change on this file since 1174 was 1093, checked in by s10k, 7 years ago

Vago 1.4

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