summaryrefslogtreecommitdiffstats
path: root/bibletime/frontend/cmoduleindexdialog.cpp
blob: a2d48dfe8b02da07ce4f7df95f88777bdb37fc1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// C++ Implementation: cmoduleindexdialog
//
// Description: 
//
//
// Author: The BibleTime team <info@bibletime.info>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include "cmoduleindexdialog.h"

#include "util/scoped_resource.h"

//TQt includes
#include <tqstring.h>

//KDE includes
#include <tdeapplication.h>
#include <kprogress.h>
#include <tdelocale.h>

CModuleIndexDialog* CModuleIndexDialog::getInstance() {
	static CModuleIndexDialog* instance = 0;
	if (instance == 0) {
		instance = new CModuleIndexDialog();
	}

	return instance;
}

void CModuleIndexDialog::indexAllModules( const ListCSwordModuleInfo& modules ) {
	tqDebug("indexAllModules");
	if (modules.count() == 0) {
		return;
	}
	
	m_currentModuleIndex = 0;
	progress = new KProgressDialog(0, "progressDialog", i18n("Preparing instant search"), TQString(), true);
	progress->setAllowCancel(false);
	progress->progressBar()->setTotalSteps( modules.count() * 100 );
	progress->setMinimumDuration(0);
// 	progress->show();
// 	progress->raise();

	ListCSwordModuleInfo::const_iterator end_it = modules.end();
	for( ListCSwordModuleInfo::const_iterator it = modules.begin(); it != end_it; ++it) {
		(*it)->connectIndexingFinished(this, TQT_SLOT(slotFinished()));
		(*it)->connectIndexingProgress(this, TQT_SLOT(slotModuleProgress(int)));

		progress->setLabel(i18n("Creating index for work %1").arg((*it)->name()));
		tqDebug("Building index for work %s", (*it)->name().latin1());
		
		(*it)->buildIndex();

		m_currentModuleIndex++;
		(*it)->disconnectIndexingSignals(this);
	}

	delete progress;
	progress = 0;
}

void CModuleIndexDialog::indexUnindexedModules( const ListCSwordModuleInfo& modules ) {
	tqDebug("indexUnindexedModules");
	ListCSwordModuleInfo unindexedMods;
	
	ListCSwordModuleInfo::const_iterator end_it = modules.end();
	for( ListCSwordModuleInfo::const_iterator it = modules.begin(); it != end_it; ++it) {
		if ((*it)->hasIndex()) {
			continue;
		}

		unindexedMods << (*it);
	}
	
	indexAllModules(unindexedMods);
}


/*!
    \fn CModuleIndexDialog::slotModuleProgress( int percentage )
 */
void CModuleIndexDialog::slotModuleProgress( int percentage ) {
//	tqDebug("progress %d", percentage);
	
	progress->progressBar()->setProgress( m_currentModuleIndex * 100 + percentage );
	TDEApplication::kApplication()->processEvents( 10 ); //10 ms only
}

void CModuleIndexDialog::slotFinished( ) {
	tqDebug("indexing finished()");
	
	progress->progressBar()->setProgress( progress->progressBar()->totalSteps() );
	TDEApplication::kApplication()->processEvents( 1 ); //1 ms only
}