summaryrefslogtreecommitdiff
path: root/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp')
-rw-r--r--src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp157
1 files changed, 104 insertions, 53 deletions
diff --git a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp b/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp
index eca4498..47e274c 100644
--- a/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp
+++ b/src/frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.cpp
@@ -7,35 +7,33 @@
*
**********/
-//BT includes
-#include "cswordsetupinstallsourcesdialog.h"
-
-#include "frontend/bookshelfmanager/instbackend.h"
+#include "frontend/bookshelfmanager/cswordsetupinstallsourcesdialog.h"
#include <boost/scoped_ptr.hpp>
-
-//Qt includes
-#include <QLayout>
-#include <QLabel>
#include <QComboBox>
-#include <QLineEdit>
-#include <QPushButton>
-#include <QMessageBox>
+#include <QDir>
#include <QFileInfo>
+#include <QFileDialog>
#include <QGridLayout>
#include <QHBoxLayout>
+#include <QLabel>
+#include <QLayout>
+#include <QLineEdit>
+#include <QPushButton>
#include <QVBoxLayout>
-#include <QFileDialog>
-#include <QDir>
-
-
+#include <QDialogButtonBox>
+#include <QProgressDialog>
+#include <QApplication>
+#include <QDebug>
+#include "frontend/bookshelfmanager/instbackend.h"
+#include "util/dialogutil.h"
const QString PROTO_FILE( QObject::tr("Local") ); //Local path
const QString PROTO_FTP( QObject::tr("Remote") ); //Remote path
-
CSwordSetupInstallSourcesDialog::CSwordSetupInstallSourcesDialog(/*QWidget *parent*/)
- : QDialog() {
+ : QDialog(),
+ m_remoteListAdded(false) {
setWindowTitle(tr("New Installation Source"));
QVBoxLayout* mainLayout = new QVBoxLayout( this );
@@ -48,7 +46,7 @@ CSwordSetupInstallSourcesDialog::CSwordSetupInstallSourcesDialog(/*QWidget *pare
captionLayout->addWidget( label );
m_captionEdit = new QLineEdit( this );
- m_captionEdit->setText("Crosswire Bible Society");
+ m_captionEdit->setText("CrossWire Bible Society");
captionLayout->addWidget( m_captionEdit );
mainLayout->addSpacing( 10 );
@@ -83,24 +81,22 @@ CSwordSetupInstallSourcesDialog::CSwordSetupInstallSourcesDialog(/*QWidget *pare
mainLayout->addSpacing( 10 );
- QHBoxLayout* buttonLayout = new QHBoxLayout( this );
- mainLayout->addLayout(buttonLayout);
- buttonLayout->addStretch();
- QPushButton* okButton = new QPushButton( tr("Ok"), this);
- QPushButton* discardButton = new QPushButton( tr("Discard"), this);
- buttonLayout->addWidget( discardButton);
- buttonLayout->addWidget( okButton);
- buttonLayout->addStretch();
-
- connect( okButton, SIGNAL( clicked() ), this, SLOT( slotOk() ) );
- connect( discardButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
+ QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Save, Qt::Horizontal, this);
+ util::prepareDialogBox(buttonBox);
+ QPushButton* getListButton = new QPushButton(tr("Get list..."), this);
+ getListButton->setToolTip(tr("Download a list of sources from CrossWire server and add sources"));
+ buttonBox->addButton(getListButton, QDialogButtonBox::ActionRole);
+ connect(getListButton, SIGNAL(clicked()), SLOT(slotGetListClicked()));
+ mainLayout->addWidget(buttonBox);
+ connect(buttonBox, SIGNAL(accepted()), SLOT(slotOk()));
+ connect(buttonBox, SIGNAL(rejected()), SLOT(reject()));
connect( m_protocolCombo, SIGNAL( activated(int) ), this, SLOT( slotProtocolChanged() ) );
-
}
+
void CSwordSetupInstallSourcesDialog::slotOk() {
//run a few tests to validate the input first
if ( m_captionEdit->text().trimmed().isEmpty() ) { //no caption
- QMessageBox::information( this, tr( "Error" ), tr("Please provide a caption."), QMessageBox::Retry);
+ util::showInformation( this, tr( "Error" ), tr("Please provide a caption."));
return;
}
@@ -108,25 +104,25 @@ void CSwordSetupInstallSourcesDialog::slotOk() {
//sword::InstallSource is = BTInstallMgr::Tool::RemoteConfig::source( &iMgr, m_captionEdit->text() );
sword::InstallSource is = instbackend::source(m_captionEdit->text());
if ( (QString)is.caption.c_str() == m_captionEdit->text() ) { //source already exists
- QMessageBox::information( this, tr( "Error" ),
- tr("A source with this caption already exists.<br>Please provide a different caption."), QMessageBox::Retry);
+ util::showInformation( this, tr( "Error" ),
+ tr("A source with this caption already exists.<br/>Please provide a different caption."));
return;
}
if ( m_protocolCombo->currentText() == PROTO_FTP &&
m_serverEdit->text().trimmed().isEmpty() ) { //no server name
- QMessageBox::information( this, tr( "Error" ), tr("Please provide a server name."), QMessageBox::Retry);
+ util::showInformation( this, tr( "Error" ), tr("Please provide a server name."));
return;
}
if ( m_protocolCombo->currentText() == PROTO_FILE) {
const QFileInfo fi( m_pathEdit->text() );
if (!fi.exists() || !fi.isReadable()) { //no valid and readable path
- QMessageBox::information( this, tr( "Error" ), tr("Please provide a valid, readable path."), QMessageBox::Retry);
+ util::showInformation( this, tr( "Error" ), tr("Please provide a valid, readable path."));
return;
}
else if ( m_pathEdit->text().isEmpty() ) {
- QMessageBox::information( this, tr( "Error" ), tr("Please provide a path."), QMessageBox::Retry);
+ util::showInformation( this, tr( "Error" ), tr("Please provide a path."));
}
}
@@ -155,28 +151,83 @@ void CSwordSetupInstallSourcesDialog::slotProtocolChanged() {
}
-sword::InstallSource CSwordSetupInstallSourcesDialog::getSource() {
+void CSwordSetupInstallSourcesDialog::slotGetListClicked() {
+ QString message(tr("List of sources will be downloaded from a remote server. Sources will be added to the current list. New source will replace an old one if it has the same label. You can later remove the sources you don't want to keep.\n\nDo you want to continue?"));
+ QMessageBox::StandardButton answer = util::showQuestion(this, tr("Get source list from remote server?"), message, QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
+ if (answer == QMessageBox::No) {
+ return;
+ }
+ qDebug() << "Ok, create installmgr";
+ BtInstallMgr iMgr;
+
+ m_progressDialog = new QProgressDialog("", tr("Cancel"), 0 , 100, this);
+ m_progressDialog->setWindowTitle(tr("Downloading List"));
+ m_progressDialog->setMinimumDuration(0);
+ connect(m_progressDialog, SIGNAL(canceled()), SLOT(slotRefreshCanceled()));
+ m_currentInstallMgr = &iMgr; //for the progress dialog
+ // connect this directly to the dialog setValue(int) if possible
+ connect(&iMgr, SIGNAL(percentCompleted(const int, const int)), SLOT(slotRefreshProgress(const int, const int)));
+
+ m_progressDialog->show();
+ qApp->processEvents();
+ this->slotRefreshProgress(0, 0);
+ m_progressDialog->setLabelText(tr("Connecting..."));
+ m_progressDialog->setValue(0);
+ qApp->processEvents();
+ qWarning() << "Start downloading the list of sources";
+ int ret = iMgr.refreshRemoteSourceConfiguration();
+ bool success = false;
+ if ( !ret ) { //make sure the sources were updated sucessfully
+ qDebug() << "download succeeded";
+ success = true;
+ m_progressDialog->setValue(100); //make sure the dialog closes
+ m_remoteListAdded = true;
+ accept();
+ }
+ else {
+ qWarning("InstallMgr: getting remote list returned an error.");
+ success = false;
+ }
+ delete m_progressDialog;
+ m_progressDialog = 0;
+}
- boost::scoped_ptr<CSwordSetupInstallSourcesDialog> dlg( new CSwordSetupInstallSourcesDialog() );
- sword::InstallSource newSource(""); //empty, invalid Source
+void CSwordSetupInstallSourcesDialog::slotRefreshProgress(const int, const int current) {
+ if (m_progressDialog) {
+ if (m_progressDialog->labelText() != tr("Refreshing...")) {
+ m_progressDialog->setLabelText(tr("Refreshing..."));
+ }
+ m_progressDialog->setValue(current);
+ }
+ qApp->processEvents();
+}
- if (dlg->exec() == QDialog::Accepted) {
- if (dlg->m_protocolCombo->currentText() == PROTO_FTP) {
- newSource.type = "FTP";
- newSource.source = dlg->m_serverEdit->text().toUtf8();
+void CSwordSetupInstallSourcesDialog::slotRefreshCanceled() {
+ Q_ASSERT(m_currentInstallMgr);
+ if (m_currentInstallMgr) {
+ m_currentInstallMgr->terminate();
+ }
+ qApp->processEvents();
+}
- //a message to the user would be nice, but we're in message freeze right now (1.5.1)
- if (dlg->m_serverEdit->text().right(1) == "/") { //remove a trailing slash
- newSource.source = dlg->m_serverEdit->text().mid(0, dlg->m_serverEdit->text().length() - 1).toUtf8();
- }
- }
- else {
- newSource.type = "DIR";
- newSource.source = "local";
+sword::InstallSource CSwordSetupInstallSourcesDialog::getSource() {
+ sword::InstallSource newSource(""); //empty, invalid Source
+ if (m_protocolCombo->currentText() == PROTO_FTP) {
+ newSource.type = "FTP";
+ newSource.source = m_serverEdit->text().toUtf8();
+ //a message to the user would be nice, but we're in message freeze right now (1.5.1)
+ if (m_serverEdit->text().right(1) == "/") { //remove a trailing slash
+ newSource.source = m_serverEdit->text().mid(0, m_serverEdit->text().length() - 1).toUtf8();
}
- newSource.caption = dlg->m_captionEdit->text().toUtf8();
- newSource.directory = dlg->m_pathEdit->text().toUtf8();
}
+ else {
+ newSource.type = "DIR";
+ newSource.source = "local";
+ }
+ newSource.caption = m_captionEdit->text().toUtf8();
+ newSource.directory = m_pathEdit->text().toUtf8();
+ newSource.uid = newSource.source;
+
return newSource;
}