|
|
@@ -1,9 +1,8 @@
|
|
|
-#include <QMessageBox>
|
|
|
#include <QDesktopServices>
|
|
|
+#include <QProgressDialog>
|
|
|
+#include <QMessageBox>
|
|
|
#include <QFile>
|
|
|
#include <QDir>
|
|
|
-#include <QUrl>
|
|
|
-#include <QProgressDialog>
|
|
|
#include "ui_MainWindow.h"
|
|
|
#include "mainWindow.h"
|
|
|
#include "conflictModal.h"
|
|
|
@@ -18,7 +17,7 @@ using namespace craftlab::fakeraid::ui;
|
|
|
std::string mergePath(const std::string& a, const std::string& b);
|
|
|
|
|
|
MainWindow::MainWindow(const std::vector<std::string>& dirList)
|
|
|
- : fileListItemModel(std::make_unique<QStandardItemModel>(this)),
|
|
|
+ : fileListItemModel(std::make_unique<MStandardItemModel>(this)),
|
|
|
ui(std::make_unique<Ui_MainWindow>()),
|
|
|
fileWatcher(new QFileSystemWatcher())
|
|
|
{
|
|
|
@@ -28,12 +27,16 @@ MainWindow::MainWindow(const std::vector<std::string>& dirList)
|
|
|
ui->listView->setModel(fileListItemModel.get());
|
|
|
ui->listView->setItemDelegate(new FileItemDelegate(this));
|
|
|
ui->listView->setContextMenuPolicy(Qt::ContextMenuPolicy::ActionsContextMenu);
|
|
|
+ ui->listView->setMovement(QListView::Movement::Snap);
|
|
|
+ ui->listView->setGridSize(QSize(64, 64));
|
|
|
ui->breadcrumb->setFixedHeight(36);
|
|
|
|
|
|
connect(ui->actionOuvrir, &QAction::triggered, this, &MainWindow::MenuBarActionTrigerred);
|
|
|
connect(ui->actionRefresh, &QAction::triggered, this, &MainWindow::OnPathChanged);
|
|
|
connect(ui->actionScan_for_errors, &QAction::triggered, this, &MainWindow::RequestDeepScan);
|
|
|
connect(ui->listView, &QListView::doubleClicked, this, &MainWindow::FileListItemEntered);
|
|
|
+ connect(ui->listView, &MListView::OnDropAction, this, &MainWindow::OnFileDropped);
|
|
|
+ connect(ui->breadcrumb, &MBreadcrumb::OnDropAction, this, &MainWindow::OnFileDropped);
|
|
|
connect(ui->breadcrumb, &craftlab::ui::Breadcrumb::SelectionChanged, this, &MainWindow::OnBreadcrumbSelection);
|
|
|
ui->listView->addAction("Open", [this]() { FileListItemEntered(ui->listView->currentIndex()); });
|
|
|
#ifdef _WIN32
|
|
|
@@ -108,7 +111,7 @@ void MainWindow::FileListItemEntered(const QModelIndex& index)
|
|
|
{
|
|
|
if (index.isValid() && currentDiffResult)
|
|
|
{
|
|
|
- const auto& fileIter = currentDiffResult->FileList.find(qvariant_cast<QString>(index.data(Qt::DisplayRole)).toStdString());
|
|
|
+ const auto& fileIter = currentDiffResult->FileList.find(qvariant_cast<QString>(index.data(Qt::UserRole +1)).toStdString());
|
|
|
if (fileIter != currentDiffResult->FileList.end())
|
|
|
OnListViewDoubleClick(fileIter->second);
|
|
|
}
|
|
|
@@ -119,7 +122,7 @@ void MainWindow::OpenContainingFolders(const QModelIndex& index)
|
|
|
#ifdef _WIN32
|
|
|
if (index.isValid() && currentDiffResult)
|
|
|
{
|
|
|
- const auto& fileIter = currentDiffResult->FileList.find(qvariant_cast<QString>(index.data(Qt::DisplayRole)).toStdString());
|
|
|
+ const auto& fileIter = currentDiffResult->FileList.find(qvariant_cast<QString>(index.data(Qt::UserRole + 1)).toStdString());
|
|
|
if (fileIter != currentDiffResult->FileList.end())
|
|
|
OpenContainingFolders(fileIter->second);
|
|
|
}
|
|
|
@@ -165,7 +168,7 @@ void MainWindow::OnBreadcrumbSelection(int index)
|
|
|
|
|
|
void MainWindow::UpdateBreadcrumb()
|
|
|
{
|
|
|
- craftlab::ui::Breadcrumb* breadcrumb = ui->breadcrumb;
|
|
|
+ MBreadcrumb* breadcrumb = ui->breadcrumb;
|
|
|
breadcrumb->clear();
|
|
|
breadcrumb->addItem("/");
|
|
|
for (const std::string& path : engine->GetCurrentDir())
|
|
|
@@ -177,14 +180,14 @@ void MainWindow::UpdateFileList()
|
|
|
fileListItemModel->clear();
|
|
|
std::sort(currentDiffResult->correctFiles.begin(), currentDiffResult->correctFiles.end(), [](const File& a, const File& b) { return a.fileName < b.fileName; });
|
|
|
for (const File& file : currentDiffResult->correctFiles)
|
|
|
- fileListItemModel->appendRow(new FileItem(*ui->listView, engine->GetRootPaths(), file));
|
|
|
+ fileListItemModel->appendRow(new FileItem(*engine.get(), *ui->listView, engine->GetRootPaths(), file));
|
|
|
std::vector<std::string> allFilenames;
|
|
|
std::transform(currentDiffResult->differentFiles.begin(), currentDiffResult->differentFiles.end(), std::back_inserter(allFilenames), [](const std::pair<std::string, std::vector<int>>& i) { return i.first; });
|
|
|
std::transform(currentDiffResult->missingFiles.begin(), currentDiffResult->missingFiles.end(), std::back_inserter(allFilenames), [](const std::pair<std::string, std::vector<bool>>& i) { return i.first; });
|
|
|
std::transform(currentDiffResult->missingDirs.begin(), currentDiffResult->missingDirs.end(), std::back_inserter(allFilenames), [](const std::pair<std::string, std::vector<bool>>& i) { return i.first; });
|
|
|
std::sort(allFilenames.begin(), allFilenames.end());
|
|
|
for (const std::string& file : allFilenames)
|
|
|
- fileListItemModel->appendRow(new FileItem(*ui->listView, engine->GetRootPaths(), currentDiffResult->FileList[file], false));
|
|
|
+ fileListItemModel->appendRow(new FileItem(*engine.get(), *ui->listView, engine->GetRootPaths(), currentDiffResult->FileList[file], false));
|
|
|
}
|
|
|
|
|
|
void MainWindow::ListFiles(bool ignoreErrors)
|
|
|
@@ -291,6 +294,49 @@ bool MainWindow::TryOpenningDir(const std::vector<std::string>& folders)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+bool MainWindow::OnFileDroppedImpl(const std::vector<std::string>& files, const std::string& dropTo)
|
|
|
+{
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (engine->AnyFileExists(files, dropTo))
|
|
|
+ {
|
|
|
+ if (QMessageBox::question(window.get(), "FakeRaid", "Override existing files ?", QMessageBox::StandardButton::Yes, QMessageBox::StandardButton::No) == QMessageBox::StandardButton::No)
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (const IEngine::SameFileError& e)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ engine->AddFiles(files, dropTo);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::OnFileDropped(const QList<QUrl>& files, const std::optional<std::string>& dropTo)
|
|
|
+{
|
|
|
+ std::vector<std::string> input;
|
|
|
+ std::transform(files.begin(), files.end(), std::back_inserter(input), [](const QUrl& url){ return url.toLocalFile().toStdString(); });
|
|
|
+ bool shouldReload = true;
|
|
|
+
|
|
|
+ if (dropTo == std::nullopt)
|
|
|
+ {
|
|
|
+ if (!OnFileDroppedImpl(input, engine->BuildCurrentDirPath("", engine->GetCurrentDir())))
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (!OnFileDroppedImpl(input, *dropTo))
|
|
|
+ return;
|
|
|
+
|
|
|
+ QFileInfo actualDir = QFileInfo(engine->BuildCurrentDirPath("", engine->GetCurrentDir()).c_str());
|
|
|
+ QFileInfo dropLocation = QFileInfo(dropTo->c_str());
|
|
|
+ if (actualDir != dropLocation)
|
|
|
+ shouldReload = false;
|
|
|
+ }
|
|
|
+ if (shouldReload)
|
|
|
+ ListFiles(true);
|
|
|
+}
|
|
|
+
|
|
|
void MainWindow::DisplaySourceWindow(bool canCancel, const std::vector<std::string>& previous)
|
|
|
{
|
|
|
const std::vector<std::string> folders = BrowseModal::Display(canCancel, previous);
|