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.
This commit is contained in:
Alexander Tkachev 2016-07-04 18:30:23 +06:00
parent 1cfdb96616
commit a5765a339e
4 changed files with 51 additions and 60 deletions

View file

@ -38,14 +38,12 @@ enum {
}; };
DownloadDialog::DownloadDialog(uint32 storageId): DownloadDialog::DownloadDialog(uint32 storageId):
Dialog("GlobalOptions_Cloud_DownloadDialog"), _reflow(false) { Dialog("GlobalOptions_Cloud_DownloadDialog"), _close(false), _reflow(false) {
_backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain;
_browser = new BrowserDialog(_("Select directory where to download game data"), true); _browser = new BrowserDialog(_("Select directory where to download game data"), true);
_remoteBrowser = new RemoteBrowserDialog(_("Select directory with game data")); _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: ")); _remoteDirectoryLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.RemoteDirectory", _("From: "));
_localDirectoryLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.LocalDirectory", _("To: ")); _localDirectoryLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.LocalDirectory", _("To: "));
uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress()); uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress());
@ -55,9 +53,10 @@ DownloadDialog::DownloadDialog(uint32 storageId):
_progressBar->setValue(progress); _progressBar->setValue(progress);
_progressBar->setEnabled(false); _progressBar->setEnabled(false);
_percentLabel = new StaticTextWidget(this, "GlobalOptions_Cloud_DownloadDialog.PercentText", Common::String::format("%u %%", progress)); _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); _closeButton = new ButtonWidget(this, "GlobalOptions_Cloud_DownloadDialog.CloseButton", _("OK"), 0, kCloseCmd);
updateButtons(); refreshWidgets();
CloudMan.setDownloadTarget(this); CloudMan.setDownloadTarget(this);
} }
@ -65,6 +64,15 @@ DownloadDialog::~DownloadDialog() {
CloudMan.setDownloadTarget(nullptr); CloudMan.setDownloadTarget(nullptr);
} }
void DownloadDialog::open() {
Dialog::open();
if (!CloudMan.isDownloading())
if (!selectDirectories())
close();
reflowLayout();
draw();
}
void DownloadDialog::close() { void DownloadDialog::close() {
CloudMan.setDownloadTarget(nullptr); CloudMan.setDownloadTarget(nullptr);
Dialog::close(); Dialog::close();
@ -72,16 +80,10 @@ void DownloadDialog::close() {
void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) { switch (cmd) {
case kDownloadDialogButtonCmd: { case kDownloadDialogButtonCmd: {
if (CloudMan.isDownloading()) { CloudMan.setDownloadTarget(nullptr);
CloudMan.setDownloadTarget(nullptr); CloudMan.cancelDownload();
CloudMan.cancelDownload(); close();
} else {
selectDirectories();
}
reflowLayout();
draw();
break; break;
} }
case kDownloadProgressCmd: case kDownloadProgressCmd:
@ -90,28 +92,28 @@ void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
_reflow = true; _reflow = true;
break; break;
case kDownloadEndedCmd: case kDownloadEndedCmd:
_reflow = true; _close = true;
break; break;
default: default:
Dialog::handleCommand(sender, cmd, data); Dialog::handleCommand(sender, cmd, data);
} }
} }
void DownloadDialog::selectDirectories() { bool DownloadDialog::selectDirectories() {
//first user should select remote directory to download //first user should select remote directory to download
if (_remoteBrowser->runModal() <= 0) return; if (_remoteBrowser->runModal() <= 0) return false;
Cloud::StorageFile remoteDirectory = _remoteBrowser->getResult(); Cloud::StorageFile remoteDirectory = _remoteBrowser->getResult();
//now user should select local directory to download into //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::FSNode dir(_browser->getResult());
Common::FSList files; Common::FSList files;
if (!dir.getChildren(files, Common::FSNode::kListAll)) { if (!dir.getChildren(files, Common::FSNode::kListAll)) {
MessageDialog alert(_("ScummVM couldn't open the specified directory!")); MessageDialog alert(_("ScummVM couldn't open the specified directory!"));
alert.runModal(); alert.runModal();
return; return false;
} }
//check that there is no file with the remote directory's name in the local one //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()) { if (!i->isDirectory()) {
GUI::MessageDialog alert(_("Cannot create a directory to download - the specified directory has a file with the same name."), _("OK")); GUI::MessageDialog alert(_("Cannot create a directory to download - the specified directory has a file with the same name."), _("OK"));
alert.runModal(); alert.runModal();
return; return false;
} }
GUI::MessageDialog alert( 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()), 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"), _("Yes"),
_("No") _("No")
); );
if (alert.runModal() != GUI::kMessageOK) return; if (alert.runModal() != GUI::kMessageOK) return false;
break; break;
} }
} }
@ -149,9 +151,16 @@ void DownloadDialog::selectDirectories() {
CloudMan.startDownload(remoteDirectory.path(), localPath); CloudMan.startDownload(remoteDirectory.path(), localPath);
CloudMan.setDownloadTarget(this); CloudMan.setDownloadTarget(this);
return true;
} }
void DownloadDialog::handleTickle() { void DownloadDialog::handleTickle() {
if (_close) {
close();
_close = false;
return;
}
if (_reflow) { if (_reflow) {
reflowLayout(); reflowLayout();
draw(); draw();
@ -163,27 +172,15 @@ void DownloadDialog::handleTickle() {
void DownloadDialog::reflowLayout() { void DownloadDialog::reflowLayout() {
Dialog::reflowLayout(); Dialog::reflowLayout();
updateButtons(); refreshWidgets();
} }
void DownloadDialog::updateButtons() { void DownloadDialog::refreshWidgets() {
bool downloading = CloudMan.isDownloading(); _remoteDirectoryLabel->setLabel(_("From: ") + CloudMan.getDownloadRemoteDirectory());
if (downloading) { _localDirectoryLabel->setLabel(_("To: ") + CloudMan.getDownloadLocalDirectory());
_messageText->setLabel(_("Press the button to cancel the download")); uint32 progress = (uint32)(100 * CloudMan.getDownloadingProgress());
_mainButton->setLabel(_("Cancel the download")); _percentLabel->setLabel(Common::String::format("%u %%", progress));
_remoteDirectoryLabel->setLabel(_("From: ") + CloudMan.getDownloadRemoteDirectory()); _progressBar->setValue(progress);
_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 } // End of namespace GUI

View file

@ -45,24 +45,24 @@ enum DownloadProgress {
class DownloadDialog : public Dialog { class DownloadDialog : public Dialog {
BrowserDialog *_browser; BrowserDialog *_browser;
RemoteBrowserDialog *_remoteBrowser; RemoteBrowserDialog *_remoteBrowser;
StaticTextWidget *_messageText;
ButtonWidget *_mainButton;
StaticTextWidget *_remoteDirectoryLabel; StaticTextWidget *_remoteDirectoryLabel;
StaticTextWidget *_localDirectoryLabel; StaticTextWidget *_localDirectoryLabel;
StaticTextWidget *_percentLabel; StaticTextWidget *_percentLabel;
SliderWidget *_progressBar; SliderWidget *_progressBar;
ButtonWidget *_cancelButton;
ButtonWidget *_closeButton; ButtonWidget *_closeButton;
bool _reflow; bool _close, _reflow;
void updateButtons(); void refreshWidgets();
void selectDirectories(); bool selectDirectories();
public: public:
DownloadDialog(uint32 storageId); DownloadDialog(uint32 storageId);
virtual ~DownloadDialog(); virtual ~DownloadDialog();
virtual void open();
virtual void close(); virtual void close();
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
virtual void handleTickle(); virtual void handleTickle();

View file

@ -588,12 +588,6 @@
<dialog name = 'GlobalOptions_Cloud_DownloadDialog' overlays = 'Dialog.GlobalOptions'> <dialog name = 'GlobalOptions_Cloud_DownloadDialog' overlays = 'Dialog.GlobalOptions'>
<layout type = 'vertical' padding = '16, 16, 16, 8' spacing = '8'> <layout type = 'vertical' padding = '16, 16, 16, 8' spacing = '8'>
<widget name = 'DialogDesc'
height = 'Globals.Line.Height'
/>
<widget name = 'MainButton'
type = 'Button'
/>
<widget name = 'RemoteDirectory' <widget name = 'RemoteDirectory'
height = 'Globals.Line.Height' height = 'Globals.Line.Height'
/> />
@ -610,6 +604,9 @@
/> />
<space/> <space/>
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10'> <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10'>
<widget name = 'MainButton'
type = 'Button'
/>
<space/> <space/>
<widget name = 'CloseButton' <widget name = 'CloseButton'
type = 'Button' type = 'Button'

View file

@ -585,12 +585,6 @@
<dialog name = 'GlobalOptions_Cloud_DownloadDialog' overlays = 'Dialog.GlobalOptions'> <dialog name = 'GlobalOptions_Cloud_DownloadDialog' overlays = 'Dialog.GlobalOptions'>
<layout type = 'vertical' padding = '8, 8, 8, 4' spacing = '8'> <layout type = 'vertical' padding = '8, 8, 8, 4' spacing = '8'>
<widget name = 'DialogDesc'
height = 'Globals.Line.Height'
/>
<widget name = 'MainButton'
type = 'Button'
/>
<widget name = 'RemoteDirectory' <widget name = 'RemoteDirectory'
height = 'Globals.Line.Height' height = 'Globals.Line.Height'
/> />
@ -607,6 +601,9 @@
/> />
<space/> <space/>
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6'> <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6'>
<widget name = 'MainButton'
type = 'Button'
/>
<space/> <space/>
<widget name = 'CloseButton' <widget name = 'CloseButton'
type = 'Button' type = 'Button'