mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-26 12:48:16 +00:00
GUI: Add RemoteBrowserDialog
WIP. Tested with Dropbox.
This commit is contained in:
parent
97c0bbd238
commit
72b82bd2aa
@ -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);
|
||||
|
@ -32,8 +32,13 @@ class CommandSender;
|
||||
class EditTextWidget;
|
||||
class StaticTextWidget;
|
||||
class ButtonWidget;
|
||||
class BrowserDialog;
|
||||
class RemoteBrowserDialog;
|
||||
|
||||
class DownloadDialog : public Dialog {
|
||||
BrowserDialog *_browser;
|
||||
RemoteBrowserDialog *_remoteBrowser;
|
||||
|
||||
class DownloadDialog : public Dialog {
|
||||
StaticTextWidget *_messageText;
|
||||
ButtonWidget *_mainButton;
|
||||
ButtonWidget *_closeButton;
|
||||
@ -42,6 +47,7 @@ class DownloadDialog : public Dialog {
|
||||
bool _close;
|
||||
|
||||
void updateButtons();
|
||||
void selectDirectories();
|
||||
|
||||
public:
|
||||
DownloadDialog(uint32 storageId);
|
||||
|
@ -17,6 +17,7 @@ MODULE_OBJS := \
|
||||
object.o \
|
||||
options.o \
|
||||
predictivedialog.o \
|
||||
remotebrowser.o \
|
||||
saveload.o \
|
||||
saveload-dialog.o \
|
||||
storagewizarddialog.o \
|
||||
|
220
gui/remotebrowser.cpp
Normal file
220
gui/remotebrowser.cpp
Normal file
@ -0,0 +1,220 @@
|
||||
/* 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/remotebrowser.h"
|
||||
#include "gui/widgets/list.h"
|
||||
|
||||
#include "common/config-manager.h"
|
||||
#include "common/system.h"
|
||||
#include "common/algorithm.h"
|
||||
|
||||
#include "common/translation.h"
|
||||
#include <backends/networking/curl/request.h>
|
||||
#include <backends/cloud/storage.h>
|
||||
#include <backends/cloud/cloudmanager.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
enum {
|
||||
kChooseCmd = 'Chos',
|
||||
kGoUpCmd = 'GoUp',
|
||||
kHiddenCmd = 'Hidd'
|
||||
};
|
||||
|
||||
/* We want to use this as a general directory selector at some point... possible uses
|
||||
* - to select the data dir for a game
|
||||
* - to select the place where save games are stored
|
||||
* - others???
|
||||
*/
|
||||
|
||||
RemoteBrowserDialog::RemoteBrowserDialog(const char *title, bool dirRemoteBrowser)
|
||||
: Dialog("Browser"), _navigationLocked(false), _updateList(false) {
|
||||
|
||||
_isDirRemoteBrowser = dirRemoteBrowser;
|
||||
_fileList = NULL;
|
||||
_currentPath = NULL;
|
||||
|
||||
// Headline - TODO: should be customizable during creation time
|
||||
new StaticTextWidget(this, "Browser.Headline", title);
|
||||
|
||||
// Current path - TODO: handle long paths ?
|
||||
_currentPath = new StaticTextWidget(this, "Browser.Path", "DUMMY");
|
||||
|
||||
// Add file list
|
||||
_fileList = new ListWidget(this, "Browser.List");
|
||||
_fileList->setNumberingMode(kListNumberingOff);
|
||||
_fileList->setEditable(false);
|
||||
|
||||
_backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain;
|
||||
|
||||
// hide checkbox for the "show hidden files" state.
|
||||
//_showHiddenWidget = new CheckboxWidget(this, "Browser.Hidden", _("Show hidden files"), _("Show files marked with the hidden attribute"), kHiddenCmd);
|
||||
|
||||
// Buttons
|
||||
if (g_system->getOverlayWidth() > 320)
|
||||
new ButtonWidget(this, "Browser.Up", _("Go up"), _("Go to previous directory level"), kGoUpCmd);
|
||||
else
|
||||
new ButtonWidget(this, "Browser.Up", _c("Go up", "lowres"), _("Go to previous directory level"), kGoUpCmd);
|
||||
new ButtonWidget(this, "Browser.Cancel", _("Cancel"), 0, kCloseCmd);
|
||||
new ButtonWidget(this, "Browser.Choose", _("Choose"), 0, kChooseCmd);
|
||||
}
|
||||
|
||||
void RemoteBrowserDialog::open() {
|
||||
Dialog::open();
|
||||
listDirectory(Cloud::StorageFile());
|
||||
}
|
||||
|
||||
void RemoteBrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
||||
switch (cmd) {
|
||||
case kChooseCmd:
|
||||
if (_isDirRemoteBrowser) {
|
||||
// If nothing is selected in the list widget, choose the current dir.
|
||||
// Else, choose the dir that is selected.
|
||||
int selection = _fileList->getSelected();
|
||||
if (selection >= 0)
|
||||
_choice = _nodeContent[selection];
|
||||
else
|
||||
_choice = _node;
|
||||
setResult(1);
|
||||
close();
|
||||
} else {
|
||||
int selection = _fileList->getSelected();
|
||||
if (selection < 0)
|
||||
break;
|
||||
if (_nodeContent[selection].isDirectory()) {
|
||||
_node = _nodeContent[selection];
|
||||
updateListing();
|
||||
} else {
|
||||
_choice = _nodeContent[selection];
|
||||
setResult(1);
|
||||
close();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case kGoUpCmd:
|
||||
goUp();
|
||||
break;
|
||||
case kListItemActivatedCmd:
|
||||
case kListItemDoubleClickedCmd:
|
||||
if (_nodeContent[data].isDirectory()) {
|
||||
_node = _nodeContent[data];
|
||||
listDirectory(_node);
|
||||
} else if (!_isDirRemoteBrowser) { //TODO: ????
|
||||
_choice = _nodeContent[data];
|
||||
setResult(1);
|
||||
close();
|
||||
}
|
||||
break;
|
||||
case kListSelectionChangedCmd:
|
||||
// We do not allow selecting directories in directory
|
||||
// RemoteBrowser mode, thus we will invalidate the selection
|
||||
// when the user selects an directory over here.
|
||||
if (data != (uint32)-1 && _isDirRemoteBrowser && !_nodeContent[data].isDirectory())
|
||||
_fileList->setSelected(-1);
|
||||
break;
|
||||
default:
|
||||
Dialog::handleCommand(sender, cmd, data);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteBrowserDialog::handleTickle() {
|
||||
if (_updateList) {
|
||||
updateListing();
|
||||
_updateList = false;
|
||||
}
|
||||
|
||||
Dialog::handleTickle();
|
||||
}
|
||||
|
||||
void RemoteBrowserDialog::updateListing() {
|
||||
// Update the path display
|
||||
Common::String path = _node.path();
|
||||
if (path.empty()) path = "/"; //root
|
||||
_currentPath->setLabel(path);
|
||||
|
||||
if (!_navigationLocked) {
|
||||
// Populate the ListWidget
|
||||
ListWidget::StringArray list;
|
||||
ListWidget::ColorList colors;
|
||||
for (Common::Array<Cloud::StorageFile>::iterator i = _nodeContent.begin(); i != _nodeContent.end(); ++i) {
|
||||
if (i->isDirectory()) {
|
||||
list.push_back(i->name() + "/");
|
||||
colors.push_back(ThemeEngine::kFontColorNormal);
|
||||
} else {
|
||||
list.push_back(i->name());
|
||||
colors.push_back(ThemeEngine::kFontColorAlternate);
|
||||
}
|
||||
}
|
||||
|
||||
_fileList->setList(list, &colors);
|
||||
_fileList->scrollTo(0);
|
||||
}
|
||||
|
||||
_fileList->setEnabled(!_navigationLocked);
|
||||
|
||||
// Finally, redraw
|
||||
draw();
|
||||
}
|
||||
|
||||
void RemoteBrowserDialog::goUp() {
|
||||
Common::String path = _node.path();
|
||||
if (path.size() && (path.lastChar() == '/' || path.lastChar() == '\\')) path.deleteLastChar();
|
||||
if (path.empty()) {
|
||||
draw();
|
||||
return;
|
||||
}
|
||||
for (int i = path.size()-1; i >= 0; --i)
|
||||
if (path[i] == '/' || path[i] == '\\') {
|
||||
path.erase(i);
|
||||
break;
|
||||
}
|
||||
listDirectory(Cloud::StorageFile(path, 0, 0, true));
|
||||
}
|
||||
|
||||
void RemoteBrowserDialog::listDirectory(Cloud::StorageFile node) {
|
||||
if (_navigationLocked) return;
|
||||
_navigationLocked = true;
|
||||
|
||||
_workingRequest = CloudMan.listDirectory(
|
||||
node.path(),
|
||||
new Common::Callback<RemoteBrowserDialog, Cloud::Storage::ListDirectoryResponse>(this, &RemoteBrowserDialog::directoryListedCallback),
|
||||
new Common::Callback<RemoteBrowserDialog, Networking::ErrorResponse>(this, &RemoteBrowserDialog::directoryListedErrorCallback),
|
||||
false
|
||||
);
|
||||
|
||||
_node = node;
|
||||
updateListing();
|
||||
}
|
||||
|
||||
void RemoteBrowserDialog::directoryListedCallback(Cloud::Storage::ListDirectoryResponse response) {
|
||||
_navigationLocked = false;
|
||||
//TODO: list files from response
|
||||
_nodeContent = response.value;
|
||||
_updateList = true;
|
||||
}
|
||||
|
||||
void RemoteBrowserDialog::directoryListedErrorCallback(Networking::ErrorResponse error) {
|
||||
_navigationLocked = false;
|
||||
//TODO: show error message
|
||||
}
|
||||
|
||||
} // End of namespace GUI
|
71
gui/remotebrowser.h
Normal file
71
gui/remotebrowser.h
Normal file
@ -0,0 +1,71 @@
|
||||
/* 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_REMOTEBROWSER_DIALOG_H
|
||||
#define GUI_REMOTEBROWSER_DIALOG_H
|
||||
|
||||
#include "gui/dialog.h"
|
||||
#include "common/fs.h"
|
||||
#include <backends/cloud/storagefile.h>
|
||||
#include <backends/networking/curl/request.h>
|
||||
#include <backends/cloud/storage.h>
|
||||
|
||||
namespace GUI {
|
||||
|
||||
class ListWidget;
|
||||
class StaticTextWidget;
|
||||
class CheckboxWidget;
|
||||
class CommandSender;
|
||||
|
||||
class RemoteBrowserDialog : public Dialog {
|
||||
public:
|
||||
RemoteBrowserDialog(const char *title, bool dirRemoteBrowser);
|
||||
|
||||
virtual void open();
|
||||
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
|
||||
virtual void handleTickle();
|
||||
|
||||
const Cloud::StorageFile &getResult() { return _choice; }
|
||||
|
||||
protected:
|
||||
ListWidget *_fileList;
|
||||
StaticTextWidget *_currentPath;
|
||||
Cloud::StorageFile _node;
|
||||
Common::Array<Cloud::StorageFile> _nodeContent;
|
||||
Cloud::StorageFile _choice;
|
||||
bool _isDirRemoteBrowser;
|
||||
bool _navigationLocked;
|
||||
bool _updateList;
|
||||
|
||||
Networking::Request *_workingRequest;
|
||||
bool _ignoreCallback; //?
|
||||
|
||||
void updateListing();
|
||||
void goUp();
|
||||
void listDirectory(Cloud::StorageFile node);
|
||||
void directoryListedCallback(Cloud::Storage::ListDirectoryResponse response);
|
||||
void directoryListedErrorCallback(Networking::ErrorResponse error);
|
||||
};
|
||||
|
||||
} // End of namespace GUI
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user