|
|
@@ -1,5 +1,7 @@
|
|
|
+#include <sstream>
|
|
|
#include "conflictItemWidget.h"
|
|
|
#include "iconProvider.h"
|
|
|
+#include "htmlFont.hh"
|
|
|
|
|
|
using namespace craftlab::fakeraid;
|
|
|
|
|
|
@@ -8,9 +10,11 @@ ConflictItemWidget::ConflictItemWidget(QListWidget* parent, const QFile& file, c
|
|
|
std::filesystem::path p(file.fileName().toStdString());
|
|
|
ui.setupUi(this);
|
|
|
ui.warningIcon->setPixmap(IconProvider::WarningIcon(*this));
|
|
|
- ui.fileIcon->setPixmap(IconProvider::FromFile(file));
|
|
|
+ ui.fileIcon->resize(ui.fileIcon->baseSize());
|
|
|
+ ui.fileIcon->setPixmap(IconProvider::FromFile(file, ui.fileIcon->baseSize()));
|
|
|
ui.filename->setText(p.filename().string().c_str());
|
|
|
|
|
|
+ connect(ui.buttonUseVersion, &QPushButton::clicked, this, [this]() { SetAction(Action::UseVersion); });
|
|
|
connect(ui.buttonCopy, &QPushButton::clicked, this, [this]() { SetAction(Action::Copy); });
|
|
|
connect(ui.buttonRemove, &QPushButton::clicked, this, [this]() { SetAction(Action::Remove); });
|
|
|
connect(ui.buttonIgnore, &QPushButton::clicked, this, [this]() { SetAction(Action::Ignore); });
|
|
|
@@ -20,6 +24,7 @@ void ConflictItemWidget::SetAction(Action&& action)
|
|
|
{
|
|
|
if (currentAction != action)
|
|
|
{
|
|
|
+ ui.buttonUseVersion->setChecked(action == Action::UseVersion);
|
|
|
ui.buttonCopy->setChecked(action == Action::Copy);
|
|
|
ui.buttonRemove->setChecked(action == Action::Remove);
|
|
|
ui.buttonIgnore->setChecked(action == Action::Ignore);
|
|
|
@@ -36,21 +41,114 @@ ConflictItemWidget::Action ConflictItemWidget::GetAction() const
|
|
|
return currentAction;
|
|
|
}
|
|
|
|
|
|
+std::vector<int> ConflictItemWidget::versionExistsToVersionNumber(const std::vector<bool> exists)
|
|
|
+{
|
|
|
+ std::vector<int> versionNo;
|
|
|
+ std::transform(exists.begin(), exists.end(), std::back_inserter(versionNo), [](bool b) { return b ? 1 : 0; });
|
|
|
+ return versionNo;
|
|
|
+}
|
|
|
+
|
|
|
+std::map<int, std::vector<int>> ConflictItemWidget::groupFileByVersion(const std::vector<int>& versions)
|
|
|
+{
|
|
|
+ std::map<int, std::vector<int>> result;
|
|
|
+ int repoIndex = 0;
|
|
|
+ for (int i : versions)
|
|
|
+ result[i].push_back(repoIndex++);
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+const char* FILE_STYLE = "style=\"color:green\"";
|
|
|
+const char* REPO_STYLE = "style=\"color:blue\"";
|
|
|
+const char* VERSION_STYLE = "style=\"color:red\"";
|
|
|
+
|
|
|
+void ConflictItemWidget::listRepositories(const std::vector<int>& repo, std::stringstream& stream)
|
|
|
+{
|
|
|
+ if (repo.size() == 1)
|
|
|
+ {
|
|
|
+ stream << "repository " << HTMLFont(repo.front(), REPO_STYLE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ stream << "repositories ";
|
|
|
+ bool written = false;
|
|
|
+ for (int i : repo)
|
|
|
+ {
|
|
|
+ if (written)
|
|
|
+ stream << ", ";
|
|
|
+ stream << HTMLFont(i, REPO_STYLE);
|
|
|
+ written = true;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ConflictItemWidget::populateListStream(const std::map<int, std::vector<int>>& repoByVersion, std::stringstream& stream)
|
|
|
+{
|
|
|
+ bool missing = repoByVersion.find(0) != repoByVersion.end();
|
|
|
+
|
|
|
+ for (const std::pair<int, std::vector<int>>& versionAndRepoId : repoByVersion)
|
|
|
+ {
|
|
|
+ if (versionAndRepoId.first == 0)
|
|
|
+ {
|
|
|
+ stream << "<li>Does not exists in ";
|
|
|
+ listRepositories(versionAndRepoId.second, stream);
|
|
|
+ stream << "</li>";
|
|
|
+ }
|
|
|
+ else if (repoByVersion.size() == 2 && missing)
|
|
|
+ {
|
|
|
+ stream << "<li>Do exists in ";
|
|
|
+ listRepositories(versionAndRepoId.second, stream);
|
|
|
+ stream << "</li>";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ stream << "<li>Have version " << HTMLFont(versionAndRepoId.first, VERSION_STYLE) << " in ";
|
|
|
+ listRepositories(versionAndRepoId.second, stream);
|
|
|
+ stream << "</li>";
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
ConflictItemWidget* ConflictItemWidget::FromMissingFile(QListWidget* parent, const std::vector<std::string>& rootPaths, const std::string& filename, const std::vector<bool>& version)
|
|
|
{
|
|
|
const std::string fullPathFirstFound = rootPaths[std::distance(version.begin(), std::find(version.begin(), version.end(), true))] + "/" + filename;
|
|
|
ConflictItemWidget* result = new ConflictItemWidget(parent, QFile(fullPathFirstFound.c_str()), filename);
|
|
|
+ result->ui.buttonUseVersion->setVisible(false);
|
|
|
+ result->ui.ddUseVersion->setVisible(false);
|
|
|
+ std::stringstream ss;
|
|
|
+ ss << "File " << HTMLFont(filename, FILE_STYLE) << " does not exists in every repositories: <ul>";
|
|
|
+ populateListStream(groupFileByVersion(versionExistsToVersionNumber(version)), ss);
|
|
|
+ ss << "</ul>";
|
|
|
+ result->ui.labelIssue->setText(ss.str().c_str());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
ConflictItemWidget* ConflictItemWidget::FromMissingDir(QListWidget* parent, const std::vector<std::string>& rootPaths, const std::string& filename, const std::vector<bool>& version)
|
|
|
{
|
|
|
- return FromMissingFile(parent, rootPaths, filename, version);
|
|
|
+ const std::string fullPathFirstFound = rootPaths[std::distance(version.begin(), std::find(version.begin(), version.end(), true))] + "/" + filename;
|
|
|
+ ConflictItemWidget* result = new ConflictItemWidget(parent, QFile(fullPathFirstFound.c_str()), filename);
|
|
|
+ result->ui.buttonUseVersion->setVisible(false);
|
|
|
+ result->ui.ddUseVersion->setVisible(false);
|
|
|
+ std::stringstream ss;
|
|
|
+ ss << "Folder " << HTMLFont(filename, FILE_STYLE) << " does not exists in every repositories: <ul>";
|
|
|
+ populateListStream(groupFileByVersion(versionExistsToVersionNumber(version)), ss);
|
|
|
+ ss << "</ul>";
|
|
|
+ result->ui.labelIssue->setText(ss.str().c_str());
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
ConflictItemWidget* ConflictItemWidget::FromConflict(QListWidget* parent, const std::vector<std::string>& rootPaths, const std::string& filename, const std::vector<int>& version)
|
|
|
{
|
|
|
- const std::string fullPathFirstFound = rootPaths[std::distance(version.begin(), std::find(version.begin(), version.end(), true))] + "/" + filename;
|
|
|
+ const std::string fullPathFirstFound = rootPaths[std::distance(version.begin(), std::find_if(version.begin(), version.end(), [](const int& val) { return val != 0; }))] + "/" + filename;
|
|
|
ConflictItemWidget* result = new ConflictItemWidget(parent, QFile(fullPathFirstFound.c_str()), filename);
|
|
|
+ const auto fileByVersion = groupFileByVersion(version);
|
|
|
+ for (const auto& i : fileByVersion)
|
|
|
+ if (i.first)
|
|
|
+ result->ui.ddUseVersion->addItem("Use version " +QString::number(i.first), i.first);
|
|
|
+ result->ui.ddUseVersion->setCurrentIndex(0);
|
|
|
+ result->ui.buttonCopy->setVisible(false);
|
|
|
+
|
|
|
+ std::stringstream ss;
|
|
|
+ ss << "Found different versions for file " << HTMLFont(filename, FILE_STYLE) << ": <ul>";
|
|
|
+ populateListStream(fileByVersion, ss);
|
|
|
+ ss << "</ul>";
|
|
|
+ result->ui.labelIssue->setText(ss.str().c_str());
|
|
|
return result;
|
|
|
}
|