3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
5
* Copyright 1999-2006 by the BibleTime developers.
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
12
#include "cmanageindiceswidget.h"
14
#include "cmoduleindexdialog.h"
16
#include "cbtconfig.h"
18
#include "util/ctoolclass.h"
19
#include "util/cresmgr.h"
20
#include "util/cpointers.h"
22
#include "backend/cswordmoduleinfo.h"
23
#include "backend/cswordbackend.h"
29
#include <qpushbutton.h>
31
#include <qlistview.h>
32
#include <qfileinfo.h>
33
#include <qcheckbox.h>
37
#include <klistview.h>
38
#include <kiconloader.h>
40
namespace BookshelfManager {
43
CManageIndicesWidget::CManageIndicesWidget(QWidget* parent, const char* name) :
44
ManageIndicesForm(parent, name) {
50
CManageIndicesWidget::~CManageIndicesWidget()
52
CBTConfig::set( CBTConfig::autoDeleteOrphanedIndices, m_autoDeleteOrphanedIndicesBox->isChecked() );
56
/** Initializes the look and feel of this page */
57
void CManageIndicesWidget::initView()
59
// Set description label
60
QVBoxLayout* box = new QVBoxLayout(m_labelFrame, 0, 0);
61
QLabel* mainLabel = CToolClass::explanationLabel(m_labelFrame,
62
i18n("Manage module search indices"),
63
i18n("You can use the list below to create and/or delete search indices for your installed works."));
64
box->addWidget(mainLabel);
66
// configure the list view
67
m_moduleList->addColumn(i18n("Module"));
68
m_moduleList->addColumn(i18n("Index size"));
69
m_moduleList->setRootIsDecorated(true);
70
m_moduleList->setColumnWidth(0, 150);
71
m_moduleList->setColumnAlignment(1, Qt::AlignRight);
72
m_moduleList->setSorting( -1 );
74
m_autoDeleteOrphanedIndicesBox->setChecked( CBTConfig::get( CBTConfig::autoDeleteOrphanedIndices ) );
76
// icons for our buttons
77
m_createIndicesButton->setIconSet(SmallIcon("folder_new", 16));
78
m_deleteIndicesButton->setIconSet(SmallIcon("remove", 16));
80
// connect our signals/slots
81
connect(m_createIndicesButton, SIGNAL(clicked()), this, SLOT(createIndices()));
82
connect(m_deleteIndicesButton, SIGNAL(clicked()), this, SLOT(deleteIndices()));
85
/** Populates the module list with installed modules and orphaned indices */
86
void CManageIndicesWidget::populateModuleList() {
87
m_moduleList->clear();
89
// populate installed modules
90
m_modsWithIndices = new QCheckListItem(m_moduleList, i18n("Modules with indices"),
91
QCheckListItem::CheckBoxController);
92
m_modsWithIndices->setOpen(true);
94
m_modsWithoutIndices = new QCheckListItem(m_moduleList, i18n("Modules without indices"),
95
QCheckListItem::CheckBoxController);
96
m_modsWithoutIndices->setOpen(true);
98
ListCSwordModuleInfo& modules = CPointers::backend()->moduleList();
99
ListCSwordModuleInfo::iterator end_it = modules.end();
100
for (ListCSwordModuleInfo::iterator it = modules.begin(); it != end_it; ++it) {
101
QCheckListItem* item = 0;
103
if ((*it)->hasIndex()) {
104
item = new QCheckListItem(m_modsWithIndices, (*it)->name(),
105
QCheckListItem::CheckBox);
106
item->setText(1, QString("%1 ").arg((*it)->indexSize() / 1024) + i18n("KiB"));
109
item = new QCheckListItem(m_modsWithoutIndices, (*it)->name(),
110
QCheckListItem::CheckBox);
111
item->setText(1, QString("0 ") + i18n("KiB"));
116
/** Creates indices for selected modules if no index currently exists */
117
void CManageIndicesWidget::createIndices()
119
QCheckListItem* top = m_modsWithoutIndices;
120
bool indicesCreated = false;
121
QCheckListItem* item = (QCheckListItem*)top->firstChild();
123
ListCSwordModuleInfo moduleList;
126
CSwordModuleInfo* module =
127
CPointers::backend()->findModuleByName(item->text().utf8());
131
moduleList.append( module );
132
indicesCreated = true;
135
item = (QCheckListItem*)item->nextSibling();
138
//Shows the progress dialog
139
if (indicesCreated) {
140
CModuleIndexDialog::getInstance()->indexAllModules( moduleList );
141
populateModuleList();
145
/** Deletes indices for selected modules and selected orphans */
146
void CManageIndicesWidget::deleteIndices()
148
// delete installed module indices
149
QCheckListItem* top = m_modsWithIndices;
150
bool indicesDeleted = false;
151
QCheckListItem* item = (QCheckListItem*)top->firstChild();
154
CSwordModuleInfo* module =
155
CPointers::backend()->findModuleByName(item->text().utf8());
157
CSwordModuleInfo::deleteIndexForModule( module->name() );
158
indicesDeleted = true;
161
item = (QCheckListItem*)item->nextSibling();
164
// repopulate the list if an action was taken
165
if (indicesDeleted) {
166
populateModuleList();
170
void CManageIndicesWidget::deleteOrphanedIndices()
172
QDir dir(CSwordModuleInfo::getGlobalBaseIndexLocation());
173
dir.setFilter(QDir::Dirs);
174
CSwordModuleInfo* module;
176
for (unsigned int i = 0; i < dir.count(); i++) {
177
if (dir[i] != "." && dir[i] != "..") {
178
if (module = CPointers::backend()->findModuleByName( dir[i] ) ) { //mod exists
179
if (!module->hasIndex()){ //index files found, but wrong version etc.
180
CSwordModuleInfo::deleteIndexForModule( dir[i] );
183
else{ //no module exists
184
if (CBTConfig::get( CBTConfig::autoDeleteOrphanedIndices ) ){
185
CSwordModuleInfo::deleteIndexForModule( dir[i] );