20 #include <QFileDialog>
21 #include <QGridLayout>
22 #include <QHBoxLayout>
25 #include <QMessageBox>
26 #include <QNonConstOverload>
27 #include <QPushButton>
29 #include <QVBoxLayout>
30 #include <QDialogButtonBox>
31 #include <QProgressDialog>
32 #include <QApplication>
33 #include "../../backend/btinstallbackend.h"
34 #include "../../backend/btinstallmgr.h"
35 #include "../../util/btconnect.h"
36 #include "../messagedialog.h"
39 #include <installmgr.h>
51 m_remoteListAdded(false) {
52 setWindowTitle(tr(
"New Installation Source"));
54 QVBoxLayout* mainLayout =
new QVBoxLayout(
this );
55 mainLayout->setContentsMargins(10, 10, 10, 10);
56 mainLayout->setSpacing( 5 );
58 QHBoxLayout *captionLayout =
new QHBoxLayout;
59 mainLayout->addLayout(captionLayout);
60 QLabel *label =
new QLabel( tr(
"Caption"),
this );
61 captionLayout->addWidget( label );
64 m_captionEdit->setText(QStringLiteral(
"CrossWire Bible Society"));
67 mainLayout->addSpacing( 10 );
69 QGridLayout* layout =
new QGridLayout;
70 layout->setSpacing(3);
71 layout->setContentsMargins(3, 3, 3, 3);
72 mainLayout->addLayout(layout);
73 layout->setSpacing( 5 );
75 label =
new QLabel(tr(
"Type"),
this);
76 layout->addWidget( label, 0, 0);
81 label =
new QLabel(tr(
"Path"),
this);
82 layout->addWidget( label, 0, 2 );
89 m_protocolCombo->addItem(tr(
"Remote HTTPS"),
int(SourceProtocol::HTTPS));
94 m_serverEdit->setText(QStringLiteral(
"ftp.crosswire.org"));
98 m_pathEdit->setText(QStringLiteral(
"/pub/sword/raw"));
100 mainLayout->addSpacing( 10 );
102 QDialogButtonBox* buttonBox =
new QDialogButtonBox(QDialogButtonBox::Cancel | QDialogButtonBox::Save, Qt::Horizontal,
this);
104 QPushButton* getListButton =
new QPushButton(tr(
"Get list..."),
this);
105 getListButton->setToolTip(tr(
"Download a list of sources from CrossWire server and add sources"));
106 buttonBox->addButton(getListButton, QDialogButtonBox::ActionRole);
107 BT_CONNECT(getListButton, &QPushButton::clicked,
111 tr(
"Get source list from remote server?"),
112 tr(
"List of sources will be downloaded from a "
113 "remote server. Sources will be added to the "
114 "current list. New source will replace an "
115 "old one if it has the same label. You can "
116 "later remove the sources you don't want to "
117 "keep.\n\nDo you want to continue?"),
118 QMessageBox::Yes | QMessageBox::No,
119 QMessageBox::Yes) == QMessageBox::No)
129 progressDialog.setValue(0);
130 progressDialog.setWindowTitle(tr(
"Downloading List"));
131 progressDialog.setMinimumDuration(0);
132 BT_CONNECT(&progressDialog, &QProgressDialog::canceled,
135 qApp->processEvents();
140 [&progressDialog](
const int,
const int current) {
141 progressDialog.setLabelText(
142 tr(
"Refreshing..."));
143 progressDialog.setValue(current);
144 qApp->processEvents();
147 progressDialog.show();
148 qApp->processEvents();
150 if (!iMgr.refreshRemoteSourceConfiguration()) {
152 progressDialog.setValue(100);
156 qWarning(
"InstallMgr: getting remote list returned an "
160 mainLayout->addWidget(buttonBox);
161 BT_CONNECT(buttonBox, &QDialogButtonBox::accepted,
163 struct Error { QString msg; };
166 throw Error{tr(
"Please provide a caption.")};
170 throw Error{tr(
"A source with this caption already "
171 "exists. Please provide a different "
175 !=
int(SourceProtocol::Local)
177 throw Error{tr(
"Please provide a server name.")};
180 ==
int(SourceProtocol::Local))
182 if (m_pathEdit->text().isEmpty())
183 throw Error{tr(
"Please provide a path.")};
186 if (!fi.exists() || !fi.isReadable())
187 throw Error{tr(
"Please provide a valid, "
190 }
catch (Error
const & e) {
196 BT_CONNECT(buttonBox, &QDialogButtonBox::rejected,
197 this, &CSwordSetupInstallSourcesDialog::reject);
198 BT_CONNECT(m_protocolCombo, qOverload<int>(&QComboBox::activated),
200 if (m_protocolCombo->currentData().toInt()
201 !=
int(SourceProtocol::Local))
203 m_serverLabel->setEnabled(true);
204 m_serverEdit->setEnabled(true);
206 m_serverLabel->setEnabled(false);
207 m_serverEdit->setEnabled(false);
209 QString dirname = QFileDialog::getExistingDirectory(this);
210 if (dirname.isEmpty()) {
215 m_pathEdit->setText( dir.canonicalPath() );
223 sword::InstallSource newSource(
"");
224 auto const protocol =
226 if (protocol != SourceProtocol::Local) {
227 if (protocol == SourceProtocol::FTP) {
228 newSource.type =
"FTP";
229 }
else if (protocol == SourceProtocol::SFTP) {
230 newSource.type =
"SFTP";
231 }
else if (protocol == SourceProtocol::HTTP) {
232 newSource.type =
"HTTP";
233 }
else if (protocol == SourceProtocol::HTTPS) {
234 newSource.type =
"HTTPS";
239 while (server.endsWith(
'/'))
241 newSource.source = server.toUtf8();
244 newSource.type =
"DIR";
245 newSource.source =
"local";
248 newSource.directory =
m_pathEdit->text().toUtf8();
249 newSource.uid = newSource.source;
void percentCompleted(const int total, const int file)
sword::InstallSource getSource()
QLineEdit * m_captionEdit
CSwordSetupInstallSourcesDialog()
QComboBox * m_protocolCombo
sword::InstallSource source(const QString &name)
void prepareDialogBox(QDialogButtonBox *box)
QMessageBox::StandardButton showQuestion(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMessageBox::StandardButton showCritical(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)