diff options
Diffstat (limited to 'src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp')
-rw-r--r-- | src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp | 171 |
1 files changed, 90 insertions, 81 deletions
diff --git a/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp b/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp index f18935a..8c43837 100644 --- a/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp +++ b/src/frontend/bookshelfmanager/installpage/btsourcewidget.cpp @@ -7,44 +7,42 @@ * **********/ -#include "btsourcewidget.h" +#include "frontend/bookshelfmanager/installpage/btsourcewidget.h" -#include "btinstallpage.h" -#include "btsourcearea.h" -#include "btinstallprogressdialog.h" -#include "btinstallmodulechooserdialog.h" - -#include "frontend/bookshelfmanager/btmodulemanagerdialog.h" -#include "frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h" -#include "frontend/bookshelfmanager/btinstallmgr.h" -#include "frontend/bookshelfmanager/instbackend.h" - - -#include <QString> -#include <QWidget> -#include <QTabWidget> -#include <QMessageBox> -#include <QProgressDialog> -#include <QPushButton> #include <QApplication> #include <QFileInfo> +#include <QHBoxLayout> +#include <QLabel> +#include <QProgressDialog> +#include <QPushButton> +#include <QString> #include <QTabBar> +#include <QTabWidget> #include <QTreeWidget> #include <QTreeWidgetItem> -#include <QHBoxLayout> -#include <QLabel> +#include <QWidget> +#include "frontend/bookshelfmanager/btinstallmgr.h" +#include "frontend/bookshelfmanager/btmodulemanagerdialog.h" +#include "frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h" +#include "frontend/bookshelfmanager/installpage/btinstallmodulechooserdialog.h" +#include "frontend/bookshelfmanager/installpage/btinstallpage.h" +#include "frontend/bookshelfmanager/installpage/btinstallprogressdialog.h" +#include "frontend/bookshelfmanager/installpage/btsourcearea.h" +#include "frontend/bookshelfmanager/instbackend.h" +#include "util/dialogutil.h" -// **************************************************************** -// ******** Tab Widget that holds source widgets ****************** -// **************************************************************** +/** +* Tab Widget that holds source widgets +*/ BtSourceWidget::BtSourceWidget(BtInstallPage* parent) : QTabWidget(parent), m_page(parent) { - qDebug("BtSourceWidget::BtSourceWidget start"); + qDebug() << "BtSourceWidget::BtSourceWidget start"; initSources(); - - // TODO: choose the page from config + // send queued event because "Delete" is initiated from tab which should be deleted + connect(this, SIGNAL(sigInitSources()), SLOT(initSources()), Qt::QueuedConnection); + /// \todo choose the page from config } @@ -58,56 +56,57 @@ QString BtSourceWidget::currentSourceName() { } void BtSourceWidget::initSourceConnections() { - qDebug("void BtSourceWidget::initSourceConnections() start"); + qDebug() << "void BtSourceWidget::initSourceConnections() start"; if (area()) { connect(area()->m_refreshButton, SIGNAL(clicked()), SLOT(slotRefresh())); //connect(area()->m_editButton, SIGNAL(clicked()), SLOT(slotEdit())); - connect(area()->m_deleteButton, SIGNAL(clicked()), SLOT(slotDelete())); + connect(area()->m_deleteButton, SIGNAL(clicked()), SLOT(slotDelete()), Qt::QueuedConnection); connect(area()->m_addButton, SIGNAL(clicked()), SLOT(slotAdd())); connect(area(), SIGNAL(signalSelectionChanged(QString, int)), SLOT(slotModuleSelectionChanged(QString, int)) ); } - qDebug("void BtSourceWidget::initSourceConnections() end"); + qDebug() << "void BtSourceWidget::initSourceConnections() end"; } void BtSourceWidget::slotEdit() { - qDebug("BtSourceWidget::slotEdit"); - // open the source editor dialog + qDebug() << "BtSourceWidget::slotEdit"; + /// \todo open the source editor dialog // if the source was changed, init the sources } void BtSourceWidget::slotDelete() { - qDebug("void BtSourceWidget::slotDelete() start"); + qDebug() << "void BtSourceWidget::slotDelete() start"; // ask for confirmation - int ret = QMessageBox::warning(this, tr("Delete Source?"), - tr("Do you really want to delete this source?"), - QMessageBox::Yes | QMessageBox::No); + int ret = util::showWarning(this, tr("Delete Source?"), + tr("Do you really want to delete this source?"), + QMessageBox::Yes | QMessageBox::No); if (ret == QMessageBox::Yes) { instbackend::deleteSource(currentSourceName()); - - // remove the UI elements - m_sourceNameList.removeAt(currentIndex()); - QWidget* w = currentWidget(); - removeTab(currentIndex()); - delete w; + initSources(); } } void BtSourceWidget::slotAdd() { - qDebug("void BtSourceWidget::slotAdd() start"); - qDebug("open the old dialog, TODO: write new one"); - sword::InstallSource newSource = CSwordSetupInstallSourcesDialog::getSource(); - if ( !((QString)newSource.type.c_str()).isEmpty() ) { // we have a valid source to add - instbackend::addSource(newSource); - addSource(QString(newSource.caption.c_str())); + + boost::scoped_ptr<CSwordSetupInstallSourcesDialog> dlg( new CSwordSetupInstallSourcesDialog() ); + sword::InstallSource newSource(""); //empty, invalid Source + + if (dlg->exec() == QDialog::Accepted) { + if (!dlg->wasRemoteListAdded()) { + newSource = dlg->getSource(); + if ( !((QString)newSource.type.c_str()).isEmpty() ) { // we have a valid source to add + instbackend::addSource(newSource); + } + } + initSources(); } } void BtSourceWidget::slotRefresh() { - qDebug("void BtSourceWidget::slotRefresh() start"); + qDebug() << "void BtSourceWidget::slotRefresh() start"; // (re)build the module cache for the source QString sourceName = currentSourceName(); @@ -117,18 +116,18 @@ void BtSourceWidget::slotRefresh() { m_progressDialog->setWindowTitle(tr("Refreshing Source")); m_progressDialog->setMinimumDuration(0); - // TODO: get rid of the backend code, BtInstallMgr and progressdialog could handle this + /// \todo get rid of the backend code, BtInstallMgr and progressdialog could handle this //write method BtInstallMgr::slotRefreshCanceled() connect(m_progressDialog, SIGNAL(canceled()), SLOT(slotRefreshCanceled())); // BACKEND CODE ********************************************************** // would this be possible: instbackend::refreshSource( arguments ); - qDebug("void BtSourceWidget::slotRefresh 1"); + qDebug() << "void BtSourceWidget::slotRefresh 1"; BtInstallMgr iMgr; m_currentInstallMgr = &iMgr; //for the progress dialog sword::InstallSource is = instbackend::source(sourceName); bool success = false; - qDebug("void BtSourceWidget::slotRefresh 2"); + qDebug() << "void BtSourceWidget::slotRefresh 2"; // connect this directly to the dialog setValue(int) if possible connect(&iMgr, SIGNAL(percentCompleted(const int, const int)), SLOT(slotRefreshCompleted(const int, const int))); @@ -139,11 +138,7 @@ void BtSourceWidget::slotRefresh() { m_progressDialog->setLabelText(tr("Connecting...")); m_progressDialog->setValue(0); qApp->processEvents(); - //qApp->flush(); - //qApp->processEvents(); - //m_progressDialog->repaint(); - //qApp->processEvents(); - qDebug("void BtSourceWidget::slotRefresh 3"); + qDebug() << "void BtSourceWidget::slotRefresh 3"; bool successful = iMgr.refreshRemoteSource( &is ); if (!successful ) { //make sure the sources were updated sucessfully success = true; @@ -164,14 +159,14 @@ void BtSourceWidget::slotRefresh() { // rebuild the view tree and refresh the view if (success) { - qDebug("void BtSourceWidget::slotRefresh 4"); + qDebug() << "void BtSourceWidget::slotRefresh 4"; area()->createModuleTree(); } } -//TODO: try to move this to BtInstallMgr +/// \todo try to move this to BtInstallMgr void BtSourceWidget::slotRefreshCanceled() { - qDebug("BtSourceWidget::slotRefreshCanceled"); + qDebug() << "BtSourceWidget::slotRefreshCanceled"; Q_ASSERT(m_currentInstallMgr); if (m_currentInstallMgr) { m_currentInstallMgr->terminate(); @@ -179,9 +174,9 @@ void BtSourceWidget::slotRefreshCanceled() { qApp->processEvents(); } -//TODO: try to move this to progress dialog +/// \todo try to move this to progress dialog void BtSourceWidget::slotRefreshCompleted(const int, const int current) { - qDebug("BtSourceWidget::slotRefreshCompleted"); + qDebug() << "BtSourceWidget::slotRefreshCompleted"; if (m_progressDialog) { if (m_progressDialog->labelText() != tr("Refreshing...")) { m_progressDialog->setLabelText(tr("Refreshing...")); @@ -193,18 +188,32 @@ void BtSourceWidget::slotRefreshCompleted(const int, const int current) { // init the tabbar, setup the module tree for the current source void BtSourceWidget::initSources() { - qDebug("void BtSourceWidget::initSources() start"); + qDebug() << "void BtSourceWidget::initSources() start"; + + //first clear all sources + //int i = count(); + for (int i = count()-1; i >= 0; i--) { + BtSourceArea* a = dynamic_cast<BtSourceArea*>(widget(i)); + a->prepareRemove(); + } + for (int i = count()-1; i >= 0; i--) { + qDebug() << "remove tab"<<tabText(i); + QWidget* w = widget(i); + removeTab(i); + delete w; + qDebug() << "deleted"; + } + m_sourceNameList.clear(); // ***** Use the backend to get the list of sources ***** instbackend::initPassiveFtpMode(); QStringList sourceList = instbackend::sourceList(); - + qDebug() << "got the source list from backend:" << sourceList; // Add a default entry, the Crosswire main repository - // TODO: this is easy for the user, but should the edit dialog - // open automatically? if (!sourceList.count()) { + /// \todo Open a dialog which asks whether to get list from server and add sources sword::InstallSource is("FTP"); //default return value - is.caption = "Crosswire"; + is.caption = "CrossWire Bible Society"; is.source = "ftp.crosswire.org"; is.directory = "/pub/sword/raw"; // passive ftp is not needed here, it's the default @@ -214,7 +223,7 @@ void BtSourceWidget::initSources() { sourceList = instbackend::sourceList(); //Q_ASSERT( sourceList.count() > 0 ); } - qDebug("void BtSourceWidget::initSources 1"); + qDebug() << "void BtSourceWidget::initSources 1"; // Add the sources to the widget foreach (QString sourceName, sourceList) { addSource(sourceName); @@ -222,8 +231,8 @@ void BtSourceWidget::initSources() { // connect this after the tabs have been created, // otherwise the signal is caught too early. QObject::connect(this, SIGNAL(currentChanged(int)), this, SLOT(slotTabSelected(int))); - qDebug("void BtSourceWidget::initSources end"); - // TODO: select the current source from the config + qDebug() << "void BtSourceWidget::initSources end"; + /// \todo select the current source from the config // It's important to choose something because the tree is not initialized until now setCurrentIndex(0); slotTabSelected(0); // setting the index wasn't enough if there were only 1 tab @@ -237,7 +246,7 @@ void BtSourceWidget::initSources() { } void BtSourceWidget::addSource(const QString& sourceName) { - qDebug("void BtSourceWidget::addSource(const QString& sourceName) start"); + qDebug() << "void BtSourceWidget::addSource(const QString& sourceName) start, with name" << sourceName; // The source has already been added to the backend. QString type; @@ -254,10 +263,10 @@ void BtSourceWidget::addSource(const QString& sourceName) { QFileInfo fi( is.directory.c_str() ); path = is.directory.c_str(); if (!(fi.isDir() )) { - path = path + QString(" ") + tr("Not a directory!"); //TODO: change this + path = path + QString(" ") + tr("Not a directory!"); /// \todo change this } if (!fi.isReadable()) { - path = path + QString(" ") + tr("Not readable!"); //TODO: change this + path = path + QString(" ") + tr("Not readable!"); /// \todo change this } } @@ -265,7 +274,7 @@ void BtSourceWidget::addSource(const QString& sourceName) { BtSourceArea* area = new BtSourceArea(sourceName); int tabNumber = this->addTab(area, sourceName); - // TODO: add "remote/local", server, path etc. + /// \todo add "remote/local", server, path etc. QString toolTip(QString("<p style='white-space:pre'>") + sourceName + QString("<br/><b>") + type + QString("</b> ") + server + path + QString("</p>")); tabBar()->setTabToolTip(tabNumber, toolTip); @@ -273,13 +282,13 @@ void BtSourceWidget::addSource(const QString& sourceName) { setCurrentIndex(tabNumber); m_sourceNameList.append(sourceName); initSourceConnections(); - qDebug("BtSourceWidget::addSource end"); + qDebug() << "BtSourceWidget::addSource end"; } // void BtSourceWidget::slotModuleSelectionChanged(QString sourceName, int selectedCount) { - //TODO: editing sources should update the map also - qDebug("BtSourceWidget::slotModuleSelectionChanged start"); + /// \todo editing sources should update the map also + qDebug() << "BtSourceWidget::slotModuleSelectionChanged start"; int overallCount = 0; m_selectedModulesCountMap.insert(sourceName, selectedCount); @@ -302,7 +311,7 @@ void BtSourceWidget::slotTabSelected(int /*index*/) { } void BtSourceWidget::slotInstall() { - qDebug("void BtInstallPage::slotInstall start"); + qDebug() << "void BtInstallPage::slotInstall start"; // check that the destination path is writable, do nothing if not and user doesn't want to continue QDir dir = QDir(dynamic_cast<BtInstallPage*>(parent())->selectedInstallPath()); @@ -317,7 +326,7 @@ void BtSourceWidget::slotInstall() { canWrite = false; } if (!canWrite) { - const int result = QMessageBox::warning(this, tr("Warning"), tr("The destination directory is not writable or does not exist. Installation will fail unless this has first been fixed."), QMessageBox::Ignore | QMessageBox::Cancel, QMessageBox::Cancel); + const int result = util::showWarning(this, tr("Warning"), tr("The destination directory is not writable or does not exist. Installation will fail unless this has first been fixed."), QMessageBox::Ignore | QMessageBox::Cancel, QMessageBox::Cancel); if (result != QMessageBox::Ignore) { return; } @@ -373,18 +382,18 @@ void BtSourceWidget::slotStopInstall(QTreeWidget* /*treeWidget*/) { void BtSourceWidget::slotInstallAccepted(QList<CSwordModuleInfo*> /*modules*/, QTreeWidget* treeWidget) { qDebug() << "BtSourceWidget::slotInstallAccepted"; - //TODO: first remove all modules which will be updated from the module list + /// \todo first remove all modules which will be updated from the module list // but what modules? all with the same real name? (there may be _n modules...) BtModuleManagerDialog* parentDialog = dynamic_cast<BtModuleManagerDialog*>(dynamic_cast<BtInstallPage*>(parent())->parentDialog()); BtInstallProgressDialog* dlg = new BtInstallProgressDialog(parentDialog, treeWidget, dynamic_cast<BtInstallPage*>(parent())->selectedInstallPath()); - if (!parentDialog) qDebug("error, wrong parent!"); + if (!parentDialog) qDebug() << "error, wrong parent!"; m_page->setInstallEnabled(false); // the progress dialog is now modal, it can be made modeless later. dlg->exec(); - qDebug("BtSourceWidget::slotInstallAccepted end"); + qDebug() << "BtSourceWidget::slotInstallAccepted end"; } |