mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
bug-fix: compare two paths with case convertion on Windows
On Windows, case difference in file name is ignored.
This commit is contained in:
parent
a802222b06
commit
a87048cac2
@ -18,12 +18,13 @@ void VDeleteNotebookDialog::setupUI(const QString &p_title, const QString &p_nam
|
|||||||
m_warningLabel = new QLabel();
|
m_warningLabel = new QLabel();
|
||||||
m_warningLabel->setWordWrap(true);
|
m_warningLabel->setWordWrap(true);
|
||||||
|
|
||||||
m_notDeleteCheck = new QCheckBox(tr("Do not delete files from disk."), this);
|
m_deleteCheck = new QCheckBox(tr("Delete files from disk"), this);
|
||||||
m_notDeleteCheck->setChecked(true);
|
m_deleteCheck->setChecked(false);
|
||||||
m_notDeleteCheck->setToolTip(tr("When checked, VNote just removes the notebook instead of deleting files from disk"));
|
m_deleteCheck->setToolTip(tr("When checked, VNote will delete all the files within this notebook from disk"));
|
||||||
connect(m_notDeleteCheck, &QCheckBox::stateChanged, this, &VDeleteNotebookDialog::notDeleteCheckChanged);
|
connect(m_deleteCheck, &QCheckBox::stateChanged,
|
||||||
|
this, &VDeleteNotebookDialog::deleteCheckChanged);
|
||||||
|
|
||||||
notDeleteCheckChanged(true);
|
deleteCheckChanged(false);
|
||||||
|
|
||||||
// Ok is the default button.
|
// Ok is the default button.
|
||||||
m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
@ -49,7 +50,7 @@ void VDeleteNotebookDialog::setupUI(const QString &p_title, const QString &p_nam
|
|||||||
|
|
||||||
QVBoxLayout *infoLayout = new QVBoxLayout();
|
QVBoxLayout *infoLayout = new QVBoxLayout();
|
||||||
infoLayout->addWidget(infoLabel);
|
infoLayout->addWidget(infoLabel);
|
||||||
infoLayout->addWidget(m_notDeleteCheck);
|
infoLayout->addWidget(m_deleteCheck);
|
||||||
infoLayout->addWidget(m_warningLabel);
|
infoLayout->addWidget(m_warningLabel);
|
||||||
|
|
||||||
QHBoxLayout *topLayout = new QHBoxLayout();
|
QHBoxLayout *topLayout = new QHBoxLayout();
|
||||||
@ -67,7 +68,7 @@ void VDeleteNotebookDialog::setupUI(const QString &p_title, const QString &p_nam
|
|||||||
|
|
||||||
bool VDeleteNotebookDialog::getDeleteFiles() const
|
bool VDeleteNotebookDialog::getDeleteFiles() const
|
||||||
{
|
{
|
||||||
return !m_notDeleteCheck->isChecked();
|
return m_deleteCheck->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap VDeleteNotebookDialog::standardIcon(QMessageBox::Icon p_icon)
|
QPixmap VDeleteNotebookDialog::standardIcon(QMessageBox::Icon p_icon)
|
||||||
@ -104,9 +105,9 @@ QPixmap VDeleteNotebookDialog::standardIcon(QMessageBox::Icon p_icon)
|
|||||||
return QPixmap();
|
return QPixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VDeleteNotebookDialog::notDeleteCheckChanged(int p_state)
|
void VDeleteNotebookDialog::deleteCheckChanged(int p_state)
|
||||||
{
|
{
|
||||||
if (p_state) {
|
if (!p_state) {
|
||||||
m_warningLabel->setText(tr("VNote won't delete files in directory <span style=\"%1\">%2</span>.")
|
m_warningLabel->setText(tr("VNote won't delete files in directory <span style=\"%1\">%2</span>.")
|
||||||
.arg(vconfig.c_dataTextStyle).arg(m_path));
|
.arg(vconfig.c_dataTextStyle).arg(m_path));
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,10 +16,12 @@ class VDeleteNotebookDialog : public QDialog
|
|||||||
public:
|
public:
|
||||||
VDeleteNotebookDialog(const QString &p_title, const QString &p_name, const QString &p_path,
|
VDeleteNotebookDialog(const QString &p_title, const QString &p_name, const QString &p_path,
|
||||||
QWidget *p_parent = 0);
|
QWidget *p_parent = 0);
|
||||||
|
|
||||||
|
// Whether delete files from disk.
|
||||||
bool getDeleteFiles() const;
|
bool getDeleteFiles() const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void notDeleteCheckChanged(int p_state);
|
void deleteCheckChanged(int p_state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupUI(const QString &p_title, const QString &p_name);
|
void setupUI(const QString &p_title, const QString &p_name);
|
||||||
@ -27,7 +29,7 @@ private:
|
|||||||
|
|
||||||
QString m_path;
|
QString m_path;
|
||||||
QLabel *m_warningLabel;
|
QLabel *m_warningLabel;
|
||||||
QCheckBox *m_notDeleteCheck;
|
QCheckBox *m_deleteCheck;
|
||||||
QDialogButtonBox *m_btnBox;
|
QDialogButtonBox *m_btnBox;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -96,7 +96,9 @@ QString VNewNotebookDialog::getNameInput() const
|
|||||||
|
|
||||||
QString VNewNotebookDialog::getPathInput() const
|
QString VNewNotebookDialog::getPathInput() const
|
||||||
{
|
{
|
||||||
return QDir::cleanPath(pathEdit->text());
|
// absoluteFilePath() to convert the drive to upper case.
|
||||||
|
// cleanPath() to remove duplicate separator, '.', and '..'.
|
||||||
|
return QDir::cleanPath(QFileInfo(pathEdit->text()).absoluteFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString VNewNotebookDialog::getImageFolder() const
|
QString VNewNotebookDialog::getImageFolder() const
|
||||||
@ -205,9 +207,8 @@ void VNewNotebookDialog::handleInputChanged()
|
|||||||
if (pathOk) {
|
if (pathOk) {
|
||||||
// Check if this path has been in VNote.
|
// Check if this path has been in VNote.
|
||||||
int idx = -1;
|
int idx = -1;
|
||||||
path = QDir::cleanPath(path);
|
|
||||||
for (idx = 0; idx < m_notebooks.size(); ++idx) {
|
for (idx = 0; idx < m_notebooks.size(); ++idx) {
|
||||||
if (QDir::cleanPath(m_notebooks[idx]->getPath()) == path) {
|
if (VUtils::equalPath(m_notebooks[idx]->getPath(), path)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,7 +262,8 @@ bool VNewNotebookDialog::autoComplete()
|
|||||||
|
|
||||||
QString vnoteFolder = vconfig.getVnoteNotebookFolderPath();
|
QString vnoteFolder = vconfig.getVnoteNotebookFolderPath();
|
||||||
QString pathText = pathEdit->text();
|
QString pathText = pathEdit->text();
|
||||||
if (!pathText.isEmpty() && vnoteFolder != VUtils::basePathFromPath(pathText)) {
|
if (!pathText.isEmpty()
|
||||||
|
&& !VUtils::equalPath(vnoteFolder, VUtils::basePathFromPath(pathText))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,6 +610,13 @@ bool VUtils::checkPathLegal(const QString &p_path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (QFileInfo::exists(p_path)) {
|
if (QFileInfo::exists(p_path)) {
|
||||||
|
#if defined(Q_OS_WIN)
|
||||||
|
// On Windows, "/" and ":" will also make exists() return true.
|
||||||
|
if (p_path.startsWith('/') || p_path == ":") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -626,6 +633,14 @@ bool VUtils::checkPathLegal(const QString &p_path)
|
|||||||
|
|
||||||
if (QFileInfo::exists(basePath)) {
|
if (QFileInfo::exists(basePath)) {
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
|
#if defined(Q_OS_WIN)
|
||||||
|
// On Windows, "/" and ":" will also make exists() return true.
|
||||||
|
if (basePath.startsWith('/') || basePath == ":") {
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -636,3 +651,16 @@ bool VUtils::checkPathLegal(const QString &p_path)
|
|||||||
delete validator;
|
delete validator;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VUtils::equalPath(const QString &p_patha, const QString &p_pathb)
|
||||||
|
{
|
||||||
|
QString a = QDir::cleanPath(p_patha);
|
||||||
|
QString b = QDir::cleanPath(p_pathb);
|
||||||
|
|
||||||
|
#if defined(Q_OS_WIN)
|
||||||
|
a = a.toLower();
|
||||||
|
b = b.toLower();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return a == b;
|
||||||
|
}
|
||||||
|
@ -106,6 +106,9 @@ public:
|
|||||||
// Try to check if @p_path is legal.
|
// Try to check if @p_path is legal.
|
||||||
static bool checkPathLegal(const QString &p_path);
|
static bool checkPathLegal(const QString &p_path);
|
||||||
|
|
||||||
|
// Returns true if @p_patha and @p_pathb points to the same file/directory.
|
||||||
|
static bool equalPath(const QString &p_patha, const QString &p_pathb);
|
||||||
|
|
||||||
// Regular expression for image link.
|
// Regular expression for image link.
|
||||||
// 
|
// 
|
||||||
// Captured texts (need to be trimmed):
|
// Captured texts (need to be trimmed):
|
||||||
|
@ -484,7 +484,7 @@ VFile *VDirectory::copyFile(VDirectory *p_destDir, const QString &p_destName,
|
|||||||
{
|
{
|
||||||
QString srcPath = QDir::cleanPath(p_srcFile->retrivePath());
|
QString srcPath = QDir::cleanPath(p_srcFile->retrivePath());
|
||||||
QString destPath = QDir::cleanPath(QDir(p_destDir->retrivePath()).filePath(p_destName));
|
QString destPath = QDir::cleanPath(QDir(p_destDir->retrivePath()).filePath(p_destName));
|
||||||
if (srcPath == destPath) {
|
if (VUtils::equalPath(srcPath, destPath)) {
|
||||||
return p_srcFile;
|
return p_srcFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,7 +554,7 @@ VFile *VDirectory::copyFile(VDirectory *p_destDir, const QString &p_destName,
|
|||||||
destImagePath = QDir(destImagePath).filePath(VUtils::fileNameFromPath(link.m_path));
|
destImagePath = QDir(destImagePath).filePath(VUtils::fileNameFromPath(link.m_path));
|
||||||
|
|
||||||
// Copy or Cut the images accordingly.
|
// Copy or Cut the images accordingly.
|
||||||
if (destImagePath == link.m_path) {
|
if (VUtils::equalPath(destImagePath, link.m_path)) {
|
||||||
ret = false;
|
ret = false;
|
||||||
} else {
|
} else {
|
||||||
ret = VUtils::copyFile(link.m_path, destImagePath, p_cut);
|
ret = VUtils::copyFile(link.m_path, destImagePath, p_cut);
|
||||||
@ -607,7 +607,7 @@ VDirectory *VDirectory::copyDirectory(VDirectory *p_destDir, const QString &p_de
|
|||||||
{
|
{
|
||||||
QString srcPath = QDir::cleanPath(p_srcDir->retrivePath());
|
QString srcPath = QDir::cleanPath(p_srcDir->retrivePath());
|
||||||
QString destPath = QDir::cleanPath(QDir(p_destDir->retrivePath()).filePath(p_destName));
|
QString destPath = QDir::cleanPath(QDir(p_destDir->retrivePath()).filePath(p_destName));
|
||||||
if (srcPath == destPath) {
|
if (VUtils::equalPath(srcPath, destPath)) {
|
||||||
return p_srcDir;
|
return p_srcDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,7 +619,7 @@ bool VDirectoryTree::copyDirectory(VDirectory *p_destDir, const QString &p_destN
|
|||||||
QString srcName = p_srcDir->getName();
|
QString srcName = p_srcDir->getName();
|
||||||
QString srcPath = QDir::cleanPath(p_srcDir->retrivePath());
|
QString srcPath = QDir::cleanPath(p_srcDir->retrivePath());
|
||||||
QString destPath = QDir::cleanPath(QDir(p_destDir->retrivePath()).filePath(p_destName));
|
QString destPath = QDir::cleanPath(QDir(p_destDir->retrivePath()).filePath(p_destName));
|
||||||
if (srcPath == destPath) {
|
if (VUtils::equalPath(srcPath, destPath)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,8 @@ FileType VFile::getType() const
|
|||||||
|
|
||||||
bool VFile::isInternalImageFolder(const QString &p_path) const
|
bool VFile::isInternalImageFolder(const QString &p_path) const
|
||||||
{
|
{
|
||||||
return VUtils::basePathFromPath(p_path) == getDirectory()->retrivePath();
|
return VUtils::equalPath(VUtils::basePathFromPath(p_path),
|
||||||
|
getDirectory()->retrivePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl VFile::getBaseUrl() const
|
QUrl VFile::getBaseUrl() const
|
||||||
|
@ -485,7 +485,7 @@ bool VFileList::copyFile(VDirectory *p_destDir, const QString &p_destName, VFile
|
|||||||
{
|
{
|
||||||
QString srcPath = QDir::cleanPath(p_file->retrivePath());
|
QString srcPath = QDir::cleanPath(p_file->retrivePath());
|
||||||
QString destPath = QDir::cleanPath(QDir(p_destDir->retrivePath()).filePath(p_destName));
|
QString destPath = QDir::cleanPath(QDir(p_destDir->retrivePath()).filePath(p_destName));
|
||||||
if (srcPath == destPath) {
|
if (VUtils::equalPath(srcPath, destPath)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ void VMdEdit::clearUnusedImages()
|
|||||||
|
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; j < images.size(); ++j) {
|
for (j = 0; j < images.size(); ++j) {
|
||||||
if (link.m_path == images[j].m_path) {
|
if (VUtils::equalPath(link.m_path, images[j].m_path)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ void VMdEdit::clearUnusedImages()
|
|||||||
|
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; j < images.size(); ++j) {
|
for (j = 0; j < images.size(); ++j) {
|
||||||
if (link.m_path == images[j].m_path) {
|
if (VUtils::equalPath(link.m_path, images[j].m_path)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,8 @@ void VOrphanFile::setContent(const QString & /* p_content */)
|
|||||||
|
|
||||||
bool VOrphanFile::isInternalImageFolder(const QString &p_path) const
|
bool VOrphanFile::isInternalImageFolder(const QString &p_path) const
|
||||||
{
|
{
|
||||||
return VUtils::basePathFromPath(p_path) == VUtils::basePathFromPath(m_path);
|
return VUtils::equalPath(VUtils::basePathFromPath(p_path),
|
||||||
|
VUtils::basePathFromPath(m_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VOrphanFile::rename(const QString &p_name)
|
bool VOrphanFile::rename(const QString &p_name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user