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
|
/*
Copyright (C) 2012 Sebastian Herbord. All rights reserved.
This file is part of Mod Organizer.
Mod Organizer 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.
Mod Organizer 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 Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "modinfodialog.h"
#include "ui_modinfodialog.h"
#include "mainwindow.h"
#include "modidlineedit.h"
#include "iplugingame.h"
#include "nexusinterface.h"
#include "report.h"
#include "utility.h"
#include "messagedialog.h"
#include "bbcode.h"
#include "questionboxmemory.h"
#include "settings.h"
#include "categories.h"
#include "organizercore.h"
#include "pluginlistsortproxy.h"
#include "previewgenerator.h"
#include "previewdialog.h"
#include "texteditor.h"
#include "modinfodialogtextfiles.h"
#include "modinfodialogimages.h"
#include "modinfodialogesps.h"
#include "modinfodialogconflicts.h"
#include "modinfodialogcategories.h"
#include "modinfodialognexus.h"
#include "modinfodialogfiletree.h"
#include <QDir>
#include <QDirIterator>
#include <QPushButton>
#include <QInputDialog>
#include <QMessageBox>
#include <QMenu>
#include <QFileSystemModel>
#include <QInputDialog>
#include <QPointer>
#include <QFileDialog>
#include <QShortcut>
#include <Shlwapi.h>
#include <sstream>
using namespace MOBase;
using namespace MOShared;
const int max_scan_for_context_menu = 50;
class ModFileListWidget : public QListWidgetItem {
friend bool operator<(const ModFileListWidget &LHS, const ModFileListWidget &RHS);
public:
ModFileListWidget(const QString &text, int sortValue, QListWidget *parent = 0)
: QListWidgetItem(text, parent, QListWidgetItem::UserType + 1), m_SortValue(sortValue) {}
private:
int m_SortValue;
};
static bool operator<(const ModFileListWidget &LHS, const ModFileListWidget &RHS)
{
return LHS.m_SortValue < RHS.m_SortValue;
}
bool canPreviewFile(
PluginContainer& pluginContainer, bool isArchive, const QString& filename)
{
if (isArchive) {
return false;
}
const auto ext = QFileInfo(filename).suffix();
return pluginContainer.previewGenerator().previewSupported(ext);
}
bool canOpenFile(bool isArchive, const QString&)
{
// can open anything as long as it's not in an archive
return !isArchive;
}
bool canHideFile(bool isArchive, const QString& filename)
{
if (isArchive) {
// can't hide files from archives
return false;
}
if (filename.endsWith(ModInfo::s_HiddenExt)) {
// already hidden
return false;
}
return true;
}
bool canUnhideFile(bool isArchive, const QString& filename)
{
if (isArchive) {
// can't unhide files from archives
return false;
}
if (!filename.endsWith(ModInfo::s_HiddenExt)) {
// already visible
return false;
}
return true;
}
FileRenamer::RenameResults hideFile(FileRenamer& renamer, const QString &oldName)
{
const QString newName = oldName + ModInfo::s_HiddenExt;
return renamer.rename(oldName, newName);
}
FileRenamer::RenameResults unhideFile(FileRenamer& renamer, const QString &oldName)
{
QString newName = oldName.left(oldName.length() - ModInfo::s_HiddenExt.length());
return renamer.rename(oldName, newName);
}
ModInfoDialog::ModInfoDialog(ModInfo::Ptr modInfo, const DirectoryEntry *directory, bool unmanaged, OrganizerCore *organizerCore, PluginContainer *pluginContainer, QWidget *parent)
: TutorableDialog("ModInfoDialog", parent), ui(new Ui::ModInfoDialog), m_ModInfo(modInfo),
m_NewFolderAction(nullptr), m_OpenAction(nullptr), m_PreviewAction(nullptr),
m_RenameAction(nullptr), m_DeleteAction(nullptr), m_HideAction(nullptr),
m_UnhideAction(nullptr), m_Directory(directory), m_Origin(nullptr),
m_OrganizerCore(organizerCore), m_PluginContainer(pluginContainer)
{
ui->setupUi(this);
m_tabs = createTabs();
for (std::size_t i=0; i<m_tabs.size(); ++i) {
connect(
m_tabs[i].get(), &ModInfoDialogTab::originModified,
[&](int originID){ emit originModified(originID); });
connect(
m_tabs[i].get(), &ModInfoDialogTab::modOpen,
[&](const QString& name){
close();
emit modOpen(name, static_cast<int>(i));
});
}
this->setWindowTitle(modInfo->name());
this->setWindowModality(Qt::WindowModal);
m_RootPath = modInfo->absolutePath();
//TODO: No easy way to delegate links
//ui->descriptionView->page()->acceptNavigationRequest(QWebEnginePage::DelegateAllLinks);
new QShortcut(QKeySequence::Delete, this, SLOT(delete_activated()));
if (directory->originExists(ToWString(modInfo->name()))) {
m_Origin = &directory->getOriginByName(ToWString(modInfo->name()));
if (m_Origin->isDisabled()) {
m_Origin = nullptr;
}
}
if (modInfo->hasFlag(ModInfo::FLAG_SEPARATOR))
{
ui->tabWidget->setTabEnabled(TAB_TEXTFILES, false);
ui->tabWidget->setTabEnabled(TAB_INIFILES, false);
ui->tabWidget->setTabEnabled(TAB_IMAGES, false);
ui->tabWidget->setTabEnabled(TAB_ESPS, false);
ui->tabWidget->setTabEnabled(TAB_CONFLICTS, false);
ui->tabWidget->setTabEnabled(TAB_CATEGORIES, true);
ui->tabWidget->setTabEnabled(TAB_NEXUS, false);
ui->tabWidget->setTabEnabled(TAB_NOTES, true);
ui->tabWidget->setTabEnabled(TAB_FILETREE, false);
}
else if (unmanaged)
{
ui->tabWidget->setTabEnabled(TAB_TEXTFILES, false);
ui->tabWidget->setTabEnabled(TAB_INIFILES, false);
ui->tabWidget->setTabEnabled(TAB_IMAGES, false);
ui->tabWidget->setTabEnabled(TAB_ESPS, false);
ui->tabWidget->setTabEnabled(TAB_CONFLICTS, true);
ui->tabWidget->setTabEnabled(TAB_CATEGORIES, false);
ui->tabWidget->setTabEnabled(TAB_NEXUS, false);
ui->tabWidget->setTabEnabled(TAB_NOTES, false);
ui->tabWidget->setTabEnabled(TAB_FILETREE, false);
} else {
ui->tabWidget->setTabEnabled(TAB_TEXTFILES, true);
ui->tabWidget->setTabEnabled(TAB_INIFILES, true);
ui->tabWidget->setTabEnabled(TAB_IMAGES, true);
ui->tabWidget->setTabEnabled(TAB_ESPS, true);
ui->tabWidget->setTabEnabled(TAB_CONFLICTS, true);
ui->tabWidget->setTabEnabled(TAB_CATEGORIES, true);
ui->tabWidget->setTabEnabled(TAB_NEXUS, true);
ui->tabWidget->setTabEnabled(TAB_NOTES, true);
ui->tabWidget->setTabEnabled(TAB_FILETREE, true);
}
// activate first enabled tab
for (int i = 0; i < ui->tabWidget->count(); ++i) {
if (ui->tabWidget->isTabEnabled(i)) {
ui->tabWidget->setCurrentIndex(i);
break;
}
}
for (auto& tab : m_tabs) {
tab->setMod(m_ModInfo, m_Origin);
}
}
ModInfoDialog::~ModInfoDialog()
{
delete ui;
}
template <class... Ts>
std::vector<std::unique_ptr<ModInfoDialogTab>> createTabsImpl(
OrganizerCore& oc, PluginContainer& plugin,
ModInfoDialog* self, Ui::ModInfoDialog* ui)
{
std::vector<std::unique_ptr<ModInfoDialogTab>> v;
(v.push_back(std::make_unique<Ts>(oc, plugin, self, ui)), ...);
return v;
}
std::vector<std::unique_ptr<ModInfoDialogTab>> ModInfoDialog::createTabs()
{
return createTabsImpl<
TextFilesTab, IniFilesTab, ImagesTab, ESPsTab,
ConflictsTab, CategoriesTab, NexusTab, NotesTab, FileTreeTab>(
*m_OrganizerCore, *m_PluginContainer, this, ui);
}
int ModInfoDialog::exec()
{
refreshLists();
return TutorableDialog::exec();
}
int ModInfoDialog::tabIndex(const QString &tabId)
{
for (int i = 0; i < ui->tabWidget->count(); ++i) {
if (ui->tabWidget->widget(i)->objectName() == tabId) {
return i;
}
}
return -1;
}
void ModInfoDialog::saveState(Settings& s) const
{
s.directInterface().setValue("mod_info_tabs", saveTabState());
for (const auto& tab : m_tabs) {
tab->saveState(s);
}
}
void ModInfoDialog::restoreState(const Settings& s)
{
restoreTabState(s.directInterface().value("mod_info_tabs").toByteArray());
for (const auto& tab : m_tabs) {
tab->restoreState(s);
}
}
void ModInfoDialog::restoreTabState(const QByteArray &state)
{
QDataStream stream(state);
int count = 0;
stream >> count;
QStringList tabIds;
// first, only determine the new mapping
for (int newPos = 0; newPos < count; ++newPos) {
QString tabId;
stream >> tabId;
tabIds.append(tabId);
int oldPos = tabIndex(tabId);
if (oldPos != -1) {
m_RealTabPos[newPos] = oldPos;
} else {
m_RealTabPos[newPos] = newPos;
}
}
// then actually move the tabs
QTabBar *tabBar = ui->tabWidget->findChild<QTabBar*>("qt_tabwidget_tabbar"); // magic name = bad
ui->tabWidget->blockSignals(true);
for (int newPos = 0; newPos < count; ++newPos) {
QString tabId = tabIds.at(newPos);
int oldPos = tabIndex(tabId);
tabBar->moveTab(oldPos, newPos);
}
ui->tabWidget->blockSignals(false);
}
QByteArray ModInfoDialog::saveTabState() const
{
QByteArray result;
QDataStream stream(&result, QIODevice::WriteOnly);
stream << ui->tabWidget->count();
for (int i = 0; i < ui->tabWidget->count(); ++i) {
stream << ui->tabWidget->widget(i)->objectName();
}
return result;
}
void ModInfoDialog::refreshLists()
{
for (auto& tab : m_tabs) {
tab->update();
}
refreshFiles();
}
void ModInfoDialog::refreshFiles()
{
if (m_RootPath.length() > 0) {
QDirIterator dirIterator(m_RootPath, QDir::Files, QDirIterator::Subdirectories);
while (dirIterator.hasNext()) {
QString fileName = dirIterator.next();
for (auto& tab : m_tabs) {
if (tab->feedFile(m_RootPath, fileName)) {
break;
}
}
}
}
}
void ModInfoDialog::on_closeButton_clicked()
{
for (auto& tab : m_tabs) {
if (!tab->canClose()) {
return;
}
}
close();
}
void ModInfoDialog::openTab(int tab)
{
QTabWidget *tabWidget = findChild<QTabWidget*>("tabWidget");
if (tabWidget->isTabEnabled(tab)) {
tabWidget->setCurrentIndex(tab);
}
}
void ModInfoDialog::on_tabWidget_currentChanged(int index)
{
}
void ModInfoDialog::on_nextButton_clicked()
{
int currentTab = ui->tabWidget->currentIndex();
int tab = m_RealTabPos[currentTab];
emit modOpenNext(tab);
this->accept();
}
void ModInfoDialog::on_prevButton_clicked()
{
int currentTab = ui->tabWidget->currentIndex();
int tab = m_RealTabPos[currentTab];
emit modOpenPrev(tab);
this->accept();
}
|