ENGINES: Add unknown game variants to the game detector results

This commit is contained in:
Bastien Bouclet 2017-12-02 17:14:22 +01:00
parent 9587dd5c21
commit cf1ebf2951
31 changed files with 597 additions and 428 deletions

View file

@ -20,14 +20,16 @@
*
*/
#include "engines/unknown-game-dialog.h"
#include "common/translation.h"
#include "common/str-array.h"
#include "common/system.h"
#include "gui/gui-manager.h"
#include "gui/message.h"
#include "gui/ThemeEval.h"
#include "gui/widgets/popup.h"
#include "engines/unknown-game-dialog.h"
enum {
kCopyToClipboard = 'cpcl',
@ -35,36 +37,33 @@ enum {
kClose = 'clse'
};
UnknownGameDialog::UnknownGameDialog(const Common::String &reportData, const Common::String &reportTranslated, const Common::String &bugtrackerAffectedEngine)
: Dialog(30, 20, 260, 124) {
UnknownGameDialog::UnknownGameDialog(const DetectionResults &detectionResults) :
Dialog(30, 20, 260, 124),
_detectionResults(detectionResults) {
Common::String reportTranslated = _detectionResults.generateUnknownGameReport(true);
_reportData = reportData;
_reportTranslated = reportTranslated;
_bugtrackerAffectedEngine = bugtrackerAffectedEngine;
//Check if we have clipboard functionality and expand the reportTranslated message if needed...
// Check if we have clipboard functionality and expand the reportTranslated message if needed...
if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
_reportTranslated += "\n";
_reportTranslated += _("Use the button below to copy the required game information into your clipboard.");
reportTranslated += "\n";
reportTranslated += _("Use the button below to copy the required game information into your clipboard.");
}
#if 0
//Check if we have support for opening URLs and expand the reportTranslated message if needed...
// Check if we have support for opening URLs and expand the reportTranslated message if needed...
if (g_system->hasFeature(OSystem::kFeatureOpenUrl)) {
_reportTranslated += "\n";
_reportTranslated += _("You can also directly report your game to the Bug Tracker!");
reportTranslated += "\n";
reportTranslated += _("You can also directly report your game to the Bug Tracker.");
}
#endif
const int screenW = g_system->getOverlayWidth();
const int screenH = g_system->getOverlayHeight();
int buttonWidth = g_gui.xmlEval()->getVar("Globals.Button.Width", 0);
int buttonHeight = g_gui.xmlEval()->getVar("Globals.Button.Height", 0);
//Calculate the size the dialog needs
// Calculate the size the dialog needs
Common::Array<Common::String> lines;
int maxlineWidth = g_gui.getFont().wordWrapText(_reportTranslated, screenW - 2 * 20, lines);
int maxlineWidth = g_gui.getFont().wordWrapText(reportTranslated, screenW - 2 * 20, lines);
int lineCount = lines.size() + 1;
_h = 3 * kLineHeight + lineCount * kLineHeight;
@ -84,7 +83,7 @@ UnknownGameDialog::UnknownGameDialog(const Common::String &reportData, const Com
int buttonPos = _w - closeButtonWidth - 10;
new GUI::ButtonWidget(this, buttonPos, _h - buttonHeight - 8, buttonWidth, buttonHeight, _("Close"), 0, kClose);
//Check if we have clipboard functionality
// Check if we have clipboard functionality
if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
buttonPos -= copyToClipboardButtonWidth + 5;
new GUI::ButtonWidget(this, buttonPos, _h - buttonHeight - 8, copyToClipboardButtonWidth, buttonHeight, _("Copy to clipboard"), 0, kCopyToClipboard);
@ -98,15 +97,10 @@ UnknownGameDialog::UnknownGameDialog(const Common::String &reportData, const Com
// https://www.scummvm.org/unknowngame?engine=Foo&description=Bar) that would
// redirect to whatever our bugtracker system is.
//Check if we have support for opening URLs
// Check if we have support for opening URLs
if (g_system->hasFeature(OSystem::kFeatureOpenUrl)) {
buttonPos -= openBugtrackerURLButtonWidth + 5;
new GUI::ButtonWidget(this, buttonPos, _h - buttonHeight - 8, openBugtrackerURLButtonWidth, buttonHeight, _("Report game"), 0, kOpenBugtrackerURL);
//Formatting the reportData for bugtracker submission [replace line breaks]...
_bugtrackerGameData = _reportData;
while (_bugtrackerGameData.contains("\n")) {
Common::replace(_bugtrackerGameData, "\n", "%0A");
}
}
#endif
@ -126,27 +120,39 @@ void UnknownGameDialog::reflowLayout() {
}
Common::String UnknownGameDialog::generateBugtrackerURL() {
return Common::String::format((
// TODO: Remove the filesystem path from the bugtracker report
Common::String report = _detectionResults.generateUnknownGameReport(false);
// Formatting the report for bugtracker submission [replace line breaks]...
while (report.contains("\n")) {
Common::replace(report, "\n", "%0A");
}
return Common::String::format(
"https://bugs.scummvm.org/newticket?"
"summary=[UNK] Unknown game for engine %s:"
"&description=%s"
"&component=Engine%%3A%s"
"&type=enhancement"
"&keywords=unknown-game,%s"),
_bugtrackerAffectedEngine.c_str(), _bugtrackerGameData.c_str(), _bugtrackerAffectedEngine.c_str(), _bugtrackerAffectedEngine.c_str());
"&keywords=unknown-game",
report.c_str());
}
void UnknownGameDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
switch(cmd) {
case kCopyToClipboard:
g_system->setTextInClipboard(_reportData);
if (g_system->setTextInClipboard(_reportData)) {
g_system->displayMessageOnOSD(_("All necessary information about your game has been copied into the clipboard"));
case kCopyToClipboard: {
// TODO: Remove the filesystem path from the report
Common::String report = _detectionResults.generateUnknownGameReport(false);
if (g_system->setTextInClipboard(report)) {
g_system->displayMessageOnOSD(
_("All necessary information about your game has been copied into the clipboard"));
} else {
g_system->displayMessageOnOSD(_("Copying the game information to the clipboard has failed!"));
}
break;
}
case kClose:
// When the detection entry comes from the fallback detector, the game can be added / launched anyways.
// TODO: Add a button to cancel adding the game. And make it clear that launching the game may not work properly.
close();
break;
case kOpenBugtrackerURL: