Skip to content

Commit

Permalink
GH #384.
Browse files Browse the repository at this point in the history
  • Loading branch information
textbrowser committed Nov 30, 2024
1 parent bf0dfae commit 4b3d7c0
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 36 deletions.
2 changes: 2 additions & 0 deletions Documentation/Release-Notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<li>New terminal option --open-sqlite-database-index index, where
index is the index of the entry in the Recent SQLite Files
menu. First index is one.</li>
<li>Optional progress dialogs in CSV Import Browser.
<b>GitHub ticket #384.</b></li>
<li>Q_OS_WIN -> Q_OS_WINDOWS.</li>
<li>Poppler and Qt 6. Poppler is an exterior product covering PDF
documents.</li>
Expand Down
110 changes: 76 additions & 34 deletions Source/biblioteq_import.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ biblioteq_import::biblioteq_import(biblioteq *parent):QMainWindow(parent)
m_qmain = parent;
m_ui.setupUi(this);
m_ui.about_csv->setText(tr("0 Columns | 0 Lines"));
m_ui.show_progress_dialogs->setChecked
(QSettings().value("show_progress_dialogs_csv_import", true).toBool());
connect(m_qmain,
SIGNAL(fontChanged(const QFont &)),
this,
Expand Down Expand Up @@ -76,6 +78,10 @@ biblioteq_import::biblioteq_import(biblioteq *parent):QMainWindow(parent)
SIGNAL(clicked(void)),
this,
SLOT(slotSelectCSVFile(void)));
connect(m_ui.show_progress_dialogs,
SIGNAL(toggled(bool)),
this,
SLOT(slotSaveOption(void)));
connect(m_ui.templates,
SIGNAL(activated(int)),
this,
Expand Down Expand Up @@ -122,7 +128,7 @@ void biblioteq_import::importBooks(QProgressDialog *progress,
qint64 *imported,
qint64 *notImported)
{
if(!progress || m_ui.csv_file->text().trimmed().isEmpty())
if(m_ui.csv_file->text().trimmed().isEmpty())
return;

QFile file(m_ui.csv_file->text());
Expand Down Expand Up @@ -200,13 +206,17 @@ void biblioteq_import::importBooks(QProgressDialog *progress,

while(ct++, !in.atEnd())
{
if(progress->wasCanceled())
if(progress && progress->wasCanceled())
break;
else
{
progress->setLabelText
(tr("Importing the CSV file. Processing line %1.").arg(ct));
progress->repaint();
if(progress)
{
progress->setLabelText
(tr("Importing the CSV file. Processing line %1.").arg(ct));
progress->repaint();
}

QApplication::processEvents();
}

Expand Down Expand Up @@ -535,7 +545,7 @@ void biblioteq_import::importPatrons(QProgressDialog *progress,
qint64 *imported,
qint64 *notImported)
{
if(!progress || m_ui.csv_file->text().trimmed().isEmpty())
if(m_ui.csv_file->text().trimmed().isEmpty())
return;

QFile file(m_ui.csv_file->text());
Expand Down Expand Up @@ -590,13 +600,17 @@ void biblioteq_import::importPatrons(QProgressDialog *progress,

while(ct++, !in.atEnd())
{
if(progress->wasCanceled())
if(progress && progress->wasCanceled())
break;
else
{
progress->setLabelText
(tr("Importing the CSV file. Processing line %1.").arg(ct));
progress->repaint();
if(progress)
{
progress->setLabelText
(tr("Importing the CSV file. Processing line %1.").arg(ct));
progress->repaint();
}

QApplication::processEvents();
}

Expand Down Expand Up @@ -734,17 +748,22 @@ void biblioteq_import::loadPreview(void)
if(m_ui.csv_file->text().trimmed().isEmpty())
return;

QScopedPointer<QProgressDialog> progress(new QProgressDialog(this));
QScopedPointer<QProgressDialog> progress(nullptr);

if(m_ui.show_progress_dialogs->isChecked())
{
progress.reset(new QProgressDialog(this));
progress->setLabelText(tr("Reading the CSV file..."));
progress->setMaximum(0);
progress->setMinimum(0);
progress->setModal(true);
progress->setValue(0);
progress->setWindowTitle(tr("BiblioteQ: Progress Dialog"));
progress->show();
progress->repaint();
QApplication::processEvents();
}

progress->setLabelText(tr("Reading the CSV file..."));
progress->setMaximum(0);
progress->setMinimum(0);
progress->setModal(true);
progress->setValue(0);
progress->setWindowTitle(tr("BiblioteQ: Progress Dialog"));
progress->show();
progress->repaint();
QApplication::processEvents();
m_ui.preview->clear();
m_ui.preview->setColumnCount(0);
m_ui.preview->setRowCount(0);
Expand All @@ -756,9 +775,16 @@ void biblioteq_import::loadPreview(void)
QTextStream in(&file);
int row = 0;

while(!in.atEnd() && !progress->wasCanceled())
while(!in.atEnd())
{
progress->repaint();
if(progress)
{
if(progress->wasCanceled())
break;

progress->repaint();
}

QApplication::processEvents();

auto const data(in.readLine().trimmed());
Expand Down Expand Up @@ -816,7 +842,7 @@ void biblioteq_import::loadPreview(void)
}

file.close();
progress->close();
progress ? (void) progress->close() : (void) 0;
QApplication::processEvents();
}

Expand Down Expand Up @@ -1181,17 +1207,23 @@ void biblioteq_import::slotImport(void)
return;
}

QScopedPointer<QProgressDialog> progress(new QProgressDialog(this));
QScopedPointer<QProgressDialog> progress(nullptr);

progress->setLabelText(tr("Importing the CSV file..."));
progress->setMaximum(0);
progress->setMinimum(0);
progress->setModal(true);
progress->setValue(0);
progress->setWindowTitle(tr("BiblioteQ: Progress Dialog"));
progress->show();
progress->repaint();
QApplication::processEvents();
if(m_ui.show_progress_dialogs->isChecked())
{
progress.reset(new QProgressDialog(this));
progress->setLabelText(tr("Importing the CSV file..."));
progress->setMaximum(0);
progress->setMinimum(0);
progress->setModal(true);
progress->setValue(0);
progress->setWindowTitle(tr("BiblioteQ: Progress Dialog"));
progress->show();
progress->repaint();
QApplication::processEvents();
}

QApplication::setOverrideCursor(Qt::WaitCursor);
m_mappings = map;

QStringList errors;
Expand Down Expand Up @@ -1224,7 +1256,8 @@ void biblioteq_import::slotImport(void)
else if(index == static_cast<int> (Templates::TEMPLATE_3))
importPatrons(progress.data(), errors, &imported, &notImported);

progress->close();
QApplication::restoreOverrideCursor();
progress ? (void) progress->close() : (void) 0;
QApplication::processEvents();

if(!errors.isEmpty())
Expand Down Expand Up @@ -1312,6 +1345,15 @@ void biblioteq_import::slotReset(void)
m_ui.templates->setCurrentIndex(0);
}

void biblioteq_import::slotSaveOption(void)
{
QSettings settings;

settings.setValue
("show_progress_dialogs_csv_import",
m_ui.show_progress_dialogs->isChecked());
}

void biblioteq_import::slotSelectCSVFile(void)
{
QFileDialog dialog(this);
Expand Down
1 change: 1 addition & 0 deletions Source/biblioteq_import.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class biblioteq_import: public QMainWindow
void slotImport(void);
void slotRefreshPreview(void);
void slotReset(void);
void slotSaveOption(void);
void slotSelectCSVFile(void);
void slotSetGlobalFonts(const QFont &font);
void slotTemplates(int index);
Expand Down
18 changes: 16 additions & 2 deletions UI/biblioteq_import.ui
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="show_progress_dialogs">
<property name="toolTip">
<string>Saved in the INI file. An import of a large file may not be gently canceled.</string>
</property>
<property name="text">
<string>Show Progress Dialogs</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
Expand Down Expand Up @@ -209,8 +222,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>699</width>
<height>426</height>
<width>714</width>
<height>395</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
Expand Down Expand Up @@ -624,6 +637,7 @@
</action>
</widget>
<tabstops>
<tabstop>show_progress_dialogs</tabstop>
<tabstop>csv_file</tabstop>
<tabstop>select_csv_file</tabstop>
<tabstop>preview</tabstop>
Expand Down

0 comments on commit 4b3d7c0

Please sign in to comment.