2018-04-15 16:10:09 +00:00
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-05-28 19:55:00 +00:00
|
|
|
#include "gui/unknown-game-dialog.h"
|
2017-12-02 16:14:22 +00:00
|
|
|
|
2018-04-15 16:10:09 +00:00
|
|
|
#include "common/translation.h"
|
|
|
|
#include "common/str-array.h"
|
2018-04-29 22:37:46 +00:00
|
|
|
#include "common/system.h"
|
2017-12-02 16:14:22 +00:00
|
|
|
|
2018-04-15 16:10:09 +00:00
|
|
|
#include "gui/gui-manager.h"
|
|
|
|
#include "gui/message.h"
|
|
|
|
#include "gui/ThemeEval.h"
|
|
|
|
#include "gui/widgets/popup.h"
|
2018-05-28 21:03:20 +00:00
|
|
|
#include "gui/widgets/scrollcontainer.h"
|
2018-04-15 16:10:09 +00:00
|
|
|
|
2018-05-28 19:55:00 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2018-04-15 16:10:09 +00:00
|
|
|
enum {
|
|
|
|
kCopyToClipboard = 'cpcl',
|
|
|
|
kOpenBugtrackerURL = 'ourl',
|
2018-05-28 21:03:20 +00:00
|
|
|
kClose = 'clse',
|
2019-12-28 09:43:58 +00:00
|
|
|
kAddAnyway = 'adda'
|
2018-04-15 16:10:09 +00:00
|
|
|
};
|
|
|
|
|
2019-05-03 18:48:06 +00:00
|
|
|
UnknownGameDialog::UnknownGameDialog(const DetectedGame &detectedGame) :
|
2019-12-28 09:43:58 +00:00
|
|
|
Dialog("UnknownGameDialog"),
|
2019-05-03 18:48:06 +00:00
|
|
|
_detectedGame(detectedGame) {
|
|
|
|
|
|
|
|
if (detectedGame.canBeAdded) {
|
2020-11-15 18:15:58 +00:00
|
|
|
_addAnywayButton = new ButtonWidget(this, "UnknownGameDialog.Add", _("Add anyway"), Common::U32String(), kAddAnyway);
|
2019-05-03 18:48:06 +00:00
|
|
|
} else {
|
|
|
|
_addAnywayButton = nullptr;
|
|
|
|
}
|
2018-05-28 21:18:39 +00:00
|
|
|
|
2020-11-15 18:15:58 +00:00
|
|
|
_closeButton = new ButtonWidget(this, "UnknownGameDialog.Close", detectedGame.canBeAdded ? _("Cancel") : _("Close"), Common::U32String(), kClose);
|
2019-12-28 09:43:58 +00:00
|
|
|
|
2018-05-28 21:18:39 +00:00
|
|
|
//Check if we have clipboard functionality
|
|
|
|
if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
|
2020-11-15 18:15:58 +00:00
|
|
|
_copyToClipboardButton = new ButtonWidget(this, "UnknownGameDialog.Copy", _("Copy to clipboard"), Common::U32String(), kCopyToClipboard);
|
2018-05-28 21:18:39 +00:00
|
|
|
} else
|
|
|
|
_copyToClipboardButton = nullptr;
|
|
|
|
|
|
|
|
//Check if we have support for opening URLs
|
|
|
|
if (g_system->hasFeature(OSystem::kFeatureOpenUrl)) {
|
2020-11-15 18:15:58 +00:00
|
|
|
_openBugTrackerUrlButton = new ButtonWidget(this, "UnknownGameDialog.Report", _("Report game"), Common::U32String(), kOpenBugtrackerURL);
|
2018-05-28 21:18:39 +00:00
|
|
|
} else
|
|
|
|
_openBugTrackerUrlButton = nullptr;
|
|
|
|
|
|
|
|
// Use a ScrollContainer for the report in case we have a lot of lines.
|
2019-12-28 09:43:58 +00:00
|
|
|
_textContainer = new ScrollContainerWidget(this, "UnknownGameDialog.TextContainer", "");
|
2018-05-28 21:18:39 +00:00
|
|
|
_textContainer->setTarget(this);
|
|
|
|
|
|
|
|
rebuild();
|
|
|
|
}
|
|
|
|
|
2018-10-11 04:52:02 +00:00
|
|
|
void UnknownGameDialog::handleMouseWheel(int x, int y, int direction) {
|
|
|
|
_textContainer->handleMouseWheel(x, y, direction);
|
|
|
|
}
|
|
|
|
|
2018-05-28 21:18:39 +00:00
|
|
|
void UnknownGameDialog::reflowLayout() {
|
|
|
|
Dialog::reflowLayout();
|
2019-12-28 09:43:58 +00:00
|
|
|
rebuild();
|
2018-05-28 21:18:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UnknownGameDialog::rebuild() {
|
|
|
|
// First remove the old text widgets
|
|
|
|
for (uint i = 0; i < _textWidgets.size() ; i++) {
|
|
|
|
_textContainer->removeWidget(_textWidgets[i]);
|
2019-12-28 09:43:58 +00:00
|
|
|
|
|
|
|
// Also remove the widget from the dialog for the case it was
|
|
|
|
// the active widget.
|
|
|
|
removeWidget(_textWidgets[i]);
|
2018-05-28 21:18:39 +00:00
|
|
|
delete _textWidgets[i];
|
|
|
|
}
|
|
|
|
_textWidgets.clear();
|
|
|
|
|
2020-06-13 16:42:25 +00:00
|
|
|
Common::U32String reportTranslated = generateUnknownGameReport(_detectedGame, true, true);
|
2018-04-15 16:10:09 +00:00
|
|
|
|
2017-12-02 16:14:22 +00:00
|
|
|
// Check if we have clipboard functionality and expand the reportTranslated message if needed...
|
2018-04-15 16:10:09 +00:00
|
|
|
if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
|
2020-06-13 16:42:25 +00:00
|
|
|
reportTranslated += Common::U32String("\n");
|
2017-12-02 16:14:22 +00:00
|
|
|
reportTranslated += _("Use the button below to copy the required game information into your clipboard.");
|
2018-04-15 16:10:09 +00:00
|
|
|
}
|
2017-12-02 16:14:22 +00:00
|
|
|
// Check if we have support for opening URLs and expand the reportTranslated message if needed...
|
2018-04-15 16:10:09 +00:00
|
|
|
if (g_system->hasFeature(OSystem::kFeatureOpenUrl)) {
|
2020-06-13 16:42:25 +00:00
|
|
|
reportTranslated += Common::U32String("\n");
|
2017-12-02 16:14:22 +00:00
|
|
|
reportTranslated += _("You can also directly report your game to the Bug Tracker.");
|
2018-04-15 16:10:09 +00:00
|
|
|
}
|
|
|
|
|
2019-12-28 09:43:58 +00:00
|
|
|
// We use a ScrollContainer to display the text, with a 2 * 10 margin for the text in the container.
|
2020-06-13 16:42:25 +00:00
|
|
|
Common::Array<Common::U32String> lines;
|
2019-12-28 09:43:58 +00:00
|
|
|
g_gui.getFont().wordWrapText(reportTranslated, _textContainer->getWidth() - 20, lines);
|
2018-04-15 16:10:09 +00:00
|
|
|
|
2019-12-28 09:43:58 +00:00
|
|
|
// Create text widgets
|
2018-05-28 21:03:20 +00:00
|
|
|
uint y = 8;
|
|
|
|
for (uint i = 0; i < lines.size() ; i++) {
|
2019-12-28 09:43:58 +00:00
|
|
|
StaticTextWidget *widget = new StaticTextWidget(_textContainer, 10, y, _textContainer->getWidth() - 20, kLineHeight, lines[i], Graphics::kTextAlignLeft);
|
2018-05-28 21:03:20 +00:00
|
|
|
_textWidgets.push_back(widget);
|
2018-04-15 16:10:09 +00:00
|
|
|
y += kLineHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-29 17:47:34 +00:00
|
|
|
Common::String UnknownGameDialog::encodeUrlString(const Common::String &string) {
|
|
|
|
Common::String encoded;
|
2019-04-28 22:29:22 +00:00
|
|
|
for (uint i = 0 ; i < string.size() ; ++i) {
|
2020-08-29 17:47:34 +00:00
|
|
|
char c = string[i];
|
2019-04-28 22:29:22 +00:00
|
|
|
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') ||
|
|
|
|
c == '~' || c == '-' || c == '.' || c == '_')
|
|
|
|
encoded += c;
|
|
|
|
else
|
|
|
|
encoded += Common::String::format("%%%02X", c);
|
2019-04-27 01:42:16 +00:00
|
|
|
}
|
2019-04-28 22:29:22 +00:00
|
|
|
return encoded;
|
2019-04-27 01:42:16 +00:00
|
|
|
}
|
2018-04-30 13:01:44 +00:00
|
|
|
|
2020-08-29 17:47:34 +00:00
|
|
|
Common::String UnknownGameDialog::generateBugtrackerURL() {
|
|
|
|
Common::String report = generateUnknownGameReport(_detectedGame, false, false);
|
2019-04-28 22:29:22 +00:00
|
|
|
report = encodeUrlString(report);
|
2019-04-27 01:42:16 +00:00
|
|
|
|
2016-09-15 16:39:45 +00:00
|
|
|
Common::String engineId = encodeUrlString(_detectedGame.engineId);
|
2017-12-02 16:14:22 +00:00
|
|
|
|
2020-08-29 17:47:34 +00:00
|
|
|
return Common::String::format(
|
2019-04-28 22:29:22 +00:00
|
|
|
"https://www.scummvm.org/unknowngame?"
|
2020-08-29 17:47:34 +00:00
|
|
|
"engine=%s"
|
|
|
|
"&description=%s",
|
|
|
|
engineId.c_str(),
|
|
|
|
report.c_str());
|
2018-04-15 16:10:09 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 19:55:00 +00:00
|
|
|
void UnknownGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
2018-04-15 16:10:09 +00:00
|
|
|
switch(cmd) {
|
2017-12-02 16:14:22 +00:00
|
|
|
case kCopyToClipboard: {
|
2020-07-21 23:23:38 +00:00
|
|
|
Common::U32String report = generateUnknownGameReport(_detectedGame, false, false);
|
2017-12-02 16:14:22 +00:00
|
|
|
|
|
|
|
if (g_system->setTextInClipboard(report)) {
|
|
|
|
g_system->displayMessageOnOSD(
|
|
|
|
_("All necessary information about your game has been copied into the clipboard"));
|
2018-04-15 16:10:09 +00:00
|
|
|
} else {
|
|
|
|
g_system->displayMessageOnOSD(_("Copying the game information to the clipboard has failed!"));
|
|
|
|
}
|
|
|
|
break;
|
2017-12-02 16:14:22 +00:00
|
|
|
}
|
2018-04-15 16:10:09 +00:00
|
|
|
case kClose:
|
2019-05-03 18:48:06 +00:00
|
|
|
// The user cancelled adding the game
|
|
|
|
setResult(-1);
|
|
|
|
close();
|
|
|
|
break;
|
|
|
|
case kAddAnyway:
|
2017-12-02 16:14:22 +00:00
|
|
|
// When the detection entry comes from the fallback detector, the game can be added / launched anyways.
|
2018-04-15 16:10:09 +00:00
|
|
|
close();
|
|
|
|
break;
|
|
|
|
case kOpenBugtrackerURL:
|
|
|
|
g_system->openUrl(generateBugtrackerURL());
|
|
|
|
break;
|
2019-10-03 05:03:46 +00:00
|
|
|
default:
|
|
|
|
break;
|
2018-04-15 16:10:09 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-28 19:55:00 +00:00
|
|
|
|
|
|
|
} // End of namespace GUI
|