summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-10-12 12:04:47 (GMT)
committerMontel Laurent <montel@kde.org>2016-10-12 12:04:47 (GMT)
commitcbc0329559939ce6bf4c66261bbf503fdfe175b1 (patch)
treee7547cf139eb70510d7202d23a12c9e029ac09ed
parent2f6483e9470b875558bee026947b652179069bac (diff)
Fix progressbar
-rw-r--r--kaddressbook/importexportplugins/shared/importexportengine.cpp26
-rw-r--r--kaddressbook/importexportplugins/shared/importexportengine.h4
2 files changed, 19 insertions, 11 deletions
diff --git a/kaddressbook/importexportplugins/shared/importexportengine.cpp b/kaddressbook/importexportplugins/shared/importexportengine.cpp
index 4948336..13a0431 100644
--- a/kaddressbook/importexportplugins/shared/importexportengine.cpp
+++ b/kaddressbook/importexportplugins/shared/importexportengine.cpp
@@ -31,7 +31,9 @@
ImportExportEngine::ImportExportEngine(QObject *parent)
: QObject(parent),
mParentWidget(Q_NULLPTR),
- mImportProgressDialog(Q_NULLPTR)
+ mImportProgressDialog(Q_NULLPTR),
+ mNumberElementToImport(-1),
+ mImportDone(0)
{
}
@@ -101,6 +103,8 @@ void ImportExportEngine::importContacts()
mImportProgressDialog->show();
+ mNumberElementToImport = mContactsList.count();
+
for (int i = 0; i < mContactsList.addressList().count(); ++i) {
Akonadi::Item item;
item.setPayload<KContacts::Addressee>(mContactsList.addressList().at(i));
@@ -118,21 +122,23 @@ void ImportExportEngine::importContacts()
connect(createJob, &KJob::result, this, &ImportExportEngine::slotImportJobDone);
}
Q_EMIT finished();
- deleteLater();
}
void ImportExportEngine::slotImportJobDone(KJob *)
{
- if (!mImportProgressDialog) {
- return;
- }
+ mImportDone++;
+ if (mImportProgressDialog) {
- mImportProgressDialog->setValue(mImportProgressDialog->value() + 1);
+ mImportProgressDialog->setValue(mImportProgressDialog->value() + 1);
- // cleanup on last step
- if (mImportProgressDialog->value() == mImportProgressDialog->maximum()) {
- mImportProgressDialog->deleteLater();
- mImportProgressDialog = Q_NULLPTR;
+ // cleanup on last step
+ if (mImportProgressDialog->value() == mImportProgressDialog->maximum()) {
+ mImportProgressDialog->deleteLater();
+ mImportProgressDialog = Q_NULLPTR;
+ }
+ }
+ if (mImportDone >= mNumberElementToImport) {
+ deleteLater();
}
}
diff --git a/kaddressbook/importexportplugins/shared/importexportengine.h b/kaddressbook/importexportplugins/shared/importexportengine.h
index 256ccf3..8ff4fc6 100644
--- a/kaddressbook/importexportplugins/shared/importexportengine.h
+++ b/kaddressbook/importexportplugins/shared/importexportengine.h
@@ -43,11 +43,13 @@ Q_SIGNALS:
void finished();
private:
+ void slotImportJobDone(KJob *);
KAddressBookImportExport::KAddressBookImportExportContactList mContactsList;
Akonadi::Collection mDefaultAddressBook;
QWidget *mParentWidget;
QProgressDialog *mImportProgressDialog;
- void slotImportJobDone(KJob *);
+ int mNumberElementToImport;
+ int mImportDone;
};
#endif // IMPORTEXPORTENGINE_H