Improved saving of new profiles.

This commit is contained in:
LoRd_MuldeR 2012-02-02 18:55:55 +01:00
parent c7d9019870
commit 0d22776128
5 changed files with 87 additions and 49 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@
/*.sdf
/*.suo
/*.user
/*.opensdf

View File

@ -82,7 +82,7 @@ bool OptionsModel::saveTemplate(OptionsModel *model, const QString &name)
const QString templateName = name.simplified();
const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
if(templateName.startsWith("<") || templateName.endsWith(">") || templateName.contains("\\") || templateName.contains("/"))
if(templateName.contains('<') || templateName.contains('>') || templateName.contains('\\') || templateName.contains('/'))
{
return false;
}

View File

@ -53,6 +53,21 @@ g_filters[] =
#define VALID_DIR(PATH) ((!(PATH).isEmpty()) && QFileInfo(PATH).exists() && QFileInfo(PATH).isDir())
#define REMOVE_USAFED_ITEM \
{ \
for(int i = 0; i < cbxTemplate->count(); i++) \
{ \
OptionsModel* temp = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(i).value<void*>()); \
if(temp == NULL) \
{ \
cbxTemplate->blockSignals(true); \
cbxTemplate->removeItem(i); \
cbxTemplate->blockSignals(false); \
break; \
} \
} \
}
///////////////////////////////////////////////////////////////////////////////
// Validator
///////////////////////////////////////////////////////////////////////////////
@ -333,17 +348,7 @@ void AddJobDialog::templateSelected(void)
if(options)
{
qDebug("Loading options!");
for(int i = 0; i < cbxTemplate->model()->rowCount(); i++)
{
OptionsModel* temp = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(i).value<void*>());
if(temp == NULL)
{
cbxTemplate->blockSignals(true);
cbxTemplate->removeItem(i);
cbxTemplate->blockSignals(false);
break;
}
}
REMOVE_USAFED_ITEM;
restoreOptions(options);
}
@ -355,16 +360,56 @@ void AddJobDialog::saveTemplateButtonClicked(void)
qDebug("Saving template");
QString name = tr("New Template");
OptionsModel *options = new OptionsModel();
saveOptions(options);
if(options->equals(m_defaults))
{
QMessageBox::warning (this, tr("Default"), tr("It makes no sense to save the defaults!"));
cbxTemplate->blockSignals(true);
cbxTemplate->setCurrentIndex(0);
cbxTemplate->blockSignals(false);
REMOVE_USAFED_ITEM;
X264_DELETE(options);
return;
}
for(int i = 0; i < cbxTemplate->count(); i++)
{
OptionsModel* test = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(i).value<void*>());
if(test != NULL)
{
if(options->equals(test))
{
QMessageBox::warning (this, tr("Oups"), tr("<nobr>There already is a template for the current settings!"));
cbxTemplate->blockSignals(true);
cbxTemplate->setCurrentIndex(i);
cbxTemplate->blockSignals(false);
REMOVE_USAFED_ITEM;
X264_DELETE(options);
return;
}
}
}
forever
{
bool ok = false;
name = QInputDialog::getText(this, tr("Save Template"), tr("Please enter the name of the template:").leftJustified(160, ' '), QLineEdit::Normal, name, &ok).simplified();
if(!ok) return;
if(name.startsWith("<") || name.endsWith(">"))
if(!ok)
{
X264_DELETE(options);
return;
}
if(name.contains('<') || name.contains('>') || name.contains('\\') || name.contains('/') || name.contains('"'))
{
QMessageBox::warning (this, tr("Invalid Name"), tr("Sorry, the name you have entered is invalid!"));
while(name.startsWith("<")) name = name.mid(1).trimmed();
while(name.endsWith(">")) name = name.left(name.size() - 1).trimmed();
while(name.contains('<')) name.remove('<');
while(name.contains('>')) name.remove('>');
while(name.contains('\\')) name.remove('\\');
while(name.contains('/')) name.remove('/');
while(name.contains('"')) name.remove('"');
name = name.simplified();
continue;
}
if(OptionsModel::templateExists(name))
@ -374,19 +419,10 @@ void AddJobDialog::saveTemplateButtonClicked(void)
}
break;
}
OptionsModel *options = new OptionsModel();
saveOptions(options);
if(options->equals(m_defaults))
{
QMessageBox::warning (this, tr("Default"), tr("It makes no sense to save the defaults!"));
X264_DELETE(options);
return;
}
if(!OptionsModel::saveTemplate(options, name))
{
QMessageBox::warning (this, tr("Save Failed"), tr("Sorry, the template could not be used!"));
QMessageBox::critical(this, tr("Save Failed"), tr("Sorry, the template could not be saved!"));
X264_DELETE(options);
return;
}
@ -395,16 +431,9 @@ void AddJobDialog::saveTemplateButtonClicked(void)
cbxTemplate->blockSignals(true);
cbxTemplate->insertItem(index, name, QVariant::fromValue<void*>(options));
cbxTemplate->setCurrentIndex(index);
for(int i = 0; i < cbxTemplate->model()->rowCount(); i++)
{
OptionsModel* temp = reinterpret_cast<OptionsModel*>(cbxTemplate->itemData(i).value<void*>());
if(temp == NULL)
{
cbxTemplate->removeItem(i);
break;
}
}
cbxTemplate->blockSignals(false);
REMOVE_USAFED_ITEM;
}
void AddJobDialog::deleteTemplateButtonClicked(void)
@ -412,7 +441,7 @@ void AddJobDialog::deleteTemplateButtonClicked(void)
const int index = cbxTemplate->currentIndex();
QString name = cbxTemplate->itemText(index);
if(name.startsWith("<") || name.endsWith(">"))
if(name.contains('<') || name.contains('>'))
{
QMessageBox::warning (this, tr("Invalid Item"), tr("Sorry, the selected item cannot be deleted!"));
return;

View File

@ -140,8 +140,10 @@ MainWindow::~MainWindow(void)
// Slots
///////////////////////////////////////////////////////////////////////////////
void MainWindow::addButtonPressed(const QString &filePath)
void MainWindow::addButtonPressed(const QString &filePath, bool *ok)
{
if(ok) *ok = false;
AddJobDialog *addDialog = new AddJobDialog(this, m_options);
addDialog->setRunImmediately(!havePendingJobs());
if(!filePath.isEmpty()) addDialog->setSourceFile(filePath);
@ -161,14 +163,18 @@ void MainWindow::addButtonPressed(const QString &filePath)
QModelIndex newIndex = m_jobList->insertJob(thrd);
if(addDialog->runImmediately())
if(newIndex.isValid())
{
jobsView->selectRow(newIndex.row());
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
m_jobList->startJob(newIndex);
}
if(addDialog->runImmediately())
{
jobsView->selectRow(newIndex.row());
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
m_jobList->startJob(newIndex);
}
m_label->setVisible(false);
m_label->setVisible(false);
if(ok) *ok = true;
}
}
X264_DELETE(addDialog);
@ -279,7 +285,7 @@ void MainWindow::showAbout(void)
forever
{
int ret = QMessageBox::information(this, tr("About..."), text.replace("-", "&minus;"), tr("Abou x264"), tr("About Qt"), tr("Close"));
int ret = QMessageBox::information(this, tr("About..."), text.replace("-", "&minus;"), tr("About x264"), tr("About Qt"), tr("Close"));
switch(ret)
{
@ -289,7 +295,7 @@ void MainWindow::showAbout(void)
text2 += tr("<nobr><tt>x264, the best H.264/AVC encoder. Copyright (c) 2003-2011 x264 project.<br>");
text2 += tr("Free software library for encoding video streams into the H.264/MPEG-4 AVC format.<br>");
text2 += tr("Released under the terms of the GNU General Public License.<br><br>");
text2 += tr("Please visit <a href=\"http://x264licensing.com/\">http://x264licensing.com/</a> for obtaining a commercial x264 license!<br></tt></nobr>");
text2 += tr("Please visit <a href=\"http://x264licensing.com/\">http://x264licensing.com/</a> for obtaining a <u>commercial</u> x264 license!<br></tt></nobr>");
QMessageBox::information(this, tr("About x264"), text2.replace("-", "&minus;"), tr("Close"));
}
break;
@ -349,6 +355,7 @@ void MainWindow::init(void)
//Check all binaries
while(!binaries.isEmpty())
{
qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
QString current = binaries.takeFirst();
QFile *file = new QFile(QString("%1/toolset/%2").arg(m_appDir, current));
if(file->open(QIODevice::ReadOnly))
@ -508,12 +515,13 @@ void MainWindow::dropEvent(QDropEvent *event)
}
droppedFiles.sort();
while(!droppedFiles.isEmpty())
bool ok = true;
while((!droppedFiles.isEmpty()) && ok)
{
QString currentFile = droppedFiles.takeFirst();
qDebug("Adding file: %s", currentFile.toUtf8().constData());
addButtonPressed(currentFile);
addButtonPressed(currentFile, &ok);
}
}

View File

@ -59,7 +59,7 @@ private:
bool havePendingJobs(void);
private slots:
void addButtonPressed(const QString &filePath = QString());
void addButtonPressed(const QString &filePath = QString(), bool *ok = NULL);
void abortButtonPressed(void);
void copyLogToClipboard(bool checked);
void init(void);