-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgameinfodialog.cpp
246 lines (195 loc) · 7.69 KB
/
gameinfodialog.cpp
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#include "gameinfodialog.h"
#include "ui_gameinfodialog.h"
#include "gamedbartselectordialog.h"
#include <fartmanager.h>
#include <QMessageBox>
#include <QFileDialog>
#include <QDesktopServices>
#include <QFileInfo>
#include <fdb.h>
GameInfoDialog::GameInfoDialog(FGame *g, FDB *database, QWidget *parent) :
QDialog(parent),
ui(new Ui::GameInfoDialog)
{
ui->setupUi(this);
game = g;
this->db = database;
ui->le_Title->setText(game->getName());
ui->le_Exec->setText(game->getExe());
ui->le_Directory->setText(game->getPath());
ui->le_Type->setText(FGame::FGameTypeToStr(game->getType()));
QString args;
for(int i=0;i<game->getArgs().length();++i)
args += " " + game->getArgs()[i];
ui->le_Params->setText(args);
runningDownloads = 0;
totalDownloads = 0;
lastDir = "/";
ui->aw_la_Cover->setStyleSheet("#aw_la_Cover{border-image:url("+ game->getArt(FArtBox) +") 0 0 0 0 stretch stretch}");
ui->aw_la_Banner->setStyleSheet("#aw_la_Banner{border-image:url("+ game->getArt(FArtBanner) +") 0 0 0 0 repeat stretch}");
ui->aw_la_Clearart->setStyleSheet("#aw_la_Clearart{border-image:url("+ game->getArt(FArtClearart) +") 0 0 0 0 stretch stretch}");
ui->aw_la_Fanart->setStyleSheet("#aw_la_Fanart{border-image:url("+ game->getArt(FArtFanart) +") 0 0 0 0 stretch stretch}");
QList<FLauncher> launchers = db->getLaunchers();
for(int i = 0; i < launchers.length(); i++)
{
FLauncher launcher = launchers.at(i);
ui->launcherComboBox->addItem(launcher.getName(), QVariant(launcher.getDbId()));
}
if(game->doesUseLauncher())
{
qDebug() << "Current launcher:" << game->getLauncher().getName() << ", id:" << game->getLauncher().getDbId();
qDebug() << "Game is using launcher.";
ui->launcherCheckBox->setChecked(true);
ui->launcherComboBox->setEnabled(true);
ui->launcherComboBox->setCurrentIndex(game->getLauncher().getDbId()-1);
}
//Savegame-Sync
/*
if(game->savegameSyncEndabled()) {
ui->cb_useSavegameSync->setChecked(true);
ui->le_savegameDir->setEnabled(true);
ui->le_savegameDir->setText(game->getSavegameDir().absolutePath());
ui->pb_setSavegameDir->setEnabled(true);
}
else {
ui->cb_useSavegameSync->setChecked(false);
ui->le_savegameDir->setEnabled(false);
ui->pb_setSavegameDir->setEnabled(false);
}
*/
}
void GameInfoDialog::on_chooseGameDirButton_clicked()
{
QDir gameDir = QFileDialog::getExistingDirectory(this, tr("Choose the game directory"), ui->le_Directory->text());
if(gameDir.dirName()!=".")
ui->le_Directory->setText(gameDir.absolutePath());
}
void GameInfoDialog::on_pb_deleteGame_clicked()
{
QMessageBox::StandardButton btn = QMessageBox::warning(this, tr("Really delete game?"), tr("Are you sure you want to delete") + "\"" + game->getName() + "\"?", QMessageBox::Yes|QMessageBox::No);
if(btn == QMessageBox::Yes) {
db->removeGameById(game->dbId);
emit reloadRequired();
this->close();
}
}
void GameInfoDialog::on_chooseGameExecutableButton_clicked()
{
QString file;
QDir gameDir = QDir(ui->le_Directory->text());
file = QFileDialog::getOpenFileName(this, tr("Choose executable"), gameDir.absolutePath());
if(file.isEmpty())
return;
file = gameDir.relativeFilePath(file);
ui->le_Exec->setText(file);
}
GameInfoDialog::~GameInfoDialog()
{
delete ui;
}
void GameInfoDialog::on_downloadArtButton_clicked()
{
FArtManager *artmanager = new FArtManager();
connect(artmanager, SIGNAL(startedDownload()), this, SLOT(downloadStarted()));
connect(artmanager, SIGNAL(finishedDownload()), this, SLOT(downloadFinished()));
connect(artmanager, SIGNAL(foundMultipleGames(QList<TheGameDBStorage*>)), this, SLOT(on_foundMultipleGames(QList<TheGameDBStorage*>)));
artmanager->getGameData(game, "PC");
ui->label_2->setText(tr("Searching for artwork..."));
}
void GameInfoDialog::on_ShowArtworkFolder_clicked()
{
QDesktopServices::openUrl(game->getArtworkDir());
}
void GameInfoDialog::openFile(QString destFileName) {
QFileInfo fi;
QString file = QFileDialog::getOpenFileName(this, tr("Choose artwork"), lastDir, "Images (*.png *.jpg)");
if(file.isEmpty())
return;
else {
fi = QFileInfo(file);
lastDir = fi.absoluteFilePath();
if(fi.exists()) {
FArtManager fa(game);
fa.importArtwork(fi, destFileName);
}
}
}
void GameInfoDialog::on_importBannerButton_clicked()
{
openFile(FGame::FGameArtToStr(FArtBanner));
}
void GameInfoDialog::on_importClearartButton_clicked()
{
openFile(FGame::FGameArtToStr(FArtClearart));
}
void GameInfoDialog::on_importCoverButton_clicked()
{
openFile(FGame::FGameArtToStr(FArtBox));
}
void GameInfoDialog::on_importFanartButton_clicked()
{
openFile(FGame::FGameArtToStr(FArtFanart));
}
void GameInfoDialog::on_foundMultipleGames(QList<TheGameDBStorage*> Games) {
GameDBArtSelectorDialog *dialog = new GameDBArtSelectorDialog(Games, this);
connect(dialog, SIGNAL(gameSelected(TheGameDBStorage*)), this, SLOT(on_gameSelected(TheGameDBStorage*)));
dialog->exec();
}
void GameInfoDialog::on_gameSelected(TheGameDBStorage* selectedGame) {
FArtManager *artmanager = new FArtManager();
connect(artmanager, SIGNAL(startedDownload()), this, SLOT(downloadStarted()));
connect(artmanager, SIGNAL(finishedDownload()), this, SLOT(downloadFinished()));
connect(artmanager, SIGNAL(foundMultipleGames(QList<TheGameDBStorage*>)), this, SLOT(on_foundMultipleGames(QList<TheGameDBStorage*>)));
artmanager->getGameData(game, selectedGame);
}
void GameInfoDialog::on_buttonBox_accepted()
{
game->setName(ui->le_Title->text());
game->setExe(ui->le_Exec->text());
game->setPath(ui->le_Directory->text());
qDebug() << "Updating game.";
if(ui->launcherCheckBox->isChecked())
{
game->setLauncher(db->getLauncher(ui->launcherComboBox->itemData(ui->launcherComboBox->currentIndex()).toInt()));
qDebug() << "Launcher set, id:" << game->getLauncher().getDbId() << ", name:" << game->getLauncher().getName() << ", boxId:" << ui->launcherComboBox->itemData(ui->launcherComboBox->currentIndex()).toInt();
}
else
{
game->disableLauncher();
}
game->setArgs(QStringList(ui->le_Params->text()));
if(ui->cb_useSavegameSync->checkState()) {
game->setSavegameDir(ui->le_savegameDir->text());
} else {
game->setSavegameDir("");
}
db->updateGame(game);
emit reloadRequired();
}
void GameInfoDialog::downloadFinished() {
--runningDownloads;
ui->label_2->setText(tr("Running downloads:") + QString::number(runningDownloads));
if(runningDownloads<=0)
QMessageBox::information(this, tr("Downloads finished"), tr("Finished %n download(s)", 0, totalDownloads));
}
void GameInfoDialog::downloadStarted() {
++runningDownloads;
++totalDownloads;
ui->label_2->setText(tr("Running downloads:") + QString::number(runningDownloads));
}
void GameInfoDialog::on_launcherCheckBox_clicked()
{
ui->launcherComboBox->setEnabled(ui->launcherCheckBox->isChecked());
}
void GameInfoDialog::on_pb_setSavegameDir_clicked()
{
QDir gameDir = QFileDialog::getExistingDirectory(this, tr("Choose the Savegame-Directory"), ui->le_Directory->text());
if(gameDir.dirName()!=".")
ui->le_savegameDir->setText(gameDir.absolutePath());
}
void GameInfoDialog::on_cb_useSavegameSync_clicked()
{
ui->cb_useSavegameSync->setChecked(ui->cb_useSavegameSync->checkState());
ui->le_savegameDir->setEnabled(ui->cb_useSavegameSync->checkState());
// ui->pb_setSavegameDir->setEnabled(ui->cb_useSavegameSync->checkState());
}