From 97c0bbd2388ac049970fc3c99ebdc072c75724f1 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Sun, 3 Jul 2016 20:09:51 +0600 Subject: GUI: Add DownloadDialog sketch --- gui/downloaddialog.cpp | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 gui/downloaddialog.cpp (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp new file mode 100644 index 0000000000..b449be5ca8 --- /dev/null +++ b/gui/downloaddialog.cpp @@ -0,0 +1,88 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "gui/downloaddialog.h" +#include "gui/widgets/list.h" +#include "gui/widget.h" +#include "gui/gui-manager.h" +#include "backends/cloud/cloudmanager.h" +#include "common/translation.h" +#include "widgets/edittext.h" + +namespace GUI { + +enum { + kDownloadDialogButtonCmd = 'Dldb' +}; + +DownloadDialog::DownloadDialog(uint32 storageId): + Dialog("GlobalOptions_Cloud_DownloadDialog"), _wasInProgress(true), _inProgress(false), _close(false) { + _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; + + _messageText = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.DialogDesc", _("Press the button to download a directory")); + _mainButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _("Start download"), 0, kDownloadDialogButtonCmd); + _closeButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.CloseButton", _("OK"), 0, kCloseCmd); + updateButtons(); +} + +void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { + switch (cmd) { + case kDownloadDialogButtonCmd: { + _inProgress = !_inProgress; + reflowLayout(); + break; + } + default: + Dialog::handleCommand(sender, cmd, data); + } +} + +void DownloadDialog::handleTickle() { + if (_close) { + setResult(1); + close(); + } + + Dialog::handleTickle(); +} + +void DownloadDialog::reflowLayout() { + Dialog::reflowLayout(); + updateButtons(); +} + +void DownloadDialog::updateButtons() { + if (_wasInProgress == _inProgress) return; + + if (_inProgress) { + _messageText->setLabel(_("Press the button to cancel the download")); + _mainButton->setLabel(_("Cancel the download")); + } else { + _messageText->setLabel(_("Press the button to download a directory")); + _mainButton->setLabel(_("Start download")); + } + + _wasInProgress = _inProgress; +} + + +} // End of namespace GUI -- cgit v1.2.3 From 72b82bd2aa66223f6c740e7bf6dce316b2145b15 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 4 Jul 2016 11:52:40 +0600 Subject: GUI: Add RemoteBrowserDialog WIP. Tested with Dropbox. --- gui/downloaddialog.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index b449be5ca8..e94b19634b 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -27,6 +27,9 @@ #include "backends/cloud/cloudmanager.h" #include "common/translation.h" #include "widgets/edittext.h" +#include "message.h" +#include "browser.h" +#include "remotebrowser.h" namespace GUI { @@ -38,6 +41,9 @@ DownloadDialog::DownloadDialog(uint32 storageId): Dialog("GlobalOptions_Cloud_DownloadDialog"), _wasInProgress(true), _inProgress(false), _close(false) { _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; + _browser = new BrowserDialog(_("Select directory where to download game data"), true); + _remoteBrowser = new RemoteBrowserDialog(_("Select directory with game data"), true); + _messageText = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.DialogDesc", _("Press the button to download a directory")); _mainButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _("Start download"), 0, kDownloadDialogButtonCmd); _closeButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.CloseButton", _("OK"), 0, kCloseCmd); @@ -47,6 +53,10 @@ DownloadDialog::DownloadDialog(uint32 storageId): void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { case kDownloadDialogButtonCmd: { + if (!_inProgress) { + selectDirectories(); + } + _inProgress = !_inProgress; reflowLayout(); break; @@ -56,6 +66,36 @@ void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat } } +void DownloadDialog::selectDirectories() { + //first user should select remote directory to download + if (_remoteBrowser->runModal() <= 0) return; + + /* + Common::FSNode dir(_browser->getResult()); + Common::FSList files; + if (!dir.getChildren(files, Common::FSNode::kListAll)) { + MessageDialog alert(_("ScummVM couldn't open the specified directory!")); + alert.runModal(); + return; + } + */ + + //now user should select local directory to download into + if (_browser->runModal() <= 0) return; + + Common::FSNode dir(_browser->getResult()); + Common::FSList files; + if (!dir.getChildren(files, Common::FSNode::kListAll)) { + MessageDialog alert(_("ScummVM couldn't open the specified directory!")); + alert.runModal(); + return; + } + + //TODO: require empty directory? + + //TODO: initiate download +} + void DownloadDialog::handleTickle() { if (_close) { setResult(1); -- cgit v1.2.3 From 73bb2e20afdd625998a1438adf29e5d9dbaa2929 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 4 Jul 2016 13:00:26 +0600 Subject: GUI: Clean up in RemoteBrowser --- gui/downloaddialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index e94b19634b..6e9410dd51 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -42,7 +42,7 @@ DownloadDialog::DownloadDialog(uint32 storageId): _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; _browser = new BrowserDialog(_("Select directory where to download game data"), true); - _remoteBrowser = new RemoteBrowserDialog(_("Select directory with game data"), true); + _remoteBrowser = new RemoteBrowserDialog(_("Select directory with game data")); _messageText = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.DialogDesc", _("Press the button to download a directory")); _mainButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _("Start download"), 0, kDownloadDialogButtonCmd); -- cgit v1.2.3 From d776b5397198835e1538071fd4fe53ab491c5da4 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 4 Jul 2016 14:49:33 +0600 Subject: GUI: Use RemoteBrowser's result in DownloadDialog It now checks the selected local directory, and shows different MessageDialogs to notify user of mistake or ambiguous situation. --- gui/downloaddialog.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index 6e9410dd51..34eddbe395 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -70,15 +70,7 @@ void DownloadDialog::selectDirectories() { //first user should select remote directory to download if (_remoteBrowser->runModal() <= 0) return; - /* - Common::FSNode dir(_browser->getResult()); - Common::FSList files; - if (!dir.getChildren(files, Common::FSNode::kListAll)) { - MessageDialog alert(_("ScummVM couldn't open the specified directory!")); - alert.runModal(); - return; - } - */ + Cloud::StorageFile remoteDirectory = _remoteBrowser->getResult(); //now user should select local directory to download into if (_browser->runModal() <= 0) return; @@ -91,7 +83,24 @@ void DownloadDialog::selectDirectories() { return; } - //TODO: require empty directory? + //check that there is no file with the remote directory's name in the local one + for (Common::FSList::iterator i = files.begin(); i != files.end(); ++i) { + if (i->getName().equalsIgnoreCase(remoteDirectory.name())) { + //if there is, ask user whether it's OK + if (!i->isDirectory()) { + GUI::MessageDialog alert(_("Cannot create a directory to download - the specified directory has a file with the same name."), _("OK")); + alert.runModal(); + return; + } + GUI::MessageDialog alert( + Common::String::format(_("The \"%s\" already exists in the specified directory.\nDo you really want to download files into that directory?"), remoteDirectory.name().c_str()), + _("Yes"), + _("No") + ); + if (alert.runModal() != GUI::kMessageOK) return; + break; + } + } //TODO: initiate download } -- cgit v1.2.3 From 71a326493b351b845ea800ae88495238b1a61066 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 4 Jul 2016 15:34:02 +0600 Subject: GUI: Initiate download in DownloadDialog --- gui/downloaddialog.cpp | 71 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 12 deletions(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index 34eddbe395..d4c44e53ff 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -38,7 +38,8 @@ enum { }; DownloadDialog::DownloadDialog(uint32 storageId): - Dialog("GlobalOptions_Cloud_DownloadDialog"), _wasInProgress(true), _inProgress(false), _close(false) { + Dialog("GlobalOptions_Cloud_DownloadDialog"), _close(false), + _workingRequest(nullptr), _ignoreCallback(false) { _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; _browser = new BrowserDialog(_("Select directory where to download game data"), true); @@ -50,15 +51,35 @@ DownloadDialog::DownloadDialog(uint32 storageId): updateButtons(); } +DownloadDialog::~DownloadDialog() { + if (_workingRequest) { + _ignoreCallback = true; + _workingRequest->finish(); + } +} + +void DownloadDialog::close() { + if (_workingRequest) { + _ignoreCallback = true; + _workingRequest->finish(); + _ignoreCallback = false; + } + Dialog::close(); +} + void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { case kDownloadDialogButtonCmd: { - if (!_inProgress) { + if (_workingRequest == nullptr) { selectDirectories(); + } else { + _ignoreCallback = true; + _workingRequest->finish(); + _ignoreCallback = false; } - _inProgress = !_inProgress; reflowLayout(); + draw(); break; } default: @@ -102,7 +123,38 @@ void DownloadDialog::selectDirectories() { } } - //TODO: initiate download + //make a local path + Common::String localPath = dir.getPath(); + + //simple heuristic to determine which path separator to use + int backslashes = 0; + for (uint32 i = 0; i < localPath.size(); ++i) + if (localPath[i] == '/') --backslashes; + else if (localPath[i] == '\\') ++backslashes; + + if (backslashes > 0) localPath += '\\' + remoteDirectory.name(); + else localPath += '/' + remoteDirectory.name(); + + _workingRequest = CloudMan.downloadFolder( + remoteDirectory.path(), localPath, + new Common::Callback(this, &DownloadDialog::directoryDownloadedCallback), + new Common::Callback(this, &DownloadDialog::directoryDownloadedErrorCallback), + true + ); +} + +void DownloadDialog::directoryDownloadedCallback(Cloud::Storage::FileArrayResponse response) { + _workingRequest = nullptr; + if (_ignoreCallback) return; + + //TODO: show response.value (if not empty), show message on OSD +} + +void DownloadDialog::directoryDownloadedErrorCallback(Networking::ErrorResponse error) { + _workingRequest = nullptr; + if (_ignoreCallback) return; + + //TODO: _showError = true; } void DownloadDialog::handleTickle() { @@ -119,19 +171,14 @@ void DownloadDialog::reflowLayout() { updateButtons(); } -void DownloadDialog::updateButtons() { - if (_wasInProgress == _inProgress) return; - - if (_inProgress) { +void DownloadDialog::updateButtons() { + if (_workingRequest != nullptr) { _messageText->setLabel(_("Press the button to cancel the download")); _mainButton->setLabel(_("Cancel the download")); } else { _messageText->setLabel(_("Press the button to download a directory")); _mainButton->setLabel(_("Start download")); - } - - _wasInProgress = _inProgress; + } } - } // End of namespace GUI -- cgit v1.2.3 From b8ee9d4e7d32d0cc0dd832cbd0ffec5c5d08db34 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 4 Jul 2016 16:14:30 +0600 Subject: CLOUD: Add FolderDownload-related methods in Storage CloudManager's shortcuts are added too. The idea is to keep FolderDownload request within Storage, and provide necessary means to access it. The download is started and cancelled through the DownloadDialog. --- gui/downloaddialog.cpp | 50 ++++++-------------------------------------------- 1 file changed, 6 insertions(+), 44 deletions(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index d4c44e53ff..ac3b3d3c72 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -38,8 +38,7 @@ enum { }; DownloadDialog::DownloadDialog(uint32 storageId): - Dialog("GlobalOptions_Cloud_DownloadDialog"), _close(false), - _workingRequest(nullptr), _ignoreCallback(false) { + Dialog("GlobalOptions_Cloud_DownloadDialog"), _close(false) { _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; _browser = new BrowserDialog(_("Select directory where to download game data"), true); @@ -51,31 +50,13 @@ DownloadDialog::DownloadDialog(uint32 storageId): updateButtons(); } -DownloadDialog::~DownloadDialog() { - if (_workingRequest) { - _ignoreCallback = true; - _workingRequest->finish(); - } -} - -void DownloadDialog::close() { - if (_workingRequest) { - _ignoreCallback = true; - _workingRequest->finish(); - _ignoreCallback = false; - } - Dialog::close(); -} - void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { case kDownloadDialogButtonCmd: { - if (_workingRequest == nullptr) { - selectDirectories(); + if (CloudMan.isDownloading()) { + CloudMan.cancelDownload(); } else { - _ignoreCallback = true; - _workingRequest->finish(); - _ignoreCallback = false; + selectDirectories(); } reflowLayout(); @@ -135,26 +116,7 @@ void DownloadDialog::selectDirectories() { if (backslashes > 0) localPath += '\\' + remoteDirectory.name(); else localPath += '/' + remoteDirectory.name(); - _workingRequest = CloudMan.downloadFolder( - remoteDirectory.path(), localPath, - new Common::Callback(this, &DownloadDialog::directoryDownloadedCallback), - new Common::Callback(this, &DownloadDialog::directoryDownloadedErrorCallback), - true - ); -} - -void DownloadDialog::directoryDownloadedCallback(Cloud::Storage::FileArrayResponse response) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - - //TODO: show response.value (if not empty), show message on OSD -} - -void DownloadDialog::directoryDownloadedErrorCallback(Networking::ErrorResponse error) { - _workingRequest = nullptr; - if (_ignoreCallback) return; - - //TODO: _showError = true; + CloudMan.startDownload(remoteDirectory.path(), localPath); } void DownloadDialog::handleTickle() { @@ -172,7 +134,7 @@ void DownloadDialog::reflowLayout() { } void DownloadDialog::updateButtons() { - if (_workingRequest != nullptr) { + if (CloudMan.isDownloading()) { _messageText->setLabel(_("Press the button to cancel the download")); _mainButton->setLabel(_("Cancel the download")); } else { -- cgit v1.2.3 From ddb1a6ccb6238aaed599b271506a94a7c0f18844 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 4 Jul 2016 17:11:58 +0600 Subject: GUI: Upgrade DownloadDialog It now shows the remote and local directories and a progress bar. Storage now shows OSD messages on download success and failure. --- gui/downloaddialog.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index ac3b3d3c72..28a29fcb64 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -38,7 +38,7 @@ enum { }; DownloadDialog::DownloadDialog(uint32 storageId): - Dialog("GlobalOptions_Cloud_DownloadDialog"), _close(false) { + Dialog("GlobalOptions_Cloud_DownloadDialog"), _reflow(false) { _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; _browser = new BrowserDialog(_("Select directory where to download game data"), true); @@ -46,14 +46,35 @@ DownloadDialog::DownloadDialog(uint32 storageId): _messageText = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.DialogDesc", _("Press the button to download a directory")); _mainButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _("Start download"), 0, kDownloadDialogButtonCmd); + _remoteDirectoryLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.RemoteDirectory", _("From: ")); + _localDirectoryLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.LocalDirectory", _("To: ")); + uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); + _progressBar = new SliderWidget(this, "GlobalOptions_Cloud_DownloadDialog.ProgressBar"); + _progressBar->setMinValue(0); + _progressBar->setMaxValue(100); + _progressBar->setValue(progress); + _progressBar->setEnabled(false); + _percentLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.PercentText", Common::String::format("%u %%", progress)); _closeButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.CloseButton", _("OK"), 0, kCloseCmd); updateButtons(); + + CloudMan.setDownloadTarget(this); +} + +DownloadDialog::~DownloadDialog() { + CloudMan.setDownloadTarget(nullptr); +} + +void DownloadDialog::close() { + CloudMan.setDownloadTarget(nullptr); + Dialog::close(); } void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { case kDownloadDialogButtonCmd: { if (CloudMan.isDownloading()) { + CloudMan.setDownloadTarget(nullptr); CloudMan.cancelDownload(); } else { selectDirectories(); @@ -63,6 +84,14 @@ void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat draw(); break; } + case kDownloadProgressCmd: + _percentLabel->setLabel(Common::String::format("%u %%", data)); + _progressBar->setValue(data); + _reflow = true; + break; + case kDownloadEndedCmd: + _reflow = true; + break; default: Dialog::handleCommand(sender, cmd, data); } @@ -117,12 +146,14 @@ void DownloadDialog::selectDirectories() { else localPath += '/' + remoteDirectory.name(); CloudMan.startDownload(remoteDirectory.path(), localPath); + CloudMan.setDownloadTarget(this); } void DownloadDialog::handleTickle() { - if (_close) { - setResult(1); - close(); + if (_reflow) { + reflowLayout(); + draw(); + _reflow = false; } Dialog::handleTickle(); @@ -133,14 +164,24 @@ void DownloadDialog::reflowLayout() { updateButtons(); } -void DownloadDialog::updateButtons() { - if (CloudMan.isDownloading()) { +void DownloadDialog::updateButtons() { + bool downloading = CloudMan.isDownloading(); + if (downloading) { _messageText->setLabel(_("Press the button to cancel the download")); _mainButton->setLabel(_("Cancel the download")); + _remoteDirectoryLabel->setLabel(_("From: ") + CloudMan.getDownloadRemoteDirectory()); + _localDirectoryLabel->setLabel(_("To: ") + CloudMan.getDownloadLocalDirectory()); + uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); + _percentLabel->setLabel(Common::String::format("%u %%", progress)); + _progressBar->setValue(progress); } else { _messageText->setLabel(_("Press the button to download a directory")); _mainButton->setLabel(_("Start download")); } + _remoteDirectoryLabel->setVisible(downloading); + _localDirectoryLabel->setVisible(downloading); + _percentLabel->setVisible(downloading); + _progressBar->setVisible(downloading); } } // End of namespace GUI -- cgit v1.2.3 From 458bfcec79e76b927414ed1b2151a4d59503ff86 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 4 Jul 2016 17:26:16 +0600 Subject: GUI: Fix DownloadDialog path creation Was adding a path separator even when none is required. --- gui/downloaddialog.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index 28a29fcb64..05d87c21d8 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -137,13 +137,15 @@ void DownloadDialog::selectDirectories() { Common::String localPath = dir.getPath(); //simple heuristic to determine which path separator to use - int backslashes = 0; - for (uint32 i = 0; i < localPath.size(); ++i) - if (localPath[i] == '/') --backslashes; - else if (localPath[i] == '\\') ++backslashes; - - if (backslashes > 0) localPath += '\\' + remoteDirectory.name(); - else localPath += '/' + remoteDirectory.name(); + if (localPath.size() && localPath.lastChar() != '/' && localPath.lastChar() != '\\') { + int backslashes = 0; + for (uint32 i = 0; i < localPath.size(); ++i) + if (localPath[i] == '/') --backslashes; + else if (localPath[i] == '\\') ++backslashes; + + if (backslashes > 0) localPath += '\\' + remoteDirectory.name(); + else localPath += '/' + remoteDirectory.name(); + } else localPath += remoteDirectory.name(); CloudMan.startDownload(remoteDirectory.path(), localPath); CloudMan.setDownloadTarget(this); -- cgit v1.2.3 From a5765a339e150952dca27035357bbfb1f88a4718 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 4 Jul 2016 18:30:23 +0600 Subject: GUI: Update DownloadDialog It now less empty, because if there is no download in progress, user sees the RemoteBrowser instead of empty dialog. The cancel button is now in the left bottom corner. --- gui/downloaddialog.cpp | 81 ++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 42 deletions(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index 05d87c21d8..9c48111153 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -38,14 +38,12 @@ enum { }; DownloadDialog::DownloadDialog(uint32 storageId): - Dialog("GlobalOptions_Cloud_DownloadDialog"), _reflow(false) { + Dialog("GlobalOptions_Cloud_DownloadDialog"), _close(false), _reflow(false) { _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; _browser = new BrowserDialog(_("Select directory where to download game data"), true); _remoteBrowser = new RemoteBrowserDialog(_("Select directory with game data")); - - _messageText = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.DialogDesc", _("Press the button to download a directory")); - _mainButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _("Start download"), 0, kDownloadDialogButtonCmd); + _remoteDirectoryLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.RemoteDirectory", _("From: ")); _localDirectoryLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.LocalDirectory", _("To: ")); uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); @@ -55,9 +53,10 @@ DownloadDialog::DownloadDialog(uint32 storageId): _progressBar->setValue(progress); _progressBar->setEnabled(false); _percentLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.PercentText", Common::String::format("%u %%", progress)); + _cancelButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _("Cancel download"), 0, kDownloadDialogButtonCmd); _closeButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.CloseButton", _("OK"), 0, kCloseCmd); - updateButtons(); - + refreshWidgets(); + CloudMan.setDownloadTarget(this); } @@ -65,6 +64,15 @@ DownloadDialog::~DownloadDialog() { CloudMan.setDownloadTarget(nullptr); } +void DownloadDialog::open() { + Dialog::open(); + if (!CloudMan.isDownloading()) + if (!selectDirectories()) + close(); + reflowLayout(); + draw(); +} + void DownloadDialog::close() { CloudMan.setDownloadTarget(nullptr); Dialog::close(); @@ -72,16 +80,10 @@ void DownloadDialog::close() { void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { - case kDownloadDialogButtonCmd: { - if (CloudMan.isDownloading()) { - CloudMan.setDownloadTarget(nullptr); - CloudMan.cancelDownload(); - } else { - selectDirectories(); - } - - reflowLayout(); - draw(); + case kDownloadDialogButtonCmd: { + CloudMan.setDownloadTarget(nullptr); + CloudMan.cancelDownload(); + close(); break; } case kDownloadProgressCmd: @@ -90,28 +92,28 @@ void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat _reflow = true; break; case kDownloadEndedCmd: - _reflow = true; + _close = true; break; default: Dialog::handleCommand(sender, cmd, data); } } -void DownloadDialog::selectDirectories() { +bool DownloadDialog::selectDirectories() { //first user should select remote directory to download - if (_remoteBrowser->runModal() <= 0) return; + if (_remoteBrowser->runModal() <= 0) return false; Cloud::StorageFile remoteDirectory = _remoteBrowser->getResult(); //now user should select local directory to download into - if (_browser->runModal() <= 0) return; + if (_browser->runModal() <= 0) return false; Common::FSNode dir(_browser->getResult()); Common::FSList files; if (!dir.getChildren(files, Common::FSNode::kListAll)) { MessageDialog alert(_("ScummVM couldn't open the specified directory!")); alert.runModal(); - return; + return false; } //check that there is no file with the remote directory's name in the local one @@ -121,14 +123,14 @@ void DownloadDialog::selectDirectories() { if (!i->isDirectory()) { GUI::MessageDialog alert(_("Cannot create a directory to download - the specified directory has a file with the same name."), _("OK")); alert.runModal(); - return; + return false; } GUI::MessageDialog alert( Common::String::format(_("The \"%s\" already exists in the specified directory.\nDo you really want to download files into that directory?"), remoteDirectory.name().c_str()), _("Yes"), _("No") ); - if (alert.runModal() != GUI::kMessageOK) return; + if (alert.runModal() != GUI::kMessageOK) return false; break; } } @@ -149,9 +151,16 @@ void DownloadDialog::selectDirectories() { CloudMan.startDownload(remoteDirectory.path(), localPath); CloudMan.setDownloadTarget(this); + return true; } void DownloadDialog::handleTickle() { + if (_close) { + close(); + _close = false; + return; + } + if (_reflow) { reflowLayout(); draw(); @@ -163,27 +172,15 @@ void DownloadDialog::handleTickle() { void DownloadDialog::reflowLayout() { Dialog::reflowLayout(); - updateButtons(); + refreshWidgets(); } -void DownloadDialog::updateButtons() { - bool downloading = CloudMan.isDownloading(); - if (downloading) { - _messageText->setLabel(_("Press the button to cancel the download")); - _mainButton->setLabel(_("Cancel the download")); - _remoteDirectoryLabel->setLabel(_("From: ") + CloudMan.getDownloadRemoteDirectory()); - _localDirectoryLabel->setLabel(_("To: ") + CloudMan.getDownloadLocalDirectory()); - uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); - _percentLabel->setLabel(Common::String::format("%u %%", progress)); - _progressBar->setValue(progress); - } else { - _messageText->setLabel(_("Press the button to download a directory")); - _mainButton->setLabel(_("Start download")); - } - _remoteDirectoryLabel->setVisible(downloading); - _localDirectoryLabel->setVisible(downloading); - _percentLabel->setVisible(downloading); - _progressBar->setVisible(downloading); +void DownloadDialog::refreshWidgets() { + _remoteDirectoryLabel->setLabel(_("From: ") + CloudMan.getDownloadRemoteDirectory()); + _localDirectoryLabel->setLabel(_("To: ") + CloudMan.getDownloadLocalDirectory()); + uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); + _percentLabel->setLabel(Common::String::format("%u %%", progress)); + _progressBar->setValue(progress); } } // End of namespace GUI -- cgit v1.2.3 From 2284333b1c9348638ce0255668f4c0abb85aeb84 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 4 Jul 2016 18:36:47 +0600 Subject: GUI: Add lowres support for DownloadDialog's button No actual translations, though. Should be just "Cancel", because "Cancel download" is too long for lowres mode. --- gui/downloaddialog.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index 9c48111153..d9260306e2 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -53,7 +53,11 @@ DownloadDialog::DownloadDialog(uint32 storageId): _progressBar->setValue(progress); _progressBar->setEnabled(false); _percentLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.PercentText", Common::String::format("%u %%", progress)); - _cancelButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _("Cancel download"), 0, kDownloadDialogButtonCmd); + if (g_system->getOverlayWidth() > 320) + _cancelButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _("Cancel download"), 0, kDownloadDialogButtonCmd); + else + _cancelButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _c("Cancel download", "lowres"), 0, kDownloadDialogButtonCmd); + _closeButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.CloseButton", _("OK"), 0, kCloseCmd); refreshWidgets(); -- cgit v1.2.3 From d5753a484719019af9b322a74c414a9d242f8f83 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Sun, 10 Jul 2016 11:05:00 +0600 Subject: CLOUD: Add auto-detect for downloaded game If that's the game, that is. Method is copy-pasted from Launcher, but fixed not to ask the directory and thus doesn't contain the loop. --- gui/downloaddialog.cpp | 100 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 87 insertions(+), 13 deletions(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index d9260306e2..001a058205 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -21,15 +21,17 @@ */ #include "gui/downloaddialog.h" -#include "gui/widgets/list.h" -#include "gui/widget.h" -#include "gui/gui-manager.h" #include "backends/cloud/cloudmanager.h" +#include "common/config-manager.h" #include "common/translation.h" -#include "widgets/edittext.h" -#include "message.h" -#include "browser.h" -#include "remotebrowser.h" +#include "engines/metaengine.h" +#include "gui/browser.h" +#include "gui/chooser.h" +#include "gui/editgamedialog.h" +#include "gui/message.h" +#include "gui/remotebrowser.h" +#include "gui/widgets/edittext.h" +#include "gui/widgets/list.h" namespace GUI { @@ -38,7 +40,7 @@ enum { }; DownloadDialog::DownloadDialog(uint32 storageId): - Dialog("GlobalOptions_Cloud_DownloadDialog"), _close(false), _reflow(false) { + Dialog("GlobalOptions_Cloud_DownloadDialog"), _close(false), _redraw(false) { _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; _browser = new BrowserDialog(_("Select directory where to download game data"), true); @@ -93,7 +95,7 @@ void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat case kDownloadProgressCmd: _percentLabel->setLabel(Common::String::format("%u %%", data)); _progressBar->setValue(data); - _reflow = true; + _redraw = true; break; case kDownloadEndedCmd: _close = true; @@ -155,33 +157,105 @@ bool DownloadDialog::selectDirectories() { CloudMan.startDownload(remoteDirectory.path(), localPath); CloudMan.setDownloadTarget(this); + _localDirectory = localPath; return true; } void DownloadDialog::handleTickle() { if (_close) { + addGame(); close(); _close = false; return; } - if (_reflow) { - reflowLayout(); + if (_redraw) { + refreshWidgets(); draw(); - _reflow = false; + _redraw = false; } Dialog::handleTickle(); } +void DownloadDialog::addGame() { + // Allow user to add a new game to the list. + // 2) try to auto detect which game is in the directory, if we cannot + // determine it uniquely present a list of candidates to the user + // to pick from + // 3) Display the 'Edit' dialog for that item, letting the user specify + // an alternate description (to distinguish multiple versions of the + // game, e.g. 'Monkey German' and 'Monkey English') and set default + // options for that game + // 4) If no game is found in the specified directory, return to the + // dialog. + + // User made his choice... + Common::FSNode dir(_localDirectory); + Common::FSList files; + if (!dir.getChildren(files, Common::FSNode::kListAll)) { + MessageDialog alert(_("ScummVM couldn't open the specified directory!")); + alert.runModal(); + return; + } + + // ...so let's determine a list of candidates, games that + // could be contained in the specified directory. + GameList candidates(EngineMan.detectGames(files)); + + int idx; + if (candidates.empty()) { + // No game was found in the specified directory + MessageDialog alert(_("ScummVM could not find any game in the specified directory!")); + alert.runModal(); + return; + } + + if (candidates.size() == 1) { + // Exact match + idx = 0; + } else { + // Display the candidates to the user and let her/him pick one + Common::StringArray list; + for (idx = 0; idx < (int)candidates.size(); idx++) + list.push_back(candidates[idx].description()); + + ChooserDialog dialog(_("Pick the game:")); + dialog.setList(list); + idx = dialog.runModal(); + } + if (0 <= idx && idx < (int)candidates.size()) { + GameDescriptor result = candidates[idx]; + + // TODO: Change the detectors to set "path" ! + result["path"] = dir.getPath(); + + Common::String domain = addGameToConf(result); + + // Display edit dialog for the new entry + EditGameDialog editDialog(domain, result.description()); + if (editDialog.runModal() > 0) { + // User pressed OK, so make changes permanent + + // Write config to disk + ConfMan.flushToDisk(); + } else { + // User aborted, remove the the new domain again + ConfMan.removeGameDomain(domain); + } + + } +} + void DownloadDialog::reflowLayout() { Dialog::reflowLayout(); refreshWidgets(); } void DownloadDialog::refreshWidgets() { + _localDirectory = CloudMan.getDownloadLocalDirectory(); _remoteDirectoryLabel->setLabel(_("From: ") + CloudMan.getDownloadRemoteDirectory()); - _localDirectoryLabel->setLabel(_("To: ") + CloudMan.getDownloadLocalDirectory()); + _localDirectoryLabel->setLabel(_("To: ") + _localDirectory); uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); _percentLabel->setLabel(Common::String::format("%u %%", progress)); _progressBar->setValue(progress); -- cgit v1.2.3 From f01402f4d8cfa5123677708622c4d15e30724b7c Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 11 Jul 2016 14:24:30 +0600 Subject: GUI: Remove unnecessary DownloadDialog's flag --- gui/downloaddialog.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index 001a058205..1d838f142c 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -40,7 +40,7 @@ enum { }; DownloadDialog::DownloadDialog(uint32 storageId): - Dialog("GlobalOptions_Cloud_DownloadDialog"), _close(false), _redraw(false) { + Dialog("GlobalOptions_Cloud_DownloadDialog"), _close(false) { _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; _browser = new BrowserDialog(_("Select directory where to download game data"), true); @@ -72,6 +72,7 @@ DownloadDialog::~DownloadDialog() { void DownloadDialog::open() { Dialog::open(); + CloudMan.setDownloadTarget(this); if (!CloudMan.isDownloading()) if (!selectDirectories()) close(); @@ -92,10 +93,11 @@ void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat close(); break; } - case kDownloadProgressCmd: - _percentLabel->setLabel(Common::String::format("%u %%", data)); - _progressBar->setValue(data); - _redraw = true; + case kDownloadProgressCmd: + if (!_close) { + refreshWidgets(); + draw(); + } break; case kDownloadEndedCmd: _close = true; @@ -169,12 +171,6 @@ void DownloadDialog::handleTickle() { return; } - if (_redraw) { - refreshWidgets(); - draw(); - _redraw = false; - } - Dialog::handleTickle(); } -- cgit v1.2.3 From d795c77ef53720fa423d9b827a66d1bea8b8e761 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 12 Jul 2016 14:00:11 +0600 Subject: GUI: Fix DownloadDialog detection Now it calls Launcher directly, so it updates games list on success. --- gui/downloaddialog.cpp | 77 ++++---------------------------------------------- 1 file changed, 5 insertions(+), 72 deletions(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index 1d838f142c..5ed287160f 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -28,6 +28,7 @@ #include "gui/browser.h" #include "gui/chooser.h" #include "gui/editgamedialog.h" +#include "gui/launcher.h" #include "gui/message.h" #include "gui/remotebrowser.h" #include "gui/widgets/edittext.h" @@ -39,8 +40,8 @@ enum { kDownloadDialogButtonCmd = 'Dldb' }; -DownloadDialog::DownloadDialog(uint32 storageId): - Dialog("GlobalOptions_Cloud_DownloadDialog"), _close(false) { +DownloadDialog::DownloadDialog(uint32 storageId, LauncherDialog *launcher): + Dialog("GlobalOptions_Cloud_DownloadDialog"), _launcher(launcher), _close(false) { _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; _browser = new BrowserDialog(_("Select directory where to download game data"), true); @@ -165,7 +166,8 @@ bool DownloadDialog::selectDirectories() { void DownloadDialog::handleTickle() { if (_close) { - addGame(); + if (_launcher) + _launcher->doGameDetection(_localDirectory); close(); _close = false; return; @@ -174,75 +176,6 @@ void DownloadDialog::handleTickle() { Dialog::handleTickle(); } -void DownloadDialog::addGame() { - // Allow user to add a new game to the list. - // 2) try to auto detect which game is in the directory, if we cannot - // determine it uniquely present a list of candidates to the user - // to pick from - // 3) Display the 'Edit' dialog for that item, letting the user specify - // an alternate description (to distinguish multiple versions of the - // game, e.g. 'Monkey German' and 'Monkey English') and set default - // options for that game - // 4) If no game is found in the specified directory, return to the - // dialog. - - // User made his choice... - Common::FSNode dir(_localDirectory); - Common::FSList files; - if (!dir.getChildren(files, Common::FSNode::kListAll)) { - MessageDialog alert(_("ScummVM couldn't open the specified directory!")); - alert.runModal(); - return; - } - - // ...so let's determine a list of candidates, games that - // could be contained in the specified directory. - GameList candidates(EngineMan.detectGames(files)); - - int idx; - if (candidates.empty()) { - // No game was found in the specified directory - MessageDialog alert(_("ScummVM could not find any game in the specified directory!")); - alert.runModal(); - return; - } - - if (candidates.size() == 1) { - // Exact match - idx = 0; - } else { - // Display the candidates to the user and let her/him pick one - Common::StringArray list; - for (idx = 0; idx < (int)candidates.size(); idx++) - list.push_back(candidates[idx].description()); - - ChooserDialog dialog(_("Pick the game:")); - dialog.setList(list); - idx = dialog.runModal(); - } - if (0 <= idx && idx < (int)candidates.size()) { - GameDescriptor result = candidates[idx]; - - // TODO: Change the detectors to set "path" ! - result["path"] = dir.getPath(); - - Common::String domain = addGameToConf(result); - - // Display edit dialog for the new entry - EditGameDialog editDialog(domain, result.description()); - if (editDialog.runModal() > 0) { - // User pressed OK, so make changes permanent - - // Write config to disk - ConfMan.flushToDisk(); - } else { - // User aborted, remove the the new domain again - ConfMan.removeGameDomain(domain); - } - - } -} - void DownloadDialog::reflowLayout() { Dialog::reflowLayout(); refreshWidgets(); -- cgit v1.2.3 From dfd68306de6f655a7bd2c68cea0b9299956ce8fc Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 14 Jul 2016 10:17:26 +0600 Subject: CLOUD: Upgrade FolderDownloadRequest::getProgress() Now NetworkReadStream, which is used in DownloadRequest, which is used in FolderDownloadRequest, returns progress information provided by libcurl. --- gui/downloaddialog.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index 5ed287160f..bfdd3d8928 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -173,6 +173,12 @@ void DownloadDialog::handleTickle() { return; } + uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); + if (_progressBar->getValue() != progress) { + refreshWidgets(); + draw(); + } + Dialog::handleTickle(); } -- cgit v1.2.3 From cdf8ab7949b93f30522ea2742eb4cea3cfcec778 Mon Sep 17 00:00:00 2001 From: Peter Bozsó Date: Thu, 14 Jul 2016 10:19:04 +0200 Subject: GUI: Change 'OK' to 'Hide' on close button of DownloadDialog --- gui/downloaddialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index bfdd3d8928..1ae4942928 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -61,7 +61,7 @@ DownloadDialog::DownloadDialog(uint32 storageId, LauncherDialog *launcher): else _cancelButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _c("Cancel download", "lowres"), 0, kDownloadDialogButtonCmd); - _closeButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.CloseButton", _("OK"), 0, kCloseCmd); + _closeButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.CloseButton", _("Hide"), 0, kCloseCmd); refreshWidgets(); CloudMan.setDownloadTarget(this); -- cgit v1.2.3 From 0ca791709329c3e7f24f68fa2da7c86c87dac557 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 14 Jul 2016 15:29:47 +0600 Subject: CLOUD: Update FolderDownloadRequest It now keeps track of downloaded bytes. --- gui/downloaddialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index 1ae4942928..fde560f271 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -192,7 +192,7 @@ void DownloadDialog::refreshWidgets() { _remoteDirectoryLabel->setLabel(_("From: ") + CloudMan.getDownloadRemoteDirectory()); _localDirectoryLabel->setLabel(_("To: ") + _localDirectory); uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); - _percentLabel->setLabel(Common::String::format("%u %%", progress)); + _percentLabel->setLabel(Common::String::format("%u %% (%u bytes out of %u)", progress, CloudMan.getDownloadBytesNumber(), CloudMan.getDownloadTotalBytesNumber())); _progressBar->setValue(progress); } -- cgit v1.2.3 From c431ae6d84be1ef73c44b84c58ee3d9edff3d5e3 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 14 Jul 2016 16:01:05 +0600 Subject: CLOUD: Calculate FolderDownload download speed --- gui/downloaddialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index fde560f271..d734839cea 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -192,7 +192,7 @@ void DownloadDialog::refreshWidgets() { _remoteDirectoryLabel->setLabel(_("From: ") + CloudMan.getDownloadRemoteDirectory()); _localDirectoryLabel->setLabel(_("To: ") + _localDirectory); uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); - _percentLabel->setLabel(Common::String::format("%u %% (%u bytes out of %u)", progress, CloudMan.getDownloadBytesNumber(), CloudMan.getDownloadTotalBytesNumber())); + _percentLabel->setLabel(Common::String::format("%u %% (%u bytes out of %u - %u bytes per second)", progress, CloudMan.getDownloadBytesNumber(), CloudMan.getDownloadTotalBytesNumber(), CloudMan.getDownloadSpeed())); _progressBar->setValue(progress); } -- cgit v1.2.3 From 1b56f59add45af1894957a58fb4cf662f534d54d Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 14 Jul 2016 16:53:38 +0600 Subject: GUI: Update DownloadDialog It now has download size and speed labels. Commit also fixes minor mistake in ConnMan. --- gui/downloaddialog.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 9 deletions(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index d734839cea..42c962895f 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -37,16 +37,16 @@ namespace GUI { enum { - kDownloadDialogButtonCmd = 'Dldb' + kDownloadDialogButtonCmd = 'Dldb' }; -DownloadDialog::DownloadDialog(uint32 storageId, LauncherDialog *launcher): +DownloadDialog::DownloadDialog(uint32 storageId, LauncherDialog *launcher) : Dialog("GlobalOptions_Cloud_DownloadDialog"), _launcher(launcher), _close(false) { _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; _browser = new BrowserDialog(_("Select directory where to download game data"), true); _remoteBrowser = new RemoteBrowserDialog(_("Select directory with game data")); - + _remoteDirectoryLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.RemoteDirectory", _("From: ")); _localDirectoryLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.LocalDirectory", _("To: ")); uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); @@ -56,14 +56,16 @@ DownloadDialog::DownloadDialog(uint32 storageId, LauncherDialog *launcher): _progressBar->setValue(progress); _progressBar->setEnabled(false); _percentLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.PercentText", Common::String::format("%u %%", progress)); - if (g_system->getOverlayWidth() > 320) + _downloadSizeLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.DownloadSize", ""); + _downloadSpeedLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.DownloadSpeed", ""); + if (g_system->getOverlayWidth() > 320) _cancelButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _("Cancel download"), 0, kDownloadDialogButtonCmd); else _cancelButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.MainButton", _c("Cancel download", "lowres"), 0, kDownloadDialogButtonCmd); - + _closeButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.CloseButton", _("Hide"), 0, kCloseCmd); refreshWidgets(); - + CloudMan.setDownloadTarget(this); } @@ -88,7 +90,8 @@ void DownloadDialog::close() { void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { - case kDownloadDialogButtonCmd: { + case kDownloadDialogButtonCmd: + { CloudMan.setDownloadTarget(nullptr); CloudMan.cancelDownload(); close(); @@ -138,7 +141,7 @@ bool DownloadDialog::selectDirectories() { Common::String::format(_("The \"%s\" already exists in the specified directory.\nDo you really want to download files into that directory?"), remoteDirectory.name().c_str()), _("Yes"), _("No") - ); + ); if (alert.runModal() != GUI::kMessageOK) return false; break; } @@ -187,12 +190,65 @@ void DownloadDialog::reflowLayout() { refreshWidgets(); } +namespace { +Common::String getHumanReadableBytes(uint64 bytes, Common::String &unitsOut) { + Common::String result = Common::String::format("%u", bytes); + unitsOut = "B"; + + if (bytes >= 1024) { + bytes /= 1024; + result = Common::String::format("%u", bytes); + unitsOut = "KB"; + } + + double floating = bytes; + + if (bytes >= 1024) { + bytes /= 1024; + floating /= 1024.0; + unitsOut = "MB"; + } + + if (bytes >= 1024) { + bytes /= 1024; + floating /= 1024.0; + unitsOut = "GB"; + } + + if (bytes >= 1024) { // woah + bytes /= 1024; + floating /= 1024.0; + unitsOut = "TB"; + } + + // print one digit after floating point + result = Common::String::format("%.1lf", floating); + return result; +} +} + +Common::String DownloadDialog::getSizeLabelText() { + Common::String downloaded, downloadedUnits, total, totalUnits; + downloaded = getHumanReadableBytes(CloudMan.getDownloadBytesNumber(), downloadedUnits); + total = getHumanReadableBytes(CloudMan.getDownloadTotalBytesNumber(), totalUnits); + return Common::String::format(_("Downloaded %s %s / %s %s"), downloaded.c_str(), _(downloadedUnits.c_str()), total.c_str(), _(totalUnits.c_str())); +} + +Common::String DownloadDialog::getSpeedLabelText() { + Common::String speed, speedUnits; + speed = getHumanReadableBytes(CloudMan.getDownloadSpeed(), speedUnits); + speedUnits += "/s"; + return Common::String::format("Download speed: %s %s", speed.c_str(), _(speedUnits.c_str())); +} + void DownloadDialog::refreshWidgets() { _localDirectory = CloudMan.getDownloadLocalDirectory(); _remoteDirectoryLabel->setLabel(_("From: ") + CloudMan.getDownloadRemoteDirectory()); _localDirectoryLabel->setLabel(_("To: ") + _localDirectory); uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); - _percentLabel->setLabel(Common::String::format("%u %% (%u bytes out of %u - %u bytes per second)", progress, CloudMan.getDownloadBytesNumber(), CloudMan.getDownloadTotalBytesNumber(), CloudMan.getDownloadSpeed())); + _percentLabel->setLabel(Common::String::format("%u %%", progress)); + _downloadSizeLabel->setLabel(getSizeLabelText()); + _downloadSpeedLabel->setLabel(getSpeedLabelText()); _progressBar->setValue(progress); } -- cgit v1.2.3 From a11b004b6bc18a23b5ab257f4da4ff9e5429c9d9 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 20 Jul 2016 12:14:22 +0600 Subject: GUI: Show warning in DownloadDialog If user's connection seems limited, ScummVM shows a warning message to prevent using that by accident. --- gui/downloaddialog.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index 42c962895f..df8783736e 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -22,6 +22,7 @@ #include "gui/downloaddialog.h" #include "backends/cloud/cloudmanager.h" +#include "backends/networking/connection/islimited.h" #include "common/config-manager.h" #include "common/translation.h" #include "engines/metaengine.h" @@ -112,6 +113,12 @@ void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat } bool DownloadDialog::selectDirectories() { + if (Networking::Connection::isLimited()) { + MessageDialog alert(_("It looks like your connection is limited. " + "Do you really want to download files with it?"), _("Yes"), _("No")); + if (alert.runModal() != GUI::kMessageOK) return false; + } + //first user should select remote directory to download if (_remoteBrowser->runModal() <= 0) return false; -- cgit v1.2.3 From 438ba985a4a97a8695a6e6fdda6930694976c07b Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 21 Jul 2016 11:44:36 +0600 Subject: JANITORIAL: Remove spaces at the end of the line I knew there were some, but I wanted to fix them once, instead of doing it all the time. --- gui/downloaddialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index df8783736e..a90783de9e 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -119,7 +119,7 @@ bool DownloadDialog::selectDirectories() { if (alert.runModal() != GUI::kMessageOK) return false; } - //first user should select remote directory to download + //first user should select remote directory to download if (_remoteBrowser->runModal() <= 0) return false; Cloud::StorageFile remoteDirectory = _remoteBrowser->getResult(); @@ -248,7 +248,7 @@ Common::String DownloadDialog::getSpeedLabelText() { return Common::String::format("Download speed: %s %s", speed.c_str(), _(speedUnits.c_str())); } -void DownloadDialog::refreshWidgets() { +void DownloadDialog::refreshWidgets() { _localDirectory = CloudMan.getDownloadLocalDirectory(); _remoteDirectoryLabel->setLabel(_("From: ") + CloudMan.getDownloadRemoteDirectory()); _localDirectoryLabel->setLabel(_("To: ") + _localDirectory); -- cgit v1.2.3 From e114d1a697b21203b09ca2c607cbd86c3db05328 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 22 Jul 2016 14:15:06 +0300 Subject: GUI: Fix format warning --- gui/downloaddialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index a90783de9e..495e9c13f0 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -199,12 +199,12 @@ void DownloadDialog::reflowLayout() { namespace { Common::String getHumanReadableBytes(uint64 bytes, Common::String &unitsOut) { - Common::String result = Common::String::format("%u", bytes); + Common::String result = Common::String::format("%lu", bytes); unitsOut = "B"; if (bytes >= 1024) { bytes /= 1024; - result = Common::String::format("%u", bytes); + result = Common::String::format("%lu", bytes); unitsOut = "KB"; } -- cgit v1.2.3 From 53aa0c46f1a5d6aefe3f2a087c60d9a59439aedf Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 22 Jul 2016 15:48:46 +0300 Subject: GUI: JANITORIAL: Fix code formatting --- gui/downloaddialog.cpp | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'gui/downloaddialog.cpp') diff --git a/gui/downloaddialog.cpp b/gui/downloaddialog.cpp index 495e9c13f0..ea7ace2f2a 100644 --- a/gui/downloaddialog.cpp +++ b/gui/downloaddialog.cpp @@ -92,12 +92,12 @@ void DownloadDialog::close() { void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { case kDownloadDialogButtonCmd: - { - CloudMan.setDownloadTarget(nullptr); - CloudMan.cancelDownload(); - close(); - break; - } + { + CloudMan.setDownloadTarget(nullptr); + CloudMan.cancelDownload(); + close(); + break; + } case kDownloadProgressCmd: if (!_close) { refreshWidgets(); @@ -116,16 +116,19 @@ bool DownloadDialog::selectDirectories() { if (Networking::Connection::isLimited()) { MessageDialog alert(_("It looks like your connection is limited. " "Do you really want to download files with it?"), _("Yes"), _("No")); - if (alert.runModal() != GUI::kMessageOK) return false; + if (alert.runModal() != GUI::kMessageOK) + return false; } //first user should select remote directory to download - if (_remoteBrowser->runModal() <= 0) return false; + if (_remoteBrowser->runModal() <= 0) + return false; Cloud::StorageFile remoteDirectory = _remoteBrowser->getResult(); //now user should select local directory to download into - if (_browser->runModal() <= 0) return false; + if (_browser->runModal() <= 0) + return false; Common::FSNode dir(_browser->getResult()); Common::FSList files; @@ -149,7 +152,8 @@ bool DownloadDialog::selectDirectories() { _("Yes"), _("No") ); - if (alert.runModal() != GUI::kMessageOK) return false; + if (alert.runModal() != GUI::kMessageOK) + return false; break; } } @@ -161,12 +165,18 @@ bool DownloadDialog::selectDirectories() { if (localPath.size() && localPath.lastChar() != '/' && localPath.lastChar() != '\\') { int backslashes = 0; for (uint32 i = 0; i < localPath.size(); ++i) - if (localPath[i] == '/') --backslashes; - else if (localPath[i] == '\\') ++backslashes; - - if (backslashes > 0) localPath += '\\' + remoteDirectory.name(); - else localPath += '/' + remoteDirectory.name(); - } else localPath += remoteDirectory.name(); + if (localPath[i] == '/') + --backslashes; + else if (localPath[i] == '\\') + ++backslashes; + + if (backslashes > 0) + localPath += '\\' + remoteDirectory.name(); + else + localPath += '/' + remoteDirectory.name(); + } else { + localPath += remoteDirectory.name(); + } CloudMan.startDownload(remoteDirectory.path(), localPath); CloudMan.setDownloadTarget(this); -- cgit v1.2.3