-
Notifications
You must be signed in to change notification settings - Fork 1
/
UserInterface.cpp
801 lines (729 loc) · 24.3 KB
/
UserInterface.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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
/*****************************************************************************
* rdr2view Red Dead Redemption 2 Profile Viewer
* Copyright (C) 2016-2019 Syping
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "UserInterface.h"
#include "ui_UserInterface.h"
#include "ProfileInterface.h"
#include "SnapmaticPicture.h"
#include "SidebarGenerator.h"
#include "SavegameDialog.h"
#include "StandardPaths.h"
#include "OptionsDialog.h"
#include "PictureDialog.h"
#include "SavegameData.h"
#include "AboutDialog.h"
#include "IconLoader.h"
#include "AppEnv.h"
#include "config.h"
#include <QtGlobal>
#include <QStringBuilder>
#include <QStyleFactory>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QSpacerItem>
#include <QPushButton>
#include <QMessageBox>
#include <QSettings>
#include <QFileInfo>
#include <QTimer>
#include <QDebug>
#include <QFile>
#include <QDir>
#include <QMap>
#ifdef GTA5SYNC_MOTD
UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, MessageThread *threadMessage, QWidget *parent) :
QMainWindow(parent), profileDB(profileDB), crewDB(crewDB), threadDB(threadDB), threadMessage(threadMessage),
ui(new Ui::UserInterface)
#else
UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent) :
QMainWindow(parent), profileDB(profileDB), crewDB(crewDB), threadDB(threadDB),
ui(new Ui::UserInterface)
#endif
{
ui->setupUi(this);
contentMode = 0;
profileOpen = 0;
profileUI = 0;
ui->menuProfile->setEnabled(false);
ui->actionSelect_profile->setEnabled(false);
ui->actionAbout_gta5sync->setIcon(IconLoader::loadingAppIcon());
ui->actionAbout_gta5sync->setText(tr("&About %1").arg(GTA5SYNC_APPSTR));
ui->cmdClose->setToolTip(ui->cmdClose->toolTip().arg(GTA5SYNC_APPSTR));
defaultWindowTitle = tr("%2 - %1").arg("%1", GTA5SYNC_APPSTR);
this->setWindowTitle(defaultWindowTitle.arg(tr("Select Profile")));
QString appVersion = GTA5SYNC_APPVER;
#ifndef GTA5SYNC_BUILDTYPE_REL
#ifdef GTA5SYNC_COMMIT
if (!appVersion.contains("-")) { appVersion = appVersion % "-" % GTA5SYNC_COMMIT; }
#endif
#endif
ui->labVersion->setText(QString("%1 %2").arg(GTA5SYNC_APPSTR, appVersion));
// Set Icon for Close Button
if (QIcon::hasThemeIcon("dialog-close"))
{
ui->cmdClose->setIcon(QIcon::fromTheme("dialog-close"));
}
else if (QIcon::hasThemeIcon("gtk-close"))
{
ui->cmdClose->setIcon(QIcon::fromTheme("gtk-close"));
}
// Set Icon for Reload Button
if (QIcon::hasThemeIcon("view-refresh"))
{
ui->cmdReload->setIcon(QIcon::fromTheme("view-refresh"));
}
else if (QIcon::hasThemeIcon("reload"))
{
ui->cmdReload->setIcon(QIcon::fromTheme("reload"));
}
// Set Icon for Choose RDR 2 Folder Menu Item
if (QIcon::hasThemeIcon("document-open-folder"))
{
ui->actionSelect_GTA_Folder->setIcon(QIcon::fromTheme("document-open-folder"));
}
else if (QIcon::hasThemeIcon("gtk-directory"))
{
ui->actionSelect_GTA_Folder->setIcon(QIcon::fromTheme("gtk-directory"));
}
// Set Icon for Open File Menu Item
if (QIcon::hasThemeIcon("document-open"))
{
ui->actionOpen_File->setIcon(QIcon::fromTheme("document-open"));
}
// Set Icon for Close Profile Menu Item
if (QIcon::hasThemeIcon("dialog-close"))
{
ui->actionSelect_profile->setIcon(QIcon::fromTheme("dialog-close"));
}
else if (QIcon::hasThemeIcon("gtk-close"))
{
ui->actionSelect_profile->setIcon(QIcon::fromTheme("gtk-close"));
}
// Set Icon for Exit Menu Item
if (QIcon::hasThemeIcon("application-exit"))
{
#ifndef Q_OS_MACOS // Setting icon for exit/quit lead to a crash in Mac OS X
ui->actionExit->setIcon(QIcon::fromTheme("application-exit"));
#endif
}
// Set Icon for Preferences Menu Item
if (QIcon::hasThemeIcon("preferences-system"))
{
#ifndef Q_OS_MACOS // Setting icon for preferences/settings/options lead to a crash in Mac OS X
ui->actionOptions->setIcon(QIcon::fromTheme("preferences-system"));
#endif
}
else if (QIcon::hasThemeIcon("configure"))
{
#ifndef Q_OS_MACOS // Setting icon for preferences/settings/options lead to a crash in Mac OS X
ui->actionOptions->setIcon(QIcon::fromTheme("configure"));
#endif
}
// Set Icon for Profile Import Menu Item
if (QIcon::hasThemeIcon("document-import"))
{
ui->action_Import->setIcon(QIcon::fromTheme("document-import"));
}
else if (QIcon::hasThemeIcon("document-open"))
{
ui->action_Import->setIcon(QIcon::fromTheme("document-open"));
}
// Set Icon for Profile Export Menu Item
if (QIcon::hasThemeIcon("document-export"))
{
ui->actionExport_selected->setIcon(QIcon::fromTheme("document-export"));
}
else if (QIcon::hasThemeIcon("document-save"))
{
ui->actionExport_selected->setIcon(QIcon::fromTheme("document-save"));
}
// Set Icon for Profile Remove Menu Item
if (QIcon::hasThemeIcon("remove"))
{
ui->actionDelete_selected->setIcon(QIcon::fromTheme("remove"));
}
// DPI calculation
qreal screenRatio = AppEnv::screenRatio();
#ifndef Q_QS_ANDROID
resize(625 * screenRatio, 500 * screenRatio);
#endif
ui->vlUserInterface->setSpacing(6 * screenRatio);
ui->vlUserInterface->setContentsMargins(9 * screenRatio, 9 * screenRatio, 9 * screenRatio, 9 * screenRatio);
}
void UserInterface::setupDirEnv()
{
// settings init
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
bool folderExists;
GTAV_Folder = AppEnv::getGameFolder(&folderExists);
if (folderExists)
{
QDir::setCurrent(GTAV_Folder);
}
else
{
GTAV_Folder = QFileDialog::getExistingDirectory(this, tr("Select RDR 2 Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly);
if (QFileInfo(GTAV_Folder).exists())
{
folderExists = true;
QDir::setCurrent(GTAV_Folder);
AppEnv::setGameFolder(GTAV_Folder);
// First time folder selection save
settings.beginGroup("dir");
if (settings.value("dir", "").toString().isEmpty())
{
settings.setValue("dir", GTAV_Folder);
}
settings.endGroup();
}
}
// profiles init
settings.beginGroup("Profile");
QString defaultProfile = settings.value("Default", "").toString();
bool contentModeOk;
contentMode = settings.value("ContentMode", 0).toInt(&contentModeOk);
if (contentMode != 0 && contentMode != 1 && contentMode != 2)
{
contentMode = 0;
}
if (folderExists)
{
QDir GTAV_ProfilesDir;
GTAV_ProfilesFolder = GTAV_Folder % "/Profiles";
GTAV_ProfilesDir.setPath(GTAV_ProfilesFolder);
GTAV_Profiles = GTAV_ProfilesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::NoSort);
setupProfileUi();
if (GTAV_Profiles.length() == 1)
{
openProfile(GTAV_Profiles.at(0));
}
else if(GTAV_Profiles.contains(defaultProfile))
{
openProfile(defaultProfile);
}
}
else
{
GTAV_Profiles = QStringList();
setupProfileUi();
}
settings.endGroup();
}
void UserInterface::setupProfileUi()
{
qreal screenRatio = AppEnv::screenRatio();
if (GTAV_Profiles.isEmpty())
{
QPushButton *changeDirBtn = new QPushButton(tr("Select &RDR 2 Folder..."), ui->swSelection);
changeDirBtn->setObjectName("cmdChangeDir");
changeDirBtn->setMinimumSize(0, 40 * screenRatio);
changeDirBtn->setAutoDefault(true);
ui->vlButtons->addWidget(changeDirBtn);
profileBtns += changeDirBtn;
QObject::connect(changeDirBtn, SIGNAL(clicked(bool)), this, SLOT(changeFolder_clicked()));
}
else for (QString GTAV_Profile : GTAV_Profiles)
{
QPushButton *profileBtn = new QPushButton(GTAV_Profile, ui->swSelection);
profileBtn->setObjectName(GTAV_Profile);
profileBtn->setMinimumSize(0, 40 * screenRatio);
profileBtn->setAutoDefault(true);
ui->vlButtons->addWidget(profileBtn);
profileBtns += profileBtn;
QObject::connect(profileBtn, SIGNAL(clicked(bool)), this, SLOT(profileButton_clicked()));
}
profileBtns.at(0)->setFocus();
}
void UserInterface::changeFolder_clicked()
{
on_actionSelect_GTA_Folder_triggered();
}
void UserInterface::on_cmdReload_clicked()
{
for (QPushButton *profileBtn : profileBtns)
{
ui->vlButtons->removeWidget(profileBtn);
delete profileBtn;
}
profileBtns.clear();
setupDirEnv();
}
void UserInterface::profileButton_clicked()
{
QPushButton *profileBtn = (QPushButton*)sender();
openProfile(profileBtn->objectName());
}
void UserInterface::openProfile(const QString &profileName_)
{
profileOpen = true;
profileName = profileName_;
profileUI = new ProfileInterface(profileDB, crewDB, threadDB);
ui->swProfile->addWidget(profileUI);
ui->swProfile->setCurrentWidget(profileUI);
profileUI->setProfileFolder(GTAV_ProfilesFolder % QDir::separator() % profileName, profileName);
profileUI->settingsApplied(contentMode, false);
profileUI->setupProfileInterface();
QObject::connect(profileUI, SIGNAL(profileClosed()), this, SLOT(closeProfile()));
QObject::connect(profileUI, SIGNAL(profileLoaded()), this, SLOT(profileLoaded()));
this->setWindowTitle(defaultWindowTitle.arg(profileName));
}
void UserInterface::closeProfile()
{
if (profileOpen)
{
closeProfile_p();
}
this->setWindowTitle(defaultWindowTitle.arg(tr("Select Profile")));
}
void UserInterface::closeProfile_p()
{
profileOpen = false;
profileName.clear();
profileName.squeeze();
ui->menuProfile->setEnabled(false);
ui->actionSelect_profile->setEnabled(false);
ui->swProfile->removeWidget(profileUI);
profileUI->disconnect();
delete profileUI;
}
void UserInterface::closeEvent(QCloseEvent *ev)
{
Q_UNUSED(ev)
#ifdef GTA5SYNC_MOTD
threadMessage->terminateThread();
#else
threadDB->terminateThread();
#endif
}
UserInterface::~UserInterface()
{
if (profileOpen)
{
closeProfile_p();
}
for (QPushButton *profileBtn : profileBtns)
{
delete profileBtn;
}
profileBtns.clear();
delete ui;
}
void UserInterface::on_actionExit_triggered()
{
this->close();
}
void UserInterface::on_actionSelect_profile_triggered()
{
closeProfile();
openSelectProfile();
}
void UserInterface::openSelectProfile()
{
// not needed right now
}
void UserInterface::on_actionAbout_gta5sync_triggered()
{
AboutDialog *aboutDialog = new AboutDialog(this);
aboutDialog->setWindowIcon(windowIcon());
aboutDialog->setModal(true);
#ifdef Q_OS_ANDROID
// Android ...
aboutDialog->showMaximized();
#else
aboutDialog->show();
#endif
aboutDialog->exec();
delete aboutDialog;
}
void UserInterface::profileLoaded()
{
ui->menuProfile->setEnabled(true);
ui->actionSelect_profile->setEnabled(true);
}
void UserInterface::on_actionSelect_all_triggered()
{
if (profileOpen)
{
profileUI->selectAllWidgets();
}
}
void UserInterface::on_actionDeselect_all_triggered()
{
if (profileOpen)
{
profileUI->deselectAllWidgets();
}
}
void UserInterface::on_actionExport_selected_triggered()
{
if (profileOpen)
{
profileUI->exportSelected();
}
}
void UserInterface::on_actionDelete_selected_triggered()
{
if (profileOpen)
{
profileUI->deleteSelected();
}
}
void UserInterface::on_actionOptions_triggered()
{
OptionsDialog *optionsDialog = new OptionsDialog(profileDB, this);
optionsDialog->setWindowIcon(windowIcon());
optionsDialog->commitProfiles(GTAV_Profiles);
QObject::connect(optionsDialog, SIGNAL(settingsApplied(int, bool)), this, SLOT(settingsApplied(int, bool)));
optionsDialog->setModal(true);
#ifdef Q_OS_ANDROID
// Android ...
optionsDialog->showMaximized();
#else
optionsDialog->show();
#endif
optionsDialog->exec();
delete optionsDialog;
}
void UserInterface::on_action_Import_triggered()
{
if (profileOpen)
{
profileUI->importFiles();
}
}
void UserInterface::on_actionOpen_File_triggered()
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("FileDialogs");
fileDialogPreOpen:
QFileDialog fileDialog(this);
fileDialog.setFileMode(QFileDialog::ExistingFiles);
fileDialog.setViewMode(QFileDialog::Detail);
fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
fileDialog.setOption(QFileDialog::DontUseNativeDialog, false);
fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
fileDialog.setWindowTitle(tr("Open File..."));
QStringList filters;
filters << ProfileInterface::tr("All profile files (*.r5e SRDR* PRDR*)");
filters << ProfileInterface::tr("RDR 2 Export (*.r5e)");
filters << ProfileInterface::tr("Savegames files (SRDR*)");
filters << ProfileInterface::tr("Snapmatic pictures (PRDR*)");
filters << ProfileInterface::tr("All files (**)");
fileDialog.setNameFilters(filters);
QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls());
fileDialog.setSidebarUrls(sidebarUrls);
fileDialog.setDirectory(settings.value("OpenDialogDirectory", StandardPaths::documentsLocation()).toString());
fileDialog.restoreGeometry(settings.value("OpenDialogGeometry","").toByteArray());
if (fileDialog.exec())
{
QStringList selectedFiles = fileDialog.selectedFiles();
if (selectedFiles.length() == 1)
{
QString selectedFile = selectedFiles.at(0);
if (!openFile(selectedFile, true)) goto fileDialogPreOpen;
}
}
settings.setValue("OpenDialogGeometry", fileDialog.saveGeometry());
settings.setValue("OpenDialogDirectory", fileDialog.directory().absolutePath());
settings.endGroup();
}
bool UserInterface::openFile(QString selectedFile, bool warn)
{
QString selectedFileName = QFileInfo(selectedFile).fileName();
if (QFile::exists(selectedFile))
{
if (selectedFileName.left(4) == "PRDR" || selectedFileName.right(4) == ".r5e")
{
SnapmaticPicture *picture = new SnapmaticPicture(selectedFile);
if (picture->readingPicture())
{
openSnapmaticFile(picture);
delete picture;
return true;
}
else
{
if (warn) QMessageBox::warning(this, tr("Open File"), ProfileInterface::tr("Failed to read Snapmatic picture"));
delete picture;
return false;
}
}
else if (selectedFileName.left(4) == "SRDR")
{
SavegameData *savegame = new SavegameData(selectedFile);
if (savegame->readingSavegame())
{
openSavegameFile(savegame);
delete savegame;
return true;
}
else
{
if (warn) QMessageBox::warning(this, tr("Open File"), ProfileInterface::tr("Failed to read Savegame file"));
delete savegame;
return false;
}
}
else
{
SnapmaticPicture *picture = new SnapmaticPicture(selectedFile);
SavegameData *savegame = new SavegameData(selectedFile);
if (picture->readingPicture())
{
delete savegame;
openSnapmaticFile(picture);
delete picture;
return true;
}
else if (savegame->readingSavegame())
{
delete picture;
openSavegameFile(savegame);
delete savegame;
return true;
}
else
{
delete savegame;
delete picture;
if (warn) QMessageBox::warning(this, tr("Open File"), tr("Can't open %1 because of not valid file format").arg("\""+selectedFileName+"\""));
return false;
}
}
}
if (warn) QMessageBox::warning(this, tr("Open File"), ProfileInterface::tr("No valid file is selected"));
return false;
}
void UserInterface::openSnapmaticFile(SnapmaticPicture *picture)
{
PictureDialog picDialog(profileDB, crewDB, this);
picDialog.setSnapmaticPicture(picture, true);
picDialog.setModal(true);
int crewID = picture->getSnapmaticProperties().crewID;
if (crewID != 0) { crewDB->addCrew(crewID); }
QObject::connect(threadDB, SIGNAL(crewNameUpdated()), &picDialog, SLOT(crewNameUpdated()));
QObject::connect(threadDB, SIGNAL(playerNameUpdated()), &picDialog, SLOT(playerNameUpdated()));
#ifdef Q_OS_ANDROID
// Android optimization should be put here
picDialog.showMaximized();
#else
picDialog.show();
picDialog.setMinimumSize(picDialog.size());
picDialog.setMaximumSize(picDialog.size());
#endif
picDialog.exec();
}
void UserInterface::openSavegameFile(SavegameData *savegame)
{
SavegameDialog sgdDialog(this);
sgdDialog.setSavegameData(savegame, savegame->getSavegameFileName(), true);
sgdDialog.setModal(true);
#ifdef Q_OS_ANDROID
// Android optimization should be put here
sgdDialog.showMaximized();
#else
sgdDialog.show();
#endif
sgdDialog.exec();
}
void UserInterface::settingsApplied(int _contentMode, bool languageChanged)
{
if (languageChanged)
{
retranslateUi();
}
contentMode = _contentMode;
if (profileOpen)
{
profileUI->settingsApplied(contentMode, languageChanged);
}
}
#ifdef GTA5SYNC_MOTD
void UserInterface::messagesArrived(const QJsonObject &object)
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("Messages");
QJsonObject::const_iterator it = object.constBegin();
QJsonObject::const_iterator end = object.constEnd();
QStringList messages;
while (it != end) {
const QString key = it.key();
const QJsonValue value = it.value();
bool uintOk;
uint messageId = key.toUInt(&uintOk);
if (uintOk && value.isString()) {
const QString valueStr = value.toString();
settings.setValue(QString::number(messageId), valueStr);
messages << valueStr;
}
it++;
}
settings.endGroup();
if (!messages.isEmpty())
showMessages(messages);
}
void UserInterface::showMessages(const QStringList messages)
{
QDialog *messageDialog = new QDialog(this);
messageDialog->setWindowTitle(tr("%1 - Messages").arg(GTA5SYNC_APPSTR));
messageDialog->setWindowFlags(messageDialog->windowFlags()^Qt::WindowContextHelpButtonHint);
QVBoxLayout *messageLayout = new QVBoxLayout;
messageDialog->setLayout(messageLayout);
QStackedWidget *stackWidget = new QStackedWidget(messageDialog);
for (const QString message : messages) {
QLabel *messageLabel = new QLabel(messageDialog);
messageLabel->setText(message);
messageLabel->setWordWrap(true);
stackWidget->addWidget(messageLabel);
}
messageLayout->addWidget(stackWidget);
QHBoxLayout *buttonLayout = new QHBoxLayout;
QPushButton *backButton = new QPushButton(messageDialog);
QPushButton *nextButton = new QPushButton(messageDialog);
if (QIcon::hasThemeIcon("go-previous") && QIcon::hasThemeIcon("go-next") && QIcon::hasThemeIcon("list-add")) {
backButton->setIcon(QIcon::fromTheme("go-previous"));
nextButton->setIcon(QIcon::fromTheme("go-next"));
}
else {
backButton->setIcon(QIcon(":/img/back.svgz"));
nextButton->setIcon(QIcon(":/img/next.svgz"));
}
backButton->setEnabled(false);
if (stackWidget->count() <= 1) {
nextButton->setEnabled(false);
}
buttonLayout->addWidget(backButton);
buttonLayout->addWidget(nextButton);
buttonLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum));
QPushButton *closeButton = new QPushButton(messageDialog);
closeButton->setText(tr("&Close"));
if (QIcon::hasThemeIcon("dialog-close")) {
closeButton->setIcon(QIcon::fromTheme("dialog-close"));
}
else if (QIcon::hasThemeIcon("gtk-close")) {
closeButton->setIcon(QIcon::fromTheme("gtk-close"));
}
buttonLayout->addWidget(closeButton);
messageLayout->addLayout(buttonLayout);
QObject::connect(backButton, &QPushButton::clicked, [stackWidget,backButton,nextButton,closeButton]() {
int index = stackWidget->currentIndex();
if (index > 0) {
index--;
stackWidget->setCurrentIndex(index);
nextButton->setEnabled(true);
if (index > 0) {
backButton->setEnabled(true);
}
else {
backButton->setEnabled(false);
closeButton->setFocus();
}
}
});
QObject::connect(nextButton, &QPushButton::clicked, [stackWidget,backButton,nextButton,closeButton]() {
int index = stackWidget->currentIndex();
if (index < stackWidget->count()-1) {
index++;
stackWidget->setCurrentIndex(index);
backButton->setEnabled(true);
if (index < stackWidget->count()-1) {
nextButton->setEnabled(true);
}
else {
nextButton->setEnabled(false);
closeButton->setFocus();
}
}
});
QObject::connect(closeButton, &QPushButton::clicked, messageDialog, &QDialog::accept);
QObject::connect(messageDialog, &QDialog::finished, messageDialog, &QDialog::deleteLater);
QTimer::singleShot(0, closeButton, SLOT(setFocus()));
messageDialog->show();
}
void UserInterface::updateCacheId(uint cacheId)
{
QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
settings.beginGroup("Messages");
settings.setValue("CacheId", cacheId);
settings.endGroup();
}
#endif
void UserInterface::on_actionSelect_GTA_Folder_triggered()
{
QString GTAV_Folder_Temp = QFileDialog::getExistingDirectory(this, tr("Select RDR 2 Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly);
if (QFileInfo(GTAV_Folder_Temp).exists())
{
if (profileOpen)
{
closeProfile_p();
}
GTAV_Folder = GTAV_Folder_Temp;
QDir::setCurrent(GTAV_Folder);
AppEnv::setGameFolder(GTAV_Folder);
on_cmdReload_clicked();
}
}
void UserInterface::on_action_Enable_In_game_triggered()
{
if (profileOpen)
{
profileUI->enableSelected();
}
}
void UserInterface::on_action_Disable_In_game_triggered()
{
if (profileOpen)
{
profileUI->disableSelected();
}
}
void UserInterface::retranslateUi()
{
ui->retranslateUi(this);
ui->actionAbout_gta5sync->setText(tr("&About %1").arg(GTA5SYNC_APPSTR));
QString appVersion = GTA5SYNC_APPVER;
#ifndef GTA5SYNC_BUILDTYPE_REL
#ifdef GTA5SYNC_COMMIT
if (!appVersion.contains("-")) { appVersion = appVersion % "-" % GTA5SYNC_COMMIT; }
#endif
#endif
ui->labVersion->setText(QString("%1 %2").arg(GTA5SYNC_APPSTR, appVersion));
if (profileOpen)
{
this->setWindowTitle(defaultWindowTitle.arg(profileName));
}
else
{
this->setWindowTitle(defaultWindowTitle.arg(tr("Select Profile")));
}
}
void UserInterface::on_actionQualify_as_Avatar_triggered()
{
profileUI->massTool(MassTool::Qualify);
}
void UserInterface::on_actionChange_Players_triggered()
{
profileUI->massTool(MassTool::Players);
}
void UserInterface::on_actionSet_Crew_triggered()
{
profileUI->massTool(MassTool::Crew);
}
void UserInterface::on_actionSet_Title_triggered()
{
profileUI->massTool(MassTool::Title);
}