解决导出/保存/另存为与保存路径文件同名时,未做替换文件提醒的问题-BUG 807
This commit is contained in:
parent
c553dbbbec
commit
6e3db40cd0
|
@ -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(".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));
|
||||
#if 0
|
||||
if (!getOcrPath().empty())
|
||||
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)
|
||||
|
||||
#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));
|
||||
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));
|
||||
|
@ -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->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;
|
||||
for(int i = 0; i < m_supportType.size(); ++i)
|
||||
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->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()
|
||||
|
@ -209,33 +187,6 @@ void Dialog_Export::getSaveIndexs(std::vector<int> &indexs)
|
|||
void Dialog_Export::on_dialog_accepted()
|
||||
{
|
||||
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());
|
||||
|
||||
|
@ -261,9 +212,15 @@ void Dialog_Export::on_dialog_accepted()
|
|||
|
||||
makeSaveIndexs();
|
||||
|
||||
// 同名警告
|
||||
if(warning && avoid_overwriting(m_savePath + "/" + m_saveName + m_saveExt))
|
||||
return;
|
||||
QFile file(m_savePath + m_saveName + m_saveExt);
|
||||
if (file.exists())
|
||||
{
|
||||
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);
|
||||
|
||||
|
@ -277,11 +234,6 @@ void Dialog_Export::on_dialog_accepted()
|
|||
saveCfgValue("export", "exportType", exportType);
|
||||
saveCfgValue("export", "saveAsMulti", ui->check_saveAsMulti->isChecked());
|
||||
|
||||
#if 0
|
||||
int ocrLanguage = ui->comboBox_ocrType->currentIndex();
|
||||
saveCfgValue("export", "ocrLanguage", ocrLanguage);
|
||||
#endif
|
||||
|
||||
accept();
|
||||
}
|
||||
|
||||
|
@ -291,11 +243,6 @@ void Dialog_Export::on_filterSelected(const QString& 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;
|
||||
ui->check_saveAsMulti->setEnabled(enabled);
|
||||
// ui->check_saveAsMulti->setEnabled(m_suffix > 2 && m_suffix < 6);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="1,0">
|
||||
<item>
|
||||
<widget class="QFileDialog" name="fileDialog" native="true"/>
|
||||
<widget class="MyFileDialog" name="fileDialog" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
|
@ -183,9 +183,9 @@ Page range will be "Chosen Pages".
|
|||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QFileDialog</class>
|
||||
<class>MyFileDialog</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">qfiledialog.h</header>
|
||||
<header>dialog_saveas.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
|
|
|
@ -8,57 +8,24 @@
|
|||
#include <qabstractproxymodel.h>
|
||||
#include <QDateTime>
|
||||
#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:
|
||||
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
|
||||
{
|
||||
return prev_->mapToSource(proxyIndex);
|
||||
}
|
||||
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);
|
||||
}
|
||||
MyFileDialog::~MyFileDialog()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MyFileDialog::accept()
|
||||
{
|
||||
emit accepted();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Dialog_SaveAs::Dialog_SaveAs(bool isSaveAs, QWidget *parent) :
|
||||
QDialog(parent)
|
||||
|
@ -102,14 +69,12 @@ Dialog_SaveAs::Dialog_SaveAs(bool isSaveAs, QWidget *parent) :
|
|||
";;PDF - Portable Document Format(*.pdf)"
|
||||
";;OFD - Open Fixed-layout Document(*.ofd)"
|
||||
";;GIF - Graphics Interchange Format(*.gif)";
|
||||
#if 0
|
||||
if (!getOcrPath().empty())
|
||||
filter += ";;OCR->PDF - Portable Document Format(*.pdf)";
|
||||
#elif !defined (x86_64) && !defined (loongarch64)
|
||||
filter += ";;OCR->PDF - Portable Document Format(*.pdf)";
|
||||
filter += ";;OCR->OFD - Open Fixed-layout Document(*.ofd)";
|
||||
if (m_isSaveAs)
|
||||
filter += ";;OCR->RTF - Rich Text Format(*.rtf)";
|
||||
|
||||
#if !defined (x86_64) && !defined (loongarch64)
|
||||
filter += ";;OCR->PDF - Portable Document Format(*.pdf)";
|
||||
filter += ";;OCR->OFD - Open Fixed-layout Document(*.ofd)";
|
||||
if (m_isSaveAs)
|
||||
filter += ";;OCR->RTF - Rich Text Format(*.rtf)";
|
||||
#endif
|
||||
|
||||
ui->fileDialog->setNameFilter(filter);
|
||||
|
@ -131,18 +96,6 @@ Dialog_SaveAs::Dialog_SaveAs(bool isSaveAs, QWidget *parent) :
|
|||
|
||||
ui->label_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()
|
||||
|
@ -255,15 +208,20 @@ void Dialog_SaveAs::on_dialog_accepted()
|
|||
}
|
||||
|
||||
if(name.endsWith(extName))
|
||||
m_savePath = getStdFileName(path + "/" + name);
|
||||
m_savePath = getStdFileName(path + name);
|
||||
else
|
||||
m_savePath = getStdFileName(path + "/" + name + extName);
|
||||
m_savePath = getStdFileName(path + name + extName);
|
||||
}
|
||||
|
||||
#if 0
|
||||
int ocrLanguage = ui->comboBox_ocrType->currentIndex();
|
||||
saveCfgValue("saveAs", "ocrLanguage", ocrLanguage);
|
||||
#endif
|
||||
QFile file(m_savePath);
|
||||
if (file.exists())
|
||||
{
|
||||
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", "subFolderByTime", ui->cbox_subFolder->isChecked());
|
||||
|
@ -274,11 +232,6 @@ void Dialog_SaveAs::on_filterSelected(const QString& filterName)
|
|||
{
|
||||
m_suffix = ui->fileDialog->nameFilters().indexOf(filterName);
|
||||
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()
|
||||
|
|
|
@ -2,11 +2,24 @@
|
|||
#define DIALOG_SAVEAS_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QFileDialog>
|
||||
|
||||
namespace Ui {
|
||||
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
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QFileDialog" name="fileDialog" native="true"/>
|
||||
<widget class="MyFileDialog" name="fileDialog" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
|
@ -69,9 +69,9 @@
|
|||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QFileDialog</class>
|
||||
<class>MyFileDialog</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>qfiledialog.h</header>
|
||||
<header>dialog_saveas.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
|
|
|
@ -2716,9 +2716,32 @@ void MainWindow::on_act_Export_triggered()
|
|||
int tiffQuality = dlg.getTiffQuality();
|
||||
bool isOcr = dlg.isOcr();
|
||||
|
||||
Dialog_ExportImageFile dlgExport(savePath, saveName, saveExt, isSaveAsMulti, jpegQuality,
|
||||
tiffCompressionBW, tiffCompression, tiffQuality, isOcr, srcFiles, this);
|
||||
dlgExport.exec();
|
||||
bool find = false;
|
||||
int count = 0;
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,6 +119,12 @@ typedef HGUInt HGResult;
|
|||
#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
|
||||
|
||||
#pragma pack(push)
|
||||
|
|
Loading…
Reference in New Issue