~ubuntu-branches/ubuntu/trusty/bibletime/trusty

« back to all changes in this revision

Viewing changes to src/frontend/cmoduleindexdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Marsden
  • Date: 2009-11-18 17:30:00 UTC
  • mfrom: (1.3.4 upstream) (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20091118173000-endkhjz5qai88tvr
Tags: 2.4-1
* New upstream version 2.4
* debian/control: 
  - Replace incorrect bibletime-data Depends on lib4qt-gui
    with bibletime Depends on libqtgui4 (>= 4.4.0). (Closes: #556209).
  - Add Build-depends: on zlib1g-dev and libcurl4-gnutls-dev 
    (Closes: #556805).

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
*
8
8
**********/
9
9
 
10
 
#include "cmoduleindexdialog.h"
 
10
#include "frontend/cmoduleindexdialog.h"
11
11
 
 
12
#include <QApplication>
 
13
#include <QDebug>
 
14
#include <QProgressDialog>
 
15
#include <QString>
 
16
#include "backend/managers/cswordbackend.h"
12
17
#include "util/cpointers.h"
13
 
#include "backend/managers/cswordbackend.h"
14
 
 
15
 
#include <boost/scoped_ptr.hpp>
16
 
 
17
 
//Qt includes
18
 
#include <QString>
19
 
#include <QProgressDialog>
20
 
#include <QDebug>
21
 
#include <QApplication>
22
 
#include <QMessageBox>
 
18
#include "util/dialogutil.h"
 
19
 
23
20
 
24
21
CModuleIndexDialog* CModuleIndexDialog::getInstance() {
25
 
        qDebug("CModuleIndexDialog::getInstance");
26
 
        static CModuleIndexDialog* instance = 0;
27
 
        if (instance == 0) {
28
 
                instance = new CModuleIndexDialog();
29
 
        }
30
 
        qDebug("CModuleIndexDialog::getInstance end");
31
 
        return instance;
 
22
    qDebug() << "CModuleIndexDialog::getInstance";
 
23
    static CModuleIndexDialog* instance = 0;
 
24
    if (instance == 0) {
 
25
        instance = new CModuleIndexDialog();
 
26
    }
 
27
    qDebug() << "CModuleIndexDialog::getInstance end";
 
28
    return instance;
32
29
}
33
30
 
34
 
void CModuleIndexDialog::indexAllModules( const QList<CSwordModuleInfo*>& modules )
35
 
{
36
 
        static bool indexing = false;
37
 
        if (!indexing) {
38
 
                indexing = true;
39
 
                if (modules.count() < 1) return;
40
 
                
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"));
45
 
                m_progress->show();
46
 
                m_progress->raise();
47
 
                
48
 
                foreach (CSwordModuleInfo* info, modules) {
49
 
                        //TODO: how to cancel
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
60
 
        
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;
66
 
                }
67
 
        
68
 
                delete m_progress;
69
 
                m_progress = 0;
70
 
                indexing = false;
71
 
        }
 
31
void CModuleIndexDialog::indexAllModules( const QList<CSwordModuleInfo*>& modules ) {
 
32
    static bool indexing = false;
 
33
    if (!indexing) {
 
34
        indexing = true;
 
35
        if (modules.count() < 1) return;
 
36
 
 
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"));
 
41
        m_progress->show();
 
42
        m_progress->raise();
 
43
 
 
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
 
56
 
 
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;
 
62
        }
 
63
 
 
64
        delete m_progress;
 
65
        m_progress = 0;
 
66
        indexing = false;
 
67
    }
72
68
}
73
69
 
74
70
void CModuleIndexDialog::indexUnindexedModules( const QList<CSwordModuleInfo*>& modules ) {
75
 
        QList<CSwordModuleInfo*> unindexedMods;
76
 
        
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()) {
80
 
                        continue;
81
 
                }
82
 
 
83
 
                unindexedMods << (*it);
84
 
        }
85
 
        indexAllModules(unindexedMods);
 
71
    QList<CSwordModuleInfo*> unindexedMods;
 
72
 
 
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()) {
 
76
            continue;
 
77
        }
 
78
 
 
79
        unindexedMods << (*it);
 
80
    }
 
81
    indexAllModules(unindexedMods);
86
82
}
87
83
 
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();
91
87
}
92
88
 
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();
96
92
}
97
93
 
98
94
// Modules may be removed
99
 
void CModuleIndexDialog::slotSwordSetupChanged()
100
 
{
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."));
103
 
        emit sigCancel();
 
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."));
 
98
    emit sigCancel();
104
99
}