r18866 - gnucash/trunk/src/gnc - Cutecash: Add progress bar during loading the file.
Christian Stimming
cstim at code.gnucash.org
Sun Mar 7 08:36:11 EST 2010
Author: cstim
Date: 2010-03-07 08:36:11 -0500 (Sun, 07 Mar 2010)
New Revision: 18866
Trac: http://svn.gnucash.org/trac/changeset/18866
Modified:
gnucash/trunk/src/gnc/mainwindow.cpp
Log:
Cutecash: Add progress bar during loading the file.
Modified: gnucash/trunk/src/gnc/mainwindow.cpp
===================================================================
--- gnucash/trunk/src/gnc/mainwindow.cpp 2010-03-07 13:09:37 UTC (rev 18865)
+++ gnucash/trunk/src/gnc/mainwindow.cpp 2010-03-07 13:36:11 UTC (rev 18866)
@@ -25,6 +25,8 @@
#include <QtGui/QFileDialog>
#include <QtGui/QMessageBox>
#include <QtGui/QToolBar>
+#include <QtGui/QProgressBar>
+#include <QDebug>
#include "config.h"
#include "mainwindow.hpp"
@@ -310,6 +312,38 @@
}
}
+namespace
+{
+/** This is a workaround functor so that we can obtain a
+ * QofPercentageFunc without extra boost::bind usage; obviously due to
+ * the static member variable it will not work if multiple instances
+ * are in use simultaneously */
+class progress_functor
+{
+ public:
+ progress_functor(QProgressBar *progressBar)
+ {
+ m_progressBar = progressBar;
+ }
+ ~progress_functor()
+ {
+ m_progressBar = NULL;
+ }
+ static void static_func(const char *message, double percent)
+ {
+ assert(m_progressBar);
+ m_progressBar->setValue(int(percent));
+ // Give the Qt event loop some time
+ qApp->processEvents();
+ }
+ private:
+ static QProgressBar *m_progressBar;
+};
+QProgressBar *progress_functor::m_progressBar = NULL;
+
+} // END namespace anonymous
+
+
void MainWindow::loadFile(const QString &fileName)
{
if (fileName.isEmpty())
@@ -413,8 +447,28 @@
xaccLogSetBaseName (logpath);
xaccLogDisable();
- statusBar()->showMessage(tr("Loading user data..."), 2000);
- qof_session_load (new_session, NULL);
+ {
+ // Set up a progress bar in the statusBar()
+ QProgressBar progressBar;
+ progressBar.setMinimum(0);
+ progressBar.setMaximum(100);
+ statusBar()->showMessage(tr("Loading user data..."));
+ statusBar()->addWidget(&progressBar);
+ progressBar.show();
+ // This local progress_functor is a workaround on how to
+ // pass the suitable function pointer to session_load -
+ // not very nice because of its static member, but it does
+ // the trick for now.
+ progress_functor functor(&progressBar);
+
+ // Do the loading.
+ qof_session_load (new_session, &progress_functor::static_func);
+
+ // Remove the progress bar again from the status bar. No
+ // explicit delete necessary because it is just a local
+ // variable.
+ statusBar()->removeWidget(&progressBar);
+ }
xaccLogEnable();
/* check for i/o error, put up appropriate error dialog */
More information about the gnucash-changes
mailing list