summaryrefslogtreecommitdiff
path: root/src/frontend/bookshelfmanager
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/bookshelfmanager')
-rw-r--r--src/frontend/bookshelfmanager/btconfigdialog.cpp27
-rw-r--r--src/frontend/bookshelfmanager/btconfigdialog.h5
-rw-r--r--src/frontend/bookshelfmanager/btinstallmgr.cpp22
-rw-r--r--src/frontend/bookshelfmanager/btinstallmgr.h12
-rw-r--r--src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp20
-rw-r--r--src/frontend/bookshelfmanager/btmodulemanagerdialog.h4
-rw-r--r--src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp157
-rw-r--r--src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h23
-rw-r--r--src/frontend/bookshelfmanager/indexpage/btindexpage.cpp37
-rw-r--r--src/frontend/bookshelfmanager/indexpage/btindexpage.h2
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp129
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h7
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpage.cpp106
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpage.h3
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp166
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h10
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp37
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h13
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallthread.cpp41
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallthread.h6
-rw-r--r--src/frontend/bookshelfmanager/installpage/btsourcearea.cpp82
-rw-r--r--src/frontend/bookshelfmanager/installpage/btsourcearea.h12
-rw-r--r--src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp171
-rw-r--r--src/frontend/bookshelfmanager/installpage/btsourcewidget.h15
-rw-r--r--src/frontend/bookshelfmanager/instbackend.cpp128
-rw-r--r--src/frontend/bookshelfmanager/instbackend.h12
-rw-r--r--src/frontend/bookshelfmanager/removepage/btremovepage.cpp53
-rw-r--r--src/frontend/bookshelfmanager/removepage/btremovepage.h7
28 files changed, 681 insertions, 626 deletions
diff --git a/src/frontend/bookshelfmanager/btconfigdialog.cpp b/src/frontend/bookshelfmanager/btconfigdialog.cpp
index 0fcbc5a..565765d 100644
--- a/src/frontend/bookshelfmanager/btconfigdialog.cpp
+++ b/src/frontend/bookshelfmanager/btconfigdialog.cpp
@@ -7,23 +7,22 @@
*
**********/
-
-#include "btconfigdialog.h"
-
-#include "util/directoryutil.h"
-#include "util/ctoolclass.h"
+#include "frontend/bookshelfmanager/btconfigdialog.h"
#include <QDialog>
-#include <QStackedWidget>
+#include <QDialogButtonBox>
+#include <QEvent>
+#include <QFrame>
+#include <QHBoxLayout>
+#include <QLabel>
#include <QListWidget>
#include <QListView>
#include <QListWidgetItem>
+#include <QStackedWidget>
#include <QVBoxLayout>
-#include <QHBoxLayout>
-#include <QLabel>
-#include <QDialogButtonBox>
-#include <QFrame>
-#include <QEvent>
+#include "util/directory.h"
+#include "util/tool.h"
+
BtConfigDialog::BtConfigDialog(QWidget* parent)
: QDialog(parent),
@@ -63,11 +62,13 @@ BtConfigDialog::BtConfigDialog(QWidget* parent)
BtConfigDialog::~BtConfigDialog() {}
void BtConfigDialog::addPage(BtConfigPage* pageWidget) {
+ namespace DU = util::directory;
+
// this is a friend
pageWidget->m_parentDialog = this;
QVBoxLayout* containerLayout = new QVBoxLayout;
- QLabel* headerLabel = CToolClass::explanationLabel(pageWidget, pageWidget->header(), pageWidget->label());
+ QLabel* headerLabel = util::tool::explanationLabel(pageWidget, pageWidget->header(), pageWidget->label());
containerLayout->addWidget(headerLabel);
containerLayout->addWidget(pageWidget);
QWidget* containerWidget = new QWidget(m_pageWidget);
@@ -76,7 +77,7 @@ void BtConfigDialog::addPage(BtConfigPage* pageWidget) {
QListWidgetItem* item = new QListWidgetItem(m_contentsList);
- item->setIcon(util::filesystem::DirectoryUtil::getIcon(pageWidget->iconName()));
+ item->setIcon(DU::getIcon(pageWidget->iconName()));
item->setText(pageWidget->header());
item->setTextAlignment(Qt::AlignHCenter);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
diff --git a/src/frontend/bookshelfmanager/btconfigdialog.h b/src/frontend/bookshelfmanager/btconfigdialog.h
index 8773a83..547cb4e 100644
--- a/src/frontend/bookshelfmanager/btconfigdialog.h
+++ b/src/frontend/bookshelfmanager/btconfigdialog.h
@@ -10,14 +10,13 @@
#ifndef BTCONFIGDIALOG_H
#define BTCONFIGDIALOG_H
-
#include <QDialog>
-#include <QWidget>
#include <QDebug>
+#include <QWidget>
-class BtConfigPage;
+class BtConfigPage;
class QListWidgetItem;
class QListWidget;
class QStackedWidget;
diff --git a/src/frontend/bookshelfmanager/btinstallmgr.cpp b/src/frontend/bookshelfmanager/btinstallmgr.cpp
index 799fa0d..ace804f 100644
--- a/src/frontend/bookshelfmanager/btinstallmgr.cpp
+++ b/src/frontend/bookshelfmanager/btinstallmgr.cpp
@@ -7,31 +7,27 @@
*
**********/
-//BibleTime includes
-#include "btinstallmgr.h"
+#include "frontend/bookshelfmanager/btinstallmgr.h"
-#include "frontend/bookshelfmanager/instbackend.h"
#include "backend/managers/cswordbackend.h"
-
-//Qt includes
-#include <QObject>
+#include "frontend/bookshelfmanager/instbackend.h"
+#include <QDebug>
#include <QList>
+#include <QObject>
#include <QString>
#include <QStringList>
-#include <QDebug>
-
-//sword includes
+// Sword includes:
#include <installmgr.h>
#include <ftptrans.h>
-using namespace sword;
+using namespace sword;
BtInstallMgr::BtInstallMgr()
: InstallMgr(instbackend::configPath().toLatin1(), this),
m_firstCallOfPreStatus(true) { //use this class also as status reporter
- qDebug("BtInstallMgr::BtInstallMgr");
+ qDebug() << "BtInstallMgr::BtInstallMgr";
this->setFTPPassive(true);
}
@@ -41,13 +37,13 @@ BtInstallMgr::~BtInstallMgr() {
}
bool BtInstallMgr::isUserDisclaimerConfirmed() const {
- // TODO: Check from config if it's been confirmed with "don't show this anymore" checked.
+ // \todo Check from config if it's been confirmed with "don't show this anymore" checked.
// Create a dialog with the message, checkbox and Continue/Cancel, Cancel as default.
return true;
}
void BtInstallMgr::statusUpdate(double dltotal, double dlnow) {
- //qDebug("BtInstallMgr::statusUpdate");
+ //qDebug() << "BtInstallMgr::statusUpdate";
if (dlnow > dltotal)
dlnow = dltotal;
diff --git a/src/frontend/bookshelfmanager/btinstallmgr.h b/src/frontend/bookshelfmanager/btinstallmgr.h
index 0561b96..7eff1ae 100644
--- a/src/frontend/bookshelfmanager/btinstallmgr.h
+++ b/src/frontend/bookshelfmanager/btinstallmgr.h
@@ -10,19 +10,19 @@
#ifndef NEWBTINSTALLMGR_H
#define NEWBTINSTALLMGR_H
-//sword includes
-#include <installmgr.h>
-#include <ftptrans.h>
-
-//Qt includes
#include <QObject>
+
#include <QList>
#include <QString>
#include <QStringList>
-class CSwordBackend;
+// Sword includes:
+#include <installmgr.h>
+#include <ftptrans.h>
+class CSwordBackend;
+
typedef QList<sword::InstallSource*> InstallSourceList;
/**
diff --git a/src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp b/src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp
index b361965..b261305 100644
--- a/src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp
+++ b/src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp
@@ -7,21 +7,19 @@
*
**********/
-#include "btmodulemanagerdialog.h"
-
-#include "installpage/btinstallpage.h"
-#include "removepage/btremovepage.h"
-#include "indexpage/btindexpage.h"
+#include "frontend/bookshelfmanager/btmodulemanagerdialog.h"
+#include <QDialogButtonBox>
+#include "backend/config/cbtconfig.h"
+#include "backend/managers/cswordbackend.h"
+#include "frontend/bookshelfmanager/indexpage/btindexpage.h"
+#include "frontend/bookshelfmanager/installpage/btinstallpage.h"
+#include "frontend/bookshelfmanager/removepage/btremovepage.h"
#include "util/cpointers.h"
#include "util/dialogutil.h"
-#include "backend/managers/cswordbackend.h"
-#include "backend/config/cbtconfig.h"
-
-#include <QDialogButtonBox>
-static BtModuleManagerDialog* m_staticModuleManagerDialog = 0;
+static BtModuleManagerDialog *m_staticModuleManagerDialog = 0;
BtModuleManagerDialog* BtModuleManagerDialog::getInstance(QWidget* parent) {
if (!m_staticModuleManagerDialog) {
@@ -67,7 +65,7 @@ BtModuleManagerDialog::~BtModuleManagerDialog() {
// The QWidget close() sends close event, so does closing by the window X button.
void BtModuleManagerDialog::closeEvent(QCloseEvent*) {
- qDebug("BtModuleManagerDialog::closeEvent");
+ qDebug() << "BtModuleManagerDialog::closeEvent";
}
void BtModuleManagerDialog::loadDialogSettings() {
diff --git a/src/frontend/bookshelfmanager/btmodulemanagerdialog.h b/src/frontend/bookshelfmanager/btmodulemanagerdialog.h
index ff8c35f..c51efd2 100644
--- a/src/frontend/bookshelfmanager/btmodulemanagerdialog.h
+++ b/src/frontend/bookshelfmanager/btmodulemanagerdialog.h
@@ -7,11 +7,11 @@
*
**********/
-
#ifndef BTMODULEMANAGERDIALOG_H
#define BTMODULEMANAGERDIALOG_H
-#include "btconfigdialog.h"
+#include "frontend/bookshelfmanager/btconfigdialog.h"
+
class QWidget;
diff --git a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp b/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp
index eca4498..47e274c 100644
--- a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp
+++ b/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp
@@ -7,35 +7,33 @@
*
**********/
-//BT includes
-#include "cswordsetupinstallsourcesdialog.h"
-
-#include "frontend/bookshelfmanager/instbackend.h"
+#include "frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h"
#include <boost/scoped_ptr.hpp>
-
-//Qt includes
-#include <QLayout>
-#include <QLabel>
#include <QComboBox>
-#include <QLineEdit>
-#include <QPushButton>
-#include <QMessageBox>
+#include <QDir>
#include <QFileInfo>
+#include <QFileDialog>
#include <QGridLayout>
#include <QHBoxLayout>
+#include <QLabel>
+#include <QLayout>
+#include <QLineEdit>
+#include <QPushButton>
#include <QVBoxLayout>
-#include <QFileDialog>
-#include <QDir>
-
-
+#include <QDialogButtonBox>
+#include <QProgressDialog>
+#include <QApplication>
+#include <QDebug>
+#include "frontend/bookshelfmanager/instbackend.h"
+#include "util/dialogutil.h"
const QString PROTO_FILE( QObject::tr("Local") ); //Local path
const QString PROTO_FTP( QObject::tr("Remote") ); //Remote path
-
CSwordSetupInstallSourcesDialog::CSwordSetupInstallSourcesDialog(/*QWidget *parent*/)
- : QDialog() {
+ : QDialog(),
+ m_remoteListAdded(false) {
setWindowTitle(tr("New Installation Source"));
QVBoxLayout* mainLayout = new QVBoxLayout( this );
@@ -48,7 +46,7 @@ CSwordSetupInstallSourcesDialog::CSwordSetupInstallSourcesDialog(/*QWidget *pare
captionLayout->addWidget( label );
m_captionEdit = new QLineEdit( this );
- m_captionEdit->setText("Crosswire Bible Society");
+ m_captionEdit->setText("CrossWire Bible Society");
captionLayout->addWidget( m_captionEdit );
mainLayout->addSpacing( 10 );
@@ -83,24 +81,22 @@ CSwordSetupInstallSourcesDialog::CSwordSetupInstallSourcesDialog(/*QWidget *pare
mainLayout->addSpacing( 10 );
- QHBoxLayout* buttonLayout = new QHBoxLayout( this );
- mainLayout->addLayout(buttonLayout);
- buttonLayout->addStretch();
- QPushButton* okButton = new QPushButton( tr("Ok"), this);
- QPushButton* discardButton = new QPushButton( tr("Discard"), this);
- buttonLayout->addWidget( discardButton);
- buttonLayout->addWidget( okButton);
- buttonLayout->addStretch();
-
- connect( okButton, SIGNAL( clicked() ), this, SLOT( slotOk() ) );
- connect( discardButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
+ QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Save, Qt::Horizontal, this);
+ util::prepareDialogBox(buttonBox);
+ QPushButton* getListButton = new QPushButton(tr("Get list..."), this);
+ getListButton->setToolTip(tr("Download a list of sources from CrossWire server and add sources"));
+ buttonBox->addButton(getListButton, QDialogButtonBox::ActionRole);
+ connect(getListButton, SIGNAL(clicked()), SLOT(slotGetListClicked()));
+ mainLayout->addWidget(buttonBox);
+ connect(buttonBox, SIGNAL(accepted()), SLOT(slotOk()));
+ connect(buttonBox, SIGNAL(rejected()), SLOT(reject()));
connect( m_protocolCombo, SIGNAL( activated(int) ), this, SLOT( slotProtocolChanged() ) );
-
}
+
void CSwordSetupInstallSourcesDialog::slotOk() {
//run a few tests to validate the input first
if ( m_captionEdit->text().trimmed().isEmpty() ) { //no caption
- QMessageBox::information( this, tr( "Error" ), tr("Please provide a caption."), QMessageBox::Retry);
+ util::showInformation( this, tr( "Error" ), tr("Please provide a caption."));
return;
}
@@ -108,25 +104,25 @@ void CSwordSetupInstallSourcesDialog::slotOk() {
//sword::InstallSource is = BTInstallMgr::Tool::RemoteConfig::source( &iMgr, m_captionEdit->text() );
sword::InstallSource is = instbackend::source(m_captionEdit->text());
if ( (QString)is.caption.c_str() == m_captionEdit->text() ) { //source already exists
- QMessageBox::information( this, tr( "Error" ),
- tr("A source with this caption already exists.<br>Please provide a different caption."), QMessageBox::Retry);
+ util::showInformation( this, tr( "Error" ),
+ tr("A source with this caption already exists.<br/>Please provide a different caption."));
return;
}
if ( m_protocolCombo->currentText() == PROTO_FTP &&
m_serverEdit->text().trimmed().isEmpty() ) { //no server name
- QMessageBox::information( this, tr( "Error" ), tr("Please provide a server name."), QMessageBox::Retry);
+ util::showInformation( this, tr( "Error" ), tr("Please provide a server name."));
return;
}
if ( m_protocolCombo->currentText() == PROTO_FILE) {
const QFileInfo fi( m_pathEdit->text() );
if (!fi.exists() || !fi.isReadable()) { //no valid and readable path
- QMessageBox::information( this, tr( "Error" ), tr("Please provide a valid, readable path."), QMessageBox::Retry);
+ util::showInformation( this, tr( "Error" ), tr("Please provide a valid, readable path."));
return;
}
else if ( m_pathEdit->text().isEmpty() ) {
- QMessageBox::information( this, tr( "Error" ), tr("Please provide a path."), QMessageBox::Retry);
+ util::showInformation( this, tr( "Error" ), tr("Please provide a path."));
}
}
@@ -155,28 +151,83 @@ void CSwordSetupInstallSourcesDialog::slotProtocolChanged() {
}
-sword::InstallSource CSwordSetupInstallSourcesDialog::getSource() {
+void CSwordSetupInstallSourcesDialog::slotGetListClicked() {
+ QString message(tr("List of sources will be downloaded from a remote server. Sources will be added to the current list. New source will replace an old one if it has the same label. You can later remove the sources you don't want to keep.\n\nDo you want to continue?"));
+ QMessageBox::StandardButton answer = util::showQuestion(this, tr("Get source list from remote server?"), message, QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
+ if (answer == QMessageBox::No) {
+ return;
+ }
+ qDebug() << "Ok, create installmgr";
+ BtInstallMgr iMgr;
+
+ m_progressDialog = new QProgressDialog("", tr("Cancel"), 0 , 100, this);
+ m_progressDialog->setWindowTitle(tr("Downloading List"));
+ m_progressDialog->setMinimumDuration(0);
+ connect(m_progressDialog, SIGNAL(canceled()), SLOT(slotRefreshCanceled()));
+ m_currentInstallMgr = &iMgr; //for the progress dialog
+ // connect this directly to the dialog setValue(int) if possible
+ connect(&iMgr, SIGNAL(percentCompleted(const int, const int)), SLOT(slotRefreshProgress(const int, const int)));
+
+ m_progressDialog->show();
+ qApp->processEvents();
+ this->slotRefreshProgress(0, 0);
+ m_progressDialog->setLabelText(tr("Connecting..."));
+ m_progressDialog->setValue(0);
+ qApp->processEvents();
+ qWarning() << "Start downloading the list of sources";
+ int ret = iMgr.refreshRemoteSourceConfiguration();
+ bool success = false;
+ if ( !ret ) { //make sure the sources were updated sucessfully
+ qDebug() << "download succeeded";
+ success = true;
+ m_progressDialog->setValue(100); //make sure the dialog closes
+ m_remoteListAdded = true;
+ accept();
+ }
+ else {
+ qWarning("InstallMgr: getting remote list returned an error.");
+ success = false;
+ }
+ delete m_progressDialog;
+ m_progressDialog = 0;
+}
- boost::scoped_ptr<CSwordSetupInstallSourcesDialog> dlg( new CSwordSetupInstallSourcesDialog() );
- sword::InstallSource newSource(""); //empty, invalid Source
+void CSwordSetupInstallSourcesDialog::slotRefreshProgress(const int, const int current) {
+ if (m_progressDialog) {
+ if (m_progressDialog->labelText() != tr("Refreshing...")) {
+ m_progressDialog->setLabelText(tr("Refreshing..."));
+ }
+ m_progressDialog->setValue(current);
+ }
+ qApp->processEvents();
+}
- if (dlg->exec() == QDialog::Accepted) {
- if (dlg->m_protocolCombo->currentText() == PROTO_FTP) {
- newSource.type = "FTP";
- newSource.source = dlg->m_serverEdit->text().toUtf8();
+void CSwordSetupInstallSourcesDialog::slotRefreshCanceled() {
+ Q_ASSERT(m_currentInstallMgr);
+ if (m_currentInstallMgr) {
+ m_currentInstallMgr->terminate();
+ }
+ qApp->processEvents();
+}
- //a message to the user would be nice, but we're in message freeze right now (1.5.1)
- if (dlg->m_serverEdit->text().right(1) == "/") { //remove a trailing slash
- newSource.source = dlg->m_serverEdit->text().mid(0, dlg->m_serverEdit->text().length() - 1).toUtf8();
- }
- }
- else {
- newSource.type = "DIR";
- newSource.source = "local";
+sword::InstallSource CSwordSetupInstallSourcesDialog::getSource() {
+ sword::InstallSource newSource(""); //empty, invalid Source
+ if (m_protocolCombo->currentText() == PROTO_FTP) {
+ newSource.type = "FTP";
+ newSource.source = m_serverEdit->text().toUtf8();
+ //a message to the user would be nice, but we're in message freeze right now (1.5.1)
+ if (m_serverEdit->text().right(1) == "/") { //remove a trailing slash
+ newSource.source = m_serverEdit->text().mid(0, m_serverEdit->text().length() - 1).toUtf8();
}
- newSource.caption = dlg->m_captionEdit->text().toUtf8();
- newSource.directory = dlg->m_pathEdit->text().toUtf8();
}
+ else {
+ newSource.type = "DIR";
+ newSource.source = "local";
+ }
+ newSource.caption = m_captionEdit->text().toUtf8();
+ newSource.directory = m_pathEdit->text().toUtf8();
+ newSource.uid = newSource.source;
+
return newSource;
}
diff --git a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h b/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h
index d875cda..64c7f21 100644
--- a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h
+++ b/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h
@@ -7,39 +7,44 @@
*
**********/
-
#ifndef CSWORDSETUPINSTALLSOURCESDIALOG_H
#define CSWORDSETUPINSTALLSOURCESDIALOG_H
-#include "frontend/bookshelfmanager/btinstallmgr.h"
-
#include <QDialog>
+#include "frontend/bookshelfmanager/btinstallmgr.h"
+
+// Sword includes:
#include <installmgr.h>
-class QLabel;
+
class QComboBox;
+class QLabel;
class QLineEdit;
-
-
+class QProgressDialog;
class CSwordSetupInstallSourcesDialog : public QDialog {
Q_OBJECT
public:
- static sword::InstallSource getSource();
-
- protected:
+ sword::InstallSource getSource();
+ bool wasRemoteListAdded() {return m_remoteListAdded;}
CSwordSetupInstallSourcesDialog();
protected slots:
void slotOk();
void slotProtocolChanged();
+ void slotGetListClicked();
+ void slotRefreshCanceled();
+ void slotRefreshProgress(const int, const int current);
private:
QLabel *m_serverLabel;
QLineEdit *m_captionEdit, *m_serverEdit, *m_pathEdit;
QComboBox *m_protocolCombo;
+ QProgressDialog* m_progressDialog;
+ BtInstallMgr* m_currentInstallMgr;
+ bool m_remoteListAdded;
};
diff --git a/src/frontend/bookshelfmanager/indexpage/btindexpage.cpp b/src/frontend/bookshelfmanager/indexpage/btindexpage.cpp
index 2a628c9..df388dd 100644
--- a/src/frontend/bookshelfmanager/indexpage/btindexpage.cpp
+++ b/src/frontend/bookshelfmanager/indexpage/btindexpage.cpp
@@ -7,31 +7,28 @@
*
**********/
-#include "btindexpage.h"
+#include "frontend/bookshelfmanager/indexpage/btindexpage.h"
-#include "frontend/cmoduleindexdialog.h"
-#include "backend/config/cbtconfig.h"
-
-#include "util/ctoolclass.h"
-#include "util/cresmgr.h"
-#include "util/cpointers.h"
-#include "util/directoryutil.h"
-
-#include "backend/drivers/cswordmoduleinfo.h"
-#include "backend/managers/cswordbackend.h"
-
-//Qt includes
-#include <QVBoxLayout>
-#include <QHBoxLayout>
-#include <QTreeWidget>
-#include <QTreeWidgetItem>
#include <QCheckBox>
#include <QDir>
+#include <QHBoxLayout>
#include <QPushButton>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
+#include <QVBoxLayout>
+#include "backend/config/cbtconfig.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/cswordbackend.h"
+#include "frontend/cmoduleindexdialog.h"
+#include "util/directory.h"
+#include "util/cpointers.h"
+#include "util/cresmgr.h"
+#include "util/tool.h"
BtIndexPage::BtIndexPage()
: BtConfigPage() {
+ namespace DU = util::directory;
QVBoxLayout *vboxLayout;
QHBoxLayout *hboxLayout;
@@ -65,15 +62,15 @@ BtIndexPage::BtIndexPage()
// configure the list view
m_moduleList->setHeaderLabels( (QStringList(tr("Work")) << tr("Index size")) );
m_moduleList->setRootIsDecorated(true);
- m_moduleList->setColumnWidth(0, CToolClass::mWidth(m_moduleList, 20) );
+ m_moduleList->setColumnWidth(0, util::tool::mWidth(m_moduleList, 20) );
//m_moduleList->setTextAlignment(1, Qt::AlignRight); see doc...
m_moduleList->setSortingEnabled(false);
m_autoDeleteOrphanedIndicesBox->setChecked( CBTConfig::get( CBTConfig::autoDeleteOrphanedIndices ) );
// icons for our buttons
- m_createButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::indexpage::create_icon));
- m_deleteButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::indexpage::delete_icon));
+ m_createButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::indexpage::create_icon));
+ m_deleteButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::indexpage::delete_icon));
// connect our signals/slots
connect(m_createButton, SIGNAL(clicked()), this, SLOT(createIndices()));
diff --git a/src/frontend/bookshelfmanager/indexpage/btindexpage.h b/src/frontend/bookshelfmanager/indexpage/btindexpage.h
index 139c4a7..aa13eb0 100644
--- a/src/frontend/bookshelfmanager/indexpage/btindexpage.h
+++ b/src/frontend/bookshelfmanager/indexpage/btindexpage.h
@@ -7,13 +7,13 @@
*
**********/
-
#ifndef BTINDEXPAGE_H
#define BTINDEXPAGE_H
#include "frontend/bookshelfmanager/btconfigdialog.h"
#include "backend/btmoduletreeitem.h"
+
class QCheckBox;
class QTreeWidget;
class QTreeWidgetItem;
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp
index 1668a87..8fd87ec 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp
+++ b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp
@@ -1,132 +1,29 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
-* Copyright 1999-2008 by the BibleTime developers.
+* Copyright 1999-2009 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/
-#include "btinstallmodulechooserdialog.h"
+#include "frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h"
-#include "frontend/cmodulechooserdialog.h"
-#include "backend/drivers/cswordmoduleinfo.h"
-#include "backend/btmoduletreeitem.h"
-
-#include <QString>
+#include <QBrush>
+#include <QDebug>
#include <QList>
-#include <QWidget>
+#include <QPushButton>
#include <QString>
#include <QTreeWidgetItem>
-#include <QBrush>
-#include <QPushButton>
-
-#include <QDebug>
+#include <QWidget>
+#include "backend/btmoduletreeitem.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "frontend/cmodulechooserdialog.h"
BtInstallModuleChooserDialog::BtInstallModuleChooserDialog(QWidget* parent, QString title, QString label, QList<CSwordModuleInfo*>* empty)
: CModuleChooserDialog(parent, title, label, empty) {
- qDebug("BtInstallModuleChooserDialog::BtInstallModuleChooserDialog start");
+ qDebug() << "BtInstallModuleChooserDialog::BtInstallModuleChooserDialog start";
init();
okButton()->setText(tr("Install"));
m_nameList = QStringList();
@@ -163,16 +60,16 @@ void BtInstallModuleChooserDialog::initModuleItem(QString name, QTreeWidgetItem*
void BtInstallModuleChooserDialog::slotItemChecked(QTreeWidgetItem* item, int column) {
QString moduleName = item->text(0);
- qDebug("BtInstallModuleChooserDialog::slotItemChecked start");
+ qDebug() << "BtInstallModuleChooserDialog::slotItemChecked start";
// handle only non-toplevel items which has duplicates and where the first column was changed
if (item->parent() && column == 0 && (findModuleItemsByName(moduleName).count() > 1)) {
//prevent handling when the color is changed
if (item->data(1, Qt::UserRole).toBool() == false) {
- qDebug("was not updating");
+ qDebug() << "was not updating";
item->setData(1, Qt::UserRole, true);
}
else {
- qDebug("was updating");
+ qDebug() << "was updating";
item->setData(1, Qt::UserRole, false);
return;
}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h
index 788dbf5..06144ff 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h
+++ b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h
@@ -12,17 +12,16 @@
#include "frontend/cmodulechooserdialog.h"
+#include <QList>
+#include <QMap>
#include <QObject>
#include <QString>
-#include <QMap>
-#include <QList>
-class BTModuleTreeItem;
+class BTModuleTreeItem;
class QWidget;
class QTreeWidgetItem;
-
/**
* Confirmation dialog for installation. Lets the user
* uncheck modules from the list.
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp b/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp
index 4fe9c41..ecdf7e3 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp
+++ b/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp
@@ -7,58 +7,48 @@
*
**********/
-
-#include "btinstallpage.h"
-
-#include "btinstallpathdialog.h"
-#include "btinstallprogressdialog.h"
-#include "btsourcewidget.h"
-#include "btsourcearea.h"
-
-#include "frontend/bookshelfmanager/btinstallmgr.h"
-#include "frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h"
-#include "frontend/bookshelfmanager/btconfigdialog.h"
-#include "frontend/bookshelfmanager/instbackend.h"
-#include "frontend/bookshelfmanager/btmodulemanagerdialog.h"
-
-#include "frontend/cmodulechooserdialog.h"
-
-#include "backend/drivers/cswordmoduleinfo.h"
-#include "backend/managers/cswordbackend.h"
-#include "backend/config/cbtconfig.h"
-
-#include "util/cpointers.h"
-#include "util/ctoolclass.h"
-#include "util/cresmgr.h"
-#include "util/directoryutil.h"
-
-#include <boost/scoped_ptr.hpp>
-
+#include "frontend/bookshelfmanager/installpage/btinstallpage.h"
#include <QAction>
#include <QApplication>
-#include <QWidget>
#include <QButtonGroup>
#include <QComboBox>
#include <QDialog>
+#include <QFileInfo>
#include <QHBoxLayout>
+#include <QHeaderView>
#include <QLabel>
+#include <QMessageBox>
+#include <QProgressBar>
+#include <QProgressDialog>
#include <QPushButton>
-#include <QToolButton>
#include <QSpacerItem>
-#include <QTabBar>
#include <QStackedWidget>
+#include <QTabBar>
+#include <QTimer>
#include <QTreeWidget>
#include <QTreeWidgetItem>
+#include <QToolButton>
#include <QVBoxLayout>
-#include <QFileInfo>
-#include <QMessageBox>
-#include <QProgressDialog>
-#include <QTimer>
-#include <QProgressBar>
-
-#include <QHeaderView>
+#include <QWidget>
+#include "backend/config/cbtconfig.h"
+#include "backend/drivers/cswordmoduleinfo.h"
+#include "backend/managers/cswordbackend.h"
+#include "frontend/bookshelfmanager/btconfigdialog.h"
+#include "frontend/bookshelfmanager/btinstallmgr.h"
+#include "frontend/bookshelfmanager/btmodulemanagerdialog.h"
+#include "frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h"
+#include "frontend/bookshelfmanager/installpage/btinstallpathdialog.h"
+#include "frontend/bookshelfmanager/installpage/btinstallprogressdialog.h"
+#include "frontend/bookshelfmanager/installpage/btsourcewidget.h"
+#include "frontend/bookshelfmanager/installpage/btsourcearea.h"
+#include "frontend/bookshelfmanager/instbackend.h"
+#include "frontend/cmodulechooserdialog.h"
+#include "util/directory.h"
+#include "util/cpointers.h"
+#include "util/cresmgr.h"
+// Sword includes:
#include <swversion.h>
@@ -68,13 +58,13 @@
BtInstallPage::BtInstallPage()
: BtConfigPage() {
- qDebug("BtInstallPage::BtInstallPage() start");
+ qDebug() << "BtInstallPage::BtInstallPage() start";
initView();
initConnections();
}
void BtInstallPage::setInstallEnabled(bool b) {
- qDebug("void BtInstallPage::setInstallEnabled(bool b) start");
+ qDebug() << "void BtInstallPage::setInstallEnabled(bool b) start";
m_installButton->setEnabled(b);
}
@@ -83,7 +73,9 @@ QString BtInstallPage::selectedInstallPath() {
}
void BtInstallPage::initView() {
- qDebug("void BtInstallPage::initView() start");
+ namespace DU = util::directory;
+
+ qDebug() << "void BtInstallPage::initView() start";
QVBoxLayout *mainLayout = new QVBoxLayout(this);
// installation path chooser
@@ -95,24 +87,24 @@ void BtInstallPage::initView() {
int right;
pathLayout->getContentsMargins(&left, &top, &right, &bottom);
pathLayout->setContentsMargins(left, top + 7, right, bottom + 7 );
- QSpacerItem *pathSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
- QLabel* pathLabel = new QLabel(tr("Install path:"));
+ QLabel* pathLabel = new QLabel(tr("Install folder:"));
m_pathCombo = new QComboBox();
- m_pathCombo->setToolTip(tr("The path where the new works will be installed"));
+ m_pathCombo->setMinimumContentsLength(20);
+ m_pathCombo->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLengthWithIcon);
+ m_pathCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
+ m_pathCombo->setToolTip(tr("The folder where the new works will be installed"));
+ m_pathCombo->view()->setTextElideMode(Qt::ElideMiddle);
initPathCombo(); // set the paths and the current path
- //m_configurePathButton = new QPushButton(tr("Configure...")); //TODO: icon only?
m_configurePathButton = new QToolButton(this);
- m_configurePathButton->setToolTip(tr("Configure paths where works are installed"));
- m_configurePathButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::installpage::path_icon));
+ m_configurePathButton->setToolTip(tr("Configure folders where works are installed and found"));
+ m_configurePathButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::installpage::path_icon));
- pathLayout->addItem(pathSpacer);
pathLayout->addWidget(pathLabel);
pathLayout->addWidget(m_pathCombo);
pathLayout->addWidget(m_configurePathButton);
mainLayout->addLayout(pathLayout);
// Source widget
- //QTabWidget* m_sourcesTabWidget;
m_sourceWidget = new BtSourceWidget(this);
mainLayout->addWidget(m_sourceWidget);
// Install button
@@ -122,7 +114,7 @@ void BtInstallPage::initView() {
installButtonLayout->addItem(installButtonSpacer);
m_installButton = new QPushButton(tr("Install..."), this);
m_installButton->setToolTip(tr("Install or update selected works"));
- m_installButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::installpage::install_icon));
+ m_installButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::installpage::install_icon));
m_installButton->setEnabled(false);
installButtonLayout->addWidget(m_installButton);
@@ -130,7 +122,7 @@ void BtInstallPage::initView() {
}
void BtInstallPage::initConnections() {
- qDebug("void BtInstallPage::initConnections() start");
+ qDebug() << "void BtInstallPage::initConnections() start";
QObject::connect(m_pathCombo, SIGNAL(activated(const QString&)), this , SLOT(slotPathChanged(const QString&)));
QObject::connect(m_configurePathButton, SIGNAL(clicked()), this, SLOT(slotEditPaths()));
QObject::connect(m_installButton, SIGNAL(clicked()), m_sourceWidget, SLOT(slotInstall()) );
@@ -140,14 +132,20 @@ void BtInstallPage::initConnections() {
}
void BtInstallPage::initPathCombo() {
- qDebug("void BtInstallPage::initPathCombo() start");
+ qDebug() << "void BtInstallPage::initPathCombo() start";
//populate the combo list
m_pathCombo->clear();
QStringList targets = instbackend::targetList();
for (QStringList::iterator it = targets.begin(); it != targets.end(); ++it) {
+ // Add the path only if it's writable
if ((*it).isEmpty()) continue;
- m_pathCombo->addItem(*it);
+ QDir dir(*it);
+ if (!dir.exists()) continue;
+ if (!dir.isReadable()) continue;
+ QFileInfo fi( dir.canonicalPath());
+ if (!fi.isWritable()) continue;
+ m_pathCombo->addItem(util::directory::convertDirSeparators(*it));
}
// choose the current value from config but check whether we have so many items
@@ -161,7 +159,7 @@ void BtInstallPage::slotPathChanged(const QString& /*pathText*/) {
}
void BtInstallPage::slotEditPaths() {
- qDebug("void BtInstallPage::slotEditPaths() start");
+ qDebug() << "void BtInstallPage::slotEditPaths() start";
BtInstallPathDialog* dlg = new BtInstallPathDialog();
int result = dlg->exec();
@@ -177,7 +175,7 @@ QString BtInstallPage::iconName() {
return CResMgr::bookshelfmgr::installpage::icon;
}
QString BtInstallPage::label() {
- // TODO: move the warning to a dialog which is shown when adding a source.
+ // \todo move the warning to a dialog which is shown when adding a source.
return tr("Install and update works. Add remote or local sources, refresh them, select the works to be installed/updated and click Install.<br/><b>WARNING:</b> If you live in a persecuted country and don't want to risk detection don't use remote sources.");
}
QString BtInstallPage::header() {
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpage.h b/src/frontend/bookshelfmanager/installpage/btinstallpage.h
index 41493f8..fde9919 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallpage.h
+++ b/src/frontend/bookshelfmanager/installpage/btinstallpage.h
@@ -10,16 +10,15 @@
#ifndef BTINSTALLPAGE_H
#define BTINSTALLPAGE_H
-
#include "frontend/bookshelfmanager/btconfigdialog.h"
#include <QString>
+// Sword includes:
#include <installmgr.h>
class BtSourceWidget;
-
class QComboBox;
class QPushButton;
class QToolButton;
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp
index 27b3d3a..c6175d5 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp
+++ b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp
@@ -7,32 +7,31 @@
*
**********/
-#include "btinstallpathdialog.h"
+#include "frontend/bookshelfmanager/installpage/btinstallpathdialog.h"
-#include "frontend/bookshelfmanager/instbackend.h"
-
-#include "util/ctoolclass.h"
-#include "util/dialogutil.h"
-#include "util/directoryutil.h"
-#include "util/cresmgr.h"
-
-#include <QString>
+#include <QDebug>
#include <QDialog>
+#include <QDialogButtonBox>
#include <QDir>
+#include <QFileDialog>
#include <QGridLayout>
+#include <QHeaderView>
#include <QLabel>
+#include <QPushButton>
+#include <QString>
#include <QTreeWidget>
#include <QTreeWidgetItem>
-#include <QPushButton>
-#include <QFileDialog>
-#include <QMessageBox>
-#include <QHeaderView>
-#include <QDialogButtonBox>
+#include "frontend/bookshelfmanager/instbackend.h"
+#include "util/dialogutil.h"
+#include "util/directory.h"
+#include "util/cresmgr.h"
+#include "util/tool.h"
-#include <QDebug>
BtInstallPathDialog::BtInstallPathDialog() {
- setWindowTitle(tr("Bookshelf Paths"));
+ namespace DU = util::directory;
+
+ setWindowTitle(tr("Bookshelf Folders"));
QVBoxLayout *mainLayout;
QHBoxLayout *viewLayout;
@@ -40,15 +39,17 @@ BtInstallPathDialog::BtInstallPathDialog() {
mainLayout = new QVBoxLayout(this);
viewLayout = new QHBoxLayout();
- QString l1 = tr("Works can be installed in one or more directories. After setting up directories here you can choose one of them in Install page.");
- QString l2 = tr("BibleTime and the Sword library find the modules from all of these directories. If the directory is removed here it still exists in the system with all the works in it. \".sword\" directory in your home directory is always used automatically and can't be removed or added.");
+ QString l1 = tr("Works can be installed in one or more folders. After setting up folders here you can choose one of them in Install page.");
+ /// \bug The following string has an extra space character:
+ QString l2 = tr("BibleTime and the SWORD library find the works from all of these folders. If a folder is removed here it still exists in the system with all the works in it.");
- QLabel* mainLabel = CToolClass::explanationLabel(this,
- tr("Configure bookshelf paths"), l1 + QString("<small><br><br>") + l2 + QString("</small>"));
+ QLabel* mainLabel = util::tool::explanationLabel(this,
+ tr("Configure bookshelf folders"), l1 + QString("<small><br/><br/>") + l2 + QString("</small>"));
mainLayout->addWidget(mainLabel);
QString swordConfPath = instbackend::swordConfigFilename();
- QLabel* confPathLabel = new QLabel(tr("Configuration file for the paths is: ").append("<b>%1</b>").arg(swordConfPath), this);
+ /// \todo After releasing 2.4, change the following line to: QLabel *confPathLabel = new QLabel(tr("Configuration file for the folders is: <b>%1</b>").arg(swordConfPath), this);
+ QLabel* confPathLabel = new QLabel(tr("Configuration file for the folders is: ").append("<b>%1</b>").arg(swordConfPath), this);
confPathLabel->setWordWrap(true);
mainLayout->addWidget(confPathLabel);
@@ -56,32 +57,40 @@ BtInstallPathDialog::BtInstallPathDialog() {
m_swordPathListBox = new QTreeWidget(this);
m_swordPathListBox->header()->hide();
- QDir swordDir = instbackend::swordDir();
+ QString rwfolderitem(tr("Folders where new works can be installed"));
+ m_writableItem = new QTreeWidgetItem(m_swordPathListBox, QStringList(rwfolderitem));;
+ m_writableItem->setFlags(Qt::ItemIsEnabled);
+ m_readableItem = new QTreeWidgetItem(m_swordPathListBox, QStringList(tr("Read-only folders")));;
+ m_readableItem->setFlags(Qt::ItemIsEnabled);
+ m_nonexistingItem = new QTreeWidgetItem(m_swordPathListBox, QStringList(tr("Nonexistent folders")));;
+ m_nonexistingItem->setFlags(Qt::ItemIsEnabled);
+
QStringList targets = instbackend::targetList();
+
foreach (QString pathname, targets) {
- if (pathname.isEmpty() || QDir(pathname) == swordDir) continue;
- new QTreeWidgetItem(m_swordPathListBox, QStringList(pathname) );
+ addPathToList(pathname);
}
+ updateTopLevelItems();
viewLayout->addWidget(m_swordPathListBox);
QVBoxLayout* buttonLayout = new QVBoxLayout();
m_addButton = new QPushButton(tr("Add..."), this);
- m_addButton->setToolTip(tr("Add new path"));
- m_addButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::paths::add_icon));
+ m_addButton->setToolTip(tr("Add new folder"));
+ m_addButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::paths::add_icon));
connect(m_addButton, SIGNAL(clicked()), this, SLOT(slotAddClicked()));
buttonLayout->addWidget(m_addButton);
m_editButton = new QPushButton(tr("Edit..."), this);
- m_editButton->setToolTip(tr("Edit the selected path"));
- m_editButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::paths::edit_icon));
+ m_editButton->setToolTip(tr("Edit the selected folder"));
+ m_editButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::paths::edit_icon));
connect(m_editButton, SIGNAL(clicked()), this, SLOT(slotEditClicked()));
buttonLayout->addWidget(m_editButton);
m_removeButton = new QPushButton(tr("Remove"), this);
- m_removeButton->setToolTip(tr("Remove the selected path"));
- m_removeButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::paths::remove_icon));
+ m_removeButton->setToolTip(tr("Remove the selected folder"));
+ m_removeButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::paths::remove_icon));
connect(m_removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveClicked()));
buttonLayout->addWidget(m_removeButton);
@@ -98,12 +107,65 @@ BtInstallPathDialog::BtInstallPathDialog() {
mainLayout->addWidget(buttonBox);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+ //clumsy way to set width. Could someone please fix Qt to have an easy way to set widget sizes?
+ int textWidth = fontMetrics().width(rwfolderitem.append("MMMMMMMMMM"));
+ int buttonWidth = m_addButton->width();
+ resize(textWidth + buttonWidth, size().height());
+}
+
+BtInstallPathDialog::~BtInstallPathDialog() {
+ m_swordPathListBox->invisibleRootItem()->takeChildren();
+ delete m_readableItem;
+ delete m_writableItem;
+ delete m_nonexistingItem;
+}
+
+void BtInstallPathDialog::updateTopLevelItems() {
+ qDebug() << "BtInstallPathDialog::updateTopLevelItems";
+ if (m_writableItem->childCount()) {
+ m_writableItem->setHidden(false);
+ m_swordPathListBox->expandItem(m_writableItem);
+ } else {
+ m_writableItem->setHidden(true);
+ }
+ if (m_readableItem->childCount()) {
+ m_readableItem->setHidden(false);
+ m_swordPathListBox->expandItem(m_readableItem);
+ } else {
+ m_readableItem->setHidden(true);
+ }
+ if (m_nonexistingItem->childCount()) {
+ m_nonexistingItem->setHidden(false);
+ m_swordPathListBox->expandItem(m_nonexistingItem);
+ } else {
+ m_nonexistingItem->setHidden(true);
+ }
+}
+
+void BtInstallPathDialog::addPathToList(QString pathname) {
+ if (pathname.isEmpty()) return;
+ QTreeWidgetItem* i = 0;
+ QDir dir(pathname);
+ if (!dir.exists()) {
+ i = new QTreeWidgetItem(m_nonexistingItem, QStringList(pathname) );
+ } else if (dir.isReadable()) {
+ const QFileInfo fi( dir.canonicalPath() );
+ if (fi.isWritable()) {
+ i = new QTreeWidgetItem(m_writableItem, QStringList(pathname) );
+ } else {
+ i = new QTreeWidgetItem(m_readableItem, QStringList(pathname) );
+ }
+ }
+ if (i && QDir(pathname) == instbackend::swordDir()) {
+ i->setFlags(Qt::NoItemFlags);
+ i->setToolTip(0, tr("This default folder in your home directory can't be removed"));
+ }
}
void BtInstallPathDialog::slotEditClicked() {
if (QTreeWidgetItem* i = m_swordPathListBox->currentItem()) {
- QString dirname = QFileDialog::getExistingDirectory(this, tr("Choose directory"), i->text(0), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
+ QString dirname = QFileDialog::getExistingDirectory(this, tr("Choose Folder"), i->text(0), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (dirname.isEmpty()) { // if user cancelled the dialog
return;
@@ -112,16 +174,19 @@ void BtInstallPathDialog::slotEditClicked() {
if (dir.isReadable()) {
const QFileInfo fi( dir.canonicalPath() );
if (!fi.exists() || !fi.isWritable()) {
- const int result = QMessageBox::warning(this, tr("Use Directory?"), tr("This directory is not writable, so works can not be installed here using BibleTime. Do you want to use this directory instead of the previous value?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
+ const int result = util::showWarning(this, tr("Use Folder?"), tr("This folder is not writable, so works can not be installed here using BibleTime. Do you want to use this folder instead of the previous value?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (result != QMessageBox::Yes) return;
}
- i->setText(0, dir.absolutePath()); // absolute, not canonical
+ //i->setText(0, dir.absolutePath()); // absolute, not canonical
+ addPathToList(dir.absolutePath());
+ delete i;
+ updateTopLevelItems();
}
}
}
void BtInstallPathDialog::slotAddClicked() {
- QString dirname = QFileDialog::getExistingDirectory(this, tr("Choose directory"), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
+ QString dirname = QFileDialog::getExistingDirectory(this, tr("Choose Folder"), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (dirname.isEmpty()) { // if user cancelled the dialog
return;
}
@@ -129,36 +194,39 @@ void BtInstallPathDialog::slotAddClicked() {
if (dir.isReadable()) {
const QFileInfo fi( dir.canonicalPath() );
if (!fi.exists() || !fi.isWritable()) {
- const int result = QMessageBox::warning(this, tr("Warning"), tr("This directory is not writable, so works can not be installed here using BibleTime. Do you still want to add it to the list of bookshelf directories?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
+ const int result = util::showWarning(this, tr("Use Folder?"), tr("This folder is not writable, so works can not be installed here using BibleTime. Do you still want to add it to the list of bookshelf folders?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (result != QMessageBox::Yes) {
return;
}
}
- new QTreeWidgetItem(m_swordPathListBox, QStringList(dir.canonicalPath()) );
+ addPathToList(util::directory::convertDirSeparators(dir.canonicalPath()));
+ updateTopLevelItems();
}
}
void BtInstallPathDialog::slotRemoveClicked() {
- QTreeWidgetItem* i = m_swordPathListBox->currentItem();
- if (i) {
+ qDebug() << "BtInstallPathDialog::slotRemoveClicked";
+ QTreeWidgetItem* i = m_swordPathListBox->selectedItems().value(0);
+ qDebug() << i;
+ if (i && i->parent() != m_swordPathListBox->invisibleRootItem()) {
+ qDebug() << "delete" << i;
delete i;
}
+ updateTopLevelItems();
}
void BtInstallPathDialog::writeSwordConfig() {
- qDebug("BtInstallPathDialog::writeSwordConfig");
- if (m_swordPathListBox->topLevelItemCount() >= 0) {
- QStringList targets;
- QTreeWidgetItemIterator it(m_swordPathListBox);
- while (*it) {
- if (!(*it)->text(0).isEmpty()) {
- targets << (*it)->text(0);
- }
- ++it;
+ qDebug() << "BtInstallPathDialog::writeSwordConfig";
+ QStringList targets;
+ QTreeWidgetItemIterator it(m_swordPathListBox, QTreeWidgetItemIterator::NoChildren|QTreeWidgetItemIterator::Enabled|QTreeWidgetItemIterator::NotHidden);
+ while (*it) {
+ if (!(*it)->text(0).isEmpty()) {
+ targets << (*it)->text(0);
}
- qDebug() << "save the target list" << targets;
- instbackend::setTargetList(targets); //creates new Sword config
+ ++it;
}
+ qDebug() << "save the target list" << targets;
+ instbackend::setTargetList(targets); //creates new Sword config
}
void BtInstallPathDialog::accept() {
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h
index b2f18a1..e72da3c 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h
+++ b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h
@@ -12,14 +12,16 @@
#include <QDialog>
+
class QPushButton;
class QTreeWidget;
-
+class QTreeWidgetItem;
class BtInstallPathDialog : public QDialog {
Q_OBJECT
public:
BtInstallPathDialog();
+ ~BtInstallPathDialog();
public slots:
virtual void accept();
@@ -31,13 +33,17 @@ class BtInstallPathDialog : public QDialog {
private:
void writeSwordConfig();
+ void updateTopLevelItems();
+ void addPathToList(QString path);
private:
QPushButton* m_editButton;
QPushButton* m_addButton;
QPushButton* m_removeButton;
QTreeWidget* m_swordPathListBox;
-
+ QTreeWidgetItem* m_writableItem;
+ QTreeWidgetItem* m_readableItem;
+ QTreeWidgetItem* m_nonexistingItem;
};
#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp
index 7883220..365d5c8 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp
+++ b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp
@@ -7,26 +7,22 @@
*
**********/
-#include "btinstallprogressdialog.h"
+#include "frontend/bookshelfmanager/installpage/btinstallprogressdialog.h"
-#include "btinstallthread.h"
-
-#include "util/ctoolclass.h"
-#include "util/cpointers.h"
-#include "backend/managers/cswordbackend.h"
-
-#include <QTreeWidget>
-#include <QTreeWidgetItem>
+#include <QApplication>
+#include <QCloseEvent>
+#include <QDebug>
#include <QDialog>
#include <QHeaderView>
+#include <QMultiMap>
#include <QProgressBar>
#include <QPushButton>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
#include <QVBoxLayout>
-#include <QApplication>
-#include <QCloseEvent>
-#include <QMultiMap>
-
-#include <QDebug>
+#include "backend/managers/cswordbackend.h"
+#include "frontend/bookshelfmanager/installpage/btinstallthread.h"
+#include "util/cpointers.h"
BtInstallProgressDialog::BtInstallProgressDialog(QWidget* parent, QTreeWidget* selectedModulesTreeWidget, QString destination)
@@ -41,7 +37,7 @@ BtInstallProgressDialog::BtInstallProgressDialog(QWidget* parent, QTreeWidget* s
m_statusWidget->header()->setStretchLastSection(false);
m_statusWidget->header()->setResizeMode(1, QHeaderView::Stretch);
m_statusWidget->header()->setMovable(false);
- //m_statusWidget->setColumnWidth(1, CToolClass::mWidth(m_statusWidget, 2));
+ //m_statusWidget->setColumnWidth(1, util::tool::mWidth(m_statusWidget, 2));
foreach (QTreeWidgetItem* sourceItem, selectedModulesTreeWidget->invisibleRootItem()->takeChildren()) {
// create items and threads for modules under this source
@@ -125,7 +121,7 @@ void BtInstallProgressDialog::startThreads() {
t->start();
}
- qDebug("BtInstallProgressDialog::startThreads end");
+ qDebug() << "BtInstallProgressDialog::startThreads end";
}
BtInstallProgressDialog::~BtInstallProgressDialog() {}
@@ -133,7 +129,8 @@ BtInstallProgressDialog::~BtInstallProgressDialog() {}
void BtInstallProgressDialog::slotOneItemCompleted(QString module, QString source, int status) {
QString message;
- //status comes from the sword installer. TODO: Additionally we should check that there are files really installed.
+ //status comes from the sword installer.
+ /// \todo Additionally we should check that there are files really installed.
if (status != 0) {
message = tr("Failed");
}
@@ -189,7 +186,7 @@ void BtInstallProgressDialog::oneItemStoppedOrCompleted(QString module, QString
}
void BtInstallProgressDialog::slotStopInstall() {
- qDebug("BtInstallProgressDialog::slotStopInstall");
+ qDebug() << "BtInstallProgressDialog::slotStopInstall";
// Clear the waiting threads map, stop all running threads.
@@ -205,7 +202,7 @@ void BtInstallProgressDialog::slotStopInstall() {
}
void BtInstallProgressDialog::slotStatusUpdated(QString module, int status) {
- //qDebug("BtInstallProgressDialog::slotStatusUpdated");
+ //qDebug() << "BtInstallProgressDialog::slotStatusUpdated";
//qDebug() << "module:" << module << "status:" << status;
// find the progress bar for this module and update the value
QWidget* itemWidget = m_statusWidget->itemWidget(getItem(module) , 1);
@@ -234,7 +231,7 @@ QTreeWidgetItem* BtInstallProgressDialog::getItem(QString moduleName) {
}
void BtInstallProgressDialog::closeEvent(QCloseEvent* event) {
- qDebug("BtInstallProgressDialog::closeEvent");
+ qDebug() << "BtInstallProgressDialog::closeEvent";
if (event->spontaneous()) {
event->ignore();
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h
index 79c6331..1d8113a 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h
+++ b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h
@@ -11,18 +11,15 @@
#define BTINSTALLPROGRESSDIALOG_H
#include <QDialog>
-#include <QString>
+
#include <QMultiMap>
+#include <QString>
-class QTreeWidget;
-class QTreeWidgetItem;
class BtInstallThread;
+class QTreeWidget;
+class QTreeWidgetItem;
-
-/**
-
-*/
class BtInstallProgressDialog : public QDialog {
Q_OBJECT
public:
@@ -50,7 +47,7 @@ class BtInstallProgressDialog : public QDialog {
private:
- //TODO: using maps is tedious and error prone. Find better solution for handling the modules
+ /// \todo using maps is tedious and error prone. Find better solution for handling the modules
// and their states.
QMultiMap<QString, BtInstallThread*> m_waitingThreads;
QMultiMap<QString, BtInstallThread*> m_runningThreads;
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallthread.cpp b/src/frontend/bookshelfmanager/installpage/btinstallthread.cpp
index 48e38ce..53ae071 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallthread.cpp
+++ b/src/frontend/bookshelfmanager/installpage/btinstallthread.cpp
@@ -7,23 +7,22 @@
*
**********/
-#include "btinstallthread.h"
-
-#include "frontend/bookshelfmanager/btinstallmgr.h"
-#include "frontend/bookshelfmanager/instbackend.h"
-#include "util/cpointers.h"
-#include "backend/managers/cswordbackend.h"
+#include "frontend/bookshelfmanager/installpage/btinstallthread.h"
#include <QApplication>
+#include <QDebug>
+#include <QDir>
#include <QString>
#include <QThread>
-#include <QDir>
-
-#include <QDebug>
+#include "backend/managers/cswordbackend.h"
+#include "frontend/bookshelfmanager/btinstallmgr.h"
+#include "frontend/bookshelfmanager/instbackend.h"
+#include "util/cpointers.h"
-// sword
+// Sword includes:
#include <filemgr.h>
+
BtInstallThread::BtInstallThread(QObject* parent, QString moduleName, QString sourceName, QString destinationName)
: QThread(parent),
done(false),
@@ -44,12 +43,13 @@ void BtInstallThread::run() {
emit preparingInstall(m_module, m_source);
-
+ //This is 0 before set here - remember when using the value when cancelling
+ // the installation before this has been run
m_installSource.reset(new sword::InstallSource(instbackend::source(m_source)));
m_backendForSource.reset(instbackend::backend(*m_installSource));
//make sure target/mods.d and target/modules exist
- //TODO: move this to some common precondition
+ /// \todo move this to some common precondition
QDir dir(m_destination);
if (!dir.exists()) {
dir.mkdir(m_destination);
@@ -68,7 +68,7 @@ void BtInstallThread::run() {
QObject::connect(m_iMgr, SIGNAL(downloadStarted()), this, SLOT(slotDownloadStarted()), Qt::QueuedConnection);
//check whether it's an update. If yes, remove existing module first
- //TODO: silently removing without undo if the user cancels the update is WRONG!!!
+ /// \todo silently removing without undo if the user cancels the update is WRONG!!!
removeModule();
// manager for the destination path
@@ -112,35 +112,36 @@ void BtInstallThread::slotStopInstall() {
qDebug() << "BtInstallThread::slotStopInstall 2";
//qApp->processEvents();
// wait to terminate for some secs. We rather let the execution go on and cleaning up to fail than the app to freeze
- int notRun = this->wait(200);
+ int notRun = this->wait(25000);
if (notRun) {
this->terminate();
- this->wait(2);
+ this->wait(10000);
qDebug() << "installthread (" << m_module << ") terminated, delete m_iMgr";
delete m_iMgr; // this makes sure the ftp library will be cleaned up in the destroyer
m_iMgr = 0;
}
qDebug() << "BtInstallThread::slotStopInstall 3";
// cleanup: remove the module, remove the temp files
- if (true) {
+ // if installation has already started
+ if (m_installSource.get() != 0) {
qDebug() << "BtInstallThread::slotStopInstall 4";
// remove the installed module, just to be sure because mgr may
// have been terminated when copying files
removeModule();
removeTempFiles();
qDebug() << "BtInstallThread::slotStopInstall will emit installStopped...";
- emit installStopped(m_module, m_source);
}
+ emit installStopped(m_module, m_source);
}
}
void BtInstallThread::slotManagerStatusUpdated(int totalProgress, int /*fileProgress*/) {
- //qDebug("BtInstallThread::slotManagerStatusUpdated");
+ //qDebug() << "BtInstallThread::slotManagerStatusUpdated";
emit statusUpdated(m_module, totalProgress);
}
void BtInstallThread::slotDownloadStarted() {
- qDebug("BtInstallThread::slotDownloadStarted");
+ qDebug() << "BtInstallThread::slotDownloadStarted";
emit downloadStarted(m_module);
}
@@ -176,7 +177,7 @@ void BtInstallThread::removeModule() {
}
void BtInstallThread::removeTempFiles() {
- qDebug("BtInstallThread::removeTempFiles start");
+ qDebug() << "BtInstallThread::removeTempFiles start";
// (take the remote conf file for this module, take DataPath,
// take the absolute path of the InstallMgr)
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallthread.h b/src/frontend/bookshelfmanager/installpage/btinstallthread.h
index 8a8cb37..a50910f 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallthread.h
+++ b/src/frontend/bookshelfmanager/installpage/btinstallthread.h
@@ -10,11 +10,11 @@
#ifndef BTINSTALLTHREAD_H
#define BTINSTALLTHREAD_H
-#include "frontend/bookshelfmanager/btinstallmgr.h"
-
#include <QThread>
#include <boost/scoped_ptr.hpp>
+#include "frontend/bookshelfmanager/btinstallmgr.h"
+
class BtInstallProgressDialog;
@@ -78,7 +78,7 @@ class BtInstallThread : public QThread {
BtInstallMgr* m_iMgr;
//BtInstallMgr m_iMgr;
boost::scoped_ptr<sword::InstallSource> m_installSource;
- //TODO: it would be best to get the backend from the bookshelf manager install page
+ /// \todo it would be best to get the backend from the bookshelf manager install page
// where it has already been created. Could fasten the progress dialog startup.
boost::scoped_ptr<CSwordBackend> m_backendForSource;
diff --git a/src/frontend/bookshelfmanager/installpage/btsourcearea.cpp b/src/frontend/bookshelfmanager/installpage/btsourcearea.cpp
index cfdc8bb..ca85822 100644
--- a/src/frontend/bookshelfmanager/installpage/btsourcearea.cpp
+++ b/src/frontend/bookshelfmanager/installpage/btsourcearea.cpp
@@ -7,19 +7,7 @@
*
**********/
-#include "btsourcearea.h"
-
-#include "frontend/bookshelfmanager/instbackend.h"
-
-#include "util/ctoolclass.h"
-#include "util/cpointers.h"
-#include "util/cresmgr.h"
-#include "util/directoryutil.h"
-
-#include "backend/managers/cswordbackend.h"
-#include "frontend/btaboutmoduledialog.h"
-
-#include <installmgr.h>
+#include "frontend/bookshelfmanager/installpage/btsourcearea.h"
#include <QString>
#include <QWidget>
@@ -32,9 +20,19 @@
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QHeaderView>
-
#include <QDebug>
#include <QTime>
+#include "backend/managers/cswordbackend.h"
+#include "frontend/bookshelfmanager/instbackend.h"
+#include "frontend/btaboutmoduledialog.h"
+#include "util/directory.h"
+#include "util/cpointers.h"
+#include "util/cresmgr.h"
+#include "util/tool.h"
+
+// Sword includes:
+#include <installmgr.h>
+
// ****************************************************************
// ******** Installation source and module list widget ************
@@ -45,46 +43,40 @@ BtSourceArea::BtSourceArea(const QString& sourceName)
m_sourceName(sourceName),
m_treeAlreadyInitialized(false),
m_remoteBackend(0) { //important!
+ setObjectName(sourceName);
m_checkedModules = QMap<QString, bool>();
qDebug() << "BtSourceArea::BtSourceArea, " << m_sourceName;
initView();
}
BtSourceArea::~BtSourceArea() {
+ qDebug() << "BtSourceArea::~BtSourceArea" << m_sourceName;
delete m_remoteBackend;
}
void BtSourceArea::initView() {
- qDebug("BtSourceArea::initView");
+ namespace DU = util::directory;
+
+ qDebug() << "BtSourceArea::initView";
QVBoxLayout *mainLayout = new QVBoxLayout(this);
- //QHBoxLayout *refreshLabelLayout = new QHBoxLayout();
- //QLabel *refreshLabel = new QLabel(tr("Last refreshed:"));
- //m_refreshTimeLabel = new QLabel();
- //QSpacerItem *refreshLabelSpacer = new QSpacerItem(201, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
-
- //refreshLabelLayout->addWidget(refreshLabel);
- //refreshLabelLayout->addWidget(m_refreshTimeLabel);
- //refreshLabelLayout->addItem(refreshLabelSpacer);
- // TODO: or would it be better to integrate this information into the tooltip
- // of the source tab?
- //mainLayout->addLayout(refreshLabelLayout);
// source related button row
QHBoxLayout *sourceLayout = new QHBoxLayout();
m_refreshButton = new QPushButton(tr("Refresh..."));
m_refreshButton->setToolTip(tr("Refresh the list of works from this source"));
- m_refreshButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::installpage::refresh_icon));
+ m_refreshButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::installpage::refresh_icon));
//m_refreshButton->setEnabled(false);
QSpacerItem *sourceSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
//m_editButton = new QPushButton(tr("Edit..."));
- //m_editButton->setEnabled(false); // TODO after writing the edit widget
+ /// \todo after writing the edit widget:
+ //m_editButton->setEnabled(false);
m_deleteButton = new QPushButton(tr("Delete..."));
m_deleteButton->setToolTip(tr("Delete this source"));
- m_deleteButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::installpage::delete_icon));
+ m_deleteButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::installpage::delete_icon));
//m_deleteButton->setEnabled(false);
m_addButton = new QPushButton(tr("Add..."));
m_addButton->setToolTip(tr("Add new source"));
- m_addButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::installpage::add_icon));
+ m_addButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::installpage::add_icon));
sourceLayout->addWidget(m_refreshButton);
sourceLayout->addItem(sourceSpacer);
@@ -96,7 +88,7 @@ void BtSourceArea::initView() {
// There are no views for the stack yet, see initSources
m_view = new QTreeWidget(this);
m_view->setHeaderLabels(QStringList() << tr("Work") << tr("Description"));
- m_view->setColumnWidth(0, CToolClass::mWidth(m_view, 20));
+ m_view->setColumnWidth(0, util::tool::mWidth(m_view, 20));
mainLayout->addWidget(m_view);
connect(m_view, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), SLOT(slotItemDoubleClicked(QTreeWidgetItem*, int)));
@@ -104,6 +96,11 @@ void BtSourceArea::initView() {
connect(this, SIGNAL(signalCreateTree()), SLOT(slotCreateTree()), Qt::QueuedConnection);
}
+void BtSourceArea::prepareRemove() {
+ // don't create tree anymore, this will be removed
+ disconnect(this, SIGNAL(signalCreateTree()), this, SLOT(slotCreateTree()));
+}
+
QSize BtSourceArea::sizeHint() const {
return QSize(100, m_refreshButton->height() + (m_view->header()->height() * 5));
}
@@ -116,7 +113,7 @@ void BtSourceArea::initTreeFirstTime() {
}
void BtSourceArea::createModuleTree() {
- qDebug("BtSourceArea::createModuleTree start");
+ qDebug() << "BtSourceArea::createModuleTree start";
// Start creating tree with a queued connection.
// This makes showing the dialog possible even before the tree is initialized.
emit signalCreateTree();
@@ -133,8 +130,7 @@ void BtSourceArea::slotCreateTree() {
disconnect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) );
m_view->clear();
- // TODO: if the tree already exists for this source,
- // maybe the selections should be preserved
+ /// \todo if the tree already exists for this source, maybe the selections should be preserved
m_checkedModules.clear();
sword::InstallSource is = instbackend::source(m_sourceName);
@@ -181,11 +177,13 @@ void BtSourceArea::addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem
QString installedV;
if (!installedModule) {
- // possible TODO: save the module list of a source before refreshing,
- // compare after refreshing, mark the newly added modules
- //if not newly added:
- //state: installable (no indicator)
- //else: status: newly added, color yellow
+ /**
+ \todo maybe? save the module list of a source before refreshing,
+ compare after refreshing, mark the newly added modules if
+ not newly added:
+ state: installable (no indicator)
+ else: status: newly added, color yellow
+ */
} else { // the module is already installed
QBrush bg(QColor(255, 153, 153)); /// \bug Possible color conflict
widgetItem->setBackground(0, bg);
@@ -206,7 +204,7 @@ void BtSourceArea::addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem
QString descr(mInfo->config(CSwordModuleInfo::Description));
- QString toolTipText = CToolClass::remoteModuleToolTip(mInfo, installedV);
+ QString toolTipText = util::tool::remoteModuleToolTip(mInfo, installedV);
widgetItem->setText(1, descr);
widgetItem->setToolTip(0, toolTipText);
@@ -226,7 +224,7 @@ QMap<QString, bool>* BtSourceArea::selectedModules() {
// when a module is checked/unchecked
void BtSourceArea::slotSelectionChanged(QTreeWidgetItem* item, int column) {
- //qDebug("BtSourceArea::slotSelectionChanged");
+ //qDebug() << "BtSourceArea::slotSelectionChanged";
// modify the internal list of selected (actually checked) modules
// if() leaves groups away
if (!item->childCount() && column == 0) {
@@ -269,7 +267,7 @@ bool BtSourceArea::InstalledFilter::filter(CSwordModuleInfo* mInfo) {
//qDebug() << "BtSourceArea::InstalledFilter::filter, module " << mInfo->name();
CSwordModuleInfo* const installedModule = CPointers::backend()->findModuleByName(mInfo->name());
if (installedModule) {
- //qDebug("already installed, check if it's an update...");
+ //qDebug() << "already installed, check if it's an update...";
const sword::SWVersion installedVersion(installedModule->config(CSwordModuleInfo::ModuleVersion).toLatin1());
const sword::SWVersion newVersion(mInfo->config(CSwordModuleInfo::ModuleVersion).toLatin1());
if (installedVersion >= newVersion) {
diff --git a/src/frontend/bookshelfmanager/installpage/btsourcearea.h b/src/frontend/bookshelfmanager/installpage/btsourcearea.h
index e39efef..ece20ed 100644
--- a/src/frontend/bookshelfmanager/installpage/btsourcearea.h
+++ b/src/frontend/bookshelfmanager/installpage/btsourcearea.h
@@ -10,15 +10,16 @@
#ifndef BTSOURCEAREA_H
#define BTSOURCEAREA_H
-#include "backend/btmoduletreeitem.h"
+#include <QWidget>
#include <boost/scoped_ptr.hpp>
+#include <QApplication>
+#include <QMap>
+#include "backend/btmoduletreeitem.h"
+// Sword includes:
#include <installmgr.h>
-#include <QWidget>
-#include <QMap>
-#include <QApplication>
class QTreeWidget;
class QTreeWidgetItem;
@@ -54,6 +55,7 @@ class BtSourceArea : public QWidget {
~BtSourceArea();
void initView();
+ void prepareRemove();
/** Reimplemented from QWidget. */
virtual QSize sizeHint() const;
void initTreeFirstTime();
@@ -89,8 +91,6 @@ class BtSourceArea : public QWidget {
QPushButton* m_editButton;
QPushButton* m_deleteButton;
QPushButton* m_addButton;
-
-
};
#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp b/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp
index f18935a..8c43837 100644
--- a/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp
+++ b/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp
@@ -7,44 +7,42 @@
*
**********/
-#include "btsourcewidget.h"
+#include "frontend/bookshelfmanager/installpage/btsourcewidget.h"
-#include "btinstallpage.h"
-#include "btsourcearea.h"
-#include "btinstallprogressdialog.h"
-#include "btinstallmodulechooserdialog.h"
-
-#include "frontend/bookshelfmanager/btmodulemanagerdialog.h"
-#include "frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h"
-#include "frontend/bookshelfmanager/btinstallmgr.h"
-#include "frontend/bookshelfmanager/instbackend.h"
-
-
-#include <QString>
-#include <QWidget>
-#include <QTabWidget>
-#include <QMessageBox>
-#include <QProgressDialog>
-#include <QPushButton>
#include <QApplication>
#include <QFileInfo>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QProgressDialog>
+#include <QPushButton>
+#include <QString>
#include <QTabBar>
+#include <QTabWidget>
#include <QTreeWidget>
#include <QTreeWidgetItem>
-#include <QHBoxLayout>
-#include <QLabel>
+#include <QWidget>
+#include "frontend/bookshelfmanager/btinstallmgr.h"
+#include "frontend/bookshelfmanager/btmodulemanagerdialog.h"
+#include "frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h"
+#include "frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h"
+#include "frontend/bookshelfmanager/installpage/btinstallpage.h"
+#include "frontend/bookshelfmanager/installpage/btinstallprogressdialog.h"
+#include "frontend/bookshelfmanager/installpage/btsourcearea.h"
+#include "frontend/bookshelfmanager/instbackend.h"
+#include "util/dialogutil.h"
-// ****************************************************************
-// ******** Tab Widget that holds source widgets ******************
-// ****************************************************************
+/**
+* Tab Widget that holds source widgets
+*/
BtSourceWidget::BtSourceWidget(BtInstallPage* parent)
: QTabWidget(parent),
m_page(parent) {
- qDebug("BtSourceWidget::BtSourceWidget start");
+ qDebug() << "BtSourceWidget::BtSourceWidget start";
initSources();
-
- // TODO: choose the page from config
+ // send queued event because "Delete" is initiated from tab which should be deleted
+ connect(this, SIGNAL(sigInitSources()), SLOT(initSources()), Qt::QueuedConnection);
+ /// \todo choose the page from config
}
@@ -58,56 +56,57 @@ QString BtSourceWidget::currentSourceName() {
}
void BtSourceWidget::initSourceConnections() {
- qDebug("void BtSourceWidget::initSourceConnections() start");
+ qDebug() << "void BtSourceWidget::initSourceConnections() start";
if (area()) {
connect(area()->m_refreshButton, SIGNAL(clicked()), SLOT(slotRefresh()));
//connect(area()->m_editButton, SIGNAL(clicked()), SLOT(slotEdit()));
- connect(area()->m_deleteButton, SIGNAL(clicked()), SLOT(slotDelete()));
+ connect(area()->m_deleteButton, SIGNAL(clicked()), SLOT(slotDelete()), Qt::QueuedConnection);
connect(area()->m_addButton, SIGNAL(clicked()), SLOT(slotAdd()));
connect(area(), SIGNAL(signalSelectionChanged(QString, int)), SLOT(slotModuleSelectionChanged(QString, int)) );
}
- qDebug("void BtSourceWidget::initSourceConnections() end");
+ qDebug() << "void BtSourceWidget::initSourceConnections() end";
}
void BtSourceWidget::slotEdit() {
- qDebug("BtSourceWidget::slotEdit");
- // open the source editor dialog
+ qDebug() << "BtSourceWidget::slotEdit";
+ /// \todo open the source editor dialog
// if the source was changed, init the sources
}
void BtSourceWidget::slotDelete() {
- qDebug("void BtSourceWidget::slotDelete() start");
+ qDebug() << "void BtSourceWidget::slotDelete() start";
// ask for confirmation
- int ret = QMessageBox::warning(this, tr("Delete Source?"),
- tr("Do you really want to delete this source?"),
- QMessageBox::Yes | QMessageBox::No);
+ int ret = util::showWarning(this, tr("Delete Source?"),
+ tr("Do you really want to delete this source?"),
+ QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::Yes) {
instbackend::deleteSource(currentSourceName());
-
- // remove the UI elements
- m_sourceNameList.removeAt(currentIndex());
- QWidget* w = currentWidget();
- removeTab(currentIndex());
- delete w;
+ initSources();
}
}
void BtSourceWidget::slotAdd() {
- qDebug("void BtSourceWidget::slotAdd() start");
- qDebug("open the old dialog, TODO: write new one");
- sword::InstallSource newSource = CSwordSetupInstallSourcesDialog::getSource();
- if ( !((QString)newSource.type.c_str()).isEmpty() ) { // we have a valid source to add
- instbackend::addSource(newSource);
- addSource(QString(newSource.caption.c_str()));
+
+ boost::scoped_ptr<CSwordSetupInstallSourcesDialog> dlg( new CSwordSetupInstallSourcesDialog() );
+ sword::InstallSource newSource(""); //empty, invalid Source
+
+ if (dlg->exec() == QDialog::Accepted) {
+ if (!dlg->wasRemoteListAdded()) {
+ newSource = dlg->getSource();
+ if ( !((QString)newSource.type.c_str()).isEmpty() ) { // we have a valid source to add
+ instbackend::addSource(newSource);
+ }
+ }
+ initSources();
}
}
void BtSourceWidget::slotRefresh() {
- qDebug("void BtSourceWidget::slotRefresh() start");
+ qDebug() << "void BtSourceWidget::slotRefresh() start";
// (re)build the module cache for the source
QString sourceName = currentSourceName();
@@ -117,18 +116,18 @@ void BtSourceWidget::slotRefresh() {
m_progressDialog->setWindowTitle(tr("Refreshing Source"));
m_progressDialog->setMinimumDuration(0);
- // TODO: get rid of the backend code, BtInstallMgr and progressdialog could handle this
+ /// \todo get rid of the backend code, BtInstallMgr and progressdialog could handle this
//write method BtInstallMgr::slotRefreshCanceled()
connect(m_progressDialog, SIGNAL(canceled()), SLOT(slotRefreshCanceled()));
// BACKEND CODE **********************************************************
// would this be possible: instbackend::refreshSource( arguments );
- qDebug("void BtSourceWidget::slotRefresh 1");
+ qDebug() << "void BtSourceWidget::slotRefresh 1";
BtInstallMgr iMgr;
m_currentInstallMgr = &iMgr; //for the progress dialog
sword::InstallSource is = instbackend::source(sourceName);
bool success = false;
- qDebug("void BtSourceWidget::slotRefresh 2");
+ qDebug() << "void BtSourceWidget::slotRefresh 2";
// connect this directly to the dialog setValue(int) if possible
connect(&iMgr, SIGNAL(percentCompleted(const int, const int)), SLOT(slotRefreshCompleted(const int, const int)));
@@ -139,11 +138,7 @@ void BtSourceWidget::slotRefresh() {
m_progressDialog->setLabelText(tr("Connecting..."));
m_progressDialog->setValue(0);
qApp->processEvents();
- //qApp->flush();
- //qApp->processEvents();
- //m_progressDialog->repaint();
- //qApp->processEvents();
- qDebug("void BtSourceWidget::slotRefresh 3");
+ qDebug() << "void BtSourceWidget::slotRefresh 3";
bool successful = iMgr.refreshRemoteSource( &is );
if (!successful ) { //make sure the sources were updated sucessfully
success = true;
@@ -164,14 +159,14 @@ void BtSourceWidget::slotRefresh() {
// rebuild the view tree and refresh the view
if (success) {
- qDebug("void BtSourceWidget::slotRefresh 4");
+ qDebug() << "void BtSourceWidget::slotRefresh 4";
area()->createModuleTree();
}
}
-//TODO: try to move this to BtInstallMgr
+/// \todo try to move this to BtInstallMgr
void BtSourceWidget::slotRefreshCanceled() {
- qDebug("BtSourceWidget::slotRefreshCanceled");
+ qDebug() << "BtSourceWidget::slotRefreshCanceled";
Q_ASSERT(m_currentInstallMgr);
if (m_currentInstallMgr) {
m_currentInstallMgr->terminate();
@@ -179,9 +174,9 @@ void BtSourceWidget::slotRefreshCanceled() {
qApp->processEvents();
}
-//TODO: try to move this to progress dialog
+/// \todo try to move this to progress dialog
void BtSourceWidget::slotRefreshCompleted(const int, const int current) {
- qDebug("BtSourceWidget::slotRefreshCompleted");
+ qDebug() << "BtSourceWidget::slotRefreshCompleted";
if (m_progressDialog) {
if (m_progressDialog->labelText() != tr("Refreshing...")) {
m_progressDialog->setLabelText(tr("Refreshing..."));
@@ -193,18 +188,32 @@ void BtSourceWidget::slotRefreshCompleted(const int, const int current) {
// init the tabbar, setup the module tree for the current source
void BtSourceWidget::initSources() {
- qDebug("void BtSourceWidget::initSources() start");
+ qDebug() << "void BtSourceWidget::initSources() start";
+
+ //first clear all sources
+ //int i = count();
+ for (int i = count()-1; i >= 0; i--) {
+ BtSourceArea* a = dynamic_cast<BtSourceArea*>(widget(i));
+ a->prepareRemove();
+ }
+ for (int i = count()-1; i >= 0; i--) {
+ qDebug() << "remove tab"<<tabText(i);
+ QWidget* w = widget(i);
+ removeTab(i);
+ delete w;
+ qDebug() << "deleted";
+ }
+ m_sourceNameList.clear();
// ***** Use the backend to get the list of sources *****
instbackend::initPassiveFtpMode();
QStringList sourceList = instbackend::sourceList();
-
+ qDebug() << "got the source list from backend:" << sourceList;
// Add a default entry, the Crosswire main repository
- // TODO: this is easy for the user, but should the edit dialog
- // open automatically?
if (!sourceList.count()) {
+ /// \todo Open a dialog which asks whether to get list from server and add sources
sword::InstallSource is("FTP"); //default return value
- is.caption = "Crosswire";
+ is.caption = "CrossWire Bible Society";
is.source = "ftp.crosswire.org";
is.directory = "/pub/sword/raw";
// passive ftp is not needed here, it's the default
@@ -214,7 +223,7 @@ void BtSourceWidget::initSources() {
sourceList = instbackend::sourceList();
//Q_ASSERT( sourceList.count() > 0 );
}
- qDebug("void BtSourceWidget::initSources 1");
+ qDebug() << "void BtSourceWidget::initSources 1";
// Add the sources to the widget
foreach (QString sourceName, sourceList) {
addSource(sourceName);
@@ -222,8 +231,8 @@ void BtSourceWidget::initSources() {
// connect this after the tabs have been created,
// otherwise the signal is caught too early.
QObject::connect(this, SIGNAL(currentChanged(int)), this, SLOT(slotTabSelected(int)));
- qDebug("void BtSourceWidget::initSources end");
- // TODO: select the current source from the config
+ qDebug() << "void BtSourceWidget::initSources end";
+ /// \todo select the current source from the config
// It's important to choose something because the tree is not initialized until now
setCurrentIndex(0);
slotTabSelected(0); // setting the index wasn't enough if there were only 1 tab
@@ -237,7 +246,7 @@ void BtSourceWidget::initSources() {
}
void BtSourceWidget::addSource(const QString& sourceName) {
- qDebug("void BtSourceWidget::addSource(const QString& sourceName) start");
+ qDebug() << "void BtSourceWidget::addSource(const QString& sourceName) start, with name" << sourceName;
// The source has already been added to the backend.
QString type;
@@ -254,10 +263,10 @@ void BtSourceWidget::addSource(const QString& sourceName) {
QFileInfo fi( is.directory.c_str() );
path = is.directory.c_str();
if (!(fi.isDir() )) {
- path = path + QString(" ") + tr("Not a directory!"); //TODO: change this
+ path = path + QString(" ") + tr("Not a directory!"); /// \todo change this
}
if (!fi.isReadable()) {
- path = path + QString(" ") + tr("Not readable!"); //TODO: change this
+ path = path + QString(" ") + tr("Not readable!"); /// \todo change this
}
}
@@ -265,7 +274,7 @@ void BtSourceWidget::addSource(const QString& sourceName) {
BtSourceArea* area = new BtSourceArea(sourceName);
int tabNumber = this->addTab(area, sourceName);
- // TODO: add "remote/local", server, path etc.
+ /// \todo add "remote/local", server, path etc.
QString toolTip(QString("<p style='white-space:pre'>") + sourceName + QString("<br/><b>") + type + QString("</b> ") + server + path + QString("</p>"));
tabBar()->setTabToolTip(tabNumber, toolTip);
@@ -273,13 +282,13 @@ void BtSourceWidget::addSource(const QString& sourceName) {
setCurrentIndex(tabNumber);
m_sourceNameList.append(sourceName);
initSourceConnections();
- qDebug("BtSourceWidget::addSource end");
+ qDebug() << "BtSourceWidget::addSource end";
}
//
void BtSourceWidget::slotModuleSelectionChanged(QString sourceName, int selectedCount) {
- //TODO: editing sources should update the map also
- qDebug("BtSourceWidget::slotModuleSelectionChanged start");
+ /// \todo editing sources should update the map also
+ qDebug() << "BtSourceWidget::slotModuleSelectionChanged start";
int overallCount = 0;
m_selectedModulesCountMap.insert(sourceName, selectedCount);
@@ -302,7 +311,7 @@ void BtSourceWidget::slotTabSelected(int /*index*/) {
}
void BtSourceWidget::slotInstall() {
- qDebug("void BtInstallPage::slotInstall start");
+ qDebug() << "void BtInstallPage::slotInstall start";
// check that the destination path is writable, do nothing if not and user doesn't want to continue
QDir dir = QDir(dynamic_cast<BtInstallPage*>(parent())->selectedInstallPath());
@@ -317,7 +326,7 @@ void BtSourceWidget::slotInstall() {
canWrite = false;
}
if (!canWrite) {
- const int result = QMessageBox::warning(this, tr("Warning"), tr("The destination directory is not writable or does not exist. Installation will fail unless this has first been fixed."), QMessageBox::Ignore | QMessageBox::Cancel, QMessageBox::Cancel);
+ const int result = util::showWarning(this, tr("Warning"), tr("The destination directory is not writable or does not exist. Installation will fail unless this has first been fixed."), QMessageBox::Ignore | QMessageBox::Cancel, QMessageBox::Cancel);
if (result != QMessageBox::Ignore) {
return;
}
@@ -373,18 +382,18 @@ void BtSourceWidget::slotStopInstall(QTreeWidget* /*treeWidget*/) {
void BtSourceWidget::slotInstallAccepted(QList<CSwordModuleInfo*> /*modules*/, QTreeWidget* treeWidget) {
qDebug() << "BtSourceWidget::slotInstallAccepted";
- //TODO: first remove all modules which will be updated from the module list
+ /// \todo first remove all modules which will be updated from the module list
// but what modules? all with the same real name? (there may be _n modules...)
BtModuleManagerDialog* parentDialog = dynamic_cast<BtModuleManagerDialog*>(dynamic_cast<BtInstallPage*>(parent())->parentDialog());
BtInstallProgressDialog* dlg = new BtInstallProgressDialog(parentDialog, treeWidget, dynamic_cast<BtInstallPage*>(parent())->selectedInstallPath());
- if (!parentDialog) qDebug("error, wrong parent!");
+ if (!parentDialog) qDebug() << "error, wrong parent!";
m_page->setInstallEnabled(false);
// the progress dialog is now modal, it can be made modeless later.
dlg->exec();
- qDebug("BtSourceWidget::slotInstallAccepted end");
+ qDebug() << "BtSourceWidget::slotInstallAccepted end";
}
diff --git a/src/frontend/bookshelfmanager/installpage/btsourcewidget.h b/src/frontend/bookshelfmanager/installpage/btsourcewidget.h
index 46b7d0a..fbe8426 100644
--- a/src/frontend/bookshelfmanager/installpage/btsourcewidget.h
+++ b/src/frontend/bookshelfmanager/installpage/btsourcewidget.h
@@ -9,16 +9,16 @@
#ifndef BTSOURCEWIDGET_H
#define BTSOURCEWIDGET_H
-class CSwordModuleInfo;
-
#include <QTabWidget>
-#include <QString>
+
#include <QMap>
+#include <QString>
+
class BtInstallMgr;
class BtInstallPage;
class BtSourceArea;
-
+class CSwordModuleInfo;
class QProgressDialog;
class QTreeWidget;
@@ -46,13 +46,13 @@ class BtSourceWidget : public QTabWidget {
private:
void initSourceConnections();
- /** Add tabs/views for each source. */
- void initSources();
/** Add one source to tabs/stack. */
void addSource(const QString& sourceName);
private slots:
+ /** Add tabs/views for each source. */
+ void initSources();
void slotRefresh();
@@ -72,7 +72,8 @@ class BtSourceWidget : public QTabWidget {
void slotTabSelected(int index);
void slotInstallAccepted(QList<CSwordModuleInfo*> mi, QTreeWidget* treeWidget);
-
+ signals:
+ void sigInitSources();
private:
QStringList m_sourceNameList;
diff --git a/src/frontend/bookshelfmanager/instbackend.cpp b/src/frontend/bookshelfmanager/instbackend.cpp
index caf1e08..d671430 100644
--- a/src/frontend/bookshelfmanager/instbackend.cpp
+++ b/src/frontend/bookshelfmanager/instbackend.cpp
@@ -7,31 +7,26 @@
*
**********/
-#include "instbackend.h"
+#include "frontend/bookshelfmanager/instbackend.h"
-#include "frontend/bookshelfmanager/btinstallmgr.h"
-#include "backend/managers/cswordbackend.h"
-
-#include "util/cpointers.h"
-#include "util/directoryutil.h"
-
-//Qt includes
+#include <functional>
+#include <map>
+#include <QDebug>
+#include <QDir>
#include <QFile>
#include <QFileInfo>
-#include <QDir>
-#include <QMessageBox>
-
-#include <QDebug>
+#include <utility>
+#include "backend/managers/cswordbackend.h"
+#include "frontend/bookshelfmanager/btinstallmgr.h"
+#include "util/cpointers.h"
+#include "util/directory.h"
+#include "util/dialogutil.h"
-//Sword includes
+// Sword includes:
#include <filemgr.h>
#include <swconfig.h>
#include <swbuf.h>
-//Stl includes
-#include <functional>
-#include <map>
-#include <utility>
using namespace sword;
@@ -39,7 +34,7 @@ namespace instbackend {
/** Adds the source described by Source to the backend. */
bool addSource(sword::InstallSource& source) {
- qDebug("backend::addSource");
+ qDebug() << "backend::addSource";
SWConfig config(configFilename().toLatin1());
if (!strcmp(source.type, "FTP")) {
//make sure the path doesn't have a trailing slash, sword doesn't like it
@@ -58,7 +53,7 @@ bool addSource(sword::InstallSource& source) {
/** Returns the Source struct. */
sword::InstallSource source(QString name) {
- qDebug("backend::source");
+ qDebug() << "backend::source";
BtInstallMgr mgr;
InstallSourceMap::iterator source = mgr.sources.find(name.toLatin1().data());
if (source != mgr.sources.end()) {
@@ -93,7 +88,7 @@ sword::InstallSource source(QString name) {
/** Deletes the source. */
bool deleteSource(QString name) {
- qDebug("backend::deleteSource");
+ qDebug() << "backend::deleteSource";
sword::InstallSource is = source(name );
SWConfig config(configFilename().toLatin1());
@@ -105,28 +100,48 @@ bool deleteSource(QString name) {
: config["Sources"].equal_range("DIRSource");
ConfigEntMap::iterator it = range.first;
+ SWBuf sourceConfigEntry = is.getConfEnt();
+ bool notFound = true;
while (it != range.second) {
- if (it->second == is.getConfEnt()) {
- // qWarning("found the source!");
+ //SWORD lib gave us a "nice" surprise: getConfEnt() adds uid, so old sources added by BT are not recognized here
+ if (it->second == sourceConfigEntry) {
config["Sources"].erase(it);
+ notFound = false;
break;
}
++it;
}
+ if (notFound) {
+ qDebug() << "source was not found, try without uid";
+ //try again without uid
+ QString sce(sourceConfigEntry.c_str());
+ QStringList l = sce.split('|');
+ l.removeLast();
+ sce = l.join("|").append("|");
+ it = range.first;
+ while (it != range.second) {
+ qDebug() << it->second;
+ if (it->second == sce) {
+ config["Sources"].erase(it);
+ break;
+ }
+ ++it;
+ }
+ }
config.Save();
- return true; //TODO: dummy
+ return true; /// \todo dummy
}
/** Refreshes the remote source module list. */
bool refreshSource(QString /*name*/) {
// not possible until manager and progressdialog work together
- return true; //TODO: dummy
+ return true; /// \todo dummy
}
/** Returns the moduleinfo list for the source. Delete the pointer after using. IS THIS POSSIBLE?*/
QList<CSwordModuleInfo*> moduleList(QString /*name*/) {
- QList<CSwordModuleInfo*> list; //TODO: dummy
+ QList<CSwordModuleInfo*> list; /// \todo dummy
return list;
}
@@ -135,10 +150,8 @@ bool isRemote(const sword::InstallSource& source) {
}
const QString configPath() {
- const char *envhomedir = getenv("HOME");
- QString confPath = QString(envhomedir ? envhomedir : ".");
- confPath.append("/.sword/InstallMgr");
-
+ QString confPath = util::directory::getUserHomeSwordDir().absolutePath();
+ confPath.append("/InstallMgr");
return confPath;
}
@@ -147,16 +160,18 @@ const QString configFilename() {
}
QStringList targetList() {
- qDebug("backend::targetList");
+ qDebug() << "backend::targetList";
QStringList names = CPointers::backend()->swordDirList();
return names;
}
bool setTargetList( const QStringList& targets ) {
- qDebug("backend::setTargetList");
+ namespace DU = util::directory;
+
+ qDebug() << "backend::setTargetList";
//saves a new Sword config using the provided target list
//QString filename = KGlobal::dirs()->saveLocation("data", "bibletime/") + "sword.conf"; //default is to assume the real location isn't writable
- //QString filename = util::filesystem::DirectoryUtil::getUserBaseDir().canonicalPath().append("/.sword/sword.conf");
+ //QString filename = util::DirectoryUtil::getUserBaseDir().canonicalPath().append("/.sword/sword.conf");
//bool directAccess = false;
QString filename = swordConfigFilename();
QFileInfo i(filename);
@@ -177,15 +192,30 @@ bool setTargetList( const QStringList& targets ) {
else {
// There is no way to save to the file
qWarning() << "The Sword config file is not writable!";
- QMessageBox::warning(0, QObject::tr("Can't write file"), QObject::tr("The Sword config file can't be written!"));
+ util::showWarning(0, QObject::tr("Can't write file"), QObject::tr("The Sword config file can't be written!"));
return false;
}
+
+ filename = util::directory::convertDirSeparators(filename);
SWConfig conf(filename.toLocal8Bit());
conf.Sections.clear();
+
+#ifdef Q_WS_WIN
+ // On Windows, add the sword directory to the config file.
+ QString swordPath = DU::convertDirSeparators( DU::getApplicationSwordDir().absolutePath());
+ conf["Install"].insert(
+ std::make_pair( SWBuf("LocalePath"), swordPath.toLocal8Bit().data() )
+ );
+#endif
+
bool setDataPath = false;
for (QStringList::const_iterator it = targets.begin(); it != targets.end(); ++it) {
- QString t = *it;
- if (t.contains( util::filesystem::DirectoryUtil::getUserHomeDir().canonicalPath().append("/.sword") )) {
+ QString t = DU::convertDirSeparators(*it);
+#ifdef Q_WS_WIN
+ if (t.contains(DU::convertDirSeparators(DU::getUserHomeDir().canonicalPath().append("\\Sword")))) {
+#else
+ if (t.contains(DU::getUserHomeDir().canonicalPath().append("/.sword"))) {
+#endif
//we don't want $HOME/.sword in the config
continue;
}
@@ -202,7 +232,7 @@ bool setTargetList( const QStringList& targets ) {
}
QStringList sourceList() {
- qDebug("backend::sourceList");
+ qDebug() << "backend::sourceList";
BtInstallMgr mgr;
Q_ASSERT(mgr.installConf);
@@ -233,23 +263,37 @@ QStringList sourceList() {
void initPassiveFtpMode() {
- qDebug("backend::initPassiveFtpMode");
+ qDebug() << "backend::initPassiveFtpMode";
SWConfig config(configFilename().toLatin1());
config["General"]["PassiveFTP"] = "true";
config.Save();
}
const QString swordConfigFilename() {
- qDebug("backend::swordConfigFilename");
- qDebug() << util::filesystem::DirectoryUtil::getUserHomeDir().absolutePath().append("/.sword/sword.conf");
- return util::filesystem::DirectoryUtil::getUserHomeDir().absolutePath().append("/.sword/sword.conf");
+ namespace DU = util::directory;
+
+ qDebug() << "backend::swordConfigFilename";
+#ifdef Q_WS_WIN
+ qDebug() << DU::getUserHomeDir().absolutePath().append("/Sword/sword.conf");
+ return DU::getUserHomeDir().absolutePath().append("/Sword/sword.conf");
+// return DU::getApplicationDir().absolutePath().append("/sword.conf");
+#else
+ qDebug() << DU::getUserHomeDir().absolutePath().append("/.sword/sword.conf");
+ return DU::getUserHomeDir().absolutePath().append("/.sword/sword.conf");
+#endif
}
const QDir swordDir() {
- return QDir(util::filesystem::DirectoryUtil::getUserHomeDir().absolutePath().append("/.sword/"));
+ namespace DU = util::directory;
+
+#ifdef Q_WS_WIN
+ return QDir(DU::getUserHomeDir().absolutePath().append("/Sword/"));
+#else
+ return QDir(DU::getUserHomeDir().absolutePath().append("/.sword/"));
+#endif
}
CSwordBackend* backend( const sword::InstallSource& is) {
- qDebug("backend::backend");
+ qDebug() << "backend::backend";
CSwordBackend* ret = 0;
if (isRemote(is)) {
ret = new CSwordBackend( QString(is.localShadow.c_str()), false );
diff --git a/src/frontend/bookshelfmanager/instbackend.h b/src/frontend/bookshelfmanager/instbackend.h
index 4f60ed9..3a98e5a 100644
--- a/src/frontend/bookshelfmanager/instbackend.h
+++ b/src/frontend/bookshelfmanager/instbackend.h
@@ -10,16 +10,16 @@
#ifndef INSTBACKEND_H
#define INSTBACKEND_H
-#include "backend/managers/cswordbackend.h"
-
-class CSwordModuleInfo;
-
-#include <QString>
#include <QDir>
+#include <QString>
+#include "backend/managers/cswordbackend.h"
+// Sword includes:
#include <installmgr.h>
+class CSwordModuleInfo;
+
namespace instbackend {
/** Adds the source to the backend. */
@@ -55,7 +55,7 @@ const QString configPath();
const QString configFilename();
/** Sets the passive mode for as default.
-* TODO: see if we can en/disable this per source.
+* \todo see if we can en/disable this per source.
*/
void initPassiveFtpMode();
diff --git a/src/frontend/bookshelfmanager/removepage/btremovepage.cpp b/src/frontend/bookshelfmanager/removepage/btremovepage.cpp
index cd8f687..1cc6398 100644
--- a/src/frontend/bookshelfmanager/removepage/btremovepage.cpp
+++ b/src/frontend/bookshelfmanager/removepage/btremovepage.cpp
@@ -7,38 +7,35 @@
*
**********/
+#include "frontend/bookshelfmanager/removepage/btremovepage.h"
-#include "btremovepage.h"
-
-
+#include <QDebug>
+#include <QGridLayout>
+#include <QLabel>
+#include <QList>
+#include <QMultiMap>
+#include <QPushButton>
+#include <QString>
+#include <QTreeWidget>
+#include <QTreeWidgetItem>
#include "backend/btmoduletreeitem.h"
#include "backend/config/cbtconfig.h"
#include "backend/drivers/cswordmoduleinfo.h"
-
-#include "util/ctoolclass.h"
+#include "util/directory.h"
+#include "util/dialogutil.h"
#include "util/cpointers.h"
-#include "util/directoryutil.h"
#include "util/cresmgr.h"
+#include "util/tool.h"
+// Sword includes:
#include <swmgr.h>
#include <installmgr.h>
-#include <QString>
-#include <QGridLayout>
-#include <QLabel>
-#include <QPushButton>
-#include <QTreeWidget>
-#include <QTreeWidgetItem>
-#include <QMessageBox>
-#include <QList>
-#include <QMultiMap>
-
-#include <QDebug>
-
-
BtRemovePage::BtRemovePage()
: BtConfigPage() {
+ namespace DU = util::directory;
+
QGridLayout* layout = new QGridLayout(this);
layout->setMargin(5);
@@ -48,13 +45,13 @@ BtRemovePage::BtRemovePage()
m_view = new QTreeWidget(this);
m_view->setHeaderLabels(QStringList() << tr("Work") << tr("Install path"));
- m_view->setColumnWidth(0, CToolClass::mWidth(m_view, 20));
+ m_view->setColumnWidth(0, util::tool::mWidth(m_view, 20));
layout->addWidget( m_view, 2, 0, 1, 2);
m_removeButton = new QPushButton(tr("Remove..."), this);
m_removeButton->setToolTip(tr("Remove the selected works"));
- m_removeButton->setIcon( util::filesystem::DirectoryUtil::getIcon(CResMgr::bookshelfmgr::removepage::remove_icon) );
+ m_removeButton->setIcon(DU::getIcon(CResMgr::bookshelfmgr::removepage::remove_icon));
m_removeButton->setEnabled(false);
layout->addWidget(m_removeButton, 3, 1, Qt::AlignRight);
@@ -89,7 +86,7 @@ void BtRemovePage::populateModuleList() {
// receive signal when user checks modules
connect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) );
- qDebug("BtSourceArea::createModuleTree end");
+ qDebug() << "BtSourceArea::createModuleTree end";
}
void BtRemovePage::addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem) {
@@ -111,11 +108,11 @@ void BtRemovePage::addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem
widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
widgetItem->setCheckState(0, Qt::Unchecked);
- //TODO: add the relevant information in to item or tooltip
+ /// \todo add the relevant information in to item or tooltip
// (install path, is still available from some source)
QString descr(mInfo->config(CSwordModuleInfo::AbsoluteDataPath));
- QString toolTipText = CToolClass::moduleToolTip(mInfo);
+ QString toolTipText = util::tool::moduleToolTip(mInfo);
widgetItem->setText(1, descr);
widgetItem->setToolTip(0, toolTipText);
widgetItem->setToolTip(1, descr);
@@ -139,7 +136,7 @@ void BtRemovePage::slotRemoveModules() {
.append("\n\n")
.append(tr("Do you really want to remove them from your system?"));
- if ((QMessageBox::question(this, tr("Remove Works?"), message, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)) { //Yes was pressed.
+ if ((util::showQuestion(this, tr("Remove Works?"), message, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)) { //Yes was pressed.
// Update the module list before really removing. Remember deleting the pointers later.
QList<CSwordModuleInfo*> toBeDeleted = CPointers::backend()->takeModulesFromList(moduleNames);
@@ -181,12 +178,12 @@ void BtRemovePage::slotRemoveModules() {
void BtRemovePage::slotSelectionChanged(QTreeWidgetItem* item, int column) {
- //qDebug("BtRemovePage::slotSelectionChanged");
+ //qDebug() << "BtRemovePage::slotSelectionChanged";
// modify the internal list of checked modules
// if() leaves groups away
if (!item->childCount() && column == 0) {
CSwordModuleInfo* mInfo = 0;
- //qDebug("BtRemovePage::slotSelectionChanged");
+ //qDebug() << "BtRemovePage::slotSelectionChanged";
foreach (CSwordModuleInfo* module, CPointers::backend()->moduleList()) {
if (module->name() == item->text(0) && module->config(CSwordModuleInfo::AbsoluteDataPath) == item->text(1)) {
mInfo = module;
@@ -213,7 +210,7 @@ void BtRemovePage::slotSelectionChanged(QTreeWidgetItem* item, int column) {
}
void BtRemovePage::slotItemDoubleClicked(QTreeWidgetItem* /*item*/, int /*column*/) {
- // TODO: Open the About dialog.
+ // \todo Open the About dialog.
}
void BtRemovePage::slotSwordSetupChanged() {
diff --git a/src/frontend/bookshelfmanager/removepage/btremovepage.h b/src/frontend/bookshelfmanager/removepage/btremovepage.h
index 782fcc0..920b1ee 100644
--- a/src/frontend/bookshelfmanager/removepage/btremovepage.h
+++ b/src/frontend/bookshelfmanager/removepage/btremovepage.h
@@ -7,23 +7,20 @@
*
**********/
-
#ifndef BTREMOVEPAGE_H
#define BTREMOVEPAGE_H
#include "frontend/bookshelfmanager/btconfigdialog.h"
-#include "backend/btmoduletreeitem.h"
-#include <QString>
#include <QMultiMap>
+#include <QString>
+#include "backend/btmoduletreeitem.h"
-//class BTModuleTreeItem;
class QTreeWidget;
class QTreeWidgetItem;
class QPushButton;
-
class BtRemovePage : public BtConfigPage {
Q_OBJECT