diff options
Diffstat (limited to 'src/mainwindow.cpp')
| -rw-r--r-- | src/mainwindow.cpp | 58 |
1 files changed, 21 insertions, 37 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index cdc048fd..69f90ce4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -430,7 +430,10 @@ MainWindow::MainWindow(Settings &settings this, &MainWindow::refresherProgress); connect(m_OrganizerCore.directoryRefresher(), SIGNAL(error(QString)), this, SLOT(showError(QString))); - connect(&m_SavesWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(refreshSavesIfOpen())); + m_SavesWatcherTimer.setSingleShot(true); + m_SavesWatcherTimer.setInterval(500); + connect(&m_SavesWatcher, &QFileSystemWatcher::directoryChanged, [this]() { m_SavesWatcherTimer.start(); }); + connect(&m_SavesWatcherTimer, &QTimer::timeout, this, &MainWindow::refreshSavesIfOpen); connect(&m_OrganizerCore.settings(), SIGNAL(languageChanged(QString)), this, SLOT(languageChange(QString))); connect(&m_OrganizerCore.settings(), SIGNAL(styleChanged(QString)), this, SIGNAL(styleChanged(QString))); @@ -508,6 +511,7 @@ MainWindow::MainWindow(Settings &settings m_Tutorial.expose("espList", m_OrganizerCore.pluginList()); m_OrganizerCore.setUserInterface(this); + m_PluginContainer.setUserInterface(this); connect(this, &MainWindow::userInterfaceInitialized, &m_OrganizerCore, &OrganizerCore::userInterfaceInitialized); for (const QString &fileName : m_PluginContainer.pluginFileNames()) { installTranslator(QFileInfo(fileName).baseName()); @@ -700,7 +704,7 @@ MainWindow::~MainWindow() try { cleanup(); - m_PluginContainer.setUserInterface(nullptr, nullptr); + m_PluginContainer.setUserInterface(nullptr); m_OrganizerCore.setUserInterface(nullptr); if (m_IntegratedBrowser) { @@ -1529,7 +1533,6 @@ void MainWindow::displaySaveGameInfo(QListWidgetItem *newItem) return; } - QString const &save = newItem->data(Qt::UserRole).toString(); if (m_CurrentSaveView == nullptr) { IPluginGame const *game = m_OrganizerCore.managedGame(); SaveGameInfo const *info = game->feature<SaveGameInfo>(); @@ -1540,7 +1543,7 @@ void MainWindow::displaySaveGameInfo(QListWidgetItem *newItem) return; } } - m_CurrentSaveView->setSave(save); + m_CurrentSaveView->setSave(*m_SaveGames[ui->savegameList->row(newItem)]); QWindow *window = m_CurrentSaveView->window()->windowHandle(); QRect screenRect; @@ -1674,7 +1677,6 @@ void MainWindow::updateToolMenu() void MainWindow::registerModPage(IPluginModPage *modPage) { QAction *action = new QAction(modPage->icon(), modPage->displayName(), this); - modPage->setParentWidget(this); connect(action, &QAction::triggered, this, [this, modPage]() { if (modPage->useIntegratedBrowser()) { @@ -1961,36 +1963,23 @@ void MainWindow::stopMonitorSaves() void MainWindow::refreshSaveList() { - ui->savegameList->clear(); + TimeThis tt("MainWindow::refreshSaveList()"); startMonitorSaves(); // re-starts monitoring - QStringList filters; - filters << QString("*.") + m_OrganizerCore.managedGame()->savegameExtension(); - QDir savesDir = currentSavesDir(); - savesDir.setNameFilters(filters); - savesDir.setFilter(QDir::Files); - QDirIterator it(savesDir, QDirIterator::Subdirectories); - log::debug("reading save games from {}", savesDir.absolutePath()); - - QFileInfoList files; - while (it.hasNext()) { - it.next(); - files.append(it.fileInfo()); - } - std::sort(files.begin(), files.end(), [](auto const& lhs, auto const& rhs) { - return lhs.fileTime(QFileDevice::FileModificationTime) > rhs.fileTime(QFileDevice::FileModificationTime); + MOBase::log::debug("reading save games from {}", savesDir.absolutePath()); + m_SaveGames = m_OrganizerCore.managedGame()->listSaves(savesDir); + std::sort(m_SaveGames.begin(), m_SaveGames.end(), [](auto const& lhs, auto const& rhs) { + return lhs->getCreationTime() > rhs->getCreationTime(); }); - for (const QFileInfo &file : files) { - QListWidgetItem *item = new QListWidgetItem(savesDir.relativeFilePath(file.absoluteFilePath())); - item->setData(Qt::UserRole, file.absoluteFilePath()); - ui->savegameList->addItem(item); + ui->savegameList->clear(); + for (auto& save: m_SaveGames) { + ui->savegameList->addItem(savesDir.relativeFilePath(save->getFilepath())); } } - static bool BySortValue(const std::pair<UINT32, QTreeWidgetItem*> &LHS, const std::pair<UINT32, QTreeWidgetItem*> &RHS) { return LHS.first < RHS.first; @@ -4957,20 +4946,15 @@ void MainWindow::deleteSavegame_clicked() int count = 0; for (const QModelIndex &idx : ui->savegameList->selectionModel()->selectedIndexes()) { - QString name = idx.data(Qt::UserRole).toString(); + + auto& saveGame = m_SaveGames[idx.row()]; if (count < 10) { - savesMsgLabel += "<li>" + QFileInfo(name).completeBaseName() + "</li>"; + savesMsgLabel += "<li>" + QFileInfo(saveGame->getFilepath()).completeBaseName() + "</li>"; } ++count; - if (info == nullptr) { - deleteFiles.push_back(name); - } else { - ISaveGame const *save = info->getSaveGameInfo(name); - deleteFiles += save->allFiles(); - delete save; - } + deleteFiles += saveGame->allFiles(); } if (count > 10) { @@ -5029,8 +5013,8 @@ void MainWindow::on_savegameList_customContextMenuRequested(const QPoint& pos) QAction* action = menu.addAction(tr("Enable Mods...")); action->setEnabled(false); if (selection->selectedIndexes().count() == 1) { - QString save = ui->savegameList->currentItem()->data(Qt::UserRole).toString(); - SaveGameInfo::MissingAssets missing = info->getMissingAssets(save); + auto& save = m_SaveGames[selection->selectedIndexes()[0].row()]; + SaveGameInfo::MissingAssets missing = info->getMissingAssets(*save); if (missing.size() != 0) { connect(action, &QAction::triggered, this, [this, missing] { fixMods_clicked(missing); }); action->setEnabled(true); |
