summaryrefslogtreecommitdiff
path: root/src/frontend/bookshelfmanager
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/bookshelfmanager')
-rw-r--r--src/frontend/bookshelfmanager/btconfigdialog.cpp145
-rw-r--r--src/frontend/bookshelfmanager/btconfigdialog.h86
-rw-r--r--src/frontend/bookshelfmanager/btinstallmgr.cpp88
-rw-r--r--src/frontend/bookshelfmanager/btinstallmgr.h76
-rw-r--r--src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp84
-rw-r--r--src/frontend/bookshelfmanager/btmodulemanagerdialog.h35
-rw-r--r--src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp237
-rw-r--r--src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h24
-rw-r--r--src/frontend/bookshelfmanager/indexpage/btindexpage.cpp282
-rw-r--r--src/frontend/bookshelfmanager/indexpage/btindexpage.h115
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp188
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h29
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpage.cpp203
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpage.h67
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp241
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h43
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp340
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h69
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallthread.cpp281
-rw-r--r--src/frontend/bookshelfmanager/installpage/btinstallthread.h83
-rw-r--r--src/frontend/bookshelfmanager/installpage/btsourcearea.cpp432
-rw-r--r--src/frontend/bookshelfmanager/installpage/btsourcearea.h105
-rw-r--r--src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp625
-rw-r--r--src/frontend/bookshelfmanager/installpage/btsourcewidget.h107
-rw-r--r--src/frontend/bookshelfmanager/instbackend.cpp380
-rw-r--r--src/frontend/bookshelfmanager/removepage/btremovepage.cpp320
-rw-r--r--src/frontend/bookshelfmanager/removepage/btremovepage.h53
27 files changed, 2312 insertions, 2426 deletions
diff --git a/src/frontend/bookshelfmanager/btconfigdialog.cpp b/src/frontend/bookshelfmanager/btconfigdialog.cpp
index 87cb12e..0fcbc5a 100644
--- a/src/frontend/bookshelfmanager/btconfigdialog.cpp
+++ b/src/frontend/bookshelfmanager/btconfigdialog.cpp
@@ -26,93 +26,88 @@
#include <QEvent>
BtConfigDialog::BtConfigDialog(QWidget* parent)
- : QDialog(parent),
- m_maxItemWidth(0),
- m_previousPageIndex(-2)
-{
- setWindowFlags(Qt::Window);
- m_contentsList = new QListWidget(this);
- m_contentsList->setViewMode(QListView::IconMode);
- m_contentsList->setMovement(QListView::Static);
-
- m_pageWidget = new QStackedWidget(this);
- m_pageWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
-
- QHBoxLayout *mainLayout = new QHBoxLayout;
- setLayout(mainLayout);
- mainLayout->addWidget(m_contentsList);
- m_pageLayout = new QVBoxLayout;
- mainLayout->addLayout(m_pageLayout);
-
- m_pageLayout->addWidget(m_pageWidget);
-
- // Horizontal line
- QFrame* line = new QFrame();
- line->setGeometry(QRect(1, 1, 1, 3));
+ : QDialog(parent),
+ m_maxItemWidth(0),
+ m_previousPageIndex(-2) {
+ setWindowFlags(Qt::Window);
+ m_contentsList = new QListWidget(this);
+ m_contentsList->setViewMode(QListView::IconMode);
+ m_contentsList->setMovement(QListView::Static);
+
+ m_pageWidget = new QStackedWidget(this);
+ m_pageWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+
+ QHBoxLayout *mainLayout = new QHBoxLayout;
+ setLayout(mainLayout);
+ mainLayout->addWidget(m_contentsList);
+ m_pageLayout = new QVBoxLayout;
+ mainLayout->addLayout(m_pageLayout);
+
+ m_pageLayout->addWidget(m_pageWidget);
+
+ // Horizontal line
+ QFrame* line = new QFrame();
+ line->setGeometry(QRect(1, 1, 1, 3));
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
- line->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
- m_pageLayout->addWidget(line);
-
- connect(m_contentsList,
- SIGNAL(currentRowChanged(int)),
- this, SLOT(slotChangePage(int))
- );
-
+ line->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ m_pageLayout->addWidget(line);
+
+ connect(m_contentsList,
+ SIGNAL(currentRowChanged(int)),
+ this, SLOT(slotChangePage(int))
+ );
+
}
BtConfigDialog::~BtConfigDialog() {}
-void BtConfigDialog::addPage(BtConfigPage* pageWidget)
-{
- // this is a friend
- pageWidget->m_parentDialog = this;
-
- QVBoxLayout* containerLayout = new QVBoxLayout;
- QLabel* headerLabel = CToolClass::explanationLabel(pageWidget, pageWidget->header(), pageWidget->label());
- containerLayout->addWidget(headerLabel);
- containerLayout->addWidget(pageWidget);
- QWidget* containerWidget = new QWidget(m_pageWidget);
- containerWidget->setLayout(containerLayout);
- m_pageWidget->addWidget(containerWidget);
-
-
- QListWidgetItem* item = new QListWidgetItem(m_contentsList);
- item->setIcon(util::filesystem::DirectoryUtil::getIcon(pageWidget->iconName()));
- item->setText(pageWidget->header());
- item->setTextAlignment(Qt::AlignHCenter);
- item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
-
- //set the list width - it may bee too wide (if there were no pages) or too narrow
- if (m_maxItemWidth < m_contentsList->visualItemRect(item).width()) {
- m_maxItemWidth = m_contentsList->visualItemRect(item).width();
- m_contentsList->setFixedWidth( m_maxItemWidth + (m_contentsList->frameWidth()*2) );
- }
- // all items should has the same width
- for(int i = 0; i < m_contentsList->count(); ++i) {
- m_contentsList->item(i)->setSizeHint(QSize(m_maxItemWidth, m_contentsList->visualItemRect(m_contentsList->item(i)).height()) );
- }
-
- slotChangePage(m_contentsList->row(item));
+void BtConfigDialog::addPage(BtConfigPage* pageWidget) {
+ // this is a friend
+ pageWidget->m_parentDialog = this;
+
+ QVBoxLayout* containerLayout = new QVBoxLayout;
+ QLabel* headerLabel = CToolClass::explanationLabel(pageWidget, pageWidget->header(), pageWidget->label());
+ containerLayout->addWidget(headerLabel);
+ containerLayout->addWidget(pageWidget);
+ QWidget* containerWidget = new QWidget(m_pageWidget);
+ containerWidget->setLayout(containerLayout);
+ m_pageWidget->addWidget(containerWidget);
+
+
+ QListWidgetItem* item = new QListWidgetItem(m_contentsList);
+ item->setIcon(util::filesystem::DirectoryUtil::getIcon(pageWidget->iconName()));
+ item->setText(pageWidget->header());
+ item->setTextAlignment(Qt::AlignHCenter);
+ item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+
+ //set the list width - it may bee too wide (if there were no pages) or too narrow
+ if (m_maxItemWidth < m_contentsList->visualItemRect(item).width()) {
+ m_maxItemWidth = m_contentsList->visualItemRect(item).width();
+ m_contentsList->setFixedWidth( m_maxItemWidth + (m_contentsList->frameWidth()*2) );
+ }
+ // all items should has the same width
+ for (int i = 0; i < m_contentsList->count(); ++i) {
+ m_contentsList->item(i)->setSizeHint(QSize(m_maxItemWidth, m_contentsList->visualItemRect(m_contentsList->item(i)).height()) );
+ }
+
+ slotChangePage(m_contentsList->row(item));
}
-void BtConfigDialog::addButtonBox(QDialogButtonBox* box)
-{
- m_pageLayout->addWidget(box);
+void BtConfigDialog::addButtonBox(QDialogButtonBox* box) {
+ m_pageLayout->addWidget(box);
}
-BtConfigPage* BtConfigDialog::currentPage()
-{
- return dynamic_cast<BtConfigPage*>(m_pageWidget->currentWidget());
+BtConfigPage* BtConfigDialog::currentPage() {
+ return dynamic_cast<BtConfigPage*>(m_pageWidget->currentWidget());
}
-void BtConfigDialog::slotChangePage(int newIndex)
-{
- if (m_previousPageIndex != newIndex) {
- m_previousPageIndex = newIndex;
- m_contentsList->setCurrentRow(newIndex);
- m_pageWidget->setCurrentIndex(newIndex);
- }
+void BtConfigDialog::slotChangePage(int newIndex) {
+ if (m_previousPageIndex != newIndex) {
+ m_previousPageIndex = newIndex;
+ m_contentsList->setCurrentRow(newIndex);
+ m_pageWidget->setCurrentIndex(newIndex);
+ }
}
diff --git a/src/frontend/bookshelfmanager/btconfigdialog.h b/src/frontend/bookshelfmanager/btconfigdialog.h
index 7fb3482..8773a83 100644
--- a/src/frontend/bookshelfmanager/btconfigdialog.h
+++ b/src/frontend/bookshelfmanager/btconfigdialog.h
@@ -32,31 +32,30 @@ class QVBoxLayout;
* Connect the button box signals. Use setAttribute(Qt::WA_DeleteOnClose) if you want
* an auto-destroying window.
*/
-class BtConfigDialog : public QDialog
-{
- Q_OBJECT
-public:
- BtConfigDialog(QWidget* parent);
- virtual ~BtConfigDialog();
-
- /** Adds a BtConfigPage to the paged widget stack. The new page will be the current page.*/
- void addPage(BtConfigPage* pageWidget);
- /** Adds a button box to the lower edge of the dialog. */
- void addButtonBox(QDialogButtonBox* buttonBox);
-
- /** Returns the currently selected page. */
- BtConfigPage* currentPage();
-
-public slots:
- /** Changes the current page using the given index number. */
- void slotChangePage(int newIndex);
-
-private:
- QListWidget* m_contentsList;
- QStackedWidget* m_pageWidget;
- QVBoxLayout* m_pageLayout;
- int m_maxItemWidth;
- int m_previousPageIndex;
+class BtConfigDialog : public QDialog {
+ Q_OBJECT
+ public:
+ BtConfigDialog(QWidget* parent);
+ virtual ~BtConfigDialog();
+
+ /** Adds a BtConfigPage to the paged widget stack. The new page will be the current page.*/
+ void addPage(BtConfigPage* pageWidget);
+ /** Adds a button box to the lower edge of the dialog. */
+ void addButtonBox(QDialogButtonBox* buttonBox);
+
+ /** Returns the currently selected page. */
+ BtConfigPage* currentPage();
+
+ public slots:
+ /** Changes the current page using the given index number. */
+ void slotChangePage(int newIndex);
+
+ private:
+ QListWidget* m_contentsList;
+ QStackedWidget* m_pageWidget;
+ QVBoxLayout* m_pageLayout;
+ int m_maxItemWidth;
+ int m_previousPageIndex;
};
@@ -64,24 +63,25 @@ private:
/**
* Base class for configuration dialog pages.
*/
-class BtConfigPage : public QWidget
-{
- Q_OBJECT
-public:
- BtConfigPage();
- virtual ~BtConfigPage();
-
- /** Implement these to return the correct values.
- * For example: header(){return tr("General");}
- */
- virtual QString iconName() = 0;
- virtual QString label() = 0;
- virtual QString header() = 0;
- BtConfigDialog* parentDialog() {return m_parentDialog;}
-
-private:
- friend class BtConfigDialog;
- BtConfigDialog* m_parentDialog;
+class BtConfigPage : public QWidget {
+ Q_OBJECT
+ public:
+ BtConfigPage();
+ virtual ~BtConfigPage();
+
+ /** Implement these to return the correct values.
+ * For example: header(){return tr("General");}
+ */
+ virtual QString iconName() = 0;
+ virtual QString label() = 0;
+ virtual QString header() = 0;
+ BtConfigDialog* parentDialog() {
+ return m_parentDialog;
+ }
+
+ private:
+ friend class BtConfigDialog;
+ BtConfigDialog* m_parentDialog;
};
diff --git a/src/frontend/bookshelfmanager/btinstallmgr.cpp b/src/frontend/bookshelfmanager/btinstallmgr.cpp
index 976250f..799fa0d 100644
--- a/src/frontend/bookshelfmanager/btinstallmgr.cpp
+++ b/src/frontend/bookshelfmanager/btinstallmgr.cpp
@@ -29,60 +29,56 @@ using namespace sword;
BtInstallMgr::BtInstallMgr()
- : InstallMgr(instbackend::configPath().toLatin1(), this),
- m_firstCallOfPreStatus(true)
-{ //use this class also as status reporter
- qDebug("BtInstallMgr::BtInstallMgr");
- this->setFTPPassive(true);
+ : InstallMgr(instbackend::configPath().toLatin1(), this),
+ m_firstCallOfPreStatus(true) { //use this class also as status reporter
+ qDebug("BtInstallMgr::BtInstallMgr");
+ this->setFTPPassive(true);
}
BtInstallMgr::~BtInstallMgr() {
- //doesn't really help because it only sets a flag
- terminate(); //make sure to close the connection
+ //doesn't really help because it only sets a flag
+ terminate(); //make sure to close the connection
}
-bool BtInstallMgr::isUserDisclaimerConfirmed() const
-{
- // 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;
+bool BtInstallMgr::isUserDisclaimerConfirmed() const {
+ // 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");
- if (dlnow > dltotal)
- dlnow = dltotal;
-
- int totalPercent = (int)((float)(dlnow + m_completedBytes) / (float)(m_totalBytes) * 100.0);
-
- if (totalPercent > 100) {
- totalPercent = 100;
- }
- else if (totalPercent < 0) {
- totalPercent = 0;
- }
-
- int filePercent = (int)((float)(dlnow) / (float)(dltotal+1) * 100.0);
- if (filePercent > 100) {
- filePercent = 100;
- }
- else if (filePercent < 0) {
- filePercent = 0;
- }
- //qApp->processEvents();
- //qDebug() << "status: total"<<totalPercent<<"file"<<filePercent;
- emit percentCompleted(totalPercent, filePercent);
+void BtInstallMgr::statusUpdate(double dltotal, double dlnow) {
+ //qDebug("BtInstallMgr::statusUpdate");
+ if (dlnow > dltotal)
+ dlnow = dltotal;
+
+ int totalPercent = (int)((float)(dlnow + m_completedBytes) / (float)(m_totalBytes) * 100.0);
+
+ if (totalPercent > 100) {
+ totalPercent = 100;
+ }
+ else if (totalPercent < 0) {
+ totalPercent = 0;
+ }
+
+ int filePercent = (int)((float)(dlnow) / (float)(dltotal + 1) * 100.0);
+ if (filePercent > 100) {
+ filePercent = 100;
+ }
+ else if (filePercent < 0) {
+ filePercent = 0;
+ }
+ //qApp->processEvents();
+ //qDebug() << "status: total"<<totalPercent<<"file"<<filePercent;
+ emit percentCompleted(totalPercent, filePercent);
}
-void BtInstallMgr::preStatus(long totalBytes, long completedBytes, const char* message)
-{
- if (m_firstCallOfPreStatus) {
- m_firstCallOfPreStatus = false;
- emit downloadStarted();
- }
- qDebug() << "BtInstallMgr::preStatus:" << (int)totalBytes << "/" << (int)completedBytes << QString(message);
- m_completedBytes = completedBytes;
- m_totalBytes = (totalBytes > 0) ? totalBytes : 1; //avoid division by zero
+void BtInstallMgr::preStatus(long totalBytes, long completedBytes, const char* message) {
+ if (m_firstCallOfPreStatus) {
+ m_firstCallOfPreStatus = false;
+ emit downloadStarted();
+ }
+ qDebug() << "BtInstallMgr::preStatus:" << (int)totalBytes << "/" << (int)completedBytes << QString(message);
+ m_completedBytes = completedBytes;
+ m_totalBytes = (totalBytes > 0) ? totalBytes : 1; //avoid division by zero
}
diff --git a/src/frontend/bookshelfmanager/btinstallmgr.h b/src/frontend/bookshelfmanager/btinstallmgr.h
index 1420079..0561b96 100644
--- a/src/frontend/bookshelfmanager/btinstallmgr.h
+++ b/src/frontend/bookshelfmanager/btinstallmgr.h
@@ -29,44 +29,44 @@ typedef QList<sword::InstallSource*> InstallSourceList;
* Our own reimplementation to provide installation and status bar updates.
*/
class BtInstallMgr : public QObject, public sword::InstallMgr, public sword::StatusReporter {
- Q_OBJECT
-public:
-
- BtInstallMgr();
- virtual ~BtInstallMgr();
-
- /**
- * Refreshing the source should be cancellable (othewise it might freeze the app if there is
- * for example something wrong with the network).
- */
- void slotRefreshCanceled();
-
- /** Re-implemented from sword::InstallMgr. */
- virtual bool isUserDisclaimerConfirmed() const;
-
-protected:
- /* Reimplementations of methods in StatusReporter */
- /**
- * Gets the total and current file status, emits the signal with those values as percents.
- */
- virtual void statusUpdate(double dltotal, double dlnow);
- /**
- * Called before starting to download each file of the module package.
- * The sword message is not i18n'ed, it's in the form "Downloading (1 of 6): nt.bzs".
- * This function is not utilized in the UI ATM.
- */
- virtual void preStatus(long totalBytes, long completedBytes, const char *message);
-
- long m_totalBytes;
- long m_completedBytes;
-
-private:
- bool m_firstCallOfPreStatus;
-
-signals:
- /** Download status. Percent of total and file.*/
- void percentCompleted( const int, const int);
- void downloadStarted();
+ Q_OBJECT
+ public:
+
+ BtInstallMgr();
+ virtual ~BtInstallMgr();
+
+ /**
+ * Refreshing the source should be cancellable (othewise it might freeze the app if there is
+ * for example something wrong with the network).
+ */
+ void slotRefreshCanceled();
+
+ /** Re-implemented from sword::InstallMgr. */
+ virtual bool isUserDisclaimerConfirmed() const;
+
+ protected:
+ /* Reimplementations of methods in StatusReporter */
+ /**
+ * Gets the total and current file status, emits the signal with those values as percents.
+ */
+ virtual void statusUpdate(double dltotal, double dlnow);
+ /**
+ * Called before starting to download each file of the module package.
+ * The sword message is not i18n'ed, it's in the form "Downloading (1 of 6): nt.bzs".
+ * This function is not utilized in the UI ATM.
+ */
+ virtual void preStatus(long totalBytes, long completedBytes, const char *message);
+
+ long m_totalBytes;
+ long m_completedBytes;
+
+ private:
+ bool m_firstCallOfPreStatus;
+
+ signals:
+ /** Download status. Percent of total and file.*/
+ void percentCompleted( const int, const int);
+ void downloadStarted();
};
diff --git a/src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp b/src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp
index c26de6f..b361965 100644
--- a/src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp
+++ b/src/frontend/bookshelfmanager/btmodulemanagerdialog.cpp
@@ -23,67 +23,61 @@
static BtModuleManagerDialog* m_staticModuleManagerDialog = 0;
-BtModuleManagerDialog* BtModuleManagerDialog::getInstance(QWidget* parent)
-{
- if (!m_staticModuleManagerDialog) {
- m_staticModuleManagerDialog = new BtModuleManagerDialog(parent);
- };
- Q_ASSERT(m_staticModuleManagerDialog);
- return m_staticModuleManagerDialog;
+BtModuleManagerDialog* BtModuleManagerDialog::getInstance(QWidget* parent) {
+ if (!m_staticModuleManagerDialog) {
+ m_staticModuleManagerDialog = new BtModuleManagerDialog(parent);
+ };
+ Q_ASSERT(m_staticModuleManagerDialog);
+ return m_staticModuleManagerDialog;
}
BtModuleManagerDialog::BtModuleManagerDialog(QWidget* parent)
- : BtConfigDialog(parent)
-{
- setAttribute(Qt::WA_DeleteOnClose);
- setWindowTitle(tr("Bookshelf Manager"));
+ : BtConfigDialog(parent) {
+ setAttribute(Qt::WA_DeleteOnClose);
+ setWindowTitle(tr("Bookshelf Manager"));
- // Install page
- BtInstallPage* installPage = new BtInstallPage();
- addPage(installPage);
+ // Install page
+ BtInstallPage* installPage = new BtInstallPage();
+ addPage(installPage);
- //Uninstall page
- BtRemovePage* removePage = new BtRemovePage();
- addPage(removePage);
+ //Uninstall page
+ BtRemovePage* removePage = new BtRemovePage();
+ addPage(removePage);
- //Index page
- BtIndexPage* indexPage = new BtIndexPage();
- addPage(indexPage);
+ //Index page
+ BtIndexPage* indexPage = new BtIndexPage();
+ addPage(indexPage);
- slotChangePage(0);
+ slotChangePage(0);
- // Dialog button (Close)
- QDialogButtonBox* bbox = new QDialogButtonBox(this);
- bbox->addButton(QDialogButtonBox::Close);
- util::prepareDialogBox(bbox);
- addButtonBox(bbox);
- connect(bbox, SIGNAL(rejected()), SLOT(close()));
+ // Dialog button (Close)
+ QDialogButtonBox* bbox = new QDialogButtonBox(this);
+ bbox->addButton(QDialogButtonBox::Close);
+ util::prepareDialogBox(bbox);
+ addButtonBox(bbox);
+ connect(bbox, SIGNAL(rejected()), SLOT(close()));
- loadDialogSettings();
+ loadDialogSettings();
}
-BtModuleManagerDialog::~BtModuleManagerDialog()
-{
- saveDialogSettings();
- m_staticModuleManagerDialog = 0;
+BtModuleManagerDialog::~BtModuleManagerDialog() {
+ saveDialogSettings();
+ m_staticModuleManagerDialog = 0;
}
// The QWidget close() sends close event, so does closing by the window X button.
-void BtModuleManagerDialog::closeEvent(QCloseEvent*)
-{
- qDebug("BtModuleManagerDialog::closeEvent");
+void BtModuleManagerDialog::closeEvent(QCloseEvent*) {
+ qDebug("BtModuleManagerDialog::closeEvent");
}
-void BtModuleManagerDialog::loadDialogSettings()
-{
- resize(CBTConfig::get(CBTConfig::bookshelfWidth), CBTConfig::get(CBTConfig::bookshelfHeight));
- move(CBTConfig::get(CBTConfig::bookshelfPosX), CBTConfig::get(CBTConfig::bookshelfPosY));
+void BtModuleManagerDialog::loadDialogSettings() {
+ resize(CBTConfig::get(CBTConfig::bookshelfWidth), CBTConfig::get(CBTConfig::bookshelfHeight));
+ move(CBTConfig::get(CBTConfig::bookshelfPosX), CBTConfig::get(CBTConfig::bookshelfPosY));
}
-void BtModuleManagerDialog::saveDialogSettings()
-{
- CBTConfig::set(CBTConfig::bookshelfWidth, size().width());
- CBTConfig::set(CBTConfig::bookshelfHeight, size().height());
- CBTConfig::set(CBTConfig::bookshelfPosX, x());
- CBTConfig::set(CBTConfig::bookshelfPosY, y());
+void BtModuleManagerDialog::saveDialogSettings() {
+ CBTConfig::set(CBTConfig::bookshelfWidth, size().width());
+ CBTConfig::set(CBTConfig::bookshelfHeight, size().height());
+ CBTConfig::set(CBTConfig::bookshelfPosX, x());
+ CBTConfig::set(CBTConfig::bookshelfPosY, y());
}
diff --git a/src/frontend/bookshelfmanager/btmodulemanagerdialog.h b/src/frontend/bookshelfmanager/btmodulemanagerdialog.h
index ffb7169..ff8c35f 100644
--- a/src/frontend/bookshelfmanager/btmodulemanagerdialog.h
+++ b/src/frontend/bookshelfmanager/btmodulemanagerdialog.h
@@ -18,30 +18,29 @@ class QWidget;
/**
* The Bookshelf Manager dialog. Includes pages for Install, Remove, Indexes.
*/
-class BtModuleManagerDialog : public BtConfigDialog
-{
- Q_OBJECT
+class BtModuleManagerDialog : public BtConfigDialog {
+ Q_OBJECT
-public:
- static BtModuleManagerDialog* getInstance(QWidget* parent);
-
- ~BtModuleManagerDialog();
+ public:
+ static BtModuleManagerDialog* getInstance(QWidget* parent);
+ ~BtModuleManagerDialog();
- //void slotClose();
-protected:
- /** Reimplementation from QWidget. */
- virtual void closeEvent(QCloseEvent* event);
- /** Adds the pages and the button box. */
- BtModuleManagerDialog(QWidget* parent);
+ //void slotClose();
+ protected:
+ /** Reimplementation from QWidget. */
+ virtual void closeEvent(QCloseEvent* event);
-private:
- // Load the settings from the resource file
- void loadDialogSettings();
+ /** Adds the pages and the button box. */
+ BtModuleManagerDialog(QWidget* parent);
- // Save the settings to the resource file
- void saveDialogSettings();
+ private:
+ // Load the settings from the resource file
+ void loadDialogSettings();
+
+ // Save the settings to the resource file
+ void saveDialogSettings();
//signals:
diff --git a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp b/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp
index bca32fa..eca4498 100644
--- a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp
+++ b/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp
@@ -35,150 +35,149 @@ const QString PROTO_FTP( QObject::tr("Remote") ); //Remote path
CSwordSetupInstallSourcesDialog::CSwordSetupInstallSourcesDialog(/*QWidget *parent*/)
- : QDialog()
-{
- setWindowTitle(tr("New Installation Source"));
+ : QDialog() {
+ setWindowTitle(tr("New Installation Source"));
- QVBoxLayout* mainLayout = new QVBoxLayout( this );
- mainLayout->setMargin( 10 );
- mainLayout->setSpacing( 5 );
+ QVBoxLayout* mainLayout = new QVBoxLayout( this );
+ mainLayout->setMargin( 10 );
+ mainLayout->setSpacing( 5 );
- QHBoxLayout *captionLayout = new QHBoxLayout( this );
- mainLayout->addLayout(captionLayout);
- QLabel *label = new QLabel( tr("Caption"), this );
- captionLayout->addWidget( label );
+ QHBoxLayout *captionLayout = new QHBoxLayout( this );
+ mainLayout->addLayout(captionLayout);
+ QLabel *label = new QLabel( tr("Caption"), this );
+ captionLayout->addWidget( label );
- m_captionEdit = new QLineEdit( this );
- m_captionEdit->setText("Crosswire Bible Society");
- captionLayout->addWidget( m_captionEdit );
+ m_captionEdit = new QLineEdit( this );
+ m_captionEdit->setText("Crosswire Bible Society");
+ captionLayout->addWidget( m_captionEdit );
- mainLayout->addSpacing( 10 );
+ mainLayout->addSpacing( 10 );
- QGridLayout* layout = new QGridLayout( this );
- layout->setSpacing(3);
- layout->setMargin(3);
- mainLayout->addLayout(layout);
- layout->setSpacing( 5 );
+ QGridLayout* layout = new QGridLayout( this );
+ layout->setSpacing(3);
+ layout->setMargin(3);
+ mainLayout->addLayout(layout);
+ layout->setSpacing( 5 );
- label = new QLabel(tr("Type"), this);
- layout->addWidget( label, 0, 0);
+ label = new QLabel(tr("Type"), this);
+ layout->addWidget( label, 0, 0);
- m_serverLabel = new QLabel(tr("Server"), this);
- layout->addWidget( m_serverLabel, 0, 1);
+ m_serverLabel = new QLabel(tr("Server"), this);
+ layout->addWidget( m_serverLabel, 0, 1);
- label = new QLabel(tr("Path"), this);
- layout->addWidget( label, 0, 2 );
+ label = new QLabel(tr("Path"), this);
+ layout->addWidget( label, 0, 2 );
- m_protocolCombo = new QComboBox( this );
- layout->addWidget(m_protocolCombo, 1, 0);
- m_protocolCombo->addItem( PROTO_FTP );
- m_protocolCombo->addItem( PROTO_FILE );
+ m_protocolCombo = new QComboBox( this );
+ layout->addWidget(m_protocolCombo, 1, 0);
+ m_protocolCombo->addItem( PROTO_FTP );
+ m_protocolCombo->addItem( PROTO_FILE );
- m_serverEdit = new QLineEdit( this );
- layout->addWidget( m_serverEdit, 1, 1 );
- m_serverEdit->setText("ftp.crosswire.org");
+ m_serverEdit = new QLineEdit( this );
+ layout->addWidget( m_serverEdit, 1, 1 );
+ m_serverEdit->setText("ftp.crosswire.org");
- m_pathEdit = new QLineEdit( this );
- layout->addWidget( m_pathEdit, 1, 2 );
- m_pathEdit->setText("/pub/sword/raw");
+ m_pathEdit = new QLineEdit( this );
+ layout->addWidget( m_pathEdit, 1, 2 );
+ m_pathEdit->setText("/pub/sword/raw");
- mainLayout->addSpacing( 10 );
+ 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();
+ 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() ) );
- connect( m_protocolCombo, SIGNAL( activated(int) ), this, SLOT( slotProtocolChanged() ) );
+ connect( okButton, SIGNAL( clicked() ), this, SLOT( slotOk() ) );
+ connect( discardButton, SIGNAL( clicked() ), this, 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);
- return;
- }
-
- //BTInstallMgr iMgr;
- //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);
- 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);
- 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);
- return;
- }
- else if ( m_pathEdit->text().isEmpty() ) {
- QMessageBox::information( this, tr( "Error" ), tr("Please provide a path."), QMessageBox::Retry);
-
- }
- }
-
- accept(); //only if nothing else failed
+ //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);
+ return;
+ }
+
+ //BTInstallMgr iMgr;
+ //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);
+ 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);
+ 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);
+ return;
+ }
+ else if ( m_pathEdit->text().isEmpty() ) {
+ QMessageBox::information( this, tr( "Error" ), tr("Please provide a path."), QMessageBox::Retry);
+
+ }
+ }
+
+ accept(); //only if nothing else failed
}
void CSwordSetupInstallSourcesDialog::slotProtocolChanged() {
- if (m_protocolCombo->currentText() == PROTO_FTP) { //REMOTE
- m_serverLabel->setEnabled(true);
- m_serverEdit->setEnabled(true);
- }
- else { //LOCAL, no server needed
- m_serverLabel->setEnabled(false);
- m_serverEdit->setEnabled(false);
-
- QString dirname = QFileDialog::getExistingDirectory(this);
- if (dirname.isEmpty()) {
- return; // user cancelled
- }
- QDir dir(dirname);
- if (dir.exists()) {
- m_pathEdit->setText( dir.canonicalPath() );
- }
- }
+ if (m_protocolCombo->currentText() == PROTO_FTP) { //REMOTE
+ m_serverLabel->setEnabled(true);
+ m_serverEdit->setEnabled(true);
+ }
+ else { //LOCAL, no server needed
+ m_serverLabel->setEnabled(false);
+ m_serverEdit->setEnabled(false);
+
+ QString dirname = QFileDialog::getExistingDirectory(this);
+ if (dirname.isEmpty()) {
+ return; // user cancelled
+ }
+ QDir dir(dirname);
+ if (dir.exists()) {
+ m_pathEdit->setText( dir.canonicalPath() );
+ }
+ }
}
sword::InstallSource CSwordSetupInstallSourcesDialog::getSource() {
- boost::scoped_ptr<CSwordSetupInstallSourcesDialog> dlg( new CSwordSetupInstallSourcesDialog() );
- sword::InstallSource newSource(""); //empty, invalid Source
-
- if (dlg->exec() == QDialog::Accepted) {
- if (dlg->m_protocolCombo->currentText() == PROTO_FTP) {
- newSource.type = "FTP";
- newSource.source = dlg->m_serverEdit->text().toUtf8();
-
- //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";
- }
- newSource.caption = dlg->m_captionEdit->text().toUtf8();
- newSource.directory = dlg->m_pathEdit->text().toUtf8();
- }
- return newSource;
+ boost::scoped_ptr<CSwordSetupInstallSourcesDialog> dlg( new CSwordSetupInstallSourcesDialog() );
+ sword::InstallSource newSource(""); //empty, invalid Source
+
+ if (dlg->exec() == QDialog::Accepted) {
+ if (dlg->m_protocolCombo->currentText() == PROTO_FTP) {
+ newSource.type = "FTP";
+ newSource.source = dlg->m_serverEdit->text().toUtf8();
+
+ //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";
+ }
+ newSource.caption = dlg->m_captionEdit->text().toUtf8();
+ newSource.directory = dlg->m_pathEdit->text().toUtf8();
+ }
+ return newSource;
}
diff --git a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h b/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h
index 47f1973..d875cda 100644
--- a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h
+++ b/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h
@@ -24,22 +24,22 @@ class QLineEdit;
class CSwordSetupInstallSourcesDialog : public QDialog {
- Q_OBJECT
+ Q_OBJECT
-public:
- static sword::InstallSource getSource();
+ public:
+ static sword::InstallSource getSource();
-protected:
- CSwordSetupInstallSourcesDialog();
+ protected:
+ CSwordSetupInstallSourcesDialog();
-protected slots:
- void slotOk();
- void slotProtocolChanged();
+ protected slots:
+ void slotOk();
+ void slotProtocolChanged();
-private:
- QLabel *m_serverLabel;
- QLineEdit *m_captionEdit, *m_serverEdit, *m_pathEdit;
- QComboBox *m_protocolCombo;
+ private:
+ QLabel *m_serverLabel;
+ QLineEdit *m_captionEdit, *m_serverEdit, *m_pathEdit;
+ QComboBox *m_protocolCombo;
};
diff --git a/src/frontend/bookshelfmanager/indexpage/btindexpage.cpp b/src/frontend/bookshelfmanager/indexpage/btindexpage.cpp
index cad5a84..2a628c9 100644
--- a/src/frontend/bookshelfmanager/indexpage/btindexpage.cpp
+++ b/src/frontend/bookshelfmanager/indexpage/btindexpage.cpp
@@ -31,185 +31,177 @@
BtIndexPage::BtIndexPage()
- : BtConfigPage()
-{
+ : BtConfigPage() {
- QVBoxLayout *vboxLayout;
- QHBoxLayout *hboxLayout;
+ QVBoxLayout *vboxLayout;
+ QHBoxLayout *hboxLayout;
vboxLayout = new QVBoxLayout(this);
- m_autoDeleteOrphanedIndicesBox = new QCheckBox(this);
- m_autoDeleteOrphanedIndicesBox->setToolTip(tr("If selected, those indexes which have no corresponding work will be deleted when BibleTime starts"));
- m_autoDeleteOrphanedIndicesBox->setText(tr("Automatically delete orphaned indexes when BibleTime starts"));
- vboxLayout->addWidget(m_autoDeleteOrphanedIndicesBox);
+ m_autoDeleteOrphanedIndicesBox = new QCheckBox(this);
+ m_autoDeleteOrphanedIndicesBox->setToolTip(tr("If selected, those indexes which have no corresponding work will be deleted when BibleTime starts"));
+ m_autoDeleteOrphanedIndicesBox->setText(tr("Automatically delete orphaned indexes when BibleTime starts"));
+ vboxLayout->addWidget(m_autoDeleteOrphanedIndicesBox);
- m_moduleList = new QTreeWidget(this);
- vboxLayout->addWidget(m_moduleList);
+ m_moduleList = new QTreeWidget(this);
+ vboxLayout->addWidget(m_moduleList);
- hboxLayout = new QHBoxLayout();
+ hboxLayout = new QHBoxLayout();
- QSpacerItem *spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
- hboxLayout->addItem(spacerItem);
+ QSpacerItem *spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
+ hboxLayout->addItem(spacerItem);
- m_deleteButton = new QPushButton(this);
- m_deleteButton->setToolTip(tr("Delete the selected indexes"));
- m_deleteButton->setText(tr("Delete"));
- hboxLayout->addWidget(m_deleteButton);
+ m_deleteButton = new QPushButton(this);
+ m_deleteButton->setToolTip(tr("Delete the selected indexes"));
+ m_deleteButton->setText(tr("Delete"));
+ hboxLayout->addWidget(m_deleteButton);
- m_createButton = new QPushButton(this);
- m_createButton->setToolTip(tr("Create new indexes for the selected works"));
- m_createButton->setText(tr("Create..."));
- hboxLayout->addWidget(m_createButton);
+ m_createButton = new QPushButton(this);
+ m_createButton->setToolTip(tr("Create new indexes for the selected works"));
+ m_createButton->setText(tr("Create..."));
+ hboxLayout->addWidget(m_createButton);
- vboxLayout->addLayout(hboxLayout);
+ vboxLayout->addLayout(hboxLayout);
- // 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->setTextAlignment(1, Qt::AlignRight); see doc...
- m_moduleList->setSortingEnabled(false);
+ // 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->setTextAlignment(1, Qt::AlignRight); see doc...
+ m_moduleList->setSortingEnabled(false);
- m_autoDeleteOrphanedIndicesBox->setChecked( CBTConfig::get( CBTConfig::autoDeleteOrphanedIndices ) );
+ 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));
+ // 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));
- // connect our signals/slots
- connect(m_createButton, SIGNAL(clicked()), this, SLOT(createIndices()));
- connect(m_deleteButton, SIGNAL(clicked()), this, SLOT(deleteIndices()));
- connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(slotSwordSetupChanged()));
+ // connect our signals/slots
+ connect(m_createButton, SIGNAL(clicked()), this, SLOT(createIndices()));
+ connect(m_deleteButton, SIGNAL(clicked()), this, SLOT(deleteIndices()));
+ connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(slotSwordSetupChanged()));
- populateModuleList();
+ populateModuleList();
}
-BtIndexPage::~BtIndexPage()
-{
- CBTConfig::set( CBTConfig::autoDeleteOrphanedIndices, m_autoDeleteOrphanedIndicesBox->isChecked() );
+BtIndexPage::~BtIndexPage() {
+ CBTConfig::set( CBTConfig::autoDeleteOrphanedIndices, m_autoDeleteOrphanedIndicesBox->isChecked() );
}
-QString BtIndexPage::label()
-{
- return tr("Create new search indexes and delete created indexes for the installed works.");
+QString BtIndexPage::label() {
+ return tr("Create new search indexes and delete created indexes for the installed works.");
}
-QString BtIndexPage::iconName()
-{
- return CResMgr::bookshelfmgr::indexpage::icon;
+QString BtIndexPage::iconName() {
+ return CResMgr::bookshelfmgr::indexpage::icon;
}
-QString BtIndexPage::header()
-{
- return tr("Search Indexes");
+QString BtIndexPage::header() {
+ return tr("Search Indexes");
}
/** Populates the module list with installed modules and orphaned indices */
void BtIndexPage::populateModuleList() {
- m_moduleList->clear();
-
- // populate installed modules
- m_modsWithIndices = new QTreeWidgetItem(m_moduleList);
- m_modsWithIndices->setText(0, tr("Indexed Works"));
- m_modsWithIndices->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
- m_modsWithIndices->setExpanded(true);
-
- m_modsWithoutIndices = new QTreeWidgetItem(m_moduleList);
- m_modsWithoutIndices->setText(0, tr("Unindexed Works"));
- m_modsWithoutIndices->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
- m_modsWithoutIndices->setExpanded(true);
-
-
-
- QList<CSwordModuleInfo*>& modules = CPointers::backend()->moduleList();
- QList<CSwordModuleInfo*>::iterator end_it = modules.end();
- for (QList<CSwordModuleInfo*>::iterator it = modules.begin(); it != end_it; ++it) {
- QTreeWidgetItem* item = 0;
-
- if ((*it)->hasIndex()) {
- item = new QTreeWidgetItem(m_modsWithIndices);
- item->setText(0, (*it)->name());
- item->setText(1, QString("%1 ").arg((*it)->indexSize() / 1024) + tr("KiB"));
- item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
- item->setCheckState(0, Qt::Unchecked);
- }
- else {
- item = new QTreeWidgetItem(m_modsWithoutIndices);
- item->setText(0, (*it)->name());
- item->setText(1, QString("0 ") + tr("KiB"));
- item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
- item->setCheckState(0, Qt::Checked);
- }
- }
+ typedef QList<CSwordModuleInfo*>::const_iterator MLCI;
+
+ m_moduleList->clear();
+
+ // populate installed modules
+ m_modsWithIndices = new QTreeWidgetItem(m_moduleList);
+ m_modsWithIndices->setText(0, tr("Indexed Works"));
+ m_modsWithIndices->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
+ m_modsWithIndices->setExpanded(true);
+
+ m_modsWithoutIndices = new QTreeWidgetItem(m_moduleList);
+ m_modsWithoutIndices->setText(0, tr("Unindexed Works"));
+ m_modsWithoutIndices->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
+ m_modsWithoutIndices->setExpanded(true);
+
+
+
+ const QList<CSwordModuleInfo*> &modules(CPointers::backend()->moduleList());
+ for (MLCI it(modules.begin()); it != modules.end(); ++it) {
+ QTreeWidgetItem* item = 0;
+
+ if ((*it)->hasIndex()) {
+ item = new QTreeWidgetItem(m_modsWithIndices);
+ item->setText(0, (*it)->name());
+ item->setText(1, QString("%1 ").arg((*it)->indexSize() / 1024) + tr("KiB"));
+ item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+ item->setCheckState(0, Qt::Unchecked);
+ }
+ else {
+ item = new QTreeWidgetItem(m_modsWithoutIndices);
+ item->setText(0, (*it)->name());
+ item->setText(1, QString("0 ") + tr("KiB"));
+ item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+ item->setCheckState(0, Qt::Checked);
+ }
+ }
}
/** Creates indices for selected modules if no index currently exists */
-void BtIndexPage::createIndices()
-{
- bool indicesCreated = false;
- QList<CSwordModuleInfo*> moduleList;
-
- for (int i = 0; i < m_modsWithoutIndices->childCount(); i++) {
- if (m_modsWithoutIndices->child(i)->checkState(0) == Qt::Checked) {
- CSwordModuleInfo* module = CPointers::backend()->findModuleByName(m_modsWithoutIndices->child(i)->text(0).toUtf8());
- if (module) {
- moduleList.append( module );
- indicesCreated = true;
- }
- }
- }
-
- //Shows the progress dialog
- if (indicesCreated) {
- CModuleIndexDialog::getInstance()->indexAllModules( moduleList );
- populateModuleList();
- }
+void BtIndexPage::createIndices() {
+ bool indicesCreated = false;
+ QList<CSwordModuleInfo*> moduleList;
+
+ for (int i = 0; i < m_modsWithoutIndices->childCount(); i++) {
+ if (m_modsWithoutIndices->child(i)->checkState(0) == Qt::Checked) {
+ CSwordModuleInfo* module = CPointers::backend()->findModuleByName(m_modsWithoutIndices->child(i)->text(0).toUtf8());
+ if (module) {
+ moduleList.append( module );
+ indicesCreated = true;
+ }
+ }
+ }
+
+ //Shows the progress dialog
+ if (indicesCreated) {
+ CModuleIndexDialog::getInstance()->indexAllModules( moduleList );
+ populateModuleList();
+ }
}
/** Deletes indices for selected modules */
-void BtIndexPage::deleteIndices()
-{
- bool indicesDeleted = false;
-
- for (int i = 0; i < m_modsWithIndices->childCount(); i++) {
- if (m_modsWithIndices->child(i)->checkState(0) == Qt::Checked) {
- CSwordModuleInfo* module = CPointers::backend()->findModuleByName(m_modsWithIndices->child(i)->text(0).toUtf8());
- if (module) {
- CSwordModuleInfo::deleteIndexForModule( module->name() );
- indicesDeleted = true;
- }
- }
- }
-
- // repopulate the list if an action was taken
- if (indicesDeleted) {
- populateModuleList();
- }
+void BtIndexPage::deleteIndices() {
+ bool indicesDeleted = false;
+
+ for (int i = 0; i < m_modsWithIndices->childCount(); i++) {
+ if (m_modsWithIndices->child(i)->checkState(0) == Qt::Checked) {
+ CSwordModuleInfo* module = CPointers::backend()->findModuleByName(m_modsWithIndices->child(i)->text(0).toUtf8());
+ if (module) {
+ CSwordModuleInfo::deleteIndexForModule( module->name() );
+ indicesDeleted = true;
+ }
+ }
+ }
+
+ // repopulate the list if an action was taken
+ if (indicesDeleted) {
+ populateModuleList();
+ }
}
-void BtIndexPage::deleteOrphanedIndices()
-{
- QDir dir(CSwordModuleInfo::getGlobalBaseIndexLocation());
- dir.setFilter(QDir::Dirs);
- CSwordModuleInfo* module;
-
- for (unsigned int i = 0; i < dir.count(); i++) {
- if (dir[i] != "." && dir[i] != "..") {
- if ( (module = CPointers::backend()->findModuleByName(dir[i])) ) { //mod exists
- if (!module->hasIndex()){ //index files found, but wrong version etc.
- CSwordModuleInfo::deleteIndexForModule( dir[i] );
- }
- }
- else{ //no module exists
- if (CBTConfig::get( CBTConfig::autoDeleteOrphanedIndices ) ){
- CSwordModuleInfo::deleteIndexForModule( dir[i] );
- }
- }
- }
- }
+void BtIndexPage::deleteOrphanedIndices() {
+ QDir dir(CSwordModuleInfo::getGlobalBaseIndexLocation());
+ dir.setFilter(QDir::Dirs);
+ CSwordModuleInfo* module;
+
+ for (unsigned int i = 0; i < dir.count(); i++) {
+ if (dir[i] != "." && dir[i] != "..") {
+ if ( (module = CPointers::backend()->findModuleByName(dir[i])) ) { //mod exists
+ if (!module->hasIndex()) { //index files found, but wrong version etc.
+ CSwordModuleInfo::deleteIndexForModule( dir[i] );
+ }
+ }
+ else { //no module exists
+ if (CBTConfig::get( CBTConfig::autoDeleteOrphanedIndices ) ) {
+ CSwordModuleInfo::deleteIndexForModule( dir[i] );
+ }
+ }
+ }
+ }
}
-void BtIndexPage::slotSwordSetupChanged()
-{
- populateModuleList();
+void BtIndexPage::slotSwordSetupChanged() {
+ populateModuleList();
}
diff --git a/src/frontend/bookshelfmanager/indexpage/btindexpage.h b/src/frontend/bookshelfmanager/indexpage/btindexpage.h
index d8b49c4..139c4a7 100644
--- a/src/frontend/bookshelfmanager/indexpage/btindexpage.h
+++ b/src/frontend/bookshelfmanager/indexpage/btindexpage.h
@@ -23,64 +23,63 @@ class QTreeWidgetItem;
* Manager. It allows for creation and deletion of search indicies for each
* installed module. It also allows for deletion of orphaned indices.
*/
-class BtIndexPage : public BtConfigPage
-{
- Q_OBJECT
-
-public:
- /**
- * Constructor
- */
- BtIndexPage();
-
- /**
- * Destructor
- */
- ~BtIndexPage();
-
- // BtConfigPage methods
- QString header();
- QString iconName();
- QString label();
-
-public slots:
- void slotSwordSetupChanged();
-
-protected:
-
- /**
- * Populates the module list with installed modules and orphaned indices
- */
- void populateModuleList();
-
-
-
-public slots:
- /**
- * Creates indices for selected modules if no index currently exists
- */
- void createIndices();
- /**
- * Deletes indices for selected modules
- */
- void deleteIndices();
-
-public:
- /**
- * Deletes orphaned indices if the autoDeleteOrphanedIndices is true
- * Always deletes indices of existing modules where hasIndex() returns false
- */
- static void deleteOrphanedIndices();
-
-private:
-
- QCheckBox *m_autoDeleteOrphanedIndicesBox;
- QTreeWidget *m_moduleList;
- QPushButton *m_deleteButton;
- QPushButton *m_createButton;
-
- QTreeWidgetItem* m_modsWithIndices;
- QTreeWidgetItem* m_modsWithoutIndices;
+class BtIndexPage : public BtConfigPage {
+ Q_OBJECT
+
+ public:
+ /**
+ * Constructor
+ */
+ BtIndexPage();
+
+ /**
+ * Destructor
+ */
+ ~BtIndexPage();
+
+ // BtConfigPage methods
+ QString header();
+ QString iconName();
+ QString label();
+
+ public slots:
+ void slotSwordSetupChanged();
+
+ protected:
+
+ /**
+ * Populates the module list with installed modules and orphaned indices
+ */
+ void populateModuleList();
+
+
+
+ public slots:
+ /**
+ * Creates indices for selected modules if no index currently exists
+ */
+ void createIndices();
+ /**
+ * Deletes indices for selected modules
+ */
+ void deleteIndices();
+
+ public:
+ /**
+ * Deletes orphaned indices if the autoDeleteOrphanedIndices is true
+ * Always deletes indices of existing modules where hasIndex() returns false
+ */
+ static void deleteOrphanedIndices();
+
+ private:
+
+ QCheckBox *m_autoDeleteOrphanedIndicesBox;
+ QTreeWidget *m_moduleList;
+ QPushButton *m_deleteButton;
+ QPushButton *m_createButton;
+
+ QTreeWidgetItem* m_modsWithIndices;
+ QTreeWidgetItem* m_modsWithoutIndices;
};
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp
index 739d2ea..1668a87 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp
+++ b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.cpp
@@ -125,108 +125,106 @@
BtInstallModuleChooserDialog::BtInstallModuleChooserDialog(QWidget* parent, QString title, QString label, QList<CSwordModuleInfo*>* empty)
- : CModuleChooserDialog(parent, title, label, empty)
-{
- qDebug("BtInstallModuleChooserDialog::BtInstallModuleChooserDialog start");
- init();
- okButton()->setText(tr("Install"));
- m_nameList = QStringList();
+ : CModuleChooserDialog(parent, title, label, empty) {
+ qDebug("BtInstallModuleChooserDialog::BtInstallModuleChooserDialog start");
+ init();
+ okButton()->setText(tr("Install"));
+ m_nameList = QStringList();
}
// Do nothing, the tree is initialized outside this class.
-void BtInstallModuleChooserDialog::initModuleItem(BTModuleTreeItem*, QTreeWidgetItem*)
-{}
-
-void BtInstallModuleChooserDialog::initModuleItem(QString name, QTreeWidgetItem* sourceItem)
-{
- QTreeWidgetItem* moduleItem = new QTreeWidgetItem(sourceItem);
- moduleItem->setText(0, name);
- moduleItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
- moduleItem->setCheckState(0, Qt::Checked);
-
- // prevent double items
- if (m_nameList.contains(name)) {
- qDebug() << "item already in list:" << name;
- //moduleItem->setCheckState(0, Qt::Unchecked);
- QBrush bg(Qt::red);
- moduleItem->setBackground(0, bg);
- //find and change the other offending items
- foreach (QTreeWidgetItem* doubleItem, treeWidget()->findItems(name, Qt::MatchFixedString|Qt::MatchCaseSensitive|Qt::MatchRecursive, 0)) {
- //doubleItem->setCheckState(0, Qt::Unchecked);
- //qDebug() << "CInstallModuleChooserDialog::initModuleItem" << doubleItem;
- doubleItem->setBackground(0, bg);
- }
- m_doubleCheckedModules[name] = true;
- enableOk(false);
- }
- m_nameList << name;
+void BtInstallModuleChooserDialog::initModuleItem(BTModuleTreeItem*, QTreeWidgetItem*) {}
+
+void BtInstallModuleChooserDialog::initModuleItem(QString name, QTreeWidgetItem* sourceItem) {
+ /// \todo Use new bookshelf model instead
+ /// \bug Valgrind reports memory leak:
+ QTreeWidgetItem* moduleItem = new QTreeWidgetItem(sourceItem);
+ moduleItem->setText(0, name);
+ moduleItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+ moduleItem->setCheckState(0, Qt::Checked);
+
+ // prevent double items
+ if (m_nameList.contains(name)) {
+ qDebug() << "item already in list:" << name;
+ //moduleItem->setCheckState(0, Qt::Unchecked);
+ QBrush bg(Qt::red);
+ moduleItem->setBackground(0, bg);
+ //find and change the other offending items
+ foreach (QTreeWidgetItem* doubleItem, treeWidget()->findItems(name, Qt::MatchFixedString | Qt::MatchCaseSensitive | Qt::MatchRecursive, 0)) {
+ //doubleItem->setCheckState(0, Qt::Unchecked);
+ //qDebug() << "CInstallModuleChooserDialog::initModuleItem" << doubleItem;
+ doubleItem->setBackground(0, bg);
+ }
+ m_doubleCheckedModules[name] = true;
+ enableOk(false);
+ }
+ m_nameList << name;
}
-void BtInstallModuleChooserDialog::slotItemChecked(QTreeWidgetItem* item, int column)
-{
- QString moduleName = item->text(0);
- 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");
- item->setData(1, Qt::UserRole, true);
- } else {
- qDebug("was updating");
- item->setData(1, Qt::UserRole, false);
- return;
- }
-
- QList<QTreeWidgetItem*> doubleNameItems = findModuleItemsByName(moduleName);
- QList<QTreeWidgetItem*> doubleCheckedItems;
- foreach (QTreeWidgetItem* nItem, doubleNameItems) {
- if (nItem->checkState(0) == Qt::Checked) {
- doubleCheckedItems << nItem;
- }
- }
-
- if (doubleCheckedItems.count() > 1) {
- enableOk(false);
- // color the items
- qDebug() << "there were more than 1 item of the name" << moduleName;
- foreach (QTreeWidgetItem* i, doubleNameItems) {
- QBrush bg(Qt::red);
- i->setBackground(0, bg);
- }
- m_doubleCheckedModules[moduleName] = true;
- } else if (doubleCheckedItems.count() == 1) {
- qDebug() << "there were 1 checked items of the name" << moduleName;
- // uncolor the items
- foreach (QTreeWidgetItem* i, doubleNameItems) {
- i->setBackground(0, i->parent()->background(0));
- }
- m_doubleCheckedModules.remove(moduleName);
- if (m_doubleCheckedModules.count() == 0) {
- enableOk(true);
- }
- }
- }
+void BtInstallModuleChooserDialog::slotItemChecked(QTreeWidgetItem* item, int column) {
+ QString moduleName = item->text(0);
+ 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");
+ item->setData(1, Qt::UserRole, true);
+ }
+ else {
+ qDebug("was updating");
+ item->setData(1, Qt::UserRole, false);
+ return;
+ }
+
+ QList<QTreeWidgetItem*> doubleNameItems = findModuleItemsByName(moduleName);
+ QList<QTreeWidgetItem*> doubleCheckedItems;
+ foreach (QTreeWidgetItem* nItem, doubleNameItems) {
+ if (nItem->checkState(0) == Qt::Checked) {
+ doubleCheckedItems << nItem;
+ }
+ }
+
+ if (doubleCheckedItems.count() > 1) {
+ enableOk(false);
+ // color the items
+ qDebug() << "there were more than 1 item of the name" << moduleName;
+ foreach (QTreeWidgetItem* i, doubleNameItems) {
+ QBrush bg(Qt::red);
+ i->setBackground(0, bg);
+ }
+ m_doubleCheckedModules[moduleName] = true;
+ }
+ else if (doubleCheckedItems.count() == 1) {
+ qDebug() << "there were 1 checked items of the name" << moduleName;
+ // uncolor the items
+ foreach (QTreeWidgetItem* i, doubleNameItems) {
+ i->setBackground(0, i->parent()->background(0));
+ }
+ m_doubleCheckedModules.remove(moduleName);
+ if (m_doubleCheckedModules.count() == 0) {
+ enableOk(true);
+ }
+ }
+ }
}
-QList<QTreeWidgetItem*> BtInstallModuleChooserDialog::findModuleItemsByName(QString name)
-{
- qDebug() << "BtInstallModuleChooserDialog::findModuleItemsByName:" << name << treeWidget()->topLevelItemCount();
- QList<QTreeWidgetItem*> doubleNamedAllItems = treeWidget()->findItems(name, Qt::MatchFixedString|Qt::MatchCaseSensitive|Qt::MatchRecursive);
- //qDebug() << "doubleNamedAllItems: " << doubleNamedAllItems.count();
- QList<QTreeWidgetItem*> doubleNamedModuleItems;
- foreach (QTreeWidgetItem* item, doubleNamedAllItems) {
- //qDebug() << "item:" << item;
- if (item->parent()) {
- doubleNamedModuleItems << item;
- }
- }
- //qDebug() << "module items:" << doubleNamedModuleItems.count();
- return doubleNamedModuleItems;
+QList<QTreeWidgetItem*> BtInstallModuleChooserDialog::findModuleItemsByName(QString name) {
+ qDebug() << "BtInstallModuleChooserDialog::findModuleItemsByName:" << name << treeWidget()->topLevelItemCount();
+ QList<QTreeWidgetItem*> doubleNamedAllItems = treeWidget()->findItems(name, Qt::MatchFixedString | Qt::MatchCaseSensitive | Qt::MatchRecursive);
+ //qDebug() << "doubleNamedAllItems: " << doubleNamedAllItems.count();
+ QList<QTreeWidgetItem*> doubleNamedModuleItems;
+ foreach (QTreeWidgetItem* item, doubleNamedAllItems) {
+ //qDebug() << "item:" << item;
+ if (item->parent()) {
+ doubleNamedModuleItems << item;
+ }
+ }
+ //qDebug() << "module items:" << doubleNamedModuleItems.count();
+ return doubleNamedModuleItems;
}
-void BtInstallModuleChooserDialog::enableOk(bool enabled)
-{
- qDebug() << "BtInstallModuleChooserDialog::enableOk" << enabled;
- okButton()->setEnabled(enabled);
+void BtInstallModuleChooserDialog::enableOk(bool enabled) {
+ qDebug() << "BtInstallModuleChooserDialog::enableOk" << enabled;
+ okButton()->setEnabled(enabled);
}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h
index 39b8a96..788dbf5 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h
+++ b/src/frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h
@@ -27,26 +27,25 @@ class QTreeWidgetItem;
* Confirmation dialog for installation. Lets the user
* uncheck modules from the list.
*/
-class BtInstallModuleChooserDialog : public CModuleChooserDialog
-{
- Q_OBJECT
+class BtInstallModuleChooserDialog : public CModuleChooserDialog {
+ Q_OBJECT
-public:
- BtInstallModuleChooserDialog(QWidget* parent, QString title, QString label, QList<CSwordModuleInfo*>* empty);
+ public:
+ BtInstallModuleChooserDialog(QWidget* parent, QString title, QString label, QList<CSwordModuleInfo*>* empty);
- void initModuleItem(QString name, QTreeWidgetItem* sourceItem);
- void enableOk(bool enabled);
+ void initModuleItem(QString name, QTreeWidgetItem* sourceItem);
+ void enableOk(bool enabled);
-public slots:
- void slotItemChecked(QTreeWidgetItem* item, int column);
+ public slots:
+ void slotItemChecked(QTreeWidgetItem* item, int column);
-protected:
- virtual void initModuleItem(BTModuleTreeItem*, QTreeWidgetItem*);
+ protected:
+ virtual void initModuleItem(BTModuleTreeItem*, QTreeWidgetItem*);
- QList<QTreeWidgetItem*> findModuleItemsByName(QString name);
-private:
- QStringList m_nameList;
- QMap<QString, bool> m_doubleCheckedModules;
+ QList<QTreeWidgetItem*> findModuleItemsByName(QString name);
+ private:
+ QStringList m_nameList;
+ QMap<QString, bool> m_doubleCheckedModules;
};
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp b/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp
index 9f8e6b9..4fe9c41 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp
+++ b/src/frontend/bookshelfmanager/installpage/btinstallpage.cpp
@@ -67,135 +67,126 @@
// *********************************************************
BtInstallPage::BtInstallPage()
- : BtConfigPage()
-{
- qDebug("BtInstallPage::BtInstallPage() start");
- initView();
- initConnections();
+ : BtConfigPage() {
+ qDebug("BtInstallPage::BtInstallPage() start");
+ initView();
+ initConnections();
}
-void BtInstallPage::setInstallEnabled(bool b)
-{
- qDebug("void BtInstallPage::setInstallEnabled(bool b) start");
- m_installButton->setEnabled(b);
+void BtInstallPage::setInstallEnabled(bool b) {
+ qDebug("void BtInstallPage::setInstallEnabled(bool b) start");
+ m_installButton->setEnabled(b);
}
-QString BtInstallPage::selectedInstallPath()
-{
- return m_pathCombo->currentText();
+QString BtInstallPage::selectedInstallPath() {
+ return m_pathCombo->currentText();
}
-void BtInstallPage::initView()
-{
- qDebug("void BtInstallPage::initView() start");
- QVBoxLayout *mainLayout = new QVBoxLayout(this);
-
- // installation path chooser
- QHBoxLayout* pathLayout = new QHBoxLayout();
- // beautify the layout
- int top; int bottom; int left; 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:"));
- m_pathCombo = new QComboBox();
- m_pathCombo->setToolTip(tr("The path where the new works will be installed"));
- 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));
-
- 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
- QHBoxLayout *installButtonLayout = new QHBoxLayout();
- installButtonLayout->setContentsMargins(0,5,0,5);
- QSpacerItem *installButtonSpacer = new QSpacerItem(371, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
- 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->setEnabled(false);
- installButtonLayout->addWidget(m_installButton);
-
- mainLayout->addLayout(installButtonLayout);
+void BtInstallPage::initView() {
+ qDebug("void BtInstallPage::initView() start");
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+
+ // installation path chooser
+ QHBoxLayout* pathLayout = new QHBoxLayout();
+ // beautify the layout
+ int top;
+ int bottom;
+ int left;
+ 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:"));
+ m_pathCombo = new QComboBox();
+ m_pathCombo->setToolTip(tr("The path where the new works will be installed"));
+ 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));
+
+ 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
+ QHBoxLayout *installButtonLayout = new QHBoxLayout();
+ installButtonLayout->setContentsMargins(0, 5, 0, 5);
+ QSpacerItem *installButtonSpacer = new QSpacerItem(371, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
+ 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->setEnabled(false);
+ installButtonLayout->addWidget(m_installButton);
+
+ mainLayout->addLayout(installButtonLayout);
}
-void BtInstallPage::initConnections()
-{
- 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()) );
+void BtInstallPage::initConnections() {
+ 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()) );
- QObject::connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), this, SLOT(slotSwordSetupChanged()));
- //source widget has its own connections, not here
+ QObject::connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), this, SLOT(slotSwordSetupChanged()));
+ //source widget has its own connections, not here
}
-void BtInstallPage::initPathCombo()
-{
- 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) {
- if ((*it).isEmpty()) continue;
- m_pathCombo->addItem(*it);
- }
-
- // choose the current value from config but check whether we have so many items
- int configValue = CBTConfig::get(CBTConfig::installPathIndex);
- int index = configValue > (m_pathCombo->count()-1) ? m_pathCombo->count()-1 : configValue;
- m_pathCombo->setCurrentIndex(index);
+void BtInstallPage::initPathCombo() {
+ 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) {
+ if ((*it).isEmpty()) continue;
+ m_pathCombo->addItem(*it);
+ }
+
+ // choose the current value from config but check whether we have so many items
+ int configValue = CBTConfig::get(CBTConfig::installPathIndex);
+ int index = configValue > (m_pathCombo->count() - 1) ? m_pathCombo->count() - 1 : configValue;
+ m_pathCombo->setCurrentIndex(index);
}
-void BtInstallPage::slotPathChanged(const QString& /*pathText*/)
-{
- CBTConfig::set(CBTConfig::installPathIndex, m_pathCombo->currentIndex( ) );
+void BtInstallPage::slotPathChanged(const QString& /*pathText*/) {
+ CBTConfig::set(CBTConfig::installPathIndex, m_pathCombo->currentIndex( ) );
}
-void BtInstallPage::slotEditPaths()
-{
- qDebug("void BtInstallPage::slotEditPaths() start");
-
- BtInstallPathDialog* dlg = new BtInstallPathDialog();
- int result = dlg->exec();
- if (result == QDialog::Accepted) {
- //dynamic_cast<BtModuleManagerDialog*>(parentDialog())->slotSwordSetupChanged();
- CPointers::backend()->reloadModules(CSwordBackend::PathChanged);
- }
+void BtInstallPage::slotEditPaths() {
+ qDebug("void BtInstallPage::slotEditPaths() start");
+
+ BtInstallPathDialog* dlg = new BtInstallPathDialog();
+ int result = dlg->exec();
+ if (result == QDialog::Accepted) {
+ //dynamic_cast<BtModuleManagerDialog*>(parentDialog())->slotSwordSetupChanged();
+ CPointers::backend()->reloadModules(CSwordBackend::PathChanged);
+ }
}
// implement the BtConfigPage methods
-QString BtInstallPage::iconName()
-{
- return CResMgr::bookshelfmgr::installpage::icon;
+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.
- 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::label() {
+ // 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()
-{
- return tr("Install/Update");
+QString BtInstallPage::header() {
+ return tr("Install/Update");
}
-void BtInstallPage::slotSwordSetupChanged()
-{
- qDebug() << "BtInstallPage::slotSwordSetupChanged";
- initPathCombo();
+void BtInstallPage::slotSwordSetupChanged() {
+ qDebug() << "BtInstallPage::slotSwordSetupChanged";
+ initPathCombo();
// for (int i = 0; i < m_sourceWidget->count(); i++ ) {
// BtSourceArea* sourceArea = dynamic_cast<BtSourceArea*>(m_sourceWidget->widget(i));
// Q_ASSERT(sourceArea);
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpage.h b/src/frontend/bookshelfmanager/installpage/btinstallpage.h
index 4d05577..41493f8 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallpage.h
+++ b/src/frontend/bookshelfmanager/installpage/btinstallpage.h
@@ -27,40 +27,39 @@ class QToolButton;
/**
* The Install page includes module path chooser, source/module handler and install button.
*/
-class BtInstallPage : public BtConfigPage
-{
- Q_OBJECT
-public:
- BtInstallPage();
-
- // reimplemented from btinstallpage
- QString iconName();
- QString label();
- QString header();
-
- void setInstallEnabled(bool b);
-
- QString selectedInstallPath();
-
-public slots:
- void slotSwordSetupChanged();
-
-private:
- void initView();
- void initConnections();
- void initPathCombo();
-
-private slots:
- void slotPathChanged(const QString& pathText);
- void slotEditPaths();
-
-private:
-
- QComboBox* m_pathCombo;
- //QPushButton* m_configurePathButton;
- QToolButton* m_configurePathButton;
- BtSourceWidget* m_sourceWidget;
- QPushButton* m_installButton;
+class BtInstallPage : public BtConfigPage {
+ Q_OBJECT
+ public:
+ BtInstallPage();
+
+ // reimplemented from btinstallpage
+ QString iconName();
+ QString label();
+ QString header();
+
+ void setInstallEnabled(bool b);
+
+ QString selectedInstallPath();
+
+ public slots:
+ void slotSwordSetupChanged();
+
+ private:
+ void initView();
+ void initConnections();
+ void initPathCombo();
+
+ private slots:
+ void slotPathChanged(const QString& pathText);
+ void slotEditPaths();
+
+ private:
+
+ QComboBox* m_pathCombo;
+ //QPushButton* m_configurePathButton;
+ QToolButton* m_configurePathButton;
+ BtSourceWidget* m_sourceWidget;
+ QPushButton* m_installButton;
};
#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp
index 82b8362..27b3d3a 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp
+++ b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.cpp
@@ -31,140 +31,137 @@
#include <QDebug>
-BtInstallPathDialog::BtInstallPathDialog()
-{
- setWindowTitle(tr("Bookshelf Paths"));
-
- QVBoxLayout *mainLayout;
- QHBoxLayout *viewLayout;
-
- 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.");
-
- QLabel* mainLabel = CToolClass::explanationLabel(this,
- tr("Configure bookshelf paths"), 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);
- confPathLabel->setWordWrap(true);
- mainLayout->addWidget(confPathLabel);
-
-
- m_swordPathListBox = new QTreeWidget(this);
- m_swordPathListBox->header()->hide();
-
- QDir swordDir = instbackend::swordDir();
- QStringList targets = instbackend::targetList();
- foreach (QString pathname, targets) {
- if (pathname.isEmpty() || QDir(pathname) == swordDir) continue;
- new QTreeWidgetItem(m_swordPathListBox, QStringList(pathname) );
- }
-
- 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));
- 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));
- 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));
- connect(m_removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveClicked()));
- buttonLayout->addWidget(m_removeButton);
-
- QSpacerItem* spacerItem = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
- buttonLayout->addItem(spacerItem);
-
- viewLayout->addLayout(buttonLayout);
- mainLayout->addLayout(viewLayout);
-
- QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
- buttonBox->setOrientation(Qt::Horizontal);
- buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok);
- util::prepareDialogBox(buttonBox);
- mainLayout->addWidget(buttonBox);
- connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
- connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+BtInstallPathDialog::BtInstallPathDialog() {
+ setWindowTitle(tr("Bookshelf Paths"));
+
+ QVBoxLayout *mainLayout;
+ QHBoxLayout *viewLayout;
+
+ 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.");
+
+ QLabel* mainLabel = CToolClass::explanationLabel(this,
+ tr("Configure bookshelf paths"), 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);
+ confPathLabel->setWordWrap(true);
+ mainLayout->addWidget(confPathLabel);
+
+
+ m_swordPathListBox = new QTreeWidget(this);
+ m_swordPathListBox->header()->hide();
+
+ QDir swordDir = instbackend::swordDir();
+ QStringList targets = instbackend::targetList();
+ foreach (QString pathname, targets) {
+ if (pathname.isEmpty() || QDir(pathname) == swordDir) continue;
+ new QTreeWidgetItem(m_swordPathListBox, QStringList(pathname) );
+ }
+
+ 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));
+ 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));
+ 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));
+ connect(m_removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveClicked()));
+ buttonLayout->addWidget(m_removeButton);
+
+ QSpacerItem* spacerItem = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
+ buttonLayout->addItem(spacerItem);
+
+ viewLayout->addLayout(buttonLayout);
+ mainLayout->addLayout(viewLayout);
+
+ QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
+ buttonBox->setOrientation(Qt::Horizontal);
+ buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::NoButton | QDialogButtonBox::Ok);
+ util::prepareDialogBox(buttonBox);
+ mainLayout->addWidget(buttonBox);
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
}
void BtInstallPathDialog::slotEditClicked() {
- if (QTreeWidgetItem* i = m_swordPathListBox->currentItem()) {
- QString dirname = QFileDialog::getExistingDirectory(this, tr("Choose directory"), i->text(0), QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks);
-
- if (dirname.isEmpty()) { // if user cancelled the dialog
- return;
- }
- QDir dir = QDir(dirname);
- 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);
- if (result != QMessageBox::Yes) return;
- }
- i->setText(0, dir.absolutePath()); // absolute, not canonical
- }
- }
+ if (QTreeWidgetItem* i = m_swordPathListBox->currentItem()) {
+ QString dirname = QFileDialog::getExistingDirectory(this, tr("Choose directory"), i->text(0), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
+
+ if (dirname.isEmpty()) { // if user cancelled the dialog
+ return;
+ }
+ QDir dir = QDir(dirname);
+ 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);
+ if (result != QMessageBox::Yes) return;
+ }
+ i->setText(0, dir.absolutePath()); // absolute, not canonical
+ }
+ }
}
void BtInstallPathDialog::slotAddClicked() {
- QString dirname = QFileDialog::getExistingDirectory(this, tr("Choose directory"), "", QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks);
- if (dirname.isEmpty()) { // if user cancelled the dialog
- return;
- }
- QDir dir = QDir(dirname);
- 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);
- if (result != QMessageBox::Yes) {
- return;
- }
- }
- new QTreeWidgetItem(m_swordPathListBox, QStringList(dir.canonicalPath()) );
- }
+ QString dirname = QFileDialog::getExistingDirectory(this, tr("Choose directory"), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
+ if (dirname.isEmpty()) { // if user cancelled the dialog
+ return;
+ }
+ QDir dir = QDir(dirname);
+ 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);
+ if (result != QMessageBox::Yes) {
+ return;
+ }
+ }
+ new QTreeWidgetItem(m_swordPathListBox, QStringList(dir.canonicalPath()) );
+ }
}
void BtInstallPathDialog::slotRemoveClicked() {
- QTreeWidgetItem* i = m_swordPathListBox->currentItem();
- if (i) {
- delete i;
- }
+ QTreeWidgetItem* i = m_swordPathListBox->currentItem();
+ if (i) {
+ delete i;
+ }
}
-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() << "save the target list" << targets;
- instbackend::setTargetList(targets); //creates new Sword config
- }
+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() << "save the target list" << targets;
+ instbackend::setTargetList(targets); //creates new Sword config
+ }
}
-void BtInstallPathDialog::accept()
-{
- writeSwordConfig();
- QDialog::accept();
+void BtInstallPathDialog::accept() {
+ writeSwordConfig();
+ QDialog::accept();
}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h
index c3b56ac..b2f18a1 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h
+++ b/src/frontend/bookshelfmanager/installpage/btinstallpathdialog.h
@@ -16,28 +16,27 @@ class QPushButton;
class QTreeWidget;
-class BtInstallPathDialog : public QDialog
-{
- Q_OBJECT
-public:
- BtInstallPathDialog();
-
-public slots:
- virtual void accept();
-
-private slots:
- void slotAddClicked();
- void slotRemoveClicked();
- void slotEditClicked();
-
-private:
- void writeSwordConfig();
-
-private:
- QPushButton* m_editButton;
- QPushButton* m_addButton;
- QPushButton* m_removeButton;
- QTreeWidget* m_swordPathListBox;
+class BtInstallPathDialog : public QDialog {
+ Q_OBJECT
+ public:
+ BtInstallPathDialog();
+
+ public slots:
+ virtual void accept();
+
+ private slots:
+ void slotAddClicked();
+ void slotRemoveClicked();
+ void slotEditClicked();
+
+ private:
+ void writeSwordConfig();
+
+ private:
+ QPushButton* m_editButton;
+ QPushButton* m_addButton;
+ QPushButton* m_removeButton;
+ QTreeWidget* m_swordPathListBox;
};
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp
index 2f60fc9..7883220 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp
+++ b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.cpp
@@ -30,79 +30,77 @@
BtInstallProgressDialog::BtInstallProgressDialog(QWidget* parent, QTreeWidget* selectedModulesTreeWidget, QString destination)
- : QDialog(parent)
-{
- // we want this dialog to be deleted when user closes it or the downloads are completed
- setAttribute(Qt::WA_DeleteOnClose, true);
- setWindowTitle(tr("Install Progress"));
- //create the dialog which shows the status and lets the user stop installation
- m_statusWidget = new QTreeWidget();
- m_statusWidget->setRootIsDecorated(false);
- m_statusWidget->setHeaderLabels(QStringList(tr("Work")) << tr("Progress") << QString::null);
- 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));
-
- foreach (QTreeWidgetItem* sourceItem, selectedModulesTreeWidget->invisibleRootItem()->takeChildren()) {
- // create items and threads for modules under this source
- foreach (QTreeWidgetItem* moduleItem, sourceItem->takeChildren()) {
- if (moduleItem->checkState(0) == Qt::Checked) {
- // create a thread for this module
- BtInstallThread* thread = new BtInstallThread(this, moduleItem->text(0), sourceItem->text(0), destination);
- m_waitingThreads.insert(sourceItem->text(0), thread);
- m_threadsByModule.insert(moduleItem->text(0), thread);
- // progress widget/item
- QPushButton* stopButton = new QPushButton(tr("Stop"), m_statusWidget);
- stopButton->setFixedSize(stopButton->sizeHint());
-
- // the item
- QTreeWidgetItem* progressItem = new QTreeWidgetItem(m_statusWidget);
- m_statusWidget->setColumnWidth(2, stopButton->sizeHint().width());
- progressItem->setSizeHint(2, stopButton->sizeHint());
- progressItem->setText(0, moduleItem->text(0));
- progressItem->setFlags(Qt::ItemIsEnabled);
- m_statusWidget->setItemWidget(progressItem, 2, stopButton);
- progressItem->setText(1, tr("Waiting for turn..."));
-
- //connect the signals between the dialog, items and threads
- QObject::connect(stopButton, SIGNAL(clicked()), thread, SLOT(slotStopInstall()), Qt::QueuedConnection);
- QObject::connect(thread, SIGNAL(installStopped(QString, QString)), this, SLOT(slotOneItemStopped(QString, QString)), Qt::QueuedConnection);
- //is this needed or is statusUpdated enough?
- QObject::connect(thread, SIGNAL(installCompleted(QString, QString, int)), this, SLOT(slotOneItemCompleted(QString, QString, int)), Qt::QueuedConnection);
- QObject::connect(thread, SIGNAL(statusUpdated(QString, int)), this, SLOT(slotStatusUpdated(QString, int)), Qt::QueuedConnection);
- QObject::connect(thread, SIGNAL(downloadStarted(QString)), this, SLOT(slotDownloadStarted(QString)), Qt::QueuedConnection);
-
- QObject::connect(thread, SIGNAL(preparingInstall(QString, QString)), this, SLOT(slotInstallStarted(QString, QString)), Qt::QueuedConnection);
-
- }
- }
- }
-
- m_statusWidget->setMinimumWidth(m_statusWidget->size().width());
- QPushButton* stopAllButton = new QPushButton(tr("Stop All"), this);
-
- QVBoxLayout* layout = new QVBoxLayout(this);
- layout->addWidget(m_statusWidget);
- layout->addWidget(stopAllButton);
-
- connect(stopAllButton, SIGNAL(clicked()), SLOT(slotStopInstall()) );
-
- qApp->processEvents();
-
- startThreads();
+ : QDialog(parent) {
+ // we want this dialog to be deleted when user closes it or the downloads are completed
+ setAttribute(Qt::WA_DeleteOnClose, true);
+ setWindowTitle(tr("Install Progress"));
+ //create the dialog which shows the status and lets the user stop installation
+ m_statusWidget = new QTreeWidget();
+ m_statusWidget->setRootIsDecorated(false);
+ m_statusWidget->setHeaderLabels(QStringList(tr("Work")) << tr("Progress") << QString::null);
+ 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));
+
+ foreach (QTreeWidgetItem* sourceItem, selectedModulesTreeWidget->invisibleRootItem()->takeChildren()) {
+ // create items and threads for modules under this source
+ foreach (QTreeWidgetItem* moduleItem, sourceItem->takeChildren()) {
+ if (moduleItem->checkState(0) == Qt::Checked) {
+ // create a thread for this module
+ BtInstallThread* thread = new BtInstallThread(this, moduleItem->text(0), sourceItem->text(0), destination);
+ m_waitingThreads.insert(sourceItem->text(0), thread);
+ m_threadsByModule.insert(moduleItem->text(0), thread);
+ // progress widget/item
+ QPushButton* stopButton = new QPushButton(tr("Stop"), m_statusWidget);
+ stopButton->setFixedSize(stopButton->sizeHint());
+
+ // the item
+ QTreeWidgetItem* progressItem = new QTreeWidgetItem(m_statusWidget);
+ m_statusWidget->setColumnWidth(2, stopButton->sizeHint().width());
+ progressItem->setSizeHint(2, stopButton->sizeHint());
+ progressItem->setText(0, moduleItem->text(0));
+ progressItem->setFlags(Qt::ItemIsEnabled);
+ m_statusWidget->setItemWidget(progressItem, 2, stopButton);
+ progressItem->setText(1, tr("Waiting for turn..."));
+
+ //connect the signals between the dialog, items and threads
+ QObject::connect(stopButton, SIGNAL(clicked()), thread, SLOT(slotStopInstall()), Qt::QueuedConnection);
+ QObject::connect(thread, SIGNAL(installStopped(QString, QString)), this, SLOT(slotOneItemStopped(QString, QString)), Qt::QueuedConnection);
+ //is this needed or is statusUpdated enough?
+ QObject::connect(thread, SIGNAL(installCompleted(QString, QString, int)), this, SLOT(slotOneItemCompleted(QString, QString, int)), Qt::QueuedConnection);
+ QObject::connect(thread, SIGNAL(statusUpdated(QString, int)), this, SLOT(slotStatusUpdated(QString, int)), Qt::QueuedConnection);
+ QObject::connect(thread, SIGNAL(downloadStarted(QString)), this, SLOT(slotDownloadStarted(QString)), Qt::QueuedConnection);
+
+ QObject::connect(thread, SIGNAL(preparingInstall(QString, QString)), this, SLOT(slotInstallStarted(QString, QString)), Qt::QueuedConnection);
+
+ }
+ }
+ }
+
+ m_statusWidget->setMinimumWidth(m_statusWidget->size().width());
+ QPushButton* stopAllButton = new QPushButton(tr("Stop All"), this);
+
+ QVBoxLayout* layout = new QVBoxLayout(this);
+ layout->addWidget(m_statusWidget);
+ layout->addWidget(stopAllButton);
+
+ connect(stopAllButton, SIGNAL(clicked()), SLOT(slotStopInstall()) );
+
+ qApp->processEvents();
+
+ startThreads();
}
-void BtInstallProgressDialog::startThreads()
-{
- // remove all the updated modules from the backend module list at once
- //foreach (QString mName, m_threadsByModule.keys()) {
- //}
- //QList<CSwordModuleInfo*> CPointers::backend()->takeModulesFromList(m_threadsByModule.keys());
- qDebug() << "start threads...";
- //loop through the multimap of the waiting threads, start at most 3 threads for each source
- QMultiMap<QString, BtInstallThread*>::iterator threadIterator = m_waitingThreads.end();
+void BtInstallProgressDialog::startThreads() {
+ // remove all the updated modules from the backend module list at once
+ //foreach (QString mName, m_threadsByModule.keys()) {
+ //}
+ //QList<CSwordModuleInfo*> CPointers::backend()->takeModulesFromList(m_threadsByModule.keys());
+ qDebug() << "start threads...";
+ //loop through the multimap of the waiting threads, start at most 3 threads for each source
+ QMultiMap<QString, BtInstallThread*>::iterator threadIterator = m_waitingThreads.end();
// concurrency is disabled for now
// while (threadIterator != m_waitingThreads.end()) {
// QString sourceName = threadIterator.key();
@@ -115,55 +113,51 @@ void BtInstallProgressDialog::startThreads()
// }
// else ++threadIterator;
// }
- //non-concurrent
- if (threadIterator != m_waitingThreads.begin()) {
- // go to the last item which is actually the first in the visible list
- // because the iterator is reversed compared to insert order
- threadIterator--;
- QString sourceName = threadIterator.key();
- BtInstallThread* t = threadIterator.value();
- m_runningThreads.insert(sourceName, t);
- threadIterator = m_waitingThreads.erase(threadIterator);
- t->start();
- }
-
- qDebug("BtInstallProgressDialog::startThreads end");
+ //non-concurrent
+ if (threadIterator != m_waitingThreads.begin()) {
+ // go to the last item which is actually the first in the visible list
+ // because the iterator is reversed compared to insert order
+ threadIterator--;
+ QString sourceName = threadIterator.key();
+ BtInstallThread* t = threadIterator.value();
+ m_runningThreads.insert(sourceName, t);
+ threadIterator = m_waitingThreads.erase(threadIterator);
+ t->start();
+ }
+
+ qDebug("BtInstallProgressDialog::startThreads end");
}
-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.
- if (status != 0) {
- message = tr("Failed");
- }
- else {
- message = tr("Completed");
- }
- oneItemStoppedOrCompleted(module, source, message);
+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.
+ if (status != 0) {
+ message = tr("Failed");
+ }
+ else {
+ message = tr("Completed");
+ }
+ oneItemStoppedOrCompleted(module, source, message);
}
-void BtInstallProgressDialog::slotOneItemStopped(QString module, QString source)
-{
- oneItemStoppedOrCompleted(module, source, tr("Cancelled"));
+void BtInstallProgressDialog::slotOneItemStopped(QString module, QString source) {
+ oneItemStoppedOrCompleted(module, source, tr("Cancelled"));
}
-void BtInstallProgressDialog::oneItemStoppedOrCompleted(QString module, QString source, QString statusMessage)
-{
- qDebug() << "\n**********************************\nBtInstallProgressDialog::oneItemStoppedOrCompleted" << module << statusMessage << "\n******************************************";
- // update the list item
- m_statusWidget->setItemWidget(getItem(module), 1, 0);
- getItem(module)->setText(1, statusMessage);
- m_statusWidget->itemWidget(getItem(module), 2)->setEnabled(false);
- getItem(module)->setDisabled(true);
+void BtInstallProgressDialog::oneItemStoppedOrCompleted(QString module, QString source, QString statusMessage) {
+ qDebug() << "\n**********************************\nBtInstallProgressDialog::oneItemStoppedOrCompleted" << module << statusMessage << "\n******************************************";
+ // update the list item
+ m_statusWidget->setItemWidget(getItem(module), 1, 0);
+ getItem(module)->setText(1, statusMessage);
+ m_statusWidget->itemWidget(getItem(module), 2)->setEnabled(false);
+ getItem(module)->setDisabled(true);
- qDebug() << "remove from threads maps" << source << m_threadsByModule.value(module);
- m_runningThreads.remove(source, m_threadsByModule.value(module));
- m_waitingThreads.remove(source, m_threadsByModule.value(module));
+ qDebug() << "remove from threads maps" << source << m_threadsByModule.value(module);
+ m_runningThreads.remove(source, m_threadsByModule.value(module));
+ m_waitingThreads.remove(source, m_threadsByModule.value(module));
//concurrency is disabled for now
// //start a waiting thread if there are any
@@ -177,85 +171,79 @@ void BtInstallProgressDialog::oneItemStoppedOrCompleted(QString module, QString
// thread->start();
// }
- //non-concurrent
- QMultiMap<QString, BtInstallThread*>::iterator threadIterator = m_waitingThreads.end();
- if (m_runningThreads.size() == 0 && threadIterator != m_waitingThreads.begin()) {
- threadIterator--; // the last item
- QString sourceName = threadIterator.key();
- BtInstallThread* t = threadIterator.value();
- m_runningThreads.insert(sourceName, t);
- threadIterator = m_waitingThreads.erase(threadIterator);
- t->start();
- }
-
- if (threadsDone()) {
- qDebug() << "close the dialog";
- close();
- }
+ //non-concurrent
+ QMultiMap<QString, BtInstallThread*>::iterator threadIterator = m_waitingThreads.end();
+ if (m_runningThreads.size() == 0 && threadIterator != m_waitingThreads.begin()) {
+ threadIterator--; // the last item
+ QString sourceName = threadIterator.key();
+ BtInstallThread* t = threadIterator.value();
+ m_runningThreads.insert(sourceName, t);
+ threadIterator = m_waitingThreads.erase(threadIterator);
+ t->start();
+ }
+
+ if (threadsDone()) {
+ qDebug() << "close the dialog";
+ close();
+ }
}
-void BtInstallProgressDialog::slotStopInstall()
-{
- qDebug("BtInstallProgressDialog::slotStopInstall");
+void BtInstallProgressDialog::slotStopInstall() {
+ qDebug("BtInstallProgressDialog::slotStopInstall");
- // Clear the waiting threads map, stop all running threads.
+ // Clear the waiting threads map, stop all running threads.
- m_waitingThreads.clear();
- if (m_runningThreads.count() > 0) {
- foreach(BtInstallThread* thread, m_runningThreads) {
- thread->slotStopInstall();
- }
- } else {
- close();
- }
+ m_waitingThreads.clear();
+ if (m_runningThreads.count() > 0) {
+ foreach(BtInstallThread* thread, m_runningThreads) {
+ thread->slotStopInstall();
+ }
+ }
+ else {
+ close();
+ }
}
-void BtInstallProgressDialog::slotStatusUpdated(QString module, int status)
-{
- //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);
- QProgressBar* bar = dynamic_cast<QProgressBar*>(itemWidget);
- if (bar) bar->setValue(status);
+void BtInstallProgressDialog::slotStatusUpdated(QString module, int status) {
+ //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);
+ QProgressBar* bar = dynamic_cast<QProgressBar*>(itemWidget);
+ if (bar) bar->setValue(status);
}
-void BtInstallProgressDialog::slotInstallStarted(QString module, QString)
-{
- getItem(module)->setText(1, tr("Preparing install..."));
+void BtInstallProgressDialog::slotInstallStarted(QString module, QString) {
+ getItem(module)->setText(1, tr("Preparing install..."));
}
-void BtInstallProgressDialog::slotDownloadStarted(QString module)
-{
- qDebug() << "BtInstallProgressDialog::slotDownloadStarted" << module;
- getItem(module)->setText(1, QString::null);
- //m_statusWidget->itemWidget(getItem(module), 1)->setVisible(true);
+void BtInstallProgressDialog::slotDownloadStarted(QString module) {
+ qDebug() << "BtInstallProgressDialog::slotDownloadStarted" << module;
+ getItem(module)->setText(1, QString::null);
+ //m_statusWidget->itemWidget(getItem(module), 1)->setVisible(true);
- QProgressBar* bar = new QProgressBar(m_statusWidget);
- bar->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
- bar->setValue(0);
- m_statusWidget->setItemWidget(getItem(module), 1, bar);
+ QProgressBar* bar = new QProgressBar(m_statusWidget);
+ bar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+ bar->setValue(0);
+ m_statusWidget->setItemWidget(getItem(module), 1, bar);
}
-QTreeWidgetItem* BtInstallProgressDialog::getItem(QString moduleName)
-{
- //qDebug() << "BtInstallProgressDialog::getItem" << moduleName;
- return m_statusWidget->findItems(moduleName, Qt::MatchExactly).at(0);
+QTreeWidgetItem* BtInstallProgressDialog::getItem(QString moduleName) {
+ //qDebug() << "BtInstallProgressDialog::getItem" << moduleName;
+ return m_statusWidget->findItems(moduleName, Qt::MatchExactly).at(0);
}
-void BtInstallProgressDialog::closeEvent(QCloseEvent* event)
-{
- qDebug("BtInstallProgressDialog::closeEvent");
-
- if (event->spontaneous()) {
- event->ignore();
- return;
- }
- // other parts of the UI/engine must be updated
- CPointers::backend()->reloadModules(CSwordBackend::AddedModules);
+void BtInstallProgressDialog::closeEvent(QCloseEvent* event) {
+ qDebug("BtInstallProgressDialog::closeEvent");
+
+ if (event->spontaneous()) {
+ event->ignore();
+ return;
+ }
+ // other parts of the UI/engine must be updated
+ CPointers::backend()->reloadModules(CSwordBackend::AddedModules);
}
-bool BtInstallProgressDialog::threadsDone()
-{
- return (m_waitingThreads.count() == 0 && m_runningThreads.count() == 0);
+bool BtInstallProgressDialog::threadsDone() {
+ return (m_waitingThreads.count() == 0 && m_runningThreads.count() == 0);
}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h
index 67aa8fb..79c6331 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h
+++ b/src/frontend/bookshelfmanager/installpage/btinstallprogressdialog.h
@@ -23,48 +23,47 @@ class BtInstallThread;
/**
*/
-class BtInstallProgressDialog : public QDialog
-{
- Q_OBJECT
-public:
- BtInstallProgressDialog(QWidget* parent, QTreeWidget* selectedModulesTreeWidget, QString destination);
-
- ~BtInstallProgressDialog();
-
-public slots:
- void slotOneItemCompleted(QString module, QString source, int status);
- void slotOneItemStopped(QString module, QString source);
- void slotStopInstall();
- void slotStatusUpdated(QString module, int status);
- void slotDownloadStarted(QString module);
- void slotInstallStarted(QString module, QString);
-
-protected:
- /**
- * Handles closing by the window close button, Cancel (Stop) All button, or completing
- * the downloads.
- */
- virtual void closeEvent(QCloseEvent* event);
+class BtInstallProgressDialog : public QDialog {
+ Q_OBJECT
+ public:
+ BtInstallProgressDialog(QWidget* parent, QTreeWidget* selectedModulesTreeWidget, QString destination);
+
+ ~BtInstallProgressDialog();
+
+ public slots:
+ void slotOneItemCompleted(QString module, QString source, int status);
+ void slotOneItemStopped(QString module, QString source);
+ void slotStopInstall();
+ void slotStatusUpdated(QString module, int status);
+ void slotDownloadStarted(QString module);
+ void slotInstallStarted(QString module, QString);
+
+ protected:
+ /**
+ * Handles closing by the window close button, Cancel (Stop) All button, or completing
+ * the downloads.
+ */
+ virtual void closeEvent(QCloseEvent* event);
//signals:
// void swordSetupChanged();
-private:
+ private:
- //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;
- QMap<QString, BtInstallThread*> m_threadsByModule;
- //QList<BtInstallThread*> m_doneThreads;
+ //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;
+ QMap<QString, BtInstallThread*> m_threadsByModule;
+ //QList<BtInstallThread*> m_doneThreads;
- QTreeWidget* m_statusWidget;
+ QTreeWidget* m_statusWidget;
-private:
- QTreeWidgetItem* getItem(QString moduleName);
- bool threadsDone();
- void startThreads();
- void oneItemStoppedOrCompleted(QString module, QString source, QString message);
+ private:
+ QTreeWidgetItem* getItem(QString moduleName);
+ bool threadsDone();
+ void startThreads();
+ void oneItemStoppedOrCompleted(QString module, QString source, QString message);
};
#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallthread.cpp b/src/frontend/bookshelfmanager/installpage/btinstallthread.cpp
index d2570ff..48e38ce 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallthread.cpp
+++ b/src/frontend/bookshelfmanager/installpage/btinstallthread.cpp
@@ -25,176 +25,169 @@
#include <filemgr.h>
BtInstallThread::BtInstallThread(QObject* parent, QString moduleName, QString sourceName, QString destinationName)
- : QThread(parent),
- done(false),
- m_module(moduleName),
- m_destination(destinationName),
- m_source(sourceName),
- m_cancelled(false)
-{
- m_iMgr = new BtInstallMgr();
+ : QThread(parent),
+ done(false),
+ m_module(moduleName),
+ m_destination(destinationName),
+ m_source(sourceName),
+ m_cancelled(false) {
+ m_iMgr = new BtInstallMgr();
}
-BtInstallThread::~BtInstallThread()
-{
- delete m_iMgr;
+BtInstallThread::~BtInstallThread() {
+ delete m_iMgr;
}
-void BtInstallThread::run()
-{
- qDebug() << "****************************************\nBtInstallThread::run, mod:" << m_module << "\n************************************";
+void BtInstallThread::run() {
+ qDebug() << "****************************************\nBtInstallThread::run, mod:" << m_module << "\n************************************";
- emit preparingInstall(m_module, m_source);
+ emit preparingInstall(m_module, m_source);
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
- QDir dir(m_destination);
- if (!dir.exists()) {
- dir.mkdir(m_destination);
- qDebug() << "made directory" << m_destination;
- }
- if (!dir.exists("modules")) {
- dir.mkdir("modules");
- qDebug() << "made directory" << m_destination << "/modules";
- }
- if (!dir.exists("mods.d")) {
- dir.mkdir("mods.d");
- qDebug() << "made directory" << m_destination << "/mods.d";
- }
-
- QObject::connect(m_iMgr, SIGNAL(percentCompleted(int, int)), this, SLOT(slotManagerStatusUpdated(int, int)), Qt::QueuedConnection);
- 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!!!
- removeModule();
-
- // manager for the destination path
- sword::SWMgr lMgr( m_destination.toLatin1() );
+ //make sure target/mods.d and target/modules exist
+ //TODO: move this to some common precondition
+ QDir dir(m_destination);
+ if (!dir.exists()) {
+ dir.mkdir(m_destination);
+ qDebug() << "made directory" << m_destination;
+ }
+ if (!dir.exists("modules")) {
+ dir.mkdir("modules");
+ qDebug() << "made directory" << m_destination << "/modules";
+ }
+ if (!dir.exists("mods.d")) {
+ dir.mkdir("mods.d");
+ qDebug() << "made directory" << m_destination << "/mods.d";
+ }
+
+ QObject::connect(m_iMgr, SIGNAL(percentCompleted(int, int)), this, SLOT(slotManagerStatusUpdated(int, int)), Qt::QueuedConnection);
+ 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!!!
+ removeModule();
+
+ // manager for the destination path
+ sword::SWMgr lMgr( m_destination.toLatin1() );
if (instbackend::isRemote(*m_installSource)) {
- qDebug() << "calling install";
+ qDebug() << "calling install";
int status = m_iMgr->installModule(&lMgr, 0, m_module.toLatin1(), m_installSource.get());
- if (status != 0) {
- qWarning() << "Error with install: " << status << "module:" << m_module;
- }
- else {
- done = true;
- emit installCompleted(m_module, m_source, status);
- }
- }
- else { //local source
- emit statusUpdated(m_module, 0);
+ if (status != 0) {
+ qWarning() << "Error with install: " << status << "module:" << m_module;
+ }
+ else {
+ done = true;
+ emit installCompleted(m_module, m_source, status);
+ }
+ }
+ else { //local source
+ emit statusUpdated(m_module, 0);
int status = m_iMgr->installModule(&lMgr, m_installSource->directory.c_str(), m_module.toLatin1());
- if (status > 0) {
- qWarning() << "Error with install: " << status << "module:" << m_module;
- }
- else if (status == -1) {
- // it was terminated, do nothing
- }
- else {
- emit statusUpdated(m_module, 100);
- done = true;
- emit installCompleted(m_module, m_source, status);
- }
- }
+ if (status > 0) {
+ qWarning() << "Error with install: " << status << "module:" << m_module;
+ }
+ else if (status == -1) {
+ // it was terminated, do nothing
+ }
+ else {
+ emit statusUpdated(m_module, 100);
+ done = true;
+ emit installCompleted(m_module, m_source, status);
+ }
+ }
}
-void BtInstallThread::slotStopInstall()
-{
- qDebug() << "*************************************\nBtInstallThread::slotStopInstall" << m_module << "\n********************************";
- if (!done) {
- done = true;
- qDebug() << "*********************************\nBtInstallThread::slotStopInstall, installing" << m_module << "was cancelled\n**************************************";
- m_iMgr->terminate();
- //this->terminate(); // It's dangerous to forcibly stop, but we will clean up the files
- 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);
- if (notRun) {
- this->terminate();
- this->wait(2);
- 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) {
- 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);
- }
- }
+void BtInstallThread::slotStopInstall() {
+ qDebug() << "*************************************\nBtInstallThread::slotStopInstall" << m_module << "\n********************************";
+ if (!done) {
+ done = true;
+ qDebug() << "*********************************\nBtInstallThread::slotStopInstall, installing" << m_module << "was cancelled\n**************************************";
+ m_iMgr->terminate();
+ //this->terminate(); // It's dangerous to forcibly stop, but we will clean up the files
+ 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);
+ if (notRun) {
+ this->terminate();
+ this->wait(2);
+ 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) {
+ 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);
+ }
+ }
}
-void BtInstallThread::slotManagerStatusUpdated(int totalProgress, int /*fileProgress*/)
-{
- //qDebug("BtInstallThread::slotManagerStatusUpdated");
- emit statusUpdated(m_module, totalProgress);
+void BtInstallThread::slotManagerStatusUpdated(int totalProgress, int /*fileProgress*/) {
+ //qDebug("BtInstallThread::slotManagerStatusUpdated");
+ emit statusUpdated(m_module, totalProgress);
}
-void BtInstallThread::slotDownloadStarted()
-{
- qDebug("BtInstallThread::slotDownloadStarted");
- emit downloadStarted(m_module);
+void BtInstallThread::slotDownloadStarted() {
+ qDebug("BtInstallThread::slotDownloadStarted");
+ emit downloadStarted(m_module);
}
-void BtInstallThread::removeModule()
-{
- qDebug() << "BtInstallThread::removeModule start";
- CSwordModuleInfo* m;
- m = CPointers::backend()->findModuleByName(m_module);
- if (!m) {
- m = instbackend::backend(instbackend::source(m_destination.toLatin1()))->findModuleByName(m_module);
- }
- if (m) { //module found?
- qDebug() << "BtInstallThread::removeModule, module" << m_module << "found";
- QString prefixPath = m->config(CSwordModuleInfo::AbsoluteDataPath) + "/";
- QString dataPath = m->config(CSwordModuleInfo::DataPath);
- if (dataPath.left(2) == "./") {
- dataPath = dataPath.mid(2);
- }
-
- if (prefixPath.contains(dataPath)) {
- prefixPath.remove( prefixPath.indexOf(dataPath), dataPath.length() );
- }
- else {
- prefixPath = QString::fromLatin1(CPointers::backend()->prefixPath);
- }
-
- sword::SWMgr mgr(prefixPath.toLatin1());
- BtInstallMgr iMgr;
- iMgr.removeModule(&mgr, m->name().toLatin1());
- } else {
- qDebug() << "BtInstallThread::removeModule, module" << m_module << "not found";
- }
+void BtInstallThread::removeModule() {
+ qDebug() << "BtInstallThread::removeModule start";
+ CSwordModuleInfo* m;
+ m = CPointers::backend()->findModuleByName(m_module);
+ if (!m) {
+ m = instbackend::backend(instbackend::source(m_destination.toLatin1()))->findModuleByName(m_module);
+ }
+ if (m) { //module found?
+ qDebug() << "BtInstallThread::removeModule, module" << m_module << "found";
+ QString prefixPath = m->config(CSwordModuleInfo::AbsoluteDataPath) + "/";
+ QString dataPath = m->config(CSwordModuleInfo::DataPath);
+ if (dataPath.left(2) == "./") {
+ dataPath = dataPath.mid(2);
+ }
+
+ if (prefixPath.contains(dataPath)) {
+ prefixPath.remove( prefixPath.indexOf(dataPath), dataPath.length() );
+ }
+ else {
+ prefixPath = QString::fromLatin1(CPointers::backend()->prefixPath);
+ }
+
+ sword::SWMgr mgr(prefixPath.toLatin1());
+ BtInstallMgr iMgr;
+ iMgr.removeModule(&mgr, m->name().toLatin1());
+ }
+ else {
+ qDebug() << "BtInstallThread::removeModule, module" << m_module << "not found";
+ }
}
-void BtInstallThread::removeTempFiles()
-{
- qDebug("BtInstallThread::removeTempFiles start");
+void BtInstallThread::removeTempFiles() {
+ qDebug("BtInstallThread::removeTempFiles start");
- // (take the remote conf file for this module, take DataPath,
- // take the absolute path of the InstallMgr)
+ // (take the remote conf file for this module, take DataPath,
+ // take the absolute path of the InstallMgr)
- //sword::InstallSource is = instbackend::source(m_source);
+ //sword::InstallSource is = instbackend::source(m_source);
if (instbackend::isRemote(*m_installSource)) {
- // get the path for the module temp files
- CSwordModuleInfo* mInfo = m_backendForSource->findModuleByName(m_module);
- QString dataPath = mInfo->config(CSwordModuleInfo::AbsoluteDataPath);
- qDebug() << "Delete path:" << dataPath;
- // it's easier to use sword than qt
- sword::FileMgr::removeDir(dataPath.toLatin1().data());
- }
+ // get the path for the module temp files
+ CSwordModuleInfo* mInfo = m_backendForSource->findModuleByName(m_module);
+ QString dataPath = mInfo->config(CSwordModuleInfo::AbsoluteDataPath);
+ qDebug() << "Delete path:" << dataPath;
+ // it's easier to use sword than qt
+ sword::FileMgr::removeDir(dataPath.toLatin1().data());
+ }
}
diff --git a/src/frontend/bookshelfmanager/installpage/btinstallthread.h b/src/frontend/bookshelfmanager/installpage/btinstallthread.h
index a9a998a..8a8cb37 100644
--- a/src/frontend/bookshelfmanager/installpage/btinstallthread.h
+++ b/src/frontend/bookshelfmanager/installpage/btinstallthread.h
@@ -51,48 +51,47 @@ temporary files manually.
* We use ftp connection and file resources; the connection can be ignored but the files
* have to be cleaned up after termination.
*/
-class BtInstallThread : public QThread
-{
- Q_OBJECT
-public:
- BtInstallThread(QObject* parent, QString moduleName, QString sourceName, QString destinationName);
-
- ~BtInstallThread();
-
-public slots:
- void slotStopInstall();
- void slotManagerStatusUpdated(int totalProgress, int fileProgress);
- void slotDownloadStarted();
-
-public: // data member
- bool done;
-
-protected:
- virtual void run();
- void removeModule();
- void removeTempFiles();
-
- QString m_module;
- QString m_destination;
- QString m_source;
- bool m_cancelled;
- 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
- // where it has already been created. Could fasten the progress dialog startup.
- boost::scoped_ptr<CSwordBackend> m_backendForSource;
-
-signals:
- /** Emitted when the install progress status is updated. */
- void statusUpdated(QString module, int progressPercent);
- /** Emitted when installing has been stopped/cancelled. */
- void installStopped(QString module, QString source);
- /** Emitted when installing is complete. */
- void installCompleted(QString module, QString source, int errorStatus);
- /** Emitted when the first file download has been started. */
- void downloadStarted(QString module);
- void preparingInstall(QString module, QString source);
+class BtInstallThread : public QThread {
+ Q_OBJECT
+ public:
+ BtInstallThread(QObject* parent, QString moduleName, QString sourceName, QString destinationName);
+
+ ~BtInstallThread();
+
+ public slots:
+ void slotStopInstall();
+ void slotManagerStatusUpdated(int totalProgress, int fileProgress);
+ void slotDownloadStarted();
+
+ public: // data member
+ bool done;
+
+ protected:
+ virtual void run();
+ void removeModule();
+ void removeTempFiles();
+
+ QString m_module;
+ QString m_destination;
+ QString m_source;
+ bool m_cancelled;
+ 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
+ // where it has already been created. Could fasten the progress dialog startup.
+ boost::scoped_ptr<CSwordBackend> m_backendForSource;
+
+ signals:
+ /** Emitted when the install progress status is updated. */
+ void statusUpdated(QString module, int progressPercent);
+ /** Emitted when installing has been stopped/cancelled. */
+ void installStopped(QString module, QString source);
+ /** Emitted when installing is complete. */
+ void installCompleted(QString module, QString source, int errorStatus);
+ /** Emitted when the first file download has been started. */
+ void downloadStarted(QString module);
+ void preparingInstall(QString module, QString source);
};
#endif
diff --git a/src/frontend/bookshelfmanager/installpage/btsourcearea.cpp b/src/frontend/bookshelfmanager/installpage/btsourcearea.cpp
index 45bfe0f..cfdc8bb 100644
--- a/src/frontend/bookshelfmanager/installpage/btsourcearea.cpp
+++ b/src/frontend/bookshelfmanager/installpage/btsourcearea.cpp
@@ -41,258 +41,244 @@
// ****************************************************************
BtSourceArea::BtSourceArea(const QString& sourceName)
- : QWidget(),
- m_sourceName(sourceName),
- m_treeAlreadyInitialized(false),
- m_remoteBackend(0) //important!
-{
- m_checkedModules = QMap<QString, bool>();
- qDebug() << "BtSourceArea::BtSourceArea, " << m_sourceName;
- initView();
+ : QWidget(),
+ m_sourceName(sourceName),
+ m_treeAlreadyInitialized(false),
+ m_remoteBackend(0) { //important!
+ m_checkedModules = QMap<QString, bool>();
+ qDebug() << "BtSourceArea::BtSourceArea, " << m_sourceName;
+ initView();
}
-BtSourceArea::~BtSourceArea()
-{
- delete m_remoteBackend;
+BtSourceArea::~BtSourceArea() {
+ delete m_remoteBackend;
}
-void BtSourceArea::initView()
-{
- 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->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
- 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->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));
-
- sourceLayout->addWidget(m_refreshButton);
- sourceLayout->addItem(sourceSpacer);
- //sourceLayout->addWidget(m_editButton);
- sourceLayout->addWidget(m_deleteButton);
- sourceLayout->addWidget(m_addButton);
-
- mainLayout->addLayout(sourceLayout);
- // 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));
- mainLayout->addWidget(m_view);
-
- connect(m_view, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), SLOT(slotItemDoubleClicked(QTreeWidgetItem*, int)));
- connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(slotSwordSetupChanged()));
- connect(this, SIGNAL(signalCreateTree()), SLOT(slotCreateTree()), Qt::QueuedConnection);
+void BtSourceArea::initView() {
+ 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->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
+ 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->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));
+
+ sourceLayout->addWidget(m_refreshButton);
+ sourceLayout->addItem(sourceSpacer);
+ //sourceLayout->addWidget(m_editButton);
+ sourceLayout->addWidget(m_deleteButton);
+ sourceLayout->addWidget(m_addButton);
+
+ mainLayout->addLayout(sourceLayout);
+ // 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));
+ mainLayout->addWidget(m_view);
+
+ connect(m_view, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), SLOT(slotItemDoubleClicked(QTreeWidgetItem*, int)));
+ connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(slotSwordSetupChanged()));
+ connect(this, SIGNAL(signalCreateTree()), SLOT(slotCreateTree()), Qt::QueuedConnection);
}
-QSize BtSourceArea::sizeHint() const
-{
- return QSize(100, m_refreshButton->height() + (m_view->header()->height() * 5));
+QSize BtSourceArea::sizeHint() const {
+ return QSize(100, m_refreshButton->height() + (m_view->header()->height() * 5));
}
-void BtSourceArea::initTreeFirstTime()
-{
- if (!m_treeAlreadyInitialized) {
- createModuleTree();
- m_treeAlreadyInitialized = true;
- }
+void BtSourceArea::initTreeFirstTime() {
+ if (!m_treeAlreadyInitialized) {
+ createModuleTree();
+ m_treeAlreadyInitialized = true;
+ }
}
-void BtSourceArea::createModuleTree()
-{
- 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();
+void BtSourceArea::createModuleTree() {
+ 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();
}
-void BtSourceArea::slotCreateTree()
-{
- qDebug()<<"BtSourceArea::slotCreateTree" << QTime::currentTime ();
- //let the dialog become visible
- QCoreApplication::processEvents();
- // Creating the view and populating list may take time
- QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
-
- // disconnect the signal so that we don't have to run functions for every module
- // (note: what to do if we want to restore the item selection when rebuilding?
- 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
- m_checkedModules.clear();
-
- sword::InstallSource is = instbackend::source(m_sourceName);
- delete m_remoteBackend; // the old one can be deleted
- m_remoteBackend = instbackend::backend(is);
- Q_ASSERT(m_remoteBackend);
- m_moduleList = m_remoteBackend->moduleList();
-
- // give the list to BTModuleTreeItem, create filter to remove
- // those modules which are installed already
- InstalledFilter alreadyInstalledFilter(m_sourceName);
- QList<BTModuleTreeItem::Filter*> filterList;
- filterList.append(&alreadyInstalledFilter);
- BTModuleTreeItem rootItem(filterList, BTModuleTreeItem::CatLangMod, &m_moduleList);
-
- addToTree(&rootItem, m_view->invisibleRootItem());
- QCoreApplication::processEvents();
- // receive signal when user checks modules
- connect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) );
- QApplication::restoreOverrideCursor();
- qDebug()<< "BtSourceArea::createModuleTree end"<< QTime::currentTime ();
+void BtSourceArea::slotCreateTree() {
+ qDebug() << "BtSourceArea::slotCreateTree" << QTime::currentTime ();
+ //let the dialog become visible
+ QCoreApplication::processEvents();
+ // Creating the view and populating list may take time
+ QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
+
+ // disconnect the signal so that we don't have to run functions for every module
+ // (note: what to do if we want to restore the item selection when rebuilding?
+ 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
+ m_checkedModules.clear();
+
+ sword::InstallSource is = instbackend::source(m_sourceName);
+ delete m_remoteBackend; // the old one can be deleted
+ m_remoteBackend = instbackend::backend(is);
+ Q_ASSERT(m_remoteBackend);
+ m_moduleList = m_remoteBackend->moduleList();
+
+ // give the list to BTModuleTreeItem, create filter to remove
+ // those modules which are installed already
+ InstalledFilter alreadyInstalledFilter(m_sourceName);
+ QList<BTModuleTreeItem::Filter*> filterList;
+ filterList.append(&alreadyInstalledFilter);
+ BTModuleTreeItem rootItem(filterList, BTModuleTreeItem::CatLangMod, &m_moduleList);
+
+ addToTree(&rootItem, m_view->invisibleRootItem());
+ QCoreApplication::processEvents();
+ // receive signal when user checks modules
+ connect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) );
+ QApplication::restoreOverrideCursor();
+ qDebug() << "BtSourceArea::createModuleTree end" << QTime::currentTime ();
}
-void BtSourceArea::addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem)
-{
- //qDebug()<<"BtSourceArea::addToTree "<<item->text();
- //qDebug() << "BTMTItem type: " << item->type();
-
- foreach (BTModuleTreeItem* i, item->children()) {
- addToTree(i, new QTreeWidgetItem(widgetItem));
- }
- if (item->type() != BTModuleTreeItem::Root) {
- CSwordModuleInfo* mInfo = item->moduleInfo();
- widgetItem->setText(0, item->text());
- if (item->type() == BTModuleTreeItem::Category || item->type() == BTModuleTreeItem::Language) {
- //qDebug() << "item"<<item->text()<< "was cat or lang";
- widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
- }
- if (item->type() == BTModuleTreeItem::Module) {
- //qDebug() << "item"<<item->text()<< "was a module";
- widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
- widgetItem->setCheckState(0, Qt::Unchecked);
-
- CSwordModuleInfo* const installedModule = CPointers::backend()->findModuleByName(mInfo->name());
- 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
- } else { // the module is already installed
- QBrush bg(QColor(255,153,153)); /// \bug Possible color conflict
- widgetItem->setBackground(0, bg);
- widgetItem->setBackground(1, bg);
- installedV = QString(installedModule->config(CSwordModuleInfo::ModuleVersion).toLatin1());
- // set the color for the parent items
- QTreeWidgetItem* parent1 = widgetItem->parent();
- if (parent1) {
- parent1->setBackground(0,bg);
- parent1->setBackground(1,bg);
- QTreeWidgetItem* parent2 = parent1->parent();
- if (parent2) {
- parent2->setBackground(0,bg);
- parent2->setBackground(1,bg);
- }
- }
- }
-
-
- QString descr(mInfo->config(CSwordModuleInfo::Description));
- QString toolTipText = CToolClass::remoteModuleToolTip(mInfo, installedV);
-
- widgetItem->setText(1, descr);
- widgetItem->setToolTip(0, toolTipText);
- widgetItem->setToolTip(1, toolTipText);
- }
- }
+void BtSourceArea::addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem) {
+ //qDebug()<<"BtSourceArea::addToTree "<<item->text();
+ //qDebug() << "BTMTItem type: " << item->type();
+
+ foreach (BTModuleTreeItem* i, item->children()) {
+ addToTree(i, new QTreeWidgetItem(widgetItem));
+ }
+ if (item->type() != BTModuleTreeItem::Root) {
+ CSwordModuleInfo* mInfo = item->moduleInfo();
+ widgetItem->setText(0, item->text());
+ if (item->type() == BTModuleTreeItem::Category || item->type() == BTModuleTreeItem::Language) {
+ //qDebug() << "item"<<item->text()<< "was cat or lang";
+ widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
+ }
+ if (item->type() == BTModuleTreeItem::Module) {
+ //qDebug() << "item"<<item->text()<< "was a module";
+ widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+ widgetItem->setCheckState(0, Qt::Unchecked);
+
+ CSwordModuleInfo* const installedModule = CPointers::backend()->findModuleByName(mInfo->name());
+ 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
+ } else { // the module is already installed
+ QBrush bg(QColor(255, 153, 153)); /// \bug Possible color conflict
+ widgetItem->setBackground(0, bg);
+ widgetItem->setBackground(1, bg);
+ installedV = QString(installedModule->config(CSwordModuleInfo::ModuleVersion).toLatin1());
+ // set the color for the parent items
+ QTreeWidgetItem* parent1 = widgetItem->parent();
+ if (parent1) {
+ parent1->setBackground(0, bg);
+ parent1->setBackground(1, bg);
+ QTreeWidgetItem* parent2 = parent1->parent();
+ if (parent2) {
+ parent2->setBackground(0, bg);
+ parent2->setBackground(1, bg);
+ }
+ }
+ }
+
+
+ QString descr(mInfo->config(CSwordModuleInfo::Description));
+ QString toolTipText = CToolClass::remoteModuleToolTip(mInfo, installedV);
+
+ widgetItem->setText(1, descr);
+ widgetItem->setToolTip(0, toolTipText);
+ widgetItem->setToolTip(1, toolTipText);
+ }
+ }
}
-QTreeWidget* BtSourceArea::treeWidget()
-{
- return m_view;
+QTreeWidget* BtSourceArea::treeWidget() {
+ return m_view;
}
// return the selected modules
-QMap<QString, bool>* BtSourceArea::selectedModules()
-{
- return &m_checkedModules;
+QMap<QString, bool>* BtSourceArea::selectedModules() {
+ return &m_checkedModules;
}
// when a module is checked/unchecked
-void BtSourceArea::slotSelectionChanged(QTreeWidgetItem* item, int column)
-{
- //qDebug("BtSourceArea::slotSelectionChanged");
- // modify the internal list of selected (actually checked) modules
- // if() leaves groups away
- if (!item->childCount() && column == 0) {
- foreach (CSwordModuleInfo* module, m_moduleList) {
- if (module->name() == item->text(0)) {
- if (item->checkState(0) == Qt::Checked) {
- qDebug() << module->name() << "was checked";
- m_checkedModules.insert(module->name(), true);
- } else {
- qDebug() << module->name() << "was unchecked";
- m_checkedModules.remove(module->name());
- }
- emit signalSelectionChanged(m_sourceName, m_checkedModules.count());
- break;
- }
- }
- }
+void BtSourceArea::slotSelectionChanged(QTreeWidgetItem* item, int column) {
+ //qDebug("BtSourceArea::slotSelectionChanged");
+ // modify the internal list of selected (actually checked) modules
+ // if() leaves groups away
+ if (!item->childCount() && column == 0) {
+ foreach (CSwordModuleInfo* module, m_moduleList) {
+ if (module->name() == item->text(0)) {
+ if (item->checkState(0) == Qt::Checked) {
+ qDebug() << module->name() << "was checked";
+ m_checkedModules.insert(module->name(), true);
+ }
+ else {
+ qDebug() << module->name() << "was unchecked";
+ m_checkedModules.remove(module->name());
+ }
+ emit signalSelectionChanged(m_sourceName, m_checkedModules.count());
+ break;
+ }
+ }
+ }
}
-void BtSourceArea::slotItemDoubleClicked(QTreeWidgetItem* item, int /*column*/)
-{
- CSwordModuleInfo* mInfo = m_remoteBackend->findModuleByName(item->text(0));
- if (mInfo) {
- BTAboutModuleDialog* dialog = new BTAboutModuleDialog(this, mInfo);
- dialog->show();
- dialog->raise();
- }
+void BtSourceArea::slotItemDoubleClicked(QTreeWidgetItem* item, int /*column*/) {
+ CSwordModuleInfo* mInfo = m_remoteBackend->findModuleByName(item->text(0));
+ if (mInfo) {
+ BTAboutModuleDialog* dialog = new BTAboutModuleDialog(this, mInfo);
+ dialog->show();
+ dialog->raise();
+ }
}
BtSourceArea::InstalledFilter::InstalledFilter(QString sourceName)
- : BTModuleTreeItem::Filter(),
- m_source(instbackend::source(sourceName)),
- m_swordBackend(instbackend::backend(m_source))
-{
- // these are set once to optimize away repeated calls
- // m_source, m_swordBackend
+ : BTModuleTreeItem::Filter(),
+ m_source(instbackend::source(sourceName)),
+ m_swordBackend(instbackend::backend(m_source)) {
+ // these are set once to optimize away repeated calls
+ // m_source, m_swordBackend
}
//filter out already installed, not updateable modules
-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...");
- const sword::SWVersion installedVersion(installedModule->config(CSwordModuleInfo::ModuleVersion).toLatin1());
- const sword::SWVersion newVersion(mInfo->config(CSwordModuleInfo::ModuleVersion).toLatin1());
- if (installedVersion >= newVersion) {
- return false;
- }
- }
- return true;
+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...");
+ const sword::SWVersion installedVersion(installedModule->config(CSwordModuleInfo::ModuleVersion).toLatin1());
+ const sword::SWVersion newVersion(mInfo->config(CSwordModuleInfo::ModuleVersion).toLatin1());
+ if (installedVersion >= newVersion) {
+ return false;
+ }
+ }
+ return true;
}
-void BtSourceArea::slotSwordSetupChanged()
-{
- createModuleTree();
+void BtSourceArea::slotSwordSetupChanged() {
+ createModuleTree();
}
diff --git a/src/frontend/bookshelfmanager/installpage/btsourcearea.h b/src/frontend/bookshelfmanager/installpage/btsourcearea.h
index 814bde8..e39efef 100644
--- a/src/frontend/bookshelfmanager/installpage/btsourcearea.h
+++ b/src/frontend/bookshelfmanager/installpage/btsourcearea.h
@@ -37,59 +37,58 @@ class QPushButton;
* the cache and rebuilds the module tree. Sources are not refreshed
* automatically, only by the user action, one source at a time.
*/
-class BtSourceArea : public QWidget
-{
- Q_OBJECT
-
- friend class BtSourceWidget;
-public:
-
- struct InstalledFilter : BTModuleTreeItem::Filter {
- InstalledFilter(QString sourceName);
- bool filter(CSwordModuleInfo*);
- sword::InstallSource m_source;
- boost::scoped_ptr<CSwordBackend> m_swordBackend;
- };
-
- BtSourceArea(const QString& sourceName);
- ~BtSourceArea();
-
- void initView();
- /** Reimplemented from QWidget. */
- virtual QSize sizeHint() const;
- void initTreeFirstTime();
- QTreeWidget* treeWidget();
-
- QMap<QString, bool>* selectedModules();
-
-public slots:
- void slotSwordSetupChanged();
- /** Create a module tree for a tree widget */
- void createModuleTree();
-
-signals:
- void signalSelectionChanged(QString sourceName, int selectedCount);
- void signalCreateTree();
-
-private slots:
- void slotCreateTree();
- void slotSelectionChanged(QTreeWidgetItem* item, int column);
- void slotItemDoubleClicked(QTreeWidgetItem* item, int column);
-private:
- void addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem);
-
- QString m_sourceName;
- bool m_treeAlreadyInitialized;
- QMap<QString, bool> m_checkedModules;
- CSwordBackend* m_remoteBackend; // needed for the module list
- QList<CSwordModuleInfo*> m_moduleList;
-
- QTreeWidget* m_view;
- QLabel* m_refreshTimeLabel;
- QPushButton* m_refreshButton;
- QPushButton* m_editButton;
- QPushButton* m_deleteButton;
- QPushButton* m_addButton;
+class BtSourceArea : public QWidget {
+ Q_OBJECT
+
+ friend class BtSourceWidget;
+ public:
+
+ struct InstalledFilter : BTModuleTreeItem::Filter {
+ InstalledFilter(QString sourceName);
+ bool filter(CSwordModuleInfo*);
+ sword::InstallSource m_source;
+ boost::scoped_ptr<CSwordBackend> m_swordBackend;
+ };
+
+ BtSourceArea(const QString& sourceName);
+ ~BtSourceArea();
+
+ void initView();
+ /** Reimplemented from QWidget. */
+ virtual QSize sizeHint() const;
+ void initTreeFirstTime();
+ QTreeWidget* treeWidget();
+
+ QMap<QString, bool>* selectedModules();
+
+ public slots:
+ void slotSwordSetupChanged();
+ /** Create a module tree for a tree widget */
+ void createModuleTree();
+
+ signals:
+ void signalSelectionChanged(QString sourceName, int selectedCount);
+ void signalCreateTree();
+
+ private slots:
+ void slotCreateTree();
+ void slotSelectionChanged(QTreeWidgetItem* item, int column);
+ void slotItemDoubleClicked(QTreeWidgetItem* item, int column);
+ private:
+ void addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem);
+
+ QString m_sourceName;
+ bool m_treeAlreadyInitialized;
+ QMap<QString, bool> m_checkedModules;
+ CSwordBackend* m_remoteBackend; // needed for the module list
+ QList<CSwordModuleInfo*> m_moduleList;
+
+ QTreeWidget* m_view;
+ QLabel* m_refreshTimeLabel;
+ QPushButton* m_refreshButton;
+ QPushButton* m_editButton;
+ QPushButton* m_deleteButton;
+ QPushButton* m_addButton;
};
diff --git a/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp b/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp
index 586a680..f18935a 100644
--- a/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp
+++ b/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp
@@ -39,365 +39,352 @@
// ****************************************************************
BtSourceWidget::BtSourceWidget(BtInstallPage* parent)
- : QTabWidget(parent),
- m_page(parent)
-{
- qDebug("BtSourceWidget::BtSourceWidget start");
- initSources();
-
- // TODO: choose the page from config
-
+ : QTabWidget(parent),
+ m_page(parent) {
+ qDebug("BtSourceWidget::BtSourceWidget start");
+ initSources();
+
+ // TODO: choose the page from config
+
}
-BtSourceArea* BtSourceWidget::area()
-{
- return dynamic_cast<BtSourceArea*>(currentWidget());
+BtSourceArea* BtSourceWidget::area() {
+ return dynamic_cast<BtSourceArea*>(currentWidget());
}
-QString BtSourceWidget::currentSourceName()
-{
- qDebug() << "BtSourceWidget::currentSourceName: " << m_sourceNameList.at(currentIndex());
- return m_sourceNameList.at(currentIndex());
+QString BtSourceWidget::currentSourceName() {
+ qDebug() << "BtSourceWidget::currentSourceName: " << m_sourceNameList.at(currentIndex());
+ return m_sourceNameList.at(currentIndex());
}
-void BtSourceWidget::initSourceConnections()
-{
- 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_addButton, SIGNAL(clicked()), SLOT(slotAdd()));
- connect(area(), SIGNAL(signalSelectionChanged(QString, int)), SLOT(slotModuleSelectionChanged(QString, int)) );
- }
- qDebug("void BtSourceWidget::initSourceConnections() end");
+void BtSourceWidget::initSourceConnections() {
+ 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_addButton, SIGNAL(clicked()), SLOT(slotAdd()));
+ connect(area(), SIGNAL(signalSelectionChanged(QString, int)), SLOT(slotModuleSelectionChanged(QString, int)) );
+ }
+ qDebug("void BtSourceWidget::initSourceConnections() end");
}
-void BtSourceWidget::slotEdit()
-{
- qDebug("BtSourceWidget::slotEdit");
- // open the source editor dialog
-
- // if the source was changed, init the sources
-
+void BtSourceWidget::slotEdit() {
+ qDebug("BtSourceWidget::slotEdit");
+ // open the source editor dialog
+
+ // if the source was changed, init the sources
+
}
-void BtSourceWidget::slotDelete()
-{
- 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);
-
- if (ret == QMessageBox::Yes) {
- instbackend::deleteSource(currentSourceName());
-
- // remove the UI elements
- m_sourceNameList.removeAt(currentIndex());
- QWidget* w = currentWidget();
- removeTab(currentIndex());
- delete w;
- }
+void BtSourceWidget::slotDelete() {
+ 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);
+
+ if (ret == QMessageBox::Yes) {
+ instbackend::deleteSource(currentSourceName());
+
+ // remove the UI elements
+ m_sourceNameList.removeAt(currentIndex());
+ QWidget* w = currentWidget();
+ removeTab(currentIndex());
+ delete w;
+ }
}
-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()));
- }
+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()));
+ }
}
-void BtSourceWidget::slotRefresh()
-{
- qDebug("void BtSourceWidget::slotRefresh() start");
- // (re)build the module cache for the source
-
- QString sourceName = currentSourceName();
-
- // quick enough, make it modal so that we don't need to take care of anything else
- m_progressDialog = new QProgressDialog("", tr("Cancel"), 0 ,100, this);
- m_progressDialog->setWindowTitle(tr("Refreshing Source"));
- m_progressDialog->setMinimumDuration(0);
-
- // 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");
- BtInstallMgr iMgr;
- m_currentInstallMgr = &iMgr; //for the progress dialog
- sword::InstallSource is = instbackend::source(sourceName);
- bool success = false;
- 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)));
-
- if (instbackend::isRemote(is)) {
- m_progressDialog->show();
- qApp->processEvents();
- this->slotRefreshCompleted(0,0);
- 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");
- bool successful = iMgr.refreshRemoteSource( &is );
- if (!successful ) { //make sure the sources were updated sucessfully
- success = true;
- m_progressDialog->setValue(100); //make sure the dialog closes
- }
- else {
- qWarning("InstallMgr: refreshRemoteSources returned an error.");
- success = false;
- }
- }
- else {
- // Local source, update the list
- success = true;
- }
-
- delete m_progressDialog;
- m_progressDialog = 0;
-
- // rebuild the view tree and refresh the view
- if (success) {
- qDebug("void BtSourceWidget::slotRefresh 4");
- area()->createModuleTree();
- }
+void BtSourceWidget::slotRefresh() {
+ qDebug("void BtSourceWidget::slotRefresh() start");
+ // (re)build the module cache for the source
+
+ QString sourceName = currentSourceName();
+
+ // quick enough, make it modal so that we don't need to take care of anything else
+ m_progressDialog = new QProgressDialog("", tr("Cancel"), 0 , 100, this);
+ m_progressDialog->setWindowTitle(tr("Refreshing Source"));
+ m_progressDialog->setMinimumDuration(0);
+
+ // 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");
+ BtInstallMgr iMgr;
+ m_currentInstallMgr = &iMgr; //for the progress dialog
+ sword::InstallSource is = instbackend::source(sourceName);
+ bool success = false;
+ 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)));
+
+ if (instbackend::isRemote(is)) {
+ m_progressDialog->show();
+ qApp->processEvents();
+ this->slotRefreshCompleted(0, 0);
+ 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");
+ bool successful = iMgr.refreshRemoteSource( &is );
+ if (!successful ) { //make sure the sources were updated sucessfully
+ success = true;
+ m_progressDialog->setValue(100); //make sure the dialog closes
+ }
+ else {
+ qWarning("InstallMgr: refreshRemoteSources returned an error.");
+ success = false;
+ }
+ }
+ else {
+ // Local source, update the list
+ success = true;
+ }
+
+ delete m_progressDialog;
+ m_progressDialog = 0;
+
+ // rebuild the view tree and refresh the view
+ if (success) {
+ qDebug("void BtSourceWidget::slotRefresh 4");
+ area()->createModuleTree();
+ }
}
//TODO: try to move this to BtInstallMgr
-void BtSourceWidget::slotRefreshCanceled()
-{
- qDebug("BtSourceWidget::slotRefreshCanceled");
- Q_ASSERT(m_currentInstallMgr);
- if (m_currentInstallMgr) {
- m_currentInstallMgr->terminate();
- }
- qApp->processEvents();
+void BtSourceWidget::slotRefreshCanceled() {
+ qDebug("BtSourceWidget::slotRefreshCanceled");
+ Q_ASSERT(m_currentInstallMgr);
+ if (m_currentInstallMgr) {
+ m_currentInstallMgr->terminate();
+ }
+ qApp->processEvents();
}
//TODO: try to move this to progress dialog
-void BtSourceWidget::slotRefreshCompleted(const int, const int current)
-{
- qDebug("BtSourceWidget::slotRefreshCompleted");
- if (m_progressDialog) {
- if (m_progressDialog->labelText() != tr("Refreshing...")) {
- m_progressDialog->setLabelText(tr("Refreshing..."));
- }
- m_progressDialog->setValue(current);
- }
- qApp->processEvents();
+void BtSourceWidget::slotRefreshCompleted(const int, const int current) {
+ qDebug("BtSourceWidget::slotRefreshCompleted");
+ if (m_progressDialog) {
+ if (m_progressDialog->labelText() != tr("Refreshing...")) {
+ m_progressDialog->setLabelText(tr("Refreshing..."));
+ }
+ m_progressDialog->setValue(current);
+ }
+ qApp->processEvents();
}
// init the tabbar, setup the module tree for the current source
-void BtSourceWidget::initSources()
-{
- qDebug("void BtSourceWidget::initSources() start");
-
- // ***** Use the backend to get the list of sources *****
- instbackend::initPassiveFtpMode();
- QStringList sourceList = instbackend::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()) {
- sword::InstallSource is("FTP"); //default return value
- is.caption = "Crosswire";
- is.source = "ftp.crosswire.org";
- is.directory = "/pub/sword/raw";
- // passive ftp is not needed here, it's the default
-
- instbackend::addSource(is);
-
- sourceList = instbackend::sourceList();
- //Q_ASSERT( sourceList.count() > 0 );
- }
- qDebug("void BtSourceWidget::initSources 1");
- // Add the sources to the widget
- foreach (QString sourceName, sourceList) {
- addSource(sourceName);
- }
- // 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
- // 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
-
- if (sourceList.count() == 0) {
- QHBoxLayout* l = new QHBoxLayout(this);
- QLabel* message = new QLabel(QString("<i>") + tr("No sources were found in the SWORD configuration and BibleTime couldn't create a default source. Check your SWORD configuration and that the configuration path is writable. Then restart the Bookshelf Manager.") + QString("</i>"), this);
- message->setWordWrap(true);
- l->addWidget(message);
- }
+void BtSourceWidget::initSources() {
+ qDebug("void BtSourceWidget::initSources() start");
+
+ // ***** Use the backend to get the list of sources *****
+ instbackend::initPassiveFtpMode();
+ QStringList sourceList = instbackend::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()) {
+ sword::InstallSource is("FTP"); //default return value
+ is.caption = "Crosswire";
+ is.source = "ftp.crosswire.org";
+ is.directory = "/pub/sword/raw";
+ // passive ftp is not needed here, it's the default
+
+ instbackend::addSource(is);
+
+ sourceList = instbackend::sourceList();
+ //Q_ASSERT( sourceList.count() > 0 );
+ }
+ qDebug("void BtSourceWidget::initSources 1");
+ // Add the sources to the widget
+ foreach (QString sourceName, sourceList) {
+ addSource(sourceName);
+ }
+ // 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
+ // 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
+
+ if (sourceList.count() == 0) {
+ QHBoxLayout* l = new QHBoxLayout(this);
+ QLabel* message = new QLabel(QString("<i>") + tr("No sources were found in the SWORD configuration and BibleTime couldn't create a default source. Check your SWORD configuration and that the configuration path is writable. Then restart the Bookshelf Manager.") + QString("</i>"), this);
+ message->setWordWrap(true);
+ l->addWidget(message);
+ }
}
-void BtSourceWidget::addSource(const QString& sourceName)
-{
- qDebug("void BtSourceWidget::addSource(const QString& sourceName) start");
- // The source has already been added to the backend.
-
- QString type;
- QString server;
- QString path;
- sword::InstallSource is = instbackend::source(sourceName);
- if (instbackend::isRemote(is)) {
- type = tr("Remote:");
- server = is.source.c_str();
- path = is.directory.c_str();
- }
- else { // local source
- type = tr("Local:");
- QFileInfo fi( is.directory.c_str() );
- path = is.directory.c_str();
- if (!(fi.isDir() )) {
- path = path + QString(" ") + tr("Not a directory!"); //TODO: change this
- }
- if (!fi.isReadable()) {
- path = path + QString(" ") + tr("Not readable!"); //TODO: change this
- }
- }
-
- // Here the tab UI is created and added to the tab widget
- BtSourceArea* area = new BtSourceArea(sourceName);
- int tabNumber = this->addTab(area, sourceName);
-
- // 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);
-
- //select the new tab
- setCurrentIndex(tabNumber);
- m_sourceNameList.append(sourceName);
- initSourceConnections();
- qDebug("BtSourceWidget::addSource end");
+void BtSourceWidget::addSource(const QString& sourceName) {
+ qDebug("void BtSourceWidget::addSource(const QString& sourceName) start");
+ // The source has already been added to the backend.
+
+ QString type;
+ QString server;
+ QString path;
+ sword::InstallSource is = instbackend::source(sourceName);
+ if (instbackend::isRemote(is)) {
+ type = tr("Remote:");
+ server = is.source.c_str();
+ path = is.directory.c_str();
+ }
+ else { // local source
+ type = tr("Local:");
+ QFileInfo fi( is.directory.c_str() );
+ path = is.directory.c_str();
+ if (!(fi.isDir() )) {
+ path = path + QString(" ") + tr("Not a directory!"); //TODO: change this
+ }
+ if (!fi.isReadable()) {
+ path = path + QString(" ") + tr("Not readable!"); //TODO: change this
+ }
+ }
+
+ // Here the tab UI is created and added to the tab widget
+ BtSourceArea* area = new BtSourceArea(sourceName);
+ int tabNumber = this->addTab(area, sourceName);
+
+ // 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);
+
+ //select the new tab
+ setCurrentIndex(tabNumber);
+ m_sourceNameList.append(sourceName);
+ initSourceConnections();
+ qDebug("BtSourceWidget::addSource end");
}
//
-void BtSourceWidget::slotModuleSelectionChanged(QString sourceName, int selectedCount)
-{
- //TODO: editing sources should update the map also
- qDebug("BtSourceWidget::slotModuleSelectionChanged start");
-
- int overallCount = 0;
- m_selectedModulesCountMap.insert(sourceName, selectedCount);
- foreach (int count, m_selectedModulesCountMap) {
- qDebug() << "add" << count << "to overall count of selected modules";
- overallCount += count;
- }
-
- if (overallCount > 0) {
- m_page->setInstallEnabled(true);
- } else {
- m_page->setInstallEnabled(false);
- }
+void BtSourceWidget::slotModuleSelectionChanged(QString sourceName, int selectedCount) {
+ //TODO: editing sources should update the map also
+ qDebug("BtSourceWidget::slotModuleSelectionChanged start");
+
+ int overallCount = 0;
+ m_selectedModulesCountMap.insert(sourceName, selectedCount);
+ foreach (int count, m_selectedModulesCountMap) {
+ qDebug() << "add" << count << "to overall count of selected modules";
+ overallCount += count;
+ }
+
+ if (overallCount > 0) {
+ m_page->setInstallEnabled(true);
+ }
+ else {
+ m_page->setInstallEnabled(false);
+ }
}
-void BtSourceWidget::slotTabSelected(int /*index*/)
-{
- BtSourceArea* area = dynamic_cast<BtSourceArea*>(currentWidget());
- if (area) area->initTreeFirstTime();
+void BtSourceWidget::slotTabSelected(int /*index*/) {
+ BtSourceArea* area = dynamic_cast<BtSourceArea*>(currentWidget());
+ if (area) area->initTreeFirstTime();
}
-void BtSourceWidget::slotInstall()
-{
- 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());
- bool canWrite = true;
- if (dir.isReadable()) {
- const QFileInfo fi( dir.canonicalPath() );
- if (!fi.exists() || !fi.isWritable()) {
- canWrite = false;
- }
- } else {
- 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);
- if (result != QMessageBox::Ignore) {
- return;
- }
- }
-
- // create the confirmation dialog
- // (module tree dialog, modules taken from all sources)
- QString dlgTitle(tr("Install/Update works?"));
- QString dlgLabel(tr("Do you really want to install these works?") +
- QString("<br/><br/><small>") +
- tr("Only one version of a work can be installed at the same time. Select only one if there are items marked with red.") +
- QString("</small>"));
-
- // with empty list we avoid creating the module tree inside the dialog code
- QList<CSwordModuleInfo*> emptyList;
- BtInstallModuleChooserDialog* dlg = new BtInstallModuleChooserDialog(this, dlgTitle, dlgLabel, &emptyList);
- //dlg->setGrouping(BTModuleTreeItem::Mod);
- QTreeWidget* treeWidget = dlg->treeWidget();
- QTreeWidgetItem* rootItem = treeWidget->invisibleRootItem();
-
- QStringList nameList;
-
- // loop through each tab
- for (int tab = 0; tab < count(); ++tab) {
- BtSourceArea* sArea = dynamic_cast<BtSourceArea*>(widget(tab));
- if (sArea && sArea->selectedModules()->count() > 0) {
- // there are selected modules in the source, create items for these
- QTreeWidgetItem* sourceItem = new QTreeWidgetItem(rootItem);
- sourceItem->setText(0, m_sourceNameList.at(tab));
- sourceItem->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsTristate|Qt::ItemIsEnabled);
- foreach (QString mName, sArea->selectedModules()->keys()) {
- dlg->initModuleItem(mName, sourceItem);
- }
- sourceItem->setExpanded(true);
- }
- }
-
- //user accepts the dialog
- connect(dlg, SIGNAL(modulesChanged(QList<CSwordModuleInfo*>, QTreeWidget*)), SLOT(slotInstallAccepted(QList<CSwordModuleInfo*>, QTreeWidget*)) );
- // user checks/unchecks an item, needed for preventing double items
- QObject::connect(treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), dlg, SLOT(slotItemChecked(QTreeWidgetItem*, int)));
- dlg->exec();
- // The OK signal sent by the dialog is catched with slotInstallAccepted.
+void BtSourceWidget::slotInstall() {
+ 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());
+ bool canWrite = true;
+ if (dir.isReadable()) {
+ const QFileInfo fi( dir.canonicalPath() );
+ if (!fi.exists() || !fi.isWritable()) {
+ canWrite = false;
+ }
+ }
+ else {
+ 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);
+ if (result != QMessageBox::Ignore) {
+ return;
+ }
+ }
+
+ // create the confirmation dialog
+ // (module tree dialog, modules taken from all sources)
+ QString dlgTitle(tr("Install/Update works?"));
+ QString dlgLabel(tr("Do you really want to install these works?") +
+ QString("<br/><br/><small>") +
+ tr("Only one version of a work can be installed at the same time. Select only one if there are items marked with red.") +
+ QString("</small>"));
+
+ // with empty list we avoid creating the module tree inside the dialog code
+ QList<CSwordModuleInfo*> emptyList;
+ BtInstallModuleChooserDialog* dlg = new BtInstallModuleChooserDialog(this, dlgTitle, dlgLabel, &emptyList);
+ //dlg->setGrouping(BTModuleTreeItem::Mod);
+ QTreeWidget* treeWidget = dlg->treeWidget();
+ QTreeWidgetItem* rootItem = treeWidget->invisibleRootItem();
+
+ QStringList nameList;
+
+ // loop through each tab
+ for (int tab = 0; tab < count(); ++tab) {
+ BtSourceArea* sArea = dynamic_cast<BtSourceArea*>(widget(tab));
+ if (sArea && sArea->selectedModules()->count() > 0) {
+ // there are selected modules in the source, create items for these
+ /// \todo Use new bookshelf model instead
+ /// \bug Valgrind reports memory leak:
+ QTreeWidgetItem* sourceItem = new QTreeWidgetItem(rootItem);
+ sourceItem->setText(0, m_sourceNameList.at(tab));
+ sourceItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsTristate | Qt::ItemIsEnabled);
+ foreach (QString mName, sArea->selectedModules()->keys()) {
+ dlg->initModuleItem(mName, sourceItem);
+ }
+ sourceItem->setExpanded(true);
+ }
+ }
+
+ //user accepts the dialog
+ connect(dlg, SIGNAL(modulesChanged(QList<CSwordModuleInfo*>, QTreeWidget*)), SLOT(slotInstallAccepted(QList<CSwordModuleInfo*>, QTreeWidget*)) );
+ // user checks/unchecks an item, needed for preventing double items
+ QObject::connect(treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), dlg, SLOT(slotItemChecked(QTreeWidgetItem*, int)));
+ dlg->exec();
+ // The OK signal sent by the dialog is catched with slotInstallAccepted.
}
-void BtSourceWidget::slotStopInstall(QTreeWidget* /*treeWidget*/)
-{
- qDebug() << "BtSourceWidget::slotStopInstall";
- // not needed?
+void BtSourceWidget::slotStopInstall(QTreeWidget* /*treeWidget*/) {
+ qDebug() << "BtSourceWidget::slotStopInstall";
+ // not needed?
}
-void BtSourceWidget::slotInstallAccepted(QList<CSwordModuleInfo*> /*modules*/, QTreeWidget* treeWidget)
-{
- qDebug() << "BtSourceWidget::slotInstallAccepted";
+void BtSourceWidget::slotInstallAccepted(QList<CSwordModuleInfo*> /*modules*/, QTreeWidget* treeWidget) {
+ qDebug() << "BtSourceWidget::slotInstallAccepted";
+
+ //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...)
- //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());
- BtModuleManagerDialog* parentDialog = dynamic_cast<BtModuleManagerDialog*>(dynamic_cast<BtInstallPage*>(parent())->parentDialog());
+ BtInstallProgressDialog* dlg = new BtInstallProgressDialog(parentDialog, treeWidget, dynamic_cast<BtInstallPage*>(parent())->selectedInstallPath());
- 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();
- 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 812c6ac..46b7d0a 100644
--- a/src/frontend/bookshelfmanager/installpage/btsourcewidget.h
+++ b/src/frontend/bookshelfmanager/installpage/btsourcewidget.h
@@ -27,60 +27,59 @@ class QTreeWidget;
* This widget implements the slots for the source action buttons and
* applies the actions to the proper source(s).
*/
-class BtSourceWidget : public QTabWidget
-{
- Q_OBJECT
-public:
- friend class BtInstallPage;
-
- BtSourceWidget(BtInstallPage* parent);
- virtual ~BtSourceWidget() {}
-
- BtSourceArea* area();
- QString currentSourceName();
-
-public slots:
- /** Install button has been clicked. */
- void slotInstall();
- /** "Stop All" button clicked */
- void slotStopInstall(QTreeWidget* treeWidget);
-
-private:
- void initSourceConnections();
- /** Add tabs/views for each source. */
- void initSources();
-
- /** Add one source to tabs/stack. */
- void addSource(const QString& sourceName);
-
-private slots:
-
- void slotRefresh();
-
- void slotRefreshCanceled();
-
- void slotRefreshCompleted(int, int);
-
- /** Edit button clicked. */
- void slotEdit();
- /** Delete button clicked. */
- void slotDelete();
- /** Add button clicked. */
- void slotAdd();
- /** Modules have been checked/unchecked in the view. */
- void slotModuleSelectionChanged(QString sourceName, int selectedCount);
-
- void slotTabSelected(int index);
- void slotInstallAccepted(QList<CSwordModuleInfo*> mi, QTreeWidget* treeWidget);
-
-
-
-private:
- QStringList m_sourceNameList;
- BtInstallPage* m_page;
- QProgressDialog* m_progressDialog; // for refreshing
- BtInstallMgr* m_currentInstallMgr; // for refreshing
- QMap<QString, int> m_selectedModulesCountMap;
+class BtSourceWidget : public QTabWidget {
+ Q_OBJECT
+ public:
+ friend class BtInstallPage;
+
+ BtSourceWidget(BtInstallPage* parent);
+ virtual ~BtSourceWidget() {}
+
+ BtSourceArea* area();
+ QString currentSourceName();
+
+ public slots:
+ /** Install button has been clicked. */
+ void slotInstall();
+ /** "Stop All" button clicked */
+ void slotStopInstall(QTreeWidget* treeWidget);
+
+ private:
+ void initSourceConnections();
+ /** Add tabs/views for each source. */
+ void initSources();
+
+ /** Add one source to tabs/stack. */
+ void addSource(const QString& sourceName);
+
+ private slots:
+
+ void slotRefresh();
+
+ void slotRefreshCanceled();
+
+ void slotRefreshCompleted(int, int);
+
+ /** Edit button clicked. */
+ void slotEdit();
+ /** Delete button clicked. */
+ void slotDelete();
+ /** Add button clicked. */
+ void slotAdd();
+ /** Modules have been checked/unchecked in the view. */
+ void slotModuleSelectionChanged(QString sourceName, int selectedCount);
+
+ void slotTabSelected(int index);
+ void slotInstallAccepted(QList<CSwordModuleInfo*> mi, QTreeWidget* treeWidget);
+
+
+
+ private:
+ QStringList m_sourceNameList;
+ BtInstallPage* m_page;
+ QProgressDialog* m_progressDialog; // for refreshing
+ BtInstallMgr* m_currentInstallMgr; // for refreshing
+ QMap<QString, int> m_selectedModulesCountMap;
};
#endif
diff --git a/src/frontend/bookshelfmanager/instbackend.cpp b/src/frontend/bookshelfmanager/instbackend.cpp
index f981f54..caf1e08 100644
--- a/src/frontend/bookshelfmanager/instbackend.cpp
+++ b/src/frontend/bookshelfmanager/instbackend.cpp
@@ -38,243 +38,231 @@ using namespace sword;
namespace instbackend {
/** Adds the source described by Source to the backend. */
-bool addSource(sword::InstallSource& source)
-{
- 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
- if (source.directory[ source.directory.length()-1 ] == '/') {
- source.directory--; //make one char shorter
- }
-
- config["Sources"].insert( std::make_pair(SWBuf("FTPSource"), source.getConfEnt()) );
- }
- else if (!strcmp(source.type, "DIR")) {
- config["Sources"].insert( std::make_pair(SWBuf("DIRSource"), source.getConfEnt()) );
- }
- config.Save();
- return true;
+bool addSource(sword::InstallSource& source) {
+ 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
+ if (source.directory[ source.directory.length()-1 ] == '/') {
+ source.directory--; //make one char shorter
+ }
+
+ config["Sources"].insert( std::make_pair(SWBuf("FTPSource"), source.getConfEnt()) );
+ }
+ else if (!strcmp(source.type, "DIR")) {
+ config["Sources"].insert( std::make_pair(SWBuf("DIRSource"), source.getConfEnt()) );
+ }
+ config.Save();
+ return true;
}
/** Returns the Source struct. */
-sword::InstallSource source(QString name)
-{
- qDebug("backend::source");
- BtInstallMgr mgr;
- InstallSourceMap::iterator source = mgr.sources.find(name.toLatin1().data());
- if (source != mgr.sources.end()) {
- return *(source->second);
- }
- else { //not found in Sword, may be a local DIR source
- SWConfig config(configFilename().toLatin1());
- SectionMap::iterator sourcesSection = config.Sections.find("Sources");
- if (sourcesSection != config.Sections.end()) {
- ConfigEntMap::iterator sourceBegin =
- sourcesSection->second.lower_bound("DIRSource");
- ConfigEntMap::iterator sourceEnd =
- sourcesSection->second.upper_bound("DIRSource");
-
- while (sourceBegin != sourceEnd) {
- InstallSource is("DIR", sourceBegin->second.c_str());
- if (!strcmp(is.caption, name.toLatin1()) ) { //found local dir source
- return is;
- }
-
- sourceBegin++;//next source
- }
- }
- }
-
- InstallSource is("EMPTY"); //default return value
- is.caption = "unknown caption";
- is.source = "unknown source";
- is.directory = "unknown dir";
- return is;
+sword::InstallSource source(QString name) {
+ qDebug("backend::source");
+ BtInstallMgr mgr;
+ InstallSourceMap::iterator source = mgr.sources.find(name.toLatin1().data());
+ if (source != mgr.sources.end()) {
+ return *(source->second);
+ }
+ else { //not found in Sword, may be a local DIR source
+ SWConfig config(configFilename().toLatin1());
+ SectionMap::iterator sourcesSection = config.Sections.find("Sources");
+ if (sourcesSection != config.Sections.end()) {
+ ConfigEntMap::iterator sourceBegin =
+ sourcesSection->second.lower_bound("DIRSource");
+ ConfigEntMap::iterator sourceEnd =
+ sourcesSection->second.upper_bound("DIRSource");
+
+ while (sourceBegin != sourceEnd) {
+ InstallSource is("DIR", sourceBegin->second.c_str());
+ if (!strcmp(is.caption, name.toLatin1()) ) { //found local dir source
+ return is;
+ }
+
+ sourceBegin++;//next source
+ }
+ }
+ }
+
+ InstallSource is("EMPTY"); //default return value
+ is.caption = "unknown caption";
+ is.source = "unknown source";
+ is.directory = "unknown dir";
+ return is;
}
/** Deletes the source. */
-bool deleteSource(QString name)
-{
- qDebug("backend::deleteSource");
- sword::InstallSource is = source(name );
-
- SWConfig config(configFilename().toLatin1());
-
- //this code can probably be shortened by using the stl remove_if functionality
- std::pair< ConfigEntMap::iterator, ConfigEntMap::iterator > range =
- isRemote(is)
- ? config["Sources"].equal_range("FTPSource")
- : config["Sources"].equal_range("DIRSource");
-
- ConfigEntMap::iterator it = range.first;
- while (it != range.second) {
- if (it->second == is.getConfEnt()) {
- // qWarning("found the source!");
- config["Sources"].erase(it);
- break;
- }
- ++it;
- }
-
- config.Save();
- return true; //TODO: dummy
+bool deleteSource(QString name) {
+ qDebug("backend::deleteSource");
+ sword::InstallSource is = source(name );
+
+ SWConfig config(configFilename().toLatin1());
+
+ //this code can probably be shortened by using the stl remove_if functionality
+ std::pair< ConfigEntMap::iterator, ConfigEntMap::iterator > range =
+ isRemote(is)
+ ? config["Sources"].equal_range("FTPSource")
+ : config["Sources"].equal_range("DIRSource");
+
+ ConfigEntMap::iterator it = range.first;
+ while (it != range.second) {
+ if (it->second == is.getConfEnt()) {
+ // qWarning("found the source!");
+ config["Sources"].erase(it);
+ break;
+ }
+ ++it;
+ }
+
+ config.Save();
+ 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
+bool refreshSource(QString /*name*/) {
+ // not possible until manager and progressdialog work together
+ 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
- return list;
+QList<CSwordModuleInfo*> moduleList(QString /*name*/) {
+ QList<CSwordModuleInfo*> list; //TODO: dummy
+ return list;
}
-bool isRemote(const sword::InstallSource& source)
-{
- return !strcmp(source.type, "FTP");
+bool isRemote(const sword::InstallSource& source) {
+ return !strcmp(source.type, "FTP");
}
const QString configPath() {
- const char *envhomedir = getenv("HOME");
- QString confPath = QString(envhomedir ? envhomedir : ".");
- confPath.append("/.sword/InstallMgr");
+ const char *envhomedir = getenv("HOME");
+ QString confPath = QString(envhomedir ? envhomedir : ".");
+ confPath.append("/.sword/InstallMgr");
- return confPath;
+ return confPath;
}
const QString configFilename() {
- return (configPath() + "/InstallMgr.conf");
+ return (configPath() + "/InstallMgr.conf");
}
-QStringList targetList()
-{
- qDebug("backend::targetList");
- QStringList names = CPointers::backend()->swordDirList();
- return names;
+QStringList targetList() {
+ qDebug("backend::targetList");
+ QStringList names = CPointers::backend()->swordDirList();
+ return names;
}
-bool setTargetList( const QStringList& targets )
-{
- 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");
- //bool directAccess = false;
- QString filename = swordConfigFilename();
- QFileInfo i(filename);
- QFileInfo dirInfo(i.absolutePath());
-
-
- if ( !i.exists() && dirInfo.isWritable() ) {
- // if the file doesn't exist but the parent is writable, create it
- qWarning() << "The Sword config file does not exist, it has to be created";
- QFile f(filename);
- f.open(QIODevice::WriteOnly);
- f.close();
- i.refresh();
- }
- if ( i.exists() && i.isWritable() ) { //we can write to the file ourself
- qDebug() << "The Sword config file is writable";
- } 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!"));
- return false;
- }
- SWConfig conf(filename.toLocal8Bit());
- conf.Sections.clear();
- 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") )) {
- //we don't want $HOME/.sword in the config
- continue;
- }
- else {
- qDebug() << "Add path to the conf file" << filename << ":" << t;
- conf["Install"].insert( std::make_pair(!setDataPath ? SWBuf("DataPath") : SWBuf("AugmentPath"), t.toLocal8Bit().data()) );
- setDataPath = true;
- }
- }
- qDebug() << "save the sword conf...";
- conf.Save();
- CPointers::backend()->reloadModules(CSwordBackend::PathChanged);
- return true;
+bool setTargetList( const QStringList& targets ) {
+ 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");
+ //bool directAccess = false;
+ QString filename = swordConfigFilename();
+ QFileInfo i(filename);
+ QFileInfo dirInfo(i.absolutePath());
+
+
+ if ( !i.exists() && dirInfo.isWritable() ) {
+ // if the file doesn't exist but the parent is writable, create it
+ qWarning() << "The Sword config file does not exist, it has to be created";
+ QFile f(filename);
+ f.open(QIODevice::WriteOnly);
+ f.close();
+ i.refresh();
+ }
+ if ( i.exists() && i.isWritable() ) { //we can write to the file ourself
+ qDebug() << "The Sword config file is writable";
+ }
+ 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!"));
+ return false;
+ }
+ SWConfig conf(filename.toLocal8Bit());
+ conf.Sections.clear();
+ 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") )) {
+ //we don't want $HOME/.sword in the config
+ continue;
+ }
+ else {
+ qDebug() << "Add path to the conf file" << filename << ":" << t;
+ conf["Install"].insert( std::make_pair(!setDataPath ? SWBuf("DataPath") : SWBuf("AugmentPath"), t.toLocal8Bit().data()) );
+ setDataPath = true;
+ }
+ }
+ qDebug() << "save the sword conf...";
+ conf.Save();
+ CPointers::backend()->reloadModules(CSwordBackend::PathChanged);
+ return true;
}
-QStringList sourceList()
-{
- qDebug("backend::sourceList");
- BtInstallMgr mgr;
- Q_ASSERT(mgr.installConf);
+QStringList sourceList() {
+ qDebug("backend::sourceList");
+ BtInstallMgr mgr;
+ Q_ASSERT(mgr.installConf);
- QStringList names;
+ QStringList names;
- //add Sword remote sources
- for (InstallSourceMap::iterator it = mgr.sources.begin(); it != mgr.sources.end(); it++) {
- names << QString::fromLocal8Bit(it->second->caption);
- }
+ //add Sword remote sources
+ for (InstallSourceMap::iterator it = mgr.sources.begin(); it != mgr.sources.end(); it++) {
+ names << QString::fromLocal8Bit(it->second->caption);
+ }
- // Add local directory sources
- SWConfig config(configFilename().toLatin1());
- sword::SectionMap::iterator sourcesSection = config.Sections.find("Sources");
- if (sourcesSection != config.Sections.end()) {
- sword::ConfigEntMap::iterator sourceBegin = sourcesSection->second.lower_bound("DIRSource");
- sword::ConfigEntMap::iterator sourceEnd = sourcesSection->second.upper_bound("DIRSource");
+ // Add local directory sources
+ SWConfig config(configFilename().toLatin1());
+ sword::SectionMap::iterator sourcesSection = config.Sections.find("Sources");
+ if (sourcesSection != config.Sections.end()) {
+ sword::ConfigEntMap::iterator sourceBegin = sourcesSection->second.lower_bound("DIRSource");
+ sword::ConfigEntMap::iterator sourceEnd = sourcesSection->second.upper_bound("DIRSource");
- while (sourceBegin != sourceEnd) {
- InstallSource is("DIR", sourceBegin->second.c_str());
- names << QString::fromLatin1(is.caption.c_str());
+ while (sourceBegin != sourceEnd) {
+ InstallSource is("DIR", sourceBegin->second.c_str());
+ names << QString::fromLatin1(is.caption.c_str());
- sourceBegin++;
- }
- }
+ sourceBegin++;
+ }
+ }
- return names;
+ return names;
}
-void initPassiveFtpMode()
-{
- qDebug("backend::initPassiveFtpMode");
- SWConfig config(configFilename().toLatin1());
- config["General"]["PassiveFTP"] = "true";
- config.Save();
+void 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");
+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");
}
-const QDir swordDir()
-{
- return QDir(util::filesystem::DirectoryUtil::getUserHomeDir().absolutePath().append("/.sword/"));
+const QDir swordDir() {
+ return QDir(util::filesystem::DirectoryUtil::getUserHomeDir().absolutePath().append("/.sword/"));
}
-CSwordBackend* backend( const sword::InstallSource& is)
-{
- qDebug("backend::backend");
- CSwordBackend* ret = 0;
- if (isRemote(is)) {
- ret = new CSwordBackend( QString(is.localShadow.c_str()), false );
- }
- else {
- ret = new CSwordBackend( QString(is.directory.c_str()), false);
- }
-
- Q_ASSERT(ret);
- if (ret) {
- ret->initModules(CSwordBackend::OtherChange);
- }
- return ret;
+CSwordBackend* backend( const sword::InstallSource& is) {
+ qDebug("backend::backend");
+ CSwordBackend* ret = 0;
+ if (isRemote(is)) {
+ ret = new CSwordBackend( QString(is.localShadow.c_str()), false );
+ }
+ else {
+ ret = new CSwordBackend( QString(is.directory.c_str()), false);
+ }
+
+ Q_ASSERT(ret);
+ if (ret) {
+ ret->initModules(CSwordBackend::OtherChange);
+ }
+ return ret;
}
}
diff --git a/src/frontend/bookshelfmanager/removepage/btremovepage.cpp b/src/frontend/bookshelfmanager/removepage/btremovepage.cpp
index c4324e3..cd8f687 100644
--- a/src/frontend/bookshelfmanager/removepage/btremovepage.cpp
+++ b/src/frontend/bookshelfmanager/removepage/btremovepage.cpp
@@ -38,192 +38,184 @@
BtRemovePage::BtRemovePage()
- : BtConfigPage()
-{
- QGridLayout* layout = new QGridLayout(this);
- layout->setMargin(5);
-
- layout->setSpacing(10);
- layout->setColumnStretch(1,1);
- layout->setRowStretch(2,1);
-
- m_view = new QTreeWidget(this);
- m_view->setHeaderLabels(QStringList() << tr("Work") << tr("Install path"));
- m_view->setColumnWidth(0, CToolClass::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->setEnabled(false);
- layout->addWidget(m_removeButton, 3, 1, Qt::AlignRight);
-
- connect(m_view, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), SLOT(slotItemDoubleClicked(QTreeWidgetItem*, int)));
- connect(m_removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveModules()));
- connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(slotSwordSetupChanged()));
- populateModuleList();
+ : BtConfigPage() {
+ QGridLayout* layout = new QGridLayout(this);
+ layout->setMargin(5);
+
+ layout->setSpacing(10);
+ layout->setColumnStretch(1, 1);
+ layout->setRowStretch(2, 1);
+
+ m_view = new QTreeWidget(this);
+ m_view->setHeaderLabels(QStringList() << tr("Work") << tr("Install path"));
+ m_view->setColumnWidth(0, CToolClass::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->setEnabled(false);
+ layout->addWidget(m_removeButton, 3, 1, Qt::AlignRight);
+
+ connect(m_view, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), SLOT(slotItemDoubleClicked(QTreeWidgetItem*, int)));
+ connect(m_removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveModules()));
+ connect(CPointers::backend(), SIGNAL(sigSwordSetupChanged(CSwordBackend::SetupChangedReason)), SLOT(slotSwordSetupChanged()));
+ populateModuleList();
}
-QString BtRemovePage::label()
-{
- return tr("Remove installed works. Select the works and click Remove button.");
+QString BtRemovePage::label() {
+ return tr("Remove installed works. Select the works and click Remove button.");
}
-QString BtRemovePage::iconName()
-{
- return CResMgr::bookshelfmgr::removepage::icon;
+QString BtRemovePage::iconName() {
+ return CResMgr::bookshelfmgr::removepage::icon;
}
-QString BtRemovePage::header()
-{
- return tr("Remove");
+QString BtRemovePage::header() {
+ return tr("Remove");
}
-void BtRemovePage::populateModuleList()
-{
+void BtRemovePage::populateModuleList() {
- m_view->clear();
- m_selectedModules.clear();
+ m_view->clear();
+ m_selectedModules.clear();
- // disconnect the signal so that we don't have to run functions for every module
- disconnect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) );
+ // disconnect the signal so that we don't have to run functions for every module
+ disconnect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) );
- QList<BTModuleTreeItem::Filter*> empty;
- BTModuleTreeItem rootItem(empty, (BTModuleTreeItem::Grouping)CBTConfig::get(CBTConfig::bookshelfGrouping));
- addToTree(&rootItem, m_view->invisibleRootItem());
+ QList<BTModuleTreeItem::Filter*> empty;
+ BTModuleTreeItem rootItem(empty, (BTModuleTreeItem::Grouping)CBTConfig::get(CBTConfig::bookshelfGrouping));
+ addToTree(&rootItem, m_view->invisibleRootItem());
- // receive signal when user checks modules
- connect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) );
- qDebug("BtSourceArea::createModuleTree end");
+ // receive signal when user checks modules
+ connect(m_view, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(slotSelectionChanged(QTreeWidgetItem*, int)) );
+ qDebug("BtSourceArea::createModuleTree end");
}
-void BtRemovePage::addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem)
-{
- //qDebug()<<"BtRemovePage::addToTree "<<item->text();
- //qDebug() << "BTMTItem type: " << item->type();
-
- foreach (BTModuleTreeItem* i, item->children()) {
- addToTree(i, new QTreeWidgetItem(widgetItem));
- }
- if (item->type() != BTModuleTreeItem::Root) {
- CSwordModuleInfo* mInfo = item->moduleInfo();
- widgetItem->setText(0, item->text());
- if (item->type() == BTModuleTreeItem::Category || item->type() == BTModuleTreeItem::Language) {
- //qDebug() << "item"<<item->text()<< "was cat or lang";
- widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
- }
- if (item->type() == BTModuleTreeItem::Module) {
- //qDebug() << "item"<<item->text()<< "was a module";
- widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
- widgetItem->setCheckState(0, Qt::Unchecked);
-
- //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);
- widgetItem->setText(1, descr);
- widgetItem->setToolTip(0, toolTipText);
- widgetItem->setToolTip(1, descr);
- }
- }
+void BtRemovePage::addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem) {
+ //qDebug()<<"BtRemovePage::addToTree "<<item->text();
+ //qDebug() << "BTMTItem type: " << item->type();
+
+ foreach (BTModuleTreeItem* i, item->children()) {
+ addToTree(i, new QTreeWidgetItem(widgetItem));
+ }
+ if (item->type() != BTModuleTreeItem::Root) {
+ CSwordModuleInfo* mInfo = item->moduleInfo();
+ widgetItem->setText(0, item->text());
+ if (item->type() == BTModuleTreeItem::Category || item->type() == BTModuleTreeItem::Language) {
+ //qDebug() << "item"<<item->text()<< "was cat or lang";
+ widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsTristate);
+ }
+ if (item->type() == BTModuleTreeItem::Module) {
+ //qDebug() << "item"<<item->text()<< "was a module";
+ widgetItem->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
+ widgetItem->setCheckState(0, Qt::Unchecked);
+
+ //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);
+ widgetItem->setText(1, descr);
+ widgetItem->setToolTip(0, toolTipText);
+ widgetItem->setToolTip(1, descr);
+ }
+ }
}
-void BtRemovePage::slotRemoveModules()
-{
- if ( m_selectedModules.empty() ) {
- return; //no message, just do nothing
- }
-
- QStringList moduleNames;
- foreach (CSwordModuleInfo* m, m_selectedModules) {
- moduleNames.append(m->name());
- }
- const QString message = tr("You selected the following work(s): ")
- .append(moduleNames.join(", "))
- .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.
-
- // Update the module list before really removing. Remember deleting the pointers later.
- QList<CSwordModuleInfo*> toBeDeleted = CPointers::backend()->takeModulesFromList(moduleNames);
-
- sword::InstallMgr installMgr;
- QMap<QString, sword::SWMgr*> mgrDict; //maps config paths to SWMgr objects
- foreach ( CSwordModuleInfo* mInfo, toBeDeleted ) {
- Q_ASSERT(mInfo); // Only installed modules could have been selected and returned by takeModulesFromList
- // Find the install path for the sword manager
- QString prefixPath = mInfo->config(CSwordModuleInfo::AbsoluteDataPath) + "/";
- QString dataPath = mInfo->config(CSwordModuleInfo::DataPath);
- if (dataPath.left(2) == "./") {
- dataPath = dataPath.mid(2);
- }
- if (prefixPath.contains(dataPath)) { //remove module part to get the prefix path
- prefixPath = prefixPath.remove( prefixPath.indexOf(dataPath), dataPath.length() );
- }
- else { //This is an error, should not happen
- qWarning() << "Removing" << mInfo->name() << "didn't succeed because the absolute path" << prefixPath << "didn't contain the data path" << dataPath;
- continue; // don't remove this, go to next of the for loop
- }
-
- // Create the sword manager and remove the module
- sword::SWMgr* mgr = mgrDict[ prefixPath ];
- if (!mgr) { //create new mgr if it's not yet available
- mgrDict.insert(prefixPath, new sword::SWMgr(prefixPath.toLocal8Bit()));
- mgr = mgrDict[ prefixPath ];
- }
- qDebug() << "Removing the module"<< mInfo->name() << "...";
- installMgr.removeModule(mgr, mInfo->module()->Name());
- }
- //delete the removed moduleinfo pointers
- qDeleteAll(toBeDeleted);
- //delete all mgrs which were created above
- qDeleteAll(mgrDict);
- mgrDict.clear();
- }
+void BtRemovePage::slotRemoveModules() {
+ if ( m_selectedModules.empty() ) {
+ return; //no message, just do nothing
+ }
+
+ QStringList moduleNames;
+ foreach (CSwordModuleInfo* m, m_selectedModules) {
+ moduleNames.append(m->name());
+ }
+ const QString message = tr("You selected the following work(s): ")
+ .append(moduleNames.join(", "))
+ .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.
+
+ // Update the module list before really removing. Remember deleting the pointers later.
+ QList<CSwordModuleInfo*> toBeDeleted = CPointers::backend()->takeModulesFromList(moduleNames);
+
+ sword::InstallMgr installMgr;
+ QMap<QString, sword::SWMgr*> mgrDict; //maps config paths to SWMgr objects
+ foreach ( CSwordModuleInfo* mInfo, toBeDeleted ) {
+ Q_ASSERT(mInfo); // Only installed modules could have been selected and returned by takeModulesFromList
+ // Find the install path for the sword manager
+ QString prefixPath = mInfo->config(CSwordModuleInfo::AbsoluteDataPath) + "/";
+ QString dataPath = mInfo->config(CSwordModuleInfo::DataPath);
+ if (dataPath.left(2) == "./") {
+ dataPath = dataPath.mid(2);
+ }
+ if (prefixPath.contains(dataPath)) { //remove module part to get the prefix path
+ prefixPath = prefixPath.remove( prefixPath.indexOf(dataPath), dataPath.length() );
+ }
+ else { //This is an error, should not happen
+ qWarning() << "Removing" << mInfo->name() << "didn't succeed because the absolute path" << prefixPath << "didn't contain the data path" << dataPath;
+ continue; // don't remove this, go to next of the for loop
+ }
+
+ // Create the sword manager and remove the module
+ sword::SWMgr* mgr = mgrDict[ prefixPath ];
+ if (!mgr) { //create new mgr if it's not yet available
+ mgrDict.insert(prefixPath, new sword::SWMgr(prefixPath.toLocal8Bit()));
+ mgr = mgrDict[ prefixPath ];
+ }
+ qDebug() << "Removing the module" << mInfo->name() << "...";
+ installMgr.removeModule(mgr, mInfo->module()->Name());
+ }
+ //delete the removed moduleinfo pointers
+ qDeleteAll(toBeDeleted);
+ //delete all mgrs which were created above
+ qDeleteAll(mgrDict);
+ mgrDict.clear();
+ }
}
-void BtRemovePage::slotSelectionChanged(QTreeWidgetItem* item, int column)
-{
- //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");
- foreach (CSwordModuleInfo* module, CPointers::backend()->moduleList()) {
- if (module->name() == item->text(0) && module->config(CSwordModuleInfo::AbsoluteDataPath) == item->text(1)) {
- mInfo = module;
- break;
- }
- }
- Q_ASSERT(mInfo); // this should have been found
- if (item->checkState(0) == Qt::Checked) {
- //qDebug() << item->text(0) << "in" << item->text(1) << "was checked";
- m_selectedModules.append(mInfo);
- } else {
- //qDebug() << mInfo->name() << "was unchecked";
- m_selectedModules.removeAll(mInfo); // there is only one, it's a pointer
- }
-
- if (m_selectedModules.count() > 0) {
- m_removeButton->setEnabled(true);
- } else {
- m_removeButton->setEnabled(false);
- }
- }
+void BtRemovePage::slotSelectionChanged(QTreeWidgetItem* item, int column) {
+ //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");
+ foreach (CSwordModuleInfo* module, CPointers::backend()->moduleList()) {
+ if (module->name() == item->text(0) && module->config(CSwordModuleInfo::AbsoluteDataPath) == item->text(1)) {
+ mInfo = module;
+ break;
+ }
+ }
+ Q_ASSERT(mInfo); // this should have been found
+ if (item->checkState(0) == Qt::Checked) {
+ //qDebug() << item->text(0) << "in" << item->text(1) << "was checked";
+ m_selectedModules.append(mInfo);
+ }
+ else {
+ //qDebug() << mInfo->name() << "was unchecked";
+ m_selectedModules.removeAll(mInfo); // there is only one, it's a pointer
+ }
+
+ if (m_selectedModules.count() > 0) {
+ m_removeButton->setEnabled(true);
+ }
+ else {
+ m_removeButton->setEnabled(false);
+ }
+ }
}
-void BtRemovePage::slotItemDoubleClicked(QTreeWidgetItem* /*item*/, int /*column*/)
-{
- // TODO: Open the About dialog.
+void BtRemovePage::slotItemDoubleClicked(QTreeWidgetItem* /*item*/, int /*column*/) {
+ // TODO: Open the About dialog.
}
-void BtRemovePage::slotSwordSetupChanged()
-{
- populateModuleList();
+void BtRemovePage::slotSwordSetupChanged() {
+ populateModuleList();
}
diff --git a/src/frontend/bookshelfmanager/removepage/btremovepage.h b/src/frontend/bookshelfmanager/removepage/btremovepage.h
index 046534c..782fcc0 100644
--- a/src/frontend/bookshelfmanager/removepage/btremovepage.h
+++ b/src/frontend/bookshelfmanager/removepage/btremovepage.h
@@ -24,44 +24,43 @@ class QTreeWidgetItem;
class QPushButton;
-class BtRemovePage : public BtConfigPage
-{
- Q_OBJECT
+class BtRemovePage : public BtConfigPage {
+ Q_OBJECT
-public:
- BtRemovePage();
+ public:
+ BtRemovePage();
- ~BtRemovePage(){}
+ ~BtRemovePage() {}
- // BtConfigPage methods
- QString header();
- QString iconName();
- QString label();
+ // BtConfigPage methods
+ QString header();
+ QString iconName();
+ QString label();
- void populateModuleList();
+ void populateModuleList();
//signals:
- //void swordSetupChanged();
+ //void swordSetupChanged();
-public slots:
- void slotSwordSetupChanged();
+ public slots:
+ void slotSwordSetupChanged();
-private slots:
+ private slots:
- void slotRemoveModules();
- /** Handles activating the Remove button. */
- void slotSelectionChanged(QTreeWidgetItem* item, int column);
- void slotItemDoubleClicked(QTreeWidgetItem* item, int column);
+ void slotRemoveModules();
+ /** Handles activating the Remove button. */
+ void slotSelectionChanged(QTreeWidgetItem* item, int column);
+ void slotItemDoubleClicked(QTreeWidgetItem* item, int column);
-private: // methods
- void addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem);
+ private: // methods
+ void addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem);
+
+ private: // data
+ QTreeWidget* m_view;
+ QPushButton* m_removeButton;
+ /** Map of module name and install path (absolute path from the moduleinfo config entry).*/
+ QList<CSwordModuleInfo*> m_selectedModules;
-private: // data
- QTreeWidget* m_view;
- QPushButton* m_removeButton;
- /** Map of module name and install path (absolute path from the moduleinfo config entry).*/
- QList<CSwordModuleInfo*> m_selectedModules;
-
};
#endif