10
#include "cmoduleindexdialog.h"
10
#include "frontend/cmoduleindexdialog.h"
12
#include <QApplication>
14
#include <QProgressDialog>
16
#include "backend/managers/cswordbackend.h"
12
17
#include "util/cpointers.h"
13
#include "backend/managers/cswordbackend.h"
15
#include <boost/scoped_ptr.hpp>
19
#include <QProgressDialog>
21
#include <QApplication>
22
#include <QMessageBox>
18
#include "util/dialogutil.h"
24
21
CModuleIndexDialog* CModuleIndexDialog::getInstance() {
25
qDebug("CModuleIndexDialog::getInstance");
26
static CModuleIndexDialog* instance = 0;
28
instance = new CModuleIndexDialog();
30
qDebug("CModuleIndexDialog::getInstance end");
22
qDebug() << "CModuleIndexDialog::getInstance";
23
static CModuleIndexDialog* instance = 0;
25
instance = new CModuleIndexDialog();
27
qDebug() << "CModuleIndexDialog::getInstance end";
34
void CModuleIndexDialog::indexAllModules( const QList<CSwordModuleInfo*>& modules )
36
static bool indexing = false;
39
if (modules.count() < 1) return;
41
m_currentModuleIndex = 0;
42
m_progress = new QProgressDialog(QString(""), tr("Cancel"), 0, modules.count()*100);
43
m_progress->setWindowModality(Qt::WindowModal); // not useful actually, should have parent for this
44
m_progress->setWindowTitle(tr("Creating indices"));
48
foreach (CSwordModuleInfo* info, modules) {
50
//QObject::connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged()), this, SLOT(swordSetupChanged()));
51
connect(this, SIGNAL(sigCancel()), info, SLOT(cancelIndexing()) );
52
connect(m_progress, SIGNAL(canceled()), info, SLOT(cancelIndexing()));
53
connect(info, SIGNAL(indexingFinished()), this, SLOT(slotFinished()));
54
connect(info, SIGNAL(indexingProgress(int)), this, SLOT(slotModuleProgress(int)) );
55
QString modname(info->name());
56
const QString labelText = tr("Creating index for work: %1").arg(modname);
57
m_progress->setLabelText(labelText);
58
//todo: if we want to cancel indexing from
59
info->buildIndex(); //waits until this module is finished
61
m_currentModuleIndex++;
62
disconnect(m_progress, SIGNAL(canceled()), info, SLOT(cancelIndexing()));
63
disconnect(info, SIGNAL(indexingFinished()), this, SLOT(slotFinished()));
64
disconnect(info, SIGNAL(indexingProgress(int)), this, SLOT(slotModuleProgress(int)) );
65
if (m_progress->wasCanceled()) break;
31
void CModuleIndexDialog::indexAllModules( const QList<CSwordModuleInfo*>& modules ) {
32
static bool indexing = false;
35
if (modules.count() < 1) return;
37
m_currentModuleIndex = 0;
38
m_progress = new QProgressDialog(QString(""), tr("Cancel"), 0, modules.count()*100);
39
m_progress->setWindowModality(Qt::WindowModal); // not useful actually, should have parent for this
40
m_progress->setWindowTitle(tr("Creating indices"));
44
foreach (CSwordModuleInfo* info, modules) {
45
/// \todo how to cancel
46
//QObject::connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged()), this, SLOT(swordSetupChanged()));
47
connect(this, SIGNAL(sigCancel()), info, SLOT(cancelIndexing()) );
48
connect(m_progress, SIGNAL(canceled()), info, SLOT(cancelIndexing()));
49
connect(info, SIGNAL(indexingFinished()), this, SLOT(slotFinished()));
50
connect(info, SIGNAL(indexingProgress(int)), this, SLOT(slotModuleProgress(int)) );
51
QString modname(info->name());
52
const QString labelText = tr("Creating index for work: %1").arg(modname);
53
m_progress->setLabelText(labelText);
54
/// \todo if we want to cancel indexing from
55
info->buildIndex(); //waits until this module is finished
57
m_currentModuleIndex++;
58
disconnect(m_progress, SIGNAL(canceled()), info, SLOT(cancelIndexing()));
59
disconnect(info, SIGNAL(indexingFinished()), this, SLOT(slotFinished()));
60
disconnect(info, SIGNAL(indexingProgress(int)), this, SLOT(slotModuleProgress(int)) );
61
if (m_progress->wasCanceled()) break;
74
70
void CModuleIndexDialog::indexUnindexedModules( const QList<CSwordModuleInfo*>& modules ) {
75
QList<CSwordModuleInfo*> unindexedMods;
77
QList<CSwordModuleInfo*>::const_iterator end_it = modules.end();
78
for( QList<CSwordModuleInfo*>::const_iterator it = modules.begin(); it != end_it; ++it) {
79
if ((*it)->hasIndex()) {
83
unindexedMods << (*it);
85
indexAllModules(unindexedMods);
71
QList<CSwordModuleInfo*> unindexedMods;
73
QList<CSwordModuleInfo*>::const_iterator end_it = modules.end();
74
for ( QList<CSwordModuleInfo*>::const_iterator it = modules.begin(); it != end_it; ++it) {
75
if ((*it)->hasIndex()) {
79
unindexedMods << (*it);
81
indexAllModules(unindexedMods);
88
84
void CModuleIndexDialog::slotModuleProgress( int percentage ) {
89
m_progress->setValue(m_currentModuleIndex * 100 + percentage);
90
qApp->processEvents();
85
m_progress->setValue(m_currentModuleIndex * 100 + percentage);
86
qApp->processEvents();
93
89
void CModuleIndexDialog::slotFinished( ) {
94
m_progress->setValue(m_currentModuleIndex * 100 + 100);
95
qApp->processEvents();
90
m_progress->setValue(m_currentModuleIndex * 100 + 100);
91
qApp->processEvents();
98
94
// Modules may be removed
99
void CModuleIndexDialog::slotSwordSetupChanged()
101
qDebug("CModuleIndexDialog::slotSwordSetupChanged, TODO: cancel if modules are removed");
102
QMessageBox::information(0, tr("Indexing Is Cancelled"), tr("Indexing is cancelled because modules are removed."));
95
void CModuleIndexDialog::slotSwordSetupChanged() {
96
qDebug() << "CModuleIndexDialog::slotSwordSetupChanged"; /// \todo cancel if modules are removed
97
util::showInformation(0, tr("Indexing Is Cancelled"), tr("Indexing is cancelled because modules are removed."));