Skip to content

Commit

Permalink
Adds reset button, autofill split output directory, makes merge songdir
Browse files Browse the repository at this point in the history
line edit writeable, fixes reported crash, and fixes folder picker on
win32.
This commit fixes #1 and fixes #2.
  • Loading branch information
InspectorConstructor committed Aug 27, 2019
1 parent 743b9eb commit 9213228
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 83 deletions.
72 changes: 41 additions & 31 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ MainWindow::MainWindow(QWidget *parent) :
m_split_sav(nullptr)
{
ui->setupUi(this);
ui->testButton->setHidden(true);
ui->toolBar->setHidden(true);

// make the lemon work
// todo: use statusBar to indicate status
// ui->statusBar->showMessage("welcome", 5000);

// make the lemon
QPixmap bkgnd(":/images/lemon.jpg");
bkgnd = bkgnd.scaled(ui->lemon->size(), Qt::KeepAspectRatio);
ui->lemon->setPixmap(bkgnd);

resetSplit();
resetMerge();
updateSplitEnables();
updateMergeEnables();
toHome();
}

MainWindow::~MainWindow()
Expand All @@ -42,17 +44,20 @@ MainWindow::~MainWindow()
void MainWindow::toHome()
{
ui->stackedWidget->setCurrentIndex(0);
ui->resetButton->setEnabled(false);
}

void MainWindow::toSplit()
{
ui->resetButton->setEnabled(true);
resetSplit();
updateSplitEnables();
ui->stackedWidget->setCurrentIndex(1);
}

void MainWindow::toMerge()
{
ui->resetButton->setEnabled(true);
resetMerge();
updateMergeEnables();
ui->stackedWidget->setCurrentIndex(2);
Expand Down Expand Up @@ -107,8 +112,13 @@ void MainWindow::updateSplitEnables()

void MainWindow::updateMergeEnables()
{
bool en = QFile::exists(ui->mergeDirectoryLine->text());
en = en && !ui->mergeFileView->selectionModel()->selectedIndexes().empty();
bool en = false;
if (QFile::exists(ui->mergeDirectoryLine->text()))
{
auto model_p = ui->mergeFileView->selectionModel();
if (model_p != nullptr)
en = !model_p->selectedIndexes().empty();
}
ui->doMergeButton->setEnabled(en);
}

Expand Down Expand Up @@ -157,23 +167,18 @@ void MainWindow::mergeSongs(QStringList &songFiles)
}

// SUCCESS
// QFileDialog dialog(this);
// dialog.setFileMode(QFileDialog::AnyFile);
//if (dialog.exec())
{
QString selected = QFileDialog::getSaveFileName(this, "Name your new .sav file", QString(), "*.sav");
QString selected = QFileDialog::getSaveFileName(this, "Name your new .sav file", QString(), "*.sav");

if (selected.isEmpty())
return;
if (selected.isEmpty())
return;

// dialog.selectedFiles().first();
lsdj_sav_write_to_file(sav, selected.toLocal8Bit(), &err);
if (lsdj_check_err(err))
return;
// dialog.selectedFiles().first();
lsdj_sav_write_to_file(sav, selected.toLocal8Bit(), &err);
if (lsdj_check_err(err))
return;

QMessageBox::information(this, "Merge Success", "Successfully merged " +
QString::number(i) + " .lsdsng files!");
}
QMessageBox::information(this, "Merge Success", "Successfully merged " +
QString::number(i) + " .lsdsng files!");
}

void MainWindow::on_toSplitButton_clicked()
Expand All @@ -189,6 +194,7 @@ void MainWindow::on_toMergeButton_clicked()
void MainWindow::on_selectMergeDirectoryButton_clicked()
{
QFileDialog d(this);
d.setFileMode(QFileDialog::Directory);

d.setOption(QFileDialog::ShowDirsOnly, true);

Expand All @@ -199,10 +205,9 @@ void MainWindow::on_selectMergeDirectoryButton_clicked()

if (QFile::exists(outputPath)) // extra safe!
{
//m_model = new QFileSystemModel(ui->mergeFileView);
ui->mergeFileView->setEnabled(true);
ui->mergeFileView->setModel(m_model);
m_model->setFilter(QDir::Files /*| QDir::AllDirs*/ );
m_model->setFilter(QDir::Files);
m_model->setReadOnly(true);
m_model->setRootPath(outputPath);
m_model->setNameFilterDisables(false); // true shows disabled files, false hides 'em.
Expand Down Expand Up @@ -257,12 +262,9 @@ void MainWindow::on_mergeFileView_clicked(const QModelIndex &index)
; */
}

void MainWindow::on_testButton_clicked()
void MainWindow::on_resetButton_clicked()
{
QFileDialog dialog;
dialog.setFileMode(QFileDialog::ExistingFiles);
dialog.setNameFilter("*.lsdsng");
dialog.exec();
toHome();
}

void MainWindow::on_splitSelectSavButton_clicked()
Expand All @@ -278,11 +280,11 @@ void MainWindow::on_splitSelectSavButton_clicked()

void MainWindow::on_splitSavLine_textChanged(const QString &arg1)
{
Q_UNUSED(arg1)
ui->splitSongList->clear();
updateSplitEnables();

if (QFile::exists(arg1))
QFileInfo savFile(arg1);
if (savFile.exists())
{
lsdj_error_t *err = nullptr;
m_split_sav = lsdj_sav_read_from_file(arg1.toLocal8Bit(), &err);
Expand Down Expand Up @@ -322,6 +324,9 @@ void MainWindow::on_splitSavLine_textChanged(const QString &arg1)

ui->splitSongList->focusWidget();
}

if (ui->splitSelectOutputLine->text().isEmpty())
ui->splitSelectOutputLine->setText(savFile.path());
}
}
}
Expand Down Expand Up @@ -398,10 +403,15 @@ void MainWindow::on_doSplitButton_clicked()
break;
}
}

if (success)
QMessageBox::information(this, "Split Success", "Successfully created " + QString::number(selected.length()) + " .lsdsng files.");
QMessageBox::information(this, "Split Success", "Successfully created "
+ QString::number(selected.length())
+ " .lsdsng files.");
else
QMessageBox::information(this, "Split Failure", "Split failed after creating " + QString::number(i) + " .lsdsng files.");
QMessageBox::information(this, "Split Failure", "Split failed after creating "
+ QString::number(i)
+ " .lsdsng files.");
}

void MainWindow::on_splitSongList_itemSelectionChanged()
Expand Down
2 changes: 1 addition & 1 deletion mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private slots:

void on_mergeFileView_clicked(const QModelIndex &index);

void on_testButton_clicked();
void on_resetButton_clicked();

void on_splitSelectSavButton_clicked();

Expand Down
102 changes: 51 additions & 51 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,69 @@
<string>SpreadMechanism</string>
</property>
<widget class="QWidget" name="centralWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
<width>320</width>
<height>220</height>
</size>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="verticalSpacing">
<number>12</number>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="resetButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="homePage">
<layout class="QGridLayout" name="gridLayout_2">
<item row="5" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="lemon">
<item row="3" column="0">
<widget class="QPushButton" name="toSplitButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>80</height>
<height>100</height>
</size>
</property>
<property name="text">
<string>welcome</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<string>Split .sav file</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="toSplitButton">
<property name="minimumSize">
<item row="4" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>100</height>
<width>20</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>Split .sav file</string>
</property>
</widget>
</spacer>
</item>
<item row="3" column="0" colspan="2">
<item row="2" column="0" colspan="2">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -99,23 +102,32 @@
</property>
</spacer>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="toMergeButton">
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="lemon">
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
<height>80</height>
</size>
</property>
<property name="text">
<string>Merge .lsdsng files</string>
<string>welcome</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="testButton">
<item row="3" column="1">
<widget class="QPushButton" name="toMergeButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="text">
<string>test</string>
<string>Merge .lsdsng files</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -198,9 +210,6 @@
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="mergeDirectoryLine">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Press Select Directory and choose a folder!</string>
</property>
Expand Down Expand Up @@ -254,15 +263,6 @@
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionHome"/>
<addaction name="actionSplit"/>
<addaction name="actionMerge"/>
</widget>
<addaction name="menuFile"/>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
Expand Down

0 comments on commit 9213228

Please sign in to comment.