解决导出/保存/另存为与保存路径文件同名时,未做替换文件提醒的问题-BUG 807

This commit is contained in:
luoliangyi 2023-12-11 11:38:34 +08:00
parent c553dbbbec
commit 6e3db40cd0
7 changed files with 92 additions and 150 deletions

View File

@ -40,10 +40,8 @@ Dialog_Export::Dialog_Export(int total, const std::vector<int> &selectedIndexs,
m_supportType.push_back(SupportType(".pdf", "PDF - Portable Document Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES | FILE_TYPE_ATTR_MORE_OPTIONS)); m_supportType.push_back(SupportType(".pdf", "PDF - Portable Document Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES | FILE_TYPE_ATTR_MORE_OPTIONS));
m_supportType.push_back(SupportType(".ofd", "OFD - Open Fixed-layout Document", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES | FILE_TYPE_ATTR_MORE_OPTIONS)); m_supportType.push_back(SupportType(".ofd", "OFD - Open Fixed-layout Document", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES | FILE_TYPE_ATTR_MORE_OPTIONS));
m_supportType.push_back(SupportType(".gif", "GIF - Graphics Interchange Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES)); m_supportType.push_back(SupportType(".gif", "GIF - Graphics Interchange Format", FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES));
#if 0
if (!getOcrPath().empty()) #if !defined (x86_64) && !defined (loongarch64)
m_supportType.push_back(SupportType(".pdf", "OCR->PDF - Portable Document Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES));
#elif !defined (x86_64) && !defined (loongarch64)
m_supportType.push_back(SupportType(".pdf", "OCR->PDF - Portable Document Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES)); m_supportType.push_back(SupportType(".pdf", "OCR->PDF - Portable Document Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES));
m_supportType.push_back(SupportType(".ofd", "OCR->OFD - Open Fixed-layout Document", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES)); m_supportType.push_back(SupportType(".ofd", "OCR->OFD - Open Fixed-layout Document", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES));
m_supportType.push_back(SupportType(".rtf", "OCR->RTF - Rich Text Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES)); m_supportType.push_back(SupportType(".rtf", "OCR->RTF - Rich Text Format", FILE_TYPE_ATTR_THIRD_HANDLER | FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES));
@ -55,14 +53,6 @@ Dialog_Export::Dialog_Export(int total, const std::vector<int> &selectedIndexs,
ui->fileDialog->setOption(QFileDialog::ReadOnly, true); // disable 'Delete' menu item ui->fileDialog->setOption(QFileDialog::ReadOnly, true); // disable 'Delete' menu item
ui->fileDialog->setSizeGripEnabled(false); ui->fileDialog->setSizeGripEnabled(false);
// ui->fileDialog->setNameFilter("JPG - JPEG / JFIF(*.jpg);;"
// "BMP - Windows Bitmap(*.bmp);;"
// "PNG - Portable Network Graphics(*.png);;"
// "TIF - TIFF Revision 6(*.tif);;"
// "PDF - Portable Document Format(*.pdf);;"
// "OFD - Open Fixed-layout Document(*.ofd);;"
// "OCR->PDF - Portable Document Format(*.pdf);;"
// "OCR->OFD - Open Fixed-layout Document(*.ofd)");
QStringList filters; QStringList filters;
for(int i = 0; i < m_supportType.size(); ++i) for(int i = 0; i < m_supportType.size(); ++i)
filters.push_back(m_supportType[i].title + "(*" + m_supportType[i].ext + ")"); filters.push_back(m_supportType[i].title + "(*" + m_supportType[i].ext + ")");
@ -136,18 +126,6 @@ Dialog_Export::Dialog_Export(int total, const std::vector<int> &selectedIndexs,
ui->label_ocrType->setVisible(false); ui->label_ocrType->setVisible(false);
ui->comboBox_ocrType->setVisible(false); ui->comboBox_ocrType->setVisible(false);
#if 0
if (!getOcrPath().empty())
{
ui->label_ocrType->setVisible(isOcr());
ui->comboBox_ocrType->setVisible(isOcr());
QStringList ocrType = { tr("English"), tr("Simplified Chinese"), tr("Traditional Chinese"), tr("Japanese"), tr("Korean") };
ui->comboBox_ocrType->addItems(ocrType);
ui->comboBox_ocrType->setCurrentIndex(getCfgValue("export", "ocrLanguage", 0));
}
#endif
} }
Dialog_Export::~Dialog_Export() Dialog_Export::~Dialog_Export()
@ -209,33 +187,6 @@ void Dialog_Export::getSaveIndexs(std::vector<int> &indexs)
void Dialog_Export::on_dialog_accepted() void Dialog_Export::on_dialog_accepted()
{ {
QString extName(m_supportType[m_suffix].ext); QString extName(m_supportType[m_suffix].ext);
// switch (m_suffix)
// {
// case 0:
// extName = ".jpg";
// break;
// case 1:
// extName = ".bmp";
// break;
// case 2:
// extName = ".png";
// break;
// case 3:
// extName = ".tif";
// break;
// case 4:
// extName = ".pdf";
// break;
// case 5:
// extName = ".ofd";
// break;
// case 6:
// extName = ".pdf";
// break;
// case 7:
// extName = ".ofd";
// break;
// }
assert(!extName.isEmpty()); assert(!extName.isEmpty());
@ -261,9 +212,15 @@ void Dialog_Export::on_dialog_accepted()
makeSaveIndexs(); makeSaveIndexs();
// 同名警告 QFile file(m_savePath + m_saveName + m_saveExt);
if(warning && avoid_overwriting(m_savePath + "/" + m_saveName + m_saveExt)) if (file.exists())
return; {
int ret = QMessageBox::question(this, tr("Question"), tr("The file already exists. Do you want to overwrite it?"));
if (ret != QMessageBox::Yes)
{
return;
}
}
saveCfgValue("export", "suffix", m_suffix); saveCfgValue("export", "suffix", m_suffix);
@ -277,11 +234,6 @@ void Dialog_Export::on_dialog_accepted()
saveCfgValue("export", "exportType", exportType); saveCfgValue("export", "exportType", exportType);
saveCfgValue("export", "saveAsMulti", ui->check_saveAsMulti->isChecked()); saveCfgValue("export", "saveAsMulti", ui->check_saveAsMulti->isChecked());
#if 0
int ocrLanguage = ui->comboBox_ocrType->currentIndex();
saveCfgValue("export", "ocrLanguage", ocrLanguage);
#endif
accept(); accept();
} }
@ -291,11 +243,6 @@ void Dialog_Export::on_filterSelected(const QString& filterName)
m_suffix = ui->fileDialog->nameFilters().indexOf(filterName); m_suffix = ui->fileDialog->nameFilters().indexOf(filterName);
#if 0
ui->label_ocrType->setVisible(isOcr());
ui->comboBox_ocrType->setVisible(isOcr());
#endif
enabled = (m_supportType[m_suffix].attr & FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES) == FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES; enabled = (m_supportType[m_suffix].attr & FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES) == FILE_TYPE_ATTR_CONTAIN_MULTI_PAGES;
ui->check_saveAsMulti->setEnabled(enabled); ui->check_saveAsMulti->setEnabled(enabled);
// ui->check_saveAsMulti->setEnabled(m_suffix > 2 && m_suffix < 6); // ui->check_saveAsMulti->setEnabled(m_suffix > 2 && m_suffix < 6);

View File

@ -15,7 +15,7 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="1,0"> <layout class="QVBoxLayout" name="verticalLayout_3" stretch="1,0">
<item> <item>
<widget class="QFileDialog" name="fileDialog" native="true"/> <widget class="MyFileDialog" name="fileDialog" native="true"/>
</item> </item>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
@ -183,9 +183,9 @@ Page range will be &quot;Chosen Pages&quot;.
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>QFileDialog</class> <class>MyFileDialog</class>
<extends>QWidget</extends> <extends>QWidget</extends>
<header location="global">qfiledialog.h</header> <header>dialog_saveas.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
</customwidgets> </customwidgets>

View File

@ -8,57 +8,24 @@
#include <qabstractproxymodel.h> #include <qabstractproxymodel.h>
#include <QDateTime> #include <QDateTime>
#include <QLineEdit> #include <QLineEdit>
#include <QMessageBox>
class del_delegate : public QAbstractProxyModel MyFileDialog::MyFileDialog(QWidget *parent)
: QFileDialog(parent)
{ {
QAbstractProxyModel* prev_ = nullptr;
QFileDialog* dlg_ = nullptr;
public: }
del_delegate(QFileDialog* fd) : dlg_(fd)
{
prev_ = dlg_->proxyModel();
dlg_->setProxyModel(this);
dlg_->setOption(QFileDialog::Option::ReadOnly, true);
}
~del_delegate()
{
dlg_->setProxyModel(prev_);
prev_ = nullptr;
}
public: MyFileDialog::~MyFileDialog()
virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override {
{
return prev_->removeRows(row, count, parent); }
}
Q_INVOKABLE virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const override void MyFileDialog::accept()
{ {
return prev_->mapToSource(proxyIndex); emit accepted();
} }
Q_INVOKABLE virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override
{
return prev_->mapFromSource(sourceIndex);
}
Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override
{
return prev_->rowCount(parent);
}
Q_INVOKABLE virtual int columnCount(const QModelIndex &parent = QModelIndex()) const override
{
return prev_->columnCount(parent);
}
Q_INVOKABLE virtual QModelIndex index(int row, int column,
const QModelIndex &parent = QModelIndex()) const override
{
return prev_->index(row, column, parent);
}
Q_INVOKABLE virtual QModelIndex parent(const QModelIndex &child) const override
{
return prev_->parent(child);
}
};
Dialog_SaveAs::Dialog_SaveAs(bool isSaveAs, QWidget *parent) : Dialog_SaveAs::Dialog_SaveAs(bool isSaveAs, QWidget *parent) :
QDialog(parent) QDialog(parent)
@ -102,14 +69,12 @@ Dialog_SaveAs::Dialog_SaveAs(bool isSaveAs, QWidget *parent) :
";;PDF - Portable Document Format(*.pdf)" ";;PDF - Portable Document Format(*.pdf)"
";;OFD - Open Fixed-layout Document(*.ofd)" ";;OFD - Open Fixed-layout Document(*.ofd)"
";;GIF - Graphics Interchange Format(*.gif)"; ";;GIF - Graphics Interchange Format(*.gif)";
#if 0
if (!getOcrPath().empty()) #if !defined (x86_64) && !defined (loongarch64)
filter += ";;OCR->PDF - Portable Document Format(*.pdf)"; filter += ";;OCR->PDF - Portable Document Format(*.pdf)";
#elif !defined (x86_64) && !defined (loongarch64) filter += ";;OCR->OFD - Open Fixed-layout Document(*.ofd)";
filter += ";;OCR->PDF - Portable Document Format(*.pdf)"; if (m_isSaveAs)
filter += ";;OCR->OFD - Open Fixed-layout Document(*.ofd)"; filter += ";;OCR->RTF - Rich Text Format(*.rtf)";
if (m_isSaveAs)
filter += ";;OCR->RTF - Rich Text Format(*.rtf)";
#endif #endif
ui->fileDialog->setNameFilter(filter); ui->fileDialog->setNameFilter(filter);
@ -131,18 +96,6 @@ Dialog_SaveAs::Dialog_SaveAs(bool isSaveAs, QWidget *parent) :
ui->label_ocrType->setVisible(false); ui->label_ocrType->setVisible(false);
ui->comboBox_ocrType->setVisible(false); ui->comboBox_ocrType->setVisible(false);
#if 0
if (!getOcrPath().empty())
{
ui->label_ocrType->setVisible(isOcr());
ui->comboBox_ocrType->setVisible(isOcr());
QStringList ocrType = { tr("English"), tr("Simplified Chinese"), tr("Traditional Chinese"), tr("Japanese"), tr("Korean") };
ui->comboBox_ocrType->addItems(ocrType);
ui->comboBox_ocrType->setCurrentIndex(getCfgValue("saveAs", "ocrLanguage", 0));
}
#endif
} }
Dialog_SaveAs::~Dialog_SaveAs() Dialog_SaveAs::~Dialog_SaveAs()
@ -255,15 +208,20 @@ void Dialog_SaveAs::on_dialog_accepted()
} }
if(name.endsWith(extName)) if(name.endsWith(extName))
m_savePath = getStdFileName(path + "/" + name); m_savePath = getStdFileName(path + name);
else else
m_savePath = getStdFileName(path + "/" + name + extName); m_savePath = getStdFileName(path + name + extName);
} }
#if 0 QFile file(m_savePath);
int ocrLanguage = ui->comboBox_ocrType->currentIndex(); if (file.exists())
saveCfgValue("saveAs", "ocrLanguage", ocrLanguage); {
#endif int ret = QMessageBox::question(this, tr("Question"), tr("The file already exists. Do you want to overwrite it?"));
if (ret != QMessageBox::Yes)
{
return;
}
}
saveCfgValue("saveAs", "suffix", m_suffix); saveCfgValue("saveAs", "suffix", m_suffix);
saveCfgValue("saveAs", "subFolderByTime", ui->cbox_subFolder->isChecked()); saveCfgValue("saveAs", "subFolderByTime", ui->cbox_subFolder->isChecked());
@ -274,11 +232,6 @@ void Dialog_SaveAs::on_filterSelected(const QString& filterName)
{ {
m_suffix = ui->fileDialog->nameFilters().indexOf(filterName); m_suffix = ui->fileDialog->nameFilters().indexOf(filterName);
ui->btn_option->setEnabled(0 == m_suffix || 6 == m_suffix || 7 == m_suffix || 8 == m_suffix); ui->btn_option->setEnabled(0 == m_suffix || 6 == m_suffix || 7 == m_suffix || 8 == m_suffix);
#if 0
ui->label_ocrType->setVisible(isOcr());
ui->comboBox_ocrType->setVisible(isOcr());
#endif
} }
void Dialog_SaveAs::on_btn_option_clicked() void Dialog_SaveAs::on_btn_option_clicked()

View File

@ -2,11 +2,24 @@
#define DIALOG_SAVEAS_H #define DIALOG_SAVEAS_H
#include <QDialog> #include <QDialog>
#include <QFileDialog>
namespace Ui { namespace Ui {
class Dialog_SaveAs; class Dialog_SaveAs;
} }
class MyFileDialog : public QFileDialog
{
Q_OBJECT
public:
explicit MyFileDialog(QWidget *parent = nullptr);
~MyFileDialog();
protected:
void accept() override;
};
class Dialog_SaveAs : public QDialog class Dialog_SaveAs : public QDialog
{ {
Q_OBJECT Q_OBJECT

View File

@ -15,7 +15,7 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QFileDialog" name="fileDialog" native="true"/> <widget class="MyFileDialog" name="fileDialog" native="true"/>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
@ -69,9 +69,9 @@
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>QFileDialog</class> <class>MyFileDialog</class>
<extends>QWidget</extends> <extends>QWidget</extends>
<header>qfiledialog.h</header> <header>dialog_saveas.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
</customwidgets> </customwidgets>

View File

@ -2716,9 +2716,32 @@ void MainWindow::on_act_Export_triggered()
int tiffQuality = dlg.getTiffQuality(); int tiffQuality = dlg.getTiffQuality();
bool isOcr = dlg.isOcr(); bool isOcr = dlg.isOcr();
Dialog_ExportImageFile dlgExport(savePath, saveName, saveExt, isSaveAsMulti, jpegQuality, bool find = false;
tiffCompressionBW, tiffCompression, tiffQuality, isOcr, srcFiles, this); int count = 0;
dlgExport.exec(); m_thumb->getItemCount(&count);
for (int i = 0; i < count; ++i)
{
QString fileName;
m_thumb->getItemFileName(i, fileName);
assert(!fileName.isEmpty());
if (fileName == savePath + saveName + saveExt)
{
find = true;
break;
}
}
if (!find)
{
Dialog_ExportImageFile dlgExport(savePath, saveName, saveExt, isSaveAsMulti, jpegQuality,
tiffCompressionBW, tiffCompression, tiffQuality, isOcr, srcFiles, this);
dlgExport.exec();
}
else
{
QMessageBox::information(this, tr("tips"), tr("find savePath in thumbnail"));
}
} }
} }
} }

View File

@ -119,6 +119,12 @@ typedef HGUInt HGResult;
#endif #endif
#endif #endif
#if defined(HG_CMP_MSC)
#define HG_SEP "\\"
#else
#define HG_SEP "/"
#endif
#define HG_DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name #define HG_DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name
#pragma pack(push) #pragma pack(push)