Esempio n. 1
0
inline static qulonglong hash(const CFileSystemObject& object)
{
	const auto properties = object.properties();
	const auto hashData = QByteArray::fromRawData((const char*)&properties.hash, sizeof(properties.hash)) +
			QByteArray::fromRawData((const char*)&properties.modificationDate, sizeof(properties.modificationDate)) +
			QByteArray::fromRawData((const char*)&properties.type, sizeof(properties.type));

	return fasthash64(hashData.constData(), hashData.size(), 0);
}
DISABLE_COMPILER_WARNINGS
#include <QDateTime>
#include <QInputDialog>
#include <QLineEdit>
RESTORE_COMPILER_WARNINGS

CPromptDialog::CPromptDialog(QWidget *parent, Operation op, HaltReason promptReason,
	const CFileSystemObject& source, const CFileSystemObject& dest, const QString& message) :

		QDialog(parent),
		ui(new Ui::CPromptDialog),
		_response(urNone)
{
	ui->setupUi(this);

	connect(ui->btnCancel,          &QPushButton::clicked, this, &CPromptDialog::onCancelClicked);
	connect(ui->btnCancelDeletion,  &QPushButton::clicked, this, &CPromptDialog::onCancelClicked);
	connect(ui->btnDeleteAnyway,    &QPushButton::clicked, this, &CPromptDialog::onProceedClicked);
	connect(ui->btnDeleteAllAnyway, &QPushButton::clicked, this, &CPromptDialog::onProceedAllClicked);
	connect(ui->btnOverwrite,       &QPushButton::clicked, this, &CPromptDialog::onProceedClicked);
	connect(ui->btnOverwriteAll,    &QPushButton::clicked, this, &CPromptDialog::onProceedAllClicked);
	connect(ui->btnRename,          &QPushButton::clicked, this, &CPromptDialog::onRenameClicked);
	connect(ui->btnSkip,            &QPushButton::clicked, this, &CPromptDialog::onSkipClicked);
	connect(ui->btnSkipAll,         &QPushButton::clicked, this, &CPromptDialog::onSkipAllClicked);
	connect(ui->btnSkipDeletion,    &QPushButton::clicked, this, &CPromptDialog::onSkipClicked);
	connect(ui->btnSkipAllDeletion, &QPushButton::clicked, this, &CPromptDialog::onSkipAllClicked);
	connect(ui->btnRetry,           &QPushButton::clicked, this, &CPromptDialog::onRetryClicked);

	switch (promptReason)
	{
	case hrFileExists:
		ui->lblQuestion->setText("File or folder already exists.");
		break;
	case hrSourceFileIsReadOnly:
		ui->btnOverwrite->setVisible(false);
		ui->btnOverwriteAll->setVisible(false);
		ui->btnRename->setVisible(false);
		ui->lblQuestion->setText("The source file or folder is read-only.");
		break;
	case hrDestFileIsReadOnly:
		ui->lblQuestion->setText("The destination file or folder is read-only.");
		break;
	case hrFailedToMakeItemWritable:
		ui->lblQuestion->setText("Failed to make the file or folder writable.");
		ui->btnOverwrite->setVisible(false);
		ui->btnOverwriteAll->setVisible(false);
		ui->btnRename->setVisible(false);
	case hrFileDoesntExit:
		ui->lblQuestion->setText("The file or folder doesn't exist.");
		ui->btnOverwrite->setVisible(false);
		ui->btnOverwriteAll->setVisible(false);
		ui->btnRename->setVisible(false);
		ui->btnDeleteAllAnyway->setVisible(false);
		ui->btnDeleteAnyway->setVisible(false);
		break;
	case hrCreatingFolderFailed:
		ui->lblQuestion->setText(tr("Failed to create the folder\n%1").arg(source.fullAbsolutePath()));
		ui->btnOverwrite->setVisible(false);
		ui->btnOverwriteAll->setVisible(false);
		ui->btnRename->setVisible(false);
		break;
	case hrFailedToDelete:
		ui->btnOverwrite->setVisible(false);
		ui->btnOverwriteAll->setVisible(false);
		ui->btnDeleteAnyway->setVisible(false);
		ui->btnDeleteAllAnyway->setVisible(false);
		ui->btnRename->setVisible(false);
		ui->lblQuestion->setText(tr("Failed to delete\n%1").arg(source.fullAbsolutePath()));
		break;
	case hrUnknownError:
		ui->lblQuestion->setText("An unknown error occurred. What do you want to do?");
		ui->btnOverwrite->setVisible(false);
		ui->btnOverwriteAll->setVisible(false);
		ui->btnRename->setVisible(false);
		break;
	default:
		ui->lblQuestion->setText("An unknown error occurred. What do you want to do?");
		break;
	}

	if (!message.isEmpty())
		ui->lblQuestion->setText(ui->lblQuestion->text() + "\n\n" + message);

	if (op == operationDelete || promptReason == hrSourceFileIsReadOnly || promptReason == hrFailedToMakeItemWritable)
	{
		ui->stackedWidget->setCurrentIndex(1);

		ui->m_lblItemBeingDeleted->setText(source.fullAbsolutePath());
		ui->lblSize->setText(fileSizeToString(source.size()));
		QDateTime modificationDate;
		modificationDate.setTime_t((uint)source.properties().modificationDate);
		modificationDate = modificationDate.toLocalTime();
		ui->lblModTime->setText(modificationDate.toString("dd.MM.yyyy hh:mm"));
	}
	else
	{
		ui->stackedWidget->setCurrentIndex(0);

		if (source.isValid())
		{
			ui->lblSrcFile->setText(source.fullAbsolutePath());
			ui->lblSourceSize->setText(fileSizeToString(source.size()));
			QDateTime modificationDate;
			modificationDate.setTime_t((uint)source.properties().modificationDate);
			modificationDate = modificationDate.toLocalTime();
			ui->lblSourceModTime->setText(modificationDate.toString("dd.MM.yyyy hh:mm"));
		}
		else
			WidgetUtils::setLayoutVisible(ui->sourceFileInfo, false);

		if (dest.isValid())
		{
			ui->lblDstFile->setText(dest.fullAbsolutePath());
			ui->lblDestSize->setText(fileSizeToString(dest.size()));
			QDateTime modificationDate;
			modificationDate.setTime_t((uint)dest.properties().modificationDate);
			modificationDate = modificationDate.toLocalTime();
			ui->lblDestModTime->setText(modificationDate.toString("dd.MM.yyyy hh:mm"));
		}
		else
			WidgetUtils::setLayoutVisible(ui->destFileInfo, false);
	}

	_srcFileName = source.fullName();
}