diff options
author | Alexander Tkachev | 2016-07-12 14:00:11 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | d795c77ef53720fa423d9b827a66d1bea8b8e761 (patch) | |
tree | 2fac5ef89c3a83298dc151c247198df3f73617b9 /gui | |
parent | 5c60cd14c2cf27e4b0c03183cef1b1b2e596782a (diff) | |
download | scummvm-rg350-d795c77ef53720fa423d9b827a66d1bea8b8e761.tar.gz scummvm-rg350-d795c77ef53720fa423d9b827a66d1bea8b8e761.tar.bz2 scummvm-rg350-d795c77ef53720fa423d9b827a66d1bea8b8e761.zip |
GUI: Fix DownloadDialog detection
Now it calls Launcher directly, so it updates games list on success.
Diffstat (limited to 'gui')
-rw-r--r-- | gui/downloaddialog.cpp | 77 | ||||
-rw-r--r-- | gui/downloaddialog.h | 5 | ||||
-rw-r--r-- | gui/launcher.cpp | 139 | ||||
-rw-r--r-- | gui/launcher.h | 2 | ||||
-rw-r--r-- | gui/options.cpp | 6 | ||||
-rw-r--r-- | gui/options.h | 4 |
6 files changed, 93 insertions, 140 deletions
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(); diff --git a/gui/downloaddialog.h b/gui/downloaddialog.h index 39c4cea2e4..4b277c8334 100644 --- a/gui/downloaddialog.h +++ b/gui/downloaddialog.h @@ -28,6 +28,7 @@ #include <backends/cloud/storage.h> namespace GUI { +class LauncherDialog; class CommandSender; class EditTextWidget; @@ -43,6 +44,7 @@ enum DownloadProgress { }; class DownloadDialog : public Dialog { + LauncherDialog *_launcher; BrowserDialog *_browser; RemoteBrowserDialog *_remoteBrowser; @@ -58,10 +60,9 @@ class DownloadDialog : public Dialog { void refreshWidgets(); bool selectDirectories(); - void addGame(); public: - DownloadDialog(uint32 storageId); + DownloadDialog(uint32 storageId, LauncherDialog *launcher); virtual ~DownloadDialog(); virtual void open(); diff --git a/gui/launcher.cpp b/gui/launcher.cpp index f2474a5947..d1a226fe57 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -328,9 +328,8 @@ void LauncherDialog::addGame() { if (_browser->runModal() > 0) { // User made his choice... - Common::FSNode dir(_browser->getResult()); #ifdef USE_LIBCURL - String selectedDirectory = dir.getPath(); + String selectedDirectory = _browser->getResult().getPath(); String bannedDirectory = CloudMan.getDownloadLocalDirectory(); if (selectedDirectory.size() && selectedDirectory.lastChar() != '/' && selectedDirectory.lastChar() != '\\') selectedDirectory += '/'; @@ -343,64 +342,7 @@ void LauncherDialog::addGame() { return; } #endif - 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(); - idx = -1; - - looping = true; - } else if (candidates.size() == 1) { - // Exact match - idx = 0; - } else { - // Display the candidates to the user and let her/him pick one - 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(); - - // Update the ListWidget, select the new item, and force a redraw - updateListing(); - selectTarget(editDialog.getDomain()); - draw(); - } else { - // User aborted, remove the the new domain again - ConfMan.removeGameDomain(domain); - } - - } + looping = !doGameDetection(_browser->getResult().getPath()); } } while (looping); } @@ -579,6 +521,81 @@ void LauncherDialog::handleKeyUp(Common::KeyState state) { updateButtons(); } +bool LauncherDialog::doGameDetection(const Common::String &path) { + // 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(path); + Common::FSList files; + if (!dir.getChildren(files, Common::FSNode::kListAll)) { + MessageDialog alert(_("ScummVM couldn't open the specified directory!")); + alert.runModal(); + return true; + } + + // ...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(); + idx = -1; + return false; + } else if (candidates.size() == 1) { + // Exact match + idx = 0; + } else { + // Display the candidates to the user and let her/him pick one + 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(); + + // Update the ListWidget, select the new item, and force a redraw + updateListing(); + selectTarget(editDialog.getDomain()); + draw(); + } else { + // User aborted, remove the the new domain again + ConfMan.removeGameDomain(domain); + } + + } + + return true; +} + void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { int item = _list->getSelected(); @@ -596,7 +613,7 @@ void LauncherDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat loadGameButtonPressed(item); break; case kOptionsCmd: { - GlobalOptionsDialog options; + GlobalOptionsDialog options(this); options.runModal(); } break; diff --git a/gui/launcher.h b/gui/launcher.h index e9c76a5320..58f1c930ed 100644 --- a/gui/launcher.h +++ b/gui/launcher.h @@ -51,7 +51,7 @@ public: virtual void handleKeyDown(Common::KeyState state); virtual void handleKeyUp(Common::KeyState state); - + bool doGameDetection(const Common::String &path); protected: EditTextWidget *_searchWidget; ListWidget *_list; diff --git a/gui/options.cpp b/gui/options.cpp index 42d6a66053..b5f7293e5d 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -1099,8 +1099,8 @@ void OptionsDialog::reflowLayout() { #pragma mark - -GlobalOptionsDialog::GlobalOptionsDialog() - : OptionsDialog(Common::ConfigManager::kApplicationDomain, "GlobalOptions") { +GlobalOptionsDialog::GlobalOptionsDialog(LauncherDialog *launcher) + : OptionsDialog(Common::ConfigManager::kApplicationDomain, "GlobalOptions"), _launcher(launcher) { // The tab widget TabWidget *tab = new TabWidget(this, "GlobalOptions.TabWidget"); @@ -1632,7 +1632,7 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 } case kDownloadStorageCmd: { - DownloadDialog dialog(_selectedStorageIndex); + DownloadDialog dialog(_selectedStorageIndex, _launcher); dialog.runModal(); break; } diff --git a/gui/options.h b/gui/options.h index 1d7f9ffd49..e68778cf8e 100644 --- a/gui/options.h +++ b/gui/options.h @@ -42,6 +42,7 @@ #endif namespace GUI { +class LauncherDialog; class CheckboxWidget; class PopUpWidget; @@ -204,7 +205,7 @@ protected: class GlobalOptionsDialog : public OptionsDialog { public: - GlobalOptionsDialog(); + GlobalOptionsDialog(LauncherDialog *launcher); ~GlobalOptionsDialog(); void open(); @@ -215,6 +216,7 @@ public: virtual void reflowLayout(); protected: + LauncherDialog *_launcher; #ifdef GUI_ENABLE_KEYSDIALOG KeysDialog *_keysDialog; #endif |