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):
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

View file

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

View file

@ -588,12 +588,6 @@
<dialog name = 'GlobalOptions_Cloud_DownloadDialog' overlays = 'Dialog.GlobalOptions'>
<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'
height = 'Globals.Line.Height'
/>
@ -610,6 +604,9 @@
/>
<space/>
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10'>
<widget name = 'MainButton'
type = 'Button'
/>
<space/>
<widget name = 'CloseButton'
type = 'Button'

View file

@ -585,12 +585,6 @@
<dialog name = 'GlobalOptions_Cloud_DownloadDialog' overlays = 'Dialog.GlobalOptions'>
<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'
height = 'Globals.Line.Height'
/>
@ -607,6 +601,9 @@
/>
<space/>
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6'>
<widget name = 'MainButton'
type = 'Button'
/>
<space/>
<widget name = 'CloseButton'
type = 'Button'