From beb168a3a5bac602a9bf1455e7fe93dda0b13a1c Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 9 Jun 2016 17:00:05 +0600 Subject: GUI: Add Cloud tab StorageWizardDialog This is a dialog which guides user through Storage connection procedure. --- gui/storagewizarddialog.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 gui/storagewizarddialog.cpp (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp new file mode 100644 index 0000000000..996365da03 --- /dev/null +++ b/gui/storagewizarddialog.cpp @@ -0,0 +1,73 @@ +/* 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. + * + */ + +#include "gui/storagewizarddialog.h" +#include "gui/widgets/list.h" +#include "gui/widget.h" +#include "gui/gui-manager.h" + +#include "common/translation.h" +#include "backends/cloud/cloudmanager.h" + +namespace GUI { + +enum { + kConnectCmd = 'Cnnt' +}; + +StorageWizardDialog::StorageWizardDialog(uint32 storageId): Dialog("GlobalOptions_Cloud_ConnectionWizard"), _storageId(storageId) { + _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; + + Common::String headline = Common::String::format(_("%s Storage Connection Wizard"), CloudMan.listStorages()[_storageId].c_str()); + new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.Headline", headline); + + new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.NavigateLine", _s("Navigate to the following URL:")); + + Common::String url = "https://www.scummvm.org/cloud-"; + switch (storageId) { + case Cloud::kStorageDropboxId: url += "dropbox"; break; + case Cloud::kStorageOneDriveId: url += "onedrive"; break; + case Cloud::kStorageGoogleDriveId: url += "googledrive"; break; + } + + new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.URLLine", url); + + new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine1", _s("Press 'Continue' when you obtain")); + new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine2", _s("the code from the storage.")); + + // Buttons + new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.CancelButton", _("Cancel"), 0, kCloseCmd); + new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ConnectButton", _("Connect"), 0, kConnectCmd); +} + +void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { + switch (cmd) { + case kConnectCmd: + setResult(1); + close(); + break; + default: + Dialog::handleCommand(sender, cmd, data); + } +} + +} // End of namespace GUI -- cgit v1.2.3 From 9ee2eb4e60a34948797620a0f80ae0a80037efc0 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Fri, 10 Jun 2016 16:35:23 +0600 Subject: GUI: Add EditText in StorageWizardDialog One can enter the code, press 'Connect' button and get a working Storage! --- gui/storagewizarddialog.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index 996365da03..d637440fc8 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -27,11 +27,13 @@ #include "common/translation.h" #include "backends/cloud/cloudmanager.h" +#include "widgets/edittext.h" namespace GUI { enum { - kConnectCmd = 'Cnnt' + kConnectCmd = 'Cnnt', + kCodeBoxCmd = 'CdBx' }; StorageWizardDialog::StorageWizardDialog(uint32 storageId): Dialog("GlobalOptions_Cloud_ConnectionWizard"), _storageId(storageId) { @@ -42,17 +44,18 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): Dialog("GlobalOption new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.NavigateLine", _s("Navigate to the following URL:")); - Common::String url = "https://www.scummvm.org/cloud-"; + Common::String url = "https://www.scummvm.org/c/"; switch (storageId) { - case Cloud::kStorageDropboxId: url += "dropbox"; break; - case Cloud::kStorageOneDriveId: url += "onedrive"; break; - case Cloud::kStorageGoogleDriveId: url += "googledrive"; break; + case Cloud::kStorageDropboxId: url += "db"; break; + case Cloud::kStorageOneDriveId: url += "od"; break; + case Cloud::kStorageGoogleDriveId: url += "gd"; break; } new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.URLLine", url); - new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine1", _s("Press 'Continue' when you obtain")); - new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine2", _s("the code from the storage.")); + new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine1", _s("Obtain the code from the storage, enter it")); + new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine2", _s("in the following field and press 'Connect':")); + _codeWidget = new EditTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.CodeBox", _s("Code"), 0, kCodeBoxCmd); // Buttons new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.CancelButton", _("Cancel"), 0, kCloseCmd); @@ -61,7 +64,10 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): Dialog("GlobalOption void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { + case kCodeBoxCmd: + break; case kConnectCmd: + CloudMan.connectStorage(_storageId, _codeWidget->getEditString()); setResult(1); close(); break; -- cgit v1.2.3 From 3db4915b663d989c01a0e8bf7f8d10a6be754432 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 15 Jun 2016 00:47:41 +0600 Subject: CLOUD: Add checks in StorageWizardDialog It now calculates the checksums for code pieces to determine whether it's correct and CRC-32 for user to compare with one shown on site. --- gui/storagewizarddialog.cpp | 152 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 147 insertions(+), 5 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index d637440fc8..a4091706c8 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -55,25 +55,167 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): Dialog("GlobalOption new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine1", _s("Obtain the code from the storage, enter it")); new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine2", _s("in the following field and press 'Connect':")); - _codeWidget = new EditTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.CodeBox", _s("Code"), 0, kCodeBoxCmd); + for (uint32 i = 0; i < CODE_FIELDS; ++i) + _codeWidget[i] = new EditTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.CodeBox" + Common::String::format("%d", i+1), "", 0, kCodeBoxCmd); + _messageWidget = new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.MessageLine", ""); // Buttons new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.CancelButton", _("Cancel"), 0, kCloseCmd); - new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ConnectButton", _("Connect"), 0, kConnectCmd); + _connectWidget = new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ConnectButton", _("Connect"), 0, kConnectCmd); } void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { - case kCodeBoxCmd: + case kCodeBoxCmd: { + Common::String code, message; + int correctFields = 0; + for (uint32 i = 0; i < CODE_FIELDS; ++i) { + Common::String subcode = _codeWidget[i]->getEditString(); + if (subcode.size() == 0) { + ++correctFields; + continue; + } + bool correct = correctChecksum(subcode); + if (correct) { + code += subcode; + code.deleteLastChar(); + ++correctFields; + } else { + if (i == correctFields) { //first incorrect field + message += Common::String::format("#%d", i + 1); + } else { + message += Common::String::format(", #%d", i + 1); + } + } + } + if (message.size() > 0) { + Common::String messageTemplate; + if (CODE_FIELDS - correctFields == 1) messageTemplate = _("Field %s has a mistake in it."); + else messageTemplate = _("Fields %s have mistakes in them."); + message = Common::String::format(messageTemplate.c_str(), message.c_str()); + } + if (correctFields == CODE_FIELDS && code.size() > 0) { + message = Common::String::format(_("CRC-32 for this code is: %x"), crc32(code)); + _connectWidget->setEnabled(true); + } else { + _connectWidget->setEnabled(false); + } + _messageWidget->setLabel(message); break; - case kConnectCmd: - CloudMan.connectStorage(_storageId, _codeWidget->getEditString()); + } + case kConnectCmd: { + Common::String code; + for (uint32 i = 0; i < CODE_FIELDS; ++i) { + Common::String subcode = _codeWidget[i]->getEditString(); + if (subcode.size() == 0) continue; + code += subcode; + code.deleteLastChar(); + } + CloudMan.connectStorage(_storageId, code); setResult(1); close(); break; + } default: Dialog::handleCommand(sender, cmd, data); } } +int StorageWizardDialog::calculate(char b) { + int r = 0; + for (; b; b = b >> 1) + r += b & 1; + return r; +} + +bool StorageWizardDialog::correctChecksum(Common::String s) { + const char HASHCHARS[65] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!"; + char c = s.lastChar(); + int providedChecksum = -1; + for (uint32 i = 0; i < 64; ++i) + if (c == HASHCHARS[i]) { + providedChecksum = i; + break; + } + int calculatedChecksum = 0; + for (uint32 i = 0; i < s.size()-1; ++i) { + calculatedChecksum = (calculatedChecksum << 1) | (calculate(s[i]) & 1); + } + return providedChecksum == calculatedChecksum; //we can use compare bits to determine which characters are wrong +} + +const uint32 Crc32Table[256] = { + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, + 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, + 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, + 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, + 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, + 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, + 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, + 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, + 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, + 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, + 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, + 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, + 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, + 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, + 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, + 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, + 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, + 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, + 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, + 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, + 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, + 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, + 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, + 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, + 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, + 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, + 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, + 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, + 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, + 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, + 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, + 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, + 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, + 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, + 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, + 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, + 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, + 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, + 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, + 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, + 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, + 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, + 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, + 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, + 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, + 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, + 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, + 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, + 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, + 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, + 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, + 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, + 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, + 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D +}; + +uint32 StorageWizardDialog::crc32(Common::String s) { + uint32 crc = 0xFFFFFFFF; + for (uint32 i = 0; i < s.size(); ++i) + crc = (crc >> 8) ^ Crc32Table[(crc ^ s[i]) & 0xFF]; + return crc ^ 0xFFFFFFFF; +} + } // End of namespace GUI -- cgit v1.2.3 From a83e91e1ca6666be620d1cd1b0a8e4f267d7eaf2 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 15 Jun 2016 13:31:59 +0600 Subject: CLOUD: Update StorageWizardDialog's code check Now the code contains its own crc16 in it, plus the way checksum is calculated has changed. Some online tool calls this exact way of calculating crc16 "CRC16_CCITT_FALSE". --- gui/storagewizarddialog.cpp | 125 ++++++++++++-------------------------------- 1 file changed, 33 insertions(+), 92 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index a4091706c8..b419d1127a 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -88,18 +88,28 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 } } } + if (message.size() > 0) { Common::String messageTemplate; if (CODE_FIELDS - correctFields == 1) messageTemplate = _("Field %s has a mistake in it."); else messageTemplate = _("Fields %s have mistakes in them."); message = Common::String::format(messageTemplate.c_str(), message.c_str()); } + + bool ok = false; if (correctFields == CODE_FIELDS && code.size() > 0) { - message = Common::String::format(_("CRC-32 for this code is: %x"), crc32(code)); - _connectWidget->setEnabled(true); - } else { - _connectWidget->setEnabled(false); + //the last 3 chars must be an encoded crc16 + if (code.size() > 3) { + uint32 size = code.size(); + uint32 gotcrc = decodeHashchar(code[size-3]) | (decodeHashchar(code[size-2]) << 6) | (decodeHashchar(code[size-1]) << 12); + code.erase(size - 3); + uint32 crc = crc16(code); + ok = (crc == gotcrc); + } + if (ok) message = _("All OK!"); + else message = _("Invalid code"); } + _connectWidget->setEnabled(ok); _messageWidget->setLabel(message); break; } @@ -111,6 +121,7 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 code += subcode; code.deleteLastChar(); } + code.erase(code.size() - 3); CloudMan.connectStorage(_storageId, code); setResult(1); close(); @@ -121,101 +132,31 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 } } -int StorageWizardDialog::calculate(char b) { - int r = 0; - for (; b; b = b >> 1) - r += b & 1; - return r; +int StorageWizardDialog::decodeHashchar(char c) { + const char HASHCHARS[65] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!"; + for (uint32 i = 0; i < 64; ++i) + if (c == HASHCHARS[i]) + return i; + return -1; } bool StorageWizardDialog::correctChecksum(Common::String s) { - const char HASHCHARS[65] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!"; - char c = s.lastChar(); - int providedChecksum = -1; - for (uint32 i = 0; i < 64; ++i) - if (c == HASHCHARS[i]) { - providedChecksum = i; - break; - } - int calculatedChecksum = 0; + int providedChecksum = decodeHashchar(s.lastChar()); + int calculatedChecksum = 0x2A; for (uint32 i = 0; i < s.size()-1; ++i) { - calculatedChecksum = (calculatedChecksum << 1) | (calculate(s[i]) & 1); + calculatedChecksum = calculatedChecksum ^ s[i]; } - return providedChecksum == calculatedChecksum; //we can use compare bits to determine which characters are wrong + return providedChecksum == (calculatedChecksum % 64); } -const uint32 Crc32Table[256] = { - 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, - 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, - 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, - 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, - 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, - 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, - 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, - 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, - 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, - 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, - 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, - 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, - 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, - 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, - 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, - 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, - 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, - 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, - 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, - 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, - 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, - 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, - 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, - 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, - 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, - 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, - 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, - 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, - 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, - 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, - 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, - 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, - 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, - 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, - 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, - 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, - 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, - 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, - 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, - 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, - 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, - 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, - 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, - 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, - 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, - 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, - 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, - 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, - 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, - 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, - 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, - 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, - 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, - 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, - 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, - 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, - 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, - 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, - 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, - 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, - 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, - 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, - 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, - 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D -}; - -uint32 StorageWizardDialog::crc32(Common::String s) { - uint32 crc = 0xFFFFFFFF; - for (uint32 i = 0; i < s.size(); ++i) - crc = (crc >> 8) ^ Crc32Table[(crc ^ s[i]) & 0xFF]; - return crc ^ 0xFFFFFFFF; +uint32 StorageWizardDialog::crc16(Common::String s) { //"CRC16_CCITT_FALSE" + uint32 crc = 0xFFFF, x; + for (uint32 i = 0; i < s.size(); ++i) { + x = ((crc >> 8) ^ s[i]) & 0xFF; + x ^= x >> 4; + crc = ((crc << 8) ^ (x << 12) ^ (x << 5) ^ x) & 0xFFFF; + } + return crc; } } // End of namespace GUI -- cgit v1.2.3 From f571f3dd28a4b82973d26ff724edec60ad6ea845 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 15 Jun 2016 13:40:15 +0600 Subject: CLOUD: Add comments for StorageWizardDialog methods --- gui/storagewizarddialog.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index b419d1127a..46be812f6d 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -141,6 +141,7 @@ int StorageWizardDialog::decodeHashchar(char c) { } bool StorageWizardDialog::correctChecksum(Common::String s) { + if (s.size() == 0) return false; //no last char int providedChecksum = decodeHashchar(s.lastChar()); int calculatedChecksum = 0x2A; for (uint32 i = 0; i < s.size()-1; ++i) { -- cgit v1.2.3 From 0af97e59bc63538d18d2241285b68ed287ccd87c Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 15 Jun 2016 16:38:37 +0600 Subject: CLOUD: Add LocalWebserver Available as LocalServer singleton. It's being started and stopped by StorageWizardDialog. It doesn't handle clients yet, though. --- gui/storagewizarddialog.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index 46be812f6d..579591ba18 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -24,9 +24,11 @@ #include "gui/widgets/list.h" #include "gui/widget.h" #include "gui/gui-manager.h" - -#include "common/translation.h" #include "backends/cloud/cloudmanager.h" +#ifdef USE_SDL_NET +#include "backends/networking/sdl_net/localwebserver.h" +#endif +#include "common/translation.h" #include "widgets/edittext.h" namespace GUI { @@ -64,6 +66,20 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): Dialog("GlobalOption _connectWidget = new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ConnectButton", _("Connect"), 0, kConnectCmd); } +void StorageWizardDialog::open() { + Dialog::open(); +#ifdef USE_SDL_NET + LocalServer.start(); +#endif +} + +void StorageWizardDialog::close() { +#ifdef USE_SDL_NET + LocalServer.stop(); +#endif + Dialog::close(); +} + void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { case kCodeBoxCmd: { -- cgit v1.2.3 From 434b740f4da7f77df902c0be6476cd360688c7ac Mon Sep 17 00:00:00 2001 From: Peter Bozsó Date: Thu, 16 Jun 2016 07:52:44 +0200 Subject: CLOUD: Remove a couple of unnecessary whitespaces --- gui/storagewizarddialog.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index 579591ba18..f93721fdc1 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -91,7 +91,7 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 ++correctFields; continue; } - bool correct = correctChecksum(subcode); + bool correct = correctChecksum(subcode); if (correct) { code += subcode; code.deleteLastChar(); @@ -114,18 +114,18 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 bool ok = false; if (correctFields == CODE_FIELDS && code.size() > 0) { - //the last 3 chars must be an encoded crc16 + //the last 3 chars must be an encoded crc16 if (code.size() > 3) { uint32 size = code.size(); - uint32 gotcrc = decodeHashchar(code[size-3]) | (decodeHashchar(code[size-2]) << 6) | (decodeHashchar(code[size-1]) << 12); + uint32 gotcrc = decodeHashchar(code[size-3]) | (decodeHashchar(code[size-2]) << 6) | (decodeHashchar(code[size-1]) << 12); code.erase(size - 3); uint32 crc = crc16(code); ok = (crc == gotcrc); - } + } if (ok) message = _("All OK!"); else message = _("Invalid code"); } - _connectWidget->setEnabled(ok); + _connectWidget->setEnabled(ok); _messageWidget->setLabel(message); break; } @@ -171,7 +171,7 @@ uint32 StorageWizardDialog::crc16(Common::String s) { //"CRC16_CCITT_FALSE" for (uint32 i = 0; i < s.size(); ++i) { x = ((crc >> 8) ^ s[i]) & 0xFF; x ^= x >> 4; - crc = ((crc << 8) ^ (x << 12) ^ (x << 5) ^ x) & 0xFFFF; + crc = ((crc << 8) ^ (x << 12) ^ (x << 5) ^ x) & 0xFFFF; } return crc; } -- cgit v1.2.3 From ceb86a0dd8421047fc3d067da2a4c7faccc2f782 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 16 Jun 2016 12:37:44 +0600 Subject: CLOUD: Clarify calculatedChecksum's initial value --- gui/storagewizarddialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index f93721fdc1..58ca095148 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -159,7 +159,7 @@ int StorageWizardDialog::decodeHashchar(char c) { bool StorageWizardDialog::correctChecksum(Common::String s) { if (s.size() == 0) return false; //no last char int providedChecksum = decodeHashchar(s.lastChar()); - int calculatedChecksum = 0x2A; + int calculatedChecksum = 0x2A; //any initial value would do, but it must equal to the one used on the page where these checksums were generated for (uint32 i = 0; i < s.size()-1; ++i) { calculatedChecksum = calculatedChecksum ^ s[i]; } -- cgit v1.2.3 From 5ac3adbd4fbf40c22fccab6ce8bf8dcab8f98eff Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 16 Jun 2016 15:19:13 +0600 Subject: CLOUD: Add IndexPageHandler This commit also adds LocalWebserver's stopOnIdle(). That means server is not stopped immediately, but only when all clients are served. --- gui/storagewizarddialog.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index 58ca095148..c2759f2ae6 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -38,7 +38,8 @@ enum { kCodeBoxCmd = 'CdBx' }; -StorageWizardDialog::StorageWizardDialog(uint32 storageId): Dialog("GlobalOptions_Cloud_ConnectionWizard"), _storageId(storageId) { +StorageWizardDialog::StorageWizardDialog(uint32 storageId): + Dialog("GlobalOptions_Cloud_ConnectionWizard"), _storageId(storageId), _close(false) { _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; Common::String headline = Common::String::format(_("%s Storage Connection Wizard"), CloudMan.listStorages()[_storageId].c_str()); @@ -70,12 +71,14 @@ void StorageWizardDialog::open() { Dialog::open(); #ifdef USE_SDL_NET LocalServer.start(); + LocalServer.indexPageHandler().setTarget(this); #endif } void StorageWizardDialog::close() { #ifdef USE_SDL_NET - LocalServer.stop(); + LocalServer.stopOnIdle(); + LocalServer.indexPageHandler().setTarget(nullptr); #endif Dialog::close(); } @@ -143,11 +146,26 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 close(); break; } +#ifdef USE_SDL_NET + case kStorageCodePassedCmd: + CloudMan.connectStorage(_storageId, LocalServer.indexPageHandler().code()); + _close = true; + break; +#endif default: Dialog::handleCommand(sender, cmd, data); } } +void StorageWizardDialog::handleTickle() { + if (_close) { + setResult(1); + close(); + } + + Dialog::handleTickle(); +} + int StorageWizardDialog::decodeHashchar(char c) { const char HASHCHARS[65] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!"; for (uint32 i = 0; i < 64; ++i) -- cgit v1.2.3 From c2c2ba908ff916e0ba680596bb1b565069255a67 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 16 Jun 2016 21:04:10 +0600 Subject: GUI: Hide StorageWizardDialog fields if server present --- gui/storagewizarddialog.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index c2759f2ae6..88826c2fb8 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -53,11 +53,14 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): case Cloud::kStorageOneDriveId: url += "od"; break; case Cloud::kStorageGoogleDriveId: url += "gd"; break; } +#ifdef USE_SDL_NET + url += "s"; +#endif new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.URLLine", url); - new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine1", _s("Obtain the code from the storage, enter it")); - new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine2", _s("in the following field and press 'Connect':")); + StaticTextWidget *returnLine1 = new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine1", _s("Obtain the code from the storage, enter it")); + StaticTextWidget *returnLine2 = new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine2", _s("in the following field and press 'Connect':")); for (uint32 i = 0; i < CODE_FIELDS; ++i) _codeWidget[i] = new EditTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.CodeBox" + Common::String::format("%d", i+1), "", 0, kCodeBoxCmd); _messageWidget = new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.MessageLine", ""); @@ -65,6 +68,16 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): // Buttons new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.CancelButton", _("Cancel"), 0, kCloseCmd); _connectWidget = new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ConnectButton", _("Connect"), 0, kConnectCmd); + +#ifdef USE_SDL_NET + // hide fields and even the button if local webserver is on + returnLine1->setLabel(_s("You would be navigated to ScummVM's page")); + returnLine2->setLabel(_s("when you'd allow it to use your storage.")); + for (uint32 i = 0; i < CODE_FIELDS; ++i) + _codeWidget[i]->setVisible(false); + _messageWidget->setVisible(false); + _connectWidget->setVisible(false); +#endif } void StorageWizardDialog::open() { -- cgit v1.2.3 From b908b286b9767ff7a0207ce9414279ce5291762c Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Sat, 18 Jun 2016 14:34:43 +0600 Subject: CLOUD: Fix "signed/unsigned integers" warning The "comparison between signed and unsigned integer expressions" one. Note that in UploadRequests size() and pos() are acutally signed, because they could return -1. This commit implies that Requests are working with such Streams which doesn't. --- gui/storagewizarddialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index 88826c2fb8..6734d1c97e 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -100,7 +100,7 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 switch (cmd) { case kCodeBoxCmd: { Common::String code, message; - int correctFields = 0; + uint32 correctFields = 0; for (uint32 i = 0; i < CODE_FIELDS; ++i) { Common::String subcode = _codeWidget[i]->getEditString(); if (subcode.size() == 0) { -- cgit v1.2.3 From e601c39802adbb64dce4b449c617e1786ef584ed Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 5 Jul 2016 16:31:52 +0600 Subject: CLOUD: Make "Run server" button active It should show the real server's IP over there, but that doesn't work yet. --- gui/storagewizarddialog.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index 6734d1c97e..7871017f5d 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -39,7 +39,7 @@ enum { }; StorageWizardDialog::StorageWizardDialog(uint32 storageId): - Dialog("GlobalOptions_Cloud_ConnectionWizard"), _storageId(storageId), _close(false) { + Dialog("GlobalOptions_Cloud_ConnectionWizard"), _storageId(storageId), _close(false), _stopServerOnClose(false) { _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; Common::String headline = Common::String::format(_("%s Storage Connection Wizard"), CloudMan.listStorages()[_storageId].c_str()); @@ -83,6 +83,7 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): void StorageWizardDialog::open() { Dialog::open(); #ifdef USE_SDL_NET + _stopServerOnClose = !LocalServer.isRunning(); LocalServer.start(); LocalServer.indexPageHandler().setTarget(this); #endif @@ -90,7 +91,7 @@ void StorageWizardDialog::open() { void StorageWizardDialog::close() { #ifdef USE_SDL_NET - LocalServer.stopOnIdle(); + if (_stopServerOnClose) LocalServer.stopOnIdle(); LocalServer.indexPageHandler().setTarget(nullptr); #endif Dialog::close(); -- cgit v1.2.3 From b37b392fa07c5d24fbef2ffe4b4704e8f666f9a1 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 13 Jul 2016 00:33:35 +0600 Subject: CLOUD: Add BoxStorage sketch --- gui/storagewizarddialog.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index 7871017f5d..8e3f17746b 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -52,6 +52,7 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): case Cloud::kStorageDropboxId: url += "db"; break; case Cloud::kStorageOneDriveId: url += "od"; break; case Cloud::kStorageGoogleDriveId: url += "gd"; break; + case Cloud::kStorageBoxId: url += "bx"; break; } #ifdef USE_SDL_NET url += "s"; -- cgit v1.2.3 From 2ae438327b0c5cbe3fbc3a45ac1069fed7709326 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 14 Jul 2016 12:34:31 +0600 Subject: GUI: Add "Open URL" button in StorageWizardDialog It uses Networking::Browser::openUrl(). --- gui/storagewizarddialog.cpp | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index 8e3f17746b..86513e2980 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -28,6 +28,7 @@ #ifdef USE_SDL_NET #include "backends/networking/sdl_net/localwebserver.h" #endif +#include "backends/networking/browser/openurl.h" #include "common/translation.h" #include "widgets/edittext.h" @@ -35,7 +36,8 @@ namespace GUI { enum { kConnectCmd = 'Cnnt', - kCodeBoxCmd = 'CdBx' + kCodeBoxCmd = 'CdBx', + kOpenUrlCmd = 'OpUr' }; StorageWizardDialog::StorageWizardDialog(uint32 storageId): @@ -46,19 +48,7 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.Headline", headline); new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.NavigateLine", _s("Navigate to the following URL:")); - - Common::String url = "https://www.scummvm.org/c/"; - switch (storageId) { - case Cloud::kStorageDropboxId: url += "db"; break; - case Cloud::kStorageOneDriveId: url += "od"; break; - case Cloud::kStorageGoogleDriveId: url += "gd"; break; - case Cloud::kStorageBoxId: url += "bx"; break; - } -#ifdef USE_SDL_NET - url += "s"; -#endif - - new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.URLLine", url); + new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.URLLine", getUrl()); StaticTextWidget *returnLine1 = new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine1", _s("Obtain the code from the storage, enter it")); StaticTextWidget *returnLine2 = new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine2", _s("in the following field and press 'Connect':")); @@ -68,6 +58,7 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): // Buttons new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.CancelButton", _("Cancel"), 0, kCloseCmd); + new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.OpenUrlButton", _("Open URL"), 0, kOpenUrlCmd); _connectWidget = new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ConnectButton", _("Connect"), 0, kConnectCmd); #ifdef USE_SDL_NET @@ -147,6 +138,12 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 _messageWidget->setLabel(message); break; } + case kOpenUrlCmd: { + if (!Networking::Browser::openUrl(getUrl())) { + _messageWidget->setLabel(_("Failed to open URL!")); + } + break; + } case kConnectCmd: { Common::String code; for (uint32 i = 0; i < CODE_FIELDS; ++i) { @@ -181,6 +178,21 @@ void StorageWizardDialog::handleTickle() { Dialog::handleTickle(); } +Common::String StorageWizardDialog::getUrl() const { + Common::String url = "https://www.scummvm.org/c/"; + switch (_storageId) { + case Cloud::kStorageDropboxId: url += "db"; break; + case Cloud::kStorageOneDriveId: url += "od"; break; + case Cloud::kStorageGoogleDriveId: url += "gd"; break; + case Cloud::kStorageBoxId: url += "bx"; break; + } +#ifdef USE_SDL_NET + url += "s"; +#endif + return url; +} + + int StorageWizardDialog::decodeHashchar(char c) { const char HASHCHARS[65] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!"; for (uint32 i = 0; i < 64; ++i) -- cgit v1.2.3 From 33ca8d485c0973d30290163a198e81bd511cf0ec Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 14 Jul 2016 12:44:05 +0600 Subject: GUI: Fix StorageWizardDialog It now shows a MessageDialog (its message label is hidden in some cases). --- gui/storagewizarddialog.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index 86513e2980..393b8263ef 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -21,9 +21,9 @@ */ #include "gui/storagewizarddialog.h" -#include "gui/widgets/list.h" -#include "gui/widget.h" #include "gui/gui-manager.h" +#include "gui/message.h" +#include "gui/widget.h" #include "backends/cloud/cloudmanager.h" #ifdef USE_SDL_NET #include "backends/networking/sdl_net/localwebserver.h" @@ -140,7 +140,8 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 } case kOpenUrlCmd: { if (!Networking::Browser::openUrl(getUrl())) { - _messageWidget->setLabel(_("Failed to open URL!")); + MessageDialog alert(_("Failed to open URL!\nYou should navigate there manually then.")); + alert.runModal(); } break; } -- cgit v1.2.3 From b1264df120b6594a79d99cbb1cc5ef944fa2e448 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 20 Jul 2016 15:00:44 +0600 Subject: CLOUD: Check whether Storage is working when replacing it We do that in CloudManager::replaceStorage(), but I've tried to eliminate such possibility by adding a check in the StorageWizardDialog. --- gui/storagewizarddialog.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index 393b8263ef..a8574ab7d2 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -74,6 +74,29 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): void StorageWizardDialog::open() { Dialog::open(); + + if (CloudMan.isWorking()) { + bool doClose = true; + + MessageDialog alert(_("The other Storage is working. Do you want to interrupt it?"), _("Yes"), _("No")); + if (alert.runModal() == GUI::kMessageOK) { + if (CloudMan.isDownloading()) CloudMan.cancelDownload(); + if (CloudMan.isSyncing()) CloudMan.cancelSync(); + + // I believe it still would return `true` here, but just in case + if (CloudMan.isWorking()) { + MessageDialog alert2(_("Wait until current Storage finishes up and try again.")); + alert2.runModal(); + } else + doClose = false; + } + + if (doClose) { + close(); + return; + } + } + #ifdef USE_SDL_NET _stopServerOnClose = !LocalServer.isRunning(); LocalServer.start(); -- cgit v1.2.3 From 85f4c69fc981ae1d3807ffb0280b59d627a92ebc Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 20 Jul 2016 16:36:44 +0600 Subject: CLOUD: Update StorageWizardDialog It now hides code fields not just when built with SDL_Net, but also when LocalWebserver's using default port. So that's why NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE is defined in localwebserver.h now. --- gui/storagewizarddialog.cpp | 50 ++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index a8574ab7d2..299da11812 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -61,15 +61,15 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.OpenUrlButton", _("Open URL"), 0, kOpenUrlCmd); _connectWidget = new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ConnectButton", _("Connect"), 0, kConnectCmd); -#ifdef USE_SDL_NET - // hide fields and even the button if local webserver is on - returnLine1->setLabel(_s("You would be navigated to ScummVM's page")); - returnLine2->setLabel(_s("when you'd allow it to use your storage.")); - for (uint32 i = 0; i < CODE_FIELDS; ++i) - _codeWidget[i]->setVisible(false); - _messageWidget->setVisible(false); - _connectWidget->setVisible(false); -#endif + if (couldUseLocalServer()) { + // hide fields and even the button if local webserver is on + returnLine1->setLabel(_s("You would be navigated to ScummVM's page")); + returnLine2->setLabel(_s("when you'd allow it to use your storage.")); + for (uint32 i = 0; i < CODE_FIELDS; ++i) + _codeWidget[i]->setVisible(false); + _messageWidget->setVisible(false); + _connectWidget->setVisible(false); + } } void StorageWizardDialog::open() { @@ -97,18 +97,18 @@ void StorageWizardDialog::open() { } } -#ifdef USE_SDL_NET - _stopServerOnClose = !LocalServer.isRunning(); - LocalServer.start(); - LocalServer.indexPageHandler().setTarget(this); -#endif + if (couldUseLocalServer()) { + _stopServerOnClose = !LocalServer.isRunning(); + LocalServer.start(); + LocalServer.indexPageHandler().setTarget(this); + } } void StorageWizardDialog::close() { -#ifdef USE_SDL_NET - if (_stopServerOnClose) LocalServer.stopOnIdle(); - LocalServer.indexPageHandler().setTarget(nullptr); -#endif + if (couldUseLocalServer()) { + if (_stopServerOnClose) LocalServer.stopOnIdle(); + LocalServer.indexPageHandler().setTarget(nullptr); + } Dialog::close(); } @@ -182,12 +182,10 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 close(); break; } -#ifdef USE_SDL_NET case kStorageCodePassedCmd: CloudMan.connectStorage(_storageId, LocalServer.indexPageHandler().code()); _close = true; break; -#endif default: Dialog::handleCommand(sender, cmd, data); } @@ -210,12 +208,18 @@ Common::String StorageWizardDialog::getUrl() const { case Cloud::kStorageGoogleDriveId: url += "gd"; break; case Cloud::kStorageBoxId: url += "bx"; break; } -#ifdef USE_SDL_NET - url += "s"; -#endif + + if (couldUseLocalServer()) url += "s"; return url; } +bool StorageWizardDialog::couldUseLocalServer() const { +#ifdef USE_SDL_NET + return Networking::LocalWebserver::getPort() == Networking::LocalWebserver::DEFAULT_SERVER_PORT; +#else + return false; +#endif +} int StorageWizardDialog::decodeHashchar(char c) { const char HASHCHARS[65] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!"; -- cgit v1.2.3 From 438ba985a4a97a8695a6e6fdda6930694976c07b Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 21 Jul 2016 11:44:36 +0600 Subject: JANITORIAL: Remove spaces at the end of the line I knew there were some, but I wanted to fix them once, instead of doing it all the time. --- gui/storagewizarddialog.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index 299da11812..b411a2e0dc 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -46,7 +46,7 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): Common::String headline = Common::String::format(_("%s Storage Connection Wizard"), CloudMan.listStorages()[_storageId].c_str()); new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.Headline", headline); - + new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.NavigateLine", _s("Navigate to the following URL:")); new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.URLLine", getUrl()); @@ -114,7 +114,7 @@ void StorageWizardDialog::close() { void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { switch (cmd) { - case kCodeBoxCmd: { + case kCodeBoxCmd: { Common::String code, message; uint32 correctFields = 0; for (uint32 i = 0; i < CODE_FIELDS; ++i) { @@ -184,7 +184,7 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 } case kStorageCodePassedCmd: CloudMan.connectStorage(_storageId, LocalServer.indexPageHandler().code()); - _close = true; + _close = true; break; default: Dialog::handleCommand(sender, cmd, data); @@ -208,7 +208,7 @@ Common::String StorageWizardDialog::getUrl() const { case Cloud::kStorageGoogleDriveId: url += "gd"; break; case Cloud::kStorageBoxId: url += "bx"; break; } - + if (couldUseLocalServer()) url += "s"; return url; } @@ -222,7 +222,7 @@ bool StorageWizardDialog::couldUseLocalServer() const { } int StorageWizardDialog::decodeHashchar(char c) { - const char HASHCHARS[65] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!"; + const char HASHCHARS[65] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!"; for (uint32 i = 0; i < 64; ++i) if (c == HASHCHARS[i]) return i; @@ -232,10 +232,10 @@ int StorageWizardDialog::decodeHashchar(char c) { bool StorageWizardDialog::correctChecksum(Common::String s) { if (s.size() == 0) return false; //no last char int providedChecksum = decodeHashchar(s.lastChar()); - int calculatedChecksum = 0x2A; //any initial value would do, but it must equal to the one used on the page where these checksums were generated + int calculatedChecksum = 0x2A; //any initial value would do, but it must equal to the one used on the page where these checksums were generated for (uint32 i = 0; i < s.size()-1; ++i) { calculatedChecksum = calculatedChecksum ^ s[i]; - } + } return providedChecksum == (calculatedChecksum % 64); } -- cgit v1.2.3 From 772d8ee42b820a5c19a8d9a9efb215f17606fb8f Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 21 Jul 2016 12:06:00 +0600 Subject: CLOUD: Fix `redirect_uri` selection code Now it's not hardcoded based on USE_SDL_NET, but one or another value is used depending on currently selected LocalWebserver's port. --- gui/storagewizarddialog.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index b411a2e0dc..5838dd1f11 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -61,7 +61,7 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.OpenUrlButton", _("Open URL"), 0, kOpenUrlCmd); _connectWidget = new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ConnectButton", _("Connect"), 0, kConnectCmd); - if (couldUseLocalServer()) { + if (Cloud::CloudManager::couldUseLocalServer()) { // hide fields and even the button if local webserver is on returnLine1->setLabel(_s("You would be navigated to ScummVM's page")); returnLine2->setLabel(_s("when you'd allow it to use your storage.")); @@ -97,7 +97,7 @@ void StorageWizardDialog::open() { } } - if (couldUseLocalServer()) { + if (Cloud::CloudManager::couldUseLocalServer()) { _stopServerOnClose = !LocalServer.isRunning(); LocalServer.start(); LocalServer.indexPageHandler().setTarget(this); @@ -105,7 +105,7 @@ void StorageWizardDialog::open() { } void StorageWizardDialog::close() { - if (couldUseLocalServer()) { + if (Cloud::CloudManager::couldUseLocalServer()) { if (_stopServerOnClose) LocalServer.stopOnIdle(); LocalServer.indexPageHandler().setTarget(nullptr); } @@ -209,18 +209,10 @@ Common::String StorageWizardDialog::getUrl() const { case Cloud::kStorageBoxId: url += "bx"; break; } - if (couldUseLocalServer()) url += "s"; + if (Cloud::CloudManager::couldUseLocalServer()) url += "s"; return url; } -bool StorageWizardDialog::couldUseLocalServer() const { -#ifdef USE_SDL_NET - return Networking::LocalWebserver::getPort() == Networking::LocalWebserver::DEFAULT_SERVER_PORT; -#else - return false; -#endif -} - int StorageWizardDialog::decodeHashchar(char c) { const char HASHCHARS[65] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ?!"; for (uint32 i = 0; i < 64; ++i) -- cgit v1.2.3 From 53aa0c46f1a5d6aefe3f2a087c60d9a59439aedf Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 22 Jul 2016 15:48:46 +0300 Subject: GUI: JANITORIAL: Fix code formatting --- gui/storagewizarddialog.cpp | 50 +++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 15 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index 5838dd1f11..e3bac98175 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -80,15 +80,18 @@ void StorageWizardDialog::open() { MessageDialog alert(_("The other Storage is working. Do you want to interrupt it?"), _("Yes"), _("No")); if (alert.runModal() == GUI::kMessageOK) { - if (CloudMan.isDownloading()) CloudMan.cancelDownload(); - if (CloudMan.isSyncing()) CloudMan.cancelSync(); + if (CloudMan.isDownloading()) + CloudMan.cancelDownload(); + if (CloudMan.isSyncing()) + CloudMan.cancelSync(); // I believe it still would return `true` here, but just in case if (CloudMan.isWorking()) { MessageDialog alert2(_("Wait until current Storage finishes up and try again.")); alert2.runModal(); - } else + } else { doClose = false; + } } if (doClose) { @@ -106,7 +109,8 @@ void StorageWizardDialog::open() { void StorageWizardDialog::close() { if (Cloud::CloudManager::couldUseLocalServer()) { - if (_stopServerOnClose) LocalServer.stopOnIdle(); + if (_stopServerOnClose) + LocalServer.stopOnIdle(); LocalServer.indexPageHandler().setTarget(nullptr); } Dialog::close(); @@ -139,8 +143,10 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 if (message.size() > 0) { Common::String messageTemplate; - if (CODE_FIELDS - correctFields == 1) messageTemplate = _("Field %s has a mistake in it."); - else messageTemplate = _("Fields %s have mistakes in them."); + if (CODE_FIELDS - correctFields == 1) + messageTemplate = _("Field %s has a mistake in it."); + else + messageTemplate = _("Fields %s have mistakes in them."); message = Common::String::format(messageTemplate.c_str(), message.c_str()); } @@ -154,8 +160,10 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 uint32 crc = crc16(code); ok = (crc == gotcrc); } - if (ok) message = _("All OK!"); - else message = _("Invalid code"); + if (ok) + message = _("All OK!"); + else + message = _("Invalid code"); } _connectWidget->setEnabled(ok); _messageWidget->setLabel(message); @@ -172,7 +180,8 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 Common::String code; for (uint32 i = 0; i < CODE_FIELDS; ++i) { Common::String subcode = _codeWidget[i]->getEditString(); - if (subcode.size() == 0) continue; + if (subcode.size() == 0) + continue; code += subcode; code.deleteLastChar(); } @@ -203,13 +212,23 @@ void StorageWizardDialog::handleTickle() { Common::String StorageWizardDialog::getUrl() const { Common::String url = "https://www.scummvm.org/c/"; switch (_storageId) { - case Cloud::kStorageDropboxId: url += "db"; break; - case Cloud::kStorageOneDriveId: url += "od"; break; - case Cloud::kStorageGoogleDriveId: url += "gd"; break; - case Cloud::kStorageBoxId: url += "bx"; break; + case Cloud::kStorageDropboxId: + url += "db"; + break; + case Cloud::kStorageOneDriveId: + url += "od"; + break; + case Cloud::kStorageGoogleDriveId: + url += "gd"; + break; + case Cloud::kStorageBoxId: + url += "bx"; + break; } - if (Cloud::CloudManager::couldUseLocalServer()) url += "s"; + if (Cloud::CloudManager::couldUseLocalServer()) + url += "s"; + return url; } @@ -222,7 +241,8 @@ int StorageWizardDialog::decodeHashchar(char c) { } bool StorageWizardDialog::correctChecksum(Common::String s) { - if (s.size() == 0) return false; //no last char + if (s.size() == 0) + return false; //no last char int providedChecksum = decodeHashchar(s.lastChar()); int calculatedChecksum = 0x2A; //any initial value would do, but it must equal to the one used on the page where these checksums were generated for (uint32 i = 0; i < s.size()-1; ++i) { -- cgit v1.2.3 From c9b819b577e9e406fd8ac85773c82101b98766c2 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Sun, 24 Jul 2016 11:13:20 +0600 Subject: GUI: Make Options dialog stop LocalServer on close Commit also adds a fix for StorageWizardDialog, where LocalServer was used even if USE_SDL_NET was undefined. --- gui/storagewizarddialog.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index e3bac98175..d4ad3e32df 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -100,19 +100,23 @@ void StorageWizardDialog::open() { } } +#ifdef USE_SDL_NET if (Cloud::CloudManager::couldUseLocalServer()) { _stopServerOnClose = !LocalServer.isRunning(); LocalServer.start(); LocalServer.indexPageHandler().setTarget(this); } +#endif } void StorageWizardDialog::close() { +#ifdef USE_SDL_NET if (Cloud::CloudManager::couldUseLocalServer()) { if (_stopServerOnClose) LocalServer.stopOnIdle(); LocalServer.indexPageHandler().setTarget(nullptr); } +#endif Dialog::close(); } -- cgit v1.2.3 From 86f7b75dd7436322f90b6633739b96f92dec16a2 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 25 Jul 2016 13:13:47 +0600 Subject: GUI: Fix SDL_Net-related errors Checked by rebuilding ScummVM without SDL_Net in MinGW. Also fixes StorageWizardDialog's warning about _stopServerOnClose. --- gui/storagewizarddialog.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index d4ad3e32df..9e522fb2de 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -41,7 +41,10 @@ enum { }; StorageWizardDialog::StorageWizardDialog(uint32 storageId): - Dialog("GlobalOptions_Cloud_ConnectionWizard"), _storageId(storageId), _close(false), _stopServerOnClose(false) { + Dialog("GlobalOptions_Cloud_ConnectionWizard"), _storageId(storageId), _close(false) { +#ifdef USE_SDL_NET + _stopServerOnClose = false; +#endif _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; Common::String headline = Common::String::format(_("%s Storage Connection Wizard"), CloudMan.listStorages()[_storageId].c_str()); @@ -195,10 +198,12 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 close(); break; } +#ifdef USE_SDL_NET case kStorageCodePassedCmd: CloudMan.connectStorage(_storageId, LocalServer.indexPageHandler().code()); _close = true; break; +#endif default: Dialog::handleCommand(sender, cmd, data); } -- cgit v1.2.3 From c74ba4652d497ddbdec4342029d94bc77387a705 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 25 Jul 2016 16:37:44 +0600 Subject: GUI: Add "Paste" button in StorageWizardDialog It pastes clipboard contents as code into 8 fields of that dialog. (Clipboard support works with SDL2 only.) "Open URL" and "Paste" buttons are placed in the left column under the picture (because there is no room for 4 buttons in the bottom row). Commit also adds "dropbox.bmp", which is just a square 115x115 picture. Such pictures are would be used as Storages logos in that dialog. In lowres there is no left column, so all 4 buttons are in the same row. None of them are visible, because they are overflowed. Container has to be added to continue working on them. --- gui/storagewizarddialog.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index 9e522fb2de..e04ca0255e 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -20,6 +20,13 @@ * */ +#ifdef USE_SDL2 +#define FORBIDDEN_SYMBOL_ALLOW_ALL + +#include +#include +#endif + #include "gui/storagewizarddialog.h" #include "gui/gui-manager.h" #include "gui/message.h" @@ -37,7 +44,8 @@ namespace GUI { enum { kConnectCmd = 'Cnnt', kCodeBoxCmd = 'CdBx', - kOpenUrlCmd = 'OpUr' + kOpenUrlCmd = 'OpUr', + kPasteCodeCmd = 'PsCd' }; StorageWizardDialog::StorageWizardDialog(uint32 storageId): @@ -62,6 +70,7 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): // Buttons new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.CancelButton", _("Cancel"), 0, kCloseCmd); new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.OpenUrlButton", _("Open URL"), 0, kOpenUrlCmd); + _pasteCodeWidget = new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.PasteCodeButton", _("Paste"), _("Pastes clipboard contents into fields"), kPasteCodeCmd); _connectWidget = new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ConnectButton", _("Connect"), 0, kConnectCmd); if (Cloud::CloudManager::couldUseLocalServer()) { @@ -72,7 +81,20 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): _codeWidget[i]->setVisible(false); _messageWidget->setVisible(false); _connectWidget->setVisible(false); + _pasteCodeWidget->setVisible(false); } + +#ifndef USE_SDL2 + _pasteCodeWidget->setVisible(false); +#endif + +#ifndef DISABLE_FANCY_THEMES + if (g_gui.theme()->supportsImages() && g_system->getOverlayWidth() > 320) { // picture only in high-res + GraphicsWidget *gfx = new GraphicsWidget(this, "GlobalOptions_Cloud_ConnectionWizard.Picture"); + gfx->useThemeTransparency(true); + gfx->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageDropboxLogo)); + } +#endif } void StorageWizardDialog::open() { @@ -162,7 +184,7 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 //the last 3 chars must be an encoded crc16 if (code.size() > 3) { uint32 size = code.size(); - uint32 gotcrc = decodeHashchar(code[size-3]) | (decodeHashchar(code[size-2]) << 6) | (decodeHashchar(code[size-1]) << 12); + uint32 gotcrc = decodeHashchar(code[size - 3]) | (decodeHashchar(code[size - 2]) << 6) | (decodeHashchar(code[size - 1]) << 12); code.erase(size - 3); uint32 crc = crc16(code); ok = (crc == gotcrc); @@ -183,6 +205,35 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 } break; } + case kPasteCodeCmd: { +#ifdef USE_SDL2 + if (SDL_HasClipboardText() == SDL_TRUE) { + char *text = SDL_GetClipboardText(); + if (text != nullptr) { + Common::String message = text; + for (uint32 i = 0; i < CODE_FIELDS; ++i) { + if (message.empty()) break; + Common::String subcode = ""; + for (uint32 j = 0; j < message.size(); ++j) { + if (message[j] == ' ') { + message.erase(0, j+1); + break; + } + subcode += message[j]; + if (j+1 == message.size()) { + message = ""; + break; + } + } + _codeWidget[i]->setEditString(subcode); + } + handleCommand(sender, kCodeBoxCmd, data); + draw(); + } + } +#endif + break; + } case kConnectCmd: { Common::String code; for (uint32 i = 0; i < CODE_FIELDS; ++i) { -- cgit v1.2.3 From f39b6ed4ac414d381ed0f46043586b26c05092a1 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 25 Jul 2016 18:27:13 +0600 Subject: GUI: Add Container in StorageWizardDialog It now looks fine in both 640x400 and 320x200! --- gui/storagewizarddialog.cpp | 91 +++++++++++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 28 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index e04ca0255e..f1b1796b5c 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -31,13 +31,14 @@ #include "gui/gui-manager.h" #include "gui/message.h" #include "gui/widget.h" +#include "gui/widgets/edittext.h" +#include "gui/widgets/scrollcontainer.h" #include "backends/cloud/cloudmanager.h" #ifdef USE_SDL_NET #include "backends/networking/sdl_net/localwebserver.h" #endif #include "backends/networking/browser/openurl.h" #include "common/translation.h" -#include "widgets/edittext.h" namespace GUI { @@ -45,7 +46,8 @@ enum { kConnectCmd = 'Cnnt', kCodeBoxCmd = 'CdBx', kOpenUrlCmd = 'OpUr', - kPasteCodeCmd = 'PsCd' + kPasteCodeCmd = 'PsCd', + kStorageWizardContainerReflowCmd = 'SWCr', }; StorageWizardDialog::StorageWizardDialog(uint32 storageId): @@ -55,46 +57,42 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): #endif _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain; + ScrollContainerWidget *container = new ScrollContainerWidget(this, "GlobalOptions_Cloud_ConnectionWizard.Container", kStorageWizardContainerReflowCmd); + container->setTarget(this); + Common::String headline = Common::String::format(_("%s Storage Connection Wizard"), CloudMan.listStorages()[_storageId].c_str()); - new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.Headline", headline); + _headlineWidget = new StaticTextWidget(container, "GlobalOptions_Cloud_ConnectionWizard_Container.Headline", headline); - new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.NavigateLine", _s("Navigate to the following URL:")); - new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.URLLine", getUrl()); + _navigateLineWidget = new StaticTextWidget(container, "GlobalOptions_Cloud_ConnectionWizard_Container.NavigateLine", _s("Navigate to the following URL:")); + _urlLineWidget = new StaticTextWidget(container, "GlobalOptions_Cloud_ConnectionWizard_Container.URLLine", getUrl()); - StaticTextWidget *returnLine1 = new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine1", _s("Obtain the code from the storage, enter it")); - StaticTextWidget *returnLine2 = new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ReturnLine2", _s("in the following field and press 'Connect':")); + _returnLine1 = new StaticTextWidget(container, "GlobalOptions_Cloud_ConnectionWizard_Container.ReturnLine1", _s("Obtain the code from the storage, enter it")); + _returnLine2 = new StaticTextWidget(container, "GlobalOptions_Cloud_ConnectionWizard_Container.ReturnLine2", _s("in the following field and press 'Connect':")); for (uint32 i = 0; i < CODE_FIELDS; ++i) - _codeWidget[i] = new EditTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.CodeBox" + Common::String::format("%d", i+1), "", 0, kCodeBoxCmd); - _messageWidget = new StaticTextWidget(this, "GlobalOptions_Cloud_ConnectionWizard.MessageLine", ""); + _codeWidget[i] = new EditTextWidget(container, "GlobalOptions_Cloud_ConnectionWizard_Container.CodeBox" + Common::String::format("%d", i+1), "", 0, kCodeBoxCmd); + _messageWidget = new StaticTextWidget(container, "GlobalOptions_Cloud_ConnectionWizard_Container.MessageLine", ""); // Buttons - new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.CancelButton", _("Cancel"), 0, kCloseCmd); - new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.OpenUrlButton", _("Open URL"), 0, kOpenUrlCmd); - _pasteCodeWidget = new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.PasteCodeButton", _("Paste"), _("Pastes clipboard contents into fields"), kPasteCodeCmd); - _connectWidget = new ButtonWidget(this, "GlobalOptions_Cloud_ConnectionWizard.ConnectButton", _("Connect"), 0, kConnectCmd); + _cancelWidget = new ButtonWidget(container, "GlobalOptions_Cloud_ConnectionWizard_Container.CancelButton", _("Cancel"), 0, kCloseCmd); + _openUrlWidget = new ButtonWidget(container, "GlobalOptions_Cloud_ConnectionWizard_Container.OpenUrlButton", _("Open URL"), 0, kOpenUrlCmd); + _pasteCodeWidget = new ButtonWidget(container, "GlobalOptions_Cloud_ConnectionWizard_Container.PasteCodeButton", _("Paste"), _("Pastes clipboard contents into fields"), kPasteCodeCmd); + _connectWidget = new ButtonWidget(container, "GlobalOptions_Cloud_ConnectionWizard_Container.ConnectButton", _("Connect"), 0, kConnectCmd); if (Cloud::CloudManager::couldUseLocalServer()) { // hide fields and even the button if local webserver is on - returnLine1->setLabel(_s("You would be navigated to ScummVM's page")); - returnLine2->setLabel(_s("when you'd allow it to use your storage.")); - for (uint32 i = 0; i < CODE_FIELDS; ++i) - _codeWidget[i]->setVisible(false); - _messageWidget->setVisible(false); - _connectWidget->setVisible(false); - _pasteCodeWidget->setVisible(false); + _returnLine1->setLabel(_s("You would be navigated to ScummVM's page")); + _returnLine2->setLabel(_s("when you'd allow it to use your storage.")); } - -#ifndef USE_SDL2 - _pasteCodeWidget->setVisible(false); -#endif + _picture = new GraphicsWidget(container, "GlobalOptions_Cloud_ConnectionWizard_Container.Picture"); #ifndef DISABLE_FANCY_THEMES - if (g_gui.theme()->supportsImages() && g_system->getOverlayWidth() > 320) { // picture only in high-res - GraphicsWidget *gfx = new GraphicsWidget(this, "GlobalOptions_Cloud_ConnectionWizard.Picture"); - gfx->useThemeTransparency(true); - gfx->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageDropboxLogo)); + if (g_gui.theme()->supportsImages()) { + _picture->useThemeTransparency(true); + _picture->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageDropboxLogo)); } #endif + + containerWidgetsReflow(); } void StorageWizardDialog::open() { @@ -255,6 +253,9 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 _close = true; break; #endif + case kStorageWizardContainerReflowCmd: + containerWidgetsReflow(); + break; default: Dialog::handleCommand(sender, cmd, data); } @@ -269,6 +270,40 @@ void StorageWizardDialog::handleTickle() { Dialog::handleTickle(); } +void StorageWizardDialog::containerWidgetsReflow() { + // contents + if (_headlineWidget) _headlineWidget->setVisible(true); + if (_navigateLineWidget) _navigateLineWidget->setVisible(true); + if (_urlLineWidget) _urlLineWidget->setVisible(true); + if (_returnLine1) _returnLine1->setVisible(true); + if (_returnLine2) _returnLine2->setVisible(true); + + bool showFields = (!Cloud::CloudManager::couldUseLocalServer()); + for (uint32 i = 0; i < CODE_FIELDS; ++i) + _codeWidget[i]->setVisible(showFields); + _messageWidget->setVisible(showFields); + + // left column / first bottom row + if (_picture) { + _picture->setVisible(g_system->getOverlayWidth() > 320); + } + if (_openUrlWidget) _openUrlWidget->setVisible(true); + if (_pasteCodeWidget) { +#ifdef USE_SDL2 + bool visible = showFields; +#else + bool visible = false; +#endif + _pasteCodeWidget->setVisible(visible); + } + + // bottom row + if (_cancelWidget) _cancelWidget->setVisible(true); + if (_connectWidget) { + _connectWidget->setVisible(showFields); + } +} + Common::String StorageWizardDialog::getUrl() const { Common::String url = "https://www.scummvm.org/c/"; switch (_storageId) { -- cgit v1.2.3 From 091ff83ed66336fffada6453a34710214ac3576d Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 25 Jul 2016 19:25:49 +0600 Subject: GUI: Add Storage providers logos StorageWizardDialog now shows logo of the Storage being connected (in modern highres theme). --- gui/storagewizarddialog.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index f1b1796b5c..ba3ebd8597 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -88,7 +88,20 @@ StorageWizardDialog::StorageWizardDialog(uint32 storageId): #ifndef DISABLE_FANCY_THEMES if (g_gui.theme()->supportsImages()) { _picture->useThemeTransparency(true); - _picture->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageDropboxLogo)); + switch (_storageId) { + case Cloud::kStorageDropboxId: + _picture->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageDropboxLogo)); + break; + case Cloud::kStorageOneDriveId: + _picture->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageOneDriveLogo)); + break; + case Cloud::kStorageGoogleDriveId: + _picture->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageGoogleDriveLogo)); + break; + case Cloud::kStorageBoxId: + _picture->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageBoxLogo)); + break; + } } #endif -- cgit v1.2.3 From 527ab4cdf6fc314cb260ae329d88794440b875ef Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 26 Jul 2016 11:38:53 +0600 Subject: GUI: Fix StorageWizardDialog warning Removed extra comma in the enum. --- gui/storagewizarddialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index ba3ebd8597..6d0c504521 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -47,7 +47,7 @@ enum { kCodeBoxCmd = 'CdBx', kOpenUrlCmd = 'OpUr', kPasteCodeCmd = 'PsCd', - kStorageWizardContainerReflowCmd = 'SWCr', + kStorageWizardContainerReflowCmd = 'SWCr' }; StorageWizardDialog::StorageWizardDialog(uint32 storageId): -- cgit v1.2.3 From b9bba9bd4bec1bf00a61c347f411a8ecf9ea69e8 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 26 Jul 2016 12:21:15 +0600 Subject: ALL: Move Clipboard support to OSystem Commit adds kFeatureClipboardSupport. hasTextInClipboard() and getTextFromClipboard(). OSystem_SDL has this feature if SDL2 is used. EditableWidget and StorageWizardDialog use g_system to access clipboard now. --- gui/storagewizarddialog.cpp | 52 ++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index 6d0c504521..dd1a3aae37 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -20,13 +20,6 @@ * */ -#ifdef USE_SDL2 -#define FORBIDDEN_SYMBOL_ALLOW_ALL - -#include -#include -#endif - #include "gui/storagewizarddialog.h" #include "gui/gui-manager.h" #include "gui/message.h" @@ -217,32 +210,27 @@ void StorageWizardDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3 break; } case kPasteCodeCmd: { -#ifdef USE_SDL2 - if (SDL_HasClipboardText() == SDL_TRUE) { - char *text = SDL_GetClipboardText(); - if (text != nullptr) { - Common::String message = text; - for (uint32 i = 0; i < CODE_FIELDS; ++i) { - if (message.empty()) break; - Common::String subcode = ""; - for (uint32 j = 0; j < message.size(); ++j) { - if (message[j] == ' ') { - message.erase(0, j+1); - break; - } - subcode += message[j]; - if (j+1 == message.size()) { - message = ""; - break; - } + if (g_system->hasTextInClipboard()) { + Common::String message = g_system->getTextFromClipboard(); + for (uint32 i = 0; i < CODE_FIELDS; ++i) { + if (message.empty()) break; + Common::String subcode = ""; + for (uint32 j = 0; j < message.size(); ++j) { + if (message[j] == ' ') { + message.erase(0, j+1); + break; + } + subcode += message[j]; + if (j+1 == message.size()) { + message = ""; + break; } - _codeWidget[i]->setEditString(subcode); } - handleCommand(sender, kCodeBoxCmd, data); - draw(); + _codeWidget[i]->setEditString(subcode); } + handleCommand(sender, kCodeBoxCmd, data); + draw(); } -#endif break; } case kConnectCmd: { @@ -302,11 +290,7 @@ void StorageWizardDialog::containerWidgetsReflow() { } if (_openUrlWidget) _openUrlWidget->setVisible(true); if (_pasteCodeWidget) { -#ifdef USE_SDL2 - bool visible = showFields; -#else - bool visible = false; -#endif + bool visible = showFields && g_system->hasFeature(OSystem::kFeatureClipboardSupport); _pasteCodeWidget->setVisible(visible); } -- cgit v1.2.3 From 126fe9c8457b95b13b06eb457f7ce445b031e26b Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 1 Aug 2016 12:54:54 +0600 Subject: CLOUD: Add "minimal mode" in LocalWebserver StorageWizardDialog now runs LocalWebserver in "minimal mode" for security reasons. In this mode server uses only those handlers which state to support it. There are two handlers which support minimal mode: IndexPageHandler (which handles `code` requests needed by StorageWizardDialog) and ResourceHandler (which provides inner resources like `style.css` or `logo.png` from `wwwroot.zip` archive). --- gui/storagewizarddialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gui/storagewizarddialog.cpp') diff --git a/gui/storagewizarddialog.cpp b/gui/storagewizarddialog.cpp index dd1a3aae37..60f31d1e38 100644 --- a/gui/storagewizarddialog.cpp +++ b/gui/storagewizarddialog.cpp @@ -132,7 +132,7 @@ void StorageWizardDialog::open() { #ifdef USE_SDL_NET if (Cloud::CloudManager::couldUseLocalServer()) { _stopServerOnClose = !LocalServer.isRunning(); - LocalServer.start(); + LocalServer.start(true); // using "minimal mode" (no "/files", "/download", etc available) LocalServer.indexPageHandler().setTarget(this); } #endif -- cgit v1.2.3