ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

unknown-game-dialog.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "gui/unknown-game-dialog.h"
00024 
00025 #include "common/translation.h"
00026 #include "common/str-array.h"
00027 #include "common/system.h"
00028 
00029 #include "gui/gui-manager.h"
00030 #include "gui/message.h"
00031 #include "gui/ThemeEval.h"
00032 #include "gui/widgets/popup.h"
00033 #include "gui/widgets/scrollcontainer.h"
00034 
00035 namespace GUI {
00036 
00037 enum {
00038     kCopyToClipboard = 'cpcl',
00039     kOpenBugtrackerURL = 'ourl',
00040     kClose = 'clse',
00041     kAddAnyway = 'adda'
00042 };
00043 
00044 UnknownGameDialog::UnknownGameDialog(const DetectedGame &detectedGame) :
00045         Dialog("UnknownGameDialog"),
00046         _detectedGame(detectedGame) {
00047 
00048     if (detectedGame.canBeAdded) {
00049         _addAnywayButton = new ButtonWidget(this, "UnknownGameDialog.Add", _("Add anyway"), nullptr, kAddAnyway);
00050     } else {
00051         _addAnywayButton = nullptr;
00052     }
00053 
00054     _closeButton = new ButtonWidget(this, "UnknownGameDialog.Close", detectedGame.canBeAdded ? _("Cancel") : _("Close"), nullptr, kClose);
00055 
00056     //Check if we have clipboard functionality
00057     if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
00058         _copyToClipboardButton = new ButtonWidget(this, "UnknownGameDialog.Copy", _("Copy to clipboard"), nullptr, kCopyToClipboard);
00059     } else
00060         _copyToClipboardButton = nullptr;
00061 
00062 #if 0 // ResidualVM specific
00063     //Check if we have support for opening URLs
00064     if (g_system->hasFeature(OSystem::kFeatureOpenUrl)) {
00065         _openBugTrackerUrlButton = new ButtonWidget(this, "UnknownGameDialog.Report", _("Report game"), nullptr, kOpenBugtrackerURL);
00066     } else
00067 #endif
00068         _openBugTrackerUrlButton = nullptr;
00069 
00070     // Use a ScrollContainer for the report in case we have a lot of lines.
00071     _textContainer = new ScrollContainerWidget(this, "UnknownGameDialog.TextContainer", "");
00072     _textContainer->setTarget(this);
00073 
00074     rebuild();
00075 }
00076 
00077 void UnknownGameDialog::handleMouseWheel(int x, int y, int direction) {
00078     _textContainer->handleMouseWheel(x, y, direction);
00079 }
00080 
00081 void UnknownGameDialog::reflowLayout() {
00082     Dialog::reflowLayout();
00083     rebuild();
00084 }
00085 
00086 void UnknownGameDialog::rebuild() {
00087     // First remove the old text widgets
00088     for (uint i = 0; i < _textWidgets.size() ; i++) {
00089         _textContainer->removeWidget(_textWidgets[i]);
00090 
00091         // Also remove the widget from the dialog for the case it was
00092         // the active widget.
00093         removeWidget(_textWidgets[i]);
00094         delete _textWidgets[i];
00095     }
00096     _textWidgets.clear();
00097 
00098     Common::String reportTranslated = generateUnknownGameReport(_detectedGame, true, true);
00099 
00100     // Check if we have clipboard functionality and expand the reportTranslated message if needed...
00101     if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
00102         reportTranslated += "\n";
00103         reportTranslated += _("Use the button below to copy the required game information into your clipboard.");
00104     }
00105 #if 0 // ResidualVM specific
00106     // Check if we have support for opening URLs and expand the reportTranslated message if needed...
00107     if (g_system->hasFeature(OSystem::kFeatureOpenUrl)) {
00108         reportTranslated += "\n";
00109         reportTranslated += _("You can also directly report your game to the Bug Tracker.");
00110     }
00111 #endif
00112 
00113     // We use a ScrollContainer to display the text, with a 2 * 10 margin for the text in the container.
00114     Common::Array<Common::String> lines;
00115     g_gui.getFont().wordWrapText(reportTranslated, _textContainer->getWidth() - 20, lines);
00116 
00117     // Create text widgets
00118     uint y = 8;
00119     for (uint i = 0; i < lines.size() ; i++) {
00120         StaticTextWidget *widget = new StaticTextWidget(_textContainer, 10, y, _textContainer->getWidth() - 20, kLineHeight, lines[i], Graphics::kTextAlignLeft);
00121         _textWidgets.push_back(widget);
00122         y += kLineHeight;
00123     }
00124 }
00125 
00126 Common::String UnknownGameDialog::encodeUrlString(const Common::String &string) {
00127     Common::String encoded;
00128     for (uint i = 0 ; i < string.size() ; ++i) {
00129         char c = string[i];
00130         if ((c >= 'a' && c <= 'z') || (c >= 'A'  && c <= 'Z') || (c >= '0' && c <= '9') ||
00131             c == '~' || c == '-' || c == '.' || c == '_')
00132             encoded += c;
00133         else
00134             encoded += Common::String::format("%%%02X", c);
00135     }
00136     return encoded;
00137 }
00138 
00139 Common::String UnknownGameDialog::generateBugtrackerURL() {
00140     Common::String report = generateUnknownGameReport(_detectedGame, false, false);
00141     report = encodeUrlString(report);
00142 
00143     Common::String engineId = encodeUrlString(_detectedGame.engineId);
00144 
00145     return Common::String::format(
00146         "https://www.residualvm.org/unknowngame?"
00147         "engine=%s"
00148         "&description=%s",
00149         engineId.c_str(),
00150         report.c_str());
00151 }
00152 
00153 void UnknownGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
00154     switch(cmd) {
00155     case kCopyToClipboard: {
00156         Common::String report = generateUnknownGameReport(_detectedGame, false, false);
00157 
00158         if (g_system->setTextInClipboard(report)) {
00159             g_system->displayMessageOnOSD(
00160                     _("All necessary information about your game has been copied into the clipboard"));
00161         } else {
00162             g_system->displayMessageOnOSD(_("Copying the game information to the clipboard has failed!"));
00163         }
00164         break;
00165     }
00166     case kClose:
00167         // The user cancelled adding the game
00168         setResult(-1);
00169         close();
00170         break;
00171     case kAddAnyway:
00172         // When the detection entry comes from the fallback detector, the game can be added / launched anyways.
00173         close();
00174         break;
00175     case kOpenBugtrackerURL:
00176         g_system->openUrl(generateBugtrackerURL());
00177         break;
00178     default:
00179         break;
00180     }
00181 }
00182 
00183 } // End of namespace GUI


Generated on Sat May 23 2020 05:00:45 for ResidualVM by doxygen 1.7.1
curved edge   curved edge