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 "cswordsetupdialog.h"
13
#include "cswordsetupmodulelistview.h"
14
#include "cswordsetupinstallsourcesdialog.h"
16
#include "backend/cswordbackend.h"
17
#include "backend/cswordmoduleinfo.h"
18
// #include "btinstallmgr.h"
20
#include "cmanageindiceswidget.h"
22
#include "util/cresmgr.h"
23
#include "util/ctoolclass.h"
24
#include "util/scoped_resource.h"
30
#include <qcombobox.h>
31
#include <qwidgetstack.h>
32
#include <qfileinfo.h>
33
#include <qpushbutton.h>
34
#include <qlineedit.h>
38
#include <kapplication.h>
40
#include <kdirselectdialog.h>
41
#include <keditlistbox.h>
43
#include <kstandarddirs.h>
44
#include <kiconloader.h>
45
#include <kmessagebox.h>
46
#include <kprogress.h>
50
#include <installmgr.h>
52
#include <swversion.h>
54
using namespace sword;
56
namespace BookshelfManager {
58
CSwordSetupDialog::CSwordSetupDialog(QWidget *parent, const char *name )
59
: KDialogBase(IconList, i18n("Bookshelf Manager"), Ok, Ok, parent, name, true, true, QString::null, QString::null, QString::null),
60
m_removeModuleListView(0),
61
m_installModuleListPage(0),
62
m_installModuleListView(0),
64
m_refreshedRemoteSources(false) {
65
setIconListAllVisible(true);
66
m_swordSetupChanged = false;
74
void CSwordSetupDialog::initSwordConfig() {
75
QFrame* page = m_swordConfigPage = addPage(i18n("Bookshelf path(s)"), QString::null, SmallIcon("bt_swordconfig",32));
76
page->setMinimumSize(500,400);
78
QGridLayout* layout = new QGridLayout(page, 6, 4);
81
layout->setSpacing(10);
82
layout->setColStretch(0,1);
83
layout->setRowStretch(5,1);
85
QLabel* mainLabel = CToolClass::explanationLabel(page,
86
i18n("Configure bookshelf path(s)"),
87
i18n("You can store your bookshelfs in one or more directories, which you can specify here.")
89
layout->addMultiCellWidget(mainLabel, 0, 0, 0, 3);
92
QString swordConfPath = BTInstallMgr::Tool::LocalConfig::swordConfigFilename();
93
QLabel* confPathLabel = new QLabel(i18n("Your bookshelf configuration file is <b>%1</b>").arg(swordConfPath), page);
94
layout->addMultiCellWidget(confPathLabel, 1,1,0,3);
96
m_swordPathListBox = new QListView(page);
97
// m_swordPathListBox->setFullWidth(true);
98
m_swordPathListBox->addColumn(i18n("Path to bookshelf"));
99
connect(m_swordPathListBox, SIGNAL(selectionChanged()), this, SLOT(slot_swordPathSelected()));
100
layout->addMultiCellWidget(m_swordPathListBox, 2,5,0,1);
102
m_swordEditPathButton = new QPushButton(i18n("Edit Entry"), page);
103
m_swordEditPathButton->setIconSet(SmallIcon("edit", 16));
104
connect(m_swordEditPathButton, SIGNAL(clicked()), this, SLOT(slot_swordEditClicked()));
105
layout->addWidget(m_swordEditPathButton, 2, 3);
107
m_swordAddPathButton = new QPushButton(i18n("Add Entry"), page);
108
m_swordAddPathButton->setIconSet(SmallIcon("edit_add", 16));
109
connect(m_swordAddPathButton, SIGNAL(clicked()), this, SLOT(slot_swordAddClicked()));
110
layout->addWidget(m_swordAddPathButton, 3,3);
112
m_swordRemovePathButton = new QPushButton(i18n("Remove Entry"), page);
113
m_swordRemovePathButton->setIconSet(SmallIcon("editdelete", 16));
114
connect(m_swordRemovePathButton, SIGNAL(clicked()), this, SLOT(slot_swordRemoveClicked()));
115
layout->addWidget(m_swordRemovePathButton, 4,3);
117
setupSwordPathListBox();
120
void CSwordSetupDialog::initInstall() {
121
m_installPage = addPage(i18n("Install/Update works"), QString::null, SmallIcon("bt_bible",32));
123
QVBoxLayout* vboxlayout = new QVBoxLayout(m_installPage);
124
QHBoxLayout* hboxlayout = new QHBoxLayout();
125
hboxlayout->setAutoAdd( true );
127
vboxlayout->addLayout(hboxlayout);
129
m_installWidgetStack = new QWidgetStack(m_installPage);
130
hboxlayout->addWidget(m_installWidgetStack);
132
m_installSourcePage = new QWidget(0);
133
m_installWidgetStack->addWidget(m_installSourcePage);
135
// m_installSourcePage->setMinimumSize(500,400);
137
QGridLayout* layout = new QGridLayout(m_installSourcePage, 7, 3);
138
layout->setMargin(5);
139
layout->setSpacing(10);
140
layout->setRowStretch(6,5);
141
layout->setColStretch(0,5);
143
QLabel* installLabel = CToolClass::explanationLabel(m_installSourcePage,
144
i18n("Install/update works - Step 1"),
145
i18n("Please choose a (local or remote) library and a bookshelf path to install the work(s) to. \
146
After that step click on the connect button.<br/>\
147
<b>WARNING: If you live in a persecuted country and do not wish to risk detection you should NOT use \
148
the module remote installation feature!</b>")
150
layout->addMultiCellWidget(installLabel, 0,0,0,2);
152
QLabel* sourceHeadingLabel = new QLabel(QString("<b>%1</b>").arg(i18n("Select library")), m_installSourcePage);
153
layout->addMultiCellWidget(sourceHeadingLabel, 1,1,0,1);
155
m_sourceCombo = new QComboBox(m_installSourcePage);
156
layout->addWidget(m_sourceCombo, 2, 0);
158
QPushButton* deleteSourceButton = new QPushButton(i18n("Delete library"), m_installSourcePage);
159
deleteSourceButton->setIconSet(SmallIcon("remove", 16));
160
connect(deleteSourceButton, SIGNAL(clicked()), SLOT(slot_installDeleteSource()));
161
layout->addWidget(deleteSourceButton, 2, 1, Qt::AlignLeft);
163
QPushButton* addSourceButton = new QPushButton(i18n("Add library"), m_installSourcePage);
164
addSourceButton->setIconSet(SmallIcon("folder_new", 16));
165
connect(addSourceButton, SIGNAL(clicked()), SLOT(slot_installAddSource()));
166
layout->addWidget(addSourceButton, 2, 2, Qt::AlignLeft);
168
m_sourceLabel = new QLabel(m_installSourcePage);
169
layout->addMultiCellWidget(m_sourceLabel, 3,3,0,1);
171
QLabel* targetHeadingLabel = new QLabel(QString("<b>%1</b>").arg(i18n("Select bookshelf path")), m_installSourcePage);
172
layout->addMultiCellWidget(targetHeadingLabel, 4,4,0,1);
174
m_targetCombo = new QComboBox(m_installSourcePage);
175
layout->addWidget(m_targetCombo, 5, 0);
177
m_targetLabel = new QLabel(m_installSourcePage);
178
layout->addMultiCellWidget(m_targetLabel, 6,6,0,0,Qt::AlignTop);
180
//part beloew main layout with the back/next buttons
181
QHBoxLayout* myHBox = new QHBoxLayout();
182
vboxlayout->addLayout(myHBox);
184
m_installBackButton = new QPushButton(i18n("Back"), m_installPage);
185
m_installBackButton->setIconSet(SmallIcon("back",16));
186
myHBox->addWidget(m_installBackButton);
188
myHBox->addSpacing(10);
189
myHBox->addStretch(5);
191
m_installContinueButton = new QPushButton(i18n("Connect to library"), m_installPage);
192
m_installContinueButton->setIconSet(SmallIcon("forward",16));
193
connect(m_installContinueButton, SIGNAL(clicked()), this, SLOT(slot_connectToSource()));
194
myHBox->addWidget(m_installContinueButton);
196
m_installBackButton->setEnabled(false);
198
connect(m_sourceCombo, SIGNAL( highlighted(const QString&) ), SLOT( slot_sourceSelected( const QString&) ));
199
connect(m_targetCombo, SIGNAL( highlighted(const QString&) ), SLOT( slot_targetSelected( const QString&) ));
200
populateInstallCombos();
202
slot_sourceSelected( m_sourceCombo->currentText() );
205
void CSwordSetupDialog::initRemove() {
206
QFrame* page = m_removePage = addPage(i18n("Remove works"), QString::null, SmallIcon("edittrash",32));
208
page->setMinimumSize(500,400);
210
QGridLayout* layout = new QGridLayout(page, 4, 4);
211
layout->setMargin(5);
213
layout->setSpacing(10);
214
layout->setColStretch(1,1);
215
layout->setRowStretch(2,1);
217
QLabel* mainLabel= CToolClass::explanationLabel(page,
218
i18n("Remove installed work(s)"),
219
i18n("This dialog lets you remove installed works from your system. Choose the modules and then click on the remove button.")
221
layout->addMultiCellWidget(mainLabel, 0, 0, 0, 3);
223
QLabel* headingLabel = new QLabel(QString("<b>%1</b>").arg(i18n("Select works to be uninstalled")), page);
224
layout->addMultiCellWidget(headingLabel, 1, 1, 0, 3);
226
m_removeModuleListView = new CSwordSetupModuleListView(page, false);
227
layout->addMultiCellWidget( m_removeModuleListView, 2,2,0,3);
229
m_removeRemoveButton = new QPushButton(i18n("Remove selected work(s)"), page);
230
m_removeRemoveButton->setIconSet( SmallIcon("edittrash", 16) );
231
layout->addWidget(m_removeRemoveButton, 3, 3, Qt::AlignRight);
233
connect(m_removeRemoveButton, SIGNAL(clicked()),
234
this, SLOT(slot_doRemoveModules()));
236
populateRemoveModuleListView();
239
void CSwordSetupDialog::initManageIndices()
241
QFrame* page = m_manageIndiciesPage = addPage(i18n("Manage search indicies"),
242
QString::null, SmallIcon("filefind",32));
244
page->setMinimumSize(500,400);
245
QVBoxLayout* box = new QVBoxLayout(page, 4, 4);
246
CManageIndicesWidget* mi = new CManageIndicesWidget(page);
250
void CSwordSetupDialog::slotOk() {
252
KDialogBase::slotOk();
253
emit signalSwordSetupChanged( );
256
void CSwordSetupDialog::writeSwordConfig() {
257
if (m_swordSetupChanged && m_swordPathListBox->childCount()) {
259
QListViewItemIterator it( m_swordPathListBox );
260
while ( it.current() ) {
261
QListViewItem *item = it.current();
262
if (!item->text(0).isEmpty()) {
263
targets << item->text(0);
268
BTInstallMgr::Tool::LocalConfig::setTargetList(targets); //creates new Sword config
272
const bool CSwordSetupDialog::showPart( CSwordSetupDialog::Parts ID ) {
275
case CSwordSetupDialog::Sword:
276
showPage( pageIndex(m_swordConfigPage) );
278
case CSwordSetupDialog::Install:
279
showPage( pageIndex(m_installPage) );
281
case CSwordSetupDialog::Remove:
282
showPage( pageIndex(m_removePage) );
291
void CSwordSetupDialog::populateInstallCombos() {
292
m_sourceCombo->clear();
294
BTInstallMgr::Tool::RemoteConfig::initConfig();
299
list = BTInstallMgr::Tool::RemoteConfig::sourceList(&mgr);
301
if (!list.count()) { //add Crosswire entry
302
InstallSource is("FTP"); //default return value
303
is.caption = "Crosswire";
304
is.source = "ftp.crosswire.org";
305
is.directory = "/pub/sword/raw";
306
BTInstallMgr::Tool::RemoteConfig::addSource(&is);
308
BTInstallMgr mgr; //make sure we're uptodate
309
list = BTInstallMgr::Tool::RemoteConfig::sourceList(&mgr);
311
Q_ASSERT( list.count() > 0 );
315
for (QStringList::iterator it = list.begin(); it != list.end(); ++it) {
316
sword::InstallSource is = BTInstallMgr::Tool::RemoteConfig::source(&mgr, *it);
318
if (BTInstallMgr::Tool::RemoteConfig::isRemoteSource(&is)) {
319
m_sourceCombo->insertItem( i18n("[Remote]") + " " + *it ); //remote source
321
else { // local source
322
QFileInfo fi( is.directory.c_str() );
323
if (fi.isDir() && fi.isReadable()) {
324
m_sourceCombo->insertItem( i18n("[Local]") + " " + *it );
329
//Fill in the targets in the targets combobox
330
//list = (m_targetCombo->count()) ? m_swordPathListBox : BTInstallMgr::Tool::LocalConfig::targetList();
331
if (m_targetCombo->count()) { //we already read in the list once, we have to use the Sword paths list items now because this list is newer
333
QListViewItemIterator it2( m_swordPathListBox );
334
while (it2.current()) {
335
list << it2.current()->text(0);
341
list = BTInstallMgr::Tool::LocalConfig::targetList();
344
m_targetCombo->clear();
345
for (QStringList::iterator it = list.begin(); it != list.end(); ++it) {
347
if (fi.isDir() && fi.isWritable()) {
348
m_targetCombo->insertItem( *it );
353
m_targetCombo->setEnabled( (m_targetCombo->count() > 0) );
354
m_installContinueButton->setEnabled(
355
(m_sourceCombo->count() > 0) && (m_targetCombo->count() > 0)
358
slot_sourceSelected( m_sourceCombo->currentText() );
362
void CSwordSetupDialog::slot_sourceSelected(const QString &sourceName) {
363
//remove status parta
364
QString source = sourceName;
366
QString rep = i18n("[Local]") + " ";
367
int i = source.find(rep);
369
source.remove(i, rep.length());
371
rep = i18n("[Remote]") + " ";
372
i = source.find(rep);
374
source.remove(i, rep.length());
379
sword::InstallSource is = BTInstallMgr::Tool::RemoteConfig::source(&mgr, source) ;
381
if (BTInstallMgr::Tool::RemoteConfig::isRemoteSource(&is)) {
382
url = QString("ftp://%1%2").arg(is.source.c_str()).arg(is.directory.c_str());
385
url = QString("%1").arg(is.directory.c_str());
387
m_sourceLabel->setText( url );
389
m_refreshedRemoteSources = false;
393
void CSwordSetupDialog::slot_targetSelected(const QString &targetName) {
394
m_targetLabel->setText( m_targetMap[targetName] );
395
target = m_targetMap[targetName];
399
void CSwordSetupDialog::slot_doRemoveModules() {
401
QStringList moduleList = m_removeModuleListView->selectedModules();
403
if ( moduleList.empty() ) {
404
return; //no message, just do nothing
407
const QString message = i18n("You selected the following work(s): %1.\n\n"
408
"Do you really want to remove them from your system?").arg(moduleList.join(", "));
410
if ((KMessageBox::warningYesNo(0, message, i18n("Warning")) == KMessageBox::Yes)) { //Yes was pressed.
411
sword::InstallMgr installMgr;
412
QDict<sword::SWMgr> mgrDict; //maps config paths to SWMgr objects
414
for ( QStringList::Iterator it = moduleList.begin(); it != moduleList.end(); ++it ) {
415
if (CSwordModuleInfo* m = backend()->findModuleByName(*it)) { //module found?
416
QString prefixPath = m->config(CSwordModuleInfo::AbsoluteDataPath) + "/";
417
QString dataPath = m->config(CSwordModuleInfo::DataPath);
419
if (dataPath.left(2) == "./") {
420
dataPath = dataPath.mid(2);
423
if (prefixPath.contains(dataPath)) { //remove module part to get the prefix path
424
prefixPath = prefixPath.remove( prefixPath.find(dataPath), dataPath.length() );
426
else { //fall back to default Sword config path
427
prefixPath = QString::fromLatin1(backend()->prefixPath);
430
sword::SWMgr* mgr = mgrDict[ prefixPath ];
431
if (!mgr) { //create new mgr if it's not yet available
432
mgrDict.insert(prefixPath, new sword::SWMgr(prefixPath.local8Bit()));
433
mgr = mgrDict[ prefixPath ];
436
installMgr.removeModule(mgr, m->name().latin1());
440
CPointers::backend()->reloadModules();
441
populateRemoveModuleListView(); //rebuild the tree
442
populateInstallModuleListView( currentInstallSource() ); //rebuild the tree
445
mgrDict.setAutoDelete(true);
450
void CSwordSetupDialog::populateRemoveModuleListView() {
451
CSwordBackend myBackend;
452
KApplication::kApplication()->processEvents();
453
myBackend.initModules();
455
m_removeModuleListView->clear();
457
ListCSwordModuleInfo list = myBackend.moduleList();
459
sword::SWConfig moduleConfig("");
462
ListCSwordModuleInfo::iterator end_it = list.end();
464
for (ListCSwordModuleInfo::iterator it(list.begin()); it != end_it; ++it, ++mod) {
465
m_removeModuleListView->addModule(
467
(*it)->config(CSwordModuleInfo::ModuleVersion)
471
m_removeModuleListView->finish();
474
const bool CSwordSetupDialog::refreshRemoteModuleCache( const QString& sourceName ) {
475
if (m_refreshedRemoteSources) { //the module info is up-to-date
480
m_currentInstallMgr = &iMgr; //for the progress dialog
481
sword::InstallSource is = BTInstallMgr::Tool::RemoteConfig::source(&iMgr, sourceName);
482
bool success = false;
484
m_progressDialog = new KProgressDialog(0,0,i18n("Download"), QString::null, true);
487
m_progressDialog, SIGNAL(cancelClicked()),
488
SLOT(slot_moduleRefreshProgressCancelClicked())
491
&iMgr, SIGNAL(completed(const int, const int)),
492
SLOT(slot_moduleRefreshCompleted(const int, const int))
495
m_progressDialog->progressBar()->setTotalSteps(100);
496
m_progressDialog->setMinimumDuration(0); //show immediately
497
m_progressDialog->setLabel( i18n("Downloading library information...") );
499
if (BTInstallMgr::Tool::RemoteConfig::isRemoteSource(&is)) {
500
// int errorCode = 0;
501
if (!m_refreshedRemoteSources) {
502
if (!iMgr.refreshRemoteSource( &is ) ) { //make sure the sources were updates sucessfully
503
m_refreshedRemoteSources = true;
505
m_progressDialog->progressBar()->setProgress(100); //make sure the dialog closes
507
else { //an error occurres, the KIO library should display an error message
508
qWarning("InstallMgr: refreshRemoteSources returned an error.");
509
m_refreshedRemoteSources = false;
515
delete m_progressDialog;
516
m_progressDialog = 0;
521
bool CSwordSetupDialog::populateInstallModuleListView( const QString& sourceName ) {
522
KApplication::kApplication()->processEvents();
523
Q_ASSERT(m_installModuleListView);
524
if (!m_installModuleListView) { // this may be an update after removing modules
528
m_installModuleListView->clear();
531
sword::InstallSource is = BTInstallMgr::Tool::RemoteConfig::source(&iMgr, sourceName);
533
if (BTInstallMgr::Tool::RemoteConfig::isRemoteSource(&is)
534
&& !refreshRemoteModuleCache(sourceName)) {
535
// qWarning("finish");
536
m_installModuleListView->finish();
540
//kind of a hack to provide a pointer to mgr next line
541
// qWarning("createing remote_backend");
542
util::scoped_ptr<CSwordBackend> remote_backend( BTInstallMgr::Tool::backend(&is) );
543
// qWarning("config path1 is %s", remote_backend->configPath);
544
// qWarning("config path2 is %s", BTInstallMgr::Tool::backend(&is)->configPath ); //mem leak
545
// qWarning("after creating remote_backend");
546
Q_ASSERT(remote_backend);
547
Q_ASSERT( BTInstallMgr::Tool::RemoteConfig::isRemoteSource(&is) );
548
if (!remote_backend) {
549
m_installModuleListView->finish();
553
CSwordBackend* local_backend = CPointers::backend();
554
Q_ASSERT(local_backend);
555
// qWarning("local backend has path %s", local_backend->);
556
KApplication::kApplication()->processEvents();
557
//local_backend.initModules();
559
// qWarning("config path3 is %s", remote_backend->configPath);
560
ListCSwordModuleInfo mods = remote_backend->moduleList();
561
Q_ASSERT(mods.count() > 0);
563
ListCSwordModuleInfo::iterator end_it = mods.end();
564
for (ListCSwordModuleInfo::iterator it(mods.begin()); it != end_it; ++it) {
565
// qWarning("adding module %s (%s)", (*it)->name().latin1(), (*it)->config(CSwordModuleInfo::AbsoluteDataPath).latin1());
566
bool isUpdate = false;
568
CSwordModuleInfo* const installedModule = local_backend->findModuleByName((*it)->name());
569
if (installedModule) {
570
// qWarning("module is already installed in %s", installedModule->config(CSwordModuleInfo::AbsoluteDataPath).latin1());
572
// Q_ASSERT(installedModule);
574
if (installedModule) { //module already installed?
575
//check whether it's an uodated module or just the same
576
const SWVersion installedVersion(
577
installedModule->config(CSwordModuleInfo::ModuleVersion).latin1()
580
const SWVersion newVersion(
581
(*it)->config(CSwordModuleInfo::ModuleVersion).latin1()
584
isUpdate = (newVersion > installedVersion);
586
// qWarning(" mod %s is not an update", (*it)->name().latin1());
591
// Q_ASSERT(installedModule);
592
m_installModuleListView->addModule(
595
? installedModule->config(CSwordModuleInfo::ModuleVersion)
599
m_installModuleListView->finish();
603
void CSwordSetupDialog::slot_connectToSource() {
604
if (!m_installModuleListPage) { //the widgets are not yet created
605
m_installModuleListPage = new QWidget(0);
607
QGridLayout* layout = new QGridLayout(m_installModuleListPage, 7, 2);
608
layout->setMargin(5);
609
layout->setSpacing(10);
611
QLabel* installLabel = CToolClass::explanationLabel(m_installModuleListPage,
612
i18n("Install/update works - Step 2"),
613
i18n("Please choose the works which should be installed and/or updated and click the install button.")
615
layout->addMultiCellWidget(installLabel, 0,0,0,1);
616
layout->setRowStretch(0,0);
618
m_installWidgetStack->addWidget(m_installModuleListPage);
619
m_installModuleListPage->setMinimumSize(500,400);
621
//insert a list box which contains all available remote modules
623
sword::InstallSource is = BTInstallMgr::Tool::RemoteConfig::source(&iMgr, currentInstallSource());
625
m_installModuleListView = new CSwordSetupModuleListView(m_installModuleListPage, true, &is);
626
layout->addMultiCellWidget( m_installModuleListView, 1,6,0,1);
627
layout->setColStretch(0,5);
628
layout->setRowStretch(1,5);
630
connect(m_installModuleListView, SIGNAL(selectedModulesChanged()), SLOT(slot_installModulesChanged()));
633
if (populateInstallModuleListView( currentInstallSource() ) ){
635
//code valid for already existing and newly created widgets
636
disconnect( m_installContinueButton, SIGNAL(clicked()), this, SLOT(slot_connectToSource()));
637
connect( m_installContinueButton, SIGNAL(clicked()), this, SLOT(slot_installModules()));
639
m_installContinueButton->setText(i18n("Install works"));
640
m_installContinueButton->setEnabled(false);
642
m_installWidgetStack->raiseWidget(m_installModuleListPage);
644
connect( m_installBackButton, SIGNAL(clicked()), this, SLOT(slot_showInstallSourcePage()));
645
m_installBackButton->setEnabled(true);
649
void CSwordSetupDialog::slot_installAddSource() {
651
sword::InstallSource newSource = CSwordSetupInstallSourcesDialog::getSource();
653
if ( !((QString)newSource.type.c_str()).isEmpty() ) { // we have a valid source to add
654
BTInstallMgr::Tool::RemoteConfig::addSource( &newSource );
657
populateInstallCombos(); //make sure the items are updated
660
void CSwordSetupDialog::slot_installDeleteSource() {
663
sword::InstallSource is = BTInstallMgr::Tool::RemoteConfig::source( &iMgr, currentInstallSource() );
664
BTInstallMgr::Tool::RemoteConfig::removeSource( &iMgr, &is );
666
populateInstallCombos();
669
void CSwordSetupDialog::slot_installModulesChanged() {
670
// This function enabled the Install modules button if modules are chosen
671
// If an item was clicked to be not chosen look if there are other selected items
672
// If the item was clicked to be chosen enable the button without looking at the other items
674
const int moduleCount = m_installModuleListView->selectedModules().count();
675
m_installContinueButton->setEnabled(moduleCount > 0);
678
void CSwordSetupDialog::slot_installModules() {
679
qWarning("CSwordSetupDialog::slot_installModules()");
680
// m_installContinueButton->setEnabled(false);
681
// m_installBackButton->setEnabled(false);
683
//first get all chosen modules
684
QStringList moduleList = m_installModuleListView->selectedModules();
685
Q_ASSERT(moduleList.count() != 0);
686
if (moduleList.count() == 0) { // no modules selected
690
const QString message = i18n("You selected the following works: %1.\n\n\
691
Do you really want to install them on your system?").arg(moduleList.join(", "));
693
if ((KMessageBox::warningYesNo(0, message, i18n("Warning")) == KMessageBox::Yes)) { //Yes was pressed.
695
m_currentInstallMgr = &iMgr;
696
sword::InstallSource is = BTInstallMgr::Tool::RemoteConfig::source(&iMgr, currentInstallSource());
698
qWarning("installing from %s/%s", is.source.c_str(), is.directory.c_str());
699
QString target = m_targetCombo->currentText();
701
//make sure target/mods.d and target/modules exist
702
QDir dir(target.latin1());
704
dir.mkdir(target, true);
706
if (!dir.exists("modules")) {
707
dir.mkdir("modules");
709
if (!dir.exists("mods.d")) {
713
sword::SWMgr lMgr( target.latin1() );
715
//module are removed in this section of code
716
m_installedModuleCount = 0;
717
m_progressDialog = new KProgressDialog(0,0,i18n("Download of work(s)"), QString::null, true);
720
m_progressDialog, SIGNAL(cancelClicked()),
721
SLOT(slot_installProgressCancelClicked())
724
&iMgr, SIGNAL(completed(const int, const int)),
725
SLOT(installCompleted(const int, const int))
728
m_progressDialog->progressBar()->setTotalSteps(100 * moduleList.count());
729
m_progressDialog->setMinimumDuration(0); //show immediately
732
for ( QStringList::Iterator it = moduleList.begin(); (it != moduleList.end()) && !m_progressDialog->wasCancelled(); ++it, ++m_installedModuleCount ) {
734
qWarning("installing %s", (*it).latin1());
735
m_installingModule = *it;
737
//check whether it's an update. If yes, remove existing module first
738
CSwordModuleInfo* m = backend()->findModuleByName(*it);
740
if (m) { //module found?
741
QString prefixPath = m->config(CSwordModuleInfo::AbsoluteDataPath) + "/";
742
QString dataPath = m->config(CSwordModuleInfo::DataPath);
743
if (dataPath.left(2) == "./") {
744
dataPath = dataPath.mid(2);
747
if (prefixPath.contains(dataPath)) {
748
prefixPath.remove( prefixPath.find(dataPath), dataPath.length() ); //complicated to work with Qt 3.0
749
//prefixPath = prefixPath.replace(dataPath, ""); //old code working with Qt 3.2
752
prefixPath = QString::fromLatin1(backend()->prefixPath);
755
sword::SWMgr mgr(prefixPath.latin1());
756
iMgr.removeModule(&mgr, m->name().latin1());
759
if (!m_progressDialog->wasCancelled()
760
&& BTInstallMgr::Tool::RemoteConfig::isRemoteSource(&is)) {
761
// qWarning("calling install");
762
int status = iMgr.installModule(&lMgr, 0, (*it).latin1(), &is);
763
// qWarning("status: %d", status);
764
Q_ASSERT(status != -1);
766
else if (!m_progressDialog->wasCancelled()) { //local source
767
iMgr.installModule(&lMgr, is.directory.c_str(), (*it).latin1());
771
delete m_progressDialog;
772
m_progressDialog = 0;
774
//reload our backend because modules may have changed
775
backend()->reloadModules();
776
populateInstallModuleListView( currentInstallSource() ); //rebuild the tree
777
populateRemoveModuleListView();
780
m_currentInstallMgr = 0;
781
m_installBackButton->setEnabled(true);
782
slot_installModulesChanged();
785
void CSwordSetupDialog::installCompleted( const int total, const int /* file */) {
786
if (m_progressDialog) {
787
m_progressDialog->progressBar()->setProgress(total+100*m_installedModuleCount);
788
m_progressDialog->setLabel( i18n("[%1]: %2% complete").arg(m_installingModule).arg(total) );
792
void CSwordSetupDialog::slot_showInstallSourcePage() {
793
connect( m_installContinueButton, SIGNAL(clicked()), this, SLOT(slot_connectToSource()));
794
disconnect( m_installContinueButton, SIGNAL(clicked()), this, SLOT(slot_installModules()));
795
m_installBackButton->setEnabled(false);
797
m_installContinueButton->setText(i18n("Connect to library"));
798
m_installContinueButton->setEnabled(true);
800
m_installWidgetStack->raiseWidget(m_installSourcePage);
803
void CSwordSetupDialog::slot_swordEditClicked() {
804
if (QListViewItem* i = m_swordPathListBox->currentItem()) {
805
KURL url = KDirSelectDialog::selectDirectory(i->text(0), true);
807
const QFileInfo fi( url.path() );
808
if (!fi.exists() || !fi.isWritable()) {
809
const int result = KMessageBox::warningYesNo(this, i18n("This directory is not writable, so works \
810
can not be installed here using BibleTime. \
811
Do you want to use this directory instead of the previous value?"));
812
if (result == KMessageBox::No) {
816
i->setText(0, url.path());
817
m_swordSetupChanged = true;
818
writeSwordConfig(); //to make sure other parts work with the new setting
819
populateInstallCombos(); //update target list bof on install page
820
populateRemoveModuleListView();
825
void CSwordSetupDialog::slot_swordAddClicked() {
826
KURL url = KDirSelectDialog::selectDirectory(QString::null, true);
828
const QFileInfo fi( url.path() );
829
if (!fi.exists() || !fi.isWritable()) {
830
const int result = KMessageBox::warningYesNo(this, i18n("This directory is not writable, \
831
so works can not be installed here using BibleTime. \
832
Do you want to add it to the list of module directories?"));
833
if (result == KMessageBox::No) {
837
(void)new QListViewItem(m_swordPathListBox, url.path());
838
m_swordSetupChanged = true;
839
writeSwordConfig(); //to make sure other parts work with the new setting
840
populateInstallCombos(); //update target list bof on install page
841
populateRemoveModuleListView();
845
void CSwordSetupDialog::slot_swordRemoveClicked() {
846
QListViewItem* i = m_swordPathListBox->currentItem();
850
m_swordSetupChanged = true;
851
writeSwordConfig(); //to make sure other parts work with the new setting
852
populateInstallCombos(); //update target list bof on install page
853
populateRemoveModuleListView();
857
void CSwordSetupDialog::setupSwordPathListBox() {
858
QStringList targets = BTInstallMgr::Tool::LocalConfig::targetList();
859
m_swordPathListBox->clear();
861
for (QStringList::iterator it = targets.begin(); it != targets.end(); ++it) {
862
if ((*it).isEmpty()) {
865
new QListViewItem(m_swordPathListBox, *it);
867
m_swordPathListBox->setCurrentItem( m_swordPathListBox->firstChild() );
870
void CSwordSetupDialog::slot_swordPathSelected() {
871
m_swordEditPathButton->setEnabled( m_swordPathListBox->currentItem() );
874
const QString CSwordSetupDialog::currentInstallSource() {
875
QString source = m_sourceCombo->currentText();
876
QString rep = i18n("[Local]") + " ";
877
int i = source.find(rep);
879
source.remove(i, rep.length());
881
rep = i18n("[Remote]") + " ";
882
i = source.find(rep);
884
source.remove(i, rep.length());
889
void CSwordSetupDialog::slot_installProgressCancelClicked() {
890
//cancel possible active module installation
891
Q_ASSERT(m_currentInstallMgr);
892
if (m_currentInstallMgr) {
893
m_currentInstallMgr->terminate();
897
void CSwordSetupDialog::slot_moduleRefreshProgressCancelClicked() {
898
Q_ASSERT(m_currentInstallMgr);
899
if (m_currentInstallMgr) {
900
m_currentInstallMgr->terminate();
904
void CSwordSetupDialog::slot_moduleRefreshCompleted(const int /*total*/, const int current) {
905
if (m_progressDialog) {
906
m_progressDialog->progressBar()->setProgress(current);