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     kScrollContainerReflow = 'SCRf'
00042 };
00043 
00044 UnknownGameDialog::UnknownGameDialog(const DetectionResults &detectionResults) :
00045         Dialog(30, 20, 260, 124),
00046         _detectionResults(detectionResults) {
00047     // For now place the buttons with a default place and size. They will be resized and moved when rebuild() is called.
00048     _closeButton = new ButtonWidget(this, 0, 0, 0, 0, _("Close"), 0, kClose);
00049 
00050     //Check if we have clipboard functionality
00051     if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
00052         _copyToClipboardButton = new ButtonWidget(this, 0, 0, 0, 0, _("Copy to clipboard"), 0, kCopyToClipboard);
00053     } else
00054         _copyToClipboardButton = nullptr;
00055 
00056 #if 0
00057     // Do not create the button for reporting the game directly to the bugtracker
00058     // for now until we find a proper solution for the problem that a change
00059     // to our bugtracker system might break the URL generation. A possible approach
00060     // for solving this would be to have a ULR under the .scummvm.org (of the type
00061     // https://www.scummvm.org/unknowngame?engine=Foo&description=Bar) that would
00062     // redirect to whatever our bugtracker system is.
00063 
00064     //Check if we have support for opening URLs
00065     if (g_system->hasFeature(OSystem::kFeatureOpenUrl)) {
00066         buttonPos -= openBugtrackerURLButtonWidth + 5;
00067         _openBugTrackerUrlButton = new ButtonWidget(this, 0, 0, 0, 0, _("Report game"), 0, kOpenBugtrackerURL);
00068         //Formatting the reportData for bugtracker submission [replace line breaks]...
00069         _bugtrackerGameData = _reportData;
00070         while (_bugtrackerGameData.contains("\n")) {
00071             Common::replace(_bugtrackerGameData, "\n", "%0A");
00072         }
00073     } else
00074 #endif
00075         _openBugTrackerUrlButton = nullptr;
00076 
00077     // Use a ScrollContainer for the report in case we have a lot of lines.
00078     _textContainer = new ScrollContainerWidget(this, 0, 0, 0, 0, kScrollContainerReflow);
00079     _textContainer->setTarget(this);
00080 
00081     rebuild();
00082 }
00083 
00084 void UnknownGameDialog::handleMouseWheel(int x, int y, int direction) {
00085     _textContainer->handleMouseWheel(x, y, direction);
00086 }
00087 
00088 void UnknownGameDialog::reflowLayout() {
00089     rebuild();
00090     Dialog::reflowLayout();
00091 }
00092 
00093 void UnknownGameDialog::rebuild() {
00094     // First remove the old text widgets
00095     for (uint i = 0; i < _textWidgets.size() ; i++) {
00096         _textContainer->removeWidget(_textWidgets[i]);
00097         delete _textWidgets[i];
00098     }
00099     _textWidgets.clear();
00100 
00101     // Work out dialog size and position of the various elements in the dialog.
00102     // Limit the width of the dialog to 600 - 2 * 10 pixels.
00103     const int screenW = MIN((int)g_system->getOverlayWidth(), 600);
00104     const int screenH = g_system->getOverlayHeight();
00105 
00106     int buttonHeight = g_gui.xmlEval()->getVar("Globals.Button.Height", 0);
00107     int buttonWidth = g_gui.xmlEval()->getVar("Globals.Button.Width", 0);
00108 
00109     Common::String reportTranslated = _detectionResults.generateUnknownGameReport(true);
00110 
00111     // Check if we have clipboard functionality and expand the reportTranslated message if needed...
00112     if (g_system->hasFeature(OSystem::kFeatureClipboardSupport)) {
00113         reportTranslated += "\n";
00114         reportTranslated += _("Use the button below to copy the required game information into your clipboard.");
00115     }
00116 
00117 #if 0
00118     // Check if we have support for opening URLs and expand the reportTranslated message if needed...
00119     if (g_system->hasFeature(OSystem::kFeatureOpenUrl)) {
00120         reportTranslated += "\n";
00121         reportTranslated += _("You can also directly report your game to the Bug Tracker.");
00122     }
00123 #endif
00124 
00125     // We use a ScrollContainer to display the text, with a 2 * 8 pixels margin to the dialog border,
00126     // the scrollbar, and 2 * 10 margin for the text in the container.
00127     // We also keep 2 * 10 pixels between the screen border and the dialog.
00128     int scrollbarWidth = g_gui.xmlEval()->getVar("Globals.Scrollbar.Width", 0);
00129     Common::Array<Common::String> lines;
00130     int maxlineWidth = g_gui.getFont().wordWrapText(reportTranslated, screenW - 2 * 20 - 16 - scrollbarWidth, lines);
00131 
00132     int lineCount = lines.size() + 1;
00133 
00134     _h = MIN(screenH - 20, lineCount * kLineHeight + kLineHeight + buttonHeight + 24);
00135 
00136     int closeButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_closeButton->getLabel()) + 10);
00137     int copyToClipboardButtonWidth = 0, openBugtrackerURLButtonWidth = 0, totalButtonWidth = closeButtonWidth;
00138     if (_copyToClipboardButton) {
00139         copyToClipboardButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_copyToClipboardButton->getLabel()) + 10);
00140         totalButtonWidth += copyToClipboardButtonWidth + 10;
00141     }
00142     if (_openBugTrackerUrlButton) {
00143         openBugtrackerURLButtonWidth = MAX(buttonWidth, g_gui.getFont().getStringWidth(_openBugTrackerUrlButton->getLabel()) + 10);
00144         totalButtonWidth += openBugtrackerURLButtonWidth + 10;
00145     }
00146 
00147     _w = MAX(MAX(maxlineWidth, 0) + 16 + scrollbarWidth, totalButtonWidth) + 20;
00148 
00149     // Center the dialog on the screen
00150     _x = (g_system->getOverlayWidth() - _w) / 2;
00151     _y = (g_system->getOverlayHeight() - _h) / 2;
00152 
00153     // Now move the buttons and text container to their proper place
00154     int buttonPos = _w - closeButtonWidth - 10;
00155     _closeButton->resize(buttonPos, _h - buttonHeight - 8, closeButtonWidth, buttonHeight);
00156     if (_copyToClipboardButton) {
00157         buttonPos -= copyToClipboardButtonWidth + 5;
00158         _copyToClipboardButton->resize(buttonPos, _h - buttonHeight - 8, copyToClipboardButtonWidth, buttonHeight);
00159     }
00160     if (_openBugTrackerUrlButton) {
00161         buttonPos -= openBugtrackerURLButtonWidth + 5;
00162         _openBugTrackerUrlButton->resize(buttonPos, _h - buttonHeight - 8, openBugtrackerURLButtonWidth, buttonHeight);
00163     }
00164 
00165     int containerHeight = _h - kLineHeight - buttonHeight - 16;
00166     _textContainer->resize(8, 8, _w - 16, containerHeight);
00167 
00168     // And create text widgets
00169     uint y = 8;
00170     for (uint i = 0; i < lines.size() ; i++) {
00171         StaticTextWidget *widget = new StaticTextWidget(_textContainer, 10, y, _w - 36 - scrollbarWidth, kLineHeight, lines[i], Graphics::kTextAlignLeft);
00172         _textWidgets.push_back(widget);
00173         y += kLineHeight;
00174     }
00175 }
00176 
00177 
00178 Common::String UnknownGameDialog::generateBugtrackerURL() {
00179     // TODO: Remove the filesystem path from the bugtracker report
00180     Common::String report = _detectionResults.generateUnknownGameReport(false);
00181 
00182     // Formatting the report for bugtracker submission [replace line breaks]...
00183     while (report.contains("\n")) {
00184         Common::replace(report, "\n", "%0A");
00185     }
00186 
00187     return Common::String::format(
00188         "https://github.com/residualvm/residualvm/issues/new?"
00189         "&body=%s",
00190         report.c_str());
00191 }
00192 
00193 void UnknownGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
00194     switch(cmd) {
00195     case kCopyToClipboard: {
00196         // TODO: Remove the filesystem path from the report
00197         Common::String report = _detectionResults.generateUnknownGameReport(false);
00198 
00199         if (g_system->setTextInClipboard(report)) {
00200             g_system->displayMessageOnOSD(
00201                     _("All necessary information about your game has been copied into the clipboard"));
00202         } else {
00203             g_system->displayMessageOnOSD(_("Copying the game information to the clipboard has failed!"));
00204         }
00205         break;
00206     }
00207     case kClose:
00208         // When the detection entry comes from the fallback detector, the game can be added / launched anyways.
00209         // TODO: Add a button to cancel adding the game. And make it clear that launching the game may not work properly.
00210         close();
00211         break;
00212     case kOpenBugtrackerURL:
00213         g_system->openUrl(generateBugtrackerURL());
00214         break;
00215     case kScrollContainerReflow:
00216         for (uint i = 0; i < _textWidgets.size() ; i++)
00217             _textWidgets[i]->setVisible(true);
00218         break;
00219     }
00220 }
00221 
00222 } // End of namespace GUI


Generated on Sat May 18 2019 05:01:28 for ResidualVM by doxygen 1.7.1
curved edge   curved edge