GUI: Add Options dialog Cloud tab

With StorageBrowser to select a Storage. It actually uses CloudMan to
switch active Storage.
This commit is contained in:
Alexander Tkachev 2016-06-08 18:56:17 +06:00
parent 870e96eb9c
commit 90ae7b7337
7 changed files with 234 additions and 1 deletions

View file

@ -18,6 +18,7 @@ MODULE_OBJS := \
predictivedialog.o \
saveload.o \
saveload-dialog.o \
storagebrowser.o \
themebrowser.o \
ThemeEngine.o \
ThemeEval.o \

View file

@ -43,6 +43,11 @@
#include "audio/mixer.h"
#include "audio/fmopl.h"
#ifdef USE_CLOUD
#include "backends/cloud/cloudmanager.h"
#include "gui/storagebrowser.h"
#endif
namespace GUI {
enum {
@ -84,6 +89,12 @@ enum {
};
#endif
#ifdef USE_CLOUD
enum {
kChooseStorageCmd = 'chst'
};
#endif
static const char *savePeriodLabels[] = { _s("Never"), _s("every 5 mins"), _s("every 10 mins"), _s("every 15 mins"), _s("every 30 mins"), 0 };
static const int savePeriodValues[] = { 0, 5 * 60, 10 * 60, 15 * 60, 30 * 60, -1 };
static const char *outputRateLabels[] = { _s("<default>"), _s("8 kHz"), _s("11 kHz"), _s("22 kHz"), _s("44 kHz"), _s("48 kHz"), 0 };
@ -1251,6 +1262,19 @@ GlobalOptionsDialog::GlobalOptionsDialog()
new ButtonWidget(tab, "GlobalOptions_Misc.UpdatesCheckManuallyButton", _("Check now"), 0, kUpdatesCheckCmd);
#endif
#ifdef USE_CLOUD
//
// 7) The cloud tab
//
if (g_system->getOverlayWidth() > 320)
tab->addTab(_("Cloud"));
else
tab->addTab(_c("Cloud", "lowres"));
new ButtonWidget(tab, "GlobalOptions_Cloud.StorageButton", _("Storage:"), 0, kChooseStorageCmd);
_curStorage = new StaticTextWidget(tab, "GlobalOptions_Cloud.CurStorage", CloudMan.getStorageName());
#endif
// Activate the first tab
tab->setActiveTab(0);
_tabWidget = tab;
@ -1481,7 +1505,8 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
}
break;
}
case kChooseThemeCmd: {
case kChooseThemeCmd:
{
ThemeBrowser browser;
if (browser.runModal() > 0) {
// User made his choice...
@ -1513,6 +1538,33 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
}
break;
}
#ifdef USE_CLOUD
case kChooseStorageCmd:
{
StorageBrowser storageBrowser;
if (storageBrowser.runModal() > 0) {
// User made his choice...
uint32 storageIndex = storageBrowser.getSelected();
// FIXME: Actually, any changes (including the storage change?) should
// only become active *after* the options dialog has closed.
if (CloudMan.switchStorage(storageIndex)) {
_curStorage->setLabel(CloudMan.getStorageName());
//automatically saves in the config if switched successfully
} else {
bool anotherStorageIsWorking = CloudMan.isWorking();
Common::String message = _("Failed to change cloud storage!");
if (anotherStorageIsWorking) {
message += "\n";
message += _("Current cloud storage is working at the moment.");
}
MessageDialog dialog(message);
dialog.runModal();
}
draw();
}
break;
}
#endif
#ifdef GUI_ENABLE_KEYSDIALOG
case kChooseKeyMappingCmd:
_keysDialog->runModal();

View file

@ -241,6 +241,13 @@ protected:
StaticTextWidget *_updatesPopUpDesc;
PopUpWidget *_updatesPopUp;
#endif
#ifdef USE_CLOUD
//
// Misc controls
//
StaticTextWidget *_curStorage;
#endif
};
} // End of namespace GUI

96
gui/storagebrowser.cpp Normal file
View file

@ -0,0 +1,96 @@
/* 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/storagebrowser.h"
#include "gui/widgets/list.h"
#include "gui/widget.h"
#include "gui/gui-manager.h"
#include "common/translation.h"
#ifdef USE_CLOUD
#include "backends/cloud/cloudmanager.h"
#endif
namespace GUI {
enum {
kChooseCmd = 'Chos'
};
StorageBrowser::StorageBrowser() : Dialog("Browser") {
new StaticTextWidget(this, "Browser.Headline", _("Select a Storage"));
// Add storages list
_storagesList = new ListWidget(this, "Browser.List");
_storagesList->setNumberingMode(kListNumberingOff);
_storagesList->setEditable(false);
_backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain;
// Buttons
new ButtonWidget(this, "Browser.Cancel", _("Cancel"), 0, kCloseCmd);
new ButtonWidget(this, "Browser.Choose", _("Choose"), 0, kChooseCmd);
}
void StorageBrowser::open() {
// Always refresh storages list
updateListing();
// Call super implementation
Dialog::open();
}
void StorageBrowser::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) {
case kChooseCmd:
case kListItemActivatedCmd:
case kListItemDoubleClickedCmd: {
int selection = _storagesList->getSelected();
if (selection < 0)
break;
_selectionIndex = selection;
setResult(1);
close();
break;
}
default:
Dialog::handleCommand(sender, cmd, data);
}
}
void StorageBrowser::updateListing() {
Common::StringArray list;
uint32 currentStorageIndex = 0;
#ifdef USE_CLOUD
list = CloudMan.listStorages();
currentStorageIndex = CloudMan.getStorageIndex();
#endif
_storagesList->setList(list);
_storagesList->scrollTo(0);
_storagesList->setSelected(currentStorageIndex);
// Finally, redraw
draw();
}
} // End of namespace GUI

51
gui/storagebrowser.h Normal file
View file

@ -0,0 +1,51 @@
/* 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.
*
*/
#ifndef GUI_STORAGEBROWSER_H
#define GUI_STORAGEBROWSER_H
#include "gui/dialog.h"
#include "common/str.h"
namespace GUI {
class CommandSender;
class ListWidget;
class StorageBrowser : public Dialog {
public:
StorageBrowser();
void open();
void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
uint32 getSelected() const { return _selectionIndex; }
private:
ListWidget *_storagesList;
uint32 _selectionIndex;
void updateListing();
};
} // End of namespace GUI
#endif

View file

@ -538,6 +538,19 @@
</layout>
</dialog>
<dialog name = 'GlobalOptions_Cloud' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '16, 16, 16, 16' spacing = '8'>
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'>
<widget name = 'StorageButton'
type = 'Button'
/>
<widget name = 'CurStorage'
height = 'Globals.Line.Height'
/>
</layout>
</layout>
</dialog>
<dialog name='KeysDialog' overlays='Dialog.GlobalOptions' shading='dim'>
<layout type='vertical' padding='8,8,8,8' center='true'>
<widget name='Action'

View file

@ -527,6 +527,19 @@
</layout>
</dialog>
<dialog name = 'GlobalOptions_Cloud' overlays = 'Dialog.GlobalOptions.TabWidget'>
<layout type = 'vertical' padding = '16, 16, 16, 16' spacing = '8'>
<layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'>
<widget name = 'StorageButton'
type = 'Button'
/>
<widget name = 'CurStorage'
height = 'Globals.Line.Height'
/>
</layout>
</layout>
</dialog>
<dialog name='KeysDialog' overlays='Dialog.GlobalOptions' shading='dim'>
<layout type='vertical' padding='8,8,8,8' center='true'>
<widget name='Action'