Skip to content

Commit cee27a7

Browse files
committed
add remove option, for now only the zip file
1 parent a6cbbf7 commit cee27a7

File tree

4 files changed

+91
-55
lines changed

4 files changed

+91
-55
lines changed

src/Controller.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ const InfoData Controller::getInfo(int id) {
142142
return model.getInfo(id);
143143
}
144144

145+
const bool Controller::deleteZip(int id) {
146+
return model.deleteZip(id);
147+
}
148+
145149
const QString Controller::getWalkthrough(int id) {
146150
return model.getWalkthrough(id);
147151
}

src/Controller.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Controller : public QObject {
4343
int checkGameDirectory(int id);
4444
void getList(QVector<QSharedPointer<ListItemData>>* list);
4545
const InfoData getInfo(int id);
46+
const bool deleteZip(int id);
4647
const QString getWalkthrough(int id);
4748
bool link(int id);
4849
int getItemState(int id);

src/Dialog.cpp

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,38 @@ Dialog::Dialog(QWidget *parent)
2323
m_buttonGroup(new QButtonGroup(this)),
2424
m_okButton(new QPushButton("OK", this))
2525
{
26-
m_layout->addWidget(m_label);
27-
m_layout->addWidget(m_optionContainer);
28-
m_layout->addWidget(m_okButton);
26+
// Remove or reduce spacing between widgets
27+
m_layout->setSpacing(4); // smaller space between widgets
28+
m_layout->setContentsMargins(10, 10, 10, 10);
2929

30+
// Add stretch to push content to vertical center
31+
m_layout->addStretch(1);
32+
33+
// Label (centered)
34+
m_label->setAlignment(Qt::AlignCenter);
35+
m_layout->addWidget(m_label, 0, Qt::AlignHCenter);
36+
37+
// Option container (centered and compact)
38+
m_optionLayout->setContentsMargins(0, 0, 0, 0);
39+
m_optionLayout->setSpacing(4);
40+
m_optionContainer->setLayout(m_optionLayout);
41+
m_layout->addWidget(m_optionContainer, 0, Qt::AlignHCenter);
42+
43+
// OK Button (centered, fixed width)
44+
m_okButton->setFixedWidth(80);
45+
m_layout->addWidget(m_okButton, 0, Qt::AlignHCenter);
46+
47+
m_layout->addStretch(1);
48+
49+
// Connect OK button
3050
connect(m_okButton, &QPushButton::clicked, this, [this]() {
3151
emit okClicked();
3252
});
3353
}
3454

3555
void Dialog::setMessage(const QString &text) {
3656
m_label->setText(text);
57+
this->adjustSize();
3758
}
3859

3960
void Dialog::setOptions(const QStringList &options) {
@@ -47,15 +68,19 @@ void Dialog::setOptions(const QStringList &options) {
4768

4869
if (options.isEmpty()) {
4970
m_optionContainer->hide();
50-
return;
71+
} else {
72+
m_optionContainer->show();
73+
for (quint64 i = 0; i < options.size(); i++) {
74+
QRadioButton *rb = new QRadioButton(options.at(i));
75+
if (i == 0) {
76+
rb->setChecked(true);
77+
}
78+
m_buttonGroup->addButton(rb);
79+
m_optionLayout->addWidget(rb);
80+
}
5181
}
5282

53-
m_optionContainer->show();
54-
for (const QString &opt : options) {
55-
QRadioButton *rb = new QRadioButton(opt);
56-
m_buttonGroup->addButton(rb);
57-
m_optionLayout->addWidget(rb);
58-
}
83+
this->adjustSize();
5984
}
6085

6186
QString Dialog::selectedOption() const {

src/TombRaiderLinuxLauncher.cpp

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "../src/globalTypes.hpp"
1616
#include "ui_TombRaiderLinuxLauncher.h"
1717
#include <QLineEdit>
18+
#include <qlogging.h>
1819

1920
TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
2021
: QMainWindow(parent) {
@@ -158,8 +159,15 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
158159
m_dialogWidget = new Dialog(ui->dialog);
159160
ui->verticalLayout_17->addWidget(m_dialogWidget);
160161
connect(m_dialogWidget, &Dialog::okClicked, this, [this]() {
161-
qDebug() << "OK clicked, selected:" << m_dialogWidget->selectedOption();
162-
// handle it here
162+
const QString selected = m_dialogWidget->selectedOption();
163+
qDebug() << "OK clicked, selected:" << selected;
164+
if (selected == "Remove zip file") {
165+
controller.deleteZip(levelListProxy->getLid(m_current));
166+
} else if (selected == "Remove Level") {
167+
// fileManager.removeFileOrDirectory(testLevel);
168+
}
169+
ui->stackedWidget->setCurrentWidget(
170+
ui->stackedWidget->findChild<QWidget*>("select"));
163171
});
164172

165173

@@ -245,6 +253,7 @@ void TombRaiderLinuxLauncher::generateList(const QList<int>& availableGames) {
245253
}
246254

247255
InstalledStatus TombRaiderLinuxLauncher::getInstalled() {
256+
// TODO: read from disk all the id.TRLE and Original.id directories.
248257
QStringList keys = g_settings.allKeys();
249258
InstalledStatus list;
250259
for (const auto &key : std::as_const(keys)) {
@@ -369,23 +378,25 @@ void TombRaiderLinuxLauncher::levelDirSelected(qint64 id) {
369378
int state = controller.getItemState(id);
370379
// Activate or deactivate pushbuttons based on the selected item
371380
qDebug() << "Selected: " << id << Qt::endl;
372-
// if state == 1 then only activate link button
373-
// if state == 2 then only activate link and info button
374-
// if state == 0 then only activate download button
381+
// if state == 0 We dont have (id).TRLE directory
382+
// if state == 1 We dont have Original.TR(id) directory
383+
// if state == 2 we have Original.TR(id) if id was negative or (id).TRLE
375384
// if state == -1 then de-activate all buttons
376-
377385
if (state == 1) {
378386
ui->pushButtonRun->setEnabled(true);
379387
ui->pushButtonInfo->setEnabled(false);
380-
ui->pushButtonDownload->setEnabled(false);
388+
ui->pushButtonDownload->setEnabled(true);
389+
ui->pushButtonDownload->setText("Remove");
381390
} else if (state == 2) {
382391
ui->pushButtonRun->setEnabled(true);
383392
ui->pushButtonInfo->setEnabled(true);
384-
ui->pushButtonDownload->setEnabled(false);
393+
ui->pushButtonDownload->setEnabled(true);
394+
ui->pushButtonDownload->setText("Remove");
385395
} else if (state == 0) {
386396
ui->pushButtonRun->setEnabled(false);
387397
ui->pushButtonInfo->setEnabled(true);
388398
ui->pushButtonDownload->setEnabled(true);
399+
ui->pushButtonDownload->setText("Download and install");
389400
} else {
390401
ui->pushButtonRun->setEnabled(false);
391402
ui->pushButtonInfo->setEnabled(false);
@@ -399,22 +410,8 @@ void TombRaiderLinuxLauncher::onCurrentItemChanged(
399410
m_current = levelListProxy->mapToSource(current);
400411
if (m_current.isValid()) {
401412
qint64 id = levelListProxy->getLid(m_current);
413+
levelDirSelected(id);
402414
ui->lcdNumberLevelID->display(QString::number(id));
403-
if (levelListProxy->getItemType(m_current)) { // its the original game
404-
if (levelListProxy->getInstalled(m_current)) {
405-
ui->pushButtonRun->setEnabled(true);
406-
ui->pushButtonDownload->setEnabled(false);
407-
ui->pushButtonDownload->setText("Remove");
408-
409-
} else {
410-
ui->pushButtonRun->setEnabled(false);
411-
ui->pushButtonDownload->setText("Download and install");
412-
ui->pushButtonDownload->setEnabled(true);
413-
}
414-
ui->pushButtonInfo->setEnabled(false);
415-
} else {
416-
levelDirSelected(id);
417-
}
418415
ui->lineEditEnvironmentVariables->setEnabled(true);
419416
ui->lineEditEnvironmentVariables->setText(
420417
g_settings.value(QString("level%1/EnvironmentVariables")
@@ -563,20 +560,36 @@ void TombRaiderLinuxLauncher::runningLevelDone() {
563560
void TombRaiderLinuxLauncher::downloadClicked() {
564561
if (m_current.isValid()) {
565562
qint64 id = levelListProxy->getLid(m_current);
566-
qDebug() << "void TombRaiderLinuxLauncher" <<
567-
"::downloadClicked() qint64 id: " << id;
568-
ui->listViewLevels->setEnabled(false);
569-
ui->groupBoxSearch->setEnabled(false);
570-
ui->groupBoxFilter->setEnabled(false);
571-
ui->groupBoxToggle->setEnabled(false);
572-
ui->groupBoxSort->setEnabled(false);
573-
ui->progressBar->setValue(0);
574-
ui->stackedWidgetBar->setCurrentWidget(
575-
ui->stackedWidgetBar->findChild<QWidget*>("progress"));
576-
if (levelListProxy->getItemType(m_current)) {
577-
controller.setupGame(id);
563+
int state = controller.getItemState(id);
564+
if (state > 0) {
565+
// TODO: add the ability to remove the level without its save files
566+
QString text(
567+
"Select what you want to remove.\n"
568+
"For now we can only remove the zip file.\n"
569+
);
570+
m_dialogWidget->setMessage(text);
571+
m_dialogWidget->setOptions(QStringList()
572+
<< "Remove zip file");
573+
574+
ui->stackedWidget->setCurrentWidget(
575+
ui->stackedWidget->findChild<QWidget*>("dialog"));
576+
578577
} else {
579-
controller.setupLevel(id);
578+
qDebug() << "void TombRaiderLinuxLauncher" <<
579+
"::downloadClicked() qint64 id: " << id;
580+
ui->listViewLevels->setEnabled(false);
581+
ui->groupBoxSearch->setEnabled(false);
582+
ui->groupBoxFilter->setEnabled(false);
583+
ui->groupBoxToggle->setEnabled(false);
584+
ui->groupBoxSort->setEnabled(false);
585+
ui->progressBar->setValue(0);
586+
ui->stackedWidgetBar->setCurrentWidget(
587+
ui->stackedWidgetBar->findChild<QWidget*>("progress"));
588+
if (levelListProxy->getItemType(m_current)) {
589+
controller.setupGame(id);
590+
} else {
591+
controller.setupLevel(id);
592+
}
580593
}
581594
}
582595
}
@@ -690,16 +703,10 @@ void TombRaiderLinuxLauncher::workTick() {
690703
g_settings.setValue(
691704
QString("installed/game%1").arg(id),
692705
"true");
693-
ui->pushButtonRun->setEnabled(true);
694-
ui->pushButtonInfo->setEnabled(false);
695-
ui->pushButtonDownload->setEnabled(false);
696706
} else {
697707
g_settings.setValue(
698708
QString("installed/level%1").arg(id),
699709
"true");
700-
ui->pushButtonRun->setEnabled(true);
701-
ui->pushButtonInfo->setEnabled(true);
702-
ui->pushButtonDownload->setEnabled(false);
703710
}
704711
ui->stackedWidgetBar->setCurrentWidget(
705712
ui->stackedWidgetBar->findChild<QWidget*>("navigate"));
@@ -708,6 +715,7 @@ void TombRaiderLinuxLauncher::workTick() {
708715
ui->groupBoxFilter->setEnabled(true);
709716
ui->groupBoxToggle->setEnabled(true);
710717
ui->groupBoxSort->setEnabled(true);
718+
levelDirSelected(id);
711719
}
712720
}
713721
}
@@ -783,15 +791,13 @@ void TombRaiderLinuxLauncher::LevelSaveClicked() {
783791
if (m_current.isValid()) {
784792
qint64 id = levelListProxy->getLid(m_current);
785793

786-
// settings.setValue(QString("level%1/CustomCommand")
787-
// .arg(id), ui->lineEditCustomCommand->text());
788-
789794
g_settings.setValue(QString("level%1/EnvironmentVariables")
790795
.arg(id), ui->lineEditEnvironmentVariables->text());
791796

792797
g_settings.setValue(QString("level%1/RunnerType")
793798
.arg(id), ui->comboBoxRunnerType->currentIndex());
794799
}
800+
ui->pushButtonRun->setText(ui->comboBoxRunnerType->currentText());
795801
}
796802

797803
void TombRaiderLinuxLauncher::LevelResetClicked() {

0 commit comments

Comments
 (0)