// Returns true if this object is a child of parent, either direct or indirect bool CFileSystemObject::isChildOf(const CFileSystemObject &parent) const { if (!isValid() || !parent.isValid()) return false; if (fullAbsolutePath().startsWith(parent.fullAbsolutePath(), caseSensitiveFilesystem() ? Qt::CaseSensitive : Qt::CaseInsensitive)) return true; if (!isSymLink() && !parent.isSymLink()) return false; const auto resolvedChildLink = isSymLink() ? symLinkTarget() : fullAbsolutePath(); const auto resolvedParentLink = parent.isSymLink() ? parent.symLinkTarget() : parent.fullAbsolutePath(); assert_and_return_r(!resolvedChildLink.isEmpty() && !resolvedParentLink.isEmpty(), false); return resolvedChildLink.startsWith(resolvedParentLink, caseSensitiveFilesystem() ? Qt::CaseSensitive : Qt::CaseInsensitive); }
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(); }