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

updates-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 "common/system.h"
00024 #include "common/translation.h"
00025 #include "common/updates.h"
00026 #include "common/config-manager.h"
00027 
00028 #include "gui/updates-dialog.h"
00029 #include "gui/gui-manager.h"
00030 #include "gui/ThemeEval.h"
00031 #include "gui/widgets/popup.h"
00032 
00033 namespace GUI {
00034 
00035 enum {
00036     kProceedCmd = 'PROC'
00037 };
00038 
00039 
00040 UpdatesDialog::UpdatesDialog() : Dialog(30, 20, 260, 124) {
00041 
00042     const int screenW = g_system->getOverlayWidth();
00043     const int screenH = g_system->getOverlayHeight();
00044 
00045     int buttonWidth = g_gui.xmlEval()->getVar("Globals.Button.Width", 0);
00046     int buttonHeight = g_gui.xmlEval()->getVar("Globals.Button.Height", 0);
00047 
00048     const char *message = _(
00049         "ResidualVM now supports automatic check for updates\n"
00050         "which requires access to the Internet. Would you\n"
00051         "like to enable this feature?");
00052     const char *message2 = _("You can change this setting later in the Misc tab\n"
00053         "in the Options dialog.");
00054 
00055     // First, determine the size the dialog needs. For this we have to break
00056     // down the string into lines, and taking the maximum of their widths.
00057     // Using this, and accounting for the space the button(s) need, we can set
00058     // the real size of the dialog
00059     Common::Array<Common::String> lines, lines2, lines3;
00060     int maxlineWidth = g_gui.getFont().wordWrapText(message, screenW - 2 * 20, lines);
00061     int maxlineWidth2 = g_gui.getFont().wordWrapText(message2, screenW - 2 * 20, lines2);
00062 
00063     _w = MAX(MAX(maxlineWidth, maxlineWidth2), (2 * buttonWidth) + 10) + 20;
00064 
00065     int lineCount = lines.size() + 1 + lines2.size();
00066 
00067     _h = 16 + 3 * kLineHeight;
00068     _h += buttonHeight + 8;
00069 
00070     _h += lineCount * kLineHeight;
00071 
00072     // Center the dialog
00073     _x = (screenW - _w) / 2;
00074     _y = (screenH - _h) / 2;
00075 
00076     // Each line is represented by one static text item.
00077     uint y = 10;
00078     for (uint i = 0; i < lines.size(); i++) {
00079         new StaticTextWidget(this, 10, y, maxlineWidth, kLineHeight,
00080                                 lines[i], Graphics::kTextAlignLeft);
00081         y += kLineHeight;
00082     }
00083 
00084     y += kLineHeight;
00085 
00086     const char *updMessage = _("Update check:");
00087 
00088     int updatelineWidth = g_gui.getFont().wordWrapText(updMessage, screenW - 2 * 20, lines3) + 5;
00089 
00090     new StaticTextWidget(this, 10, y, maxlineWidth, kLineHeight, lines3[0], Graphics::kTextAlignLeft);
00091 
00092     _updatesPopUp = new PopUpWidget(this, 10 + updatelineWidth, y, _w - 20 - updatelineWidth, g_gui.xmlEval()->getVar("Globals.PopUp.Height", kLineHeight));
00093 
00094     const int *vals = Common::UpdateManager::getUpdateIntervals();
00095 
00096     while (*vals != -1) {
00097         _updatesPopUp->appendEntry(Common::UpdateManager::updateIntervalToString(*vals), *vals);
00098         vals++;
00099     }
00100 
00101     _updatesPopUp->setSelectedTag(Common::UpdateManager::kUpdateIntervalOneWeek);
00102 
00103     y += kLineHeight * 2;
00104 
00105     for (uint i = 0; i < lines2.size(); i++) {
00106         new StaticTextWidget(this, 10, y, maxlineWidth2, kLineHeight,
00107                                 lines2[i], Graphics::kTextAlignLeft);
00108         y += kLineHeight;
00109     }
00110 
00111     y += kLineHeight + 3;
00112 
00113     int buttonPos = _w - buttonWidth - 10;
00114 
00115     _proceedButton = new ButtonWidget(this, buttonPos, _h - buttonHeight - 8, buttonWidth, buttonHeight,
00116                 _("Proceed"), 0, kProceedCmd, Common::ASCII_RETURN);
00117 }
00118 
00119 void UpdatesDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
00120     if (cmd == kProceedCmd) {
00121         ConfMan.setInt("updates_check", _updatesPopUp->getSelectedTag());
00122 
00123         if (g_system->getUpdateManager()) {
00124             if (_updatesPopUp->getSelectedTag() == Common::UpdateManager::kUpdateIntervalNotSupported) {
00125                 g_system->getUpdateManager()->setAutomaticallyChecksForUpdates(Common::UpdateManager::kUpdateStateDisabled);
00126             } else {
00127                 g_system->getUpdateManager()->setAutomaticallyChecksForUpdates(Common::UpdateManager::kUpdateStateEnabled);
00128                 g_system->getUpdateManager()->setUpdateCheckInterval(_updatesPopUp->getSelectedTag());
00129             }
00130         }
00131         close();
00132     } else {
00133         Dialog::handleCommand(sender, cmd, data);
00134     }
00135 }
00136 
00137 } // End of namespace GUI


Generated on Sat Feb 16 2019 05:01:10 for ResidualVM by doxygen 1.7.1
curved edge   curved edge