6#include <QDesktopServices>
12#include <QStandardPaths>
15#include "ui_installxswiftbuscomponent.h"
26using namespace swift::config;
28using namespace swift::misc::db;
29using namespace swift::misc::network;
30using namespace swift::misc::simulation;
31using namespace swift::misc::simulation::settings;
32using namespace swift::misc::simulation::xplane;
41 ui->le_XSwiftBusPluginDir->setText(this->getXPlanePluginDirectory());
43 ui->cb_DownloadFile->setEnabled(
false);
46 &CInstallXSwiftBusComponent::selectPluginDirectory);
48 &CInstallXSwiftBusComponent::selectDownloadDirectory);
50 &CInstallXSwiftBusComponent::triggerDownloadingOfXSwiftBusFile);
55 this->updatesChanged();
62 m_defaultDownloadName = defaultDownload;
63 this->updatesChanged();
66 void CInstallXSwiftBusComponent::selectPluginDirectory()
70 xPlanePluginDir, m_fileDialogOptions);
76 if (!
QDir(xPlanePluginDir).exists())
79 .
warning(u
"'%1' is not a valid X-Plane plugin directory")
84 ui->le_XSwiftBusPluginDir->setText(xPlanePluginDir);
87 void CInstallXSwiftBusComponent::selectDownloadDirectory()
91 downloadDir, m_fileDialogOptions);
97 if (!QDir(downloadDir).exists())
99 const CStatusMessage msg =
105 ui->le_DownloadDir->setText(downloadDir);
108 void CInstallXSwiftBusComponent::installXSwiftBus()
110 const CRemoteFile rf = this->getRemoteFileSelected();
112 QPointer<CInstallXSwiftBusComponent> myself(
this);
113 QFile downloadFile(downloadFileName);
115 if (!downloadFile.exists())
117 const CStatusMessage msg =
124 const QString xSwiftBusDirectory = this->GetXSwiftBusDir();
125 if (xSwiftBusDirectory.
isEmpty())
127 const CStatusMessage msg =
133 const QDir installDir(xSwiftBusDirectory);
134 if (!installDir.exists())
136 const CStatusMessage msg =
138 << xSwiftBusDirectory;
145 QFile destFile(destFileName);
146 if (destFile.exists())
148 const bool removed = destFile.remove();
151 const CStatusMessage msg =
159 const bool copied =
QFile::copy(downloadFileName, destFileName);
162 const CStatusMessage msg =
164 << downloadFileName << destFileName;
170 const QFileInfo destFile(destFileName);
171 if (!destFile.exists())
173 const CStatusMessage msg =
181 QStringList stdOutAndError;
185 const CStatusMessage msg =
187 << xSwiftBusDirectory;
193 QFile downloadFile(downloadFileName);
194 if (!downloadFile.exists())
198 const bool removed = downloadFile.remove();
205 const CStatusMessage msg =
207 <<
safeAt(stdOutAndError, 0) <<
safeAt(stdOutAndError, 1);
214 "You need to manually unzip xswiftbus into the plugins directory.\nIt needs to look "
215 "like 'plugin/xswiftbus'.\n\nOpen the archive?",
224 void CInstallXSwiftBusComponent::triggerDownloadingOfXSwiftBusFile()
226 using namespace std::chrono_literals;
231 const CRemoteFile rf = this->getRemoteFileSelected();
235 this,
"Download xswiftbus",
236 QStringLiteral(u
"The xswiftbus versions seems to be for a different version\n"
237 u
"Your version is '%1'. Use this version.\n\n"
238 u
"If not available, you can try the version next to your version number.\n\n"
239 u
"Continue with this version?")
248 if (!this->existsDownloadDir())
250 const CStatusMessage msg =
259 const CStatusMessage msg =
267 const QFile saveFile(saveAsFile);
268 if (saveFile.exists())
271 this,
"The file already exists",
"Do you want to use the existing '" + saveAsFile +
"'?",
279 const CStatusMessage msg = CStatusMessage(
this).
info(u
"Using existing file '%1'") << saveAsFile;
280 const QPointer<CInstallXSwiftBusComponent> guard(
this);
286 this->downloadedXSwiftBusFile(msg);
293 download, saveAsFile, {
this, &CInstallXSwiftBusComponent::downloadedXSwiftBusFile });
296 CLogMessage(
this).info(u
"Triggered downloading of xswiftbus file from '%1'") << download.
getHost();
301 const CStatusMessage msg =
308 void CInstallXSwiftBusComponent::downloadedXSwiftBusFile(
const CStatusMessage &status)
320 if (!this->existsXSwiftBusPluginDir())
322 const CStatusMessage msg = CStatusMessage(
this).
warning(u
"No valid install directory, cannot continue.");
327 static const QString confirm(
"Install in '%1'?");
329 status,
false, confirm.arg(ui->le_XSwiftBusPluginDir->text()),
330 [=,
this] { QTimer::singleShot(0, this, &CInstallXSwiftBusComponent::installXSwiftBus); });
333 CRemoteFile CInstallXSwiftBusComponent::getRemoteFileSelected()
const
335 const QString baseNameAndSize = ui->cb_DownloadFile->currentText();
336 const CUpdateInfo
update = m_updates.get();
337 const CRemoteFileList remoteFiles =
update.getArtifactsXSwiftBus().asRemoteFiles();
341 QString CInstallXSwiftBusComponent::getDownloadDir()
const
346 QString CInstallXSwiftBusComponent::GetXSwiftBusDir()
const
351 bool CInstallXSwiftBusComponent::existsDownloadDir()
const
353 const QDir dir(this->getDownloadDir());
354 return dir.exists() && dir.isReadable();
357 bool CInstallXSwiftBusComponent::existsXSwiftBusPluginDir()
const
359 const QDir dir(this->GetXSwiftBusDir());
360 return dir.exists() && dir.isReadable();
363 QString CInstallXSwiftBusComponent::getXPlanePluginDirectory()
const
365 const CXPlaneSimulatorSettings settings = m_simulatorSettings.getSettings(CSimulatorInfo::XPLANE);
369 void CInstallXSwiftBusComponent::updatesChanged()
371 const CUpdateInfo updateInfo = m_updates.get();
376 const CArtifactList artifacts =
383 const CRemoteFileList remoteFiles = artifacts.
asRemoteFiles();
387 m_xSwiftBusArtifacts = artifacts;
388 ui->cb_DownloadFile->addItems(xSwiftBusFiles);
391 QString current = xSwiftBusFiles.
front();
392 if (m_defaultDownloadName.isEmpty())
394 const CRemoteFile rf =
413 ui->cb_DownloadFile->setEnabled(!remoteFiles.
isEmpty());
416 void CInstallXSwiftBusComponent::openInstallDir()
418 if (!this->existsXSwiftBusPluginDir())
426 void CInstallXSwiftBusComponent::openDownloadDir()
428 if (!this->existsDownloadDir())
static const QString & getVersionString()
Version as QVersionNumber.
QNetworkReply * downloadFromNetwork(const swift::misc::network::CUrl &url, const QString &saveAsFileName, const swift::misc::CSlot< void(const swift::misc::CStatusMessage &)> &callback, int maxRedirects=DefaultMaxRedirects)
Download file from network and store it as passed.
bool hasWebDataServices() const
Web data services available?
bool isShuttingDown() const
Is application shutting down?
void showLoading(std::chrono::milliseconds timeout=std::chrono::milliseconds(0), bool processEvents=true)
Show load indicator.
void hideLoading()
Hide load indicator.
CLoadIndicatorEnabled(QWidget *usingWidget)
Ctor.
bool showOverlayMessage(const swift::misc::CStatusMessage &message, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
void showOverlayMessagesWithConfirmation(const swift::misc::CStatusMessageList &messages, bool appendOldMessages, const QString &confirmationMessage, std::function< void()> okLambda, QMessageBox::StandardButton defaultButton=QMessageBox::Cancel, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
COverlayMessagesFrame(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
Constructor.
void setDefaultDownloadName(const QString &defaultDownload)
Set a default name for download.
~CInstallXSwiftBusComponent()
Dtor.
CInstallXSwiftBusComponent(QWidget *parent=nullptr)
Default constructor.
static bool zipUncompress(const QString &file, const QString &directory, QStringList *stdOutAndError=nullptr)
Unzip file.
static QString appendFilePathsAndFixUnc(const QString &path1, const QString &path2)
Append file paths.
static QString fixWindowsUncPath(const QString &filePath)
UNC file paths on Qt start with "/", but UNC file paths only work when they start with "//".
static const QString & validation()
Validation.
Derived & warning(const char16_t(&format)[N])
Set the severity to warning, providing a format string.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
const_reference frontOrDefault() const
Access the first element, or a default-initialized value if the sequence is empty.
reference front()
Access the first element.
bool isEmpty() const
Synonym for empty.
Streamable status message, e.g.
bool isWarningOrAbove() const
Warning or above.
CArtifactList findWithUnrestrictedDistributions() const
Find artifacts with public (unrestricted) distributions.
network::CRemoteFileList asRemoteFiles() const
As remote files.
CArtifactList getArtifactsXSwiftBusLatestVersionFirst() const
Artifacts (xswiftbus).
const CArtifactList & getArtifactsXSwiftBus() const
Artifacts (xswiftbus).
QString getBaseName() const
Name with directory stripped.
CUrl getSmartUrl() const
Automatically concatenates the name if missing.
bool hasName() const
Has name?
QString getBaseNameAndSize() const
Name + human readable size.
CRemoteFile findFirstContainingNameOrDefault(const QString &name, Qt::CaseSensitivity cs) const
First by name contained of default.
QStringList getBaseNamesPlusSize(bool sorted=true) const
All file names plus size.
CRemoteFile findFirstByMatchingBaseNameOrDefault(const QString &name) const
Find first matching name of default.
const QString & getHost() const
Get host.
bool isEmpty() const
Empty.
QString getFullUrl(bool withQuery=true) const
Qualified name.
QString getPluginDirOrDefault() const
Plugin directory or default plugin dir.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
High level reusable GUI components.
Free functions in swift::misc.
const QString & safeAt(const QStringList &stringList, int index)
Safe "at" function, returns empty string if index does not exists.
bool openUrl(const QUrl &url)
bool copy(const QString &fileName, const QString &newName)
QString getExistingDirectory(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options)
QMessageBox::StandardButton question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString writableLocation(QStandardPaths::StandardLocation type)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
QUrl fromLocalFile(const QString &localFile)