-
Notifications
You must be signed in to change notification settings - Fork 0
/
filesdialog.cpp
373 lines (341 loc) · 17.9 KB
/
filesdialog.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
#include "filesdialog.h"
#include "ui_filesdialog.h"
#include <QMessageBox>
#include <QFileDialog>
#include <QDir>
#include <QDebug>
FilesDialog::FilesDialog(QWidget *parent, QMap<QString, QString> *directoryForPointer, QString *directories) :
QDialog(parent),
ui(new Ui::FilesDialog)
{
ui->setupUi(this);
this->directoryFor = directoryForPointer;
directories_init(directories);
}
FilesDialog::~FilesDialog()
{
delete ui;
}
void FilesDialog::makeDefaultDir(QLineEdit *field, QString configFile, QString configDir)
{
QString dirName;
QStringList subDirList;
if (configFile.compare("/AlphaTeamDirectory.txt") == 0) {
dirName = configDir + "/TeamsDirectory";
} else if (configFile.compare("/BravoTeamDirectory.txt") == 0) {
dirName = configDir + "/TeamsDirectory";
} else if (configFile.compare("/LogosDirectory.txt") == 0) {
dirName = configDir + "/LogosDirectory";
} else if (configFile.compare("/MapsDirectory.txt") == 0) {
dirName = configDir + "/MapsDirectory";
} else if (configFile.compare("/ModeIconsDirectory.txt") == 0) {
dirName = configDir + "/ModeIconsDirectory";
} else if (configFile.compare("/SplatfestColorsDirectory.txt") == 0) {
dirName = configDir + "/Colors/SplatfestColorsDirectory";
QDir().mkdir(configDir + "/Colors");
subDirList << dirName + "/alpha" << dirName + "/bravo" << dirName + "/combo";
} else if (configFile.compare("/RankedColorsDirectory.txt") == 0) {
dirName = configDir + "/Colors/RankedColorsDirectory";
QDir().mkdir(configDir + "/Colors");
subDirList << dirName + "/alpha" << dirName + "/bravo" << dirName + "/combo";
} else if (configFile.compare("/TurfWarColorsDirectory.txt") == 0) {
dirName = configDir + "/Colors/Turf WarColorsDirectory";
QDir().mkdir(configDir + "/Colors");
subDirList << dirName + "/alpha" << dirName + "/bravo" << dirName + "/combo";
} else if (configFile.compare("/ImportingFilesDirectory.txt") == 0) {
dirName = configDir + "/ImportingFilesDirectory";
subDirList << dirName + "/casters" << dirName + "/info" << dirName + "/round";
subDirList << dirName + "/set" << dirName + "/teamAlpha" << dirName + "/teamBravo";
subDirList << dirName + "/set/maps" << dirName + "/set/modes";
subDirList << dirName + "/set/winners" << dirName + "/set/winPoints";
subDirList << dirName + "/set/weapons" << dirName + "/set/winPoints";
} else if (configFile.compare("/DefaultDirectory.txt") == 0) {
dirName = configDir + "/DefaultDirectory";
subDirList << dirName + "/logo";
} else if (configFile.compare("/WinPointsDirectory.txt") == 0) {
dirName = configDir + "/WinPointsDirectory";
subDirList << dirName + "/teamAlpha" << dirName + "/teamBravo";
} else if (configFile.compare("/WeaponsDirectory.txt") == 0) {
dirName = configDir + "/WeaponsDirectory";
}
field->setText(dirName);
QDir().mkdir(dirName); // Make sure default dir exists
for (int i = 0; i < subDirList.size(); ++i) {
QDir().mkdir(subDirList.at(i));
}
saveConfigDirectory(configDir + configFile, field); // Save default dir in config File
}
void FilesDialog::directories_init(QString *dirs)
{
// put content from config files on lineEdits
// Initialize fields and directories
QLineEdit *widgets[dirAmount] {
ui->AlphaTeamDirectoryEdit, ui->BravoTeamDirectoryEdit, ui->LogosDirectoryEdit,
ui->MapsDirectoryEdit, ui->ModeIconsDirectoryEdit, ui->SplatfestColorsDirectoryEdit, ui->TurfWarColorsDirectoryEdit,
ui->RankedColorsDirectoryEdit, ui->ImportingFilesDirectoryEdit, ui->DefaultDirectoryEdit, ui->WinPointsDirectoryEdit,
ui->WeaponsDirectoryEdit
};
for (int i = 0; i < dirAmount; i++) {
this->fields[i] = widgets[i];
this->directories[i] = dirs[i];
}
QFile file;
QString directory = QCoreApplication::applicationDirPath() + "/config";
QString filename;
QString dirname;
QString text;
bool makeDefault = false;
// for each field
for (int i = 0; i < dirAmount; i++) {
filename = directory + this->directories[i];
file.setFileName(filename);
// if no saved location create and save location for default
if (!file.open(QFile::ReadOnly | QFile::Text)) {
makeDefault = true;
// If there's a file
} else {
QTextStream in(&file);
text = in.readAll();
// Unless the file points to an invalid directory
if (!QDir(text).exists()) {
makeDefault = true;
// Set the file content as the config directory
} else {
this->fields[i]->setText(text);
}
}
file.close();
if (makeDefault) {
this->makeDefaultDir(this->fields[i], dirs[i], directory);
}
}
}
int FilesDialog::saveConfigDirectory(QString filename, QLineEdit *lineEdit)
{
QFile file(filename);
if (file.open(QFile::WriteOnly | QFile::Text)) {
QTextStream out(&file);
out << lineEdit->text();
file.flush();
file.close();
return 0;
} else {
return 1;
}
}
void FilesDialog::on_DirectoriesDialogButtonBox_accepted()
{
// Initialize config directory
QString directory = QCoreApplication::applicationDirPath() + "/config";
QDir dir;
dir.mkdir(directory);
// Storing config Directories on config files
QString filename;
for (int i = 0; i < dirAmount; i++) {
filename = directory + this->directories[i];
saveConfigDirectory(filename, this->fields[i]);
(*this->directoryFor)[this->directories[i]] = this->fields[i]->text();
}
// create subfolders for specific directories
// Importing Files Directory
QString dirname = (*this->directoryFor)["/ImportingFilesDirectory.txt"];
QDir().mkdir(dirname + "/casters");
QDir().mkdir(dirname + "/info");
QDir().mkdir(dirname + "/round");
QDir().mkdir(dirname + "/set");
QDir().mkdir(dirname + "/teamAlpha");
QDir().mkdir(dirname + "/teamBravo");
emit allDone();
}
void FilesDialog::on_AlphaTeamDirectoryHelp_clicked()
{
QMessageBox::information(this, "Alpha Team Directory", "This Directory will contain the list of teams you will can use for the Alpha Team.\n\nTo add a team, put in this directory an image file of the team logo.\n\nThe team name will be shown as the image file's name (excluding extension [.png / .jpg / .jpeg / .gif])");
}
void FilesDialog::on_BravoTeamDirectoryHelp_clicked()
{
QMessageBox::information(this, "Bravo Team Directory", "This Directory will contain the list of teams you will can use for the Bravo Team.\n\nYou probably want it to be the same as the Alpha Team directory!\n\nTo add a team, put in this directory an image file of the team logo.\n\nThe team name will be shown as the image file's name (excluding extension [.png / .jpg / .jpeg / .gif])");
}
void FilesDialog::on_LogosDirectoryHelp_clicked()
{
QMessageBox::information(this, "Logos Directory", "This Directory will contain the Logos.\n\nTo add a logo, put in this directory an image file of the logo.\n\nThe logo name will be shown as the image file's name (excluding extension [.png / .jpg / .jpeg / .gif])");
}
void FilesDialog::on_MapsDirectoryHelp_clicked()
{
QMessageBox::information(this, "Maps Directory", "This Directory will contain the maps.\n\nTo add a map, put in this directory an image file of the map.\n\nThe map name will be shown as the image file's name (excluding extension [.png / .jpg / .jpeg / .gif])");
}
void FilesDialog::on_ModeIconsDirectoryHelp_clicked()
{
QMessageBox::information(this, "Modes Directory", "This Directory will contain the modes.\n\nTo add a mode, put in this directory an image file of the mode.\n\nThe mode name will be shown as the image file's name (excluding extension [.png / .jpg / .jpeg / .gif])");
}
void FilesDialog::on_SplatfestColorsDirectoryHelp_clicked()
{
QMessageBox::information(this, "Splatfest Colors Directory", "This Directory will contain the colors for Splatfest matches.\n\nIf you use images that contain the color for both teams, puth them inside a \"combo\" subdirectory.\nEX: /combo/blueVSorange.png.\n\n If you use separate images for each team color, puth each file with the same name under the \"alpha\" and \"bravo\" subdirectories.\nEX: /alpha/blueVSorange.png and /bravo/blueVSorange.png\n\n If you have more than one set of images that you use (for example, square shaped ones and triangle shaped ones, for some reason), you can put them in subdirectories, with the same name as the ones in the root directory. Ex: you can have \"combo/Blue vs Green.png\", \"combo/inGame/Blue vs Green.png\" and \"combo/triangleShaped/Blue vs Green.png\" and they'll all be coppied to the importing file as \"color\", \"ingame_color\" and \"triangleShaped_color\", as long as you have color images inside the root directory.");
}
void FilesDialog::on_TurfWarColorsDirectoryHelp_clicked()
{
QMessageBox::information(this, "Turf War Colors Directory", "This Directory will contain the colors for Turf War matches.\n\nIf you use images that contain the color for both teams, puth them inside a \"combo\" subdirectory.\nEX: /combo/blueVSorange.png.\n\n If you use separate images for each team color, puth each file with the same name under the \"alpha\" and \"bravo\" subdirectories.\nEX: /alpha/blueVSorange.png and /bravo/blueVSorange.png\n\n If you have more than one set of images that you use (for example, square shaped ones and triangle shaped ones, for some reason), you can put them in subdirectories, with the same name as the ones in the root directory. Ex: you can have \"combo/Blue vs Green.png\", \"combo/inGame/Blue vs Green.png\" and \"combo/triangleShaped/Blue vs Green.png\" and they'll all be coppied to the importing file as \"color\", \"ingame_color\" and \"triangleShaped_color\", as long as you have color images inside the root directory.");
}
void FilesDialog::on_RankedColorsDirectoryHelp_clicked()
{
QMessageBox::information(this, "Ranked Colors Directory", "This Directory will contain the colors for Ranked modes matches.\n\nIf you use images that contain the color for both teams, puth them inside a \"combo\" subdirectory.\nEX: /combo/blueVSorange.png.\n\n If you use separate images for each team color, puth each file with the same name under the \"alpha\" and \"bravo\" subdirectories.\nEX: /alpha/blueVSorange.png and /bravo/blueVSorange.png\n\n If you have more than one set of images that you use (for example, square shaped ones and triangle shaped ones, for some reason), you can put them in subdirectories, with the same name as the ones in the root directory. Ex: you can have \"combo/Blue vs Green.png\", \"combo/inGame/Blue vs Green.png\" and \"combo/triangleShaped/Blue vs Green.png\" and they'll all be coppied to the importing file as \"color\", \"ingame_color\" and \"triangleShaped_color\", as long as you have color images inside the root directory.");
}
void FilesDialog::on_ImportingFilesDirectoryHelp_clicked()
{
QMessageBox::information(this, "Importing Files Directory", "This directory will contain all files that the scoreboard uses to save your selections (maps, modes, teams, colors, info, casters... everything).\n\nDon't change the default structure of this folder, because the scoreboard will look for specific subdirectories to save the correct files.\n\n The subdirectories of this folders are: casters, info, round, set, teamAlpha and teamBravo. The files within these directories will contain your selection of each of these topics, so you'll only need to import these files to OBS / SLOBS");
}
void FilesDialog::on_DefaultDirectoryHelp_clicked()
{
QMessageBox::information(this, "Default Directory", "This Directory will contain the default images for teams that don't have logos (or when you didn't save it).\n\nBy putting an image here (with any name) it will be used as the default team logo.\n\nYou can also place a bunch of default images in here and the scoreboard will pick one at random each time you enter a team without a saved logo.");
}
void FilesDialog::on_WinPointsDirectoryHelp_clicked()
{
QMessageBox::information(this, "Win Points Directory", "This Directory will contain the images for win points that will be assigned depending on the winner of each game.\n\nYou can set as many win points you want for alpha an for bravo, and they'll all be assigned on each winner on the importingDirectory/set/winpoints.");
}
void FilesDialog::on_WeaponsDirectoryHelp_clicked()
{
QMessageBox::information(this, "Weapons Directory", "This Directory will contain the images for weapons that can be assigned to the players of each game.\n\nThe weapon name will be shown as the image file's name (excluding extension [.png / .jpg / .jpeg / .gif])");
}
void FilesDialog::on_AlphaTeamDirectoryFind_clicked()
{
QString alphaTeamDirectory = QFileDialog::getExistingDirectory(
this,
tr("Open the Alpha team directory"),
QCoreApplication::applicationDirPath() + "/config",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (alphaTeamDirectory.length() != 0) {
ui->AlphaTeamDirectoryEdit->setText(alphaTeamDirectory);
}
}
void FilesDialog::on_BravoTeamDirectoryFind_clicked()
{
QString bravoTeamDirectory = QFileDialog::getExistingDirectory(
this,
tr("Open the Bravo team directory"),
QCoreApplication::applicationDirPath() + "/config",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (bravoTeamDirectory.length() != 0) {
ui->BravoTeamDirectoryEdit->setText(bravoTeamDirectory);
}
}
void FilesDialog::on_LogosDirectoryFind_clicked()
{
QString logosDirectory = QFileDialog::getExistingDirectory(
this,
tr("Open the logos directory"),
QCoreApplication::applicationDirPath() + "/config",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (logosDirectory.length() != 0) {
ui->LogosDirectoryEdit->setText(logosDirectory);
}
}
void FilesDialog::on_MapsDirectoryFind_clicked()
{
QString mapsDirectory = QFileDialog::getExistingDirectory(
this,
tr("Open the maps directory"),
QCoreApplication::applicationDirPath() + "/config",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (mapsDirectory.length() != 0) {
ui->MapsDirectoryEdit->setText(mapsDirectory);
}
}
void FilesDialog::on_ModeIconsDirectoryFind_clicked()
{
QString modeIconsDirectory = QFileDialog::getExistingDirectory(
this,
tr("Open the mode icons directory"),
QCoreApplication::applicationDirPath() + "/config",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (modeIconsDirectory.length() != 0) {
ui->ModeIconsDirectoryEdit->setText(modeIconsDirectory);
}
}
void FilesDialog::on_SplatfestColorsDirectoryFind_clicked()
{
QString splatfestColorsDirectory = QFileDialog::getExistingDirectory(
this,
tr("Open the Splatfest colors directory"),
QCoreApplication::applicationDirPath() + "/config",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (splatfestColorsDirectory.length() != 0) {
ui->SplatfestColorsDirectoryEdit->setText(splatfestColorsDirectory);
}
}
void FilesDialog::on_TurfWarColorsDirectoryFind_clicked()
{
QString turfWarColorsDirectory = QFileDialog::getExistingDirectory(
this,
tr("Open the Turf War Colors directory"),
QCoreApplication::applicationDirPath() + "/config",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (turfWarColorsDirectory.length() != 0) {
ui->TurfWarColorsDirectoryEdit->setText(turfWarColorsDirectory);
}
}
void FilesDialog::on_RankedColorsDirectoryFind_clicked()
{
QString rankedColorsDirectory = QFileDialog::getExistingDirectory(
this,
tr("Open the ranked colors directory"),
QCoreApplication::applicationDirPath() + "/config",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (rankedColorsDirectory.length() != 0) {
ui->RankedColorsDirectoryEdit->setText(rankedColorsDirectory);
}
}
void FilesDialog::on_ImportingFilesDirectoryFind_clicked()
{
QString importingFilesDirectory = QFileDialog::getExistingDirectory(
this,
tr("Open the importing files directory"),
QCoreApplication::applicationDirPath() + "/config",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (importingFilesDirectory.length() != 0) {
ui->ImportingFilesDirectoryEdit->setText(importingFilesDirectory);
}
}
void FilesDialog::on_DefaultDirectoryFind_clicked()
{
QString defaultDirectory = QFileDialog::getExistingDirectory(
this,
tr("Open the Default directory"),
QCoreApplication::applicationDirPath() + "/config",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (defaultDirectory.length() != 0) {
ui->DefaultDirectoryEdit->setText(defaultDirectory);
}
}
void FilesDialog::on_WinPointsDirectoryFind_clicked()
{
QString winPointDirectory = QFileDialog::getExistingDirectory(
this,
tr("Open the Win Points directory"),
QCoreApplication::applicationDirPath() + "/config",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (winPointDirectory.length() != 0) {
ui->DefaultDirectoryEdit->setText(winPointDirectory);
}
}
void FilesDialog::on_WeaponsDirectoryFind_clicked()
{
QString weaponsDirectory = QFileDialog::getExistingDirectory(
this,
tr("Open the weapons directory"),
QCoreApplication::applicationDirPath() + "/config",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
);
if (weaponsDirectory.length() != 0) {
ui->WeaponsDirectoryEdit->setText(weaponsDirectory);
}
}