-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaddgamedialog.cpp
More file actions
114 lines (99 loc) · 3.17 KB
/
addgamedialog.cpp
File metadata and controls
114 lines (99 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "addgamedialog.h"
#include "ui_addgamedialog.h"
#include "fgame.h"
#include <QFileDialog>
#include <QMessageBox>
#include "fdb.h"
#include "flauncher.h"
AddGameDialog::AddGameDialog(QWidget *parent, QList<FLauncher> *launchers) :
QDialog(parent),
ui(new Ui::AddGameDialog)
{
this->launchers = launchers;
if(launchers == 0)
{
return;
}
ui->setupUi(this);
game = FGame();
if(launchers->length() > 0)
{
launchersAvailable = true;
for(int i = 0; i < launchers->length(); i++)
{
FLauncher launcher = launchers->at(i);
ui->launcherComboBox->addItem(launcher.getName(), QVariant(i));
qDebug() << "Name:" << launcher.getName();
}
}
}
AddGameDialog::~AddGameDialog()
{
delete ui;
}
void AddGameDialog::on_chooseGameDirButton_clicked()
{
QDir gameDir = QFileDialog::getExistingDirectory(this, tr("Choose the game directory"), QDir::homePath());
game.setPath(gameDir.absolutePath());
ui->gameDirLabel->setText(gameDir.absolutePath());
}
void AddGameDialog::on_chooseGameExecutableButton_clicked()
{
QString file;
QDir gameDir = QDir(game.getPath());
file = QFileDialog::getOpenFileName(this, tr("Choose executable"), gameDir.absolutePath());
if(file.isEmpty())
return;
file = gameDir.relativeFilePath(file);
game.setExe(file);
ui->gameExecutableLabel->setText(file);
}
void AddGameDialog::on_buttonBox_accepted()
{
if(ui->gameNameEdit->text().isEmpty()
|| game.getPath().isEmpty()
|| game.getExe().isEmpty())
{
return;
}
game.setName(ui->gameNameEdit->text());
if(game.getName().length() <= 0) {
QMessageBox::warning(this, tr("Please fill all fields!"), tr("You have to fill the name-field!"), QMessageBox::Ok);
return;
}
if(game.getExe().length() <= 0) {
QMessageBox::warning(this, tr("Please fill all fields!"), tr("You have to set an executable!"), QMessageBox::Ok);
return;
}
if(game.getPath().length() <= 0) {
QMessageBox::warning(this, tr("Please fill all fields!"), tr("You have to set a path!"), QMessageBox::Ok);
return;
}
game.setCommand(ui->gameCommandEdit->text());
game.setArgs(QStringList(ui->gameArgsEdit->text()));
game.setType(Executable);
if(ui->launcherEnabledCheckBox->isChecked())
{
if ((ui->launcherComboBox->itemText(ui->launcherComboBox->currentIndex()).isEmpty()) || (ui->launcherComboBox->itemText(ui->launcherComboBox->currentIndex()).isNull()))
{
ui->launcherEnabledCheckBox->setChecked(false);
}
else
{
game.setLauncher(launchers->at(ui->launcherComboBox->itemData(ui->launcherComboBox->currentIndex()).toInt()));
}
}
emit AddGameDialog::gameSet(game);
close();
}
void AddGameDialog::on_gameCommandBrowse_clicked()
{
QString command = QFileDialog::getOpenFileName(this, tr("Choose command"));
if(command.isEmpty())
return;
ui->gameCommandEdit->setText(command);
}
void AddGameDialog::on_launcherEnabledCheckBox_clicked()
{
ui->launcherComboBox->setEnabled(ui->launcherEnabledCheckBox->isChecked());
}